window.onload=function()
	{
		var border_style = '1px solid #7F9DB9';
		$('send').observe('click',Send);
		$('fullname').setStyle({border:border_style,width:'150px'});
		$('email').setStyle({border:border_style,width:'150px'});
		$('subject').setStyle({border:border_style,width:'250px'});
		$('messagebody').setStyle({border:border_style});
		$('countryofresidence').setStyle({border:border_style});
		//$('send').enable();
		getCountries();
	}
	
	var Send = function()
	{
		var fullname = isEmpty('fullname');
		var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($F('email'));
		var subject = isEmpty('subject');
		var messagebody = isEmpty('messagebody');
		if(!fullname) $('fullnameError').update(contact_us[0]);
		else $('fullnameError').update('');
		
		if(!email) $('emailError').update(contact_us[1]);
		else $('emailError').update('');
		
		if(!subject) $('subjectError').update(contact_us[0]);
		else $('subjectError').update('');
		
		if(!messagebody) $('messagebodyError').update(contact_us[0]);
		else $('messagebodyError').update('');
		
		if(!fullname || !email || !subject || !messagebody)
		{}
		else
		{
			var data = $('ContactUsForm').serialize();
			$('ContactUsForm').disable();
			new Ajax.Request('send_mail.php',
			{
				method: 'post',
				parameters: data,
				onSuccess: function(Response)
				{
					/*
					$('ContactUsForm').enable();
					$('ContactUsForm').reset();
					hideBox();
					$('contact_us_box').hide();
					$('messeg_sent_box').show();
					*/
				},
				onLoading:function()
				{
					showBox();
					setTimeout('hide_show()',1000);
				},
				onFailure:function()
				{
					hideBox();
				}
			});
		}
	}
	
	function hide_show()
	{
		$('ContactUsForm').enable();
		$('ContactUsForm').reset();
		hideBox();
		$('contact_us_box').hide();
		$('messeg_sent_box').show();
	}
	
	function isEmpty(id)
	{
		return !($F(id)=='' || $F(id)==0 || $(id)==null);
	}
	
	function getCountries()
	{
		var gCountries = new Ajax.Request('/countries.php?lang='+lang+'&ref=' + get_time_stamp(),
						{
							method: 'get',
							onLoading:function()
								{
									$('countryofresidence').update('<option value="">'+contact_us[2]+'</option>');
								},
							onSuccess: function(Response)
								{
									$('countryofresidence').update(Response.responseText);															
								},
							onFailure:function()
								{
									$('countryofresidence').update('<option value="">Faild Loading</option>');
								}
						});
	}
	
	function get_time_stamp()
	{
		var time_stamp = new Date();
		time_stamp = time_stamp.getTime();
		return time_stamp;
	}