// Copyright (c) 2011, The Search Agency, Inc., All Rights Reserved
var TSAConst=TSAConst||new (function(){this.SOURCE_PARAM="refcd";this.CREATIVE_PARAM="tsacr";this.VISITOR_COOKIE_NAME_PREFIX="tsa1v";this.VISITOR_COOKIE_VALUE_PREFIX="uvid";this.SESSION_COOKIE_NAME_PREFIX="tsa1s";this.SESSION_COOKIE_VALUE_PREFIX="usid";this.SERVER_HOSTNAME_BASE="api";this.SERVER_DOMAIN="thesearchagency.net";this.DEFAULT_COOKIE_DOMAIN="";this.BASE_SCRIPT_NAME="tsaapi";this.BASE_SCRIPT_PATH="/v2/a";this.IMAGE_SCRIPT="tsaimg.php";this.REDIR_SCRIPT="tsaredir.php"});var TSAGlobal=TSAGlobal||new (function(){this.params=new Array();var f=document.location.search.substring(1);var b=f.split("&");for(var c=0;c<b.length;c++){var e=b[c].toLowerCase();var a=e.indexOf("=");if(a>0){this.params[e.substr(0,a)]=e.substr(a+1)}}var d=document.referrer;this.baseParams=((!d||(d==""))?"&nu=1":("&u="+encodeURIComponent(d)));this.baseParams=this.baseParams+("&l="+encodeURIComponent(document.location));if(f){this.baseParams+=("&qs="+encodeURIComponent(f))}});function TSACookie(h){this.name=h;this.path="/";if(TSACookie._theDomain==undefined){var f="";var g=document.domain.replace(/\s+/g,"").split(".");var b=g.length;while((b>0)&&(g[b-1].length==0)){b--}if(b>1){var d=2;if(g[b-1].length==2){d=3}if(b>=d){var a=b-1;var e=0;while((e<d)&&(a>=0)){var c=g[a--];if(c.length>0){f=("."+c+f);e++}}if(e<d){f=""}}}TSACookie._theDomain=f||TSAConst.DEFAULT_COOKIE_DOMAIN}this.domain=TSACookie._theDomain}TSACookie.prototype.set=function(c,a){if(this.name&&c){var b=(this.name+"="+escape(c)+(a?("; expires="+a.toGMTString()):"")+("; domain="+this.domain)+("; path="+this.path)+"");document.cookie=b}};TSACookie.prototype.get=function(){var c=null;var b=document.cookie;var e=this.name+"=";var d=b.indexOf("; "+e);if(d==-1){d=b.indexOf(e)}else{d+=2}if(d>=0){var a=document.cookie.indexOf(";",d);if(a==-1){a=b.length}var f=b.substring(d+e.length,a);if(f&&(f.length>0)){c=unescape(f)}}return c};function _BaseTSAAPI(b,e){this.debug=false;if(b!=undefined){this.siteID=b;this.waypointID=(e||"");this.backref=null;this.visitorCookie=new TSACookie(TSAConst.VISITOR_COOKIE_NAME_PREFIX+this.siteID);this.sessionCookie=new TSACookie(TSAConst.SESSION_COOKIE_NAME_PREFIX+this.siteID);this.instanceBaseParams="&s="+encodeURIComponent(this.siteID)+"&w="+encodeURIComponent(this.waypointID);this.setCookies();var g=null;var a=this._getBaseScriptName();var m=document.getElementsByTagName("script");for(var c=0;c<m.length;c++){var h=m[c].src;if(h){if(h.substring(0,a.length)==a){g=document.URL.substring(0,document.URL.lastIndexOf("/")+1);break}else{var k=new RegExp("^(https?://.+?/v2/[^/]+/)"+a,"i");var d=h.match(k);if(d&&(d.length>0)){g=d[1]}}}}if(!g){this.instanceBaseParams+="&_warn=1";var j=TSAConst.SERVER_HOSTNAME_BASE;var f=0;if(this.siteID){var l=this.siteID;if(l){f=(l%10);j+=f}}j+=("."+TSAConst.SERVER_DOMAIN);g=((document.location.protocol=="https:")?"https":"http")+"://"+j;g+=(TSAConst.BASE_SCRIPT_PATH+f+"/")}this.serverBaseURL=g}}_BaseTSAAPI.prototype.setReference=function(a){this.backref=a};_BaseTSAAPI.prototype.record=function(){if(this.siteID&&this.waypointID){var a=this._getRecordingURL(TSAConst.IMAGE_SCRIPT);_BaseTSAAPI._theImage=new Image();_BaseTSAAPI._theImage.src=a}};_BaseTSAAPI.prototype.setCookies=function(){var c=null;var b=this.visitorCookie.get();if(!b){if(!c){c=this._getUniqueKey()}b=(TSAConst.VISITOR_COOKIE_VALUE_PREFIX+c)}var a=new Date();a.setTime(a.getTime());expires=new Date(a.getTime()+(86400000*1000));this.visitorCookie.set(b,expires);var b=this.sessionCookie.get();if(!b){if(!c){c=this._getUniqueKey()}b=(TSAConst.SESSION_COOKIE_VALUE_PREFIX+c)}expires=new Date(a.getTime()+(3600000*4));this.sessionCookie.set(b,expires)};_BaseTSAAPI.prototype._setDebug=function(a){this.debug=a};_BaseTSAAPI.prototype._cleanInt=function(b){var a=parseInt(b);if(isNaN(a)){a=null}return a};_BaseTSAAPI.prototype._cleanFloat=function(b){var a=parseFloat(b);if(isNaN(a)){a=null}return a};_BaseTSAAPI.prototype._getInstanceParams=function(){var a=this.instanceBaseParams;if(this.backref){a+=("&b="+encodeURIComponent(this.backref))}return a};_BaseTSAAPI.prototype._getUniqueKey=function(){var a="";var d=32;var c=268435456;while(a.length<d){var b=Math.floor((Math.random()%1)*c);a+=b.toString(16)}a=a.substr(0,d);return a};_BaseTSAAPI.prototype._getBaseScriptName=function(){return"err1"};_BaseTSAAPI.prototype._getRecordingURL=function(a){return"err2"};function TSAConversion(b,c,d,a){this.typeName=b;this.setCount(c);this.setValue(d);this.setCOGS(a)}TSAConversion.prototype.setCount=function(a){this.count=a};TSAConversion.prototype.setValue=function(a){this.value=a};TSAConversion.prototype.setCOGS=function(a){this.cogs=a};TSAConversion.prototype.encode=function(){var a=encodeURIComponent(this.typeName);a+=("|"+(this.count?encodeURIComponent(this.count):1));a+=("|"+(this.value?encodeURIComponent(this.value):0));a+=("|"+(this.cogs?encodeURIComponent(this.cogs):0));a=("&c="+escape(a));return a};function TSATrackingAPI(a,b){_BaseTSAAPI.call(this,a,b);this.cpc=null;this.refcdTagName=TSAConst.SOURCE_PARAM;this.tsacrTagName=TSAConst.CREATIVE_PARAM;this.refcd=null;this.tsacr=null;this.conversions=new Array()}TSATrackingAPI.prototype=new _BaseTSAAPI();TSATrackingAPI.prototype.setCPC=function(a){this.cpc=a};TSATrackingAPI.prototype.setTagNames=function(a,b){if(a){this.refcdTagName=a}if(b){this.tsacrTagName=b}};TSATrackingAPI.prototype.setTagValues=function(b,a){if(b){this.refcd=b}if(a){this.tsacr=a}};TSATrackingAPI.prototype.addConversion=function(d,b,c,a){if(arguments.length>1||typeof(d)=="string"){this.conversions.push(new TSAConversion(d,b,c,a))}else{if(d){this.conversions.push(d)}}};TSATrackingAPI.prototype.getClickURL=function(b){var a="";if(b){a=this._getRecordingURL(TSAConst.REDIR_SCRIPT);a+=("&d="+escape(encodeURI(b)))}return a};TSATrackingAPI.prototype._getBaseScriptName=function(){return TSAConst.BASE_SCRIPT_NAME};TSATrackingAPI.prototype._getRecordingURL=function(f){var b="";if(this.siteID){var a=f||TSAConst.IMAGE_SCRIPT;b=(this.serverBaseURL+a+("?tsatime="+new Date().getTime())+TSAGlobal.baseParams+this._getInstanceParams()+e(TSAConst.SOURCE_PARAM,this.refcd,this.refcdTagName)+e(TSAConst.CREATIVE_PARAM,this.tsacr,this.tsacrTagName)+"");if(this.debug){b+="&debug="+(this.debug=="logonly"?this.debug:1)}if(this.cpc){b+=("&cpc="+encodeURIComponent(this.cpc))}var g=this.visitorCookie.get();if(g){b+=("&"+TSAConst.VISITOR_COOKIE_NAME_PREFIX+"="+g)}g=this.sessionCookie.get();if(g){b+=("&"+TSAConst.SESSION_COOKIE_NAME_PREFIX+"="+g)}for(var d=0;d<this.conversions.length;d++){b+=this.conversions[d].encode()}}return b;function e(i,h,k){var c="";var j=h;if(!j||(j=="null")){j=TSAGlobal.params[k]||null;if(j=="null"){j=null}}if(j){c=("&"+i+"="+encodeURIComponent(j))}return c}};var __tsaapi__=__tsaapi__||false;(function(){var b=function(f){if(f){if(typeof f=="function"){f()}else{if(f.constructor==Array){var e=f.length;for(var g=0;g<e;g++){b(f[g])}}}}};var d=function(){if(__tsaapi__){b(__tsaapi__);__tsaapi__=false}};if(window.addEventListener){window.addEventListener("load",d,false);window.addEventListener("beforeunload",d,false)}else{if(window.attachEvent){window.attachEvent("onload",d);window.attachEvent("onbeforeunload",d)}else{var a=window.onload||(function(){});window.onload=function(){d();a()};var c=window.onBeforeUnload||(function(){});window.onBeforeUnload=function(){d();c()}}}})();TSAConst.BUILD_ID="Pixel-Recording-altKeyStrategy release-2011-12-27-r31080-b1";
