/* This source code is Copyright (c) Tailsweep 2007-2008 */
var tsTools = new Object();
tsTools.isDebug = function(){
if(window.location.href.indexOf('tsDebug=1') != -1){
return true;
}
else{
return false;
}
}
tsTools.getQParamFromStr = function(str, paramName){
var regex = new RegExp("[\\?&]"+paramName+"=([^&#]*)");
var qParam = regex.exec(str);
if(qParam == null){
return "";
}
return qParam[1];
}
tsTools.getQParam = function(paramName){
return tsTools.getQParamFromStr(window.location.href, paramName);
}
tsTools.PosPopUp = function(id,x,y,offset)
{
var el = document.getElementById(id);
el.style.left=x+offset;
el.style.top=y-document.body.scrollTop+offset;
}
var countryCode=tsTools.getQParam('tsCountryCode') ||"US";
var regionCode=tsTools.getQParam('tsRegionCode') ||"%REGION_CODE%";
//var countryCode = "%COUNTRY_CODE%";
//var regionCode = "%REGION_CODE%";
var headerShown = "false";
var placement = "top";
var success = 0;
if (typeof(tsUrl)=="undefined") {var tsUrl="";}
if (typeof(tsPlacementConfig)=="undefined") {var tsPlacementConfig = new Array();}
var _tsbd=document;
var _tsdl=_tsbd.location;
var _tsdlh = "";
var _tsBH = "";
var _tsDM= "";
var _tsHO = "";
var _tsLP = "";
var _tsQu = "";
var _tsT =  "";
var _tsFpc = "";
var _tsSession =  "";
var _tsUid = "";
var _tsUV = "";
var _tsRef = "";
if (_tsdl.hostname && _tsdl.hostname != "") { _tsHO = _tsES(_tsdl.hostname); }
if (_tsdl.search && _tsdl.search != "") { _tsQu = _tsES(_tsdl.search); }
if (_tsdl.hash && _tsdl.hash != "") { _tsdlh=_tsdl.href.substring(_tsdl.href.indexOf('#')); }
if (_tsbd.domain &&  _tsbd.domain != "") {  _tsDM = _tsbd.domain; }
if(_tsdl.pathname && _tsdl.pathname != "") { _tsLP = _tsdl.pathname;}
if(_tsbd.referrer && _tsbd.referrer != "") { _tsRef = _tsES(_tsbd.referrer);}
var nTsUrl="";
if(tsUrl != "")
{
nTsUrl = escape(tsUrl);
}
_tsSession = getCookieValue("ts_session") ? getCookieValue("ts_session") : "";
_tsUid = getCookieValue("ts_uid") ? getCookieValue("ts_uid") : "";
_tsUV = getCookieValue("ts_uv") ? getCookieValue("ts_uv") : "";
function tsGetUrl()
{
var s="";
s+="&tsUUI="+getRand();
//s+="&tsT=" + _tsT;
s += "&tsLho=" + _tsHO;
s += "&tsLha=" + _tsdlh;
s += "&tsQu=" + _tsQu;
s += "&tsRef=" + _tsRef;
s += "&tsLP="+_tsLP + getBrowserProperties();
return s;
}
function getBrowserProperties()
{
return '&tsSW='+self.screen.width+'&tsSH='+self.screen.height+'&tsSC='+self.screen.colorDepth+'&tsPD='+self.screen.pixelDepth;
}
function isSet()
{
var a = arguments; var l = a.length; var i=0;
while ( i != l )
{
if (typeof(a[i])=='undefined' || a[i] == undefined || a[i] == '')
{
return false;
}
else
{
i++;
}
}
return true;
}
function _tsES(s,u) {
if (typeof(encodeURIComponent) == 'function') {
if (u) return encodeURI(s);
else return encodeURIComponent(s);
} else {
return escape(s);
}
}
function getRand()
{
var uu=Math.round(Math.random()*2147483647);
return uu;
}
function getRandomNr(max)
{
var ranNum= Math.floor(Math.random()*(max));
return ranNum;
}
function TsHash()
{
this.length = 0;
this.items = new Array();
for (var i = 0; i < arguments.length; i += 2) {
if (typeof(arguments[i + 1]) != 'undefined') {
this.items[arguments[i]] = arguments[i + 1];
this.length++;
}
}
this.remove = function(in_key)
{
var tmp_value;
if (typeof(this.items[in_key]) != 'undefined') {
this.length--;
var tmp_value = this.items[in_key];
delete this.items[in_key];
}
return tmp_value;
}
this.get = function(in_key) {
return this.items[in_key];
}
this.put = function(in_key, in_value)
{
if (typeof(in_value) != 'undefined') {
if (typeof(this.items[in_key]) == 'undefined') {
this.length++;
}
this.items[in_key] = in_value;
}
return in_value;
}
this.hasItem = function(in_key)
{
return typeof(this.items[in_key]) != 'undefined';
}
}
function tsPlacementHit()
{
var _tsPlUrl = "http://script.tailsweep.com/siteplacementhit/97876" + "?sitePlacements=4,"+window.tailsweep_currPos_top +"&tsSession="+_tsSession+"&tsUid="+_tsUid+"&tsUV="+_tsUV+"&tsUrl="+nTsUrl+tsGetUrl();
var plurl = "<img src='"+_tsPlUrl+"' border='0' width='0' height='0' style='width:0px;height:0px;margin: 0 auto;padding:0;border-style:none;border-width:0' alt='' />";
document.write(plurl);
}
function writeSessionCookie (cookieName, cookieValue) {
if (testSessionCookie()) {
document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
return true;
}
else return false;
}
function writePersistentCookie (CookieName, CookieValue, periodType, offset) {
var expireDate = new Date ();
offset = offset / 1;
var myPeriodType = periodType;
switch (myPeriodType.toLowerCase()) {
case "years":
var year = expireDate.getYear();
// Note some browsers give only the years since 1900, and some since 0.
if (year < 1000) year = year + 1900;
expireDate.setYear(year + offset);
break;
case "months":
expireDate.setMonth(expireDate.getMonth() + offset);
break;
case "days":
expireDate.setDate(expireDate.getDate() + offset);
break;
case "hours":
expireDate.setHours(expireDate.getHours() + offset);
break;
case "minutes":
expireDate.setMinutes(expireDate.getMinutes() + offset);
break;
default:
alert ("Invalid periodType parameter for writePersistentCookie()");
break;
}
document.cookie = escape(CookieName ) + "=" + escape(CookieValue) + "; expires=" + expireDate.toGMTString() + "; path=/";
}
function testSessionCookie () {
document.cookie ="testSessionCookie=Enabled";
if (getCookieValue ("testSessionCookie")=="Enabled")
return true
else
return false;
}
function getCookieValue (cookieName) {
var exp = new RegExp (escape(cookieName) + "=([^;]+)");
if (exp.test (document.cookie + ";")) {
exp.exec (document.cookie + ";");
return unescape(RegExp.$1);
}
else return false;
}
function testPersistentCookie () {
writePersistentCookie ("testPersistentCookie", "Enabled", "minutes", 1);
if (getCookieValue ("testPersistentCookie")=="Enabled")
return true
else
return false;
}
function showHeader()
{
var h = "<div><a class='tailsweep-link' href='http://www.tailsweep.com/'><img border='0' src='http://files.tailsweep.com/resources/ts_adheader_250_sv.png' width='250' height='9' alt='' style='padding:0;margin: 0 auto;border-style:none;border-width:0'/></a></div>";
document.write(h);
}
function incrementCookie(id,frequence,frequenceDays)
{
if(frequence != '' && frequence > 0)
{
var cval = getCookieValue("ts_ad_"+id);
if(!cval)
{
cval = 0;
}
if(cval < frequence)
{
cval++;
//SetCookie("ts_ad_"+id, cval, frequenceDays, "/", _tsHO, undefined);
writePersistentCookie ("ts_ad_"+id, cval, "days", frequenceDays);
return true;
}
return false;
}
return true;
}
function incrementSessionCookie(id, sessionFrequence)
{
if(sessionFrequence != '' && sessionFrequence > 0)
{
var cval = getCookieValue("ts_ad_session"+id);
if(!cval)
{
cval = 0;
}
if(cval < sessionFrequence)//8
{
cval++;
writeSessionCookie("ts_ad_session"+id, cval);
return true;
}
return false;
}
return true;
}
function isInCountry(adCountryCode)
{
var isin = (adCountryCode == '0' || adCountryCode == 0 || adCountryCode == '' || adCountryCode == countryCode || countryCode == "%COUNTRY_CODE%");
return isin;
}
function isInRegion(adRegionCode)
{
var isin = (adRegionCode == '0' || adRegionCode == 0 || adRegionCode =='' || adRegionCode == regionCode || regionCode == "%REGION_CODE%");
return isin;
}
function TsAd(url, width, height, id, countryCode, regionCode, sov, frequence, frequenceDays, sessionFrequence, startDate, endDate) {
this.url = url;
this.width = width;
this.height = height;
this.id = id;
this.countryCode = countryCode;
this.regionCode = regionCode;
this.sov = sov;
this.frequence = frequence;
this.frequenceDays = frequenceDays;
this.sessionFrequence = sessionFrequence;
this.startDate = startDate;
this.endDate = endDate;
}
function renderAd(myTsAd)
{
var adCountryCode = myTsAd.countryCode;
var adRegionCode = myTsAd.regionCode;
var sov = myTsAd.sov;
var randNr = getRandomNr(100);
var diff = 1;
/*
if(isSet(myTsAd.endDate))
{
diff = myTsAd.endDate - new Date();
}
*/
var sovOK = (randNr <= sov) ? true: false;
var uniqueOK = incrementCookie(myTsAd.id,myTsAd.frequence, myTsAd.frequenceDays);
var sessionUniqueOK = incrementSessionCookie(myTsAd.id,myTsAd.sessionFrequence);
var inCountry = isInCountry(adCountryCode);
var inRegion = isInRegion(adRegionCode);
var allOK = diff > 0 && sovOK && uniqueOK && sessionUniqueOK && inCountry && inRegion;
if(allOK)
{
if(headerShown == "false")
{
headerShown = "true";
showHeader();
}
++success;
if(success > 1)
{
document.write("<img border='0' src='http://files.tailsweep.com/resources/pix.gif' height='10' width='1' alt='vspacer' style='width:1px;height:10px;margin: 0 auto;padding:0;border-style:none;border-width:0' />");
}
document.write('<div style="height:'+myTsAd.height+'px;">');
document.write("<iframe src='" + myTsAd.url +"'  name='tsIframe_" + myTsAd.id + "' width='" + myTsAd.width + "' height='" + myTsAd.height + "' vspace='0' hspace='0' allowtransparency='true' scrolling='no' marginwidth='0' marginheight='0' frameborder='0' style='width:"+ myTsAd.width + "px; height:" + myTsAd.height + "px; border: 0px;'></iframe>");
document.write("</div>");
}
}
function renderAds(ads, maxAds)
{
var adsTotal = ads.length;
if(adsTotal > maxAds)
{
var ml = 20;
for (var x = 0; x < ml; x++)
{
var random = getRandomNr(ads.length);
var myTsAd = ads[random];
ads.splice(random, 1);
/*var myTsAd = ads[0];
ads.splice(0, 1);*/
renderAd(myTsAd);
if(success == maxAds || ads.length == 0)
break;
}
}
else
{
for(var x = 0;x < adsTotal; x++)
{
//var random = getRandomNr(ads.length);
//var myTsAd = ads[random];
//ads.splice(random, 1);
var myTsAd = ads[0];
ads.splice(0, 1);
renderAd(myTsAd);
}
}
}
function geoCallback(myTsAd)
{
/*if(headerShown == "false")
{
headerShown = "true";
showHeader();
}*/
var el = document.getElementById(myTsAd.divId);
var s = "";
s += "<iframe src='" + myTsAd.url +"' name='tsIframe_" + myTsAd.id + "'  width='" + myTsAd.width + "' height='" + myTsAd.height + "' vspace='0' hspace='0' allowtransparency='true' scrolling='no' marginwidth='0' marginheight='0' frameborder='0' style='width:"+ myTsAd.width + "px; height:" + myTsAd.height + "px; border: 0px;'></iframe>";
s += "<img border='0' src='http://files.tailsweep.com/resources/pix.gif' height='10' width='1' alt='vspacer' style='width:1px;height:10px;margin: 0 auto;padding:0;border-style:none;border-width:0' />";
el.innerHTML = s;
}
if (typeof(topIdx)=="undefined") {var topIdx=1;}
if(window.tailsweep_currPos_top!=null)
{
window.tailsweep_currPos_top++;
}
else
{
window.tailsweep_currPos_top=1;
}
//Placement type 0
//type==?
if(window.tailsweep_currPos_top == topIdx )
{
if(tsTools.isDebug() || true)
{
if(typeof(tsAdStyle)=="undefined") {var tsAdStyle='text-align: center';}
document.write('<style type="text/css">.tailsweep-div{font-family: arial,verdana,sans-serif;font-size: 12px;color: #000000;margin: 0 auto; padding: 0; display: block;} .smallBr{font-size: 1px;line-height: 0;} .tailsweep-host,.tailsweep-host:link{color:green;font-size:10} .tailsweep-buylink:link{color:#00c;font-size:12px} .tailsweep-buylink:visited{color:#551a8b;font-size:12px} .tailsweep-buylink:active {color:red;font-size:12px} .tailsweep-link:link {color:#00c;font-size:12px;font-weight:bold} .tailsweep-link:visited {color:#551a8b;font-size:12px} .tailsweep-link:active {color:red;font-size:12px} .tailsweep-title:link {color:#00c;font-size:12px;font-weight:bold} .tailsweep-title:visited {color:#551a8b;font-size:12px} .tailsweep-title:active {color:red;font-size:12px} .tailsweep-title:hover {color:#00c;font-size:16px;text-decoration: underline;}</style>');
document.write("<div class='tailsweep-div' id='tailsweep-div-top' style='"+tsAdStyle+"'>");
if(tsTools.isDebug())
{
var randPopUpId = getRandomNr(1000);
document.write('<div id="tsDebugPop_'+randPopUpId+'" style="display:none;border:#666 1px solid;width:200px;height:110px;text-align:left;background:#eee;position:fixed;z-index:99;left:40%;top:40%;padding:0px 5px 10px 5px;"><p style="cursor:pointer;text-align:right;margin:0px;" onclick="this.parentNode.style.display=\'none\';">X</p>Height<br/><input onkeyup="document.getElementById(\'tsDebugAd_'+randPopUpId+'\').style.height=this.value+\'px\';"><br />Width:<br/><input onkeyup="document.getElementById(\'tsDebugAd_'+randPopUpId+'\').style.width=this.value+\'px\';"></div>');
document.write('<button id="tsDebugAd_'+randPopUpId+'" onclick="tsTools.PosPopUp(\'tsDebugPop_'+randPopUpId+'\',this.offsetLeft,this.offsetTop,20);document.getElementById(\'tsDebugPop_'+randPopUpId+'\').style.display=\'block\';" style="border:#000 0px solid;background-image:none;background-color:#ff17fc;text-align:center;font-size:12px;color:#fff; ' );
var H=tsTools.getQParam('tsHT') ||"130";
var W=tsTools.getQParam('tsWT') ||"740";
document.write(' height:'+H+'px;width:'+W+'px;">Tailsweep Debug<br />top');
document.write('</button>');
}
else
{
var tsGlobalAdsInit_top = "";
if (typeof(tsGlobalAds_top)=='undefined')
{
var tsGlobalAds_top = new Array();
tsGlobalAdsInit_top = "1"
}
var ads = new Array();
var fillerAds = new Array();
if(success == 0 && window.tailsweep_backupAd_top!=1){window.tailsweep_backupAd_top=1; document.write("<br /> <scr"+"ipt type=\"text/javascript\"> google_ad_client = \"pub-1778208752617786\"; google_ad_slot = \"3250567928\"; google_ad_width = 728; google_ad_height = 90; </scr"+"ipt> <scr"+"ipt type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"> </scr"+"ipt> ");}
}
document.write('</div>');
}
//document.write("<img id='ts_top' border='0' src='http://files.tailsweep.com/resources/pix.gif' height='0' width='0' alt='vspacer' style='display:none; width:0px;height:0;margin: 0 auto;padding:0;border-style:none;border-width:0' />");
tsPlacementHit();
}
