//validate.js

var xmlHttp;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("info").innerHTML=xmlHttp.responseText;
  } 
}

function error_location() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("feedback").innerHTML=xmlHttp.responseText;
  } 
}




function validate()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
var email = document.getElementById("email").value;
var reason = document.getElementById("reason").value;

var params = "&email=" +email+"&reason="+reason;
url = "validate_email.php";
url=url+"?sid="+Math.random(); 
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xmlHttp.send(params);
}


function disable_sub(){
	document.getElementById("sub").disabled = true;	
	}

function enable_sub(){
	document.getElementById("sub").disabled = false;
	}	

	
function validate_form()
{ 


	var valid = true;

 var email = document.getElementById("email").value;
 var name = document.getElementById("name").value;
 var address1 = document.getElementById("address1").value;
 var address2 = document.getElementById("address2").value;
 var address3 = document.getElementById("address3").value;
 var postcode = document.getElementById("postcode").value;
 var phone = document.getElementById("phone").value;

 if (email == "") valid = false;
 if (name == "") valid = false;
 if (address1 == "") valid = false;
 if (address2 == "") valid = false;
 if (address3 == "") valid = false;
 if (postcode == "") valid = false;
 if (phone == "") valid = false;
 

//var params = "&name" +name+"&address1="+address1+"&address2="+address2+"&address3="+address3+"&postcode="+postcode+"&phone="+phone+"&country="+country;

if (valid == true) {enable_sub(); }
if (valid == false) {disable_sub();}


}