var posleft = 0;
var postop = 0;

function getElemPosition(curelem)
{    
    for (posleft = 0, postop = 0; curelem.offsetParent; curelem = curelem.offsetParent) 
	{
		posleft += curelem.offsetLeft;
		postop += curelem.offsetTop;
	}
}

//used to show hover for top menu
/*Credits: Dynamic Drive CSS Library */
/*URL: http://www.dynamicdrive.com/style/ */
var menuids=["submenu"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){	
	for (var i=0; i<menuids.length; i++){
	  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
		for (var t=0; t<ultags.length; t++){
			if (ultags[t].parentNode.parentNode.id == menuids[i]){ //if this is a first level submenu
				ultags[t].style.top = ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			}
			else{ //else if this is a sub level menu (ul)
			  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px"; //position menu to the right of menu item that activated it
			}
			
			if( document.getElementById('selted1') != ultags[t].parentNode ){
				ultags[t].style.visibility = "hidden";
				ultags[t].parentNode.onmouseover=function(){
					this.getElementsByTagName("ul")[0].style.visibility = "visible";
					if( document.getElementById('selted1') )
						document.getElementById('selted1').getElementsByTagName("ul")[0].style.visibility = "hidden";
					}
				ultags[t].parentNode.onmouseout=function(){
					this.getElementsByTagName("ul")[0].style.visibility = "hidden";
					if( document.getElementById('selted1') )
						document.getElementById('selted1').getElementsByTagName("ul")[0].style.visibility = "visible";
					}
			}
		}

	}
}
if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)
//end top menu


//Used in cart to confirm that customer will delete item
function validateDelete(obj)
{
	if (!confirm("Are you sure you want to delete this " + obj + "?"))
		return false;
	return true;
}

function validateCheckout()
{
	if (document.getElementById('savestate').value == 1){
		alert("Please update your cart.");
		return false;
	}
	return true;
}

function validateCheckoutMinimum()
{
	if (document.getElementById('savestate').value == 1)
		alert("Please update your cart.");
	else
	    alert('The minimum purchase amount is $375.00');
	return false;
}

function validateCart()
{
	if (document.getElementById('totalcart').value < 1){
		alert("Your shopping cart is empty");
		return false
	}
	return true;
}

function validateOpen(closeddates)
{
	if (!confirm("Our offices are closed " + closeddates + ".\nYour order will be processed after we reopen.\nDo you want to proceed with the order?"))
	    return false;
	
	return true;
}

//used on shoppingcart.aspx to check if customer is getting multiples of boxquantity
function validateqtycart()	
{
	var inputelem = document.getElementsByTagName("input");
	var qty, qtyallowed, qtyextra, qtyelem, x;
	var qtyarray = new Array();
	//var qtyallowedarray = new Array();
	x = 0;
	for(i=0;i<inputelem.length;i++){			
		if(inputelem[i].id.indexOf('BoxQuantity') > -1){
			qtyarray[x] = new Array(3);
			qtyarray[x][0] = inputelem[i].value;								
		}
		
		//check if item is qty order
		if(inputelem[i].id.indexOf('qtyquoted') > -1){
			qtyarray[x][1] = inputelem[i].value;
		}
		
		if(inputelem[i].id.indexOf('uxQuantityText') > -1){
			qtyarray[x][2] = inputelem[i].value;	
			qtyarray[x][3] = inputelem[i].id;	
			inputelem[i].style.backgroundColor = "white";
			x++;				
		}			
	}
	
	for (i=0;i<x;i++){			
		qty = parseInt(qtyarray[i][2]);		
		qtyallowed = parseInt(qtyarray[i][0]);  
		qtyelem = qtyarray[i][3];
		qtyextra = qty%qtyallowed; 			
			
		if (qtyextra != 0 && qtyallowed != 0){  
			document.getElementById(qtyelem).style.backgroundColor = "red";      
			alert("Order must be in multiples of " + qtyallowed + ".\nPlease order " + (qty + (qtyallowed-qtyextra)) + ".");
			document.getElementById(qtyelem).focus();
			return false;
		}
		
		//check if item is qty order
		qtyquoted = parseInt(qtyarray[i][1]);
		if (qtyquoted > 0){
			if (qty < qtyquoted){
				document.getElementById(qtyelem).style.backgroundColor = "red";  
				alert("This item is a quoted quantity order and has a minimum of " + qtyquoted + ".");
				document.getElementById(qtyelem).focus();
				return false;
			}
		}
	}

	return true;
}

//used on shoppingcart.asp to show popup of orderitem
function displayOrderItemDetails(curelem, productid, optionsid, leadtime, idqty)
{   
    var intxt;
    intxt = "<div class='formareapopup'>";
    
    var arrSplit;
    var optionprice = "";
    
    //show product
    for (x=0;x<cartProductDetailsArray.length;x++)
    {
        if (productid == cartProductDetailsArray[x][0])
        {
            intxt += "<p><img src='" + cartProductDetailsArray[x][2] + "'></p>";
            intxt += "<p>" + cartProductDetailsArray[x][1] + "</p>";
            intxt += "<p>" + cartProductDetailsArray[x][3] + "</p>";
            break;
        }
    }    
    intxt += "</div>";
    
    //show options
    if (optionsid != "")
    {
        intxt += "<br /><div class='formareapopup'>";
        intxt += "<p><b>Selected Options:</b></p>";
        intxt += "<table cellpadding='0' cellspacing='5px'>";
                
        arrSplit = optionsid.split(",");
        for (i=0;i<arrSplit.length;i++)
        {
            curoptionid = arrSplit[i];
            for (j=0;j<cartOptionDetailsArray.length;j++)
            {
                if (curoptionid == cartOptionDetailsArray[j][0])
                {
                    if (cartOptionDetailsArray[j][3] != "$0.00")
                        optionprice = " +" + cartOptionDetailsArray[j][3]
                    
                    intxt += "<tr>";
                    if (cartOptionDetailsArray[j][2] != "")
                        intxt += "<td><img src='" + cartOptionDetailsArray[j][2] + "'/></td>";
                    else
                        intxt += "<td>&nbsp;</td>";
                    intxt += "<td>" + cartOptionDetailsArray[j][1] + "</td>";
                    intxt += "<td>" + optionprice + "</td></tr>";
                }
            }            
        }
        
        intxt += "</table></div>";
    }
    
    //lead time
    //lead time
    if (idqty == "") //then show lead time
    {
        intxt += "<table cellpadding='0' cellspacing='5px'>";
        intxt += "<tr><td>" + leadtime + "</td></tr></table>";     
    }
    
    document.getElementById("divorderitemdetailsintxt").innerHTML = intxt;
    
    getElemPosition(curelem);

    document.getElementById("divorderitemdetails").style.left = (posleft - 50) + "px";
    
    if (optionsid != "")
        document.getElementById("divorderitemdetails").style.top = (postop - 400) + "px";     
    else // no options. so shorter popup
        document.getElementById("divorderitemdetails").style.top = (postop - 250) + "px"; 
        
    document.getElementById("divorderitemdetails").style.display = "";  
}

function closeOrderItemDetails()
{
    document.getElementById("divorderitemdetails").style.display = "none";     
}
//end of popup of orderitem

//Used to confirm that customer accepts policy
function validateAccept()
{
    if (document.getElementById("ctl00_uxPlaceHolder_chkAccept").checked == false){
        alert("You must accept the terms and conditions before completing this order.\nPlease read the full terms and conditions and scroll down to accept.");        
        return false;
    }
    return true;
}

//Validate Credit Card
function validateCard()
{
	var idPrefix = "ctl00_uxPlaceHolder_";
	var varcardType = document.getElementById(idPrefix + "CreditCartTypeDropDownList").value;
	var varcardNum = document.getElementById(idPrefix + "CreditCardNumberTextBox").value;
	var varmt = document.getElementById(idPrefix + "ExpMonthDropDownList").value;
	var varyr = document.getElementById(idPrefix + "ExpYearDropDownList").value;
	var varcvv2 = document.getElementById(idPrefix + "CVV2TextBox").value;
	varcardNum = varcardNum.replace(/\s/g,"");
	
	//Card Type
	if (varcardType == ""){
		alert("Please select the Credit Card Type");
		document.getElementById(idPrefix + "CreditCartTypeDropDownList").focus();
		return false;
	}
			
	//Card #		
	if (varcardNum == ""){
		alert("Please enter the Card Number");
		document.getElementById(idPrefix + "CreditCardNumberTextBox").focus();
		return false;
	}
			
	//CVV2	
	if (varcvv2 == ""){
		alert("Please enter the Card Verification #");
		document.getElementById(idPrefix + "CVV2TextBox").focus();
		return false;
	}		
	
	//check if user entered 3#'s for MC/Visa or 4 #'s for American Exp
	if (varcardType=="American Express"){
		if (varcvv2.length != 4){
			alert("Please enter a 4 digit CVV for American Express");
			return false;
		}
	}
	else{
		if (varcvv2.length != 3){
			alert("Please enter a 3 digit CVV for Visa or Mastercard");
			return false;
		}
	}

	//Expiration Month
	if (varmt == ""){
		alert("Please select the Exp Month");
		document.getElementById(idPrefix + "ExpMonthDropDownList").focus();
		return false;
	}
	
	//Exp Year
	if (varyr == ""){
		alert("Please select the Exp Year");
		document.getElementById(idPrefix + "ExpYearDropDownList").focus();
		return false;
	}	
	
	//check if card expired
	var myDate=new Date();
	myDate.setDate(myDate.getDate());
	var curmt = myDate.getMonth()+1;
	var curyr = myDate.getFullYear();
	if (varyr == curyr){
		if (varmt < curmt){
			alert("Invalid date.");			
			return false;
		}
	}

	return true;
}

//begin functions for customer billing & shipping info
//if billing country is outside US, show NonUS popup msg
function toggleNonUSMsg(curelem)
{
    //get position
    var posleft = 0;
    var posright = 0;
    for (posleft = 0, postop = 0; curelem.offsetParent; curelem = curelem.offsetParent) 
	{
		posleft += curelem.offsetLeft;
		postop += curelem.offsetTop;
	}
    
    if (document.getElementById("divNonUS").style.display == "none")
    {
    	document.getElementById("divNonUS").style.left = (posleft) + "px";
	    document.getElementById("divNonUS").style.top = (postop - 220) + "px";
        document.getElementById("divNonUS").style.display = "";
    }
    else
        document.getElementById("divNonUS").style.display = "none";
}

//if billing country is outside US, show textbox by state
function displayNonUSMsg(curselect)
{
    var statedrop = document.getElementById("ctl00_uxPlaceHolder_uxCustomerRegister_uxStateList_uxStateDrop");
    var statetext = document.getElementById("ctl00_uxPlaceHolder_uxCustomerRegister_uxStateList_uxStateText");
    
    if (!statedrop)
    {
        statedrop = document.getElementById("ctl00_uxPlaceHolder_uxStateList_uxStateDrop");
        statetext = document.getElementById("ctl00_uxPlaceHolder_uxStateList_uxStateText"); 
    }
    
    if( curselect.value == 'US' )
    {        
        //statedrop.disabled = false;
        statedrop.value = '';
        statetext.style.visibility = 'hidden';
        document.getElementById( 'tdNonUS' ).style.display = 'none';
        
        if (statedrop.value == 'AK' || statedrop.value == 'HI' || statedrop.value == 'OT')
            shippingAsBillingOption(0);
        else
            shippingAsBillingOption(1);
    }
    else 
    {
        statedrop.value = 'OT';
        //statedrop.disabled = true;
        statetext.style.visibility = 'visible';
        document.getElementById( 'tdNonUS' ).style.display = '';
        toggleNonUSMsg(curselect);   
        
        shippingAsBillingOption(0);
    }
}

//if billing country is outside US, disable shipping as billing 
function shippingAsBillingOption(display)
{    
    var elemprefix = "ctl00_uxPlaceHolder_uxCustomerRegister_";    
    tdUseBillingAsShippingElem = document.getElementById(elemprefix + "tdUseBillingAsShipping");
    tdDoNotUseBillingAsShippingElem = document.getElementById(elemprefix + "tdDoNotUseBillingAsShipping");
        
    if (!tdUseBillingAsShippingElem)
    {
        elemprefix = "ctl00_uxPlaceHolder_";
        tdUseBillingAsShippingElem = document.getElementById(elemprefix + "tdUseBillingAsShipping");
        tdDoNotUseBillingAsShippingElem = document.getElementById(elemprefix + "tdDoNotUseBillingAsShipping");
    }
    
    if (display == 1)
    {
        tdUseBillingAsShippingElem.style.display = '';
        tdDoNotUseBillingAsShippingElem.style.display = 'none';    
    }
    else
    {
        tdUseBillingAsShippingElem.style.display = 'none';
        tdDoNotUseBillingAsShippingElem.style.display = ''; 

        document.getElementById(elemprefix + "uxUseBillingAsShipping").checked = false; 
        document.getElementById(elemprefix + "uxShippingFirstName").disabled = false; 
        document.getElementById(elemprefix + "uxShippingLastName").disabled = false; 
        document.getElementById(elemprefix + "uxShippingCompany").disabled = false; 
        document.getElementById(elemprefix + "uxShippingAddress1").disabled = false; 
        document.getElementById(elemprefix + "uxShippingAddress2").disabled = false;
        document.getElementById(elemprefix + "uxShippingCity").disabled = false;
        document.getElementById(elemprefix + "uxShippingStateList_uxStateDrop").disabled = false; 
        document.getElementById(elemprefix + "uxShippingZip").disabled = false;
        document.getElementById(elemprefix + "uxShippingPhone").disabled = false; 
        document.getElementById(elemprefix + "uxShippingFax").disabled = false;         
    }
}
//end of functions for customer billing & shipping info

//functions for aboutus.aspx
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_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_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];}
}