$(document).ready(function() {
	
	$('#submit').click(function () {		
		
		var name = $('input[name=name]');
		var comment = $('textarea[name=msg]');
		var email_confirmation = $('input[name=email-confirmation]');
		var phone = $('input[name=phone]');		
		var tok1 = $('input[name=token1]');
		var tok2 = $('input[name=token2]');		
		var error = 0;

if (name.val()=='') { 
name.addClass('hightlight'); 
error=1;
} else name.removeClass('hightlight'); 


if (phone.val()=='') { 
phone.addClass('hightlight'); 
error=1;
} else{
	var filter1 = /^[0-9+ ()-]*$/;
	if(filter1.test(phone.val())){
		phone.removeClass('hightlight'); 
	}else{
		phone.addClass('hightlight');
		error=1;
	}

}

if (comment.val()=='') { 
comment.addClass('hightlight'); 
error=1;
} else comment.removeClass('hightlight'); 

if (error) return false;	

var data = {name : name.val(), email_confirmation : email_confirmation.val(),  msg : comment.val(), phone : phone.val(), token1 : tok1.val(), token2 : tok2.val()};

		$('.text').attr('disabled','true');
		$.ajax({
			url: "sendmsg.php",	
			type: "POST",
			data: data,		
			cache: false,
			success: function (html) {				
				if (html=='Thank you! We have received your message.') {					
					$('.form').fadeOut('fast', function() {
									$('.done').fadeIn('fast');
								});					
				} else alert('Sorry, unexpected error. Please try again later.');
			}		
		});
		return false;
	});	
});	
