﻿3
// Class to help in showing a popup dialog using another
// DOM element in the same page.
// Usage..
//    dialog = new LOLDialog( 'mainForm', 'dialogForm' );
//       all params to show are optional!
//    dialog.show( top, left, sizew, sizeh );
//    dialog.hide();
//
// It is assumed that the dialog is initially hidden already via styles

function LOLDialog (parentFormName,dialogFormName) {
	var _parentFormName = parentFormName;
	var _dialogFormName = dialogFormName;
	
	// Hide the dialog
	this.hide = function()
	{
		// restore back the parent
		this._grayer(_parentFormName,false);
		var ctrl=document.getElementById(_parentFormName);
		ctrl.style.position='absolute';
		//ctrl.style.top='0px';
		//ctrl.style.left='0px';
		ctrl.style.display='block';
		// hide the dialog
		document.getElementById(_dialogFormName).style.display='none';  
	};
	
	// show or hide the opacity on the form
	this._grayer = function(formId, yesNo) 
	{
//	   var f = document.getElementById(formId), s, opacity;
//	   s = f.style;
//	   opacity = yesNo? '40' : '100';
//	   s.opacity = s.MozOpacity = s.KhtmlOpacity = opacity/100;
//	   s.filter = 'alpha(opacity='+opacity+')';
//	   for(var i=0; i<f.length; i++) 
//  		  f[i].disabled = yesNo;
	   stop_link=yesNo;
	};
	
	// show the dialog
	//   all parameters are optional
	this.show = function(top,left,sizew,sizeh)
	{
		// size the dialog
		var dialog = document.getElementById(_dialogFormName);
		if ( sizew !== undefined && sizew != null )
			dialog.style.width=sizew+'px';
		if ( sizeh !== undefined && sizeh != null )
			dialog.style.height=sizeh+'px';

		// disable the  parent
		
		var ctrl=document.getElementById(_parentFormName);
		var ctrlParent = ctrl;
		this._grayer(_parentFormName,true);
		ctrl.style.position='absolute';
		//ctrl.style.top='0px';
		//ctrl.style.left='0px';
		ctrl.style.display='block';
		
		ctrl=document.getElementById(_dialogFormName);
		ctrl.style.position='absolute';
		ctrl.style.display='block';

		if ( top !== undefined && top != null && top != -1 )
			ctrl.style.top=top+'px';
		if ( left !== undefined && left != null && left != -1 )
			ctrl.style.left=left+'px';

		// If horizontal center and jQuery defined
		if ( left == -1 && typeof jQuery !== undefined )
			ctrl.style.left = (jQuery(ctrlParent).width() - jQuery(ctrl).width())/2 + 'px';
		// If vertical center and jQuery defined
		if ( top == -1 && typeof jQuery !== undefined )
			ctrl.style.top = (jQuery(ctrlParent).height() - jQuery(ctrl).height())/2 + 'px';
	};
};




