function ajaxvalidate()
{
//check if selected a brochure
var BR = document.getElementById("Brochure").checked;
var RN = document.getElementById("chk_0").checked;

var PD = document.getElementById("PD").value.length;

if (!(BR || RN) && PD<2)
{
alert("Please select a brochure or provide a description of your project.");
return false;
}

//check if all other required fields are filled out
  var fname = document.getElementById("fname").value.length;
  var cname = document.getElementById("cname").value.length;
  var address = document.getElementById("address").value.length;
  var city = document.getElementById("city").value.length;
  var state = document.getElementById("state").value;
  var zip = document.getElementById("zip").value.length;
  var country = document.getElementById("country").value;
  var phone = document.getElementById("phone").value.length;

  if (fname<2 ||cname<2 || address<2 || city<2 || !state || zip<2 || !country || phone<2)
  {
	alert("Error: You must fill out all of the required fields");
	return false;
  }

//check if email address is valid
  var EMail = document.getElementById("email").value;
  if ( validemail(EMail) == false)
  {
	alert("Error: You must enter a valid Email address");
	return false;
  }
  
var constcont1 = document.getElementById("chk_0").checked;
if (constcont1)
{
	document.getElementById("cchidden").value = "1";
}

var constcont= document.getElementById("Newsletter").checked;
if (constcont)
{
	ajaxFunction(EMail);
	return true;
}
return true;
}

function validemail(email)
{
  apos=email.indexOf("@");
  dotpos=email.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return false;}
  else {return true;}
}

function ajaxFunction(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  return;
  }
var url="constantcontact.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
