function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//------------------------------------------------------------------------------------
function trimFields(obj)
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//------------------------------------------------------------------------------------
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z0-9][a-z0-9_\.\-]*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr));
}

//Contact us block
$(document).ready(function()
{
	$("#send").click(function(){

		trimFields(objContact);
		if(objContact.full_name.value == "")
		{
			alert("Please enter your Name.");
			objContact.full_name.focus();
			return false;
		}
		if(objContact.email.value == "")
		{
			alert("Please enter your Email Address.");
			objContact.email.focus();
			return false;
		}
		if(!chkEmail(objContact.email.value))
		{
			alert("Please enter a valid Email Address !");
			objContact.email.focus();
			objContact.email.select();
			return false;
		}
		if(objContact.comment.value == "")
		{
			alert("Please enter your comment.");
			objContact.comment.focus();
			return false;
		}
		$("#send").hide();
		$("#loader").show();
		var full_name = objContact.full_name.value;
		var email = objContact.email.value;
		var address = objContact.address.value;
		var city = objContact.city.value;
		var phone = objContact.phone.value;
		var comment = objContact.comment.value;
        $.get("contact_us_mail_process.php", { full_name: full_name, address: address, city: city, phone: phone, email: email, comment: comment  },
		  function(data){
		    objContact.full_name.value = '';
		    objContact.address.value = '';
		    objContact.city.value = '';
		    objContact.phone.value = '';
		    objContact.email.value = '';
		    objContact.comment.value = '';
			$("#send").show();
			$("#loader").hide();
		    alert(data);
		  });
	});

	$("#right_send").click(function(){

			trimFields(obj);
			if(obj.contact_name.value == "")
			{
				alert("Please enter your Name.");
				obj.contact_name.focus();
				return false;
			}
			if(obj.contact_email_address.value == "")
			{
				alert("Please enter your Email Address.");
				obj.contact_email_address.focus();
				return false;
			}
			if(!chkEmail(obj.contact_email_address.value))
			{
				alert("Please enter a valid Email Address !");
				obj.contact_email_address.focus();
				obj.contact_email_address.select();
				return false;
			}
			if(obj.contact_question.value == "")
			{
				alert("Please enter your Question.");
				obj.contact_question.focus();
				return false;
			}
			$("#right_send").hide();
			$("#loader").show();
			var full_name = objContact.contact_name.value;
			alert(objContact.contact_name.value);
			var email = objContact.contact_email_address.value;
			var address = objContact.contact_type.value;
			var phone = objContact.contact_phone.value;
			var comment = objContact.contact_question.value;
	        $.get("contact_us_mail_process.php", { full_name: full_name, address: address, city: city, phone: phone, email: email, comment: comment  },
			  function(data){
			    objContact.contact_name.value = '';
			    objContact.contact_type.value = '';
			    objContact.contact_phone.value = '';
			    objContact.contact_email_address.value = '';
			    objContact.contact_question.value = '';
				$("#right_send").show();
				$("#loader").hide();
			    alert(data);
			  });
	});
});

