var sCookieName = 'ent_mkt';
var sPreStitialCookie = "prestitial";
var sStitialCookie = 'stitialcookie';
var sNoStitial = 'nostitial';
var sNoHomePageStitial = 'nohpstitial';
// Set hour expiration
var lnNoStitialExpiredHours = 24;
var myPath = location.pathname;

function GetCookie2 (name) { 
    var arg = name + "="; 
    var alen = arg.length; 
    var clen = document.cookie.length; 
    var i = 0; 
    while (i < clen) { 
        var j = i + alen; 
        if (document.cookie.substring(i, j) == arg) return getCookieVal2 (j); 
        i = document.cookie.indexOf(" ", i) + 1; 
        if (i == 0) break; 
    } 
    return null; 
} 
function getCookieVal2(offset) { 
    var endstr = document.cookie.indexOf(";", offset); 
    if (endstr == -1) { endstr = document.cookie.length; }
    return unescape(document.cookie.substring(offset, endstr)); 
}
function setCookie2(c_name,value,expiredays){
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function writeCookie(c_name, value, expireminutes){    
    var exdate = new Date();
    var nowLong = exdate.getTime();    
    nowLong = nowLong + (1000 * 60 * expireminutes); 
    exdate.setTime(nowLong);
    document.cookie = c_name+ "=" +escape(value)+((expireminutes==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";
}
function displayInterstitial()  {
    if (!(myPreStitialCookie!=null && myPreStitialCookie!="")) {  
        if (!(myStitialCookie!=null && myStitialCookie!="")) 
            window.location.href = "/interstitial/Ent_Interstitial.aspx?URL=" + myPath;     
    }
}
function displayHomePageInterstitial()  {
    if (!(myPreStitialCookie!=null && myPreStitialCookie!="")) {   
        var expiredInMinute = 3; // minutes
        writeCookie(sPreStitialCookie, 20, expiredInMinute); 
    }
    if (!(mycookie!=null && mycookie!="")) {   
       setCookie2(sCookieName, 12, 1);
       window.location.href = "/interstitial/default.html";   
    }
}
//NOT showing the interstitial on these pages  
switch (myPath)
{
    case "/eventconfirm.aspx":
        writeCookie(sNoStitial, sNoStitial, lnNoStitialExpiredHours*60);
        break;
    default:
        break;    
}    
mycookie = GetCookie2(sCookieName);
myPreStitialCookie = GetCookie2(sPreStitialCookie);
myStitialCookie = GetCookie2(sStitialCookie);
myNoStitialCookie = GetCookie2(sNoStitial);
myNoHomePageStitialCookie = GetCookie2(sNoHomePageStitial);

if ((myPath == "/home.html") || (myPath == "/index.html") || (myPath == "/")) {  
    //************* FOR HOME PAGE INTERSTITIAL ******************
    // -- turns off: uncomment out line below
    //var showHomeStitial = -1; 
    // -- shows: uncomment out line below
    var showHomeStitial = 10;  
	// -- shows randomly: uncomment out line below
    //var showHomeStitial = Math.floor(Math.random()*10); 
    if (myNoHomePageStitialCookie!=null && myNoHomePageStitialCookie!="")
    {   
       showHomeStitial = 99; // no show interstitial
    } 
    switch (showHomeStitial) {
		// case 0-9 = % of page shown. Add more cases for higher frequency
        case 0: 
            displayHomePageInterstitial(); 
            break;
        case 1:
            displayHomePageInterstitial(); 
            break;  
        case 2:
            displayHomePageInterstitial(); 
            break;  
        case 3:
            displayHomePageInterstitial(); 
            break;  			
        case 4:
            displayHomePageInterstitial(); 
            break;  
        case 5:
            displayHomePageInterstitial(); 
            break; 

		// DO NOT EDIT THIS BELOW
		case -1: //turns off interstitial
            break;    
        case 10: //shows interstitial
            displayHomePageInterstitial(); 
            break;
        default: 
            if (!(mycookie!=null && mycookie!="")) {
                if (!(myNoHomePageStitialCookie!=null && myNoHomePageStitialCookie!="")) {   
                    writeCookie(sNoHomePageStitial, sNoHomePageStitial, lnNoStitialExpiredHours*60);   
                } 
            } 
            if (!(myPreStitialCookie!=null && myPreStitialCookie!="")) {   
                var expiredInMinute = 3; // minutes
                writeCookie(sPreStitialCookie, 20, expiredInMinute); 
            }
            break;
    }
}
else    {
	// ********** ONLY ONE OF THESE CAN BE UNCOMMENTED ***********
	// -- turns off: uncomment out line below
    var showInterstitial = -1; 
    // -- shows all: uncomment out line below
    //var showInterstitial = 10;  
	// -- shows randomly: uncomment out line below
	//the random number will fall between 0-9; this # sets the range, the higher the number, higher the range
	//ie 10 = 0-9,  100 = 0-99
    //var showInterstitial = Math.floor(Math.random()*10); 
   if (myNoStitialCookie!=null && myNoStitialCookie!="")
    {   
       showInterstitial = 99; // no show interstitial
    } 
    switch( showInterstitial) {
		// case 0-9 = % of page shown. Add more cases for higher frequency
        case 0: 
            displayInterstitial(); 
            break;
        case 1: 
            displayInterstitial(); 
            break;
        case 2: 
            displayInterstitial(); 
            break;
        case 3: 
            displayInterstitial(); 
            break;
        case 4: 
            displayInterstitial(); 
            break;
		// DO NOT EDIT THIS BELOW
		case -1: //turns off interstitial
            break;    
        case 10: //shows interstitial
            displayInterstitial(); 
            break;
        default: 
            if (!(myStitialCookie!=null && myStitialCookie!="")) {
                if (!(myNoStitialCookie!=null && myNoStitialCookie!="")) {   
                    writeCookie(sNoStitial, sNoStitial, lnNoStitialExpiredHours*60);   
                } 
            } 
            break;
    }    
}