﻿// eluminate.js
/*Copyright 2000-2005,Coremetrics 4.3.5 $Revision:139163 $*/
if(!cGB){var cGB=true;if(!cm_ClientID){var cm_ClientID="99999999"}if(!cm_HOST){var cm_HOST="test.coremetrics.com/cm?"}if(!cm_ClientTS){var dt=new Date();var cm_ClientTS=dt.getTime()}if(!cm_TrackLink){var cm_TrackLink=""}if(!cm_DelayHandlerReg){var cm_DelayHandlerReg=""}if(!cm_SkipHandlerReg){var cm_SkipHandlerReg=""}if(!cm_TrackTime){var cm_TrackTime=false}if(!cm_TrackImpressions){var cm_TrackImpressions=""}if(!cm_SecureTags||cm_SecureTags==null){var cm_SecureTags="|2|3|"}if(!cm_FirstPartyDetect){var cm_FirstPartyDetect=false}if(!cm_DownloadExtensions){var cm_DownloadExtensions=null}if(!cm_UseUTF8){var cm_UseUTF8=false}if(!cm_FormError){var cm_FormError=""}if(!cm_FormPageID){var cm_FormPageID=false}if(cm_UseCookie==null){var cm_UseCookie=true}if(!cm_TimeoutSecs){var cm_TimeoutSecs=15}if(!cm_OffsiteImpressionsEnabled){var cm_OffsiteImpressionsEnabled=false}if(!cm_AvidHost){var cm_AvidHost="data.cmcore.com/cookie-id.js?fn=cmSetAvid"}var cm_AvidLoadTimedOut=false;if(!cm_JSFEnabled){var cm_JSFEnabled=false}if(!cm_JSFPCookieDomain){var cm_JSFPCookieDomain=null}if(!cm_JSFTrackClients){var cm_JSFTrackClients=true}if(!cm_JSFPCookieMigrate){var cm_JSFPCookieMigrate=false}if(!cm_JSFPForceMigrateCookies){var cm_JSFPForceMigrateCookies=false}if(!cm_JSFPCookieMigrateVisitorID){var cm_JSFPCookieMigrateVisitorID="cm_mc_uid"}if(!cm_JSFPCookieMigrateSessionID){var cm_JSFPCookieMigrateSessionID="cm_mc_sid"}if(!cm_JSFPMigrationDomainWhitelist){var cm_JSFPMigrationDomainWhitelist=""}if(!cm_JSFPMigrationDomainBlacklist){var cm_JSFPMigrationDomainBlacklist=""}if(!cm_JSFPMigrationPathWhitelist){var cm_JSFPMigrationPathWhitelist=""}if(!cm_JSFPMigrationOtherCookies){var cm_JSFPMigrationOtherCookies=""}if(!cm_JSFPMigrationOtherCookiesExpireTimes){var cm_JSFPMigrationOtherCookiesExpireTimes={}}if(!cm_JSFMigrationEnabled){var cm_JSFMigrationEnabled=0}if(!cm_JSFSessionType){var cm_JSFSessionType="I"}if(!cm_JSFSessionTimeout){var cm_JSFSessionTimeout=1800}if(!cm_JSFCoreCookieName){var cm_JSFCoreCookieName="CoreID6"}if(!cm_JSFSpecCookieNames){var cm_JSFSpecCookieNames=new Array()}if(!cmUA){var cmUA=new Object();cmUA["MSIE"]=2083}if(!cmDefaultLimit){var cmDefaultLimit=8197}if(cGQ==null){var cGQ=true}if(!cGO){var cGO=1024}if(!cGR){var cGR=600000}if(!encodeURIComponent){var encodeURIComponent=null}var cG8;var cG8Index;var cG6=document;var cGT;var cG7=new _cG7();cG6.cmTagCtl=cG7;var CI=cmStartTagSet;var CJ=cmSendTagSet;var cG1=0;var cG0=new Array("vn1","vn2","st","pi","rs","ec","rf","ul");var cmLastPageID=null;var cGA=null;var cmMigrationDisabled=0;var cmMigrationFrom1p_CM=1;var cmMigrationFrom1p_SA=2;var cmValidFlag_SessionContinue=1;var cmValidFlag_NewSession=2;var cmValidFlag_NewVisitor=4;var cmValidFlag_SessionReset=32;var cmSACookieName="sauid";var cmCore_JSFParamEnabled="cjen";var cmCore_JSFParamUserID="cjuid";var cmCore_JSFParamSessionID="cjsid";var cmCore_JSFParamValidFlag="cjvf";var cmCore_JSFParamSpecCookiesCount="cjscc";var cmCore_JSFParamSpecCookiesNames="cjscn";var cmCore_JSFParamSpecCookiesValues="cjscv";var cmSpecCookieNames="";var cmSpecCookieValues="";var cmSpecCookiesCount=0;if(!cG4){var cG4=5000}if(!cG5){var cG5=200}var cG2=new Object();var cG3=new Object();var cGM=navigator.appVersion;var cGN=navigator.userAgent;var cGS=cGN.indexOf("Opera")>=0;var cGU=cGN.indexOf("Safari")>=0;var cmT2=-1;var cmT3=-1;var cGC="";var cGD="";var cGE="";var cGF="";var cGG="";var cGH="";var cmSubmitFlag=false;var cmFormC1="submitbuttonreset";var cmFormC2="textpasswordtextarea";var cmFormC3="select-oneselect-multiple";var cGI="";var cGJ="";var cGK="";var cGL="";var chost=null;var cci=null;CI();for(var cmSpecCookieIndex=0;cmSpecCookieIndex<cm_JSFSpecCookieNames.length;cmSpecCookieIndex++){var currSpecCookieName=cm_JSFSpecCookieNames[cmSpecCookieIndex];var currSpecCookieValue=cI(cm_JSFSpecCookieNames[cmSpecCookieIndex]);if(currSpecCookieValue==null)continue;if(currSpecCookieValue.length==0)continue;cmSpecCookieNames=cmSpecCookieNames+(cmSpecCookieNames!=""?"|":"")+escape(currSpecCookieName);cmSpecCookieValues=cmSpecCookieValues+(cmSpecCookieValues!=""?"|":"")+escape(currSpecCookieValue);cmSpecCookiesCount++}var dt=new Date();var cmYearOffset=0;if(dt.getFullYear)cmYearOffset=dt.getFullYear();else{cmYearOffset=dt.getYear();if(cmYearOffset<1900)cmYearOffset+=1900}dt.setYear(cmYearOffset+15);var cmCookieExpDate=dt.toGMTString();if(cm_UseCookie){var pi=cI("cmRS","pi","");if(pi!="")cmLastPageID=pi;chost=cm_HOST;cm_HOST=cI("cmRS","ho",chost);cci=cm_ClientID;cm_ClientID=cI("cmRS","ci",cci);var cT3=cI("cmRS","t3","");if(cT3!=""){cGA=cT3}var jsfpdata=cI("cmRS","cjen","");if(jsfpdata!=""){cm_JSFEnabled=true}var cT1=cI("cmRS","t1","");if(cT1!=""&&(!cGA||cm_ClientTS-cGA<cGR)){cmAddShared("st",cT1);var ul=cI("cmRS","ul","");var rf=cI("cmRS","rf","");var cT2=cI("cmRS","t2","");var cT4=cI("cmRS","t4","");if(cm_TrackTime)cN(cT1,cT2,cT3,cT4,true,pi);var hr=cI("cmRS","hr","");if(hr!=""){var ti=cI("cmRS","lti","");if(cm_ClientTS-ti<cGR){var nm=cI("cmRS","ln","");cM(cT1,ti,nm,hr,true,pi,ul,rf)}}var cV6=cI("cmRS","ac","");var cV7=cI("cmRS","fd","");if((cV6!="")||(cV7!="")){var ti=cI("cmRS","fti","");if(cm_ClientTS-ti<cGR){var cV9=cI("cmRS","fn","");var cV0=cI("cmRS","fu","");cL(cT1,ti,cV9,cV6,cV0,cV7,true,pi,ul,rf)}}var cError=unescape(cI("cmRS","uer",""));CH(cT1,cT3,cError,true,pi)}CC("cmRS")}if(!cGS&&(cF(4)||CD(5))){this.onload=cK(this,"onload",this.onload,"cY(e)",cY);this.onunload=cK(this,"onunload",this.onunload,"cZ(e)",cZ);if(cm_DelayHandlerReg.indexOf("L")==-1)window.cX("main");if(cm_DelayHandlerReg.indexOf("F")==-1)cU()}CJ(1);if(cm_OffsiteImpressionsEnabled){var cm_Avid=cI("CMAVID");if(cm_Avid==null){document.write("<script src='"+C8(null)+"//"+cm_AvidHost+"' language='javascript1.1' type='text/javascript'></script>");var cm_AvidLoadTimer=setTimeout("cm_AvidLoadTimedOut=true",2000)}}if(chost)cm_HOST=chost;if(cci)cm_ClientID=cci}var cI=cI;var cE=cE;function cmStartTagSet(){if(cG8)return;cG8=new Array();cG8[0]=new _cm();cG8Index=1}function cmAddShared(nm,val){if(cG8)cG8[0][nm]=val}function cmSendTagSet(){var request;var cG8_tmp=cG8;while((request=C7(arguments[0]))!=null){c9(request,cG8_tmp[0].ci)}cG8=null}function CQ(pl,host,qs){this.pl=pl;this.hosts=host.split(",");if(qs)this.qs=qs;this.cM5=CR}function CR(){var a=arguments;var h=a[0]?a[0]:this.hosts[0];return this.pl+"//"+h+(this.qs?this.qs:"")}function _cG7(){this.cM0=new Object();this.uls=new Object();this.rfs=new Object();this.cTI=new Array();this.cPE=0;this.normalizeURL=c2;this.getPageID=c1;this.getPluginPageID=cmGetPluginPageID}function cmGetPluginPageID(cVA){splitClientIDs=cm_ClientID.split(";");finalClientID=cVA;for(var n=0;n<splitClientIDs.length;n++){if(splitClientIDs[n]==cVA){finalClientID=cm_ClientID;break}}return this.getPageID(finalClientID)}function c1(cVA){var pi=cG7.cM0[cVA];return pi?pi:""}function CS(cVA){var ul=cG7.uls[cVA];if(!ul)ul=window.location.href;return ul?ul:""}function CT(cVA){var rf=cG7.rfs[cVA];if(!rf)rf=cG6.referrer;return rf?rf:""}function CP(href){var h=cGT;if(!h)h=cGT=cG7.normalizeURL(window.location.href,false);var a=href.indexOf("#");if(a>=0&&a<=h.length){var ha=h.indexOf("#");if(ha<0)ha=h.length;if(href.substring(0,a)==h.substring(0,ha))return href.substring(a)}return href}function c2(url,isHref){if(isHref){url=CP(url);var pfx=window.location.protocol+"//"+window.location.host;if(url.indexOf(pfx)==0)url=url.substring(pfx.length)}return cD(url)}function c4(){for(var b in cmUA)if(cGM.indexOf(b)!=-1)return cmUA[b];return cmDefaultLimit}function C0(n){if(cG7){if(cG7.cTI&&cG7.cTI[n]){cG7.cTI[n].cmLD=true;if(cG7.cTI[n].ci){cmJSFSetValidFlagValue(cmValidFlag_SessionContinue,false,cG7.cTI[n].ci);cmJSFSetSessionCookies(false,cG7.cTI[n].ci)}}cG7.cPE--;if(cG7.onResponse)cG7.onResponse(n)}window.dontExit=false}function CN(n){if(cG7){cG7.cPE--;var img=null;if(cG7.cTI&&cG7.cTI[n]){img=cG7.cTI[n];img.cmLD=true}if(cG7.onError&&(!img||!img.cmTO))cG7.onError(3,img)}}function c6(host,n){if(cG3)cG3[host]=true;C0(n)}function CO(n){if(cG7&&cG7.cTI&&cG7.cTI[n]&&!(cG7.cTI[n].cmLD)){var img=cG7.cTI[n];img.cmTO=img.src;if(cG7.onError)cG7.onError(4,img.cmTO)}}function c8(host){if(!cG3||cG3[host])return true;var dt=new Date();if((dt.getTime()-cG2[host])>cG4)return true;return false}function CV(host,url,cVBH){if(!cVBH)cVBH=cm_ClientID;if((!cG2[host]||c8(host))&&(cm_OffsiteImpressionsEnabled==false||cm_Avid!=null||cm_AvidLoadTimedOut)){var img=new Image();var i=cG1;cG7.cTI[cG1++]=img;if(!cG2[host]){var dt=new Date();cG2[host]=dt.getTime();img.onload=new Function("if(c6)c6('"+host+"',"+i+");")}else{img.onload=new Function("if(C0)C0("+i+");")}img.onerror=new Function("if(CN)CN("+i+");");if(cm_OffsiteImpressionsEnabled&&(cm_Avid!=null)&&(cm_Avid!="none")){url+="&avid="+cm_Avid}var limit=c4();if(url.length>limit){url=url.substring(0,limit-6)+"&err=O"}if(cG7.onTagSent)cG7.onTagSent(url,i);img.src=url;img.ci=cVBH;setTimeout('if(CO)CO('+i+');',cm_TimeoutSecs*1000)}else{setTimeout('if(CV)CV("'+host+'","'+url+'","'+cVBH+'");',cG5)}}function c9(img,ci){if(cI("CMDisabled")||(cI("CMOptout")?cI("CMOptout").toUpperCase()=="OPT_OUT":false))return;for(var h=0;h<img.hosts.length;h++){var url=img.cM5(img.hosts[h]);cG7.cPE++;CV(img.hosts[h],url,ci)}}function cC(){if(!this.ul){if(this.tid=="8"||(this.tid=="9"||this.tid=="10")){this.ul=window.location.protocol+"//"+window.location.hostname}else{this.ul=window.location.href}}if(cG8)cG8[cG8Index++]=this;else{var request=this.getImgSrc(arguments[0],1);c9(request,this.ci);return request}}function cmLogError(e){}function C4(src,tgt,compact){if(!compact){if(!src.rf){if(!document.referrer)tgt.rf="";else tgt.rf=document.referrer}else if(src!=tgt)tgt.rf=src.rf;if(!src.ul||src.ul==""||src.ul=="(none)")tgt.ul=window.location.href;else if(src!=tgt)tgt.ul=src.ul;var ul=cG7.normalizeURL(tgt.ul,false);if(ul!="")tgt.ul=ul}}function C5(tgt,compact){if(cm_FirstPartyDetect&&!compact){if(cI("cmRS")||cI("TestSess")){tgt.ts="Y"}else{CB("TestSess","Y");tgt.ts=cI("TestSess")}tgt.tp=cI("TestPerm");if(tgt.tp!="Y"){dt.setHours(dt.getHours()+5);CB("TestPerm","Y",dt.toGMTString());tgt.tp=cI("TestPerm")}}}function C6(tag,cV3,skipJSFParams){var qs="";if(tag.tid)qs+="tid="+tag.tid;var isPV=(tag.tid==1||(tag.pc&&tag.pc.charAt(0)=='Y'));if(!tag.lp&&isPV)tag.lp=cmLastPageID;for(var cOb in tag){if(!tag[cOb]||tag[cOb]===false||tag[cOb]==""||tag[cOb].constructor==Function||cOb=="qs"||cOb=="tid")continue;if(cV3&&cV3[cOb]==tag[cOb])continue;if(qs!="")qs+="&";qs+=cD(cOb)+"="+cE(cD(tag[cOb]))}if(!tag.rs&&tag.ci){if(tag.pi&&isPV)cG7.cM0[tag.ci]=tag.pi;if(tag.ul)cG7.uls[tag.ci]=tag.ul;if(tag.rf)cG7.rfs[tag.ci]=tag.rf}if(cV3&&cm_SecureTags.indexOf("|"+tag.tid+"|")!=-1)cV3.protocol="https:";if(cm_JSFEnabled&&!skipJSFParams){cmJSFSetSessionCookies(false,tag.ci);qs+=(qs!=""?"&":"")+cmCore_JSFParamEnabled+"=1";var userIdParamValue=cI(cm_JSFCoreCookieName);if(userIdParamValue){userIdParamValue=userIdParamValue.split("&",2)[0];if(userIdParamValue=="anonymous"||(cI("CMOptout")?cI("CMOptout").toUpperCase()=="ANONYMOUS":false)){userIdParamValue="1000000000000003"}}qs+="&"+cmCore_JSFParamUserID+"="+(userIdParamValue!=null?userIdParamValue:"");qs+="&"+cmCore_JSFParamSessionID+"="+cmJSFGetSessionValue(tag.ci);if(cmSpecCookiesCount>0){qs+="&"+cmCore_JSFParamSpecCookiesCount+"="+cmSpecCookiesCount;qs+="&"+cmCore_JSFParamSpecCookiesNames+"="+cmSpecCookieNames;qs+="&"+cmCore_JSFParamSpecCookiesValues+"="+cmSpecCookieValues}qs+="&"+cmCore_JSFParamValidFlag+"="+cmJSFGetValidFlagValue(tag.ci)}return qs}function C8(cV3){var cm_pl=location.protocol;if(cV3&&cV3.protocol)cm_pl=cV3.protocol;if(cm_pl!="http:"&&cm_pl!="https:")cm_pl="http:";return cm_pl}function c0(){var a=arguments;C4(this,this,a[0]);C5(this,a[0]);var cV3=new Object();var qs=C6(this,cV3);var req=new CQ(C8(cV3),cm_HOST,qs);return a[1]?req:req.cM5()}function C7(){var cV3,first,p,a,pl,lim,len,l,i,tq;if(!cG8||cG8.length<2)return null;cV3=cG8[0];first=cG8[1];cV3.ci=first.ci;for(i=1;i<cG8.length;i++){if(cV3.ci.indexOf(cG8[i].ci)==-1){cV3.ci+=";"+cG8[i].ci}if(cm_SecureTags.indexOf("|"+cG8[i].tid+"|")!=-1)cV3.protocol="https:"}for(i=0;i<cG0.length;i++){p=cG0[i];if(!cV3[p])cV3[p]=first[p]}a=arguments;C4(first,cV3,a[0]);C5(cV3,a[0]);pl=C8(cV3);img=new CQ(pl,cm_HOST);img.qs=C6(cV3);lim=c4();len=0;for(var h=0;h<img.hosts.length;h++){l=pl.length+img.hosts[h].length+img.qs.length;if(l>len)len=l}for(i=1;i<cG8.length;i++){tq=C6(cG8[i],cV3,true);if(i>1&&len+tq.length+1>lim){for(j=1;j<cG8.length-i+1;j++)cG8[j]=cG8[j+i-1];cG8.length=cG8.length-i+1;break}len+=tq.length+1;img.qs+="&"+tq}if(i==cG8.length)cG8=null;return img}function _cm(){var i,a=arguments;this.ci=cm_ClientID;for(i=0;i<a.length;i++)this[a[i]]=a[++i];this.write=cC;this.getImgSrc=c0;this.writeImg=cC;this.st=cm_ClientTS;this.vn1="4.3.5";if(cF(5.5)||!cF(0)){var ec=(cm_UseUTF8&&encodeURIComponent)||cGU?"utf-8":cG6.charset;if(!ec)ec=cG6.defaultCharset;if(!ec)ec=cG6.characterSet;this.ec=ec}}function cD(s){var z="";s=z+(!s?"":s);return s.split("'").join(z).split("\"").join(z).split("\r").join(z).split("\n").join(z)}function cE(s){var i=0,j;while(s.charAt(i)==" "&&i!=s.length)i++;j=s.length-1;while(s.charAt(j)==" "&&j!=0)j--;s=s.substring(i,j+1);if(cm_UseUTF8&&encodeURIComponent)s=encodeURIComponent(s);else{s=preEscape(s);s=escape(s);var regularExpression=new RegExp("%25u00","g");s=s.replace(regularExpression,"%u00")}s=s.split("+").join("%2B");return s}function preEscape(str){for(var i=160;i<256;i++){var regularExpression=new RegExp(String.fromCharCode(i),"g");str=str.replace(regularExpression,"%u00"+i.toString(16))}return str}function cF(ver){var i=cGM.indexOf("MSIE");if(i!=-1)return(parseFloat(cGM.substring(i+5))>=ver);return false}function CD(ver){return(cGN.indexOf("Gecko")!=-1&&parseInt(cGM)>=ver)}function cI(nm,skey,cV5){var dc=cG6.cookie;var cV4=cJ(nm,dc,";");if(!skey||!cV4){if(!cV4&&cV5!=null){return cV5}return cV4}cV4=cJ(skey,cV4,"&");if(!cV4&&cV5!=null){return cV5}return unescape(cV4)}function CL(){var cookies,dc,nv,i,c=0;dc=cG6.cookie;if(dc){cookies=dc.split(";");c=cookies.length;for(i=0;i<cookies.length;i++){nv=cookies[i].split("=");if(nv.length<2||nv[1]==null||nv[1]==""){c--}}}return c}function CB(nm,val,expires,domain){var err,len,v,dc=cG6.cookie;err=null;len=val.length+1;if(!cI(nm)){len+=nm.length}if(len>4096)err=1;else if(dc){if(CL()>=50)err=2}if(err){if(cG7.onError)cG7.onError(err,name);return false}v=nm+"="+val+";path=/";if(domain)v+=";domain="+domain;if(expires)v+=";expires="+expires;cG6.cookie=v;return true}function cmSetSubCookie(nm,skey,value,expires,domain){var currentCookieVal=cI(nm);var newCookieVal;if(!currentCookieVal){newCookieVal=skey+"="+value}else{var sep='&';var pfx=skey+"=";var begin=currentCookieVal.indexOf(pfx);if(begin>=0){if(begin>0&&currentCookieVal.charAt(begin-1)!=sep){begin=currentCookieVal.indexOf(sep+pfx);if(begin>=0){begin++}}}if(begin>=0){var valueOffset=begin+skey.length+1;var end=currentCookieVal.indexOf(sep,valueOffset);if(end<0){end=currentCookieVal.length}newCookieVal=currentCookieVal.substring(0,valueOffset)+value+currentCookieVal.substring(end)}else{newCookieVal=currentCookieVal+sep+skey+"="+value}}CB(nm,newCookieVal,expires,domain)}function CC(nm,domain){var v=cI(nm);if(v!=null){var dt=new Date();dt.setYear(1973);var v=nm+"=;path=/;expires="+dt.toGMTString();if(domain)v+=";domain="+domain;cG6.cookie=v}return v}function cJ(nm,src,sep){var pfx,s,begin,end,obj=null;pfx=nm+"=";s=sep+' ';begin=src.indexOf(s+pfx);if(begin==-1){s=sep;begin=src.indexOf(s+pfx)}if(begin==-1){begin=src.indexOf(pfx);if(begin!=0){return null}}else{begin+=s.length}end=src.indexOf(s,begin);if(end==-1){end=src.length}return src.substring(begin+pfx.length,end)}function cK(elt,type,handle,fName,f){if(handle){var event=handle.toString();var tempFName=fName.substring(0,fName.indexOf("("));if(event.indexOf(tempFName)==-1){if(cGU&&event.indexOf("function "+"(")==0){if(type=="onload"){fName=event.substring(event.indexOf("{"),event.length)+";"+fName+";"}else{fName=fName+";"+event.substring(event.indexOf("{"),event.length)}}else{elt["_c_"+type]=handle;if(type=="onload"){fName="if(!e)var e=null;var ret=this._c_"+type+"("+(cF(5)?"":"e")+");"+fName+";return ret;"}else{fName="if(!e)var e=null;var tempReturn=this._c_"+type+"("+(cF(5)?"":"e")+");"+fName+";return tempReturn"}}var newfunc=new Function("e",fName);return newfunc}else{return handle}}else{return f}}function CG(e){var e;if(cF(4)){if(window.event){e=window.event.srcElement}else{return null}}else if(e){if(CD(5)){e=e.currentTarget}else{e=e.target}}return e}function CU(cm,cVBH,pi,dest,ref){var ul,rf;cm.pi=pi?pi:c1(cVBH);if(cGQ){if(dest||ref){cm.ul=dest?dest:"";cm.rf=ref?ref:""}else{ul=CS(cVBH);rf=CT(cVBH);if(cm.pi==""||ul.indexOf("cm_")>0||(rf!=""&&rf.indexOf(window.location.protocol+"//"+window.location.host)!=0)){cm.ul=ul;cm.rf=rf}}}}function cL(t1,t3,fname,cVB,url,field,resent,pi,dest,ref){var cm=new _cm("tid","10");CU(cm,cm.ci,pi,dest,ref);cm.st=t1;cm.ti=t3;cm.fo=fname;cm.ac=cVB;cm.hr=url;cm.fi=field;if(resent)cm.rs="Y";cm.write(1)}function cM(t1,ti,name,href,resent,pi,dest,ref){var cm=new _cm("tid","8");CU(cm,cm.ci,pi,dest,ref);cm.st=t1;cm.ti=ti;cm.nm=name;cm.hr=href;var cm_crIndex=href.indexOf("cm_cr=");var cm_meIndex=href.indexOf("cm_me=");if(cm_crIndex>-1){var tempIndex=href.indexOf("&",cm_crIndex);if(tempIndex==-1){cm.cm_cr=href.substring(cm_crIndex+6)}else{cm.cm_cr=href.substring(cm_crIndex+6,tempIndex)}}if(cm_meIndex>-1){var tempIndex=href.indexOf("&",cm_meIndex);if(tempIndex==-1){cm.cm_me=href.substring(cm_meIndex+6)}else{cm.cm_me=href.substring(cm_meIndex+6,tempIndex)}}if(resent)cm.rs="Y";cm.write(1)}function cN(t1,t2,cx,t4,resent,pi){var cm=new _cm("tid","11");cm.pi=pi?pi:c1(cm.ci);cm.st=t1;cm.lc=t2;cm.lx=t4;cm.cx=cx;if(resent)cm.rs="Y";cm.write(1)}function CM(href){var n,len,a,q;if((n=href.indexOf("?"))==-1)n=href.lastIndexOf("/");if(n!=-1){len=href.indexOf("#",n);if(len==-1)len=href.length;while(n!=-1&&n<len){n=href.indexOf("cm_",n);if(n!=-1){a=href.indexOf("&",n);if(a==-1)a=len;q=href.indexOf("=",n);if(q!=-1&&q<a)this[href.substring(n,q)]=href.substring(q+1,a);n=a}}}}function CK(href,trackSP,trackRE,trackCR,trackME){var cm,link,sp,re,cr,me;if((trackSP||trackRE)&&href){cm=new _cm("tid","9");link=new CM(CP(href));if(trackSP){sp=cm.cm_sp_o=link.cm_sp_o;if(!sp)sp=cm.cm_sp=link.cm_sp}if(trackRE){re=cm.cm_re_o=link.cm_re_o;if(!re)re=cm.cm_re=link.cm_re}if(trackCR){if(href.indexOf("#")==-1){cr=cm.cm_cr=link.cm_cr}}if(trackME){me=cm.cm_me=link.cm_me}if(sp||re||cr||me){cm.pi=c1(cm.ci);cm.st=cm_ClientTS;cm.write(1)}}}function CH(t1,ti,msg,resent,pi){if(msg!=cGL){var cm=new _cm("tid","12");cm.pi=pi?pi:c1(cm.ci);cm.st=t1;cm.ti=ti;if(resent)cm.rs="Y";cm.er=msg;cm.write(1);cGL=cm_FormError}}function cmFormBlurRecord(e){if(e.cmFormEleMemValue!=cmFormElementValue(e)&&e.cmFormEleMemValue!=null){cmFormReportInteraction(e)}e.form.cmEleValue=-1}function cmFormElementOnclickEvent(){try{var q;var cFE=cmFormElementValue(this);if((cmFormC1.indexOf(this.type)>=0)||(this.cmFormEleMemValue!=cFE)){if(this.type=="radio"){for(q=0;q<this.form.elements.length;q++){if(this.form.elements[q].cM2==this.cM2){this.form.elements[q].cmFormEleMemValue=null}}}this.cmFormEleMemValue=cFE;cmFormReportInteraction(this)}}catch(e){cmLogError(e)}try{if(this.cX){return this.cX()}}catch(e){cmLogError(e)}}function cmFormElementOnfocusEvent(){try{this.form.cmEleValue=this.cM2;this.cmFormEleMemValue=cmFormElementValue(this)}catch(e){cmLogError(e)}try{if(this.cmOnFocus){return this.cmOnFocus()}}catch(e){cmLogError(e)}}function cmFormElementOnblurEvent(){try{cmFormBlurRecord(this)}catch(e){cmLogError(e)}try{if(this.cmOnBlur){return this.cmOnBlur()}}catch(e){cmLogError(e)}}function cmFormElementOnchangeEvent(){try{cmFormReportInteraction(this)}catch(e){cmLogError(e)}try{if(this.cmOnChange){return this.cmOnChange()}}catch(e){cmLogError(e)}}function cmFormElementValue(e){var x;if(e.type=="checkbox")return e.checked;else if((cmFormC3.indexOf(e.type)>=0)&&e.options){var sel_val="";for(x=0;x<e.options.length;x++){if(e.options[x].selected==true)sel_val=sel_val+e.options[x].index}return sel_val}else if(cmFormC2.indexOf(e.type)>=0||e.type=="file"||e.type=="radio"){return e.value}else{return null}}function cO(cVC,cVB){var dt,url,x,cFa="";cVB=cVC+":"+cVB;if(cVC!=-1){if(cG6.forms[cVC]){var cF=cG6.forms[cVC],cFa=cF.attributes;url=cF.action?cF.action:cFa.action.nodeValue?cFa.action.nodeValue:cFa.getNamedItem('action').value?cFa.getNamedItem('action').value:""}}cGD=cG6.cmTagCtl.normalizeFORM(cGD);var pgID=c1(cm_ClientID);if(cm_FormPageID&&pgID!=""){var frmAr=cGD.split(";");cGD="";for(x=0;x<frmAr.length-1;x++){cGD+=pgID.split(":").join("").split(";").join("")+"_"+frmAr[x]+";"}cm_FormPageID=false}if(cV(url)&&(cVC!="-1"||(cVC=="-1"&&cmSubmitFlag==false))){dt=new Date();cGH=dt.getTime();cGF=cVB;cGE=cG7.normalizeURL(url,true);cL(cm_ClientTS,cGH,cGD,cGF,cGE,cGC,false);cGG=cGC;cGC=""}else{cGF=""}}function cmFormOnresetEvent(){var x;try{cO(this.cM1,"R")}catch(e){cmLogError(e)}try{for(x=0;x<cG6.forms[this.cM1].elements.length;x++){cG6.forms[this.cM1].elements[x].cmFormEleMemValue=false}}catch(e){cmLogError(e)}try{if(this.cQ){return this.cQ()}}catch(e){cmLogError(e)}}function cmFormOnsubmitEvent(e2){try{if(this.cmEleValue>-1){cmFormBlurRecord(this.elements[this.cmEleValue])}}catch(e){cmLogError(e)}try{if(this.cM1>=0&&this.cmSubmitIndex==false){cmSubmitFlag=true;this.cmSubmitIndex=true;cO(this?this.cM1:-1,"S");CE()}}catch(e){cmLogError(e)}try{if(this.cP){return this.cP()}}catch(e){cmLogError(e)}cmJSFPMigrateLink(this,"action")}function cmFormReportInteraction(e){var cmElementName=cG6.cmTagCtl.normalizeFIELDS(e.name?e.name:e.id?e.id:"");var cmTempFieldSeq=cGC+e.form.cM1+":"+e.cM2+":"+cmElementName.split(":").join("|").split(";").join("|")+";";if(cmTempFieldSeq.length<1000){cGC=cmTempFieldSeq}}function cmFormSubmit(){cmJSFPMigrateLink(this,"action");try{if(this.cmEleValue>-1){cmFormBlurRecord(this.elements[this.cmEleValue])}}catch(e){cmLogError(e)}try{if(this.cM1>=0&&this.cmSubmitIndex==false){cmSubmitFlag=true;this.cmSubmitIndex=true;cO(this?this.cM1:-1,"S");CE()}}catch(e){cmLogError(e)}try{this.cmSubmit()}catch(e){cmLogError(e)}}cG6.cmTagCtl.normalizeFORM=function(form){return form};cG6.cmTagCtl.normalizeFIELDS=function(field){return field};function cU(){if(cm_SkipHandlerReg.indexOf("F")==-1){var i,form,cV9,j,e,rdname,ei;for(i=0;i<cG6.forms.length;i++){form=cG6.forms[i];ei=0;if(!form.cM1&&!form.cmEleValue&&!form.cmSubmitIndex){form.cM1=i;form.cmEleValue=-1;form.cmSubmitIndex=false;form.radiogroup={"key":"value"};try{if(cF(5)&&!cF(8)){var cm_FA=form.attributes;cV9=cm_FA.name?cm_FA.name.nodeValue:cm_FA.id?cm_FA.id.nodeValue:"UNDEFINED"}else if(form.attributes.getNamedItem){cV9=form.attributes.getNamedItem('name').value}else{cV9=form.name}}catch(e){cV9="UNDEFINED";cmLogError(e)}cGD+=cV9+":"+i+";";try{form.cmSubmit=form.submit;form.submit=cmFormSubmit}catch(e){cmLogError(e)}try{if(form.onsubmit&&typeof(form.onsubmit)=="function"){form.cP=form.onsubmit}form.onsubmit=cmFormOnsubmitEvent}catch(e){cmLogError(e)}try{if(form.onreset&&typeof(form.onreset)=="function"){form.cQ=form.onreset}form.onreset=cmFormOnresetEvent}catch(e){cmLogError(e)}for(j=0;j<form.elements.length;j++){e=form.elements[j];if(!e.cM1&&!e.cM2&&!e.cmFormEleMemValue){e.cM1=i;e.cM2=ei;e.cmFormEleMemValue=null;ei++;if(e.type=="radio"){rdname=e.name?e.name:e.id?e.id:"";if(rdname!=""){if(form.radiogroup[rdname]){e.cM2=form.radiogroup[rdname]}else{form.radiogroup[rdname]=e.cM2}}}if(cmFormC1.indexOf(e.type)>=0||e.type=="checkbox"||e.type=="radio"){try{if(e.onclick&&typeof(e.onclick)=="function"){e.cX=e.onclick}e.onclick=cmFormElementOnclickEvent}catch(e){cmLogError(e)}}if(cmFormC2.indexOf(e.type)>=0||cmFormC3.indexOf(e.type)>=0){try{if(e.onfocus&&typeof(e.onfocus)=="function"){e.cmOnFocus=e.onfocus}e.onfocus=cmFormElementOnfocusEvent;if(e.onblur&&typeof(e.onblur)=="function"){e.cmOnBlur=e.onblur}e.onblur=cmFormElementOnblurEvent}catch(e){cmLogError(e)}}if(e.type=="file"){try{if(e.onchange&&typeof(e.onchange)=="function"){e.cmOnChange=e.onchange}e.onchange=cmFormElementOnchangeEvent}catch(e){cmLogError(e)}}}}}}}}function cV(path){if(cm_TrackLink==true||cm_TrackLink=="A")return true;else{if(cm_TrackLink=="E"&&path.indexOf("/")!=0)return true;var de;if((de=cm_DownloadExtensions)!=null){var p=path.lastIndexOf(".");if(p!=-1){var ext=path.substring(p);for(var e=0;e<de.length;e++){if(ext==de[e])return true}}}return false}}function cW(e){CI();var e=CG(e);if(e)C9(e);CA(1);CJ(1);CE()}function C9(e){cGI="";cGJ="";cGK="";var type=e.tagName.toUpperCase();if(type=="AREA"){cGJ=e.href?e.href:"";var p=e.parentElement?e.parentElement:e.parentNode;if(p!=null)cGI=p.name?p.name:""}else{while(type!="A"&&type!="HTML"){if(!e.parentElement)e=e.parentNode;else e=e.parentElement;if(e)type=e.tagName.toUpperCase()}if(type=="A"){cGJ=e.href?e.href:"";cGI=e.name?e.name:""}}if(e.getAttribute){var man_cm_re=e.getAttribute("manual_cm_re");if(man_cm_re){cGJ=cGJ.split("#");cGJ[0]=cGJ[0]+((cGJ[0].indexOf("?")>-1)?"&":"?")+"cm_re="+man_cm_re;cGJ=cGJ.join("#")}var man_cm_sp=e.getAttribute("manual_cm_sp");if(man_cm_sp){cGJ=cGJ.split("#");cGJ[0]=cGJ[0]+((cGJ[0].indexOf("?")>-1)?"&":"?")+"cm_sp="+man_cm_sp;cGJ=cGJ.join("#")}}cGJ=cG7.normalizeURL(cGJ,true);if(cV(cGJ)==true){var dt=new Date();cGK=dt.getTime();if(typeof cmCustomLinkClickHandler=='function'){cmCustomLinkClickHandler(e)}cM(cm_ClientTS,cGK,cGI,cGJ,false)}else{cGJ=""}cmJSFPMigrateLink(e,"href")}function cX(phase){CI();var i,lnk,imp,trackSP,trackRE,trackCR,trackME;imp=cm_TrackImpressions;trackSP=(imp.indexOf("S")!=-1);trackRE=(imp.indexOf("R")!=-1);trackCR=(imp.indexOf("C")!=-1);trackME=(imp.indexOf("C")!=-1);for(i=0;i<cG6.links.length;i++){lnk=cG6.links[i];if(cm_SkipHandlerReg.indexOf("L")==-1){if(!CD(5)){lnk.onclick=cK(lnk,"onclick",lnk.onclick,"cW(e)",cW)}else if(!lnk.cM4){lnk.addEventListener("click",cW,false);lnk.cM4=1}}if(phase=="onload"){var tempLinkHref=lnk.href;if(lnk.getAttribute("manual_cm_re")){tempLinkHref=tempLinkHref.split("#");tempLinkHref[0]=tempLinkHref[0]+((tempLinkHref[0].indexOf("?")>-1)?"&":"?")+"cm_re="+lnk.getAttribute("manual_cm_re");tempLinkHref=tempLinkHref.join("#")}if(lnk.getAttribute("manual_cm_sp")){tempLinkHref=tempLinkHref.split("#");tempLinkHref[0]=tempLinkHref[0]+((tempLinkHref[0].indexOf("?")>-1)?"&":"?")+"cm_sp="+lnk.getAttribute("manual_cm_sp");tempLinkHref=tempLinkHref.join("#")}if(!lnk.cmImpressionSent){CK(tempLinkHref,trackSP,trackRE,trackCR,trackME);lnk.cmImpressionSent=1}}}CJ(1)}function cY(e){var dt=new Date();cmT2=dt.getTime();CH(cm_ClientTS,cmT2,cm_FormError,false);if(!cGS&&(cF(4)||CD(5))){window.cX("onload");cU()}cGB=null}function cZ(e){cG3=null;CI();delay=false;for(x=0;x<document.forms.length;x++){try{if(cG6.forms[x].cmEleValue>-1){cmFormBlurRecord(document.forms[x].elements[document.forms[x].cmEleValue])}}catch(e){cmLogError(e)}try{if(cGC!=""){delay=true;cO(-1,"U")}}catch(e){cmLogError(e)}}CA(0);CH(cm_ClientTS,cmT3,cm_FormError,false);CJ(1);if(delay){window.dontExit=true;var d1=new Date();var d2=new Date();for(;dontExit&&(d2-d1<1000);){d2=new Date()}}CE();if(cm_UseCookie&&cG7.cPE==0){var pi=escape(c1(cm_ClientID));CB("cmRS","t3="+cmT3+"&pi="+pi)}if(cG7.onUnload)cG7.onUnload();if(cF(5)&&!cF(5.5)&&window.parent!=window)cG7.cTI=null;else{if(!cGU){for(var i=0;i<cG7.cTI.length;i++){cG7.cTI[i].onload=null;cG7.cTI[i].onerror=null}}}}function CA(force){var dt=new Date();var cx=dt.getTime();if(cm_TrackTime&&(cmT3==-1||force==1||(cx-cmT3)>10000)){cN(cm_ClientTS,cmT2,cx,cGA,false)}cmT3=cx}function CE(){if(cm_UseCookie){var cVF,cVG,pg,cVD,cVE="";cVF=cGA?"&t4="+cGA:"";cVG=(cGJ!="")?"&lti="+cGK+"&ln="+escape(cGI)+"&hr="+escape(cGJ):"";pg=new Object();CU(pg,cm_ClientID);var jsfpdata="";if(cm_JSFEnabled){jsfpdata="&cjen=1"}cVD="&t1="+cm_ClientTS+"&t2="+cmT2+"&t3="+cmT3+cVF+cVG+"&fti="+cGH+"&fn="+escape(cGD)+"&ac="+cGF+"&fd="+escape(cGG)+"&uer="+escape(cm_FormError)+"&fu="+escape(cGE)+"&pi="+escape(pg.pi)+"&ho="+escape(cm_HOST)+"&ci="+escape(cm_ClientID);if(pg.ul&&pg.rf&&pg.ul.length+pg.rf.length<cGO)cVE="&ul="+escape(pg.ul)+"&rf="+escape(pg.rf);if(!CB("cmRS",cVD+cVE+jsfpdata))if(!CB("cmRS",cVD+jsfpdata))CB("cmRS","t3="+cmT3+"&pi="+escape(pg.pi)+jsfpdata)}}function cmSetAvid(id){clearTimeout(cm_AvidLoadTimer);if(id){cm_Avid=id}else{cm_Avid="none"}CB("CMAVID",cm_Avid);cm_AvidLoadTimedOut=false}function cmJSFConvertSAtoCM(value){var len=value.length;var lenSA=22;var lenCM=23;if(len<19)return null;if(value.charAt(0)!="U"&&value.charAt(0)!="u")return null;if(len<lenSA){value=value+value.substring(len-(lenSA-len),len)}var result="99";result=result+value.substring(1,lenCM-1);return result}function cmJSFSetSessionCookies(reset,cVBHs){if(!cm_JSFEnabled)return;var splitClientIDs=cVBHs.split(";");for(var n=0;n<splitClientIDs.length;n++){cmJSFSetSingleSessionCookie(reset,splitClientIDs[n])}}function debugReadCookie(name){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0)return c.substring(nameEQ.length,c.length)}return null}function cmJSFSetSingleSessionCookie(reset,cVBH,noRecurse){if(!cm_JSFEnabled)return;if(cI("CMOptout")?cI("CMOptout").toUpperCase()=="OPT_OUT":false)return;var fpCookieVal=cI(cm_JSFCoreCookieName);if(fpCookieVal==null){if(!cmJSFDoMigrateCookies()){fpCookieVal=cmJSFCreateUserId();if(cm_JSFTrackClients){fpCookieVal+="&ci="+cVBH}CB(cm_JSFCoreCookieName,fpCookieVal,cmCookieExpDate,cm_JSFPCookieDomain)}if(!noRecurse){cmJSFSetSingleSessionCookie(true,cVBH,true)}cmJSFSetValidFlagSingleValue(cmValidFlag_NewSession,false,cVBH);cmJSFSetValidFlagSingleValue(cmValidFlag_NewVisitor,true,cVBH);return}if(cm_JSFTrackClients){var knownClientIds=cJ("ci",fpCookieVal,"&");knownClientIds=knownClientIds&&unescape(knownClientIds);if(knownClientIds&&knownClientIds.indexOf(cVBH)<0){cmSetSubCookie(cm_JSFCoreCookieName,"ci",knownClientIds+","+cVBH,cmCookieExpDate,cm_JSFPCookieDomain);knownClientIds=cI(cm_JSFCoreCookieName,"ci");if(knownClientIds.indexOf(cVBH)>=0){if(!noRecurse){cmJSFSetSingleSessionCookie(true,cVBH,true)}cmJSFSetValidFlagSingleValue(cmValidFlag_NewSession,false,cVBH);cmJSFSetValidFlagSingleValue(cmValidFlag_NewVisitor,true,cVBH);return}}}var sessionCookieExists=(cmJSFGetSessionLoginCookieValue(cVBH)!=null);if(!sessionCookieExists){if(cmJSFCombineSessionCookies(cVBH)){sessionCookieExists=(cmJSFGetSessionLoginCookieValue(cVBH)!=null)}}if(!sessionCookieExists&&!reset){if(!noRecurse){cmJSFSetSingleSessionCookie(true,cVBH,true)}cmJSFSetValidFlagSingleValue(cmValidFlag_NewSession,true,cVBH);return}var dt=new Date();var cmSessionTime=dt.getTime();var cmSessionExpTime=cmSessionTime+cm_JSFSessionTimeout*1000;var isSessionExpired=cmJSFIsSessionExpired(cmJSFGetSessionExpireCookieValue(cVBH));if((reset!=null&&reset==true)||isSessionExpired){var cmTimeoutStr=cmSessionTime.toString();if(cmTimeoutStr.length<10){while(cmTimeoutStr.length<10)cmTimeoutStr="0"+cmTimeoutStr}else cmTimeoutStr=cmTimeoutStr.substring(0,10);cmJSFSetSessionLoginCookieValue(cVBH,cmTimeoutStr);if(isSessionExpired)cmJSFSetValidFlagSingleValue(cmValidFlag_SessionReset,true,cVBH);else cmJSFSetValidFlagSingleValue(cmValidFlag_NewSession,true,cVBH);if(cm_JSFSessionType=="T")cmJSFSetSessionExpiresCookieValue(cVBH,cmSessionExpTime.toString())}if(cm_JSFSessionType=="I")cmJSFSetSessionExpiresCookieValue(cVBH,cmSessionExpTime.toString())}function cmJSFIsSessionExpired(cookieExpValue){if(cookieExpValue==null)return false;var dt=new Date();if(dt.getTime()>cookieExpValue)return true;else return false}function cmJSFCreateUserId(){var currDate=new Date();var rand1=Math.random();if(rand1==0)rand1=Math.random();var rand2=Math.random();if(rand2==0)rand2=Math.random();var userId=rand1.toString().substring(2,4)+rand2.toString().substring(2,12)+currDate.getTime().toString();var len=userId.length;var lenCM=23;if(len<lenCM){userId=userId+userId.substring(len-(lenCM-len),len)}if(len>lenCM){userId=userId.substring(0,lenCM)}return userId}function cmJSFSetValidFlagValue(value,append,cVBHs){if(!cm_JSFEnabled)return;var splitClientIDs=cVBHs.split(";");for(var n=0;n<splitClientIDs.length;n++){cmJSFSetValidFlagSingleValue(value,append,splitClientIDs[n])}}function cmJSFSetValidFlagSingleValue(value,append,cVBH){var validFlag=null;var validFlagValueStr=cmJSFGetSessionValidFlagCookieValue(cVBH);if(validFlagValueStr){var validFlagValue=parseInt(validFlagValueStr);if(!isNaN(validFlagValue))validFlag=validFlagValue}if(validFlag==null)validFlag=cmValidFlag_SessionContinue;if(append){if(value==cmValidFlag_NewSession)validFlag&=~cmValidFlag_SessionReset;if(value==cmValidFlag_SessionReset)validFlag&=~cmValidFlag_NewSession;validFlag|=value}else{validFlag=value}validFlag|=cmValidFlag_SessionContinue;cmJSFSetSessionValidFlagCookieValue(cVBH,validFlag)}function cmJSFCreateCombinedSessionCookieName(cVBH){return cVBH+"_clogin"}function cmJSFCombineSessionCookies(cVBH){var loginValue=cI(cVBH+"_login");var expiresValue=cI(cVBH+"_expires");var validFlagValue=cI(cVBH+"_valid");if(loginValue!=null&&expiresValue!=null&validFlagValue!=null){var combinedCookieStr="l="+loginValue+"&e="+expiresValue+"&v="+validFlagValue;CB(cmJSFCreateCombinedSessionCookieName(cVBH),combinedCookieStr,null,cm_JSFPCookieDomain);CC(cVBH+"_login",cm_JSFPCookieDomain);CC(cVBH+"_expires",cm_JSFPCookieDomain);CC(cVBH+"_valid",cm_JSFPCookieDomain);return true}return false}function cmJSFSetSessionLoginCookieValue(cVBH,value){cmSetSubCookie(cmJSFCreateCombinedSessionCookieName(cVBH),"l",value,null,cm_JSFPCookieDomain)}function cmJSFSetSessionExpiresCookieValue(cVBH,value){cmSetSubCookie(cmJSFCreateCombinedSessionCookieName(cVBH),"e",value,null,cm_JSFPCookieDomain)}function cmJSFSetSessionValidFlagCookieValue(cVBH,value){cmSetSubCookie(cmJSFCreateCombinedSessionCookieName(cVBH),"v",value,null,cm_JSFPCookieDomain)}function cmJSFGetSessionLoginCookieValue(cVBH){return cI(cmJSFCreateCombinedSessionCookieName(cVBH),"l")}function cmJSFGetSessionExpireCookieValue(cVBH){return cI(cmJSFCreateCombinedSessionCookieName(cVBH),"e")}function cmJSFGetSessionValidFlagCookieValue(cVBH){return cI(cmJSFCreateCombinedSessionCookieName(cVBH),"v")}function cmJSFGetSessionValue(cVBHs){var value="";var delimiter="";var splitClientIDs=cVBHs.split(";");for(var n=0;n<splitClientIDs.length;n++){var cVBH=splitClientIDs[n];if(cVBH=="")continue;var currValue=cmJSFGetSessionLoginCookieValue(cVBH);value+=delimiter+(currValue!=null?currValue:"");if(delimiter=="")delimiter="|"}return value}function cmJSFGetValidFlagValue(cVBHs){var value="";var delimiter="";var splitClientIDs=cVBHs.split(";");for(var n=0;n<splitClientIDs.length;n++){var cVBH=splitClientIDs[n];if(cVBH=="")continue;var currValue=cmJSFGetSessionValidFlagCookieValue(cVBH);value+=delimiter+(currValue!=null?currValue:"");if(delimiter=="")delimiter="|"}return value}function cmJSFDoMigrateCookies(){if(cm_JSFMigrationEnabled==cmMigrationFrom1p_SA){if(cI(cm_JSFCoreCookieName)==null){var cmSACookieValue=cI(cmSACookieName);if(cmSACookieValue){cmSACookieValue=cmJSFConvertSAtoCM(cmSACookieValue);if(cmSACookieValue!=null){CB(cm_JSFCoreCookieName,cmSACookieValue,cmCookieExpDate,cm_JSFPCookieDomain);return true}}}}return false}_cm.prototype.addTP=function(){var tp=new cmTP(new cmApp());for(var o in tp){if(tp[o]==null||tp[o]==""||tp[o].toString().indexOf("function ")==0)continue;this[o]=cE(cD(tp[o]))}return this};function cmApp(){var n=navigator,b=n.appName,c=this;if(b=="Netscape"){c.b="ns"}else if(b=="Microsoft Internet Explorer"){c.b="ie"}else{c.b=b}c.v=parseInt(n.appVersion)}function cmTP(c){var n=navigator,w=window.screen;this.jv=cmJv;if(c.b=="ns"&&c.v>=3)for(var i=0;i<n.plugins.length;i++)eval('this.np'+i+'=n.plugins['+i+'].name');if(c.v>3){if(c.v>=4&&(c.b=="ns"||c.b=="ie")){this.je=(n.javaEnabled()==true)?"y":"n"}if(c.b=="ie"){this.ce=n.cookieEnabled;this.cp=n.cpuClass}this.sw=w.width;this.sh=w.height;this.pd=w.colorDepth;if(this.pd==0){this.pd=w.pixelDepth}var fs=w.fontSmoothingEnabled;if(fs){this.fs=fs?"y":"n"}}var tz=new Date();if(tz.getTimezoneOffset()==0){this.tz="0"}else{this.tz=tz.getTimezoneOffset()/60}}function cmJSFPMigrateCookies(visitorID,sessionIDList,otherCookieList){if(visitorID&&sessionIDList&&cm_JSFEnabled&&cm_JSFPCookieMigrate){var tempVisitor=cI(cm_JSFCoreCookieName);if(!tempVisitor||cm_JSFPForceMigrateCookies){CB(cm_JSFCoreCookieName,visitorID+(cm_JSFTrackClients?"&ci="+cm_ClientID.split(";").join(","):""),cmCookieExpDate,cm_JSFPCookieDomain);var dt=new Date();var cmSessionExpTime=(dt.getTime()+cm_JSFSessionTimeout*1000).toString();var cVAArray=cm_ClientID.split(";");for(var i=0;i<cVAArray.length;++i){if(sessionIDList[cVAArray[i]]!==undefined){cmJSFSetSessionLoginCookieValue(cVAArray[i],sessionIDList[cVAArray[i]]);cmJSFSetSessionExpiresCookieValue(cVAArray[i],cmSessionExpTime);cmJSFSetSessionValidFlagCookieValue(cVAArray[i],"1")}}}}if(cm_JSFPCookieMigrate&&cm_JSFPMigrationOtherCookies!==""){var cookieList=cm_JSFPMigrationOtherCookies.split(",");var dt=new Date();dt.setTime(dt.getTime()+(1000*60*60*24*30));for(var j=0;j<cookieList.length;++j){if(otherCookieList[cookieList[j]]!==undefined){var tempExpires=cm_JSFPMigrationOtherCookiesExpireTimes[cookieList[j]];if(tempExpires){var dt=new Date();dt.setTime(dt.getTime()+parseInt(tempExpires));dt=dt.toGMTString()}else{var dt=null}CB(cookieList[j],otherCookieList[cookieList[j]],dt,cm_JSFPCookieDomain)}}}}function cmJSFPMigrateLink(e,type){if(cm_JSFPCookieMigrate){var pageDomain=cm_JSFPCookieDomain;var linkDomainRE=/:\/\/([a-z0-9_\-\.]+)/i;var linkDomain=linkDomainRE.exec(e[type]);if(linkDomain){linkDomain=linkDomain[1]}if(linkDomain&&((linkDomain.indexOf(pageDomain)===-1)&&(e[type].toLowerCase().indexOf("javascript")!==0)&&((cm_JSFPMigrationDomainWhitelist!==""&&cmTextMatchList(linkDomain.toLowerCase(),cm_JSFPMigrationDomainWhitelist.split(",")))||(cm_JSFPMigrationDomainBlacklist!==""&&!(cmTextMatchList(linkDomain.toLowerCase(),cm_JSFPMigrationDomainBlacklist.split(","))))))||(cm_JSFPMigrationPathWhitelist!==""&&cmTextMatchList(e[type].toLowerCase(),cm_JSFPMigrationPathWhitelist.split(",")))){if(cm_JSFEnabled){var tempVisitorID=cI(cm_JSFCoreCookieName);if(tempVisitorID){tempVisitorID=tempVisitorID.split("&",2)[0]}var tempClientIDList=cm_ClientID.split(";");var tempSessionParameters="";for(var i=0;i<tempClientIDList.length;++i){tempSessionParameters+="&"+cm_JSFPCookieMigrateSessionID+"_"+tempClientIDList[i]+"="+cmJSFGetSessionLoginCookieValue(tempClientIDList[i])}e[type]+=(e[type].indexOf("?")>-1?"&":"?")+cm_JSFPCookieMigrateVisitorID+"="+tempVisitorID+tempSessionParameters}if(cm_JSFPMigrationOtherCookies!==""){var cookieList=cm_JSFPMigrationOtherCookies.split(",");var otherCookieParameters="";for(var j=0;j<cookieList.length;++j){var tempCookie=cI(cookieList[j]);if(tempCookie){otherCookieParameters+="&cm_mc_"+cookieList[j]+"="+tempCookie}}otherCookieParameters=(e[type].indexOf("?")>-1?"&":"?")+otherCookieParameters.substring(1);e[type]+=otherCookieParameters}}}}function cmTextMatchList(input,matchArray){for(var i=0;i<matchArray.length;++i){if(input.indexOf(matchArray[i])>-1){return true}}return false}

// cmdatagutils_20100624.js
/*
 * cmdatatagutils.js 
 * $Id: cmdatatagutils.js 138475 2010-02-05 18:49:51Z etowb $
 * $Revision: 138475 $
 *
 * Version 4.2.0
 *
 * Coremetrics Tag v4.0, 8/7/2006
 * COPYRIGHT 1999-2002 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 *
 * The following functions aid in the creation of Coremetrics data tags.
 *
 */
 
var cm_exAttr=new Array();  
var cm_ClientID = "90303130";
var cm_TrackLink = "A";
var cm_TrackImpressions = "RS";
var cm_JSFEnabled = true;
var cmCheckCMEMFlag = true;
var cm_tempHost;
var cm_tempCookieDomain;

var cmJv = "1.0";
if (typeof(isNaN) == "function") { cmJv = "1.1";}
if (typeof(isFinite) == "function") { cmJv = "1.2";}
if (typeof(NaN) == "number") { cmJv = "1.3";}
if (typeof(decodeURI) == "function") { cmJv = "1.5";}
if (typeof(Array.forEach) == "function") { cmJv = "1.6";}
if (typeof(Iterator) == "object") {cmJv = "1.7";}

// IO V4 Configuration
if (typeof(IORequest) == "function") {
   IORequest.client_id           = cm_ClientID;
   IORequest.encrypt_cats        = true;
   IORequest.encrypt_prds        = true; 
   IORequest.conflict_resolution = true;
   IORequest.max_prd_length      = 25;
   IORequest.max_cat_length      = 25;
   IORequest.timeout             = [8000, 4000];
   IORequest.use_site_category   = false;
   if ((IORequest.ie_version() !== null) && (IORequest.ie_version() < 7.0)) {
      IORequest.a_max_elements = [3,3,5,3,3,3,3];
   }
   else {
      IORequest.a_max_elements = [3,3,5,3,3,7,7];
   }
   IORequest.required_attributes  = [0,0,0,0,0];
   IORequest.access_method			= 'json remote';
   IORequest.default_product_file = undefined;
}

/*
	clientID : REQUIRED: client id for particular site
	firstPartyCM : REQUIRED: true for Javascript First Party, false for 3rd party and 1st Party Subdomain
	hostDomain : REQUIRED for 1st PARTY:
			if firstPartyCM=true, set to site domain. 
			if firstPartyCM=false and site uses 1st party subdomain set to first party subdomain
			if firstPartyCM=false and hostDomain=null, automatically set to data.coremetrics.com
			cookieDomain : REQUIRED only for Delegated 1st party w/AdTarget - sets CoreAt in specified domain
*/
function cmSetClientID(clientID,firstPartyCM,hostDomain,cookieDomain){
	if (firstPartyCM==null || !firstPartyCM){
		cm_JSFEnabled=false;
	} else {
		cm_JSFEnabled=firstPartyCM;
	}
	cm_ClientID=clientID; 
	cm_tempHost = hostDomain;
	if ((!hostDomain && firstPartyCM==false) || (!hostDomain && !firstPartyCM)){
		cm_tempHost="data.coremetrics.com";
	}
// IO V4 case
	if (typeof(IORequest) == "function"){
		IORequest.client_id = cm_ClientID;
	}
// AdTarget case
	if (typeof cmLoad == 'function') {
		if (cookieDomain){	// Delegated 1st Party + AdTarget component
			cm_tempCookieDomain=cookieDomain;
		}
		cm_PartnerDataClientIDs = cm_ClientID; 
		if (cm_JSFEnabled==false) {
			cm_Production_HOST = cm_tempHost;
		} else {
			cm_Production_HOST = "data.coremetrics.com";
		}
		cmLoad();
	}
} 

/* TAG GENERATING FUNCTIONS */

/*
 * Calling this function points tags to the production database
 */
function cmSetProduction(){
	if (cm_JSFEnabled==false){
		cm_HOST=cm_tempHost+"/eluminate?";
		if (cm_tempCookieDomain){	// Delegated 1st Party + AdTarget component
			cm_JSFPCookieDomain=cm_tempCookieDomain;
		}	
	} else {
		cm_HOST="data.coremetrics.com/eluminate?";
		cm_JSFPCookieDomain=cm_tempHost;
	}
}

function cmCreateManualImpressionTag(pageID, trackSP, trackRE) {
		// insert code to get pageID from cmTagControl if pageID is null
		cmMakeTag(["tid","9","pi",pageID,"cm_sp",trackSP,"cm_re",trackRE,"st",cm_ClientTS]);
}

function cmCreateManualLinkClickTag(href,name,pageID) {	
	if (cmCreateLinkTag == null && cM != null) {
		var cmCreateLinkTag = cM;
	}
	if (cmCreateLinkTag != null) {		
		var dt = new Date();
		cmLnkT3 = dt.getTime();
		href=cG7.normalizeURL(href,true);
		cmCreateLinkTag(cm_ClientTS, cmLnkT3, name, href, false, pageID);
	}
}

/* manual PageviewTag for off site page tagging.  Allows client to supply URL and Referring URL
*/
function cmCreateManualPageviewTag(pageID, categoryID,DestinationURL,ReferringURL,attributes) {
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"ul",DestinationURL,"rf",ReferringURL,"cm_exAttr",cm_exAttr]);
}

function cmCreateElementTag(elementID, elementCategory, attributes) {
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","15","eid",elementID,"ecat",elementCategory,"cm_exAttr",cm_exAttr]);
}

function cmCreatePageElementTag(elementID, elementCategory, pageID, pageCategoryID, elementLocation,attributes) {
	cmCreateElementTag(elementID,elementCategory,attributes);
}

function cmCreateProductElementTag(elementID, elementCategory, productID, productCategoryID, elementLocation,attributes) {
	cmCreateElementTag(elementID,elementCategory,attributes);
}

/*
 * Creates a Conversion Event tag
 *
 * eventID			: required. Conversion event ID
 * actionType		: required. 1=conversion initiation, 2=conversion completion
 * categoryID		: optional. Category for the event
 * points			: optional. Point value to assign to conversion.
 */
 function cmCreateConversionEventTag(eventID, actionType, categoryID, points,attributes) {
 	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","14","cid",eventID,"cat",actionType,"ccid",categoryID,"cpt",points,"cm_exAttr",cm_exAttr]);
 }

/*
 * Creates a Tech Props tag.
 * pageID		: required. Page ID to set on this Pageview tag
 */
function cmCreateTechPropsTag(pageID, categoryID,attributes) {
	if(pageID == null) { pageID = cmGetDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","6","pi",pageID,"cg",categoryID,"pc","Y","cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Pageview tag with the given Page ID
 *
 * pageID	: required. Page ID to set on this Pageview tag
 * categoryID	: optional. Category ID to set on this Pageview tag
 * searchString	: optional. Internal search string entered by user to reach
 *				  this page.
 * searchResults : optional.  Total numeric search results count.
 * 
 */
function cmCreatePageviewTag(pageID, categoryID, searchString, searchResults,attributes) {
	if (pageID == null) { pageID = cmGetDefaultPageID(); }
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","1","pi",pageID,"cg",categoryID,"se",searchString,"sr",searchResults,"cm_exAttr",cm_exAttr]);
}

/*
 * Creates a Pageview tag with the default value for Page ID. 
 * Format of Page ID is "x/y/z/MyPage.asp"
 *
 * 
 */
function cmCreateDefaultPageviewTag(categoryID) {
	cmCreatePageviewTag(cmGetDefaultPageID(), categoryID);
}

/*
 * Creates a Productview Tag
 * Also creates a Pageview Tag by setting pc="Y"
 * Format of Page ID is "PRODUCT: <Product Name> (<Product ID>)"
 *
 * productID	: required. Product ID to set on this Productview tag
 * productName	: required. Product Name to set on this Productview tag
 * categoryID	: optional. Category ID to set on this Productview tag 
 * searchString	: optional. Internal search string entered by user to reach
 *				  this Product Detail page. Only usable if pc="Y".
 * searchResults : optional.  Total numeric search results count. Only usable
 *				   if pc="Y".
 */
function cmCreateProductviewTag(productID, productName, categoryID, searchString, searchResults, cmvc, attributes) {
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","5","pi","PRODUCT: "+productName+" ("+productID+")","pr",productID,"pm",productName,"cg",categoryID,"se",searchString,"sr",searchResults,"pc","Y","cm_vc",cmvc ? cmvc : cmExtractParameter("cm_vc",document.location.href),"cm_exAttr",cm_exAttr]);
}

/*
 * Variables and Arrays to support Lineitem Aggregation
 */
var __sArray = new Array();
var __skuString = "";
var __ex=new Array();

function __cmGetPIPC(__pr,__cg) {
	var __pI, i;
	var cmAttr1=new Array();
	var cmAttr2=new Array();
	for (i=0;i<__ex.length;++i){
		cmAttr1=cmAttr1+__ex[i];
	}		
	for (__pI = 0; __pI < __sArray.length; ++__pI) {
		if (__ex.length>0){
			cmAttr2=new Array();		
			for (i=__sArray[__pI].length-__ex.length*2+1;i<__sArray[__pI].length;i=i+2){
				cmAttr2=cmAttr2+__sArray[__pI][i];
			}
	
			if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9] && cmAttr1==cmAttr2){
				return __pI;
			}
		} else {
		if (__pr == __sArray[__pI][1] && __cg == __sArray[__pI][9]) return __pI;
	}
	}	
	return -1;
}

function cmAddShop(__v) {

	var __i = __cmGetPIPC(__v[1],__v[9]);
	if (__i == -1) {
		if (__ex.length>0){
			for (var i=0; i<__ex.length; ++i){
				__v[__v.length]="s_a"+(i+1);
				__v[__v.length]=__ex[i];
			}
		}
		__sArray[__sArray.length] = __v;
	}
	else {
		var __oQ = __sArray[__i][5];
		var __oP = __sArray[__i][7];
		__sArray[__i][5] = parseInt(__sArray[__i][5]) + parseInt(__v[5]);
		__sArray[__i][7] = (((__v[7]*__v[5])+(__oP*__oQ))/__sArray[__i][5]);
	}
}

/*
 * Creates a Shop tag with Action 5 (Shopping Cart)
 *
 * productID	: required. Product ID to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * categoryID	: optional. Category to set on this Shop tag
 *
 * 
 */
function cmCreateShopAction5Tag(productID,productName,productQuantity,productPrice,categoryID,attributes) {
	if ((typeof(cm_currencyCode) == "undefined") || (!cm_currencyCode)) {
		cm_currencyCode = "";
	}
	var pattern = /[^\-0-9\.]/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}	
	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"ha1",attributes ? cm_hex_sha1(attributes) : null,"cc",cm_currencyCode,"at","5","tid","4","pc","N"]);
}

/*
 * Creates a Shop tag with Action 9 (Order Receipt / Confirmed)
 *
 * productID	: required. Product ID to set on this Shop tag
 * productName	: required. Product Name to set on this Shop tag
 * quantity	: required. Quantity to set on this Shop tag
 * productPrice	: required. Price of one unit of this product
 * customerID	: required. ID of customer making the purchase
 * orderID	: required. ID of order this lineitem belongs to
 * orderTotal	: required. Total price of order this lineitem belongs to
 * categoryID	: optional. Category to set on this Shop tag
 *
 */
function cmCreateShopAction9Tag(productID,productName,productQuantity,productPrice,customerID,orderID,orderTotal,categoryID,attributes) {
	if ((typeof(cm_currencyCode) == "undefined") || (!cm_currencyCode)) {
		cm_currencyCode = "";
	}
	var pattern = /[^\-0-9\.]/gi;
	var pattern1 = /^\s+|\s+$/gi;
    productPrice = productPrice.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	productID = productID.toString().replace(pattern1, "");
	if (attributes){
		__ex=attributes.split("-_-");
	} else {
	__ex=new Array();
	}
	cmAddShop(["pr",productID,"pm",productName,"qt",productQuantity,"bp",productPrice,"cg",categoryID,"ha1",attributes ? cm_hex_sha1(attributes) : null,"cd",customerID,"on",orderID,"tr",orderTotal,"cc",cm_currencyCode,"at","9","tid","4","pc","N"]);
	cmCalcSKUString();
}

function cmDisplayShop5s() {
	cmDisplayShops();
}

function cmDisplayShop9s() {
	cmCalcSKUString();
	cmDisplayShops();
}

function cmCalcSKUString() {
	__skuString = "";
	var __skuStringArray = new Array();
	for (var i = 0; i < __sArray.length; ++i) {
		// aggregate
		var __skuStringArrayIndex = -1;
		for (var y = 0; y < __skuStringArray.length; ++y) {
			if (__sArray[i][1] == __skuStringArray[y][0] ) {
				__skuStringArrayIndex = y;
			}
		}
		if (__skuStringArrayIndex == -1) {
			// it doesn't exist, so add it
			var newArrayIndex = __skuStringArray.length;
			__skuStringArray[newArrayIndex] = new Array();
			__skuStringArray[newArrayIndex][0] = __sArray[i][1];
			__skuStringArray[newArrayIndex][1] = __sArray[i][7];
			__skuStringArray[newArrayIndex][2] = __sArray[i][5];
		}
		else {
			// it exists, so update it
			var __oP = __skuStringArray[__skuStringArrayIndex][1];
			var __oQ = __skuStringArray[__skuStringArrayIndex][2];
			__skuStringArray[__skuStringArrayIndex][2] = parseInt(__sArray[i][5]) + __oQ;
			__skuStringArray[__skuStringArrayIndex][1] = (__oP*__oQ+__sArray[i][7]*__sArray[i][5])/(parseInt(__sArray[i][5])+parseInt(__oQ));
		}
	}
	for (var x = 0; x < __skuStringArray.length; ++x) {
		__skuString += "|"+__skuStringArray[x][0]+"|"+__skuStringArray[x][1]+"|"+__skuStringArray[x][2]+"|";
	}
}

function cmDisplayShops() {
	var i;
	for (i = 0; i < __sArray.length; ++i) {
		cmMakeTag(__sArray[i]);
	}
	__sArray = new Array();
}


/*
 * Creates an Order tag
 *
 * orderID			: required. Order ID of this order
 * orderTotal		: required. Total of this order (minus tax and shipping)
 * orderShipping	: required. Shipping charge for this order
 * customerID		: required. Customer ID that placed this order
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 *
 */
function cmCreateOrderTag(orderID,orderTotal,orderShipping,customerID,customerCity,customerState,customerZIP,attributes) {
	if ((typeof(cm_currencyCode) == "undefined") || (!cm_currencyCode)) {
		cm_currencyCode = "";
	}
	var pattern = /[^\-0-9\.]/gi;
    orderShipping = orderShipping.toString().replace(pattern, "");
	orderTotal = orderTotal.toString().replace(pattern, "");
	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}	
	cmMakeTag(["tid","3","osk",__skuString,"on",orderID,"tr",orderTotal,"sg",orderShipping,"cd",customerID,"ct",customerCity,"sa",customerState,"zp",customerZIP,"cc",cm_currencyCode,"cm_exAttr",cm_exAttr]);
	__skuString = "";
}

/*
 * Creates a Registration tag and/or a Newsletter tag
 *
 * customerID		: required for Registration. ID of Customer to register.
 * customerEmail	: required for Newsletters. Optional for Registration.
 * customerCity		: optional. City of Customer that placed this order
 * customerState	: optional. State of Customer that placed this order
 * customerZIP		: optional. Zipcode of Customer that placed this order
 * newsletterName	: required for Newsletters. The name of the Newsletter.
 * subscribe		: required for Newsletters. Either "Y" or "N"
 *
 */
function cmCreateRegistrationTag(customerID, customerEmail, customerCity,
				customerState, customerZIP, customerCountry, attributes) {
 	if (attributes){
		var cm_exAttr=new Array();
		cm_exAttr=attributes.split("-_-");
	}
	cmMakeTag(["tid","2","cd",customerID,"em",customerEmail,"ct",customerCity,"sa",customerState,"zp",customerZIP,"cy",customerCountry,"cm_exAttr",cm_exAttr]);
}

/* Creates an Error Tag
 *
 */
function cmCreateErrorTag(pageID, categoryID) {
	if(pageID == null) {
		pageID = cmGetDefaultPageID();
	}
	cmMakeTag(["tid","404","pi",pageID,"cg",categoryID,"pc","Y"]);
}

function cmMakeTag(__v) {
	var cm = new _cm("vn2", "e4.0");
	var i;
	for (i = 0; i < __v.length; i += 2) {
		var _n = __v[i];
		var _v = __v[i + 1];
		cm[_n] = _v;
	}
	
	var datestamp = new Date();	
	var stamp = (Math.floor(Math.random() * 11111111)) + datestamp.valueOf();	
	cm.rnd = stamp;
	
	if (cm.tid == "6") {
		cm.addTP();
		document.cookie = "cmTPSet=Y; path=/";
	}

	if (cm.tid == "1") {
		if (cI("cmTPSet") != 'Y') {
			cm.tid = "6";
			cm.pc = "Y";
			cm.addTP();
			document.cookie = "cmTPSet=Y; path=/";
		}
	}

	if (cm.tid != "4" && typeof(cm.cm_exAttr)!="undefined"){
		switch(cm.tid){
			case "6":
				prefix="pv";
				break;
			case "1":
				prefix="pv";
				break;
			case "2":
				prefix="rg";
				break;
			case "5":
				prefix="pr";
				break;
			case "3":
				prefix="o";
				break;
			case "14":
				prefix="c";
				break;
			case "15":
				prefix="e";
				break;
			default:
				break;
		}		
		var attrNum=cm.cm_exAttr.length;
		if (attrNum>15){
			attrNum=15;
		}
		for (i=0;i<attrNum;i++){
			if (cm.tid=="2"){
				Attval=prefix+(i+1);
			} else {
				Attval=prefix+"_a"+(i+1);
			}
			cm[Attval]=cm.cm_exAttr[i];
		}
		cm.cm_exAttr=null;
	}	
	if ((cm.pi == null) && (cm.pc == "Y")) {
		cm.pi = cmGetDefaultPageID();
	}

	try{
		if (parent.cm_ref != null) {
			cm.rf = parent.cm_ref;
			if (cm.pc == "Y") {
				parent.cm_ref = document.URL;
			}
		}
	
		// if parent had mmc variables and this is the first pageview, add mmc to this url
		if(parent.cm_set_mmc) {
			cm.ul = document.location.href + 
					((document.location.href.indexOf("?") < 0) ? "?" : "&") + 
					parent.cm_mmc_params; 
			if (cm.pc == "Y") {
				parent.cm_ref = cm.ul;
				parent.cm_set_mmc = false;
			}
		}
	}
	catch(err){}

	if (cm.ul == null) {
		cm.ul = window.location.href;
	}

	//check for zero price and zero quantity
	cmSafeZero(cm,["qt","bp","tr","sg"]);

	//check for manual_cm_mmc parameter;
	if (this.manual_cm_mmc != null) {
		cm.ul = cm.ul + ((cm.ul.indexOf("&") == -1) ? ((cm.ul.indexOf("?") == -1) ? "?" : "&") : "&") + "cm_mmc=" + this.manual_cm_mmc;
	}

	// convert MMC parameters to lowercase;
	cm.ul = cm.ul.replace(/cm_mmc/gi,"cm_mmc");
	cm.ul = cm.ul.replace(/cm_ven/gi,"cm_ven");
	cm.ul = cm.ul.replace(/cm_cat/gi,"cm_cat");
	cm.ul = cm.ul.replace(/cm_pla/gi,"cm_pla");
	cm.ul = cm.ul.replace(/cm_ite/gi,"cm_ite");
	if (cmCheckCMEMFlag){cmStartTagSet();}
    cm.writeImg();
	if (cmCheckCMEMFlag) {
		cmCheckCMEMFlag = false;	
		cmCheckCMEM();
		cmSendTagSet();		
	}
// IO V4 call
	if (typeof cm_ted_io == 'function') {
		cm_ted_io(cm);
	}
}

// HELPER FUNCTIONS -----------------------------------------------------------
/* These functions are used by the tag-generating functions and/or may be used
 * in in general as convenience functions
 */

/*
 * Creates an acceptable default Page ID value to use for Pageview tags.
 * The default Page ID is based on the URL, and consists of the path and
 * filename (without the protocol, domain and query string).
 * 
 * example:
 * returns "x/y/MyPage.asp" for the URL http://www.mysite.com/x/y/MyPage.asp
 */
function cmGetDefaultPageID() { 
	var pageName = window.location.pathname; 

	// eliminates everything after "?" (for Opera browswers)
	var tempIndex1 = pageName.indexOf("?");
	if (tempIndex1 != -1) {
		pageName = pageName.substr(0, tempIndex1);
	}
	// eliminates everything after "#" (for Opera browswers)
	var tempIndex2 = pageName.indexOf("#");
	if (tempIndex2 != -1) {
		pageName = pageName.substr(0, tempIndex2);
	}
	// eliminates everything after ";"
	var tempIndex3 = pageName.indexOf(";");
	if (tempIndex3 != -1) {
		pageName = pageName.substr(0, tempIndex3);
	}

	var slashPos = pageName.lastIndexOf("/");
	if (slashPos == pageName.length - 1) {
		pageName = pageName + "default.asp"; /****************** SET TO DEFAULT DOC NAME */
	}

	while (pageName.indexOf("/") == 0) {
		pageName = pageName.substr(1,pageName.length);
	}

	return(pageName); 
} 

function cmIndexOfParameter (parameter, inString) {
	return inString.indexOf(parameter);
}

function cmExtractParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return null;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	var middle = s.indexOf("=", begin);
	return s.substring(middle + 1, end).split("#",1).join("");
}

function cmRemoveParameter (parameter, inString) {
    if (cmIndexOfParameter(parameter, inString) == -1) {
        return inString;
    }
	var s = inString;
	var begin = s.indexOf(parameter);
	var start = (begin - 1);
	var end = s.indexOf("&", begin);
	if (end == -1) {
		end = s.length;
	}
	if (s.substring(start, begin) == "?") {    // retain leading "?"
		start = (start + 1);
		end = (end + 1);
	}
	return s.substring(0, start) + s.substring(end, s.length);
}

function cmCheckCMEM() {
	if (cmIndexOfParameter("cm_em",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_em",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
	if (cmIndexOfParameter("cm_lm",document.location.href) != -1){
		var emailAddress = cmExtractParameter("cm_lm",document.location.href);
		if (emailAddress.indexOf(":")>-1){
			emailAddress=emailAddress.substring(emailAddress.indexOf(":")+1);
		}		
		cmCreateRegistrationTag(emailAddress,emailAddress);
	}
}

function cmSafeZero(cm, checkArray) {
	// put logic here to convert number 0 to string "0"
	for (var i = 0; i < checkArray.length; ++i) {
		if ((cm[checkArray[i]] != null) && (cm[checkArray[i]] == 0)) {
			cm[checkArray[i]] = "0";
		}
	}
}

if (defaultNormalize == null) { var defaultNormalize = null; }

function myNormalizeURL(url, isHref) {
    var newURL = url;
    // ... transform newURL here ...
    if (defaultNormalize != null) {
        newURL = defaultNormalize(newURL, isHref);
    }
    return newURL;
}

// install normalization
if (document.cmTagCtl != null) {
    var func = "" + document.cmTagCtl.normalizeURL;
    if (func.indexOf('myNormalizeURL') == -1) {
        defaultNormalize = document.cmTagCtl.normalizeURL;
        document.cmTagCtl.normalizeURL = myNormalizeURL;
    }
}

function cmSetCurrencyCode(currencyCode) {
	cm_currencyCode = currencyCode;
}

/*  hash functions that support shop aggregation with attributes */
function cm_hex_sha1(s)    { return cm_rstr2hex(cm_rstr_sha1(cm_str2rstr_utf8(s))); }

function cm_rstr_sha1(s)
{
  return cm_binb2rstr(cm_binb_sha1(cm_rstr2binb(s), s.length * 8));
}

function cm_rstr2hex(input)
{
  var hex_tab = 0 ? "0123456789ABCDEF" : "0123456789abcdef";
  var output = "";
  var x;
  for(var i = 0; i < input.length; i++)
  {
    x = input.charCodeAt(i);
    output += hex_tab.charAt((x >>> 4) & 0x0F)
           +  hex_tab.charAt( x        & 0x0F);
  }
  return output;
}

function cm_str2rstr_utf8(input)
{
  var output = "";
  var i = -1;
  var x, y;

  while(++i < input.length)
  {
    /* Decode utf-16 surrogate pairs */
    x = input.charCodeAt(i);
    y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
    if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF)
    {
      x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
      i++;
    }

    /* Encode output as utf-8 */
    if(x <= 0x7F)
      output += String.fromCharCode(x);
    else if(x <= 0x7FF)
      output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0xFFFF)
      output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
    else if(x <= 0x1FFFFF)
      output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07),
                                    0x80 | ((x >>> 12) & 0x3F),
                                    0x80 | ((x >>> 6 ) & 0x3F),
                                    0x80 | ( x         & 0x3F));
  }
  return output;
}

function cm_rstr2binb(input)
{
  var output = Array(input.length >> 2);
  for(var i = 0; i < output.length; i++)
    output[i] = 0;
  for(var i = 0; i < input.length * 8; i += 8)
    output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (24 - i % 32);
  return output;
}

function cm_binb2rstr(input)
{
  var output = "";
  for(var i = 0; i < input.length * 32; i += 8)
    output += String.fromCharCode((input[i>>5] >>> (24 - i % 32)) & 0xFF);
  return output;
}

function cm_binb_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);
  x[((len + 64 >> 9) << 4) + 15] = len;

  var w = Array(80);
  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;
  var e = -1009589776;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;
    var olde = e;

    for(var j = 0; j < 80; j++)
    {
      if(j < 16) w[j] = x[i + j];
      else w[j] = cm_bit_rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
      var t = cm_safe_add(cm_safe_add(cm_bit_rol(a, 5), cm_sha1_ft(j, b, c, d)),
                       cm_safe_add(cm_safe_add(e, w[j]), cm_sha1_kt(j)));
      e = d;
      d = c;
      c = cm_bit_rol(b, 30);
      b = a;
      a = t;
    }

    a = cm_safe_add(a, olda);
    b = cm_safe_add(b, oldb);
    c = cm_safe_add(c, oldc);
    d = cm_safe_add(d, oldd);
    e = cm_safe_add(e, olde);
  }
  return Array(a, b, c, d, e);

}

function cm_sha1_ft(t, b, c, d)
{
  if(t < 20) return (b & c) | ((~b) & d);
  if(t < 40) return b ^ c ^ d;
  if(t < 60) return (b & c) | (b & d) | (c & d);
  return b ^ c ^ d;
}

function cm_sha1_kt(t)
{
  return (t < 20) ?  1518500249 : (t < 40) ?  1859775393 :
         (t < 60) ? -1894007588 : -899497514;
}

function cm_safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

function cm_bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

// cmtaggingservices_20100728.js
/************************************************************************************/
/* 
 *
 * Author: Coremetrics/PSD 
 * Coremetrics  v1.3, 2010/03/23
 * COPYRIGHT 1999-2008 COREMETRICS, INC. 
 * ALL RIGHTS RESERVED. U.S.PATENT PENDING
 * Disclaimer: Coremetrics is not responsible for hosting or maintenance or this file
 *
 * 05/28/2010     Hutch White     Modified code to remove shop 9 and order tags
 * 07/29/2010	Hutch White	Modified code to use categoryId argument from document.referral query string as category id for product view pages
 *
 */
/************************************************************************************/
//Production data warehouse flag
cmSetClientID("90303130",true,"midwayusa.com");
cmSetProduction();
/*===========================GLOBAL VARIABLES ===============================*/
// options for debug mode when sending tag:
// 1: only alert
// 2: only send tag
// 3: alert & send tag
var G_PS_DEBUG_MODE = 2;

var G_PS_ARR_DOMAIN = new Array("midwayusa.com");//value must be one array of domains or null

// current page url
var G_PS_URL_PATH = "" + document.location.href.toLowerCase();
var G_PS_PATHNAME = document.location.pathname.toLowerCase();
var G_PS_QUERYSTRING = document.location.search.toLowerCase();
var G_PS_URL_REFERRER = document.referrer.toLowerCase();
var G_PS_COOKIE_LIFETIME = 432000; // 5*24*60*60 = 5 days
// cookie name
var G_PS_COOKIE_CATID = "PS_CATID";
var G_PS_COOKIE_PROD_CATID = "PS_PROD_CATID";
var G_PS_COOKIE_PROFILE = "PS_PROFILE";
var G_PS_COOKIE_FLAG = "PS_FLAG";		// used as a "session" variable to handle events between pages
// current category ID while browsing/searching/refining, etc
var G_PS_COOKIE_ORDER = "PS_ORDER";
var G_PS_COOKIE_STATUS = "PS_STATUS";
/*========================= END GLOBAL VARIABLES =============================*/

/*=========================== BEGIN NAVIGATION ===============================*/
if(G_PS_URL_PATH.search(/midwayusa\.com/i) >= 0){
	var INTERVAL_ID_Arr = new Array();
	INTERVAL_ID_Arr.push(window.setInterval("psHijackFromClearance()", 1000));
	if (psIsSearchView())
	{
		INTERVAL_ID_Arr.push(window.setInterval("psPostSearchView('null')", 1000));
		psHijackSearchFrm();	
		psHijackSearchFrmLeft();	
	}
	else if(psIsProductView())
	{
		psPostProductView();
	}
	else if(psIsCartView())
	{
		psHijackQuickAdd();
		psCreatePageviewTag("CARTVIEW", "CART", null, null, null);
		psPostCartView();
		psHijackCheckout();
		psHijackFromShopping();
	}
	else if(psIsOrderView())
	{
		psPostOrderView();
	}
	else if(G_PS_URL_PATH.search(/ereminder\.exe\/notification/i) >= 0){
		psCreatePageviewTag("Reminder", "Notification", null, null, null);
		psHijackSignInEmail();
		INTERVAL_ID_Arr.push(window.setInterval("psPostSignInEmail()", 3000));
	}
	else if(G_PS_URL_PATH.search(/gunsmithlocator/i) >= 0){
		if(G_PS_PATHNAME.search(/\/Home\.asp/i) >= 0){
			psCreatePageviewTag("Gunsmithlocator Home", "Gunsmithlocator", null, null, null);
		}
		else{
			var pageId = document.getElementById("ctl00_MainContentRight_lblGunsmithCompany");
			if(psCheckElementExist(pageId)){
				pageId = pageId.innerHTML;
				pageId = psTrim(psHtmlDecode(unescape(pageId)));
				psCreatePageviewTag(pageId, "Gunsmithlocator", null, null, null);
			}
			else{
				var pList = document.getElementById("glBrowseCategoryList");
				if(psCheckElementExist(pList)){
					INTERVAL_ID_Arr.push(window.setInterval("Pspageview()", 1000));
				}
			}
		}
	}
	else if(G_PS_URL_PATH.search(/\/staticpages/i) >= 0){
		var pageId = G_PS_URL_PATH.split(/\//gi);
		var catId  = pageId[pageId.length -2].replace(/\_/gi, " ");
		pageId = pageId[pageId.length -1].replace(/\.htm/gi, "");
		pageId = pageId.replace(/\_/gi, " ");
		psCreatePageviewTag(pageId, catId, null, null, null);
	}
	else 
	{	
		psPostPageViewTag();
	}
	psHijackRegistrations();
	psPostRegistrationTags();
	if(psDetectFeaturedProduct()){
		psHijackFeaturedProduct();
	}
}

function Pspageview(){
	var pList = document.getElementById("glBrowseCategoryList");
	if(psCheckElementExist(pList)){
		pList = pList.getElementsByTagName("a");
		if(psCheckArrayExist(pList)){
			for(var i=0; i< pList.length; i++){
				if(pList[i].getAttribute("style")!= null && pList[i].getAttribute("style")!= ""
				&& pList[i].getAttribute("style").search(/rgb/i) >= 0){
					psCreatePageviewTag(pList[i].innerHTML, "Gunsmithlocator", null, null, null);
					break;
				}
			}
		}
	}
	psClearInterval(INTERVAL_ID_Arr);
}

function psIsSearchView()
{
	return (G_PS_URL_PATH.search(/\/search\//i) >= 0 && G_PS_URL_PATH.search("_-_") >= 0);
}

function psIsProductView()
{
	
	return (G_PS_URL_PATH.search(/\/viewproduct\//i) >= 0);
}

function psIsCartView()
{
	return (G_PS_PATHNAME.search(/eshoppingcart\.exe\/EmptyCart/i) >= 0 		 
		 || G_PS_PATHNAME.search(/eshoppingcart\.exe\/quickcat/i) >= 0 
		 || G_PS_PATHNAME.search(/eshoppingcart\.exe\/viewcart/i) >= 0  
	     || G_PS_PATHNAME.search(/eshoppingcart\.exe\/DeleteItem/i) >= 0
	     || G_PS_PATHNAME.search(/eshoppingcart\.exe\/AddPromoCode/i) >= 0
	     || G_PS_PATHNAME.search(/eshoppingcart\.exe\/MoveToWishList/i) >= 0
		 || G_PS_PATHNAME.search(/eshoppingcart\.exe\/updatecart/i) >= 0) ;
}

function psIsOrderView()
{
	return G_PS_PATHNAME == "/echeckout.exe/thanks";
}
/*============================ END NAVIGATION ================================*/


/*===================== BEGIN TAGGING BUSSINESS LOGIC ========================*/
function psHijackSignInEmail(){
	var pForm  = psGetElementByName("form", "SIGNINFORM");
	if(psCheckElementExist(pForm)){
		pForm.Oldf = pForm.onsubmit;
		pForm.onsubmit = function(){
			var pEmail = psGetElementByName("input", "custemail");
			var uP = new psProfile();
			uP.cusId = uP.email = psTrim(pEmail.value);
			uP.writeProfile();
			psSetCookie(G_PS_COOKIE_FLAG, "SIGNINEMAIL");
			if(this.Oldf != null){
				return this.Oldf();
			}
		}
	}
}

function psPostSignInEmail(){
	if(psGetCookie(G_PS_COOKIE_FLAG)!= null && psGetCookie(G_PS_COOKIE_FLAG).toUpperCase() == "SIGNINEMAIL"){
		var pContent = document. getElementsByTagName("table")[0];
		if(psCheckElementExist(pContent)){
			if(pContent.innerHTML.search("Send notification to") >=0){
				var uP = new psProfile();
				uP.readProfile();
				psCreateRegistrationTag(uP.cusId, uP.email, uP.city, uP.state, uP.zipcode, uP.newsletter, uP.subscribe);
				psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
				psClearInterval(INTERVAL_ID_Arr);
			}	
		}
	}
}

function psHijackFromClearance(){
	var pClear = document.getElementById("clearancesub");
	if(psCheckElementExist(pClear)){
		var ProBox = pClear.getElementsByTagName("li");
		if(psCheckArrayExist(ProBox)){
			for(var i=0; i<ProBox.length; i++){
				var Atag = ProBox[i].getElementsByTagName("a");
				if(psCheckArrayExist(Atag)){
					for(var j=0; j<Atag.length; j++){
						if(Atag[j].href!= null && Atag[j].href.search(/viewproduct\//gi) >= 0){
							if(psCheckElementExist(Atag[j].onclick) == false || 
Atag[j].onclick.toString().indexOf("HijackView") <0){
								Atag[j].Oldf = Atag[j].onclick;
								Atag[j].onclick = function HijackView(){ 
									psSetCookie(G_PS_COOKIE_CATID, "clearance");
									if(this.Oldf != null){
										return this.Oldf();
									}
								}
							}
						}
						if(Atag[j].href!= null && Atag[j].href.search(/eshoppingcart\.exe\/quickcat/gi) >= 0){
							if(psCheckElementExist(Atag[j].onclick) == false || 
Atag[j].onclick.toString().indexOf("HijackAdd") <0){
								Atag[j].Oldf = Atag[j].onclick;
								Atag[j].onclick = function HijackAdd(){
									var pValue = psGetValueFromUrl(this.href, "SaleItemID");
									psSetValueToCookie(G_PS_COOKIE_PROD_CATID, pValue, "clearance");
									if(this.Oldf != null){
										return this.Oldf();
									}
								}
							}
						}
						if(Atag[j].href!= null && Atag[j].href.search(/productreviews/gi) >= 0){
							if(psCheckElementExist(Atag[j].onclick) == false || 
Atag[j].onclick.toString().indexOf("SendPageView") <0){
								Atag[j].Oldf = Atag[j].onclick;
								Atag[j].onclick = function SendPageView(){
									psCreatePageviewTag("Product Reviews", "Review", null, null, null);
									if(this.Oldf != null){
										return this.Oldf();
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function psHijackFromShopping(){
	var pCross = document.getElementById("crossSell");
	if(psCheckElementExist(pCross)){
		var pTable = pCross.getElementsByTagName("table")[0];
		if(psCheckElementExist(pTable)){
			pTable = pCross.getElementsByTagName("table")[0];
			if(psCheckElementExist(pTable)){
				var pTr = pTable.getElementsByTagName("tr");
				if(psCheckArrayExist(pTr)){
					for(var i=0; i< pTr.length; i++){
						var Atag = pTr[i].getElementsByTagName("a");
						if(psCheckArrayExist(Atag)){
							for(var j=0; j<Atag.length; j++){
								if(Atag[j].href!= null && Atag[j].href.search(/\/viewProduct\//i) >= 0){
									if(Atag[j].onclick == null || 
Atag[j].onclick.toString().indexOf("HijackViewFromShop") < 0){
										Atag[j].Oldf = Atag[j].onclick;
										Atag[j].onclick = function HijackViewFromShop(){
											psSetCookie(G_PS_COOKIE_CATID, "suggests");
											if(this.Oldf != null){
												return this.Oldf();
											}
										}
									}
								}
								if(Atag[j].href!= null && Atag[j].href.search(/eshoppingcart\.exe\/quickcat/gi) >= 
0){
									if(Atag[j].onclick == null || 
Atag[j].onclick.toString().indexOf("HijackAddFromShop") < 0){
										Atag[j].Oldf = Atag[j].onclick;
										Atag[j].onclick = function HijackAddFromShop(){
											var pValue = psGetValueFromUrl(this.href, "SaleItemID");
											psSetValueToCookie(G_PS_COOKIE_PROD_CATID, pValue, 
"suggests");
											if(this.Oldf != null){
												return this.Oldf();
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function psHijackSearchFrm()
{
	var frmItem = document.getElementById("search");
	if(psCheckElementExist(frmItem))
	{
		frmItem.oldCMF = frmItem.onsubmit;
		frmItem.onsubmit = function()
		{
			var searchTerm = psGetElementValueById("search_keywords",true);
			INTERVAL_ID_Arr.push(window.setInterval("psPostSearchView('" + searchTerm + "')", 1000));
			if(psCheckElementExist(this.oldCMF))
			{
				return this.oldCMF();
			}
		}
	}
}

function psHijackSearchFrmLeft()
{
	var pSec = document.getElementById("section01");
	if(psCheckElementExist(pSec)){
		var frmItem = psGetElementsByClassName(pSec, "button", "smallgraybut")[0];
		if(psCheckElementExist(frmItem)){
			frmItem.oldCMF = frmItem.onclick;
			frmItem.onclick = function()
			{
				var sTerm = psGetElementValueById("keyword",true);
				INTERVAL_ID_Arr.push(window.setInterval("psPostSearchView('" + sTerm + "')", 1000));
				if(psCheckElementExist(this.oldCMF))
				{
					return this.oldCMF();
				}
			}
		}
	}
}

function psDetectFeaturedProduct(){
	return psCheckElementExist(document.getElementById("main_image"));
}

function psHijackFeaturedProduct(){
	var Atags = document.getElementById("main_image").getElementsByTagName("a")[0];
	if(psCheckElementExist(Atags)){
		Atags.Oldf = Atags.onclick;
		Atags.onclick = function HijackFeaturedProduct(){
			psSetCookie(G_PS_COOKIE_CATID, "Featured Products");
			if(this.Oldf != null){
				return this.Oldf();
			}
		}
	}
}

function psPostSearchView(searchTerm)
{
	if(searchTerm == "null")
	{
		searchTerm = psGetSearchTerm();
	}
	if(psCheckElementExist(document.getElementById("tell_us")))
	{
		psClearInterval(INTERVAL_ID_Arr);
		psCreatePageviewTag("SEACH UNSUCCESSFULL", "Search", searchTerm, 0, null);
	}
	else if(psCheckElementExist(document.getElementById("section02"))
			&& (document.getElementById("section02").innerHTML.search(/A\s+Keyword\s+is\s+required/i) >= 0))
	{
		psClearInterval(INTERVAL_ID_Arr);
		psCreatePageviewTag("SEACH UNSUCCESSFULL", "Search", searchTerm, 0, null);
	}
	else if(psCheckArrayExist(psGetElementsByClassName(document, "div", "pagination")))
	{
		psClearInterval(INTERVAL_ID_Arr);
		psCreatePageviewTag("SEACH SUCCESSFULL", "Search", searchTerm, 1, null);
		window.setInterval("psHijackAddToCartFromBrow()", 1000);
	}
	psSetCookie(G_PS_COOKIE_CATID, "Search");
}

function psGetSearchTerm()
{
	var term = "";
	term = G_PS_URL_PATH.split(/search\//gi);
	term = term[term.length -1];
	term = term.split(/\___/i)[0];
	term = psTrim(psHtmlDecode(unescape(term.replace(/^\#/i,""))));
	return term;
}

function psClearInterval(pIds)
{
    for (var i=0; i<pIds.length; i++)
    {
        window.clearInterval(pIds[i]);
    }
    pIds = new Array();
}

function psPostProductView()
{
	var prd = new psProduct();
	prd.getProduct();{ // Get product info successfully?
		psCreateProductviewTag(prd.id, prd.name, prd.catId ,prd.attribute);
		psHijackAddToCartFromProductView(prd.id, prd.catId);
		psHijackViewFromProductView("suggestedScroller", "Suggest Products");
		psHijackViewFromProductView("substituteScroller", "Substitute Products");
		psHijackViewFromProductView("othersBoughtScroller", "Others Bought");
	}
}

function psPostCartView()
{
	var cartTbl = document.getElementById("prodList");
	if (cartTbl == null)
		return;

	var rows = cartTbl.rows; // use rows variable for optimization
	var prd = new psProduct();
	var psStatus = "";
	for (var r = 0; r < rows.length; r++) // item for each row
	{
		if (rows[r].innerHTML.search(/Product #:/gi)<0)
			continue;

		if (prd.getItem5(rows[r]) && prd.quantity > 0){
			psCreateShopAction5Tag(prd.id, prd.name, prd.quantity, prd.price, prd.catId, prd.attribute);
			psStatus += "<-->" + prd.attribute;
		}
	}
	psSetCookie(G_PS_COOKIE_STATUS, psStatus);
	psDisplayShop5s();
}

function psHijackCheckout(){
	var checkoutLinks = document.getElementsByTagName("a");
	for (var i = 0; i < checkoutLinks.length; i++)
	{
		if (checkoutLinks[i].href.toUpperCase().indexOf("SUBMITFORCHECKOUT(THIS)")>=0)
		{
			checkoutLinks[i].oldFunc = checkoutLinks[i].onclick;
			checkoutLinks[i].onclick = function ()
			{
				psPostCartView();
				if (this.oldFunc){
					return this.oldFunc();
				}
			}
		}
	}
}

function psPostOrderView()
{
	psCreatePageviewTag("THANK YOU", "CHECKOUT", null, null, null);

	/*
	var tables = document.getElementsByTagName("table");
	if (tables.length < 10)
		return;

	var rows = tables[9].rows; // table containing product

	var ord = new psOrder();
	if (ord.getOrder())
	{
		var uP = new psProfile();
		if (uP.cusID==null){
			var tmp = document.body.innerHTML.toUpperCase().split("CUSTOMER #:")[1]; 
			if (tmp)
			{
				tmp = tmp.split("<BR>")[0];
				tmp=tmp.substring(0,tmp.length-7);
				uP.cusId = psTrim(tmp.substring(tmp.lastIndexOf(">") + 1)); 
			}
		}
		//if (uP.readProfile()) // Get billing email from HTML source 
		{
			var prd = new psProduct();
			psCreateRegistrationTag(uP.cusId, uP.email, uP.city, uP.state, uP.zipcode, null, null);
			psSetCookie(G_PS_COOKIE_PROD_CATID, "", "delete");
			psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
			psSetCookie(G_PS_COOKIE_STATUS, "", "delete");
		}
	}
	*/
}

function psSignInSuccessfully()
{
	return (document.body.innerHTML.toUpperCase().indexOf("WE WERE UNABLE TO SIGN YOU IN") < 0);
}

function psPostRegistrationTags()
{
	var flag = psGetCookie(G_PS_COOKIE_FLAG);
	flag = (flag != null ? flag.toUpperCase() : "");
	if ((flag == "LOGIN" && (G_PS_PATHNAME == "/echeckout.exe/freecatalogs" || G_PS_PATHNAME == "/eshoppingcart.exe/movetowishlist"))
	|| (flag == "UPDATEPROFILE" && (G_PS_PATHNAME == "/eaddressbook.exe/saveeditaddress" || G_PS_PATHNAME == "/echeckout.exe/getaddresses"))
	|| (flag == "CHANGEEMAIL")
	|| (flag == "SIGN-IN" && G_PS_PATHNAME == "/eaccount.exe/signin" && psSignInSuccessfully())
	|| (flag == "SIGN-UP" && (G_PS_PATHNAME == "/eaccount.exe/signin" ||G_PS_PATHNAME == "/eregister.exe/createaccount"))
	|| (flag == "ADDADDRESS" && G_PS_PATHNAME == "/eaddressbook.exe/savenewaddress")
	|| (flag == "ADDEMAIL"))
	{
		var uP = new psProfile();
		if (uP.readProfile()) // get user profile from cookie
		{
			psCreateRegistrationTag(uP.cusId, uP.email, uP.city, uP.state, uP.zipcode, uP.newsletter, uP.subscribe);
			if (G_PS_PATHNAME != "/eaddressbook.exe/saveeditaddress")
				psSetCookie(G_PS_COOKIE_FLAG, "", "delete");
		}
	}
	else if ((flag == "SIGN-OUT") && (document.body.innerHTML.toLowerCase().indexOf("/eaccount.exe/signout") < 0))
	{
		psSetCookie(G_PS_COOKIE_PROFILE, "", "delete");
	}
}

function psHijackRegistrations()
{
	if (G_PS_PATHNAME == "/echeckout.exe/start")
	{
		if (document.forms.length > 0)
		{
			document.forms[0].OldFunc = document.forms[0].onsubmit;
			document.forms[0].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeLoginProfile())				
					psSetCookie(G_PS_COOKIE_FLAG, "LOGIN"); 
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
	else if (G_PS_PATHNAME == "/echeckout.exe/getaddresses" || G_PS_PATHNAME == "/echeckout.exe/mopcheck")
	{
		// hijack to capture other info for the profile such as city, state, ....
		if (document.forms.length > 0)
		{
			document.forms[0].OldFunc = document.forms[0].onsubmit;
			document.forms[0].onsubmit = function()
			{
				var uP = new psProfile();
				uP.writeCheckoutProfile();
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
	else if (G_PS_PATHNAME == "/eaddressbook.exe/editaddress")
	{
		// hijack to capture other info for the profile such as city, state, ....
		if (document.forms.length > 0)
		{
			if (psGetCookie(G_PS_COOKIE_FLAG) == "UPDATEPROFILE")
				psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
			document.forms[1].OldFunc = document.forms[1].onsubmit;
			document.forms[1].onsubmit = function()
			{
				var billTo = document.getElementsByName("Billto");
				if (billTo && billTo[0].checked)
				{
					var uP = new psProfile();
					if (uP.writeCheckoutProfile())
						psSetCookie(G_PS_COOKIE_FLAG, "UPDATEPROFILE"); 
				}
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
	else if (G_PS_PATHNAME == "/eemailmanager.exe/changeemail")
	{
		// hijack to capture new email
		if (document.forms.length > 0)
		{
			if (psGetCookie(G_PS_COOKIE_FLAG) == "CHANGEEMAIL")
				psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
			document.forms[1].OldFunc = document.forms[1].onsubmit;
			document.forms[1].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeLoginProfile())
					psSetCookie(G_PS_COOKIE_FLAG, "CHANGEEMAIL"); // Flag cookie
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
	else if (G_PS_PATHNAME == "/eaccount.exe/signin")
	{
		// Hijack the signout link to clear profile on cookie
		for (var i = 0; i < document.links.length; i++)
		{
			if (document.links[i].href.toLowerCase().indexOf("/eaccount.exe/signout")>=0)
			{
				if (psGetCookie(G_PS_COOKIE_FLAG) == "SIGN-OUT")
					psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
				document.links[i].OldFunc = document.links[i].onclick;
				document.links[i].onclick = function()
				{
					psSetCookie(G_PS_COOKIE_FLAG, "SIGN-OUT"); // Flag cookie
					if (this.OldFunc != null)
						return this.OldFunc();
				}
				break;
			}
		}
		psHijackSignInSignUp();
	}
	else if (G_PS_PATHNAME == "/eaccount.exe/pleasesignin")
	{
		psHijackSignInSignUp();
	}
	else if (G_PS_PATHNAME == "/eaddressbook.exe/addaddress")
	{
		if (document.forms.length > 0)
		{
			// hijack the add address
			if (psGetCookie(G_PS_COOKIE_FLAG) == "ADDADDRESS")
				psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
			document.forms[1].OldFunc = document.forms[1].onsubmit;
			document.forms[1].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeUserAddress())
					psSetCookie(G_PS_COOKIE_FLAG, "ADDADDRESS"); // Flag cookie
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
	else if (G_PS_PATHNAME == "/eaddressbook.exe/addemail")
	{
		if (document.forms.length > 0)
		{
			// hijack the add address
			if (psGetCookie(G_PS_COOKIE_FLAG) == "ADDEMAIL")
				psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
			document.forms[1].OldFunc = document.forms[1].onsubmit;
			document.forms[1].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeLoginProfile())
					psSetCookie(G_PS_COOKIE_FLAG, "ADDEMAIL"); // Flag cookie
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
}

function psHijackSignInSignUp()
{
	if (document.forms.length > 2)
	{
		// hijack the sign-in
		if (psGetCookie(G_PS_COOKIE_FLAG) == "SIGN-IN")
			psSetCookie(G_PS_COOKIE_FLAG, ""); // Clear flag
		if (document.forms[1].action.toLowerCase().indexOf("/signin")>=0)
		{
			document.forms[1].OldFunc = document.forms[1].onsubmit;
			document.forms[1].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeLoginProfile())
					psSetCookie(G_PS_COOKIE_FLAG, "SIGN-IN"); // Flag cookie
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
		if (document.forms[2].action.toLowerCase().indexOf("/createaccount")>=0)
		{
			document.forms[2].OldFunc = document.forms[2].onsubmit;
			document.forms[2].onsubmit = function()
			{
				var uP = new psProfile();
				if (uP.writeNewUserProfile())
					psSetCookie(G_PS_COOKIE_FLAG, "SIGN-UP"); // Flag cookie
				if (this.OldFunc != null)
					return this.OldFunc();
			}
		}
	}
}

function psPostPageViewTag(){
	var pageId = catId = pAttributes = null;
	if(G_PS_URL_PATH.search(/refineSearchKeywordDisplay/i) >= 0){
		pAttributes = G_PS_URL_PATH.split(/refineSearchKeywordDisplay/gi);
		pAttributes = pAttributes[pAttributes.length -1];
		pAttributes = pAttributes.split(/refineSearchKeyword/gi);
		pAttributes = pAttributes[0].replace(/^\=/gi, "");
		pAttributes = pAttributes.replace(/\&$/gi,"");
		pAttributes = psTrim(psHtmlDecode(unescape(pAttributes)));
	}
	if(G_PS_URL_PATH.search(/brandId/i) >= 0){
		if(pAttributes == null || pAttributes == ""){
			pAttributes = psGetValueFromUrl(G_PS_URL_PATH, "brandId");
		}
		else{
			pAttributes += "-_-" + psGetValueFromUrl(G_PS_URL_PATH, "brandId");
		}
	}
	if(G_PS_PATHNAME == "/" || G_PS_PATHNAME == "/default.aspx"){
		pageId = catId = "Home";
		psHijackViewFromTopSeller();
	}
	else{
		if(G_PS_URL_PATH.search(/\/reloading/i) >= 0
			 || G_PS_URL_PATH.search(/\/gunsmithing/i) >= 0
			 || G_PS_URL_PATH.search(/\/optics/i) >= 0
			 || G_PS_URL_PATH.search(/\/ammunition/i) >= 0
			 || G_PS_URL_PATH.search(/\/Rebates/i) >= 0){
			pageId = catId = G_PS_PATHNAME.replace(/^\//gi,"");
		}
		else if(G_PS_URL_PATH.search(/\/dealer\_policies/i) >= 0
			 || G_PS_URL_PATH.search(/\/dealer\_qualifications/i) >= 0
			 || G_PS_URL_PATH.search(/\/rebates\~/i) >= 0
			 || G_PS_URL_PATH.search(/\/Careers~/i) >= 0){
			if(G_PS_URL_PATH.search(/\_/gi) >= 0 && G_PS_URL_PATH.search(/\#/gi) >= 0){
				catId= G_PS_URL_PATH.split(/\_/gi);
				catId = catId[0];
				catId = catId.split(/\//gi);
				catId = catId[catId.length -1];
				pageId = G_PS_URL_PATH.split(/\#/gi);
				pageId = pageId[pageId.length -1];
			}
		}
		else if(G_PS_URL_PATH.search(/\/Promotion\/\?promotion/i) >= 0){
			pageId = catId = "Clearance";
			window.setInterval("psHijackAddToCartFromBrow()", 1000);
		}
		else if(G_PS_URL_PATH.search(/\/request/i) >= 0){
			pageId = catId = "Request";
		}
		else if(G_PS_URL_PATH.search(/\/printcart/i) >= 0){
			pageId = catId = "Print Cart";
		}
		else if(G_PS_URL_PATH.search(/NeedHelp/i) >= 0){
			pageId = "NeedHelp";
			catId = "Support";
		}	
		else if(G_PS_URL_PATH.search(/\/error\.htm/i) >= 0){
			pageId = catId = "Error";
		}	
		else if(G_PS_URL_PATH.search(/gettotal/i) >= 0){
			pageId = "NRA Support";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/\/pickup\.htm/i) >= 0){
			pageId = catId = "Pickup";
		}
		else if(G_PS_URL_PATH.search(/\/eaccount\.exe\/signout/i) >= 0){
			pageId = "Sign Out";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/BaldrigeAward/i) >= 0){
			pageId = "Baldridge Award";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/ContactUs/i) >= 0){
			pageId = "Contact Us";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/AboutUs/i) >= 0){
			pageId = "About Us";
			catId = "Careers";
		}	
		else if(G_PS_URL_PATH.search(/international\_information/i) >= 0){
			pageId = "International";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/Requestcatalogs/i) >= 0){
			pageId = "Request Catalogs";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/Careers/i) >= 0){
			pageId = "Careers";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/privacy\_policy/i) >= 0){
			pageId = "Privacy Policy";
			catId = "Company Information";
		}	
		else if(G_PS_URL_PATH.search(/\/search\//i) >= 0 && G_PS_URL_PATH.search("_-_")< 0){
			pageId = "Advanced Search";
			catId = "Search Information";
		}
		else if(G_PS_URL_PATH.search(/dealer\_information/i) >= 0){
			pageId = "Dealer Information";
			catId = "Dealer";
		}	
		else if(G_PS_URL_PATH.search(/\/eaccount\.exe\/pleasesignin/i) >= 0){ 
			pageId = "Your Account";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/\/eaccount\.exe\/signin/i) >= 0){ 
			pageId = "SignIn";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/\/createaccount/i) >= 0){
			pageId = "Account Page";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/\/getaddressbook/i) >= 0){
			pageId = "Name Address Change";
			catId = "Name-Address";
		}	
		else if(G_PS_URL_PATH.search(/\/NameChange/i) >= 0){
			pageId = "Name Change";
			catId = "Name";
		}	
		else if(G_PS_URL_PATH.search(/\/KeepPrivate/i) >= 0){
			pageId = "Keep Private";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/\/EditAddress/i) >= 0){
			pageId = "Address Edit";
			catId = "Address";
		}	
		else if(G_PS_URL_PATH.search(/\/SaveEditAddress/i) >= 0){
			pageId = "Address Change";
			catId = "Address";
		}	
		else if(G_PS_URL_PATH.search(/\/addaddress/i) >= 0){
			pageId = "Add Address";
			catId = "Address";
		}	
		else if(G_PS_URL_PATH.search(/\/SaveNewAddress/i) >= 0){
			pageId = "New Address";
			catId = "Address";
		}	
		else if(G_PS_URL_PATH.search(/\/getemailpassword/i) >= 0){
			pageId = "Email Password Birthday";
			catId = "Email-Password-Birthday";
		}	
		else if(G_PS_URL_PATH.search(/\/changeemail/i) >= 0){
			pageId = "Email Change";
			catId = "Email-Password-Birthday";
		}	
		else if(G_PS_URL_PATH.search(/\/savechange/i) >= 0){
			pageId = "Save Email Change";
			catId = "Email-Password-Birthday";
		}	
		else if(G_PS_URL_PATH.search(/\/SavePassword/i) >= 0){
			pageId = "Password Saved";
			catId = "Email-Password-Birthday";
		}	
		else if(G_PS_URL_PATH.search(/\/SaveProfile/i) >= 0){
			pageId = "Birthday Saved";
			catId = "Email-Password-Birthday";
		}	
		else if(G_PS_URL_PATH.search(/\/getorderhistory/i) >= 0){
			pageId = "Orders and History";
			catId = "Orders-History";
		}	
		else if(G_PS_URL_PATH.search(/\/getmidwaymoney/i) >= 0){
			pageId = "Money and Coupons";
			catId = "Account";
		}	
		else if(G_PS_URL_PATH.search(/echeckout\.exe/i) >= 0){
			var pValue = G_PS_URL_PATH.split(/echeckout\.exe/gi)[1];
			if(pValue != null || pValue != ""){
				pValue = pValue.replace(/^\//i, "");
				if(pValue.search(/\?/gi) >= 0){
					pValue = pValue.split(/\?/gi)[0];
				}
				pageId = "Checkout " + psTrim(psHtmlDecode(unescape(pValue)));
			}
			else {
				pageId = "Checkout";
			}
			catId = "Checkout";
		}	
		else if(G_PS_URL_PATH.search(/\/ewishlist\.exe/i) >= 0){
			pageId = catId = "WishList";
			psHijackAddFromWishList();
			psHijackMoveFromWishList();
		}
		else if(G_PS_URL_PATH.search(/\/hunting\-gear/i) >= 0
			 || G_PS_URL_PATH.search(/\/BrowseCategories\.asp/i) >= 0 
			 || G_PS_URL_PATH.search(/\/BrowseProducts\.asp/i) >= 0
			 || G_PS_URL_PATH.search(/\/shooting\-supplies/i) >= 0
			 || G_PS_URL_PATH.search(/\/bianchi/i) >= 0
			 || G_PS_URL_PATH.search(/\/federal/i) >= 0
			 || G_PS_URL_PATH.search(/\/hornady/i) >= 0
			 || G_PS_URL_PATH.search(/\/glock/i) >= 0
			 || G_PS_URL_PATH.search(/\/kimber/i) >= 0
			 || G_PS_URL_PATH.search(/\/mossberg/i) >= 0
			 || G_PS_URL_PATH.search(/\/remington/i) >= 0
			 || G_PS_URL_PATH.search(/\/ruger/i) >= 0
			 || G_PS_URL_PATH.search(/\/sierra/i) >= 0
			 || G_PS_URL_PATH.search(/\/winchester/i) >= 0
			 || G_PS_URL_PATH.search(/\/dpms/i) >= 0
			 || G_PS_URL_PATH.search(/\/browning/i) >= 0){
			var psBread= document.getElementById("cookietrail");
			if(psCheckElementExist(psBread)){
				var psBread = psBread.getElementsByTagName("p")[0];
				if(psCheckElementExist(psBread)){
					var psAtags = psBread.getElementsByTagName("a");
					if(psCheckArrayExist(psAtags)){
						var pTexts = psBread.innerHTML.split(/\<\/a\>/gi);
						pageId = psTrim(psHtmlDecode(unescape(pTexts[pTexts.length -1])));
						pageId = psTrim(pageId.replace(/^\>/i, ""));
						if (cmExtractParameter("categoryId",document.location.href))	{
							 catId=cmExtractParameter("categoryId",document.location.href);
						} else {
							if(psAtags.length == 1){
								catId = pageId;
							}
							else{
								catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
							}
						}
					}
				}
			}
			window.setInterval("psHijackAddToCartFromBrow()", 1000);
		}	
		else if(G_PS_URL_PATH.search(/\/static\//i) >= 0
			 || G_PS_URL_PATH.search(/\/Index\/Spring/i) >= 0){
			var pSection = document.getElementById("section00");
			if(psCheckElementExist(pSection)){
				var Atags = pSection.getElementsByTagName("a");
				if(psCheckArrayExist(Atags)){
					var pTexts = pSection.innerHTML.split(/\<\/a\>/gi);
					pageId = psTrim(psHtmlDecode(unescape(pTexts[pTexts.length -1])));
					pageId = psTrim(pageId.replace(/^\>/i, ""));
					if (cmExtractParameter("categoryId",document.location.href))	{
						 catId=cmExtractParameter("categoryId",document.location.href);
					} else {
						if(Atags.length == 1){
							catId = pageId;
						}
						else{
							catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
						}
					}
				}
			}	
		}
		else if(G_PS_URL_PATH.search(/\/guntecdictionary\.exe/i) >= 0){
			var psBread= document.getElementById("breadcrumbs");
			if(psCheckElementExist(psBread)){
				var psBread = psBread.getElementsByTagName("span")[0];
				if(psCheckElementExist(psBread)){
					var psAtags = psBread.getElementsByTagName("a");
					if(psCheckArrayExist(psAtags)){
						var pTexts = psBread.innerHTML.split(/\<\/a\>/gi);
						pageId = psTrim(psHtmlDecode(unescape(pTexts[pTexts.length -1])));
						pageId = psTrim(pageId.replace(/^\>/i, ""));
						pageId = psTrim(pageId.replace(/\<\s*br\s*\>/i, ""));
						if (cmExtractParameter("categoryId",document.location.href))	{
							 catId=cmExtractParameter("categoryId",document.location.href);
						} else {
							if(psAtags.length == 1){
								catId = pageId;
							}
							else{
								catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
							}
						}
					}
				}
			}
			window.setInterval("psHijackAddToCartFromBrow()", 1000);
		}	
	}	
	if(pageId == null || pageId == ""){
		var pSec = document.getElementById("section02");
		if(psCheckElementExist(pSec)){
			pSec = pSec.getElementsByTagName("h1")[0];
			if(psCheckElementExist(pSec)){
				pageId = catId = psTrim(psHtmlDecode(unescape(pSec.innerHTML)));
			}
		}
	}
	pageId = psCleanPageId(pageId);
	catId = psCleanCatId(catId);
	psSetCookie(G_PS_COOKIE_CATID, pageId);
	if(cmExtractParameter("categoryString=",window.location.href)){
		pageId = pageId + ":" + cmExtractParameter ("categoryString=", window.location.href);
	}
	if(pageId!= null && pageId !== "" && catId != null && catId != ""){
		psCreatePageviewTag(pageId, catId, null, null, pAttributes);
	}
	window.setInterval("psHijackAddToCartFromBrow()", 1000);
}

function psHijackViewFromTopSeller(){
	var pTop = document.getElementById("topsellers");
	if(psCheckElementExist(pTop)){
		var TagA = pTop.getElementsByTagName("a");
		if(psCheckArrayExist(TagA)){
			for(var i=0; i< TagA.length; i++){
				TagA[i].Oldf = TagA[i].onclick;
				TagA[i].onclick = function HijackViewFromTopSeller(){
					psSetCookie(G_PS_COOKIE_CATID, "Top Seller");
					if(this.Oldf != null){
						return this.Oldf();
					}
				}
			}
		}
	}
} 

function psHijackQuickAdd(){
	var pNum = document. getElementById("prod_number_to_cart");
	if(psCheckElementExist(pNum)){
		pNum.Oldf = pNum.onsubmit;
		pNum.onsubmit = function(){
			var proId = document.getElementById("SaleItemID");
			if(psCheckElementExist(proId)){
				proId = psTrim(psHtmlDecode(unescape(proId.value)));
				psSetValueToCookie(G_PS_COOKIE_PROD_CATID, proId, "Quick Add");
				if(this.Oldf != null){
					return this.Oldf();
				}
			}
		}
	}
}

function psHijackAddToCartFromBrow(){
	var prodId = null;
	var prodCatId = psGetCookie(G_PS_COOKIE_CATID);
	var pProd = document.getElementById("Product");
	if(psCheckElementExist(pProd) == false){
		pProd = document.getElementById("productDisplayBlock");
	}
	if(psCheckElementExist(pProd)){
		var proList = psGetElementsByClassName(pProd, "div", "prodListCont");
		if(psCheckArrayExist(proList)){
			for(var i=0; i<proList.length ;i++){
				var TagA = psGetElementsByClassName(proList[i], "a", "smallcartbut")[0];
				if(psCheckElementExist(TagA)){
					if(TagA.onclick == null || TagA.onclick.toString().indexOf("HijackAddFromBrow")< 0){
						TagA.index = i;
						TagA.Oldf = TagA.onclick ;
						TagA.onclick = function HijackAddFromBrow(){
							var Atag = proList[this.index].getElementsByTagName("a")[0];
							if(psCheckElementExist(Atag)){
								prodId = psGetValueFromUrl(Atag.href, "productNumber");
							}
							psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prodId, prodCatId);
							psClearInterval(INTERVAL_ID_Arr);
							if(this.Oldf != null){
								return this.Oldf();
							}
						}
					}
				}
			}
		}	
	}
}

function psHijackAddToCartFromProductView(prdId, prdCatId){
	var Cartbtn = document.getElementById("cartButton");
	if(psCheckElementExist(Cartbtn)){
		var TagA = psGetElementsByClassName(Cartbtn, "a", "bigcartbut")[0];
		if(psCheckElementExist(TagA)){
			if(TagA.onclick == null || TagA.onclick.toString().indexOf("HijackAddToCartFromProductView") < 0){
				TagA.Oldf = TagA.onclick;
				TagA.onclick = function HijackAddToCartFromProductView(){
					psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prdId, prdCatId);
					if(this.Oldf != null){
						return this.Oldf();
					}
				}
			}
		}
	}
}

function psHijackViewFromProductView(ElementId, catId){
	var pBox = document.getElementById(ElementId);
	if(psCheckElementExist(pBox)){
		var pDivs = psGetElementsByClassName(pBox, "div", "subimg");
		if(psCheckArrayExist(pDivs)){
			for(var i=0; i< pDivs.length; i++){
				var TagAs =pDivs[i]. getElementsByTagName("a");
				if(psCheckArrayExist(TagAs)){
					for(var j=0; j< TagAs.length; j++){
						if(TagAs[j].href != null && TagAs[j].href != ""){
							TagAs[j].Oldf = TagAs[j].onclick;
							TagAs[j].onclick = function HijackViewFromProductView(){
								psSetCookie(G_PS_COOKIE_CATID, catId);
								if(this.Oldf != null){
									return this.Oldf();
								}
							}
						}
					}
				}
			}
		}
	}
}

function psHijackAddFromWishList(){
	var WishList = document.getElementById("wishList");
	if(psCheckElementExist(WishList)){
		var Divs = psGetElementsByClassName(WishList, "div", "products")[0];
		if(psCheckElementExist(Divs)){
			var pTables = Divs.getElementsByTagName("table")[0];
			if(psCheckElementExist(pTables)){
				pTables = pTables.getElementsByTagName("table")[0];
				if(psCheckElementExist(pTables)){
					var pTrs = pTables.getElementsByTagName("tr");
					if(psCheckArrayExist(pTrs)){
						for(var i=0; i<pTrs.length; i++){
							if(pTrs[i].innerHTML.search(/\$/i) >= 0){
								var TagA = psGetElementsByClassName(pTrs[i], "a", "smallcartbut")[0];
								if(psCheckElementExist(TagA)){
									TagA.index = i;
									TagA.Oldf = TagA.onclick ;
									TagA.onclick = function HijackAddFromWishList(){
										var Atag = pTrs[this.index].getElementsByTagName("a")[0];
										if(psCheckElementExist(Atag)){
											var prodId = psGetValueFromUrl(Atag.href, "productnumber");
											psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prodId, 
"WishList");
										}	
										if(this.Oldf != null){
											return this.Oldf();
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}

function psHijackMoveFromWishList(){
	var Atags  = psGetElementsByClassName(document, "a", "smallgraybut");
	if(psCheckArrayExist(Atags)){
		for(var i=0; i< Atags.length; i++){
			if(Atags[i].href!= null && Atags[i].href.search(/\/Movealltocart/gi) >= 0){
				Atags[i].Oldf = Atags[i].onclick;
				Atags[i].onclick = function HijackMoveFromWishList(){
					var Divs = psGetElementsByClassName(document, "div", "products")[0];
					if(psCheckElementExist(Divs)){
						var pTables = Divs.getElementsByTagName("table")[0];
						if(psCheckElementExist(pTables)){
							pTables = pTables.getElementsByTagName("table")[0];
							if(psCheckElementExist(pTables)){
								var pTrs = pTables.getElementsByTagName("tr");
								if(psCheckArrayExist(pTrs)){
									for(var j=0; j<pTrs.length; j++){
										var TagA = pTrs[j].getElementsByTagName("a")[0];
										if(psCheckElementExist(TagA)){
											var prodId = psGetValueFromUrl(TagA.href, "productnumber");
											psSetValueToCookie(G_PS_COOKIE_PROD_CATID, prodId, 
"WishList");
										}
									}
								}
							}
						}
					}
					if(this.Oldf != null){
						return this.Oldf();
					}
				}
				break;
			}
		}
	}
}
/*====================== END TAGGING BUSSINESS LOGIC =========================*/


/*======================= GENERAL UTILITY FUNCTION ===========================*/
function psProduct()
{
    this.id = null;
    this.name = null;
    this.catId = null;
    this.price = null;
    this.quantity = null;
	this.attribute = null;

	this.reset = function()
	{
		this.id = null;
		this.name = null;
		this.catId = null;
		this.price = null;
		this.quantity = null;
		this.attribute = null;
	}
	
	this.getProduct = function()
	{
		try
		{
			this.reset(); // DO NOT REMOVE THIS IMPORTANT STATEMENT!
			this.id = document.getElementById("selectedSaleItem"); 
			if(psCheckElementExist(this.id)){
				this.id = psTrim(psHtmlDecode(unescape(this.id.innerHTML)));
				if (this.id.indexOf("Product #: ")>-1){
					this.id=this.id.substring(this.id.indexOf("Product #: ")+11);
				}
			}
			if (this.id==""){
				this.id = document.getElementById("productFamilyNumber"); 
				if(psCheckElementExist(this.id)){
					this.id = psTrim(psHtmlDecode(unescape(this.id.innerHTML)));
					if (this.id.indexOf("Product Family #: ")>-1){
						this.id=this.id.substring(this.id.indexOf("Product #: ")+19);
					}
				}
			}
			this.name = document.getElementById("topRight"); 
			if(psCheckElementExist(this.name)){
				this.name = this.name.getElementsByTagName("h1")[0];
				if(psCheckElementExist(this.name)){
					this.name = psTrim(psHtmlDecode(unescape(this.name.innerHTML)));
				}
			}

			if(G_PS_URL_REFERRER.search(/eshoppingcart\.exe\/EmptyCart/i) >= 0){
				this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);
			}
			if(this.catId == null || this.catId == ""){
				if(psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "home"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "search"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "clearance"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "top seller"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "featured products"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "suggests"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "suggest products"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "others bought"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "wishlist"
				|| psGetCookie(G_PS_COOKIE_CATID).toLowerCase() == "substitute products"){
					this.catId = psGetCookie(G_PS_COOKIE_CATID);
				}
			}
			if (cmExtractParameter ("categoryId", document.referrer) && !cmExtractParameter ("categoryId", window.location.href)){
				this.catId=cmExtractParameter ("categoryId", document.referrer);
			}
			if(this.catId == null || this.catId == ""){
				var psBread= document.getElementById("cookietrail");
				if(psCheckElementExist(psBread)){
					var psBread = psBread.getElementsByTagName("p")[0];
					if(psCheckElementExist(psBread)){
						var psAtags = psBread.getElementsByTagName("a");
						if(psCheckArrayExist(psAtags)){
							this.catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
						}
					}
				}
			}
			if(this.catId == null || this.catId == ""){
				var pSection = document.getElementById("section00");
				if(psCheckElementExist(pSection)){
					var Atags = pSection.getElementsByTagName("a");
					if(psCheckArrayExist(Atags)){
						this.catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
					}
				}
			}
			if(this.catId == null || this.catId == ""){
				var psBread= document.getElementById("breadcrumbs");
				if(psCheckElementExist(psBread)){
					var psBread = psBread.getElementsByTagName("span")[0];
					if(psCheckElementExist(psBread)){
						var psAtags = psBread.getElementsByTagName("a");
						if(psCheckArrayExist(psAtags)){
							this.catId = psTrim(psHtmlDecode(unescape(psAtags[psAtags.length -1].innerHTML)));	
						}
					}
				}
			}
			this.attribute = document.getElementById("productStatus");
			if(psCheckElementExist(this.attribute)){
				this.attribute = this.attribute.getElementsByTagName("em")[0];
				if(psCheckElementExist(this.attribute)){
					this.attribute = this.attribute.innerHTML;
				}
			}
			
			return true;
		}
		catch (ex) { return false; }
	}
	this.getItem5 = function(itemRow)
	{
		try
		{
			this.reset(); // DO NOT REMOVE THIS IMPORTANT STATEMENT!
			var cellNode = itemRow.cells[1].getElementsByTagName("a")[0];
			if(cellNode)
			{
				this.id = psGetValueFromUrl(cellNode.href, "productnumber");
				this.name = psGetInnerText(cellNode);
			}
			cellNode = itemRow.cells[3].getElementsByTagName("input")[0];
			if (cellNode)
			{
				this.quantity = cellNode.value;
			}
			cellNode = itemRow.cells[4]
			if (cellNode)
			{
				this.price = psCleanPrice(psGetInnerText(cellNode));
			}
			var pAttributes = itemRow.getElementsByTagName("a");
			for(var i=0; i< pAttributes.length; i++){
				if(pAttributes[i].href.search(/\/staticpages\/status\_window\/product\_status\.htm/gi) >= 0){
					this.attribute = pAttributes[i].innerHTML;
				}
			}
			
			this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);
			if(this.catId == null || this.catId == "")
			{
				this.catId = "Unknown";
			}

			return true;
		}
		catch (ex) {return false; }
	}
	this.getItem9 = function(itemRow)
	{
		try
		{
			this.reset(); // DO NOT REMOVE THIS IMPORTANT STATEMENT!

			if (itemRow)
			{
				this.id = psGetInnerText(itemRow.cells[0]);
				this.name = psGetInnerText(itemRow.cells[1]);
				this.quantity = psGetInnerText(itemRow.cells[3]);
				this.price = psGetInnerText(itemRow.cells[5]);
			}
			this.catId = psGetValueFromCookie(G_PS_COOKIE_PROD_CATID, this.id);

			return true;
		}
		catch (ex) { return false; }
	}
}

function psProfile()
{
	this.cusId = null;
    this.email = null;
    this.city = null;
    this.state = null;
    this.zipcode = null;
	this.newsletter = null;
	this.subscribe = null;

	this.reset = function()
	{
		this.cusId = null;
		this.email = null;
		this.city = null;
		this.state = null;
		this.zipcode = null;
		this.newsletter = null;
		this.subscribe = null;
	}
	this.readProfile = function()
	{
		try
		{
			this.cusId = psGetCookie(G_PS_COOKIE_PROFILE);
			if (this.cusId != null)
			{
				var buf = this.cusId.split('|');
				for (var i=0; i<buf.length; i++)
				{
					var tempVal = buf[i];
					// when NULL is written to cookie, it becomes string, not literal constant
					buf[i] = (tempVal=="null" ? null : tempVal); 
				}
				this.cusId = buf[0];
				this.email = buf[1];
				this.city = buf[2];
				this.state = buf[3];
				this.zipcode = buf[4];
				this.newsletter = buf[5];
				this.subscribe = buf[6];
			}
			return true;
		}
		catch (ex) { return false; }
	}
	this.writeLoginProfile = function()
	{
		try
		{
			this.reset();
			// email
			var nodeColl = null;
			var node = null;
			if (G_PS_PATHNAME == "/echeckout.exe/start")
			{
				nodeColl = document.getElementsByName("email");
				if (nodeColl)
					node = nodeColl[0];
			}
			else if (G_PS_PATHNAME == "/eemailmanager.exe/changeemail")
			{
				nodeColl = document.getElementsByName("emailchange");
				if (nodeColl)
					node = nodeColl[0];
			}
			else if (G_PS_PATHNAME == "/eaccount.exe/pleasesignin" || G_PS_PATHNAME == "/eaccount.exe/signin")
			{
				nodeColl = document.getElementsByName("custemail");
				if (nodeColl)
					node = nodeColl[0];
			}

			if (node)
			{
				this.email = node.value;
				this.cusId = this.email;
			}
			if (this.email == null || psTrim(this.email) == "")
				return false;

			return this.writeProfile();
		}
		catch (ex) { return false; }
	}
	this.writeCheckoutProfile = function()
	{
		try
		{
			if (this.readProfile() == false)
				return false;
			// city
			var nodes = document.getElementsByName("city");
			if (nodes)
				this.city = nodes[0].value;
			// state
			nodes = document.getElementsByName("state");
			if (nodes)
				this.state = nodes[0].value;
			// zipcode
			nodes = document.getElementsByName("zip");
			if (nodes)
				this.zipcode = nodes[0].value;

			return this.writeProfile();
		}
		catch (ex) { return false; }
	}
	this.writeNewUserProfile = function()
	{
		try
		{
			this.reset();

			var nodes = null;
			// email
			nodes = document.getElementsByName("email");
			if (nodes)
			{
				this.email = nodes[0].value;
				this.cusId = this.email;
			}
			if (this.email == null || this.email == "")
				return false;
			// city
			nodes = document.getElementsByName("city");
			if (nodes)
				this.city = nodes[0].value;

			// state
			nodes = document.getElementsByName("state");
			if (nodes)
				this.state = nodes[0].value;

			// zipcode
			nodes = document.getElementsByName("zip");
			if (nodes)
				this.zipcode = nodes[0].value;
			
			return this.writeProfile();
		}
		catch (ex) {return false;}
	}

	this.writeUserAddress = function()
	{
		try
		{
			this.readProfile();
			if (this.email == null || this.email == "")
				return false;
			// city
			var nodes = document.getElementsByName("city");
			if (nodes)
				this.city = nodes[0].value;
			// state
			nodes = document.getElementsByName("state");
			if (nodes)
				this.state = nodes[0].value;
			// zipcode
			nodes = document.getElementsByName("zip");
			if (nodes)
				this.zipcode = nodes[0].value;
			
			return this.writeProfile();
		}
		catch (ex) {return false;}
	}
	
	this.writeProfile = function()
	{
		try
		{
			if (this.cusId == null)
				return;
			// make sure that the data contains 4 parts separated by 3 '|'
			var data = this.cusId + "|" + this.email + '|' + this.city + '|' + this.state + '|' 
				+ this.zipcode + "|" + this.newsletter + '|' + this.subscribe;
			psSetCookie(G_PS_COOKIE_PROFILE, data);
			return true;
		}
		catch (ex) { return false; }
	}
}

function psOrder()
{
	this.id = null;
	this.subtotal = null;
	this.shipping = null;
	this.getOrder = function()
	{
		try
		{
			var tmp = document.body.innerHTML.toUpperCase().split("INVOICE #:")[1]; 
			if (tmp)
			{
				tmp = tmp.split("<BR>")[0];
				this.id = psTrim(tmp.substring(tmp.lastIndexOf(">") + 1)); 
			}
			if ((!this.id) || (this.id == ""))
				return false;
			// subtotal
			tmp = document.body.innerHTML.toUpperCase().split("ITEM TOTAL:")[1]; 
			if (tmp)
			{
				tmp = tmp.split("</SPAN>")[1]; 
				this.subtotal = psCleanPrice(tmp.substring(tmp.lastIndexOf(">") + 1));
			}
			// shipping
			tmp = document.body.innerHTML.toUpperCase().split("INSURANCE:")[1];
			if (tmp)
			{
				tmp = tmp.split("</SPAN>")[1];
				this.shipping = psCleanPrice(tmp.substring(tmp.lastIndexOf(">") + 1));
			}
			return true;
		}
		catch (ex) {return false;}
	}
}

function psGetInnerText(pTagOjb){
	var pattern = /<script[\s\S]*?<\/script>/gi; // question mark means non-greedy
	if (pTagOjb != null)
	{
		var sT = (typeof(pTagOjb) == "object") ? pTagOjb.innerHTML : pTagOjb;
		// remove all script tags and its content
		while (sT.search(pattern) > -1)
		{
			sT = sT.replace(pattern, "");
		}
		return sT.replace(/\<+.+?\>+/g, "");
	}
	return null;
}

function psCleanCatId(pCatId)
{
    return (pCatId != null) ? pCatId.replace(/[\'\":,\™\®]/g, "") : null;
}

function psCleanPageId(pPageId)
{
	return (pPageId != null) ? pPageId.replace(/[\n\t\v\r’\'\"\™\®]/gi, "") : null; 
}

function psCleanProductName(pProductName)
{
	return (pProductName != null) ? pProductName.replace(/[\n\t\v\r’\'\"\™\®]/gi, "") : null; 
}

function psTrim(pStr)
{
	if (pStr == null || typeof(pStr) != "string")
		return pStr;
	return (pStr != null) ? pStr.replace(/&nbsp;|\u00A0/gi, ' ').replace(/^\s+|\s+$/g, '') : null;
}

function psGetValueFromUrl(pUrl, pKey)
{
	pUrl = (pUrl != null) ? "?" + psTrim(pUrl.toLowerCase()) : null;
	pKey = (pKey != null) ? psTrim(pKey.toLowerCase()) : null;

	if (pUrl == null || pKey == null || pUrl.indexOf(pKey) == -1) 
		return null;
	
	var start = pUrl.indexOf('&' + pKey + '=');
	start = (start == -1) ? pUrl.indexOf('?' + pKey + '=') : start;
	if (start >= 0)
	{
		start = start + pKey.length;
		var end = pUrl.indexOf("&", start);
		if(end == -1) 
			end = pUrl.length;
		var middle = pUrl.indexOf("=", start);
		return pUrl.substring(middle + 1, end);
	}
	return null;
}

function psGetElementValueById(pTagId, pValueFlag)
{
    var tag = document.getElementById(pTagId);
    return psGetElementValue(tag, pValueFlag);
}

function psGetElementValue(pTagObj, pValueFlag)
{
    var tagValue = null;
    if (pTagObj != null)
    {
        if (pTagObj.tagName.search(/^INPUT$/i) > -1)
            tagValue = pTagObj.value;
        else if (pTagObj.tagName.search(/^SELECT$/i) > -1)
        {
            if (pValueFlag == true)
                tagValue = pTagObj.options[pTagObj.selectedIndex].value;
            else
                tagValue = psHtmlDecode(pTagObj.options[pTagObj.selectedIndex].innerHTML);// return label instead of value
        }
        else
            tagValue = psHtmlDecode(pTagObj.innerHTML);
    }

    return tagValue;
}

function psCheckEmail(pEmail) 
{
    if (pEmail)
    {
        var i = pEmail.search(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
        return (i > -1);
    }

    return false;
}

function psHtmlDecode(pValue)
{
    if (pValue)
    {
        pValue = pValue.replace(/&nbsp;/gi, " ");
        pValue = pValue.replace(/&quot;/gi, '"');
        pValue = pValue.replace(/&amp;/gi, "&");
        pValue = pValue.replace(/&lt;/gi, "<");
        pValue = pValue.replace(/&gt;/gi, ">");
    }

    return pValue;
}

function psGetMainDomain(pUrl){
	var se = /^https*\:\/\/([^\/\:]+)/gi;
	var domain = (pUrl.search(se) > -1) ? RegExp.$1 : null;
	if(domain != null)
	{
		if(domain.indexOf("www")==0)
		{
			domain = domain.substring(4,domain.length);
		}
		if(G_PS_ARR_DOMAIN != null)
		{
			for(var i =0; i<G_PS_ARR_DOMAIN.length; i++)
			{
				se = new RegExp("[\.]" + G_PS_ARR_DOMAIN[i] + "$","gi");
				if(("." + domain).search(se) > -1)
				{
					domain = G_PS_ARR_DOMAIN[i];
					break;
				}
			}
		}
		domain = "." + domain;
	}
	return domain;
	
}

function psGetDomain(pUrl){
    var se = /^https*\:\/\/([^\/\:]+)/gi;
    return (pUrl.search(se) > -1) ? RegExp.$1 : null;
}

function psCleanPrice(pPrice)
{
	var pattern = /[^0-9\.]/gi;
    return (pPrice != null ? pPrice.toString().replace(pattern, "") : null);
}

function psGetCookie(pCookieName)
{
	var cookies = document.cookie;
	if (!pCookieName || !cookies)
		return null;

	cookies = "; " + cookies.toLowerCase();
	var key = "; " + pCookieName.toLowerCase() + "=";
	var start = cookies.lastIndexOf(key);
	if (start >= 0)
	{
		start = start + key.length;
		var end = cookies.indexOf(";", start);
		if (end == -1)
			end = cookies.length;

		return unescape(cookies.substring(start, end));
	}

    return null;
}

function psCookieBase(pCookieName, pCookieValue, pLifeTime)
{
	var pDomain = psGetMainDomain(G_PS_URL_PATH);
	CC(pCookieName, pDomain);//delete cookie by calling coremetrics's cookie function
	if(pLifeTime == "delete") 
	{         
		return true;
	}
	// set cookie by calling coremetrics's cookie function
	var expire = (pLifeTime) ? (new Date((new Date()).getTime() + (1000 * pLifeTime))).toGMTString() : null;
	
	return CB(pCookieName, escape(pCookieValue), expire, pDomain);
}

function encodeHtml(strValue)
{
	if (strValue!=null)
	{
		strValue = escape(strValue);
		strValue = strValue.replace(/\//g,"%2F");
		strValue = strValue.replace(/\?/g,"%3F");
		strValue = strValue.replace(/=/g,"%3D");
		strValue = strValue.replace(/&/g,"%26");
		strValue = strValue.replace(/@/g,"%40");
	}
	return strValue;
}

function psSetCookie(pCookieName, pCookieValue, pLifeTime)
{
	if (!pCookieName)
	{
		return false;
	}
	
	pCookieValue = (pCookieValue==null)? "null":pCookieValue;
	
	if(pLifeTime != "delete")
	{
		pCookieName = psTrim(pCookieName);
		var oldCookieValue = psGetCookie(pCookieName);
		oldCookieValue = (oldCookieValue==null)? "null":oldCookieValue;
		var totalSize;
		if(document.cookie.indexOf(pCookieName)>-1)
		{
			totalSize =  document.cookie.length + encodeHtml(pCookieValue).length - encodeHtml(oldCookieValue).length;
		}
		else
		{
			totalSize =  document.cookie.length  + encodeHtml(pCookieValue).length + encodeHtml(pCookieName).length;
		}
		if(totalSize > 3500)
		{
			return false;
		}
	}
	psCookieBase(pCookieName,pCookieValue,pLifeTime);
}

function psSetValueToCookie(pCookieName, pKey, pValue)
{
	if (!pCookieName || !pKey)
	{
		return false;
	}

	pCookieName = psTrim(pCookieName);
	pKey = (pKey != null) ? "#" + psTrim(pKey).toLowerCase() + "~" : pKey;
	var catCookie = psGetCookie(pCookieName);
	catCookie = (catCookie == null) ? "" : catCookie;
	pValue = (pValue == null) ? "null" : pValue;
	var oldCatCookie = catCookie;
	
	var start = catCookie.indexOf(pKey);
	
	var totalsize;
	if (start >= 0) // Store before -> remove the old value
	{
		var oldValue = psGetValueFromCookie(pCookieName,pKey.replace(/[\~\#]/gi,""));
		oldValue = (oldValue == null) ? "null" : oldValue;
		var end = catCookie.indexOf("#", start + pKey.length);
		if (end == -1)
			end = catCookie.length;
		catCookie = catCookie.replace(catCookie.substring(start, end), "");
		totalsize =  document.cookie.length  + encodeHtml(pKey).length + encodeHtml(pValue).length - encodeHtml(oldValue).length;
	}
	else
	{
		totalsize =  document.cookie.length  + encodeHtml(pKey).length + encodeHtml(pValue).length;  
		if(document.cookie.indexOf(pCookieName)<0)
		{
			totalsize += encodeHtml(pCookieName).length;
		}
	}
	catCookie = pKey + pValue + catCookie;
	var cookieArray = null;   
	//Check existed ?
	while (totalsize > 3500)
	{
		var l1 = encodeHtml(catCookie).length;//length before pop
		cookieArray = catCookie.split("#");
		cookieArray.pop();
		catCookie = cookieArray.join("#");
		var l2 = encodeHtml(catCookie).length;//length after pop                                                        
		totalsize -=  (l1-l2);
	}   
	if(catCookie == null || catCookie == "")
	{
		catCookie = oldCatCookie;
	}
	// Save to cookie              
	psCookieBase(pCookieName, catCookie, G_PS_COOKIE_LIFETIME);
}

function psGetValueFromCookie(pCookieName, pKey)
{
	// "normalize" input parameters
	pCookieName = psTrim(pCookieName);
	pKey = (pKey != null) ? "#" + psTrim(pKey).toLowerCase() + "~" : pKey;
	// extract catId associated with the specified key (pKey)
    var catCookie = psGetCookie(pCookieName);
    if (catCookie != null)
    {
        var start = catCookie.indexOf(pKey);
		if (start >=0 )
		{
			start = start + pKey.length;
			var end = catCookie.indexOf("#", start);
			if (end == -1)
				end = catCookie.length;
			return catCookie.substring(start, end);
		}
		return null;
    }
    return null;
}

function psGenerateRandomValue()
{
	var dtDate = new Date();
	var cusRandom = (dtDate.getTime()%10000000) + (Math.floor(Math.random()*10000));
	return cusRandom;
}

function psShorttenPageID(pLink)
{
	var temp1 = pLink;
	if (temp1 != null)
	{
		temp1 = (temp1.length > 255) ? temp1.substr(0, 255) : temp1;
	}
	return temp1;
}

function psGetElementByName(tagName,elementName){	
	// return the first element
	var tags = document.getElementsByTagName(tagName);
	if(psCheckArrayExist(tags)){
		for(var i=0; i<tags.length; i++){
			if(tags[i].name != null && tags[i].name.toLowerCase() == elementName.toLowerCase()){
				return tags[i];
			}
		}
	}
	return null;
}

function psCheckArrayExist(pArrElement)
{
    if(typeof(pArrElement) == "undefined" || pArrElement == null || pArrElement.length <= 0)
    {
        return false;
    }

    return true;
}

function psCheckElementExist(pElement)
{
    if(typeof(pElement) == "undefined" || pElement == null)
    {
        return false;
    }

    return true;
}

function psGetElementsByClassName(psDocument, psElementTagName, psClassName)
{
    var arrResult = new Array();
    var index = 0;
    var arrInputs = psDocument.getElementsByTagName(psElementTagName);
    if(arrInputs == null)
    {
        return null;
    }
    for(var i = 0; i < arrInputs.length; i ++ )
    {
        if(arrInputs[i].className.toLowerCase() == psClassName.toLowerCase())
        {
            arrResult[index ++ ] = arrInputs[i];
        }
    }
    return arrResult;
}
/********************************************************/
/* WRAPPER FOR COREMETRICS' TAG FUNCTIONS               */
/********************************************************/
function psCreatePageviewTag(pId, pCatId, pSrchTerm, pSrchResult, pAttributes) 
{
	pId = psCleanPageId(pId);
	pId = psShorttenPageID(pId);
	pCatId = psCleanCatId(pCatId);
    if (pSrchResult != null)
        pSrchResult += "";
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreatePageviewTag(" + pId + ", " + pCatId + ", " + pSrchTerm + ", " + pSrchResult + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreatePageviewTag(pId, pCatId, pSrchTerm, pSrchResult, pAttributes);
}

function psCreateProductviewTag(pId, pName, pCatId, pAttributes) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateProductviewTag(" + pId + ", " + pName + ", " + pCatId + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
	if (window.location.href.toLowerCase().indexOf("cm_mmc=")==-1){
	        cmCreateProductviewTag(pId, pName, pCatId, null,null,pCatId,pAttributes);
	}else{
	        cmCreateProductviewTag(pId, pName, pCatId, null,null,null,pAttributes);
	}
}

function psCreateShopAction5Tag(pId, pName, pQuantity, pPrice, pCatId, pAttributes) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
	pQuantity = psCleanPrice(pQuantity);
	pPrice = psCleanPrice(pPrice);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction5Tag(" + pId + ", " + pName + ", " + pQuantity + ", " + pPrice + ", " + pCatId + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction5Tag(pId, pName, pQuantity, pPrice, pCatId, pAttributes);    
}

function psCreateShopAction9Tag(pId, pName, pQuantity, pPrice, pCusID, pOrderID, pOrderTotal, pCatId, pAttributes) 
{
	pName = psCleanProductName(pName);
	pCatId = psCleanCatId(pCatId);
	pQuantity = psCleanPrice(pQuantity);
	pPrice = psCleanPrice(pPrice);
	pOrderTotal = psCleanPrice(pOrderTotal);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateShopAction9Tag(" + pId + ", " + pName + ", " + pQuantity + ", " + pPrice + ", " + pCusID + ", " + pOrderID + ", " + 
pOrderTotal + ", " + pCatId + ", " + pAttributes + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateShopAction9Tag(pId, pName, pQuantity, pPrice, pCusID, pOrderID, pOrderTotal, pCatId, pAttributes);
}

function psCreateOrderTag(pId, pOrderTotal, pOrderShipping, pCusID, pCusCity, pCusState, pCusZip) 
{
	pOrderTotal = psCleanPrice(pOrderTotal);
	pOrderShipping = psCleanPrice(pOrderShipping);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateOrderTag(" + pId + ", " + pOrderTotal + ", " + pOrderShipping + ", " + pCusID + ", " + pCusCity + ", " + pCusState + ", " + 
pCusZip + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateOrderTag(pId, pOrderTotal, pOrderShipping, pCusID, pCusCity, pCusState, pCusZip);
}

function psCreateConversionEventTag(pId, pActionType, pCatID, pPoints) 
{
	pCatID = psCleanCatId(pCatID);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateConversionEventTag(" + pId + ", " + pActionType + ", " + pCatID + ", " + pPoints + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateConversionEventTag(pId, pActionType, pCatID, pPoints);
}

function psCreateRegistrationTag(pCusID, pCustEmail, pCusCity, pCusState, pCusZip, pNewsletter, pSubscribe) 
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateRegistrationTag(" + pCusID + ", " + pCustEmail + ", " + pCusCity + ", " + pCusState + ", " + pCusZip + ", " + pNewsletter + 
", " + pSubscribe + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateRegistrationTag(pCusID, pCustEmail, pCusCity, pCusState, pCusZip, pNewsletter, pSubscribe);
}

function psCreateErrorTag(pPageID, pCatId) 
{
	pPageID = psCleanPageId(pPageID);
	pCatId = psCleanCatId(pCatId);
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmCreateErrorTag(" + pPageID + ", " + pCatId + ")");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmCreateErrorTag(pPageID, pCatId);
}

function psDisplayShop5s()
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmDisplayShop5s()");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmDisplayShop5s();
}

function psDisplayShop9s()
{
    if (G_PS_DEBUG_MODE == 1 || G_PS_DEBUG_MODE == 3)
        alert("cmDisplayShop9s()");
    if (G_PS_DEBUG_MODE == 2 || G_PS_DEBUG_MODE == 3)
        cmDisplayShop9s();
}
/*===========================END GENERAL UTILITY FUNCTION ==================*/
