	function ID(id)
	{
		return document.getElementById(id);
	}

	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 checkEnquiryForm()
	{
		var err = '';
		var name = ID('enquiry_name').value;
		var email = ID('enquiry_email').value;

		if (name=='')
			err+='Please enter your name.\n\r';

		if (email=='')
			err+='Please enter your email.\n\r';

		var myform = ID('enquiryFormID');

		if (err == '')
		{
			var plx = new PHPLiveX();
			return plx.SubmitForm(myform,{"preloader":"pre_loader","onFinish":enquiryResponse});
		}
		else
			alert(err);
	}

	function enquiryResponse(response)
	{
		alert(response);
	}

	function addMailingList()
	{
		var err = '';
		var email = ID('newsletter_email').value;

		if (email=='')
			alert('Please enter your email.');
		else
			addToMailingList(email,{"preloader":"pre_loader","target":"maillist_status","onUpdate":mailingListResponse});
	}

	function mailingListResponse()
	{
		var response = ID('maillist_status') .value;
		alert(response);
	}

	function checkKey(e)
	{
		if(e.keyCode == '13')
		{
			submitSearch();
		}
	}

	function submitSearch()
	{
		alert("Coming Soon!");
		//var query = ID('search_text').value;
		//window.location='index.php?search_results+'+query;
	}

	function openWindow(url)
	{
		window.open(url);
	}

	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 closePopup()
	{
		var options = {};

		if($("#system_message_popup").dialog('isOpen'))
		{
			$.closePopupLayer('myStaticPopup');
			$("#system_message_popup").dialog('destroy');
		}
	}

	function openStaticPopup()
	{
		$.openPopupLayer({
			name: "myStaticPopup",
			width: 550,
			target: "system_message_hidden",
			beforeClose: function(){closePopup();}
		});
	}

	function getPortalInfo($portal_id)
	{

		getPortalHtml($portal_id,{'target':'portal_popup','onUpdate':openPortalPopUp});
	}


	function f_clientWidth() {
		return f_filterResults (
			window.innerWidth ? window.innerWidth : 0,
			document.documentElement ? document.documentElement.clientWidth : 0,
			document.body ? document.body.clientWidth : 0
		);
	}
	function f_clientHeight() {
		return f_filterResults (
			window.innerHeight ? window.innerHeight : 0,
			document.documentElement ? document.documentElement.clientHeight : 0,
			document.body ? document.body.clientHeight : 0
		);
	}
	function f_scrollLeft() {
		return f_filterResults (
			window.pageXOffset ? window.pageXOffset : 0,
			document.documentElement ? document.documentElement.scrollLeft : 0,
			document.body ? document.body.scrollLeft : 0
		);
	}
	function f_scrollTop() {
		return f_filterResults (
			window.pageYOffset ? window.pageYOffset : 0,
			document.documentElement ? document.documentElement.scrollTop : 0,
			document.body ? document.body.scrollTop : 0
		);
	}
	function f_filterResults(n_win, n_docel, n_body) {
		var n_result = n_win ? n_win : 0;
		if (n_docel && (!n_result || (n_result > n_docel)))
			n_result = n_docel;
		return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
	}

	function openPortalPopUp()
	{
		
		var pop_up_div = ID('portal_popup');
		
		$.openPopupLayer({
			name: "myStaticPopup",
			width: 550,
			target: "system_message_hidden",
			beforeClose: function(){closePortalPopup();}
		});

		$("#pop_up_div").bind('dialogclose', function(event, ui)
		{
			closePopup();
		});		
		
		
		pop_up_div.style.visibility = 'visible';

		var client_width = f_clientWidth();
		var scroll_top = f_scrollTop();
		var div_width = 500;
		var pos_x = (client_width/2)-(div_width/2);
		var pos_y = scroll_top+200;

		pop_up_div.style.left = pos_x+'px';
		pop_up_div.style.top = pos_y+'px';
	}

	function closePortalPopup()
	{
		$.closePopupLayer('myStaticPopup');
		$("#system_message_hidden").dialog('destroy');
		
		var pop_up_div = ID('portal_popup');
		pop_up_div.style.visibility = 'hidden';
		closePopup();
		closePopup();
	}
