function sz() {

	var sz_wrapper = $('container').getSize();
	var sz_doc = document.getSize();

	if (sz_wrapper.y > sz_doc.y) {

		sheight = sz_wrapper.y;

	} else {

		sheight = sz_doc.y;

	};

	if (sz_wrapper.x > sz_doc.x) {

		swidth = sz_wrapper.x;

	} else {

		swidth = sz_doc.x;

	};

	dwidth = sz_doc.x;
	dheight = sz_doc.y;

};

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if ((str.indexOf(at)==-1) ||
	((str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)) ||
	((str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)) ||
	(str.indexOf(at,(lat+1))!=-1) ||
	((str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)) ||
	(str.indexOf(dot,(lat+2))==-1) ||
	(str.indexOf(" ")!=-1)) {
		return false;
	} else {
		return true;
	};
};

function addslashes( str ) {
    return str.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0");
}

function htmlentities(s){
    var div = document.createElement('div');
    var text = document.createTextNode(s);
    div.appendChild(text);
    return div.innerHTML;
}

function stripslashes( str ) {
    return str.replace('/\0/g', '0').replace('/\(.)/g', '$1');
}

function dialog(title,content,width,height,liquid) {

	document.body.className = 'selects_off';

	sz();

	if (height > (dheight-50)) { height = dheight-50; };

	var dialog_width = width+'px';

	if (liquid!=1) {

		var dialog_height = 'height: '+height+'px;';

	} else {

		var dialog_height = '';

	};

	var dialog_top = parseInt(((dheight-height)/2));
	var dialog_left = parseInt(((dwidth-width)/2));

	if (dialog_top < 0) { dialog_top = 5; };
	if (dialog_left < 0) { dialog_left = 5; };

	var dialogOverlay_width = swidth+'px';
	var dialogOverlay_height = parseInt(sheight+46)+'px';

	var dialogOverlay = new Element('div', {
		'id': 'dialogOverlay',
		'class': 'dialogOverlay',
		'style': 'width: '+dialogOverlay_width+'; height: '+dialogOverlay_height+';'
	});
	var dialog = new Element('div', {
		'id': 'dialog',
		'class': 'dialog',
		'style': 'width: '+dialog_width+'; '+dialog_height+' top: '+dialog_top+'px; left: '+dialog_left+'px;'
	});

	dialogOverlay.inject($('body'),'top');
	dialog.inject($('body'),'top');
		
	$('dialog').innerHTML = '<h2 class="title"><div id="dialogclose" class="dialogclose"><a href="javascript:void(null)" onClick="dialog_close();">close</a></div>'+title+'</h2><div id="dialogContent" class="dialogContent" style="height: '+parseInt(height-41)+'px;"></div>';

	var lala = function() { $('dialogContent').innerHTML = content; };
	
	lala.delay(100);

	document.onkeypress = kshortcuts_dialog;

	window.addEvent('resize', function() {
		
		sz();

		$('dialogOverlay').style.width = swidth+'px';
		$('dialogOverlay').style.height = sheight+'px';

	});

};

function dialog_close() {

	if ($('dialog')) {

		$('dialog').destroy();

	};

	if ($('dialogOverlay')) {

		$('dialogOverlay').destroy();

	};

	document.onkeypress = function() { };

	$('body').style.overflow = 'visible';

	document.body.className = document.body.className.replace('selects_off','');

	window.removeEvents('resize');

};

function kshortcuts_dialog(event) {

	var event = new Event(event);

	switch(event.key) {

		case 'esc':
		dialog_close();
		break;

	}

};