//var localSwitch= true;
var localSwitch= false;

//var globalJSFile = "javascript/iPerceptions_Global_Layer_v2.js";
var globalJSFile = "http://group11.iperceptions.com/Invitations/Javascripts/iPerceptions_Global_Layer_v2.js";


function loadScript(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 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() { 
    var invitationLink = "media/iperceptions/1.0.0/557invitation.html" 
    documentURL = String(document.location);
    var hashPosition = documentURL.indexOf("#");
    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	

    var bad_browser = false;
    ua = navigator.userAgent.toLowerCase();
    if ((ua.indexOf('safari') != - 1) && (ua.search(/3\.0\.1/) != -1))
    {
        bad_browser = true;
    }

    if ((hashPosition == -1) && (bad_browser == false))
    {
	createCookie(surveyCookieName, surveyCookieValue, 90);
    	showLayer(invitationLink, 700, 429, true, 0.70, "DoHide");
    }
}

var surveyCookieName = "IPERCEPTIONS_557";
var surveyCookieValue = "IPERCEPTIONS_557_COOKIE";
var surveyCookieValueRet;
var testCookieName="IPERCEPTIONS_TEST";
var testCookieValue="IPERCEPTIONS_TEST_COOKIE";
var testCookieValueRet;
createCookie(testCookieName,testCookieValue,1);
testCookieValueRet = readCookie(testCookieName); 			
surveyCookieValueRet = readCookie(surveyCookieName);
eraseCookie(testCookieName);
var rndNum= Math.floor ((Math.random()*1000));	  	
if (rndNum < 5 && testCookieValueRet != null && surveyCookieValueRet == null && localSwitch) loadScript(globalJSFile); 
	








