function formHandler(form)
{
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
function displayFAQ(id)
{
	var thediv = document.getElementById("faq_" + id)
	if(thediv.style.display == "none"){
		thediv.style.display = "block"
	}else{
		thediv.style.display = "none"
	}
}
function setSelectBox(formname, fieldname)
{
	var theform = document.forms[formname]	
	if((theform[fieldname] != undefined) && (theform['selected'+fieldname] != undefined)){
	theform['selected'+fieldname].value = theform[fieldname].options[theform[fieldname].selectedIndex].value	
	}
	
}
function submitForm(formname)
{
	
	var theform = document.forms[formname]
	var form2
	/*var thepage = window.location.href
	var returnval = ""
	if(thepage.indexOf(".aspx") > -1){
		returnval = thepage.substring(thepage.lastIndexOf("/")+1)
	}else{
		returnval = "index.aspx"
	}	
	theform.elements.returnpage.value = returnval
	*/
	if(formname == "catalogform"){
	    if(checkMail(theform["emailto"].value) && checkMail(theform["emailfrom"].value)){
	        form2 = document.forms["datasheetform"]
	        form2["name"].value = theform["name"].value
	        form2["emailto"].value = theform["emailto"].value
	        form2["emailfrom"].value = theform["emailfrom"].value
	        form2["emailregion"].value = theform["emailregion"].value
	        form2["emailbody"].value = theform["emailbody"].value
			form2["emailphone"].value = theform["emailphone"].value
	        if(theform["copylabsphere"].checked){
	            form2["copylabsphere"].value = "on"
	        }
	        createCatalog("email")
	    }else{
	        alert("Please make sure both email addresses are valid.")
	    }
	}else{
	    if(checkForm(theform, theform.showlistsrc.value)){
		    theform.submit()
	    }
	}
	

}
function checkMail(em)
{
	var x = em
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}
function checkForm(theform, formstr)
{

	var formArray
	var i=0
	var errorflag = false
	
	formArray = formstr.split(",")
	for(i=0; i<formArray.length; i++){
		
		if((theform[formArray[i]] != undefined) && (theform[formArray[i]].selectedIndex == undefined)){
  		if(theform[formArray[i]].value.length == 0){ 			
				errorflag = true
  			theform[formArray[i]].style["background-color"] = "#FFFFCC"			
  		}		
		}else if(theform[formArray[i]].selectedIndex == 0){		
			errorflag = true
  		theform[formArray[i]].style["background-color"] = "#FFFFCC"	
		}
	}
	if(errorflag){
		alert("There were some errors in your form.\nPlease re-check all required fields")		
	}
	return !errorflag
}
function categoryselect(formname)
{
	var theform = document.forms[formname]
	var catid = theform.catselect_hide.options[theform.catselect_hide.selectedIndex].value
	location.href = 'catdetail.aspx?id=' + catid
		
}
function showProducts(index)
{
	var productlist = document.getElementById('level2_col1')
	var _html = ""
	_html = '<ul>\n\r'
	_html += '<li><a href="' + productArray[index][0][0] + '"><b>' + productArray[index][0][1] + '</b></a></li>\n\r'
	for(var i=1; i<productArray[index].length;i++){
		_html += '<li><a href="javascript:showProductDetail(' + index + ',' + i + ')">' + productArray[index][i][1] + '</a></li>\n\r'
	}
	_html += '</ul>\n\r'
	productlist.innerHTML = _html		
}
function showProductDetail(index, productnum)
{
	var imageDiv = document.getElementById("level2_productshot")	
	var textDiv = document.getElementById("level2_productdesc")	
	var _imageHTML = ""
	var _textHTML = ""
	

	if(index == productArray.length-1){
		_imageHTML = '<a href="componentdetail.aspx?id=' + productArray[index][productnum][0] + '"><img width="230" height="150"  src="data/userFiles/' + productArray[index][productnum][3] + '" alt=""/>"</a>'
	}else{
		_imageHTML = '<a href="productdetail.aspx?id=' + productArray[index][productnum][0] + '"><img width="230" height="150" src="data/userFiles/' + productArray[index][productnum][3] + '" alt=""/>"</a>'
	}
	_textHTML += '<strong>' + productArray[index][productnum][1] + '</strong><br /><span class="producdesctext">'
	if(index == productArray.length-1){
		_textHTML += '<a href="componentdetail.aspx?id=' + productArray[index][productnum][0] + '">Learn More</a><br /><br />' + productArray[index][productnum][2] + '</span><br /><br />'
	}else{
		_textHTML += '<a href="productdetail.aspx?id=' + productArray[index][productnum][0] + '">Learn More</a><br /><br />' + productArray[index][productnum][2] + '</span><br /><br />'
	}
		
	imageDiv.innerHTML = _imageHTML
	textDiv.innerHTML = _textHTML
}
function displayQuickView(index)
{
    var quickviewdiv = document.getElementById("quickviewwrapper")
    quickviewdiv.style.display = "block"
    /*quickviewdiv.style.filter = "alpha(opacity=0)";
	quickviewdiv.style.MozOpacity = "0";
	quickviewdiv.style.opacity = "0";
	quickviewdiv.style.KhtmlOpacity="0";
    */  
    var imagediv = document.getElementById("quickviewimage")
    var descriptiondiv = document.getElementById("quickviewdescription")
    var optionsdiv = document.getElementById("quickviewoptions")
    var _html = ""
                 
    _html = '<img src="data/userFiles/' + quickviewArray[index][3] + '" alt="" />'
    imagediv.innerHTML = _html
    
    _html = '<strong>' + quickviewArray[index][1] + '</strong><br />' + quickviewArray[index][2]
    descriptiondiv.innerHTML = _html
    
    _html = '<a href="productdetail.aspx?id=' + quickviewArray[index][0] + '&catid=' + quickviewArray[index][4] + '">Learn More</a><br /><a href="addtobuilder.aspx?action=add&id=p' + quickviewArray[index][0] + '">Add to Catalog</a><br /><a href="">Request Quote</a>'
    optionsdiv.innerHTML = _html
    
}
function closeQuickview()
{
    var quickviewdiv = document.getElementById("quickviewwrapper")
    quickviewdiv.style.display = "none"
}
function showCatBuilder()
{
    var transdiv = document.getElementById("catbuildertransparency")
    var catalogdiv = document.getElementById("domwrapper")
    var confirmdiv = document.getElementById("confirmmessage")
	var eventdiv
	
	//hide the events on the home page
	eventdiv = document.getElementById("eventcontainer")
	if(eventdiv != undefined){
		eventdiv.style.display = "none"
	}
		
    //first hide all pull-downs
    togglePullDowns('none')
    
	document.body.style.overflow = "hidden"
	
    transdiv.style.display = "block"
    catalogdiv.style.display = "block"
    if(document.URL.indexOf("built=true") > -1){
		confirmdiv.style.display = "block"
	}else{
		confirmdiv.style.display = "none"
	}
}
function closeCatBuilder()
{
    var transdiv = document.getElementById("catbuildertransparency")
    var catalogdiv = document.getElementById("domwrapper")
	var confirmdiv = document.getElementById("confirmmessage")   
   var eventdiv
	
	//show the events on the home page
	eventdiv = document.getElementById("eventcontainer")
	if(eventdiv != undefined){
		eventdiv.style.display = "block"
	}
	
    togglePullDowns('block')
    document.body.style.overflow = ""
    transdiv.style.display = "none"
    catalogdiv.style.display = "none"
	confirmdiv.style.display = "none"
}
function togglePullDowns(dis)
{
    var i = 0
    var j = 0 
    for(i=0;i<document.forms.length;i++){
        for(j=0;j<document.forms[i].elements.length;j++){
            if(document.forms[i].elements[j].name.indexOf("_hide") > -1){
                document.forms[i].elements[j].style.display = dis
            }
        }
    }
}
function createCatalog(action)
{
    var theForm = document.forms["datasheetform"]
    var orderStr = ""
    var cudStr = ""
    var elementName = ""
    var sessionvar = ""
	if(orderPDFs()){
	
	    for(var i=0; i<theForm.elements.length; i++){
	        elementName = theForm.elements[i].name
	        if(elementName.indexOf("_order")>-1){
	            orderStr += elementName.substring(0, elementName.indexOf("_")+1) + theForm.elements[i].value + ","
				 //codin added May_2009 because ids stopped being passed after the migration
				var tmp = elementName.substring(0, elementName.indexOf("_")+1);
				sessionvar += tmp.split("_").join("") + ",";
				
	        }else if(elementName.indexOf("_usedrawings")>-1){            
	            if(theForm.elements[i].checked){
	                cudStr += elementName.substring(0, elementName.indexOf("_")) + ","
	            }
	        } 
			
			
	    }
	    //alert(orderStr + "            " + cudStr)    
	    theForm["action"].value = action
	    theForm["ordervar"].value = orderStr
	    theForm["cudvar"].value = cudStr
	    theForm["sessionvar"].value = sessionvar //codin added May_2009 because ids stopped being passed after the migration
	    theForm.submit()
	}
}
function orderPDFs()
{
	var theForm = document.forms["datasheetform"]
	var countarray
	var pdfcount = 0
	var elementName = ""
	var integervalue
	var unorderedstring = ""
	var unorderedarray
	var tempelement
	
	for(var i=0; i<theForm.elements.length; i++){
		elementName = theForm.elements[i].name
		if(elementName.indexOf("_order")>-1){
			pdfcount += 1
		}
	}

	if(pdfcount == 0){
		alert("Please make sure to add PDF's to your catalog builder")
		return false
	}
	countarray = new Array(pdfcount+1)
	for(i=0; i<theForm.elements.length; i++){
		elementName = theForm.elements[i].name		
		if(elementName.indexOf("_order")>-1){
			integervalue = parseInt(theForm.elements[i].value)
			if((integervalue > 0) && (integervalue <= pdfcount) && (countarray[integervalue] != true)){
				theForm.elements[i].value = integervalue.toString()
				countarray[integervalue] = true
			}else{
				unorderedstring += elementName + ","
			}
		}
	}
	if(unorderedstring.length > 0){
		unorderedarray = unorderedstring.split(",")
		for(i=0;i<unorderedarray.length-1;i++){
			tempelement = theForm[unorderedarray[i]]
			tempelement.value = getNextOrder(countarray).toString()
			countarray[parseInt(tempelement.value)] = true
		}
	}
	return true
}
function getNextOrder(carray)
{
	for(var i=1; i<carray.length;i++){
		if(carray[i] != true){
			return i
		}
	}
}
function displayContacts(region)
{
	var theDiv = document.getElementById("salesofficesresults")
	var html = ""
	var infoArray = regionhashtable[region]
	for(var i=0; i<infoArray.length; i++){
		html += '<strong>' + infoArray[i][0] + '</strong><br />' + infoArray[i][1] + '<br />' + infoArray[i][2] + '<br />' + infoArray[i][3] + '<br />TEL: ' + infoArray[i][4] + '<br />FAX: ' + infoArray[i][5] + '<br /><br /><a href="mailto:' + infoArray[i][6] + '">' + infoArray[i][6] + '</a><br /><br />'
	}
	
	theDiv.innerHTML = html
	
}
function gotoRegion()
{
	var theform = document.forms["selectregion"]
	var theselect = theform["region_hide"]
	
	if(theselect.options[theselect.selectedIndex].value.length > 0){
		theform.selectedregion.value = theselect.options[theselect.selectedIndex].value
		theform.submit()
	}	
}
function explainCatalog(page)
{	
	window.open(page,'explainwindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=275')
	//window.open('explain.aspx', 'explainwindow', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=750,height=275')
}
function submitSearch(formname)
{
	var theForm = document.forms[formname]
	var term = theForm["searchterm"].value
	
	if(term.length == 0){
		alert("Please enter a term to search for")
	}else{
		//alert("The Labsphere search is currently updating and is unavailable. Please try again shortly.")
		//location.replace("Int_Search.aspx?q=" + term)
		
		//The google mini appliance is down so use standard google search for now.
		window.open("http://www.google.com/search?q=" + term + "+site%3Alabsphere.com&btnG=Google+Search")
	}
		
}
/*
function fade(d, s, a)
{   
    

 
    var fadeInterval
    clearInterval(fadeInterval);
	fadeInterval = setInterval(this.myName+"._resize("+nH+","+nW+")",10);        
}
function _fade(d, s, a)
{
    var thediv = document.getElementById(d)
   
    thediv.style.filter = "alpha(opacity=0)";
    thediv.style.MozOpacity = "0";
	thediv.style.opacity = "0";
	thediv.style.KhtmlOpacity="0";
}
*/
