/*
    Preload images
*/
if (document.images) {

    abouton = new Image();
    abouton.src = "/images/nav_aboutus_r.gif";
    aboutoff = new Image();
    aboutoff.src = "/images/nav_aboutus.gif";
    
    prodon = new Image();
    prodon.src = "/images/nav_productinfo_r.gif";
    prodoff = new Image();
    prodoff.src = "/images/nav_productinfo.gif";
    
    //diamondon = new Image();
    //diamondon.src = "/images/nav_diamonded_r.gif";
    //diamondoff = new Image();
    //diamondoff.src = "/images/nav_diamonded.gif";
    
    custservon = new Image();
    custservon.src = "/images/nav_custserv_r.gif";
    custservoff = new Image();
    custservoff.src = "/images/nav_custserv.gif";
    
    faqon = new Image();
    faqon.src = "/images/nav_faqs_r.gif";
    faqoff = new Image();
    faqoff.src = "/images/nav_faqs.gif";
    
    contacton = new Image();
    contacton.src = "/images/nav_contactus_r.gif";
    contactoff = new Image();
    contactoff.src = "/images/nav_contactus.gif";
    
    homeon = new Image();
    homeon.src = "/images/nav_home_r.gif";
    homeoff = new Image();
    homeoff.src = "/images/nav_home.gif";
    
}


/*
    Suckerfish dropdowns
*/

sfHover = function() {
	var sfEls = document.getElementById("mainnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			if (document.getElementById("ddlStyle")) {
				document.getElementById("ddlStyle").style.visibility = "hidden";
			}
			if (document.getElementById("lstSort")) {
				document.getElementById("lstSort").style.visibility = "hidden";
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			if (document.getElementById("ddlStyle")) {
				document.getElementById("ddlStyle").style.visibility = "visible";
			}
			if (document.getElementById("lstSort")) {
				document.getElementById("lstSort").style.visibility = "visible";
			}
		}
	}
	
	sfEls = document.getElementById("sidenav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
			if (document.getElementById("ddlStyle")) {
				document.getElementById("ddlStyle").style.visibility = "hidden";
			}
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			if (document.getElementById("ddlStyle")) {
				document.getElementById("ddlStyle").style.visibility = "visible";
			}
		}
	}
	
	
	
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


/*
    Change images on rollover
*/
function changeImages() {
  if (document.images) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document.images[changeImages.arguments[i]].src = eval(changeImages.arguments[i+1] + ".src");
    }
  }
}


/*
    Empty form fields
*/
function clearText(objField){
	if (objField.defaultValue==objField.value)
	objField.value = ""
}

function popupLargerImage(url)
{
	var win = window.open('popupLargerImage.aspx?img='+url,'Detail','height=325,width=325,scrollbars=no,toolbar=no,location=no,status=no')
    win.focus();
}
function popupImage(url)
{
	var win = window.open('popupImage.aspx?img='+url,'Detail','height=175,width=175,scrollbars=no,toolbar=no,location=no,status=no')
    win.focus();
}


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}



function validate(theForm)
	{
	var returnFlag;
	var frmLength;
	var firstBlank;
	var strEmailAddress;
	var strMessage;
		
	var arrReqFields = getElementsByClassName(document.getElementById(theForm.id), "*", "required");
	
	strMessage = "Please complete all required fields."
	firstBlank = -1;
	
	// loop through fields to clear out default values
	frmLength = arrReqFields.length;
	
	for (i=0; i<frmLength;i++){ 
		if(arrReqFields[i].value == "")
		{
			
			arrReqFields[i].className = "required warning";
			returnFlag = false;
			if(firstBlank == -1) {
				firstBlank = i
			}
		}
		else if(arrReqFields[i].name == "email") {
			strEmailAddress = arrReqFields[i].value;
			intAtPosition = strEmailAddress.indexOf("@");
			intLastDotPosition = strEmailAddress.lastIndexOf(".");
			if((strEmailAddress=="") || (intAtPosition == 0) || (intAtPosition == 1) || (intLastDotPosition == -1) || (intAtPosition > intLastDotPosition) || (intLastDotPosition+1 == strEmailAddress.length)){
				arrReqFields[i].className = "required warning";
				returnFlag = false;
				if(firstBlank == -1) {
					firstBlank = i;
					strMessage = "Please enter a valid email address";
					
				}
			}
		}
		else {
			arrReqFields[i].className = "required";
		}
	}
				
	if(returnFlag == false)
		{
			alert(strMessage);
			arrReqFields[firstBlank].focus()
		}
		
	return returnFlag;
	}