function f_GetRadWindowManager() {
	try {
		var oWindow = null;
		if (typeof(GetRadWindowManager)=='function') {
		oWindow = GetRadWindowManager();
		}
		else {
		if (window.radWindow) oWindow = window.radWindow;
		else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
		oWindow = oWindow.GetWindowManager();
		}
		return oWindow;
	}
	catch(e) {
		alert ("Error: " + e.message );
	}
}

function f_OpenWindow (wName, url, wCallBackFunction, wWidth, wHeight){
	try {
		var oManager = f_GetRadWindowManager();
		var oWindow = oManager.Open(url, wName);
		if ((typeof(arguments[3])!='undefined') && (typeof(arguments[4])!='undefined')){
			oWindow.SetSize (wWidth, wHeight);	
		}
		oWindow.Center();
		if (typeof(arguments[2])!='undefined'){
			oWindow.ClientCallBackFunction = wCallBackFunction
		}
		// Intercetto la chiusura della finestra e se sono state fatte delle modifiche lo segnalo
		var oCloseButton = oWindow.BrowserWindow.document.getElementById("CloseButton" + oWindow.Id);
	   if (oCloseButton != null){
	      oCloseButton.onclick = function(){
			   try {
				   var oMgr = f_GetRadWindowManager();
				   var oWin = oMgr.GetActiveWindow();
				   var oFrameContent = oWin.GetContentFrame().contentWindow;
				   var oForm = oFrameContent.document.forms[0];				   
				   if (typeof(oForm)!="undefined"){
						if (typeof(oForm._bFormDataChanged)!="undefined"){
	    					if (oForm._bFormDataChanged==true) {
								if (!confirm('Attenzione! Sono state fatte delle modifiche, vuoi continuare?')){
									return false;
								}
								oForm._bFormDataChanged=false;
	    					}
						}
				   }
				   oWin.Close();
				   return false;
			   }
			   catch(e) {
				   alert ("Error: " + e.message );
			   }
		   }
	   }
		return oWindow;
	}
		catch(e) {
			alert ("Error: " + e.message );
	}
}

function f_CloseWindow(retValue) {
	try {
		var oManager = f_GetRadWindowManager();
		var oWindow = oManager.GetActiveWindow();
		if (oWindow != null) {
		
			var oFrameContent = oWindow.GetContentFrame().contentWindow;
			var oForm = oFrameContent.document.forms[0];
			if (typeof(oForm)!="undefined"){
			   if (typeof(oForm._bFormDataChanged)!="undefined"){
	    		   if (oForm._bFormDataChanged==true) {
					   if (!confirm('Attenzione! Sono state fatte delle modifiche, vuoi continuare?')){
						   return false;
					   }
					   oForm._bFormDataChanged=false;
	    		   }
			   }
			}   
			if (typeof(arguments[0])!='undefined'){
				oWindow.Close(retValue);
			}
			else{
				oWindow.Close();
			}
		}
	}
	catch(e) {
		alert ("Error: " + e.message );
	}
}