// Created : Nov, 2004 Z
// Updated : 11 Nov, 2004 Z
// Lib for managing Cross-browser modal window. Tested with IE 6  and Firefox/Gecko
// unfortunate : globalVar used by CB-Modal window utility. Cannot get rid of....
var winModalWindow;			// Refers to window handle.
var target;					// Points to target on this parent page/form where value is returned.

function IgnoreEvents(e)
{ return false;  }
 
function HandleFocus()
{
  if (winModalWindow)
  {
    //alert(winModalWindow.closed);
	if (!winModalWindow.closed)
    {  
	   winModalWindow.focus() ;   
	}
	else
    { 
	  window.top.releaseEvents (Event.CLICK|Event.FOCUS);
      window.top.onclick = "";    }
  }
  return false;
}

// Updated : 11 Nov, 2004 Z
function modalwin(file_url,height,width,trget)
{  
  if (trget)
  {  	 	
     if (typeof(trget) == "object")
     {  target = trget;  }
     else 
     {  
	    if (document.getElementById(trget))
	    {  target = document.getElementById(trget);  
		  if (target.id!=trget)
		  {  alert("Please use 'ID' attribute of the target placeholder for Cross-Browser compatibility.");  }
        }
	    else
	    {  alert("Target placeholder could not be located. Possible reasons :\n1.Invalid ID\n2.'Name' attribute was used instead of 'id' attribute.");return; }
     }
  }
  
  if (window.showModalDialog)
  {  window.showModalDialog(file_url, window, "dialogWidth="+width+"px;dialogHeight="+height+"px");  }
  else
  {
	  
	 window.top.captureEvents (Event.CLICK|Event.FOCUS)
     window.top.onclick=IgnoreEvents;
     window.top.onfocus=HandleFocus;
	 var theTop=(screen.height/2)-(height/2);
	 var theLeft=(screen.width/2)-(width/2);
	 winModalWindow = window.open (file_url, "ModalChild", "dependent=yes,width="+width+",height="+height+",top="+theTop+",left="+theLeft);
     winModalWindow.focus();
  }
  void(0);
  //return false;
}

// Updated : 11 Nov, 2004 Z
function modalclose(return_value)
{
  if (return_value)
  {  
	  var opener;

	  if (window.dialogArguments)
	  {   opener = window.dialogArguments;   }
	  else if (window.opener)
	  {   opener = window.opener;   }

	  if (opener)
	  {
		 if (opener.target.innerText)
		 {  opener.target.innerText=return_value;  }
		 else if (opener.target.innerHTML)
		 {  opener.target.innerHTML=return_value;   }
		 else if (opener.target.value)
		 {  opener.target.value=return_value;  }
	  }
  }
  window.close();
  return false;
}

