// JavaScript Document
function cvalidation()
{
  	 if(document.contact.name.value=="")
	 {
		 //alert('Please enter Your name');
		 document.getElementById('name_error').innerHTML='Please Enter Your Name';
		 document.contact.name.style.borderColor='#ff0000';
		 document.contact.name.focus();
		 return false;
	 }
	 if (document.contact.email.value=="")
	 {
		 document.getElementById('email_error').innerHTML='Invalid Email Id';
		  document.contact.email.style.borderColor='#ff0000';
		 document.contact.email.focus();
		 return false;
	 }
	 if(checkEmail(document.contact.email.value)==false)
	 {
		document.getElementById('name_error').innerHTML='Invalid Email Id';
		 document.contact.email.style.borderColor='#ff0000';
		document.contact.email.focus();
		return false;
	}
	if (document.contact.phone.value=="")
	{
		 document.getElementById('phone_error').innerHTML='Please Enter Your Phone No';
		  document.contact.phone.style.borderColor='#ff0000';
		 document.contact.phone.focus();
		 return false;
	 }
	if (document.contact.subject.value=="")
	 {
		 document.getElementById('subject_error').innerHTML='Please Enter A Subject';
		  document.contact.subject.style.borderColor='#ff0000';
		 document.contact.subject.focus();
		 return false;
	 }
	if (document.contact.message.value=="")
	 {
		 document.getElementById('message_error').innerHTML='Please Enter Your Message';
		  document.contact.message.style.borderColor='#ff0000';
		 document.contact.message.focus();
		 return false;
	 }
	 document.getElementById('submit').disabled=true;
	 sendRequest();
	 return false;
}

function checkEmail(myForm)
{

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm))
	{
	  return true;
	}
	else
	{		
		return false;
	}
}
function sendRequest(){
		new Ajax.Request('ajax-contact.php',
		{
			method:'post',
			parameters: $('contact').serialize(true),
			onLoading: function(){
				$('update_div').show();
				$('update_div').innerHTML = "<img src='images/loading.gif' width='220' height='19' />";
			},
			onSuccess: function(transport){
				var response = transport.responseText || "No response text";
				$('update_div').innerHTML = response;
				resetForm();
			},
			onFailure: function(){ 
				$('update_div').innerHTML = "Something went wrong...";
				resetForm();
			}
		});

}
function resetForm(){
	$("name").value = "";
	$("email").value = "";
	$("phone").value = "";
	$("subject").value = "";
	$("message").value = "";
	$("submit").disabled=false;
}