
//start div popup
var obj_div ;
var obj_div_over ;
function popup_div(obj_id)
{
	var obj = document.getElementById(obj_id);
	if(BrowserDetect.browser=='Explorer' && BrowserDetect.version=='6')
	{
		
	}
	else
	{
		obj.style.position = "fixed";
	}
	if(obj)
	{
		obj_div = document.getElementById(obj_id);
		if(obj!=null)
		{
			//set_postion(obj);
			//obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';

			set_postion(obj);
			if(obj.style.visibility == 'visible')
			{
				//hide the pop up
				obj.style.visibility = 'hidden';
				obj.style.left = '-10000';
				hideAlertLayer(obj);
				//alert(1);
				//obj.innerHTML = "<div class='add_popup_684' id='popup_parent_div_content_id'></div>";	
			//	$("#popup_parent_div_content_id").html('');
			}
			else
			{
				//alert(1);
				//show the pop up
				showAlertLayer(obj);
				obj.style.visibility = 'visible';
				obj.style.zIndex = 101;
				set_postion(obj_div);
				winOnResize();
				Cufon.replace('.din_popup', { fontFamily: 'DIN'});
				
			}

		}
		else
		{
			alert(obj_id + ' popup is null');
		}
	}
	return false;
}
function set_postion(obj)
{
	if(obj && obj.style.visibility != 'hidden')
	{
		var div_width = obj.offsetWidth
		var div_height = obj.offsetHeight;

		var theLeft = 0, theTop =0;
		if(screen.width)
		{
			var theLeft = 0;
			var theTop = 0;
			var isMozilla = document.getElementById&&!document.all;
			if(isMozilla)
			{
				theLeft = (window.innerWidth - div_width) / 2;;
				theTop = (window.innerHeight - div_height) / 2;
			}
			else
			{
				theLeft = ($(window).width() - div_width) / 2;
				theTop = ($(window).height() - div_height) / 2;
			}

		}
		if (theLeft < 0) theLeft = 0;
		if (theTop < 0) theTop = 0;
		//theTop = 80;
		
		//jQuery("html, body").scrollTop(100);
		//alert(jQuery(window).scrollTop());
		//alert($().scrollTop());
		//document.body.scrollTop
		//alert(document.body.offsetHeight);
		//alert(window.innerHeight);
		//alert($(window).height());
		if(BrowserDetect.browser=='Explorer' && BrowserDetect.version=='6')
		{
			theTop += $().scrollTop();
		}
	
		obj.style.left = theLeft + 'px' ;
		obj.style.top = (theTop - 0) + 'px' ;
	}
}

function popup_postion_div(obj_id, theLeft, theTop)
{
	var obj = document.getElementById(obj_id);
	if(obj!=null)
	{
		if(theLeft > 0 && theTop > 0)
		{
			obj.style.left = theLeft + 'px' ;
			obj.style.top = theTop + 'px' ;
		}
		obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
	}
	else
	{
		alert(obj_id + ' popup is null');
	}
	return false;
}

//start popup window
function OpenBox(winWidth, winHeight, fileSrc, scrollbars)
{
	if(screen.width)
	{
		var winl = (screen.width - winWidth) / 2;
		var wint = (screen.height - winHeight) / 2;
	}
	else
	{
		winl = 0; wint =0;
	}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
	var props = 'top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars='+scrollbars+',resizable=no,width='+winWidth+',height='+ winHeight;
	window.open(fileSrc, 'FullScreen', props);
}
function getPageSize()
{
	//alert(document.body.scrollLeft);
	arrayPageSize = new Array(document.body.clientWidth+document.body.scrollLeft,$(document).height());
	//alert($(document).height());
	return arrayPageSize;
}

function showAlertLayer(obj_div)
{
	var arrayPageSize = getPageSize();

	// setup the dividers
	var BodyObject = document.getElementsByTagName("body").item(0);

	// setup bg alert layer
	var OverlayObject = document.getElementById('da_overlay_'+obj_div.id);
	if (!OverlayObject)
		OverlayObject = document.createElement("div");
	obj_div_over = OverlayObject;
	OverlayObject.setAttribute('id','da_overlay_'+obj_div.id);
	OverlayObject.style.width = arrayPageSize[0] + "px";
	OverlayObject.style.height = (arrayPageSize[1]) + 'px';
	OverlayObject.style.left = '0px';
	OverlayObject.style.top = '0px';
	OverlayObject.style.position = "absolute";
	OverlayObject.style.backgroundColor = "#ffffff";
	//OverlayObject.style.backgroundColor = "#000000";
	OverlayObject.style.zIndex = 100;
	OverlayObject.style.filter = "alpha(opacity=65)";
	OverlayObject.style.mozOpacity = ".65";
	OverlayObject.style.opacity = ".65";
	OverlayObject.style.display = "block";

	// setup content alert layer

	BodyObject.appendChild(OverlayObject);

}

function hideAlertLayer(obj_div)
{
	var OverlayObject = document.getElementById('da_overlay_'+obj_div.id);
	if(OverlayObject)
	{
		OverlayObject.style.width = "0px";
		OverlayObject.style.height = "0px";
		OverlayObject.style.left = '0px';
		OverlayObject.style.top = '0px';
		OverlayObject.style.backgroundColor = "#000000";
		OverlayObject.style.zindex = "0";
		OverlayObject.style.filter = "alpha(opacity=0)";
		OverlayObject.style.mozOpacity = ".0";
		OverlayObject.style.opacity = ".0";
		OverlayObject.style.display = "none";
	}
}
function winOnResize()
{
	//var div_width = obj_div.offsetWidth
	//var div_height = obj_div.offsetHeight;
	if(obj_div && $("body").height() - 100 >obj_div.offsetHeight)
	{
		
		set_postion(obj_div);
	}
	$("div[id^=da_overlay_]").each(function(){															
		var arrayPageSize = getPageSize();
		$(this).css('width',arrayPageSize[0] + "px");
		$(this).css('height',arrayPageSize[1] + "px")
		//obj_div_over.style.width = arrayPageSize[0] + "px";
		//obj_div_over.style.height = (arrayPageSize[1]) + 'px';
	});
	
}
window.onresize=winOnResize;
window.onscroll=winOnResize;

