function OpenModal()
{
    DisplayModalDiv('popUpDiv');
}

function OpenModalUrl(strTitle, intWidth, intHeight, strUrl)
{
    document.getElementById('popUpDiv').style.width = intWidth + "px";
    document.getElementById('popUpDiv').style.height = intHeight + "px";
    document.getElementById('divModalContent').style.height = (intHeight - 17) + "px";
    document.getElementById('ifmFileForm').src = strUrl;
    document.getElementById('divModalTitle').innerHTML = strTitle;
    DisplayModalDiv('popUpDiv', intWidth, intHeight);
}

function OpenModalUrlPosition(strTitle, intWidth, intHeight, strUrl)
{
    document.getElementById('popUpDiv').style.width = intWidth + "px";
    document.getElementById('popUpDiv').style.height = intHeight + "px";
    document.getElementById('divModalContent').style.height = (intHeight - 17) + "px";
    document.getElementById('ifmFileForm').src = strUrl;
    document.getElementById('divModalTitle').innerHTML = strTitle;
    DisplayModalDiv('popUpDiv', intWidth, intHeight);
}

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 SetBlankSize(popUpDivVar, intDivWidth, intDivHeight)
{
    var intScrollTop = 0;
	if (typeof window.innerWidth != 'undefined') 
	{
		viewportheight = window.innerHeight;
        intScrollTop = document.body.scrollTop;
	} else 
	{
		viewportheight = document.documentElement.clientHeight;
        intScrollTop = document.documentElement.scrollTop;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) 
		intBlanketHeight = viewportheight;
	else 
	{
		//if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) 
		//	intBlanketHeight = document.body.parentNode.clientHeight;
		//else 
		if (navigator.appName.indexOf('Microsoft') != -1)
			intBlanketHeight = document.body.parentNode.scrollHeight;
		else
		    intBlanketHeight = document.getElementById("tblMain").scrollHeight;
	}
	var divBlanket = document.getElementById('divBlanket');
	divBlanket.style.height = intBlanketHeight + 'px';
	var popUpDiv = document.getElementById(popUpDivVar);
    var intHalf = (viewportheight - intDivHeight) / 2;
    intTop = intHalf <= 0 ? 50 : intHalf;
    intTop = intScrollTop + intHalf;
    popUpDiv.style.top = intTop + 'px';
}

function SetWindowPos(popUpDivVar, intDivWidth, intDivHeight)
{
	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-intDivWidth)/2; //300 is half popup's width
    popUpDiv.style.left = window_width + 'px';
}

function CloseModalDiv(strDivName) 
{
	toggle('divBlanket');
	toggle(strDivName);		
}

function popup(strDivName) 
{
	SetBlankSize(strDivName, 0, 0);
	SetWindowPos(strDivName, 0, 0);
	toggle('divBlanket');
	toggle(strDivName);		
}

function DisplayModalDiv(strDivName, intDivWidth, intDivHeight) 
{
	SetBlankSize(strDivName, intDivWidth, intDivHeight);
	SetWindowPos(strDivName, intDivWidth, intDivHeight);
	toggle('divBlanket');
	toggle(strDivName);		
}
