// htmlArea v3.0 - Copyright (c) 2002-2004 interactivetools.com, inc.
// This copyright notice MUST stay intact for use (see license.txt).
//
// Portions (c) dynarch.com, 2003-2004
//
// A free WYSIWYG editor replacement for <textarea> fields.
// For full source code and docs, visit http://www.interactivetools.com/
//
// Version 3.0 developed by Mihai Bazon.
//   http://dynarch.com/mishoo
//
// Portions (c) Copyright 2004,2005 SWsoft, Inc. http://www.swsoft.com
//

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=348,height=292,top="+topp+",left="+leftp+",resizable=no,status=no");
			}else{
				window.open(url,null,"menu=no,width=348,height=292,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,
					"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();
		ev.preventDefault();
		ev.stopPropagation();
	}
};

Dialog._return = null;

Dialog._modal = null;

Dialog._arguments = null;

Dialog._geckoOpenModal = function(url, action, init) {
	if (/select_color\.html/i.test(url)) {
		var dlg = window.open(url, "ha_dialog",
			      "location=no,directories=no,dialog=yes,toolbar=no,menubar=no,personalbar=no, sidebar=no,width=10,height=10," +
			      "scrollbars=no,resizable=no,status=no");
	}else{
			var dlg = window.open(url, "ha_dialog",
			      "location=no,directories=no,dialog=yes,modal=yes,toolbar=no,menubar=no,personalbar=no, sidebar=no,width=10,height=10," +
			      "scrollbars=no,resizable=no,status=no");
	}
	Dialog._modal = dlg;
	Dialog._arguments = init;

	function capwin(w) {
		w.addEventListener("click", Dialog._parentEvent, true);
		w.addEventListener("mousedown", Dialog._parentEvent, true);
		w.addEventListener("focus", Dialog._parentEvent, true);
	};

	function relwin(w) {
		w.removeEventListener("focus", Dialog._parentEvent, true);
		w.removeEventListener("mousedown", Dialog._parentEvent, true);
		w.removeEventListener("click", Dialog._parentEvent, true);
	};

	Dialog._return = function (val) {
		if (val && action) {
			action(val);
		}
		Dialog._modal = null;
	};
};
