//function to check & validate required form fields
function validateForm(thisform) {
    with (thisform)
    {
    //alert('validate test');     
        
        //validate FirstName
        if (checkString(FirstName,"'First Name'")==false) { 
            selectField(document.getElementById('FirstName').id,'FirstName');
            return false;
        }
        else {
            deselectField(document.getElementById('FirstName').id);
        }
        

        //validate LastName
        if (checkString(LastName,"'Last Name'")==false) {
            selectField(document.getElementById('LastName').id,'LastName');
            return false;
        }
        else {
            deselectField(document.getElementById('LastName').id);
        }
  

        //validate Title      
        if (checkString(Title,"'Position/Title'")==false) {
            selectField(document.getElementById('Title').id,'Title');
            return false;
        }
        else {
            deselectField(document.getElementById('Title').id);
        }


        //validate industry
        if(thisform.industry) {
            if (checkString(industry,"'Business Type'")==false) {
                selectField(document.getElementById('industry').id,'industry');
                return false;
            }
            else {
                deselectField(document.getElementById('industry').id);
            }
        }
        

        //validate CompanySize
        if(thisform.CompanySize) {
            if (checkString(CompanySize,"'Company Size'")==false) {
                selectField(document.getElementById('CompanySize').id,'CompanySize');
                return false;
            }
            else {
                deselectField(document.getElementById('CompanySize').id);
            }
        }


        //validate Country
        if (checkString(Country,"'Country'")==false) {
            selectField(document.getElementById('Country').id,'Country');
            return false;
        }
        else {
            deselectField(document.getElementById('Country').id);
        }

        if(Country.value == "US" || Country.value == "CA") {
            if (checkString(StateProvince,"'State/Province'")==false) {
                selectField(document.getElementById('StateProvince').id,'StateProvince');
                return false;
            }
            else {
                deselectField(document.getElementById('StateProvince').id);
            }
        }


        //validate ZipPostalCode
        if(checkString(ZipPostalCode,"'Zip/Postal Code'")==false) {
            selectField(document.getElementById('ZipPostalCode').id,'ZipPostalCode');
            return false;
        }
        else {
            deselectField(document.getElementById('ZipPostalCode').id);
        }
    
        if(checkZipPostalCode(ZipPostalCode)==false) {
            if(Country.value == 'US') alert("Please enter a valid Zip Code.");
            if(Country.value == 'CA') alert("Please enter a valid Postal Code.");
            if(Country.value == 'US' || Country.value == 'CA') {
                selectField(document.getElementById('ZipPostalCode').id,'ZipPostalCode');
                ZipPostalCode.focus();
                return false;
            }
        }
        else {
            deselectField(document.getElementById('ZipPostalCode').id);
        }
      
        
        //validate EmailAddress
        if (checkString(EmailAddress,"'E-mail'")==false) {
            selectField(document.getElementById('EmailAddress').id,'EmailAddress');
            return false;
        }
        else {
            deselectField(document.getElementById('EmailAddress').id);
        }
        
        if (checkEmail(EmailAddress,"'E-mail'")==false) {
            selectField(document.getElementById('EmailAddress').id,'EmailAddress'); 
            return false;
        }
        else {
            deselectField(document.getElementById('EmailAddress').id);
        }
        
               
        //validate ConfirmEmailAddress
        if (checkString(ConfirmEmailAddress,"'Confirm E-mail'")==false) {
            selectField(document.getElementById('ConfirmEmailAddress').id,'ConfirmEmailAddress');
            return false;
        }
        else {
            deselectField(document.getElementById('ConfirmEmailAddress').id);
        }

        if (ConfirmEmailAddress.value!=EmailAddress.value) {
            alert("The e-mail address you entered does not match the one you entered in the 'E-mail' field. Please reconfirm your e-mail address.");
            selectField(document.getElementById('ConfirmEmailAddress').id,'ConfirmEmailAddress');
            return false;
        }
        else {
            deselectField(document.getElementById('ConfirmEmailAddress').id);
        }

        
        //validate BusinessPhone
        if (checkString(BusinessPhone,"'Phone Number'")==false) {
            selectField(document.getElementById('BusinessPhone').id,'BusinessPhone');
            return false;
        }
        else {
            deselectField(document.getElementById('BusinessPhone').id);
        }

        
        //validate prodLine
        if(checkGroup(prodLine)==false) {
            alert("You have not made any selection in the 'Product Lines of Interest' section of the form. Please make at least one selection.");
            selectGroup(prodLine,'prodLine');
            document.location='#fieldset_prodLine';
            return false;
        }
        else {
            deselectGroup(prodLine,'prodLine');
        }
    } //end "with(thisform)" 


    //populates the hidden "00N60000001TjOd" field with the selected Product Line values
    var selectedProdLines = "";
    for(i=0; i < thisform.prodLine.length; i++) {
        if(thisform.prodLine[i].checked==true){
            if(selectedProdLines == '') {
                selectedProdLines = thisform.prodLine[i].value;
            }
            else {
                selectedProdLines = selectedProdLines + ", " + thisform.prodLine[i].value;
            }
        }
    }
    thisform.elements['00N60000001TjOd'].value = selectedProdLines;


    //copy contents of State/Province or Region/Province/State to a single hidden Region/Province/State field for form submission
    if(thisform.StateProvince != null) {
        if(thisform.StateProvince.value != '') {
            thisform.elqStateProvinceRegion.value = thisform.StateProvince.value;
        }
    }        
    if(thisform.RegionProvinceState != null) {
        if(thisform.RegionProvinceState.value != '') {
            thisform.elqStateProvinceRegion.value = thisform.RegionProvinceState.value;
        }
    } 


    //copy contents of "Company Size" field to the "00N60000001SXb4" hidden field for SalesForce compatibility    
        if(thisform.CompanySize != null) {
            if(thisform.CompanySize.value != '') {
                thisform.elements['00N60000001SXb4'].value = thisform.CompanySize.value;
            }
        } 


    //set value of "Lead Type" field based on value of "industry" field
    if(thisform.industry != null && thisform.elements['00N60000001PoQi']) {
        if(thisform.industry.value != 'Reseller' && thisform.industry.value != '') {
            thisform.elements['00N60000001PoQi'].value = 'End Customer';
        }
        else {
            if(thisform.industry.value == 'Reseller') {
                thisform.elements['00N60000001PoQi'].value = thisform.industry.value;
            }
        }
    }    
        
    thisform.submit();        
}
//end