function Dialog(url, action, init, w, h, getWindowSize) {
	if (!getWindowSize) getWindowSize = false;
	if (typeof init == "undefined") {
		init = window;	// pass this window object by default
	}
	
	if (getWindowSize){
		w = parseInt(window.screen.availWidth);
		h = parseInt(window.screen.availHeight);
		url += "&W=" + (w - 8) + "&H=" + (h - 32)
		
		w += "px";
		h += "px";
	}else{
		var w2 = parseInt(w);
		var h2 = parseInt(h);
		if ((w2 > 0) && (h2 > 0)){
			w = w2 + "px";
			h = h2 + "px";
			url += "&W=" + (w2 - 8) + "&H=" + (h2 - 32)
		}
	}

	if (document.all) {	// here we hope that Mozilla will never support document.all
		var value = showModalDialog(url, init,
					"resizable: no; help: no; status: no; scroll: auto; dialogWidth: " + w + "; dialogHeight:" + h);
		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");
	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;
	};
};

function closeMe(){
	try{
		window.parent.close();
	}catch(e){}
}
// Function show dialog box for email4friend.aspx
function showDialog(vLink, vWidth, vHeight)
{
	return showWindow(vLink, false, true, true, false, false, false, true, true, vWidth, vHeight, 0, 0);
}
// Function show windows
function showWindow(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vWidth, vHeight, vTop, vLeft)
{
var sLink = (typeof(vLink.href) == 'undefined') ? vLink : vLink.href;

winDef = '';
winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
winDef = winDef.concat('height=').concat(vHeight).concat(',');
winDef = winDef.concat('width=').concat(vWidth).concat(',');

if (vCentered)
{
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
}
else
{
	winDef = winDef.concat('top=').concat(vTop).concat(',');
	winDef = winDef.concat('left=').concat(vLeft);
}

open(sLink, '_blank', winDef);

if (typeof(vLink.href) != 'undefined')
{
	return false;
}
}