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

        //validate last_name
        if (checkString(last_name,"'Last Name'")==false) {
            selectField(document.getElementById('last_name').id,'last_name');
            return false;
        }
        else {
            deselectField(document.getElementById('last_name').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 zip
        if(checkString(zip,"'Zip/Postal Code'")==false) {
            selectField(document.getElementById('zip').id,'zip');
            return false;
        }
        else {
            deselectField(document.getElementById('zip').id);
        }
    
        if(checkZipPostalCode(zip)==false) {
            if(country.value == 'US') alert("Please enter a valid Zip Code.");
            if(country.value == 'CA') alert("Please enter a valid Postal Code.");
            selectField(document.getElementById('zip').id,'zip');
            zip.focus();
            return false;
        }
        else {
            deselectField(document.getElementById('zip').id);
        }
      
        
        //validate email
        if (checkString(email,"'E-mail'")==false) {
            selectField(document.getElementById('email').id,'email');
            return false;
        }
        else {
            deselectField(document.getElementById('email').id);
        }
        
        if (checkEmail(email,"'E-mail'")==false) {
            selectField(document.getElementById('email').id,'email'); 
            return false;
        }
        else {
            deselectField(document.getElementById('email').id);
        }
        
               
        //validate confirmemail
        if (checkString(confirmemail,"'Confirm E-mail'")==false) {
            selectField(document.getElementById('confirmemail').id,'confirmemail');
            return false;
        }
        else {
            deselectField(document.getElementById('confirmemail').id);
        }

        if (confirmemail.value!=email.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('confirmemail').id,'confirmemail');
            return false;
        }
        else {
            deselectField(document.getElementById('confirmemail').id);
        }

        
        //validate phone
        if (checkString(phone,"'Business Phone'")==false) {
            selectField(document.getElementById('phone').id,'phone');
            return false;
        }
        else {
            deselectField(document.getElementById('phone').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['00N60000001PoQm'].value = selectedProdLines;
    //alert(thisform.elements['00N60000001PoQm'].value);


    //copy contents of State/Province or Region/Province/State to a single hidden "state" field for form submission
    if(thisform.StateProvince != null) {
        if(thisform.StateProvince.value != '') {
            thisform.state.value = thisform.StateProvince.value;
        }
    }        
    if(thisform.RegionProvinceState != null) {
        if(thisform.RegionProvinceState.value != '') {
            thisform.state.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