﻿//Axa English invitation

var browser = new BrowserDetect(); 

//var localSwitch = true;
var localSwitch= false;

var _http = document.location.protocol;

//If Google Chrome : don't serve
try { if (browser.isChrome) { localSwitch = false; } } catch (Err) { }

//var gJSFile = "javascript/Layer_XXX.js";

var url = document.location.href;

/***********************************************/
//var ext = (url.indexOf('axa.ca/fr') != -1) ? '_fr' : '_en';
var ext = (iPerc_lang != null && iPerc_lang != 'undefined' && iPerc_lang.toLowerCase() == 'fr') ? '_fr' : '_en';
var gJSFile = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_751" + ext + ".js";

//var gJSFile = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_751_en.js";
/***********************************************/

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);
   this.isChrome = (ua.indexOf('chrome') != -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+"; path=/";
}

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 to add page counter into session cookie*/
var show = false;
var counter = '0';
function checkCookie(cookie) {

    try {
        counter = parseInt(RC(cookie));
        counter = counter + 1;
        CC(cookie, counter);
    } catch (e) { show = false; }
    return counter;
}
/********************************/

function Exec() {

    var sCName = "IPERCEPTIONS_751"; var sCVal = "iPe_751_User";
    var sCN = "IPE_Count_751"; var sCV = '0'; 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));
    //if session cookie >2 enabled invitation display
    var count = checkCookie(sCN); if (count >= 2) { show = true; }

    //June 19, 2011: 50%

    if (rndNum < 100 && tCVValRet !== null && sCValRet === null && show) {
        CC(sCName, sCVal, 90); lScript(gJSFile);
    }

    if (sCVR == null) { CC(sCN, sCV); }
}

if (localSwitch) {
    var GJS = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_Global_aicollect.js"; lScript(GJS);
}	
	

//function Exec() 
//{
//	var sCName = "IPERCEPTIONS_751"; var sCVal = "iPe_751_User";
//	var sCN = "IPE_S_751"; var sCV = "IPE_751_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));

//    //April 19, 2010: 40%
//    //April 16, 2010: 20%
//	//April 9, 2010: 100%
//	//April 13th 2010: 0%
//	//April 15th 201: 5%
//    //July 6, 2010: 70%
//    //December 16 2010: 100%
//	if (rndNum < 50 && tCVValRet !== null && sCVR === null && sCValRet === null) {
//    		CC(sCName, sCVal, 90); lScript(gJSFile);
//	}

//   if (sCVR == null) {CC(sCN, sCV);}
//}



//if (localSwitch) {
//    var GJS = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_Global_aicollect.js"; lScript(GJS);
//}	
	



