$(document).ready(function(){
	$('input[name="perform"]').click(function(){
		var ok = 1;
		$('.required').each(function(){
			if ($(this).val() == '' || ($(this).attr('name').match('email') && !validEmail($(this).val()) ) ) {
				$(this).css('backgroundColor','#edd3d7');
				ok = 0;
			}
			else {
				$(this).css('backgroundColor','#ffffff');
			}
		});
		
		if (!ok) {
			alert('Please complete the highlighted fields');
			return false;
		}
                else{
                  // check for add testimonial form-- do ajax submit
                  if( $(this).parent().parent().parent().attr('id') == 'addTestForm' ){
                    $.post("includes/testimonials.php", $("#addTestForm").serialize(), function(data){
                      $("#addTestimo").html('<h3>'+data.msg+'</h3>');
                      //var t = setTimeout("hideTestimo()",3000);
                    }, "json");
                  }
                }
	});
});

function validEmail (email) {
	var check = email.replace(/([\w|\d|.]{2,})+@([\w|\d]{2,}[.]+)+([a-zA-Z]{2,})+/,'');
	if (check == '') {
		return true;
	}
	else {
		return false;	
	}
}

function hideTestimo(){
  $("#addTestimo").css('display', 'none');
}
