
var MF = new Object();

MF.initModalForm = function()
{
    var frm = document.getElementById("modalform");
    if (frm != null)
       MF.showModalForm(frm);
    else   
       MF.restoreState();
}

MF.getModalFormCoords = function()
{
    var res = new Object();
    var frm = document.getElementById("modalform");
    if (frm != null)
    {
       res.Top = parseInt(frm.style.top, 10);
       res.Left = parseInt(frm.style.left, 10);
    }
    else
    {
       res.Top = 0;
       res.Left = 0;
    }
    return res;
}

MF.timeMFId = null;
MF.setTopModalForm = function()
{
    var frm = document.getElementById("modalform");
    if (frm != null)
    {
        if (frm.offsetHeight < document.body.clientHeight)
	    	frm.style.top = ((document.body.clientHeight - frm.offsetHeight)/2  + document.body.scrollTop) + "px";
        else{
            frm.style.top = (parseInt(document.body.scrollTop, 10) + 10) +"px";
        }
        frm.style.visibility = "visible";
    }
    MF.timeMFId = null;
}

MF.showModalForm = function(container)
{
    container.style.zIndex = 700; 
    container.style.position = "absolute";
    container.style.left = (document.body.clientWidth - container.offsetWidth)/2 + "px";
    
    //  Scroll Bar hasn't rebuild yet, because call setTimeout
    //if (container.offsetHeight < document.body.clientHeight)
	//	container.style.top = ((document.body.clientHeight - container.offsetHeight)/2  + document.body.scrollTop) + "px";
    //else		
    //    container.style.top = "10px";
    //container.style.visibility = "visible";    

    var shadow = document.getElementById("modalform_shadow");
    shadow.style.zIndex = 699; 
    shadow.style.position = "absolute";
    shadow.style.backgroundColor = "#fff"; 
    shadow.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
    shadow.style.MozOpacity = 0.7;
    shadow.style.opacity = 0.7;
    shadow.style.left="0px";
    shadow.style.top="0px";
    shadow.style.width = document.body.scrollWidth + "px";
    
    var height = Math.max(container.offsetHeight, document.forms[0].offsetHeight);
    //height = Math.max(height, document.body.scrollHeight);
    shadow.style.height = height + "px";

    if (document.all)
    {
		var selects = document.getElementsByTagName("SELECT");
		for(var i=0; i<selects.length; i++)
		{
			if (!MF.isContainerSelect(selects[i], container))
			  selects[i].style.visibility="hidden";
		}
    }
   
	var videos = document.getElementsByTagName("DIV");
	for(var i=0; i<videos.length; i++)
	{
		if(videos[i].className == 'myVideoDisplay')
			videos[i].style.visibility="hidden";
	}

    if(MF.timeMFId != null)
        clearTimeout(MF.timeMFId);
    MF.timeMFId = setTimeout("MF.setTopModalForm()", 100);
    
    if (window.attachEvent)
        window.attachEvent("onresize", MF.resizeShadow);
    else    
        window.addEventListener("resize", MF.resizeShadow, false);    
}

MF.isContainerSelect = function(sel, container)
{
   var el = sel.offsetParent;
   while(el != null)
   {
      if (el == container)
        return true;
      el = el.offsetParent;  
   }
   return false;
}

MF.restoreState = function()
{
    if (document.all)
    {
		var selects = document.getElementsByTagName("SELECT");
		for(var i=0; i<selects.length; i++)
         	  selects[i].style.visibility="visible";
    }
    
	var videos = document.getElementsByTagName("DIV");
	for(var i=0; i<videos.length; i++)
	{
		if(videos[i].className == 'myVideoDisplay')
		{
			videos[i].style.visibility="visible";
		}
	}    
}

MF.resizeShadow = function()
{
    var shadow = document.getElementById("modalform_shadow");
    if (shadow != null)
    {
        shadow.style.width = document.body.scrollWidth + "px";
        shadow.style.height = document.body.scrollHeight + "px";
    }
    
    var container = document.getElementById("modalform");
    if (container != null)
    {
        container.style.left = (document.body.clientWidth - container.offsetWidth)/2 + "px";
        if (container.offsetHeight < document.body.clientHeight)
		    container.style.top = ((document.body.clientHeight - container.offsetHeight)/2  + document.body.scrollTop) + "px";
        else
            container.style.top = (parseInt(document.body.scrollTop, 10) + 10) +"px";        
    }    
}
