function ID(id)
{
	return document.getElementById(id);
}

function htmlify_text(input_txt){
	var output_txt = input_txt.replace(/\n/g, "<br>");
	output_txt = output_txt.replace(/\s\s/g, " ");
	while (output_txt.indexOf("  ") != -1){ output_txt = output_txt.replace(/\s\s/g, " ");}
	output_txt = output_txt.replace(/\n/g, "<br>");
	output_txt = output_txt.replace(/\s<br>/g, "<br>");
	output_txt = output_txt.replace(/\"/g, "&#34;");
	output_txt = output_txt.replace(/\'/g, "&#39;");
	output_txt = output_txt.replace(/À/g, "&#192;");
	output_txt = output_txt.replace(/Á/g, "&#193;");
	output_txt = output_txt.replace(/Â/g, "&#194;");
	output_txt = output_txt.replace(/Ã/g, "&#195;");
	output_txt = output_txt.replace(/Ä/g, "&#196;");
	output_txt = output_txt.replace(/Å/g, "&#197;");
	output_txt = output_txt.replace(/Æ/g, "&#198;");
	output_txt = output_txt.replace(/Ç/g, "&#199;");
	output_txt = output_txt.replace(/È/g, "&#200;");
	output_txt = output_txt.replace(/É/g, "&#201;");
	output_txt = output_txt.replace(/Ê/g, "&#202;");
	output_txt = output_txt.replace(/Ë/g, "&#203;");
	output_txt = output_txt.replace(/Ì/g, "&#204;");
	output_txt = output_txt.replace(/Í/g, "&#205;");
	output_txt = output_txt.replace(/Î/g, "&#206;");
	output_txt = output_txt.replace(/Ï/g, "&#207;");
	output_txt = output_txt.replace(/Ð/g, "&#208;");
	output_txt = output_txt.replace(/Ñ/g, "&#209;");
	output_txt = output_txt.replace(/Ò/g, "&#210;");
	output_txt = output_txt.replace(/Ó/g, "&#211;");
	output_txt = output_txt.replace(/Ô/g, "&#212;");
	output_txt = output_txt.replace(/Õ/g, "&#213;");
	output_txt = output_txt.replace(/Ö/g, "&#214;");
	output_txt = output_txt.replace(/Ø/g, "&#216;");
	output_txt = output_txt.replace(/Ù/g, "&#217;");
	output_txt = output_txt.replace(/Ú/g, "&#218;");
	output_txt = output_txt.replace(/Û/g, "&#219;");
	output_txt = output_txt.replace(/Ü/g, "&#220;");
	output_txt = output_txt.replace(/Ý/g, "&#221;");
	output_txt = output_txt.replace(/à/g, "&#224;");
	output_txt = output_txt.replace(/á/g, "&#225;");
	output_txt = output_txt.replace(/â/g, "&#226;");
	output_txt = output_txt.replace(/ã/g, "&#227;");
	output_txt = output_txt.replace(/ä/g, "&#228;");
	output_txt = output_txt.replace(/å/g, "&#229;");
	output_txt = output_txt.replace(/æ/g, "&#230;");
	output_txt = output_txt.replace(/ç/g, "&#231;");
	output_txt = output_txt.replace(/è/g, "&#232;");
	output_txt = output_txt.replace(/é/g, "&#233;");
	output_txt = output_txt.replace(/ê/g, "&#234;");
	output_txt = output_txt.replace(/ë/g, "&#235;");
	output_txt = output_txt.replace(/ì/g, "&#236;");
	output_txt = output_txt.replace(/í/g, "&#237;");
	output_txt = output_txt.replace(/î/g, "&#238;");
	output_txt = output_txt.replace(/ï/g, "&#239;");
	output_txt = output_txt.replace(/ð/g, "&#240;");
	output_txt = output_txt.replace(/ñ/g, "&#241;");
	output_txt = output_txt.replace(/ò/g, "&#242;");
	output_txt = output_txt.replace(/ó/g, "&#243;");
	output_txt = output_txt.replace(/ô/g, "&#244;");
	output_txt = output_txt.replace(/õ/g, "&#245;");
	output_txt = output_txt.replace(/ö/g, "&#;246");
	output_txt = output_txt.replace(/ø/g, "&#248;");
	output_txt = output_txt.replace(/ù/g, "&#249;");
	output_txt = output_txt.replace(/ú/g, "&#250;");
	output_txt = output_txt.replace(/û/g, "&#251;");
	output_txt = output_txt.replace(/ü/g, "&#252;");
	output_txt = output_txt.replace(/ý/g, "&#253;");
	output_txt = output_txt.replace(/ÿ/g, "&#255;");
	output_txt = output_txt.replace(/‘/g, "&lsquo;");
	output_txt = output_txt.replace(/’/g, "&rsquo;");
	return output_txt;
}

function getMyXY(o)
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) //IE 6+ in 'standards compliant mode'
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) //IE 4 compatible
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	else
	{
		myHeight = document.getElementById('mesure').offsetHeight;
		myWidth = document.getElementById('mesure').offsetWidth;
	}

	var w = o.offsetWidth;
	var h = o.offsetHeight;

	var x = Math.round((myWidth/2)-(w/2));
	var y = Math.round((myHeight/2)-(h/2));
	y += document.body.scrollTop;

	o.style.left = x+'px';
	o.style.top = y+'px';
}

function load()
{
	getMyXY(ID('pre_loader'));
}

function closePopup()
{
	var options = {};

	if($("#system_message_popup").dialog('isOpen'))
	{
		$.closePopupLayer('myStaticPopup');
		$("#system_message_popup").dialog('destroy');
	}
}

function setSystemMessage(html,title){
	if (title == null) title = 'System Mesage';
	ID('system_message_popup').title = title;
	ID('system_message').innerHTML = html;
	checkSystemMessage();
}

function checkSystemMessage()
{
	if(ID('system_message').innerHTML != '')
	{
		openStaticPopup();
		openPopup();
	}

	if(ID('system_task_message'))
	{
		if(ID('system_task_message').innerHTML != '')
		{
			ID('system_message').innerHTML = ID('system_task_message').innerHTML;
			openStaticPopup();
			openPopup();
		}

	}
}

function openPopup()
{
	$.ui.dialog.defaults.bgiframe = true;
	$(function()
	{
		var resizable = $("#system_message_popup").dialog('option', 'resizable');
		$("#system_message_popup").dialog({ resizable: true});
		$("#system_message_popup").bind('dialogclose', function(event, ui)
		{
			closePopup();
		});
	});
}

function openStaticPopup() 
{
	$.openPopupLayer({
		name: "myStaticPopup",
		width: 550,
		target: "system_message_hidden",
		beforeClose: function(){closePopup();}
	});
}

function checkMail(mail_addr){
	var j = false;
	var i = mail_addr.split("@");
	if (i.length == 2){
		i = i[1].split(".");
		if (i.length > 1){
			i = i.pop();
			if ((i.length == 2) || (i.length == 3)) j=true;
		}
	}
	return j;
}

function checkNumber(tel_no){
	var j = false;
	var i = tel_no.replace(/[^\d]*/g,'');
	if (((i.length >= 11) && (i.charAt(0) == '2') && (i.charAt(1) == '7')) || ((i.length > 9) && (i.charAt(0) == '0'))) j = true;
	return j;
}

function addSnd(el,elpath,eltipe){
	if ($('#playing_audio').length) ID('playing_audio').pause();
	$(el).append("<audio id=\'playing_audio\' autoplay=\'autoplay\' onplaying=\'$(this).parent().parent().parent().children(\"img.play_but\").hide();$(this).parent().parent().parent().children(\"img.playing_but\").show();\' onended=\'$(this).parent().parent().parent().children(\"img.play_but\").show();$(this).parent().parent().parent().children(\"img.playing_but\").hide();$(this).remove();\' onpause=\'$(this).parent().parent().parent().children(\"img.play_but\").show();$(this).parent().parent().parent().children(\"img.playing_but\").hide();$(this).remove();\'><source src=\'"+elpath+"\' type=\'"+eltipe+"\' /><embed height=\'0px\' width=\'0px\' src=\'"+elpath+"\'></embed></audio>");
	$(el).parent().slideUp("fast");
}
