function toggle(div_id) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}	
	
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
	popUpDiv_height=blanket_height/15 -150;//150 is half popup's height
	popUpDiv.style.top = popUpDiv_height + 'px';
	//popUpDiv.style.top ='10px';
}
function window_pos(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientHeight;
	}
	
	if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
		window_width = viewportwidth;
	} else {
		if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
			window_width = document.body.parentNode.clientWidth;
		} else {
			window_width = document.body.parentNode.scrollWidth;
		}
	}
	var popUpDiv = document.getElementById(popUpDivVar);
	window_width=window_width/4-150;//150 is half popup's width
	popUpDiv.style.left = window_width + 'px';
	//popUpDiv.style.left = '300px';
}
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setContent(windowname) {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		alert(windowHeight);
		if (windowHeight > 0) {
			var contentElement = document.getElementById(windowname);
			var contentHeight = contentElement.offsetHeight;
			alert(contentHeight);
			if (windowHeight - contentHeight > 0) {
				contentElement.style.position = 'relative';
				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
			}
			else {
				contentElement.style.position = 'static';
			}
		}
	}
}

function popup(windowname) {   	
	if($.cookie("visit")==null){
		$.cookie("visit", "true"); 
	        blanket_size(windowname);
	        //window_pos(windowname);
	        showdeadcenterdiv(300,300,windowname);
		toggle('blanket');
		toggle(windowname);		
	}
	else{		
		var el = document.getElementById(windowname);
		el.style.display = 'none';
		var sl = document.getElementById('blanket');
		sl.style.display = 'none';
	}
}

function popupF(windowname) {
        blanket_sizeF(windowname);
        //window_pos(windowname);
        showdeadcenterdiv(300,250,windowname);
	toggle('blanket');
	toggle(windowname);		
}
function blanket_sizeF(popUpDivVar) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanket = document.getElementById('blanket');
	blanket.style.height = blanket_height + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);	
	//popUpDiv_height=blanket_height/2-150;//150 is half popup's height	
	//popUpDiv.style.top =blanket_height -700 + 'px';
	popUpDiv_height=(blanket_height/1.1) -300;//150 is half popup's height	
	popUpDiv.style.top = popUpDiv_height + 'px';
}


function showdeadcenterdiv(Xwidth,Yheight,divid) {        
	
	var scrolledX, scrolledY; 
	var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; 
	
	
	if( self.pageYOffset ) { 	
	scrolledX =  self.pageXOffset; 
	scrolledY = self.pageYOffset; 	
	} else if( document.documentElement && document.documentElement.scrollTop ) { 	
	scrolledX = document.documentElement.scrollLeft; 
	scrolledY = document.documentElement.scrollTop; 	
	} else if( document.body ) { 
	scrolledX = document.body.scrollLeft; 
	scrolledY = document.body.scrollTop; 	
	} 
	scrolledY=scrollTop;
                
	// Next, determine the coordinates of the center of browser's window 

	var centerX, centerY; 
	if( self.innerHeight ) { 
	centerX = self.innerWidth; 
	centerY = self.innerHeight; 
	} else if( document.documentElement && document.documentElement.clientHeight ) { 
	centerX = document.documentElement.clientWidth; 
	centerY = document.documentElement.clientHeight; 
	} else if( document.body ) { 
	centerX = document.body.clientWidth; 
	centerY = document.body.clientHeight; 
	} 
	
	//alert("centerX"+centerX);
        //alert("centerY"+centerY);

	// Xwidth is the width of the div, Yheight is the height of the 
	// div passed as arguments to the function: 
	var leftOffset = scrolledX + (centerX - Xwidth) / 4; 
	var topOffset = scrolledY + (centerY - Yheight) / 100; 
	//alert("leftOffset"+leftOffset);
       // alert("topOffset"+topOffset);
	// The initial width and height of the div can be set in the 
	// style sheet with display:none; divid is passed as an argument to // the function 
	var o=document.getElementById(divid); 
	var r=o.style; 
	r.position='absolute'; 
	r.top = topOffset + 'px'; 
	r.left = leftOffset + 'px'; 
	//r.display = "block"; 
} 


