//JavaScript File

if (typeof testim != "undefined" && testim){
	$("#testims").load("db/site_proc.php", {proc:"testim"});
}

function validate_form(){
	if(valid_form(document.contactus)){
		if(valid_recaptcha(document.contactus)){
			snd_mail();
		}
	}
}
	
function valid_form(passForm){
	if(passForm.full_name.value == ""){
		alert("Please enter your name");
		return false;
	}
	if(passForm.email.value == ""){
		alert("Please enter your email");
		return false;
	}
	if(passForm.request.value == ""){
		alert("Please enter your request");
		return false;
	}
	return true; 
}

function valid_recaptcha(passForm){
	 if (passForm.recaptcha_response_field.value == "")
	 {
		alert("Please enter the validation text");
		passForm.recaptcha_response_field.focus();
		return false
	} else {
		var prvkey = "6LebDLsSAAAAAF-CNdPq7Y6vside5_Rkp_YjqRJ3"
		var remIP = $("#clientIP").val();
		var recap_challenge = $("#recaptcha_challenge_field").val();
		var recap_response = $("#recaptcha_response_field").val();
		jQuery.post("db/site_proc.php", {proc:"valid_recaptcha", privatekey:prvkey, recap_challenge:recap_challenge, recap_response:recap_response},
			function(data){
				if(data.result == "process"){
					snd_mail();		
				} else {
					alert("Error with recaptcha\n" + data.error);
					return false;
				}
			}, "json");
	}
}

function snd_mail(){
	var full_name = $("#full_name").val();
	var email = $("#email").val();
	var request = $("#request").val();
	
	jQuery.post("db/site_proc.php", {proc:"snd_mail", full_name:full_name, email:email, request:request}, 
				function(data){
					if(data.result == "success"){
						alert("Thank you, your message has been sent");
						clear_all();
					} else {
						alert("Error with mail application");
						$("#full_name").focus();
					}
				}, "json");
}

function clear_all(){
	$("#full_name").val('');
	$("#email").val('');
	$("#request").val('');
	Recaptcha.reload();
	$("#full_name").focus();
}

