// 
//  physabek_ui_lib.js
//  Project: Physabek
//  
//  Created by Blaine Horrocks on 2009-12-18.
//  Copyright 2009 - 2066795 Ontario Ltd. All rights reserved.
// 


function styleNavbar(){
  // add classes
  $('.navtab table tr').hover( function(){
           $(this).addClass('navhover');
      }, function(){
           $(this).removeClass('navhover'); 
      });
  $('.nav_open').closest('tr').addClass('navopen'); 

  // style elements
  $('.navtab table tr.navopen').not('.navtab table tr.navopen:last').css('background-color','#d3d3d3');
  $('.navtab table tr.navopen:last td:first-child').css('background','transparent url("http://shopping.netsuite.com/c.935369/site/images/navfocus.png") ');
  $('.navtab table tr.navopen:first-child td:first-child').css('background','#CF0000');
  // shrink level three text size
  $('.navtab td[colspan=3]').parent().children().css('font-size','0.8em');

  // hide level 4 elements (assumes this these are the leaf nodes)
  // remove the .not() to hide all level four elements.  .not('.navopen')
  $('.navtab table td[colspan="4"]').parent().hide();

};

// Page structure and styling fixes to work around NS limitations
function netsuitePageFixes() {
	$('#div__title').removeAttr('style'); // fix for NS browser sniffing code injection
	$('#breadcrumbs').prependTo('#content_area_header_insert').show();
	$("input[categorytype*='Kit']").show();
	$('#menu_tabs_table .menu_divider:last').hide();
	$("input[categorytype='']").closest('.cell_content').css('height','251px');  // shrink category cells without buttons
};

function miscAdditions() {
	// internationalization tools
	$('#l10n_control').nsl10nPlaceControl({targetIsWrapper:true, isLinkUsed:true});
	$('[nsl10n]').nsl10n(	{ url: "https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=17&deploy=1&compid=935369&h=aa2a02e33f98de2c3732" } );
	$.nsl10n.hideOtherLocales();
	if($.nsl10n.currentLocale() == 'fr_FR') $('#div__header').css('background-image',"url('/site/images/headerbkgnd-fr.png')");

	// search customizations
	$('#search_form_container').insertBefore('#div__title'); // move search into header
	var go_button = $('#go');
	var search_table = go_button.closest('table');
	search_table.css('background-color','#CF0000').find('input').css('margin','5px');
	go_button.css('margin-left','2px'); // reset to prevent expanding table
	search_table.attr('width','250px'); // increase width to handle fr_FR label width
	search_table.find('input[type=text]').attr('size','20');
	// search results needed some padding
	$('#submitter').closest('table').css('margin','8px');
	
	
	// misc support
	$(".comparisonchart a[href='']").hide(); 
	
	// alternate rows in kit-category templates
	$('.kit_row>td>table>tbody>tr:even').css('background-color','#FFEFCF');
	$('.kit_row>td>table>tbody>tr>td').css('padding-top','3px');

};

function restructureOptions () {
	$('.add_to_cart_row+tr').each(function(idx){ $('table td:first-child',this).append($('table td:last',this).html()).attr('align','left').css('padding-top','5px'); $('table td:last',this).empty(); });
}

function hideNavTabExcept (excludeTab) {
	$('.navtab').each(function(){
		if (excludeTab != $('a', $(this)).html().substr(0,excludeTab.length)){
			$(this).hide();
		}else{
			//$(this).closest('a').attr('href', '#');
			//$('a', $(this)).attr ('href', '#');
		}
	});
}


function getURLParam(sParamName){
  if ( window.location.href.indexOf("?") > -1 ) {
    var aQueryString = window.location.href.split("?")[1].split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) 
	{
      if ( aQueryString[iParam].indexOf(sParamName + "=") > -1 ) return unescape(aQueryString[iParam].split("=")[1]);      
    }
  }
  return "";
}

function supplylistButtonTip () {
	$('.supplyListAddButton').bt( { 
		padding: 10, 
		width: 150, 
		spikeLength: 10, 
		spikeGirth: 10, 
		cornerRadius:5, 
		fill: 'rgba(255, 239, 207, .9)', 
		strokeWidth: 2, 
		strokeStyle: '#ED793C', 
		cssStyles: {color: '#000', fontWeight: 'normal'},
		contentSelector: "$('#supplyListTip').html()"
	 });
}


// $().appendTo('#left_menu_contents').show();
