// Top Navigation
var timeout = 500;
var closetimer	= 0;
var ddmenuitem = 0;
function topNav_open(){	
 topNav_canceltimer();
	topNav_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}
function topNav_close(){	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}
function topNav_timer(){	closetimer = window.setTimeout(topNav_close, timeout);}
function topNav_canceltimer(){	
 if(closetimer)	{	
	 window.clearTimeout(closetimer);
		closetimer = null;
	}
}
$(document).ready(function(){	
 $('#topNav > li').bind('mouseover', topNav_open);
	$('#topNav > li').bind('mouseout',  topNav_timer);}
);
document.onclick = topNav_close;

// Image swapping
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) {window.open(theURL,winName,features);}
function closeme() {window.close()}
function Go(){return}
function PrintMe(Address) {
	window.open([Address], "newWin", "top=0,left=0,scrollbars=yes,resizable=no,status=no,menubar=no,width=650,height=700")
}
function PrinterFriendly(Address) {
	window.open([Address], "newWin", "top=0,left=0,scrollbars=yes,resizable=no,status=no,menubar=no,width=610")
}
function swapProductImage(newSRC,newHREF) {
	document.getElementById('prodImage').src = newSRC;
	document.getElementById('prodImageLink').href = newHREF;
}

function validateForm(){
	var zipCodeField = document.dealerLocator.zipCode;
	var areaCodeField = document.dealerLocator.areaCode;
	var zipCodeIsBlank = (zipCodeField.value == '' || zipCodeField.value == 'Zip / Postal Code');
	var areaCodeIsBlank = (areaCodeField.value == '' || areaCodeField.value == '3 Digit Area Code');
	var zipDigits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- ";
	var errorMessage = '';
	//alert(zipIsPopulated);
	if (zipCodeIsBlank && areaCodeIsBlank){
		var stateElement = document.getElementById("state");
		if (stateElement == null){
			errorMessage = 'You must fill in a value to search!';
		}
	} else if (!zipCodeIsBlank) {
		var CharN;
		if (zipCodeField.value.length < 5){
			errorMessage = 'Zip / Postal Code Must be at least 5 digits!';
			zipCodeField.focus();
		} else {
			for (var i = 0; i < zipCodeField.value.length; i++){
				CharN = zipCodeField.value.substring(i, i + 1)
				if ( zipDigits.indexOf( CharN ) == -1 ){
					errorMessage = 'Please enter a valid Zip / Postal Code!!';
					zipCodeField.focus();
				}
			}
		}
	} else { // (!areaCodeIsBlank)
		if (isNaN(areaCodeField.value)){
		errorMessage = "Area Code must be numeric";
		areaCodeField.focus();
		} else if (areaCodeField.value.length != 3){
			errorMessage = "Area Code must be 3 digits";
			areaCodeField.focus();
		}
	}
	if (errorMessage == ''){
		return true;
	} else {
		alert(errorMessage);
		return false;
	}
}  
function showWishListPopUp() {
	var cvr = document.getElementById("cover");
	var dlg = document.getElementById("wishList");
	cvr.style.display = "block";
	dlg.style.display = "block";
	dlg.style.top = 250;
}

function showPopUp(ID) {
	var cvr = document.getElementById("cover");
	var dlg = document.getElementById(ID);
	if (ID == 'dialog') {
		dlg.style.left = document.documentElement.offsetWidth/2-200;
		dlg.style.top = document.documentElement.offsetHeight/2-100;
	}
	dlg.innerHTML = document.getElementById('pleaseWaitDisplay').innerHTML;
	cvr.style.display = "block";
	dlg.style.display = "block";
}
function closePopUp(ID) {
	var cvr = document.getElementById("cover");
	var dlg = document.getElementById(ID);
	cvr.style.display = "none";
	dlg.style.display = "none";
	document.body.style.overflowY = "scroll";
}
function formSubmit(url){
	stcls();
	showPopUp('dialog');
}
function toggleCheckbox(thisCheckbox,reloadWindow){
	var whichOneArray = thisCheckbox.split("_");
	var addOrRemove = '';
	var workFrame_src = '';
 if (document.getElementById(thisCheckbox).checked == true)	{
		addOrRemove = 'add';
	} else {
		addOrRemove = 'remove';
	}
	workFrame_src = '/Products/setSessionValues.cfm?whichOne=' + whichOneArray[0] + '&addOrRemove=' + addOrRemove + '&productID=' + whichOneArray[1];
	window.frames['workFrame'].location = workFrame_src;
	if (reloadWindow == 1){
	 window.location.reload();	
	}
}

// jQuery: When document is loaded and ready to process:
$(document).ready(function() {
    /* 	Footer Push: Pushes footer to the bottom of the page. 
    	Call the function and pass the ID of your main content element	*/    
    footerPush("#footer");
});

function footerPush (bodyElement) {
    /* Title:       Footer Push v3.01
     * Modified:    October 16th, 2008
     *
     * Description: This function will push page's footer down to the bottom of the browser 
     *              on pages where content does not fill the page.  This prevents the footer 
     *              from 'floating' in the middle of the page.  Requires jQuery 1.2.6
     *              
     *              bodyElement = ID of element you want to extend to full length of the page.
     *
     * Tested on:   Microsoft IE v6.0.2900.5512.xpsp.080413-2111 w/ SP3
     *              Mozilla's Firefox v3.0.3 (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3)
     *              Apple's Safari Windows v3.1.2 (525.21)
     *              Opera v9.60 Build 10447 (Opera/9.60 (Windows NT 5.1; U; en) Presto/2.1.1)
     *              Google's Chrome v0.2.149.30 (Official Build 2200 Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.30 Safari/525.13)
     *
     * NOT TESTED:  Microsoft IE 7
     *              Microsoft IE 8 beta 2
     *              Apple's Safari Mac 
     *
     * Notes:       jQuery 1.2.6 identifies Google's Chrome browser as Safari. This footer push currently works for both
     *              Firefox *may* render the footer too short/long -- unable to pinpoint.  When doing a hard refresh (Shift + Refresh) in Firefox, the footer is sometimes pushed down too far.
     *              Opera requires a different method to determine browser/viewport height
     *
     * Resources:   jQuery Browser Detection: http://docs.jquery.com/Utilities/jQuery.browser
     *              Browser detection for Google's Chrome: http://javascriptly.com/2008/09/javascript-to-detect-google-chrome/
     *              Opera/IE unique way of finding viewport size: http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
     *
     *Todo:         Hide / minimize the footer 'jump' effect
     *              Test on more current IE browsers
     */
    
    if ( $(window).height() > $(document.body).height() ) {
        if ( $.browser.msie ) {             //If Microsoft's IE
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) - 0);
        } else if ($.browser.mozilla) {     //If Mozilla's Firefox
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) - 17);
        } else if ($.browser.safari) {      //If Apple's Safari *or* Google's Chrome
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) - 58);
        } else {                            //Any other browser, default to 'standard' implementation
            $(bodyElement).height( $(bodyElement).height() + ( $(window).height() - $(document.body).height()) - 0);
        };
    };
    if ( $.browser.opera ) {     //If Opera
        if ( window.innerHeight > $(document.body).height() ) {
            $(bodyElement).height( $(bodyElement).height() + ( window.innerHeight - $(document.body).height()) - 0 );
        };
    };
};

