/*******************************************************************************
* Name         = general.js
*
* Description  = General purpose Javascript functions.
*
* Revision History:
*
*  Date        Developer           Description
* ------------------------------------------------------------------------------
*  09/01/05    Maria Kaufmann      Initial implementation
*  09/29/05    Maria Kaufmann      Modified LeftNav_showMenu(id) to collapse
*                                  any other menus currently expanded.  Also
*                                  Added openWindow() function.
*  10/17/05    Maria Kaufmann      Added function goToSelectedLink().
*  10/27/05    Maria Kaufmann      Added function displayPrinterFriendly().
*  11/10/05    Maria Kaufmann      Added function changeGroupTextColor().
*  11/18/05	   Maria Kaufmann      Added several form validation functions.
*  04/18/06    Maria Kaufmann      Added functions to manipulate cookies.
*  07/27/06    Maria Kaufmann      Modified openWindow() function to always
*                                  show status bar.
*  08/17/06    Maria Kaufmann      Added check for links set to "#" in
*                                  goToSelectedLink() function.
*  08/18/06    Maria Kaufmann      Added functions processSelection() and
* 								    checkRegionPreference().
*  08/30/06    Maria Kaufmann      Added function validateEmployeeAuthForm(frm).
*  08/31/06    Maria Kaufmann      Corrected typo in LeftNav_showMenu(id) where
*                                  div id name should start with "sm_" instead
*                                  of "sm-".
*  09/01/06    Maria Kaufmann      Applied changes to LeftNav_showMenu(id)
*                                  function to change left image arrow icon to
*                                  point in the right direction when collapsed
*                                  and expanded.
*  09/05/06    Maria Kaufmann      Updated getSelectedOption(listBox) and
*                                  processSelection(frm) to check for blank URL
*                                  values.
*  09/12/06    Maria Kaufmann      Added functions to validate Contact Us forms
*                                  for Rental, Leasing and Maintenance, and
*                                  Supply Chain.
*  09/13/06    Maria Kaufmann      Modified validateContactUsLMS(frm) function
*                                  to ensure answers to qualification questions
*                                  are provided.
*  09/15/06    Maria Kaufmann      Added function validateTemplatedMailForm().
*  09/15/06    Maria Kaufmann      Added function validateContactUsMain(frm).
*  09/21/06    Maria Kaufmann      Added function validateEPAForm(frm).
*  09/21/06    Maria Kaufmann      Added function openTool() and modified
*                                  function goToSelectedLink() to return listbox
*                                  to default option after tool selection is
*                                  made.
*  09/21/06    Maria Kaufmann      In goToSelectedLink(), modified to call
*                                  openTool() function instead of OpenWindow().
*  09/27/06    Damian Castroviejo  In displayPrinterFriendly(), modified to
*								   escape the 'title' param encoding format.
*  10/10/06    Maria Kaufmann      Added function validateRFPLMS().
*  10/20/06    Maria Kaufmann      Added validation for 3-yr flex lease to
*                                  validateContactUsMain(frm).
*  11/01/06    Maria Kaufmann      Updated openWindow() function to enable
*                                  display of the toolbar and back buttons on
*                                  tool owners' request.
*  11/03/06    Maria Kaufmann      Updated function validateContactUsMain() to
*                                  remove validation for SCS checkboxes, which
*                                  have been removed.
*  01/30/07    Maria Kaufmann      Added function validateChoiceLeaseForm().
*  07/05/07    Maria Kaufmann      Added call to Coremetrics tag
*                                  cmCreateRegistrationTag() from validation
*                                  function for Contact Us forms.
* 10/15/09		Antonio Suarez		Added functionality for dropdown choice for 
									careers_search.shtml
********************************************************************************/

/*******************************************************************************
* Name of cookie holding global region preference
*******************************************************************************/
var cookieGlobalRegionPref = "RyderGlobalRegionPref";

/*******************************************************************************
* Expands the left navigation bar's second-level menu items under the
* first-level menu identified by id.
*******************************************************************************/
function LeftNav_showMenu(id)
{
	var element = document.getElementById(id);
    var linkImgName = "img_" + id;

	// Toggle the state of the current division
	if ( element != null )
	{
		if ( element.style.display != "block" )
    	{
			element.style.display = "block";

            if ( document[linkImgName] != null )
				document[linkImgName].src = "images/nav_icon_down.gif";
    	}
    	else
    	{
			element.style.display = "none";

            if ( document[linkImgName] != null )
            	document[linkImgName].src = "images/nav_icon.gif";
    	}

		// Hide all other divisions
		if ( document.all )
		{
			// This is an IE browser.
			var divcount = document.all.tags("div").length;
			var divarray = document.all.tags("div");
			for ( var i=0; i < divcount; i++ )
			{
				if ( divarray[i].id )
				{
					if ( divarray[i].id.indexOf("sm_") != -1 &&
						 divarray[i].id != id )
					{
						document.getElementById(divarray[i].id).style.display = "none";

                        var linkImgName2 = "img_" + divarray[i].id;
                        if ( document[linkImgName2] != null )
                        	document[linkImgName2].src = "images/nav_icon.gif";
					}
				}
			} // end for
		} // end if ( document.all )
	} // end if ( element != null )

}

/*******************************************************************************
* Opens a scrollable, resizeable window with no menubar and tool bars.
*******************************************************************************/
function openWindow(url, urlDescription, height, width)
{
	if ( height == null ) height = 400;
	if ( width == null ) width = 600;

	var windowOptions = "width="  + width  + ",height=" + height + ",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes";
  	window.open (url, urlDescription, windowOptions);
}

/*******************************************************************************
 * Get selected option
 */
function getSelectedDropdownValue(obj)
{
	var myindex  = obj.selectedIndex;
    var SelValue = obj.options[myindex].value;

    return SelValue;

}

/*******************************************************************************
 * Open external links.
 */
function getSearchJobDropDownValue(obj, obj1, url)
{
	var iAm = getSelectedDropdownValue(document.getElementById(obj));
	var iInterested = getSelectedDropdownValue(document.getElementById(obj1));
	
	//Driver / Tech - External
	var url = 'http://www.ryder.apply2jobs.com/index.cfm?fuseaction=mhvexternal.showPositions'
	//Driver / Tech Internal
	var url1 = 'http://www.ryder.apply2jobs.com/index.cfm?fuseaction=main.hvicc'
	//Professional / Administrative - External
	var url2 = 'http://www.ryder.apply2jobs.com/index.cfm?fuseaction=mExternal.showSearchInterface'
	//Professional / Administrative - Internal
	var url3 = 'http://www.ryder.apply2jobs.com/index.cfm?fuseaction=main.icc'
	
	if (iAm == "employee" || (iInterested == "prof" && iInterested == "driver"))
	{
		if (iInterested == "prof") { 
			openWindow(url3, null,600,800) 
		}else{ 
			openWindow(url1, null,600,800); 
		}
	}
	else if (iAm == "futureSap" || (iInterested == "prof") && iInterested == "driver")
	{
		if (iInterested == "prof") { 
			openWindow(url2, null,600,800); 
		}else{ 
			openWindow(url, null,600,800);
		}
	}
	
}

/*******************************************************************************
* Opens a scrollable, resizeable window with no menubar and tool bars.
*******************************************************************************/
function openTool(url, urlDescription, height, width, suppressMenuBar)
{
	if ( height == null ) height = "600";
	if ( width == null ) width = "800";

    var strMenuOptions = ",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=yes,location=yes";
    if ( suppressMenuBar != null && suppressMenuBar == true )
    	strMenuOptions = ",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no,location=no";

	var windowOptions = "width="  + width  + ",height=" + height + strMenuOptions;
  	window.open (url, urlDescription, windowOptions);
}

/*******************************************************************************
* Given a form.select object, with a pick list of URL value definitions, this
* function takes the user to the link selected from the pick list.
*******************************************************************************/
function goToSelectedLink(selectObj)
{
	if ( selectObj != undefined && selectObj != null )
	{
    	var selIndex = selectObj.options.selectedIndex;
        var toolURL = selectObj.options[selIndex].value;
		if ( selIndex != -1 && selectObj.options[selIndex].value != "#")
		{
			openTool(toolURL, "OnlineTool", 600, 800);

            // Select default option.
            selectObj.options.selectedIndex = 0;
		}
	}
}

/*******************************************************************************
* Displays the content specified in a printer friendly pop-up window.  The
* 'title' parameter indicates the page title.  The 'relPathToContent' parameter
* indicates the relative path to the content file to display (e.g.
* 'content/fms_sol_dcc.html'.
*******************************************************************************/
function displayPrinterFriendly(title, relPathToContent)
{
	var fullURL = "http://" + document.domain + "/printerfriendly.jsp?title=" +
		escape(title) + "&rpfile=" + relPathToContent;

	openWindow(fullURL, null, 500, 650);
}

/*******************************************************************************
* Changes the color of the text of the element specified to the value specified.
*******************************************************************************/
function changeGroupTextColor(color, idprefix, startIndex, endIndex)
{
	var idname;
	var element;

	alert

	for ( var i=startIndex; i <= endIndex; i++ )
	{
		idname = idprefix + i;
		element = document.getElementById(idname);
		if ( element != null ) element.style.color = color;
	}
}

function trimField(formField)
{
    var str = formField.value;
    while (str.substr(0,1) == " " || str.substr(str.length - 1) == " ")
    {
        if (str.substr(0,1) == " ")
        {
            str = str.substr(1);
        }
        else
        {
            str = str.substr(0, str.length - 1);
        }
    }

    formField.value = str;
}

/*******************************************************************************
* Returns true if the form field with the name (fieldName) specified is not
* empty.  Returns false otherwise.
*******************************************************************************/
function isEmpty(field)
{
    trimField(field);
	if (field.value == "")  return true;

    return false;
}

/*******************************************************************************
* Returns true if the form field with the name (fieldName) specified is not
* empty.  Returns false otherwise.
*******************************************************************************/
function validateField(field, fieldName)
{
    if ( isEmpty(field) )
    {
        alert("Please enter a value in the '" + fieldName + "' field");
        field.focus();
        return false;
    }

    return true;
}

/*******************************************************************************
* Checks the for the validity of the e-mail address format by checking for the
* the occurrence of the '@' and '.' characters in the e-mail address string.
*******************************************************************************/
function isValidEmail(field, fieldName)
{
   if ( !(field.value.indexOf(".") > 2) || !(field.value.indexOf("@") > 0) )
   {
	   	alert("The e-mail address field is invalid. Please re-enter the " + fieldName + ".");
		field.focus();
		return false;
   }

   return true;
}

/*******************************************************************************
* Returns the value of the option selected from the list-box.
* Note: it is assumed that this is a single-select list-box.
*******************************************************************************/
function getSelectedOption(listBox)
{
	var i = 0;
	var strLinkURL = "";

	//  Iterate through list-box options to see which one was selected.
    while (i < listBox.options.length)
	{
	    if ( listBox.options[i].selected )
		{
			// Get the url link associated with selected option
            strLinkURL = listBox.options[i].value;
            break;
        }
		i++;
	}

	// If URL text is blank, return null
	if ( strLinkURL == "" ) return null;

	return strLinkURL;
}

/*******************************************************************************
* Sets the value of the cookie by the given name.  Null is returned if no
* cookie exists with that name.
*******************************************************************************/
function setCookie(cookieName, cookieValue, expireDays)
{
	var expirationDate = new Date(new Date().getTime() + (expireDays * 24 * 3600000));
	document.cookie = cookieName + "=" + escape(cookieValue) +
		((expireDays == null) ? "" : ";expires=" + expirationDate.toGMTString() );
}

/*******************************************************************************
* Retrieved the value of the cookie by the given name.  Null is returned if no
* cookie exists with that name.
*******************************************************************************/
function getCookie(cookieName)
{
	var cookieValue = null;

	if (document.cookie.length > 0)
  	{
  		cookieStart = document.cookie.indexOf(cookieName + "=");
  		if (cookieStart !=-1)
    	{
    		cookieStart = cookieStart + cookieName.length + 1;
    		cookieEnd = document.cookie.indexOf(";",cookieStart);
    		if (cookieEnd == -1)
				cookieEnd = document.cookie.length;

    		cookieValue = unescape(document.cookie.substring(cookieStart,cookieEnd));
    	}
  	}

	return cookieValue;
}

/*******************************************************************************
* Redirects user to the web site for the global region selected.  If remember
* my location checkbox is checked, the user's selection is saved onto a cookie
* for future reference.
*******************************************************************************/
function processSelection(frm)
{
	// Get the selected region.
	var selectedGlobalRegion = getSelectedOption(frm.region);

    if ( selectedGlobalRegion == null )
    {
        alert("Please select a global region from the pick list.")
        return false;
    }

	// Save region website URL in cookie if user wants us to remember selection.
	if ( frm.rememberSelection.checked == true )
	{
		setCookie(cookieGlobalRegionPref, selectedGlobalRegion, 3650);
	}

	// Redirect user to region web site.
	document.location.href = selectedGlobalRegion;
}

/*******************************************************************************
* Check existence of cookie holding region preference.  If exists, redirect user
* to region website.
*******************************************************************************/
function checkRegionPreference(bIgnoreCookieSetting)
{
    if ( !bIgnoreCookieSetting )
    {
		var selectedRegion = getCookie(cookieGlobalRegionPref);

    	// If cookie set, redirect user to previously selected global website.
		if ( selectedRegion != null )
		{
			document.location.href = selectedRegion;
		}

        // If cookie not set, redirect user to global site selector page.
		//document.location.href = "globalsiteselector.jsp";
    }
}

/*******************************************************************************
* Limits the size of the textarea specified to maxSize.
*******************************************************************************/
function limitTextAreaSize(fieldTextArea, maxSize)
{
    if (fieldTextArea.value.length >= maxSize)
    {
		alert("You may only enter up to " + maxSize + " characters of text.");
        fieldTextArea.value = fieldTextArea.value.substr(0, maxSize);
        return false;
    }
	else
		return true;
}

/*******************************************************************************
* Validates all fields required for the Employee Authentication form have been
* provided.
*******************************************************************************/
function validateEmployeeAuthForm(frm)
{
    if ( ! validateField(frm.firstname, 'First Name') ||
         ! validateField(frm.lastname, 'Last Name') ||
         ! validateField(frm.sap, 'Personnel Number') )
    {
        return false;
    }

    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for Rental section
*******************************************************************************/
function validateContactUsRental(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State/Province') ||
         ! validateField(frm.postalCode, 'Zip/Postal Code') ||
         ! validateField(frm.country, 'Country') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') )
    {
        return false;
    }

    // Make sure at least one information category has been checked.
    var bInfoCatChecked = false;

    if ( frm.vehicleRental.checked ) bInfoCatChecked = true;
    else if ( frm.usedVehicleSales.checked ) bInfoCatChecked = true;

    if ( ! bInfoCatChecked )
    {
        alert("Please select at least one of the products\n" +
          "for which you wish to receive information.");
        frm.firstName.focus();
        return false;
    }


	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( ! validateField(frm.remarks, 'Tell us more about your inquiry') ||
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }


	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/rental_contactus_contactthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/contactformrental.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "Rental Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for Leasing and Maintenance Section.
*******************************************************************************/
function validateContactUsFMS(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State/Province') ||
         ! validateField(frm.postalCode, 'Zip/Postal Code') ||
         ! validateField(frm.country, 'Country') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') )
    {
        return false;
    }

    // Make sure at least one information category has been checked.
    var bInfoCatChecked = false;

    if ( frm.vehicleLeasing.checked ) bInfoCatChecked = true;
    else if ( frm.fleetMaintenance.checked ) bInfoCatChecked = true;
    else if ( frm.usedVehicleSales.checked ) bInfoCatChecked = true;
    else if ( frm.procurement.checked ) bInfoCatChecked = true;
    else if ( frm.threeYearLease.checked ) bInfoCatChecked = true;

    if ( ! bInfoCatChecked )
    {
        alert("Please select at least one of the products\n" +
          "for which you wish to receive information.");
        frm.firstName.focus();
        return false;
    }


	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( ! validateField(frm.remarks, 'Tell us more about your inquiry') ||
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }


	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/fms_contactus_contactthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/contactformfms.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "Leasing and Maintenance Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for Supply Chain Section.
*******************************************************************************/
function validateContactUsLMS(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State/Province') ||
         ! validateField(frm.postalCode, 'Zip/Postal Code') ||
         ! validateField(frm.country, 'Country') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') )
    {
        return false;
    }

    // Make sure at least one information category has been checked.
    var bInfoCatChecked = false;

    if ( frm.supplyChain.checked ) bInfoCatChecked = true;
    else if ( frm.distOperations.checked ) bInfoCatChecked = true;
    else if ( frm.transSolutions.checked ) bInfoCatChecked = true;
    else if ( frm.dedicatedContractCarriage.checked ) bInfoCatChecked = true;

    if ( ! bInfoCatChecked )
    {
        alert("Please select at least one of the products\n" +
          "for which you wish to receive information.");
        frm.firstName.focus();
        return false;
    }

	// Validate Qualification Questions
	 if ( ! validateField(frm.companyPrimaryBusiness, "Your company's Industry") ||
		  ! validateField(frm.companyMarketArea, "Your company's market area") ||
         ! validateField(frm.companyAnnualRevenue, "Your company's annual revenue") ||
         ! validateField(frm.natureOfInquiry, "Nature of inquiry") ||
		  ! validateField(frm.requestorRole, "Your role within your company") ||
         ! validateField(frm.referenceSource, "How did you hear about Ryder?") )
    {
        return false;
    }

	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( ! validateField(frm.remarks, 'Tell us more about your inquiry') ||
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }

	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/lms_contactus_inq_inqthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/contactformlms.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "SCS Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for Supply Chain Section.
*******************************************************************************/
function validateContactUsMain(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State/Province') ||
         ! validateField(frm.postalCode, 'Zip/Postal Code') ||
         ! validateField(frm.country, 'Country') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') )
    {
        return false;
    }

    // Make sure at least one information category has been checked.
    var bInfoCatChecked = false;

    if ( frm.vehicleLeasing.checked ) bInfoCatChecked = true;
    else if ( frm.vehicleRental.checked ) bInfoCatChecked = true;
    else if ( frm.fleetMaintenance.checked ) bInfoCatChecked = true;
    else if ( frm.usedVehicleSales.checked ) bInfoCatChecked = true;
    else if ( frm.procurement.checked ) bInfoCatChecked = true;
    else if ( frm.threeYearLease.checked ) bInfoCatChecked = true;

    if ( ! bInfoCatChecked )
    {
        alert("Please select at least one of the products\n" +
          "for which you wish to receive information.");
        frm.firstName.focus();
        return false;
    }

	// Validate Qualification Questions
	 if ( ! validateField(frm.companyPrimaryBusiness, "Your company's Industry") ||
		  ! validateField(frm.companyMarketArea, "Your company's market area") ||
         ! validateField(frm.companyAnnualRevenue, "Your company's annual revenue") ||
         ! validateField(frm.natureOfInquiry, "Nature of inquiry") ||
		  ! validateField(frm.requestorRole, "Your role within your company") ||
         ! validateField(frm.referenceSource, "How did you hear about Ryder?") )
    {
        return false;
    }

	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( ! validateField(frm.remarks, 'Tell us more about your inquiry') ||
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }

	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/contactus_custserv_products_productsthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/contactformmain.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "FMS General Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for the Emissions Appointment form.
*******************************************************************************/
function validateEPAForm(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
         ! validateField(frm.jobTitle, 'Job Title') ||
		 ! validateField(frm.phoneNumber, 'Phone Number') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State') ||
         ! validateField(frm.postalCode, 'Zip Code') )
    {
        return false;
    }

	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( ! validateField(frm.remarks, 'Remarks') ||
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }

	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/fms_engine_appts_apptsthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/epaappointments.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "EPA Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Contact Us Form for Choice Lease
*******************************************************************************/
function validateChoiceLeaseForm(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
		 ! validateField(frm.phoneNumber, 'Phone Number') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') ||
        ! validateField(frm.postalCode, 'Zip Code') )
    {
        return false;
    }

	// Trim remarks field.
	trimField(frm.remarks);

	// Validate remarks field
    if ( frm.remarks != "" &&
		 ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }

	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/fms_choicelease_choicecontactus_choicecontactthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/choicecontactus.jsp";

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "ChoiceLease Inquiry");

	// Success
    return true;
}

/*******************************************************************************
* Validates the Request for Proposal Form in the Supply Chain Section.
*******************************************************************************/
function validateRFPLMS(frm)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.firstName, 'First Name') ||
		 ! validateField(frm.lastName, 'Last Name') ||
         ! validateField(frm.jobTitle, 'Title') ||
		 ! validateField(frm.companyName, 'Company Name') ||
         ! validateField(frm.address, 'Address') ||
         ! validateField(frm.city, 'City') ||
         ! validateField(frm.provinceState, 'State/Province') ||
         ! validateField(frm.postalCode, 'Zip/Postal Code') ||
         ! validateField(frm.country, 'Country') ||
		 ! validateField(frm.emailAddress, 'E-mail Address') ||
		 ! isValidEmail(frm.emailAddress, 'E-mail Address') ||
         ! validateField(frm.phoneNumber, 'Phone'))
    {
        return false;
    }

	// Validate Qualification Questions
	 if ( ! validateField(frm.companyPrimaryBusiness, "Your company's Industry") ||
		  ! validateField(frm.companyMarketArea, "Your company's market area") ||
         ! validateField(frm.companyAnnualRevenue, "Your company's annual revenue") ||
         ! validateField(frm.natureOfInquiry, "Nature of inquiry") ||
		  ! validateField(frm.requestorRole, "Your role within your company") ||
         ! validateField(frm.referenceSource, "How did you hear about Ryder?") )
    {
        return false;
    }

	// Trim remarks field.
	trimField(frm.remarks);

	// Validate RFP description field value and size.
    if ( isEmpty(frm.remarks) )
    {
        alert("Please enter a brief description of the nature and scope of the RFP/RFI.");
        frm.remarks.focus();
        return false;
    }

    if ( ! limitTextAreaSize(frm.remarks, 600) )
    {
        return false;
    }

	// Validate RFP File Field
	if ( ! validateField(frm.rfpDoc, "RFP Document") )
	{
    	return false;
	}
   else
   {
       // Ensure document being uploaded is a Word Document, Excel Spreadsheet,
       // or PDF.
       var rfpDocName = frm.rfpDoc.value;
       var iDotPosition = rfpDocName.lastIndexOf(".");
       var strRFPFormatMsg = "Please provide RFP document in one of these formats:\n" +
       		"- Word Document (.doc)\n" +
            "- Excel Document (.xls)\n" +
            "- Power Point (.ppt)\n" +
            "- Portable Document Format (.pdf)\n";

       if ( iDotPosition == -1 )
       {
        	alert(strRFPFormatMsg);
        	return false;
       }
       else
       {
    		// Validate file extension
           var docExt = rfpDocName.substr(iDotPosition).toUpperCase();
           if ( docExt != ".DOC" && docExt != ".XLS" && docExt != ".PDF" && docExt != ".PPT")
           {
               alert(strRFPFormatMsg);
               return false;
           }

       }

   }

	// Set Success and Failure pages
    frm.forwardToSuccessPage.value = "http://" + document.domain + "/lms_contactus_rfp_rfpthx.shtml";
    frm.forwardToErrorPage.value = "http://" + document.domain + "/rfpformlms.jsp";

	//alert("successPage = " + frm.forwardToSuccessPage.value);
    //alert("errorPage = " + frm.forwardToErrorPage.value);

	// All validation has passed.  Call Coremetrics registration tag.
	cmCreateRegistrationTag(frm.emailAddress.value, frm.emailAddress.value, frm.city.value, frm.provinceState.value, frm.postalCode.value, frm.country.value, "SCS RFP");

	// Success
    return true;
}

/*******************************************************************************
* Validates that the feedback form has been populated with the required field
* values.
*******************************************************************************/
function validateTemplatedMailForm(frm, relPathSuccessPage, relPathFailurePage)
{
    // Make sure required fields have been populated.
    if ( ! validateField(frm.comments, 'Comments') )
    {
        return false;
    }

	// If response type is e-mail, request an e-mail address from the user.
	if ( frm.responseFormat.value == 'email' )
	{
		if ( isEmpty(frm.emailAddress) || isEmpty(frm.fullName) )
		{
			alert("You must provide your name and e-mail address\nif you want to receive a response via e-mail." +
				" If\nyou do not want to receive a response, please\nchange the 'Response Preference' value to\n'Do not respond to me'.");

			if ( isEmpty(frm.emailAddress) ) frm.emailAddress.focus();
			if ( isEmpty(frm.fullName) ) frm.fullName.focus();

			return false;
		}
	}

	// If response type is phone, request an phone number from the user.
	if ( frm.responseFormat.value == 'phone' )
	{
		if ( isEmpty(frm.phoneNumber) || isEmpty(frm.fullName) )
		{
			alert("You must provide your name and phone number\nif you want to receive a response via phone." +
				" If\nyou do not want to receive a response, please\nchange the 'Response Preference' value to\n'Do not respond to me'.");

			if ( isEmpty(frm.phoneNumber) ) frm.phoneNumber.focus();
			if ( isEmpty(frm.fullName) ) frm.fullName.focus();

			return false;
		}
	}

	// If the e-mail field is not empty, ensure that the e-mail address format is correct
	if ( !isEmpty(frm.emailAddress) && !isValidEmail(frm.emailAddress, "E-mail Address") )
	{
		return false;
	}

    // Set the success property to redirect user to feedback_thanks.shtml page
    frm.successPage.value = "http://" + document.domain + "/" + relPathSuccessPage;
    frm.failurePage.value = "http://" + document.domain + "/" + relPathFailurePage;

    // Success
    return true;
}

function goToRental()
{
	var radCountry = getSelected(document.submit.radCountry);
	var radType = getSelected(document.submit.radType);
	
	location.href='http://reservations.ryder.com/default.aspx?region=' + radCountry + '&customertype=' + radType;
}

function getSelected(obj)
{
	var val = "";
	for( i = 0; i < obj.length; i++ )
	{
		if( obj[i].checked == true )
		{
			val = obj[i].value;
			break;
		}
	}
	return val;
}

