var browser = new BrowserDetect();
//var localSwitch = true;
var localSwitch= false;// rate set to zero, change when re-activating

var _http = document.location.protocol;
var _url = document.location.host; // "http://www.pagesjaunes.ca/index.html"; //"http://www.yellowpages.ca/index.html";// 
var _lang = 1; // default english
var gJSFile = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_678_ww.js";


// Site language
if (_url.match(/pagesjaunes.ca/g)) { _lang = 2; }


//Serve French invitation
if (_lang == 2) { gJSFile = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_678_fr_ww.js"; }


//**********Custom hitbox call***********
//added Dec.17,2009 PT
//GUID creation
function generateGuid() {
    var result, i, j;
    result = '';
    for (j = 0; j < 8; j++) {
        if (j == 8 || j == 12 || j == 16 || j == 20)
            result = result + '-';
        i = Math.floor(Math.random() * 16).toString(16).toUpperCase();
        result = result + i;
    }
    return result
}
var _guid = generateGuid();


//*************************************

function BrowserDetect() {
    ua = navigator.userAgent.toLowerCase(); this._string = navigator.userAgent.toLowerCase();
    this.isOpera = (ua.indexOf('opera') != -1); this.isGecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
    this.isIE = (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1));
    this.isMozilla = (this.isGecko && ua.indexOf('gecko/') + 14 == ua.length);
    this.isFirefox = (ua.indexOf('firefox') != -1);
}

function lScript(file) {
    var script = document.createElement('script');
    script.type = 'text/javascript'; script.src = file;
    if (typeof (script.onreadystatechange) == 'undefined')
        script.onload = function() { this.onload = null; };
    else
        script.onreadystatechange = function() { if (this.readyState != 'loaded' && this.readyState != 'complete') return; this.onreadystatechange = null; };

    document.getElementsByTagName('head')[0].appendChild(script);
}

function CC(name, value, days) {
    if (days) { var expDate = new Date(); expDate.setTime(expDate.getTime() + (days * 24 * 60 * 60 * 1000)); var expires = "; expires=" + expDate.toUTCString(); }
    else var expires = ''; document.cookie = name + '=' + value + expires +';';
}

function RC(NameOfCookie) {
    if (document.cookie.length > 0) {
        begin = document.cookie.indexOf(NameOfCookie + "=");
        if (begin != -1) {
            begin += NameOfCookie.length + 1; end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end));
        }
    }
    return null;
}

function EC(name) { CC(name, "", -1); }

function Exec() {
    var sCName = "IPERCEPTIONS_678"; var sCVal = "iPe_678_User";
    //for beta site
//    var today = new Date();
//    var betaCookie = "ipe678beta"; var betaCookieVal = "ip=&Date=" + today.toUTCString();
    var sCN = "IPE_S_678"; var sCV = "IPE_678_Session"; var sCVR; sCVR = RC(sCN);
    var sCValRet; var tCVName = "IPERCEPTIONS_TEST"; var tCVVal = "iPe_Test"; var tCVValRet;
    CC(tCVName, tCVVal, 1);
    tCVValRet = RC(tCVName);
    sCValRet = RC(sCName);
    EC(tCVName);
    var rndNum = Math.floor((Math.random() * 100 ));

    //Oct. 23rd 2009 : rate = 50% 
    //Dec29.: rate =75%
    //Jan. 26th 2010 - rate: 75%
    //Jan. 26th 2010 3:15 pm - rate: 50%
    //Jan. 28th 2010 9:54 am - rate: 25%
    if (rndNum < 75 && tCVValRet !== null && sCVR === null && sCValRet === null) {
        CC(sCName, sCVal, 90); lScript(gJSFile); //CC(betaCookie, betaCookieVal, 1);
    }

    if (sCVR === null) { CC(sCN, sCV); }
}

if (localSwitch) {
    var GJS = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_Global.js"; lScript(GJS);
}	
	


