//Function to validate and post the Testimonial 
function submitTestimonial(){
	var error = "";
	var name = $("#testimoName").val();
	var email = $("#testimoEmail").val();
	if(!name) {
		error += "- Please enter the Name <br>";
		$("#testimoName").focus();
	}
		else {
			var validname = /^[a-zA-Z.' _]*$/;
			
			if(!validname.test(name)) {
				
			error += "- Invalid name <br>";
			$("#testimoName").val('');
			}
	}
	if(!$("#country").val()) {
		error += "- Please select the country Name <br>";
		$("#country").focus();
	}
	if(!$("#testimoMessage").val()) {
		error += "- Please enter the Message <br>";
		}
	if (!email) {
			error += "- Please enter your Email Address <br>";
			} else {	
				if(!isValidEmailAddress(email)) {
					error += "- Please enter a valid Email Address <br>";
					$("#testimoEmail").focus();
					$("#testimoEmail").val('');
					}
				}
	if(error)
		{
		$("#errorBox").html("<b>Please correct the following errors:</b><br>" + error + "").show();
		$("#Thanks").hide();
		return false;
		}
		
		var dataStr = $("form#Testimonial_form").serialize();
		$.ajax({
		type: "post",
		data: dataStr,
		url : "testimonial.php",
		success : function(data){
			if (jQuery.trim(data))
			{		
						$("#Thanks").show();
						$("#errorBox").hide();
						$("#testimoName").val("");
						$("#testimoMessage").val("");
						$("#testimoEmail").val("");
						$("#testimoCity").val("");
						$("#testimoState").val("");
						$("#testimoCountry").val("");
						$("#charCount").val("");
						return false;
					} else {
						$("#errMessage").show();
						$("#Thanks").hide();
						return false;
						}
			}		
		});
	return false;
}



// Function to check the valid Email

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);
return pattern.test(emailAddress);
}



//	Function to limit the text in text area
function limtTextArea() {
	var textField = $("#testimoMessage").val();	
	var charLength = textField.length;
	$('span#charCount').html(charLength + ' of 150 characters used');
	if(charLength > 150)	{
		$('span#charCount').html('You may only have up to 150 characters.');
		$("#testimoMessage").val(textField.substring(0,150));
	}
}

