/**********************************************************************
  BEGIN MODAL DIALOG CODE 
***********************************************************************/
// Global for brower version branching.
var strBrowser = (navigator.appName.indexOf("Microsoft") != -1)?"IE":"NS";

// One object tracks the current modal dialog opened from this window.
var dialogWin = new Object();
dialogWin.win = 0;
var oInterval = "";

window.onfocus = HandleFocusForModalDialog;
window.onunload = HandleFocusForModalDialog;


// Generate a modal dialog.
// Parameters:
//    url -- URL of the page/frameset to be loaded into dialog
//    width -- pixel width of the dialog window
//    height -- pixel height of the dialog window

function openDialog(url, width, height) {

	if (!dialogWin.win || (dialogWin.win && dialogWin.win.closed)) {

		// Initialize properties of the modal dialog object.
		dialogWin.win = 0;
		dialogWin.returnedValue = "";
		dialogWin.url = url;
		dialogWin.width = width;
		dialogWin.height = height;
		
		//if current window is popup then adjust the offset
		if(typeof(objParentWindow)=="object"){
			dialogWin.left = ((screen.width - dialogWin.width) / 2) + 60;
			dialogWin.top = ((screen.height - dialogWin.height) / 2) - 60;
		}
		else{
			dialogWin.left = (screen.width - dialogWin.width) / 2;
			dialogWin.top = (screen.height - dialogWin.height) / 2;
		}
		var attr;
		
		if(strBrowser=="IE"){
		attr = "dialogLeft=" + dialogWin.left + "px;dialogTop=" + 
			dialogWin.top + "px;resizable=no;dialogWidth=" + dialogWin.width + 
			"px;dialogHeight=" + dialogWin.height + "px;status=no;help=no;border=thin;";
			dialogWin.win = window.showModalDialog(dialogWin.url,this,attr);
		}
		else{
			
			attr = "left=" + dialogWin.left + ",top=" + 
			dialogWin.top + ",resizable=no,width=" + dialogWin.width + 
			",height=" + dialogWin.height+ ",status=no,help=no";	
			// Generate the dialog and make sure it has focus.

			dialogWin.win=window.open(dialogWin.url, "", attr);
	
			if(typeof(objParentWindow)=="object"){
				var opw = objParentWindow;
	
				while(typeof(opw)=="object" && typeof(opw.dialogWin.win)=="object"){
					opw.dialogWin.win = dialogWin.win;
					opw = opw.objParentWindow;
				}
			}
			
			/*if(typeof(objParentWindow)=="object" && typeof(objParentWindow.dialogWin.win)=="object"){
				
				objParentWindow.dialogWin.win = dialogWin.win;
			}*/
			
			
			//dialogWin.win = openWindow(dialogWin.url,dialogWin.name,attr);
			dialogWin.win.focus();
			
			//dialogWin.win = openWindow(dialogWin.url,dialogWin.name,attr);
			//dialogWin.win.focus()
			oInterval=window.setInterval("HandleFocusForModalDialog()",50);
		}
		
		
	} else {
		dialogWin.win.focus()
	}
}

function openWindow(url, width, height) {
	var intLeft = (screen.width - width) / 2
	var intTop= (screen.height - height) / 2
	var attr;
		
	attr = "dependent=yes,left=" + intLeft + ",top=" + 
			intTop + ",resizable=yes,scrollbars=yes,width=" + width + 
			",height=" + height;	
	
	var objWin = window.open(url, "", attr)
	objWin.focus()
	return objWin;
}

function fnStopInterval(){
	if(oInterval!=""){
		window.clearInterval(oInterval);
		oInterval="";
	}
}
	
function HandleFocusForModalDialog(){
	if(typeof(dialogWin.win)=="object"){
		dialogWin.win.focus();
	}
}

function GetDialogWin()
{
	return dialogWin.win;
}

/**************************
  END MODAL DIALOG CODE
**************************/