var xmlhttp_amb_contact = getXmlHttpObject();

function amb_contact_checkForm() {
	var f = document.amb_contact_form;
	
	if (!hasData(f.amb_contact_message.value)) {
		alert("Field 'Message' is required. Please enter your message.");
		f.amb_contact_message.focus();
		return false;	
	}

	if (!hasData(f.amb_contact_name.value)) {
		alert("Field 'Name' is required. Please enter your name.");
		f.amb_contact_name.focus();
		return false;	
	}

	if (!hasData(f.amb_contact_subject.value)) {
		alert("Field 'Subject' is required. Please enter your subject.");
		f.amb_contact_subject.focus();
		return false;	
	}

	if (!isEmail(f.amb_contact_email.value)) {
		alert("The form of 'E-mail' field is not valid. Example of well formed email is: your.name@gmail.com.");
		f.amb_contact_email.focus();
		return false;	
	}	
	

	xmlhttp_amb_contact.onreadystatechange=amb_contact_stateChanged;
	xmlhttp_amb_contact.open("GET","/mail_it_amb_contact.php?email="+f.amb_contact_email.value+"&name="+escape(f.amb_contact_name.value)+"&subject="+escape(f.amb_contact_subject.value)+"&message="+escape(f.amb_contact_message.value)+"&dstname="+escape(f.dstname.value)+"&dsthost="+escape(f.dsthost.value),true);
	xmlhttp_amb_contact.send(null);
	
	return false;
}


function amb_contact_stateChanged() {
	if (xmlhttp_amb_contact.readyState==4) {
		if (xmlhttp_amb_contact.status==200) {
			if (xmlhttp_amb_contact.responseText == "ok") {
				alert("Your e-mail was successfully sent.");
				document.amb_contact_form.reset();
			} else {
				alert("There was an error sending your message. Please try again later.");
			}
		} else {
			alert("There was an error sending your message. Please try again later.");
		}
	}
}