// JavaScript Document
function send_mail()
{
	hide_errors();
	$.post("/actions/send_mail.php", $('#contact_form').serialize(),
	   function(data){
		 process_form(data);
	   });
}

function process_form(data)
{
	eval("var r="+data);
	if(r.status=='true') document.location.href="/contact.php?m="+r.m+"&r=t";
	else if(r.status=='error')
	{
		if(r.name) 
		{
			$("#err_name td:eq(1)").html(r.name);
			$("#err_name").show();
		}
		if(r.tel) 
		{
			$("#err_tel td:eq(1)").html(r.tel);
			$("#err_tel").show();
		}
		if(r.email) 
		{
			$("#err_email td:eq(1)").html(r.email);
			$("#err_email").show();
		}
		if(r.m=='c')
		{
			if(r.comments) 
			{
				$("#err_comments").html(r.comments);
				$("#err_comments").show();
			}
		}
		else if(r.m=='d')
		{
			if(r.product_type) 
			{
				$("#err_product_type").html(r.product_type);
				$("#err_product_type").show();
			}
			if(r.client_profile) 
			{
				$("#err_client_profile").html(r.client_profile);
				$("#err_client_profile").show();
			}
		}
	}
	else if(r.status=='false') alert(r.msg);
}

function hide_errors()
{
	$('content_wrapper .error').hide();
}

function reset_form()
{
	hide_errors();
	document.contact_form.reset();
}
