// Global items
var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var request=setupNewAjaxRequest();function setupNewAjaxRequest(){var request=null;try{request=new XMLHttpRequest();}catch(trymicrosoft){try{request=new ActiveXObject("Msxml2.XMLHTTP");}catch(othermicrosoft){try{request=new ActiveXObject("Microsoft.XMLHTTP");}catch(failed){request=null;}}}
return request;}
function getXMLValue(node){return(node&&node.firstChild)?node.firstChild.nodeValue:""}
function replaceText(elem,newtext){while(elem.firstChild!=null)elem.removeChild(elem.firstChild);elem.appendChild(document.createTextNode(newtext));}
function selectDropDownItem(val,list,mode){for(var x=0;x<list.options.length;x++){if(mode=="text"&&val==list.options[x].text){list.selectedIndex=x;return;}
else if(mode=="value"&&val==list.options[x].value){list.selectedIndex=x;return;}}}
function showProductImage(obj){var imgThumb=obj.getElementsByTagName("img")[0];var imgFull=document.getElementById("imgMain");if(imgThumb&&imgFull){var divFull=imgFull.parentNode;while(divFull.firstChild)divFull.removeChild(divFull.firstChild);var imgFull=document.createElement("img");imgFull.src=imgThumb.src.replace("_smthumb.jpg","_view.jpg");imgFull.setAttribute("alt",imgThumb.getAttribute("alt"));imgFull.id="imgMain";if(imgFull.complete)divFull.appendChild(imgFull);imgFull.onload=function(){divFull.appendChild(this);}}}
function preloadImages(){var d=document;if(d.images){if(!d.p)d.p=new Array();var i,j=d.p.length,a=preloadImages.arguments;for(i=0;i<a.length;i++)
if(a[i].indexOf("#")!=0){d.p[j]=new Image;d.p[j++].src=a[i];}}}
function setupNav(){var pageImages=document.getElementsByTagName("img");for(var x=0;x<pageImages.length;x++){var thisImage=pageImages[x].src.replace(location.protocol+'//'+location.hostname,'');if(thisImage.indexOf('/nav/')!=-1){var normalURL=thisImage;var rolloverURL=thisImage.replace('.','_on.');addRollover(pageImages[x],normalURL,rolloverURL);}}
var inputElements=document.getElementsByTagName("input");for(var x=0;x<inputElements.length;x++){if(inputElements[x].getAttribute("type")=="image"){var thisImage=inputElements[x].src.replace(location.protocol+'//'+location.hostname,'');if(thisImage.indexOf('/nav/')!=-1){var normalURL=thisImage;var rolloverURL=thisImage.replace('.','_on.');addRollover(inputElements[x],normalURL,rolloverURL);}}}}
function setupButtons(){var pageImages=document.getElementsByTagName("img");for(var x=0;x<pageImages.length;x++){var thisImage=pageImages[x].src.replace(location.protocol+'//'+location.hostname,'');if(thisImage.indexOf('/buttons/')!=-1){var normalURL=thisImage;var rolloverURL=thisImage.replace('.','_on.');var hitURL=thisImage.replace('.','_hit.');addRollover(pageImages[x],normalURL,rolloverURL,hitURL);}}
var inputElements=document.getElementsByTagName("input");for(var x=0;x<inputElements.length;x++){if(inputElements[x].getAttribute("type")=="image"){var thisImage=inputElements[x].src.replace(location.protocol+'//'+location.hostname,'');if(thisImage.indexOf('/buttons/')!=-1){var normalURL=thisImage;var rolloverURL=thisImage.replace('.','_on.');var hitURL=thisImage.replace('.','_hit.');addRollover(inputElements[x],normalURL,rolloverURL,hitURL);}}}}
function addRollover(img,normalURL,rolloverURL){preloadImages(rolloverURL);img.onmouseover=function(){img.src=rolloverURL;}
img.onmouseout=function(){img.src=normalURL;}
if(arguments.length>3){var hitURL=arguments[3];preloadImages(hitURL);img.onmousedown=function(){img.src=hitURL;}
img.onmouseup=function(){img.src=rolloverURL;}}}
function globalLoad(){setupNav();setupButtons();preloadImages("/images/icons/backlink_on.gif");preloadImages("/images/icons/toplink_on.gif");preloadImages("/images/icons/bulletlink_on.gif");}
if(window.addEventListener)window.addEventListener("load",globalLoad,false);else if(window.attachEvent)window.attachEvent("onload",globalLoad);

// Product search
var ProductSearch;if(!ProductSearch)ProductSearch={}
else if(typeof ProductSearch!="object")throw new Error("'ProductSearch' already exists and is not an object");ProductSearch.ajaxURL="/ajax/search.aspx";ProductSearch.progressWheel="/images/icons/progress_blue.gif";ProductSearch.timer=null;ProductSearch.typeResult=null;ProductSearch.sizeResult=null;ProductSearch.qtyResult=null;ProductSearch.getInfo=function(){var form=document.ProductSearch;if(form){if(ProductSearch.timer!=null){clearTimeout(ProductSearch.timer);ProductSearch.timer=null;}
if(request.readyState==0||request.readyState==4){var params="";if(form.k)params+="k="+escape(form.k.value)+"&";if(form.t)params+="t="+escape(form.t.value)+"&";if(form.t)params+="s="+escape(form.s.value)+"&";request.open("POST",ProductSearch.ajaxURL,true);request.onreadystatechange=function(){ProductSearch.updateInfo();}
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");request.send(params+"a=q");}else ProductSearch.timer=setTimeout(ProductSearch.getInfo,0);}else alert("Cannot get product information due to missing variables in AJAX post.");}
ProductSearch.updateInfo=function(){var status=document.getElementById("FindStatus");ProductSearch.showProgressWheel();if(request.readyState==4){var requery=false;if(request.status==200){ProductSearch.typeResult=null;ProductSearch.sizeResult=null;ProductSearch.qtyResult=null;eval(request.responseText);requery=ProductSearch.processResults();}else if(request.status==501){var msg="Data Query Error";if(status){replaceText(status,msg);status.style.color='#CC0000';}else alert(msg);}else{var msg="Communications Error";if(status){replaceText(status,msg);status.style.color='#CC0000';}else alert(msg);}
request=setupNewAjaxRequest();if(requery)ProductSearch.getInfo();}}
ProductSearch.processResults=function(){var form=document.ProductSearch;var status=document.getElementById("FindStatus");var requery=false;if(form){if(form.t){var tmpval=form.t.value;if(ProductSearch.typeResult!=null){var rs=ProductSearch.typeResult.ProductType;if(rs.length>0){var tmptext=form.t.options[form.t.selectedIndex].text;form.t.options.length=0;for(var x=0;x<rs.length;x++)form.t.options.add(new Option(rs[x].Description,rs[x].ID));form.t.options.add(new Option("Product Type",""),0);form.t.style.fontStyle='normal';selectDropDownItem(tmptext,form.t,"text");}else{form.t.options.length=0;form.t.options.add(new Option("Nothing Available",""),0);form.t.selectedIndex=0;form.t.style.fontStyle='italic';}}else{form.t.options.length=0;form.t.options.add(new Option("Nothing Available",""),0);form.t.selectedIndex=0;form.t.style.fontStyle='italic';}
if(form.t.options[form.t.selectedIndex].value!=tmpval)requery=true;}
if(form.s){var tmpval=form.s.value;if(ProductSearch.sizeResult!=null){var rs=ProductSearch.sizeResult.ProductSize;var tmptext=form.s.options[form.s.selectedIndex].text;form.s.options.length=0;for(var x=0;x<rs.length;x++)form.s.options.add(new Option(rs[x].Description,rs[x].ID));form.s.options.add(new Option("All Sizes",""),0);selectDropDownItem(tmptext,form.s,"text");}else{form.s.options.length=0;form.s.options.add(new Option("All Sizes",""));form.s.selectedIndex=0;}
if(form.s.options[form.s.selectedIndex].value!=tmpval)requery=true;}
if(status&&ProductSearch.qtyResult!=null){var matches=parseInt(ProductSearch.qtyResult.ProductQty.NumMatches);if(matches==0){status.style.color='#CC0000';replaceText(status,"No matching products found");}else if(matches==1){status.style.color='';replaceText(status,"1 matching product found");}else{status.style.color='';replaceText(status,matches+" matching products found");}}else if(status){replaceText(status,"");}}
return requery;}
ProductSearch.validateForm=function(){var form=document.ProductSearch;var status=document.getElementById("FindStatus");if(form&&status){if(form.t.selectedIndex==0){status.style.color='#CC0000';replaceText(status,"Please select a product type");return false;}else{return true;}}else return true;}
ProductSearch.showProgressWheel=function(){var status=document.getElementById("FindStatus");if(status){while(status.firstChild)status.removeChild(status.firstChild);var img=document.createElement("img");img.src=ProductSearch.progressWheel;img.width=16;img.height=16;status.appendChild(img);}}
ProductSearch.onLoad=function(){var form=document.ProductSearch;if(form){form.onsubmit=function(){return ProductSearch.validateForm();};if(form.k)form.k.onchange=ProductSearch.getInfo;if(form.t)form.t.onchange=ProductSearch.getInfo;if(form.s)form.s.onchange=ProductSearch.getInfo;}
preloadImages(ProductSearch.progressWheel);}
if(window.addEventListener)window.addEventListener("load",ProductSearch.onLoad,false);else if(window.attachEvent)window.attachEvent("onload",ProductSearch.onLoad);

// Form items
var Forms;if(!Forms)Forms={}
else if(typeof Forms!="object")throw new Error("'Forms' already exists and is not an object");Forms.checkReferral=function(){var form=document.frmQuoteRequest||document.frmContact;var ReferralOtherField=document.getElementById("ReferralOtherField");var ReferralOtherCaption=document.getElementById("ReferralOtherCaption");if(form&&form.ddlReferral&&ReferralOtherField&&ReferralOtherCaption){if(form.ddlReferral.value=="Magazine"||form.ddlReferral.value=="Other"){ReferralOtherField.style.display='';ReferralOtherCaption.style.display='';form.txtReferral.select();}else{ReferralOtherField.style.display='none';ReferralOtherCaption.style.display='none';}}}
Forms.validateReferral=function(source,args){var form=document.frmQuoteRequest||document.frmContact;if(form&&form.ddlReferral){if((form.ddlReferral.value=="Magazine"||form.ddlReferral.value=="Other")&&args.Value.length=="0")args.IsValid=false;else args.IsValid=true;}
return;}
Forms.onLoad=function(){Forms.checkReferral();}
if(window.addEventListener)window.addEventListener("load",Forms.onLoad,false);else if(window.attachEvent)window.attachEvent("onload",Forms.onLoad);

