var disclaimerActive = false;
var framElem = null;
var overlayElem = null;

function createDisclaimer(){
	disclaimerActive = true;
	c_name = "_http_refferer_";

	value = window.location.href;
	document.cookie=c_name + "=" + value+";path=/";
	
	var objBody = document.body;
	overlayElem = document.createElement('div');
	overlayElem.id = 'f_overlay';
	objBody.appendChild(overlayElem);
	framElem = $("disclaimer");
	framElem.src = XWL_PATH+"/dyn/site/disclaimer";
	if($("swf_client_disclaimer")){
		$("swf_client_disclaimer").style.visibility = "visible";
	}
	

	framElem.style.width = 420+"px";
	
	framElem.style.height = 500+"px";
	framElem.show();
	/*var overlayElem = document.createElement('div');
	overlayElem.id = 'f_overlay';
	overlayElem.style.height = 100+"%";
	objBody.appendChild(overlayElem);*/
	setWindow();
	//$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });	
//--centralizing overlay.	
	setCenterDisclaimer();
	document.body.style.visibility = "visible";
}

function setCenterDisclaimer(){
	framElem.style.left = (($(overlayElem).getWidth() - $(framElem).getWidth())/2)+"px";
	framElem.style.top = ((overlayElem.getHeight() - framElem.getHeight())/2)+"px";
	
}

function hideFlash(){
	if(disclaimerActive){
		$$('.f_embed', 'select', 'object', 'embed').each(function(node){node.style.visibility = 'hidden' });	
	}
}

function setWindow(){
//set page resize event	
	window.onresize = setWindow; 
	//window.onload = setWindow;
	 // stretch overlay to fill page and fade in
    var arrayPageSize = _getPageSize();
    var overlay = document.getElementById('f_overlay');
    overlay.style.width = arrayPageSize[0] + 'px';
    overlay.style.height = arrayPageSize[1] + 'px';
    
}
   
function _getPageSize() {
       
     var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}
function setCookie(){
	var domain = window.location.hostname;
	if(domain.indexOf("www.") === 0){
		domain = domain.substr(domain.indexOf(".")+1);
	}

	disclaimerActive = false;
	c_name = "disclaimer";
	value = 1;
	expiredays = 365;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+"; path=/;domain=." + domain;
	
	disclaimerActive = false;
	$$('.f_embed', 'select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });	
	var overlay = document.getElementById('f_overlay');
	overlay.style.display = "none";
	var overlay = document.getElementById('disclaimer');
	overlay.style.display = "none";
	$("disclaimer").hide();
}
function disclaimerRedirect(url){
	window.location=url;
}

window.onload = setWindow;
var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
if(!isIE6)
createDisclaimer();

