/*******************************************************************************
* Name         = metrovan.js
*
* Description  = General purpose Javascript functions.
*
* Revision History:
*
*  Date        Developer           Description
* ------------------------------------------------------------------------------
*  08/20/07    Maria Kaufmann      Initial implementation
********************************************************************************/

function validate(frm)
{
	// Validate Required Fields
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') ||
         ! validateField(frm.phoneNumber, 'Telephone') )
    {
        return false;
    }

	// Validate Qualification Questions
	 if ( ! validateField(frm.productInterest, 'Are you interested in Leasing?') ||
     	  ! validateField(frm.companyPrimaryBusiness, "What is your company's industry?") ||
		  ! validateField(frm.requestorRole, "Your role within your company?") ||
		  ! validateField(frm.natureOfInquiry, "Nature of the inquiry?") )
    {
        return false;
    }

    // If role within company is other, make sure user provided role
    if ( frm.requestorRole.value == "Other" && !validateField(frm.requestorRoleOther, "Specific Role") )
    {
        return false;
    }

	// Determine answer to e-mail question.
    var emailAnswer = "No";
    var iradiocount = frm.addToMailingList.length;
    for (i=0; i < iradiocount; i++ )
    {
        if ( frm.addToMailingList[i].checked )
        {
            if ( frm.addToMailingList[i].value == "Y" )
            	emailAnswer = "Yes";
            else
            	emailAnswer = "No";
            break;
        }
    }

	// Add non-standard information to remarks field
    frm.remarks.value = "Can we e-mail you? " + emailAnswer + " / Interested in Leasing? " + frm.productInterest.value;

    if ( !isEmpty(frm.requestorRoleOther) )
    	frm.remarks.value += " / Role: " + frm.requestorRoleOther.value;

	// Set Success and Failure pages
	if (frm.forwardToSuccessPage.value = "thankyou_apu"){
		frm.forwardToSuccessPage.value = "http://" + document.domain + "/greentruck/thankyou_apu.jsp";
    }else{
		frm.forwardToSuccessPage.value = "http://" + document.domain + "/greentruck/thankyou_hybrid.jsp";
	}
	
	frm.forwardToErrorPage.value = "http://" + document.domain + "/greentruck/index.jsp";

    // Success
    // alert("Validation completed successfully!");
    return true;
}

