function getBrowserHeight() { 
                var intH = 0; 
                var intW = 0; 
                
                if(typeof window.innerWidth  == 'number' ) { 
                   intH = window.innerHeight; 
                   intW = window.innerWidth; 
                }  
                else if(document.documentElement && (document.documentElement.clientWidth || 
				document.documentElement.clientHeight)) { 
                    intH = document.documentElement.clientHeight; 
                    intW = document.documentElement.clientWidth; 
                } 
                else if(document.body && (document.body.clientWidth || document.body.clientHeight)) 			   { 
                    intH = document.body.clientHeight; 
                    intW = document.body.clientWidth; 
                } 
 
                return { width: parseInt(intW), height: parseInt(intH) }; 
            }   
 /*Function to set position of interstitial on screen*/ 
function setLayerPosition() { 
               
    			var shadow = document.getElementById("shadow"); 
                var interstitial = document.getElementById("interstitial"); 
					
                var bws = getBrowserHeight(); 
                shadow.style.width = bws.width + "px"; 
                shadow.style.height = bws.height + "px"; 
 
                interstitial.style.left = parseInt((bws.width - 350) / 2); 
                interstitial.style.top = parseInt((bws.height - 200) / 2); 
				
				var agt=navigator.userAgent.toLowerCase();
				
				if (agt.indexOf("firefox") != -1)
				{
					interstitial.style.marginTop=120+"px";
					interstitial.style.marginLeft=220+"px";
				}
				if (agt.indexOf("msie") != -1)
				{
				interstitial.style.margin=-100+"px";

			    }
				if (agt.indexOf("webkit") != -1)
                {
                                                                
                  interstitial.style.marginTop=120+"px";
                 interstitial.style.marginLeft=220+"px";

                }

                shadow = null; 
                interstitial = null; 

} 
			
			
/*Function to show nonregistered user interstitial*/ 
function showNonRegInter(locale){
 
 var shadow = document.getElementById("shadow"); 
 if (shadow == null){
	return;
 }
 var interstitial = document.getElementById("interstitial"); 

  
   createCookie(locale);
   
	setLayerPosition(); 
	shadow.style.display = "block";  
	interstitial.style.display = "block"; 
	
	shadow = null; 
	interstitial = null;  
	 
  
  
 
  
 }
/*Function to hide interstitial when user clicks on close button*/ 
function hideNonRegInter(){
   
    var shadow = document.getElementById("shadow"); 
    var interstitial = document.getElementById("interstitial"); 
  
    shadow.style.display = "none";  
    interstitial.style.display = "none"; 
 
    shadow = null; 
    interstitial = null;  
	
		
}
/*cookie logic*/
function checkForCookie(locale,sec,cookiename,comingfrom){

var userId = readCookie(cookiename);

var popupExists=readCookie("nonRegInterstitial_"+locale);

if(userId==null || userId=="") {
		
		if(popupExists==null||popupExists==""){	
				thisObj = this;
				setTimeout(function() { thisObj.showNonRegInter(locale); }, sec*1000);	
			}
}else{
		userId=unescape(userId);
		
		thisObj = this;
		
		setTimeout(function() { thisObj.showCampaign(userId,locale,comingfrom); }, sec*1000);
		
	}

}			



function createCookie(locale) {
var name="nonRegInterstitial_"+locale;
var value="nonRegistered";
var domain=document.location.href+";";

var date = new Date();
	
date.setTime(date.getTime()+(24*60*60*1000));
		
var expires = "; expires="+date.toGMTString();
	
document.cookie = name + "=" + value + expires +  "; path=" + "/" ;


}

function updateCookieExpiry(locale,noOfDays) {
var name="nonRegInterstitial_"+locale;
var value="nonRegistered";
var domain=document.location.href+";";

var date = new Date();
	
date.setTime(date.getTime()+(noOfDays*24*60*60*1000));
		
var expires = "; expires="+date.toGMTString();
	
document.cookie = name + "=" + value + expires +  "; path=" + "/" ;

}


function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*function to show registered user interstitial*/

function showCampaign(username,locale,comingfrom) {   
// Add the iframe with a unique name 
 
var iframe = document.createElement("iframe");   

var uniqueString = "myiframe";   
document.body.appendChild(iframe);   
iframe.style.display = "none";   
iframe.contentWindow.name = uniqueString; 
iframe.setAttribute('id',uniqueString);
var country = locale.substring(3).toLowerCase();
var actionString= "http://profile.msd." + country + "/interstitial/raavInterstitial.do?reqType=verifyPI&locale="+locale+"&cmpname=RAAV&comingfrom="+comingfrom;

postForm(actionString,uniqueString);

} 
function postForm(actionName,targetName){

var form = document.createElement("form");  
form.target = targetName;   
form.action = actionName; 
form.method = "POST";   
document.body.appendChild(form);   
form.submit(); 
}
