var xmlhttp;
var alertMessage="";

function GetXmlHttpObject() {
if(window.XMLHttpRequest) {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();}
if(window.ActiveXObject) {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");}
return null;
}

function preValidate()
{
xmlhttp=GetXmlHttpObject();
if(xmlhttp==null) {
	alert ("Your browser does not support XMLHTTP!");
	return;}

xmlhttp.onreadystatechange=function() {
	if(xmlhttp.readyState==4) {
		alertMessage=xmlhttp.responseText;}
}

alertMessage="";
//encode form fields
if(document.postform) {
	if(document.getElementById("request").value=="register") {
		var formFields = "name_vchar=" + encodeURI(document.getElementById("name_vchar").value)
			+ "&company_vchar=" + encodeURI(document.getElementById("company_vchar").value)
			+ "&telephone_vchar=" + encodeURI(document.getElementById("telephone_vchar").value)
			+ "&email_vchar=" + encodeURI(document.getElementById("email_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	if(document.getElementById("request").value=="forgotten") {
		var formFields = "email_vchar=" + encodeURI(document.getElementById("email_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	if(document.getElementById("request").value=="login") {
		var formFields = "email_vchar=" + encodeURI(document.getElementById("email_vchar").value)
			+ "&password_vchar=" + encodeURI(document.getElementById("password_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	if(document.getElementById("request").value=="profile") {
		var formFields = "name_vchar=" + encodeURI(document.getElementById("name_vchar").value)
			+ "&company_vchar=" + encodeURI(document.getElementById("company_vchar").value)
			+ "&telephone_vchar=" + encodeURI(document.getElementById("telephone_vchar").value)
			+ "&email_vchar=" + encodeURI(document.getElementById("email_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	if(document.getElementById("request").value=="password") {
		var formFields = "current_password_vchar=" + encodeURI(document.getElementById("current_password_vchar").value)
			+ "&new_password_vchar=" + encodeURI(document.getElementById("new_password_vchar").value)
			+ "&confirm_new_password_vchar=" + encodeURI(document.getElementById("confirm_new_password_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	if(document.getElementById("request").value=="stock_enquiry") {
		var formFields = "body_vchar=" + encodeURI(document.getElementById("body_vchar").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	xmlhttp.open("POST", "validate_p.asp", false);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", formFields.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(formFields); }
if(document.getform) {
	if(document.getElementById("request").value=="search") {
		var formFields = "search_string=" + encodeURI(document.getElementById("search_string").value)
			+ "&request=" + encodeURI(document.getElementById("request").value);}
	xmlhttp.open("GET", "validate_p.asp?" + formFields, false)
	xmlhttp.send(null) }
if(alertMessage!="") {
	alert(alertMessage);
	return false;}
}

function setDefault() 
{
if(document.getform.search_string.value=="Your query") { 
	document.getform.search_string.value=""; }
}
