function Dialog(url, action, init) {
	if (typeof init == "undefined") {
		init = window;	// pass this window object by default
	}
	if (document.all) {	// here we hope that Mozilla will never support document.all
		if(url.substr(url.length-10,10).toLowerCase()=="spell.html"){
			var topp=screen.availHeight/2-106;
			var leftp= screen.availWidth/2-160;
			if(sp2Detect()){
				window.open(url,null,"menu=no,width=345,height=282,top="+topp+",left="+leftp+",resizable=no,status=no");
			}else{
				window.open(url,null,"menu=no,width=345,height=282,top="+topp+",left="+leftp+",resizable=no,status=no");
			}
		}else if(url.substr(url.length-16,16).toLowerCase()=="photogallery.php"){
			var topp=screen.availHeight/2-106;
			var leftp= screen.availWidth/2-160;
			if(sp2Detect()){
				window.open(url+"?PPID="+editor.ppID,null,"menu=no,width=345,height=282,top="+topp+",left="+leftp+",resizable=no,status=no");
			}else{
				window.open(url+"?PPID="+editor.ppID,null,"menu=no,width=345,height=282,top="+topp+",left="+leftp+",resizable=no,status=no");
			}
		}else{
			var rt=null;
			try{
				rt=editor.win
			}catch(e){
			}
			if(rt!=null){
				var value = rt.showModalDialog(url, init,
//			window.open(url, '_blank',
					"resizable: no; help: no; status: no; scroll: no");
			}else{
				var value = window.showModalDialog(url, init,
//			window.open(url, '_blank',
					"resizable: no; help: no; status: no; scroll: no");
			}
					
			if (action) {
				action(value);
			}
		}
	} else {
		return Dialog._geckoOpenModal(url, action, init);
	}
};

Dialog._parentEvent = function(ev) {
	if (Dialog._modal && !Dialog._modal.closed) {
		Dialog._modal.focus();
		// we get here in Mozilla only, anyway, so we can safely use
		// the DOM version.
		ev.preventDefault();
		ev.stopPropagation();
	}
};

// should be a function, the return handler of the currently opened dialog.
Dialog._return = null;

// constant, the currently opened dialog
Dialog._modal = null;

// the dialog will read it's args from this variable
Dialog._arguments = null;

Dialog._geckoOpenModal = function(url, action, init) {
	var dlg = window.open(url, "ha_dialog",
			      "toolbar=no,menubar=no,personalbar=no,width=10,height=10," +
			      "scrollbars=no,resizable=no,status=no");
	Dialog._modal = dlg;
	Dialog._arguments = init;

	// capture some window's events
	function capwin(w) {
		w.addEventListener("click", Dialog._parentEvent, true);
		w.addEventListener("mousedown", Dialog._parentEvent, true);
		w.addEventListener("focus", Dialog._parentEvent, true);
	};
	// release the captured events
	function relwin(w) {
		w.removeEventListener("focus", Dialog._parentEvent, true);
		w.removeEventListener("mousedown", Dialog._parentEvent, true);
		w.removeEventListener("click", Dialog._parentEvent, true);
	};
	//capwin(window);
	// capture other frames
	//for (var i = 0; i < window.frames.length; capwin(window.frames[i++]));
	// make up a function to be called when the Dialog ends.
	Dialog._return = function (val) {
		if (val && action) {
			action(val);
		}
		//relwin(window);
		// capture other frames
		//for (var i = 0; i < window.frames.length; relwin(window.frames[i++]));
		Dialog._modal = null;
	};
};
