﻿//get browser type
var msie = false
var mozilla = false
var userAgent = new String(window.navigator.userAgent)

if(userAgent.indexOf("MSIE") >= 0) 
	msie = true
else if(userAgent.indexOf("Mozilla") >= 0)
	mozilla = true
	
	
//this is the public function to call when opening a dialog window
function OpenDialog (width, height, url, windowName, scrollbars, resizable, reloadParent)
{
	//width is width of dialog window
	//height is height of dialog window
	//url is the path of the page to be displayed in the dialog
	//windowName is a string name for the window
	//scrollbars is either 1 to turn on scroll bars or 0 to turn them off
	//resizable is either 1 to make the window resizable or 0 to fix the size
	//reloadParent is true or false whether the calling page should be refreshed after closing the dialog
	var left = GetModalDialogLeft(width) 
	var top = GetModalDialogTop(height) 
	var toolbar = 0
	var status = 0
	var menubar = 0
	OpenModalDialog(url, windowName, top, left, height, width, toolbar, status, menubar, scrollbars, resizable)
	if(reloadParent && msie)
	    document.aspnetForm.submit();
	    //window.location.reload(true);
}


//this is a public function called by the dialog window when it wants to close itself
function CloseModalDialog(reloadParent)
{
    
	if(reloadParent == null || reloadParent == "") reloadParent = true 
	//alert(reloadParent);
	if(mozilla)
	{
	    if(reloadParent) window.opener.document.aspnetForm.submit();
		//if(reloadParent) window.opener.location.reload()
		window.close()
	}
	else if (msie)
	{
		window.close()
	}    
}

//this is a private function used by OpenDialog
function GetModalDialogTop(dialogHeight)
{
	var screenTop = 0
	var clientHeight = 0
	var bodyClientHeight = 0
	
	if(msie)
	{
		screenTop = window.screenTop //top of the client area relative to the screen
		//clientHeight = document.documentElement.clientHeight //the height of the client area
		clientHeight = document.body.clientHeight
	}
	else if (mozilla)
	{
		screenTop = window.screenY //top of the window 
		clientHeight = window.innerHeight //the height of the client area
	}
	var top = screenTop + (clientHeight - dialogHeight)/2 
	//alert("msie="+msie)
	//alert("mozilla="+mozilla)
	//alert("screenTop="+screenTop)
	//alert("clientHeight="+clientHeight)
	//alert("top="+top)
	return top
}
	
//this is a private function used by OpenDialog
function GetModalDialogLeft(dialogWidth)
{
	var screenLeft = 0
	var clientWidth =	0
	
	if(msie)
	{
		screenLeft = window.screenLeft //left coordinate of the client area relative to the screen
		clientWidth = document.body.clientWidth //the width of the client area
	}
	else if (mozilla)
	{
		screenLeft = window.screenX //left coordinate of the window
		clientWidth = window.innerWidth //the width of the client area
	}
	var left = screenLeft + (clientWidth - dialogWidth)/2 
	//alert("screenLeft="+screenLeft)
	//alert("clientWidth="+clientWidth)
	//alert("left="+left)
	return left
}


//this is a private function used by OpenDialog
function OpenModalDialog(url, winName, top, left, height, width, toolbar, status, menubar, scrollbars, resizable) 
{
   if(status == 0)
        status="no";
    else
        status="yes";
        
	if (window.showModalDialog) 
	{
		var features = "dialogTop:"+top+"; dialogLeft:"+left+"; dialogHeight:"+height+"px; dialogWidth:"+width+"px; resizable:"+resizable+"; status:"+status+"; scroll:"+scrollbars;
		window.showModalDialog(url, "", features)
	} 
	else 
	{
		var features = "top="+top+", left="+left+", height="+height+", width="+width+", toolbar="+toolbar+", status="+status+", menubar="+menubar+", scrollbars="+scrollbars+", resizable="+resizable+", modal=yes";
		window.open(url,winName,features);
	}
} 


