
/***************************** /home/common/js/common_all.js **********************************************/

function include_dom(script_filename) {

	document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
    
}

	$(document).ready(function (){
		
		$('#siteSearchForm').submit(function (){
			 var url = $(this).attr('action');
			 keyword = $('#siteSearchForm input[type=text]').val();
			 url += 'keyword/'+keyword;
			 document.location.href = url;
			 return false;
	 	});
 	 
	
		switch(page)
		{
			case "contact_us":
			case "return_policy":
			case "link_us":
				$.meta.setType("attr", "validate");
				$("#custInfo").validate();				
				
				// alternate to captcha
				$.get(this_www_root+'ajax.php?cmd=set_form_token',function (data){
					var hdn = '<input type="hidden" name="ts" value="'+data+'">'
					$('#custInfo').append(hdn);
				});
				
				
			break;
			
			
		}
	});

function append_script_to_header(script_path)
{	
	var script = $('script').filter('[src="'+script_path+'"]');
	if(script.length == 0)
	{
		var str_include = '<' + 'script';
	    str_include += ' language="javascript"';
	    str_include += ' type="text/javascript"';
	    str_include += ' src="' + script_path  + '">';
	    str_include += '</' + 'script' + '>';
			     
	    $('head').append(str_include);
	}
}

function append_script_to_footer(script_path)
{	
	var script = $('script').filter('[src="'+script_path+'"]');	
	if(script.length == 0)
	{
		var str_include = '<' + 'script';
	    str_include += ' language="javascript"';
	    str_include += ' type="text/javascript"';
	    str_include += ' src="' + script_path  + '">';
	    str_include += '</' + 'script' + '>';
			     
	    $('body').append(str_include);
	}
}


var popUpWin=0;

function popUpWindow(URLStr,width,height)
{

  var left = 50;
  var top = 50;

  if(width<1)
  	width = 420;

  if(height<1)
  	height = 495;

  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }

  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  //popUpWin = open(URLStr, 'popUpWin');

}

function roundoff(number,decimal_places)
{
	number = ""+number;
	dot_pos = number.indexOf(".");
	//console.log(dot_pos);
	if(dot_pos==-1){
		// decimal point not found
		// append zeros
		number += "."; 
		for(i=0;i<decimal_places;i++){
			number += "0";
		}
		//console.log(number);
		new_number = number;
		//console.log(new_number);
	}else{
		num_part = dot_pos + decimal_places +1;
		//console.log("indexof: "+num_part);
		new_number = number.substr(0,num_part);
		//console.log(new_number);
		//new_number = (new_number);
	}
	return new_number;
}




function is_valid_email(email){
	return email.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i) ;
}

function is_empty_string(str){	
	
	if(str == ''){
		return true;
	}else if (typeof str=="string" && str.match(/^\s$/i)) {		
		return true;	
	}else{		
		return false;
	}
	
}

function getMousePosX(e)
{
	var posx = 0;
	
	if (!e) var e = window.event;
	if (e.pageX) 	{
		posx = e.pageX;
		
	}
	else if (e.clientX ) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;		
	}
	
	return posx;
}

function getMousePosY(e)
{	
	var posy = 0;
	if (!e) var e = window.event;
	if ( e.pageY) {		
		posy = e.pageY;
	}
	else if (e.clientY) {		
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	
	return posy;

}


function str_replace(search, replace, str)
{
	while(str.indexOf(search) != -1){
        str = str.replace(search,replace);
    }
	return str;
}

/***************************** /home/clary50/public_html/_templates/_js/header.js **********************************************/

	
$(document).ready(function(){		

	dropdown_create('#criteria_menu');
	
	
});

/***************************** /home/clary50/public_html/_templates/_js/site.js **********************************************/



$(document).ready(function(){
	
	// code common to all pages of site except cart pages,  comes here
	
	
	
	// page specific code
	switch(page)
	{		
		case "index":
			$('.product_combo').change(function (){
				prod_id = $(this).val();				
				url = this_www_root+'index/product/id/'+prod_id+'#supplies'
				document.location = url;
			});
		break;
		
		case "contact_us":
		case "static":
		case "return_policy":
		case "product_list":
		case "product":
			adjust_panel_height();
		break;
		
		case "comparison":
			adjust_panel_height();
			$('.comparison').flexigrid({height:'auto',striped:false});
			
		break;	
		
	}
	

});



function adjust_panel_height(){
	new_height = $("#middle-right").height();			
	prev_height = $("#panel-left").height();			
	if(prev_height < new_height){
		$("#panel-left").css('height',new_height+'px');	
	}
		
}

/***************************** /home/common/js/jquery/drop-down-menu.js **********************************************/

var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function dropdown_open()
{  
	dropdown_canceltimer();
   	dropdown_close();
   	//ddmenuitem = $(this).find('ul').css('visibility', 'visible');
   	ddmenuitem = $(this).find('ul').css('display', 'block');
}

function dropdown_close()
{  
	//if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
	if(ddmenuitem) ddmenuitem.css('display', 'none');
}

function dropdown_timer()
{  
	closetimer = window.setTimeout(dropdown_close, timeout);
}

function dropdown_canceltimer()
{  
	if(closetimer)
   	{  
   		window.clearTimeout(closetimer);
      	closetimer = null;
   	}
}


function dropdown_create(menu_ul)
{
	$(menu_ul+' > li').bind('mouseover', dropdown_open)
   	$(menu_ul+' > li').bind('mouseout',  dropdown_timer)
}


document.onclick = dropdown_close;
