var localSwitch= true;
//var localSwitch= false;

var globalJSFile = "Global_Layer.js";

loadScript(globalJSFile);


function createCookie(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 readCookie(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 eraseCookie(name) { createCookie(name,"",-1); }


function Hitit(){
	//Survey Cookie 
	var surveyCookieName = "COOK_SURVEY";
	var surveyCookieValue = "COOK_SURVEY_COOKIE";
	var surveyCookieValueRet;

	var testCookieName="COOK_TEST";
	var testCookieValue="COOK_TEST_COOKIE";
	var testCookieValueRet;
		
	createCookie(testCookieName,testCookieValue,1);
	testCookieValueRet = readCookie(testCookieName); 

	surveyCookieValueRet = readCookie(surveyCookieName);	
	
	var rndNum= Math.floor ((Math.random()*10));		    		

//alert(rndNum);
//alert(testCookieValueRet);
//alert(surveyCookieValueRet);
	if (rndNum < 3 && testCookieValueRet != null && surveyCookieValueRet == null) {	
	    
	    // Adjust path to invitation url from current webpage
	    var invitationLink = "survey_invite.html"

	    documentURL = String(document.location);

	    startPosition = documentURL.indexOf("//");

        endPosition = documentURL.indexOf("?");
      
        if (startPosition == -1) startPosition = 0
        if (endPosition == -1) endPosition = documentURL.length 
        
        documentURL = documentURL.substring(startPosition + 2, endPosition);   
        var nbDirs= documentURL.match(/(\/)/g);
             
        for (var i = 1; i < nbDirs.length; i++)     
            invitationLink = "" + invitationLink		
	
 
	createCookie(surveyCookieName, surveyCookieValue, 90);		
        showLayer(invitationLink, 460, 420, true, 0.00, "NoHide");
	}
	
	eraseCookie(testCookieName);	
}


function loadScript(file){
//alert('here is the problem');
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = file;

	if (typeof(script.onreadystatechange) == 'undefined') // W3C
		script.onload = function(){ this.onload = null;  };

	else // IE
		script.onreadystatechange = function(){ if (this.readyState != 'loaded' && this.readyState != 'complete') return; this.onreadystatechange = null;  }; // Unset onreadystatechange, leaks mem in IE

	document.getElementsByTagName('head')[0].appendChild(script);
}




