// JavaScript Document

function isEmail(strEmail){
	var patrn = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+jQuery/;
	return patrn.test(strEmail);
}
function isValidDigit(s) 
{ 
	var patrn=/^[0-9]{1,20}jQuery/; 
	if (!patrn.exec(s)) return false;
	return true;
} 
function isValidInput(s)
{
	var patrn=/^([a-zA-Z0-9]|[ .,-]){1,}jQuery/; 
	if (!patrn.exec(s)) return false;
	return true;
}

function openWin(theLoc,theWidth,theHeight){
	win=window.open(theLoc,"NewWin","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight);
	if(win.opener==null) win.opener=window;
	win.opener.name="opener";
}

jQuery(document).ready(function(){
	//superfish top nav
	jQuery('ul.sf-menu').superfish();
	jQuery('#menu li.li'+jQuery('#menu a[id]').length).css('background','none');
	
	//footer nav
	var menuwd = 0;
	jQuery('#footer ul').each(function(){
		menuwd = menuwd + jQuery(this).width();
	});
	var pad = Math.floor((845-menuwd)/2/jQuery('#footer ul').length);
	jQuery('#footer ul').css('padding','0px '+pad+'px');

	var hh1 = document.body.clientHeight;
	var hh2 = document.documentElement.clientHeight;
	if(hh1<hh2)
	{
		jQuery("#main").css("padding-bottom",(hh2-hh1+14)+"px");
		jQuery("#footer").css("bottom","0");
	}
	
	//if(hh1<hh2)
	//{
	//	jQuery("#wrapper").height(hh2);
	//	jQuery("#footer").css("position","absolute");
	//	jQuery("#footer").css("bottom","0");
	//}
	
	if(jQuery("#productslist").length>0)
	{
		//jQuery("#productslist .imgdv").equalHeights();
		//jQuery("#productslist .info").equalHeights();
	}
	
	// zoom image
	if(jQuery("#product").length>0)
	{
		//jQuery("a.zoomimg").eq(0).jqzoom({
		//	zoomWidth: 375,
		//	zoomHeight: 320,
		//	xOffset: 9,
		//	yOffset: 0,
		//	lens: true,
		//	title: false,
		//	showPreload: true,
		//	preloadText: 'Loading zoom',
		//	preloadPosition: 'center'
		//});
		
		jQuery("#thumbs img").click(function(){
			openWin("/large.asp?path="+jQuery(this).attr("src").replace("/pimg/tiny_",""),660,660);
		});
		
		if(jQuery("#thumbs img").length>1)
		{
			jQuery("#thumbs img").mouseover(function(){
				var strHtml = '';
				strHtml = '<a href="'+jQuery(this).attr("src").replace("tiny_","lg_")+'" class="zoomimg"><img src="'+jQuery(this).attr("src").replace("tiny_","")+'" alt="" /></a>';
				jQuery(".imgdv").html(strHtml);
				
				var index = jQuery("#thumbs img").index(this);
				//jQuery("a.zoomimg").eq(0).jqzoom({
				//	zoomWidth: 375,
				//	zoomHeight: 320,
				//	xOffset: 9,
				//	yOffset: 0,
				//	lens: true,
				//	title: false
				//});
			});
		}
	}
	
	
	//#content2_m table
	jQuery("#content2_m table[id!='cart']").each(function(){
		if(jQuery(this).width()>460)
		jQuery(this).width(460);
	});
	
	jQuery("#leftnavul a").click(function(){
		jQuery(this).next("ul").toggle();
	});
	
	if(jQuery("#level3_on").length>0)
	{jQuery("#level3_on").parents("ul").css("display","block");}



	if (jQuery('#downloadhelppluginnotpresent').length>0){
		var isPresent = PluginDetect.detectGarminCommunicatorPlugin();
		if (isPresent != true){
		       jQuery('#download_app_fm').hide();
		//       jQuery('#downloadhelppluginnotpresent').show();
		}
		else jQuery('#downloadhelppluginnotpresent').hide();
	
			jQuery("#download_app_fm").submit(function(){
	
				if (jQuery("input#FirstName").val()=="")
				{alert("Please enter a value for the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
				if (jQuery("input#FirstName").val().length<2)
				{alert("Please enter at least 2 characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
				if (jQuery("input#FirstName").val().length>50)
				{alert("Please enter at most 50 characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
				if (!isValidInput(jQuery("input#FirstName").val()))
				{alert("Please enter only letter, whitespace and \"-.\" characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
	
				if (jQuery("input#LastName").val()=="")
				{alert("Please enter a value for the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
				if (jQuery("input#LastName").val().length<2)
				{alert("Please enter at least 2 characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
				if (jQuery("input#LastName").val().length>50)
				{alert("Please enter at most 50 characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
				if (!isValidInput(jQuery("input#LastName").val()))
				{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
	
				if (jQuery("input#Email").val()=="")
				{alert("Please enter a value for the \"Email\" field.");jQuery("input#Email").focus();return false;}
				if (!isEmail(jQuery("input#Email").val()))
				{alert("Please enter a valid email address");jQuery("input#Email").focus();return false;}
	
				if (jQuery("input#Phone").val()=="")
				{alert("Please enter a value for the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
				if (jQuery("input#Phone").val().length<10)
				{alert("Please enter at least 10 characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
				if (jQuery("input#Phone").val().length>15)
				{alert("Please enter at most 15 characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
				if (!(/[0-9( )-]{10,}/.test(jQuery("input#Phone").val())))
				{alert("Please enter only digit and \"-\" characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
	
				if (jQuery("input#Password").val()=="")
				{alert("Please enter a value for the \"Password\" field.");jQuery("input#Password").focus();return false;}
				if (jQuery("input#Password").val().length<5)
				{alert("Please enter at least 5 characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
				if (jQuery("input#Password").val().length>50)
				{alert("Please enter at most 50 characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
				if (!isValidInput(jQuery("input#Password").val()))
				{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
				if (jQuery("input#Password2").val()!=jQuery("input#Password").val())
				{alert("Please re-enter your password so that it matches.");jQuery("input#Password2").focus();return false;}
			
				if (jQuery("input#ScratchOffCode").val()=="")
				{alert("Please enter a value for the \"Scratch Off Code\" field.");jQuery("input#ScratchOffCode").focus();return false;}
			
		});
	}

});

//EvPNG.fix('#rightnav,.item1,.item2,.item3,.item1 a,.item2 a,.item3 a,#content_t,#content_b,#submission a,.jcarousel-prev-vertical,.jcarousel-next-vertical,#menu .menu_l,#menu .menu_m,#menu .menu_r,#menu ul,#content2_t,#content2_b,#homebox .t,#homebox .b');


