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 sub_consult() {
	name = document.getElementById('name').value;
	email = document.getElementById('email').value;
	project = document.getElementById('project').value;
	address = document.getElementById('address').value;
	zip = document.getElementById('zip').value;
	phone = document.getElementById('phone').value;
	time = document.getElementById('time').value;
	
		
	
	//check to make sure all fields are filled out
	if(name =="" || email =="" || project == "" || zip =="" || phone == "" || time == "" || name =="Name" || email =="E-Mail" || project == "Project" || zip == "Zip Code" || phone == "Phone" || time == "Best Time to Contact") {
		document.getElementById('error').innerHTML = "<p style='color:red'>All Fields Are Required.</p>";
		return false;
		//alert("All Fields Are Required.");
	}
	//check to make sure that email address has an @
	else if (email.indexOf("@")==-1){
		  document.getElementById('error').innerHTML = "<p style='color:red'>Invalid E-Mail Address</p>";
		  document.getElementById("email").focus();
		   return false;
		}
		
	//check to make sure that email address has an @
	else if (email.indexOf(".")==-1){
		  document.getElementById('error').innerHTML = "<p style='color:red'>All fields Are Required.</p>";
		   document.getElementById("email").focus();
		   return false;
		}
		
	//check to make sure that email address has an @
	else if (phone.length < 10 || phone.length > 15){
		   document.getElementById('error').innerHTML = "<p style='color:red'>Please enter a valid phone number.</p>";
		    document.getElementById("phone").focus();
		   return false;
		}
		
	else {
	
	
	var xmlhttp;
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 

	
	
  
var url="consult_process.php";
url=url+"?sid="+Math.random();
var parameters="&name="+name+"&email="+email+"&project="+project+"&address="+address+"&zip="+zip+"&phone="+phone+"&time="+time;
xmlhttp.open("POST", url, true);
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);


function loaded() {
//  alert('test');

document.getElementById("result").innerHTML=xmlhttp.responseText;
 document.getElementById("error").innerHTML="<p style='color:green'>Thank You!</p>";
document.getElementById('name').value = "Name";
document.getElementById('email').value = "E-Mail";
document.getElementById('project').value = "Project Description";
document.getElementById('address').value = "Address";
document.getElementById('zip').value = "Zip Code";
document.getElementById('phone').value = "Phone";
document.getElementById('time').value = "Best Time to Contact";
document.getElementById('submit').style.visibility='hidden';

}

function stateChanged()
{

if (xmlhttp.readyState==4)
  {
	  
  loaded();
  }
 if (xmlhttp.readyState==2)
  {
	
  document.getElementById("result").innerHTML="please hold...";
  }
}
}
}

function ck_txt(check) {
	check_value = document.getElementById(check).value;
	
	if (check_value == "E-Mail" || check_value == "Name" || check_value == "Phone" || check_value == "Comments/Questions" || check_value == "Project Description" || check_value == "Best Time to Contact" || check_value == "Zip Code" || check_value == "Address" ) {
		document.getElementById(check).value = "";
	}
	
	if (check == "project") {
		document.getElementById(check).style.height="70px";
	}
}

function refill_txt(refill) {
	refill_value = document.getElementById(refill).value;
	
	if (refill_value == "") {
		if (refill == "name") {
		document.getElementById(refill).value = "Name";
		}
		if (refill == "email") {
		document.getElementById(refill).value = "E-Mail";
		}
		if (refill == "phone") {
		document.getElementById(refill).value = "Phone";
		}
		if (refill == "comments") {
		document.getElementById(refill).value = "Comments/Questions";
		}
		if (refill == "project") {
		document.getElementById(refill).value = "Project Description";
		}
		if (refill == "time") {
		document.getElementById(refill).value = "Best Time to Contact";
		}
		if (refill == "zip") {
		document.getElementById(refill).value = "Zip Code";
		}
		if (refill == "address") {
		document.getElementById(refill).value = "Address";
		}
	}
	if (refill == "project") {
		document.getElementById(refill).style.height="25px";
	}
	
}

