//HISTORY
//Invitation modified 03/16/09 by PT
//04/08/09: Added separate counter in GetInv by PT

var localSwitch= true;
//var localSwitch= false;

/*code to block IE 6*/
var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
if(IE6) { localSwitch= false; }

var ct= ""; var l= 1;  var country= ""; var rate= 0; var url= location.href; var browser = new BrowserDetect(); var curDom= document.domain;
var siteID="";var _http = document.location.protocol;
var gJSFile = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_643.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); }
   
 // Look for Country identification in the URL and branch to the correct Country Layer
//rates increased on 04/06/2009 by PT

function GetInv() {    
    if (url.indexOf('/en/') != -1) { country= "";   siteID="1";   rate= 18; }                              //English
    else if (url.indexOf('/de/') != -1) { country= "_de";   siteID="5";    rate=213; }                   //German                            
    else if (url.indexOf('/cn/') != -1) { country= "_cs";   siteID="6";   rate=500; }                   //Simplified Chinese  
    else if (url.indexOf('/hk/') != -1) { country= "_ct";    siteID="7";   rate=500; }                   //Traditional Chinese  
    else if (url.indexOf('/fr/') != -1) { country= "_fr";   siteID="2";       rate=500; }                     //French
    else if (url.indexOf('/ja/') != -1) { country= "_jp"; siteID="8";        rate=75; }                    //Japanese                         
    else if (url.indexOf('/ko/') != -1) { country= "_kr";  siteID="9";     rate=500; }                   //Korean
    else if (url.indexOf('/pt/') != -1) { country= "_pt";   siteID="4";    rate=500; }                   //Portuguese
    else if (url.indexOf('/es/') != -1) { country= "_es"; siteID="3";      rate=500; }                 //Spanish
   else   { country= "";  siteID="1"; rate= 1000; }                
 } 
     
   

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); }

GetInv()	

function Exec() {
	var sCName = "IPERCEPTIONS_643"; var sCVal = "IPERCEPTIONS_643_COOKIE";
	var sCValRet; var tCVName="IPERCEPTIONS_TEST"; var tCVVal="IPERCEPTIONS_TEST_COOKIE"; var tCVValRet;
	CC(tCVName,tCVVal,1);
	tCVValRet = RC(tCVName); 			
	sCValRet = RC(sCName);
	EC(tCVName);
	var rndNum= Math.floor ((Math.random()*1000));	  	

	if (rndNum < rate && tCVValRet != null && sCValRet == null) {
    CC(sCName, sCVal, 90); lScript(gJSFile);
	}
}



if (localSwitch) {
//alert("Calling layer643.js");
	var GJS = _http + "//ipinvite.iperceptions.com/Invitations/Javascripts/Layer_Global.js"; lScript(GJS);
}	
	


