//=================
function RTrim(str)
//=================
// Name         : RTrim
// Description  : Remove trailing blanks from our string.
// Call         : RTrim(string)
// Parameters   : str - the string we want to RTrim
// Returns      : A RTrimmed string
// Author       : http://www.4guysfromrolla.com/webtech/code/RTrim.shtml
// Created      : 07/18/2000
// Copyright    : 2000, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{
    // We don't want to trip JUST spaces, but also tabs,
    // line feeds, etc.  Add anything else you want to
    // "trim" here in Whitespace
    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
        // We have a string with trailing blank(s)...

        var i = s.length - 1;       // Get length of string

        // Iterate from the far right of string until we
        // don't have any more whitespace...
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            i--;


        // Get the substring from the front of the string to
        // where the last non-whitespace character is...
        s = s.substring(0, i+1);
    }

    return s;
}

//=================
function LTrim(str)
//=================
// Name         : LTrim
// Description  : Remove leading blanks from our string.
// Call         : LTrim(string)
// Parameters   : str - the string we want to LTrim
// Returns      : A LTrimmed string
// Author       : http://www.4guysfromrolla.com/webtech/code/LTrim.shtml
// Created      : 07/18/2000
// Copyright    : 2000, Catholic Healthcare West
// Notes        :
// Updates      :
// **************
 {
    var whitespace = new String(" \t\n\r");

    var s = new String(str);

    if (whitespace.indexOf(s.charAt(0)) != -1) {
        // We have a string with leading blank(s)...

        var j=0, i = s.length;

        // Iterate from the far left of string until we
        // don't have any more whitespace...
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            j++;


        // Get the substring from the first non-whitespace
        // character to the end of the string...
        s = s.substring(j, i);
    }

    return s;
 }

//================
function Trim(str)
//================
// Name         : Trim
// Description  : Remove leading and trailing blanks from our string.
// Call         : Trim(string)
// Parameters   : str - the string we want to Trim
// Returns      : A LTrimmed string
// Author       : http://www.4guysfromrolla.com/webtech/code/Trim.shtml
// Created      : 07/18/2000
// Copyright    : 2000, Catholic Healthcare West
// Notes        :
// Updates      :
// **************
{
	return RTrim(LTrim(str));
}


//================
function btnMapClick() 
//================
// Name         : btnMapClick() 
// Description  : reuqired Field validation.
// Call         : btnMapClick()
// Parameters   : None
// Returns      : Error messages r submit
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{	
if (ValidateFields()) {
	document.facilitylocatordirections.submit();																		
	}
}



function ValidateFields()
{	
	
if (ValidateStreet()) {
	if (ValidateZip()) {
		
										
			return true;
	
	}	
	
}	
}


function ValidateStreet() 
{
	if (Trim(document.facilitylocatordirections.ADDR_ORIGIN.value)!==""){
		return true;	
	}
	else {
		alert("Street address is a required field");
	document.facilitylocatordirections.ADDR_ORIGIN.focus();
	return false;
	}
}



function ValidateZip() 
{

	if (Trim(document.facilitylocatordirections.ZO.value)!==""){
		return true;
		
	}
	else {
		alert("Zip is a required field");
		document.facilitylocatordirections.ZO.focus();
		return false;
	}
}


function ValidateState() 
{

if (document.facilitylocatordirections.STATE_ORIGIN[document.facilitylocatordirections.STATE_ORIGIN.selectedIndex].value != 0)
{ 
return true;
}

else {
	 alert("State is a required field");
	 document.facilitylocatordirections.STATE_ORIGIN.focus();
	return false;
}

}

//================
function popup(image,width,height) 
//================
// Name         : function popup(image,width,height) 
// Description  : pop up the campus map
// Call         : popup(string,string,string)
// Parameters   : image, width of image, height of image
// Returns      : Error messages r submit
// Author       : Jeremy Malone
// Created      : 02/20/2004
// Copyright    : 2004, Catholic Healthcare West
// Notes        :
// Updates      :
// **************

{ 
window.open(image,'popup','width='+width+',height='+height+',menubar=1,resizable=1,status=1,scrollbars=1,toolbar=1');
} 