var strErrorSelectInvestorRequest = "";

function isEmptyInvestorRequest(str)
{
    for(var intLoop=0; intLoop<str.length; intLoop++)
      if(str.charAt(intLoop)!=" ")
        return false;
    return true;
}

function setFocusInvestorRequest (value) {
    if (strErrorSelectInvestorRequest == "") {
         strErrorSelectInvestorRequest = value;
    }
}

function validateFormInvestorRequest ()
{
	var f= document.investor_request;
	var strError= "";
	var strErrorSelect = "";
	
	if (isEmptyInvestorRequest(f.name.value)) {
         strError +="\n-- Name";
         setFocusInvestorRequest("name");
	}
	if (isEmptyInvestorRequest(f.address1.value)) {
         strError +="\n-- Address";
         setFocusInvestorRequest("address1");
	}
	if (isEmptyInvestorRequest(f.city.value)) {
         strError +="\n-- City";
         setFocusInvestorRequest("city");
	}
	if (isEmptyInvestorRequest(f.state.value)) {
         strError +="\n-- State";
         setFocusInvestorRequest("state");
	}
	if (isEmptyInvestorRequest(f.zip.value)) {
         strError +="\n-- Zip";
         setFocusInvestorRequest("zip");
	}
	if (isEmptyInvestorRequest(f.email.value)) {
         strError +="\n-- Email";
         setFocusInvestorRequest("email");
	} else if (!validEmailInvestorRequest(f.email.value)) {
		 strError +="\n-- Invalid Email Address";
         setFocusInvestorRequest("email");
	}
	
	strErrorSelect = strErrorSelectInvestorRequest;

	//display error message
    if(strError !="") {
		alert("The following required data is missing or not valid:\n" + strError);
		if (strErrorSelect != "") {
		     if (document.investor_request[strErrorSelect]) {
		         document.investor_request[strErrorSelect].focus();
			 }
		}
		strErrorSelectInvestorRequest = "";
		return false;
    } else {
		return true;
	}
}

function validEmailInvestorRequest(emailS) {
  if (emailS.indexOf("@") > 0 && emailS.indexOf(".") != -1 && emailS.lastIndexOf(".") < (emailS.length-2) && emailS.lastIndexOf(".")>0 && (emailS.lastIndexOf(".") - emailS.lastIndexOf("@") > 1) ) 
  {
    return true;
  } else {
    return false;
  }	
}

function nextFieldInvestorRequest(as_next)
{
  document.investor_request[as_next].focus();
}