function contact_validate()
{
	$("#contactfrm").validate({
		rules: {
			fname: {
				required: true
			},
			lname: {
				required: true
			},
			phone: {
				required: true,
				minlength: 10,
				maxlength: 11,
				digits: true
			},
			email: {
				required: true,
				email: true
			},
			help: {
				required: true
			}
		},
		messages: {
			fname: {
				required: ""
			},
			lname: {
				required: ""
			},
			phone: {
				required: "",
				digits: ""
				/*minlength: "<br /><span style='color:#ff2200;'>Please enter at least 10 characters</span>",
				maxlength: "<br /><span style='color:#ff2200;'>Please enter no more than 11 characters</span>"*/
			},
			email:{
				required: "",
				email: ""
			},
			help: {
				required: ""
			}
		}
	});
}


function talkFormValidation()
{
	
	function validate_email(address) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if(reg.test(address) == false) {
  	return false;
   }else
   {
   		return true;
   }
}	
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
	
$(document).ready(function() {
	
	//if submit button is clicked
	$('#submit').click(function () {		
		
	
		//Get the data from all the fields
		var name = $('input[name=name]');
		var email = $('input[name=email]');
		var phone = $('input[name=phone]');
		var question = $('textarea[name=question]');

		//Simple validation to make sure user entered something
		//If error found, add hightlight class to the text field
		
		
		if (name.val()=='' || name.val()=='Name' ) {
			name.addClass('hightlight');
			return false;
		} else name.removeClass('hightlight');
		
		if (email.val()=='' || email.val()=='Email' ) {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');
			
			if (!validate_email(email.val()) || email.val()=='Email' ) {
			email.addClass('hightlight');
			return false;
		} else email.removeClass('hightlight');
		
		
		if (phone.val()=='' || phone.val()=='Phone') {
			phone.addClass('hightlight');
			return false;
		} else phone.removeClass('hightlight');
			
		if (!IsNumeric(phone.val()) || phone.val()=='Phone') {
			phone.addClass('hightlight');
			return false;
		} else phone.removeClass('hightlight');	
			
		if (question.val()=='' || question.val()=='Your Question') {
			question.addClass('hightlight1');
			return false;
		} else question.removeClass('hightlight1');
		
		
		
		//organize the data properly
		var data = 'name=' + name.val() + '&email=' + email.val() + '&phone=' + 
		phone.val() + '&question='  + encodeURIComponent(question.val());
		
		
		//start the ajax
		$.ajax({
			//this is the php file that processes the data and send mail
			url: "process.php",	
			
			//GET method is used
			type: "GET",

			//pass the data			
			data: data,		
			
			//Do not cache the page
			cache: false,
			
			//success
			success: function (html) {	
				//if process.php returned 1/true (send mail success)
				if (html==1) {					
					//hide the form
					$('.form').fadeOut('slow');					
					
					//show the success message
					$('.done').fadeIn('slow');
					
				//if process.php returned 0/false (send mail failed)
				} else alert('Sorry, unexpected error. Please try again later.');				
			}		
		});
		
		//cancel the submit button default behaviours
		return false;
	});	
});	
	
	
}
