/* This source code is Copyright (c) Tailsweep 2007-2010 */
if (typeof(rightScriptIdx)=="undefined") {var rightScriptIdx=1;}

if(window.tailsweep_currPos_right_script!=null)
{
    window.tailsweep_currPos_right_script++
}
else
{
    window.tailsweep_currPos_right_script=1
}
if(window.tailsweep_currPos_right_script == rightScriptIdx )
{
    if (typeof(tsId)=="undefined") {var tsId=0;}
    if (typeof(tsMId)=="undefined") {var tsMId=0;}
    if (typeof(tsUrl)=="undefined") {var tsUrl="";}

    var _tsbd=document;
    var _tsdl=_tsbd.location;
    var _tsdlh = "";
    var _tsBH = "";
    var _tsDM= "";
    var _tsHO = "";
    var _tsLP = "";
    var _tsQu = "";
    var _tsT =  "";
    var _tsRef = "";
    var _tsCh = "";
    
    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);}
    //if (_tsbd.title && _tsbd.title != "") { _tsT = _tsES(_tsbd.title); }

    var nTsUrl="";
    if(tsUrl != "")
    {
        //tsUrl = _tsES(tsUrl);
        nTsUrl = escape(tsUrl);
    }
    
    var _tsUrl = "http://script.tailsweep.com/adrenderer.do?tsId="+tsId+"&tsMId="+tsMId+"&pid=1&display=javascript&campaignType=2" + tsGetUrl()+"&tsUrl="+nTsUrl;
    var url = "<scr"+"ipt src='"+_tsUrl+"' type='text/javascript' charset='utf-8'/></scr"+"ipt>";
    document.write(url);
}

function tsGetUrl()
{
    var s="";
    s+="&tsT=" + _tsT;
    s += "&tsLho=" + _tsHO;
    s += "&tsCh=" + _tsCh;
    //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 _tsVoid() { return; }


function _tsES(s,u) {
    if (typeof(encodeURIComponent) == 'function') {
        if (u) return encodeURI(s);
        else return encodeURIComponent(s);
    } else {
        return escape(s);
    }
}

// public method for url encoding
function urlEncode (string)
{
    return escape(utf8_encode(string));
}

// public method for url decoding
function urlDecode(string)
{
    return utf8_decode(unescape(string));
}

function utf8_encode(string)
{
    string = string.replace(/\r\n/g,"\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return utftext;
}

function utf8_decode(utftext)
{
    var string = "";
    var i = 0;
    var c = c1 = c2 = 0;

    while ( i < utftext.length ) {

        c = utftext.charCodeAt(i);

        if (c < 128) {
            string += String.fromCharCode(c);
            i++;
        }
        else if((c > 191) && (c < 224)) {
            c2 = utftext.charCodeAt(i+1);
            string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        }
        else {
            c2 = utftext.charCodeAt(i+1);
            c3 = utftext.charCodeAt(i+2);
            string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }

    }

    return string;
}

function getRand()
{
    return Math.round(Math.random()*2147483647);
}