function validate_form(f) {
  if (isNotEmpty(f.companyName)) {
     if (ProductChosen(f.ProductID,f.Product_Other)) {
       if (isNotEmpty(f.FullName)) {
        if (isNotEmpty(f.email)) {
           if (isNotEmpty(f.recaptcha_response_field)) {
             return true;
           }
        }
     }
    }
  }
  return false;
}
function ProductChosen(select,fillin) {
    if (fillin.value == '') {
       if (select.selectedIndex == 0) {
           alert("Please make a choice from the list of products.");
           return false;
       }
    }
    return true;
}

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
   var searchCompanyReq = getXmlHttpRequestObject();

//Check to see if the company name exists
var CompanyExistsMsgID = 'CompanyExistsMsg';
var setCompanyExistsMsg = 'Exist';
var CompanySearchID = 'companyName';
var CompanyExistsMsg = "<br><font color='red'>A Company with that name already exists in our Database, please contact our "+
                       "<a href='mailto:info@epicorusers.org'>office</a> before you submit this registration to avoid duplicate entries.</font>";
function CheckCompanyExists() {
	if (searchCompanyReq.readyState == 4 || searchCompanyReq.readyState == 0) {
	    var elem = document.getElementById(CompanySearchID);
	    if (elem) {
	       //alert('Testing "'+elem.value+'"');
  		   var str = escape(elem.value);
		   searchCompanyReq.open("GET", '/members/CompanySearchExists.php?str=' + str, true);
		   searchCompanyReq.onreadystatechange = handleCompanyExists; 
		   searchCompanyReq.send(null);
		}
	}		
}

//Called when the AJAX response is returned.
function handleCompanyExists() {
	if (searchCompanyReq.readyState == 4) {
		var ss = document.getElementById(CompanyExistsMsgID)
		ss.innerHTML = '';
		var str = searchCompanyReq.responseText;
		//ss.innerHTML = '&quot;' + str + '&quot;';
        //debugger;        
		if (str == "0") {
		   if (setCompanyExistsMsg == 'Not Exist') ss.innerHTML = CompanyExistsMsg;
		} else {
		   if (setCompanyExistsMsg == 'Exist') ss.innerHTML = CompanyExistsMsg;
		}
		
	}
}