// Global
var AppGlobal;if(!AppGlobal)AppGlobal={};AppGlobal.BASE_URL='/';AppGlobal.CLASSPATH='js/classes/';var win=null;Number.prototype.NaN0=function(){return isNaN(this)?0:this;}
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');};String.prototype.toInteger=function(){return(isNaN(this))?0:parseInt(this);};String.prototype.toCurrency=function(){num=this;num=num.toString().replace(/\$|\,/g,'');if(isNaN(num))return"0.00";sign=(num==(num=Math.abs(num)));num=Math.floor(num*100+0.50000000001);cents=num%100;num=Math.floor(num/100).toString();if(cents<10)
cents="0"+cents;return num+"."+cents;};String.prototype.padLeft=function(len){var char="0";var str=this;if(arguments>1)char=arguments[1];for(var x=str.length;x<len;x++)str=char+str+'';return str;};String.prototype.padRight=function(len){var char="0";var str=this;if(arguments>1)char=arguments[1];for(var x=str.length;x<len;x++)str+=char+'';return str;};String.prototype.toDate=function(){var val=this.replace(/[-.]/g,"/");var tmp=Date.parse(val);if(isNaN(tmp))return this;else{var yearDigits=(val.match(/\/[0-9]{2}$/)!=null)?2:4;d=new Date(tmp);if(d.getFullYear()<'1950'&&yearDigits==2)d.setFullYear(d.getFullYear()+100);return parseInt(d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear();}};String.prototype.isInteger=function(){return(isNaN(this)||parseInt(this)!=this)?false:true;};String.prototype.stripHTML=function(){return this.replace(/<[^>]*>/g,"");}
AppGlobal.getPos=function(e){var left=0;var top=0;while(e.offsetParent){left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);e=e.offsetParent;}
left+=e.offsetLeft+(e.currentStyle?(parseInt(e.currentStyle.borderLeftWidth)).NaN0():0);top+=e.offsetTop+(e.currentStyle?(parseInt(e.currentStyle.borderTopWidth)).NaN0():0);return{x:left,y:top};}
AppGlobal.getStyle=function(oElm,strCssRule){var strValue="";if(document.defaultView&&document.defaultView.getComputedStyle)strValue=document.defaultView.getComputedStyle(oElm,"").getPropertyValue(strCssRule);else if(oElm.currentStyle){strCssRule=strCssRule.replace(/\-(\w)/g,function(strMatch,p1){return p1.toUpperCase();});strValue=oElm.currentStyle[strCssRule];}
return strValue;}
AppGlobal.setText=function(elem,text){while(elem.firstChild)elem.removeChild(elem.firstChild);elem.appendChild(document.createTextNode(text));}
AppGlobal.getXMLValue=function(node){return(node&&node.firstChild)?node.firstChild.nodeValue:""}
AppGlobal.addRollover=function(img,normalURL,rolloverURL){(new Image()).src=rolloverURL;img.onmouseover=function(){img.src=rolloverURL;}
img.onmouseout=function(){img.src=normalURL;}
if(arguments.length>3){var hitURL=arguments[3];(new Image()).src=hitURL;img.onmousedown=function(){img.src=hitURL;}
img.onmouseup=function(){img.src=rolloverURL;}}}
AppGlobal.showProductImage=function(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);}}}
AppGlobal.selectDropDownItem=function(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;}}}
AppGlobal.setupNav=function(){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.');AppGlobal.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.');AppGlobal.addRollover(inputElements[x],normalURL,rolloverURL);}}}}
AppGlobal.setupButtons=function(){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.');AppGlobal.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.');AppGlobal.addRollover(inputElements[x],normalURL,rolloverURL,hitURL);}}}}
AppGlobal.addRollover=function(img,normalURL,rolloverURL){(new Image()).src=rolloverURL;img.onmouseover=function(){img.src=rolloverURL;}
img.onmouseout=function(){img.src=normalURL;}
if(arguments.length>3){var hitURL=arguments[3];(new Image()).src=hitURL;img.onmousedown=function(){img.src=hitURL;}
img.onmouseup=function(){img.src=rolloverURL;}}}
AppGlobal.onLoad=function(){AppGlobal.setupNav();AppGlobal.setupButtons();(new Image()).src="/images/icons/backlink_on.gif";(new Image()).src="/images/icons/toplink_on.gif";(new Image()).src="/images/icons/bulletlink_on.gif";}
var Cookie={get:function(name){var getValue=function(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1)endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));}
var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg)
return getValue(j);i=document.cookie.indexOf(" ",i)+1;if(i==0)break;}
return null;},set:function(name,value,expires,path,domain,secure){tmppath=(path!="")?path:basePath;tmpdomain=(domain!="")?domain:baseDomain;document.cookie=name+"="+escape(value)+
((expires)?"; expires="+expires.toGMTString():"")+
((tmppath)?"; path="+tmppath:"")+
((tmpdomain)?"; domain="+tmpdomain:"")+
((secure)?"; secure":"");},fixDate:function(date){var base=new Date(0);var skew=base.getTime();if(skew>0)
date.setTime(date.getTime()-skew);}}
var Browser={detect:function(){this.NAME=this.searchString(this.dataBrowser)||"An unknown browser";this.VERSION=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";this.OS=this.searchString(this.dataOS)||"an unknown OS";},searchString:function(data){for(var i=0;i<data.length;i++){var dataString=data[i].string;var dataProp=data[i].prop;this.versionSearchString=data[i].versionSearch||data[i].identity;if(dataString){if(dataString.indexOf(data[i].subString)!=-1)return data[i].identity;}
else if(dataProp)return data[i].identity;}},searchVersion:function(dataString){var index=dataString.indexOf(this.versionSearchString);if(index==-1)return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1));},dataBrowser:[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",versionSearch:"Version"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Internet Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};Browser.detect();if(window.addEventListener)window.addEventListener("load",AppGlobal.onLoad,false);else if(window.attachEvent)window.attachEvent("onload",AppGlobal.onLoad);

// Forms
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.validateItemList=function(sender,e){var result=true;var form=document.getElementById("frmQuoteRequest");for(var x=0;x<form.elements.length;x++){if(form.elements[x].name.indexOf("txtQty")!=-1){if(!form.elements[x].value.isInteger())result=false;}}
e.IsValid=result;}
Forms.onLoad=function(){Forms.checkReferral();}
if(window.addEventListener)window.addEventListener("load",Forms.onLoad,false);else if(window.attachEvent)window.attachEvent("onload",Forms.onLoad);

// 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.typeResult=null;ProductSearch.qtyResult=null;var request=null;ProductSearch.getInfo=function(){var form=document.ProductSearch;if(form){request=Ajax.newRequest();var params="";if(form.k)params+="k="+escape(form.k.value)+"&";if(form.t)params+="t="+escape(form.t.value)+"&";request.open("POST",ProductSearch.ajaxURL,true);request.onreadystatechange=function(){var status=document.getElementById("FindStatus");ProductSearch.showProgressWheel();if(request.readyState==4){var requery=false;if(request.status==200){ProductSearch.typeResult=null;ProductSearch.qtyResult=null;eval(request.responseText);requery=ProductSearch.processResults();}else if(request.status==501){var msg="Data Query Error";if(status){AppGlobal.setText(status,msg);status.style.color='#CC0000';}else alert(msg);}else{var msg="Communications Error";if(status){AppGlobal.setText(status,msg);status.style.color='#CC0000';}else alert(msg);}
request=Ajax.newRequest();if(requery)ProductSearch.getInfo();}}
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");request.send(params+"a=q");}else alert("Cannot get product information due to missing variables in AJAX post.");}
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].Name,rs[x].ID));form.t.options.add(new Option("Product Type",""),0);form.t.style.fontStyle='normal';AppGlobal.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(status&&ProductSearch.qtyResult!=null){var matches=parseInt(ProductSearch.qtyResult.ProductQty.NumMatches);if(matches==0){status.style.color='#CC0000';AppGlobal.setText(status,"No matching products found");}else if(matches==1){status.style.color='';AppGlobal.setText(status,"1 matching product found");}else{status.style.color='';AppGlobal.setText(status,matches+" matching products found");}}else if(status){AppGlobal.setText(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';AppGlobal.setText(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;}
(new Image()).src=ProductSearch.progressWheel;}
if(window.addEventListener)window.addEventListener("load",ProductSearch.onLoad,false);else if(window.attachEvent)window.attachEvent("onload",ProductSearch.onLoad);

// Ajax
var Ajax={newRequest:function(){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;}}
