<!--
	var szStreet = new Array(  )
	var szCity = new Array(  )
	var szState = new Array(  )
	var szZip = new Array(  )
	var szPlace = new Array(  )
	var dLat = new Array(  )
	var dLong = new Array(  )
	var dAlt = new Array(  )
	var EID = new Array(  )
	var szGEC = new Array(  )
	var Prop = new Array(  )

// Constants
var MAX_STOPS							=	5

// Error message for having empty tabs
var IDS_EMPTY_ADDRESS_TAB				=	"Please enter information into at least one field and then click Go.";
var IDS_EMPTY_START_ADDRESS_TAB		=	"Please enter information about the location you're starting from, and then click Go.";
var IDS_EMPTY_END_ADDRESS_TAB			=	"Please enter information about the location where your drive ends, and then click Go.";
var IDS_EMPTY_PLACE_TAB					=	"Please ensure that you've entered the name of a place, and then click Go.";
var IDS_EMPTY_START_PLACE_TAB			=	"Please enter the name of the place you're starting from, and then click Go.";
var IDS_EMPTY_END_PLACE_TAB				=	"Please enter the name of the place where your drive ends, and then click Go.";

// Invalid characters for each field
var IDS_WILDCARD							=	"?*";
var IDS_ADDRESS_INVALID					=	"*?%!$,=:\\|";
var IDS_CITY_INVALID						=	"*?%&,!$=+:\\|";
var IDS_ZIP_INVALID						=	"%?*`~!@#$%^&*()_-+={}[]|\\\'\":;/<>,.";
var IDS_PLACE_INVALID					=	"*?%=:\\|";

// Error message for containing invalid characters
var IDS_ERROR_ADDRESS_INVALID			=	"Please enter a street address that does not contain any of these invalid characters: " + IDS_ADDRESS_INVALID + ", and then click Go.";
var IDS_ERROR_CITY_INVALID				=	"Please enter a city name that does not contain any of these invalid characters: " + IDS_CITY_INVALID + ", and then click Go.";
var IDS_ERROR_ZIP_INVALID				=	"Please enter a Postal Code that does not contain any of these invalid characters: " + IDS_ZIP_INVALID + ", and then click Go.";
var IDS_ERROR_PLACE_INVALID				=	"Please enter a place name that does not contain any of these invalid characters: " + IDS_PLACE_INVALID + ", and then click Go.";
var IDS_ERROR_ADDRESS_WILD_INVALID		=	"Please enter a street address that does not begin with ? or *.";
var IDS_ERROR_CITY_WILD_INVALID		=	"Please enter a city that does not begin with ? or *.";
var IDS_ERROR_PLACE_WILD_INVALID		=	"Please enter a place name that does not begin with ? or *.";


// Other misc rules error messages
var IDS_ERROR_MIN_ADDRESS_LENGTH		=	"Please enter a street address consisting of at least two valid characters, and then click Go.";
var IDS_ERROR_MIN_ADDRESS_COMMA_LENGTH=	"Please enter a street address consisting of at least two valid characters on each side of the comma, and then click Go.";
var IDS_ERROR_MIN_CITY_LENGTH			=	"Please enter a city name consisting of at least two valid characters, and then click Go.";
var IDS_ERROR_MIN_PLACE_LENGTH			=	"Please enter a place consisting of at least two valid characters, and then click Go.";
var IDS_ERROR_MIN_PLACE_COMMA_LENGTH	=	"Please enter a place name consisting of at least two valid characters on each side of the comma, and then click Go.";
var IDS_ERROR_US_ZIP_INVALID			=	"Please enter all five digits of the Postal Code or leave the Postal Code box empty, and then click Go.";
var IDS_ERROR_ADJACENT_STOPS			=	"Driving directions cannot be calculated for adjacent stops that are the same."

var szEmpty = "T";

// szAddressTab contains the value of the current findermodule's tab argument
// returns true if we are currently on the address tab
function AddressTab( szAddressTab )
{
	if ( szAddressTab == "1" ) 
	{
		return true;
	}
	return false;
}

// szSearchString - String to search through
// szInvalids - String of characters to search for
// returns true if any of the characters in szInvalids are in szSearchString
function ContainsInvalid( szSearchString, szInvalids )
{
	var iIndex, szChar;
	
	szSearchString = "" + szSearchString;
	for ( iIndex = 0; iIndex < szInvalids.length; iIndex++ )
	{
		szChar = szInvalids.substring( iIndex, ( iIndex + 1 ) );
		if( szSearchString.indexOf( szChar ) >= 0 )
		{
			return true;
		}
	}
	return false;	
}



// Checks the validity of the address contained in szAddress
function CheckAddress( szAddress )
{
	var iIndex, szError;
	
	szAddress = "" + szAddress;
	if( szAddress.length > 0 )
	{
		szAddress = Trim( szAddress );
		if ( szAddress.length > 0 )
		{
			// confirm the data is legal
			if( ContainsInvalid( szAddress, IDS_ADDRESS_INVALID ) )
			{
				return IDS_ERROR_ADDRESS_INVALID;
			}
			// must have at least 2 characters in the address length
			if ( szAddress.length < 2 )
			{
				return IDS_ERROR_MIN_ADDRESS_LENGTH;
			}

			// confirm the first two characters aren't wildcards
			if( ContainsInvalid( szAddress.substring( 0, 2 ), IDS_WILDCARD ) )
			{
				return IDS_ERROR_ADDRESS_WILD_INVALID;
			}

			// must have at least 2 characters on either side of a comma
			// can do this by recursively calling CheckAddress with each side of a comma
			iIndex = szAddress.indexOf( "," );
			if( iIndex >= 0 )
			{
				// Check before the comma
				szError = CheckAddress( szAddress.substring( 0, iIndex ) );
				if( ( szError.length > 1 ) || ( szError == szEmpty ) )
				{
					return IDS_ERROR_MIN_ADDRESS_COMMA_LENGTH;
				}
				szError = CheckAddress( szAddress.substring( ( iIndex + 1 ), szAddress.length ) );
				if( ( szError.length > 1 ) || ( szError == szEmpty ) )
				{
					return IDS_ERROR_MIN_ADDRESS_COMMA_LENGTH;
				}
				return szError;
			}
			return "F";
		}
	}
	return szEmpty;
}

// Checks the validity of the city contained in szCity
function CheckCity( szCity )
{
	szCity = "" + szCity;
	if( szCity.length > 0 )
	{
		szCity = Trim( szCity );
		if ( szCity.length > 0 )
		{
			// confirm the data is legal
			if( ContainsInvalid( szCity, IDS_CITY_INVALID ) )
			{
				return IDS_ERROR_CITY_INVALID;
			}
			// must have at least 2 characters in the city length
			if ( szCity.length < 2 )
			{
				return IDS_ERROR_MIN_CITY_LENGTH;
			}
			// confirm the first two characters aren't wildcards
			if( ContainsInvalid( szCity.substring( 0, 2 ), IDS_WILDCARD ) )
			{
				return IDS_ERROR_CITY_WILD_INVALID;
			}
			
			return "F";
		}
	}
	return szEmpty;
}

// Checks the validity of the state contained in szState
function CheckState( szState )
{
	szState = "" + szState;
	if( ( szState.length > 0 ) && ( szState != "null" ) )
	{
		szState = Trim( szState );
		if ( szState.length > 0 )
		{
			// confirm the data is legal
			// if there was anything to confirm...
			return "F";
		}
	}
	return szEmpty;
}

// Checks the validity of the state for the unusual behavior for NS4 & IE3
function CheckStateNS( iState )
{
	if( iState != 0 )
	{
		return "F";
	}
	return szEmpty;
}


// Checks the validity of the zip/postal code contained in szZip
function CheckZip( szZip )
{
	if( szZip.length > 0 )
	{
		szZip = Trim( szZip );
		if ( szZip.length > 0 )
		{
			// confirm the data is legal
			if( ContainsInvalid( szZip, IDS_ZIP_INVALID ) )
			{
				return IDS_ERROR_ZIP_INVALID;
			}
			if( CheckUSZip( szZip ) )
			{
				return IDS_ERROR_US_ZIP_INVALID;
			}
			return "F";
		}
	}
	return szEmpty;
}

// Checks the validity of the place contained in szPlace
function CheckPlace( szPlace )
{
	szPlace = "" + szPlace;
	var iIndex, szError;
	
	if( szPlace.length > 0 )
	{
		szPlace = Trim( szPlace );
		if ( szPlace.length > 0 )
		{
			// confirm the data is legal
			if( ContainsInvalid( szPlace, IDS_PLACE_INVALID ) )
			{
				return IDS_ERROR_PLACE_INVALID;
			}

			// must have at least 2 characters in the place length
			if ( szPlace.length < 2 )
			{
				return IDS_ERROR_MIN_PLACE_LENGTH;
			}
			
			// confirm the first two characters aren't wildcards
			if( ContainsInvalid( szPlace.substring( 0, 2 ), IDS_WILDCARD ) )
			{
				return IDS_ERROR_PLACE_WILD_INVALID;
			}
			
			// must have at least 2 characters on either side of a comma
			// can do this by recursively calling CheckPlace with each side of a comma
			iIndex = szPlace.indexOf( "," );
			if( iIndex >= 0 )
			{
				// Check before the comma
				szError = CheckPlace( szPlace.substring( 0, iIndex ) );
				if( ( szError.length > 1 ) || ( szError == szEmpty ) )
				{
					return IDS_ERROR_MIN_PLACE_COMMA_LENGTH;
				}
				szError = CheckPlace( szPlace.substring( ( iIndex + 1 ), szPlace.length ) );
				if( ( szError.length > 1 ) || ( szError == szEmpty ) )
				{
					return IDS_ERROR_MIN_PLACE_COMMA_LENGTH;
				}
				return szError;
			}
			return "F";
		}
	}
	return szEmpty;
}

function IsDigit( ch )
{
	return( ( ch >= '0' ) && ( ch <= '9' ) );
}

function IsLetter( ch )
{
	return( ( ( ch >= 'a' ) && ( ch <= 'z' ) ) || ( ( ch >= 'A' ) && ( ch <= 'Z' ) ) );
}

// tells if it's a legal US Zip code
// in this case consists of 5 digits only
function CheckUSZip( szZip )
{
	szZip = "" + szZip;
	var fBadZip = ( szZip.length != 5 );
	if( !fBadZip )
	{
		for( var i = 0; i < szZip.length; ++i )
		{
			if( !IsDigit( szZip.charAt( i ) ) )
			{
				fBadZip = true;
			}
		}
	}
	return fBadZip;
}

	

// removes blank space on both ends of the string sz
function Trim( sz )
{
	sz = "" + sz;
	iStart = 0;
	iEnd = sz.length - 1;
	fDone = false;
	while( ( iStart < iEnd ) && !fDone )
	{
		fDone = true;
		if( sz.charAt( iStart ) == ' ' )
		{
			iStart++;
			fDone = false;
		}
		if( sz.charAt( iEnd ) == ' ' )
		{
			iEnd--;
			fDone = false;
		}
	}
	if( ( ( iStart == iEnd ) && ( sz.charAt( iStart ) == ' ' ) ) ||
			( iStart > iEnd ) )
	{
		return "";
	}
	return sz.substring( iStart, iEnd + 1 );
}


function GetElement( oForm, szName, iIndex )
{
	with( oForm )
	{
		var oRet = elements[ szName ][ iIndex ];
		if( oRet != null )
		{
			return oRet;
		}
		for( var i = 0; i < elements.length; ++i )
		{
			if( elements[ i ].name == szName )
			{
				if( iIndex-- <= 0 )
				{
					break;
				}
			}
		}
		if( i < elements.length )
		{
			return elements[ i ];
		}
	}
	return null;
}

function SubmitForm( oForm )
{
	var iVersion = parseInt( navigator.appVersion );
	var fIE = ( navigator.userAgent.indexOf( "MSIE" ) != -1 );
	if( !fIE || ( iVersion >= 4 ) )
	{
		oForm.submit();
		return;
	}
	with( oForm )
	{
		var szURL = "", szValue = "";
		for( var i = 0; i < elements.length; ++i )
		{
			if( elements[ i ].checked == false )
			{
				continue;
			}
			if( szURL.length > 0 )
			{
				szURL += "&";
			}
			szValue = "";
			if( elements[ i ].selectedIndex != null )
			{
				szValue = elements[ i ].options[ elements[ i ].selectedIndex ].value;
			}
			else
			{
				szValue = elements[ i ].value;
			}
			szURL += elements[ i ].name + "=" + escape( szValue );
		}
		szURL = action + "?" + szURL;
		open( szURL, target );
	}
}

var fEmpty = true;

function CheckFields()
{
	var szError, iIndex, iTabCount, fIsEmpty = true;
	var theElement;
	
	iIndex = 0;
	iTabCount = 0;
	with( document.Form )
	{
		for( var i = 0; i < elements.length; ++i )
		{
			if( elements[ i ].name == "street" )
			{
				iTabCount += 1;
			}
		}
	}

	while ( iIndex < iTabCount )
	{
		theElement = GetElement( this.document.Form, "fm", iIndex );
		if( theElement.value != "-1" )
		{
			theElement = GetElement( this.document.Form, "tab", iIndex );
			if( AddressTab( theElement.value ) )
			{
				// Check address field
				theElement = GetElement( this.document.Form, "street", iIndex );
				szError = CheckAddress( theElement.value );
	
				if( szError.length > 1 )
				{
					alert( szError );
					return false;
				}
				else
				{
					if( szError == "F" )
					{
						fIsEmpty = false;
					}
				}
				
				// check city field
				theElement = GetElement( this.document.Form, "city", iIndex );
				szError = CheckCity( theElement.value );

				if( szError.length > 1 )
				{
					alert( szError );
					return false;
				}
				else
				{
					if( szError == "F" )
					{
						fIsEmpty = false;
					}
				}

				// check state field
				theElement = GetElement( this.document.Form, "state", iIndex );
				szError = CheckStateNS( theElement.selectedIndex );
				if( szError.length > 1 )
				{
					alert( szError );
					return false;
				}
				else
				{
					if( szError == "F" )
					{
						fIsEmpty = false;
					}
				}

				// check zipcode field
				theElement = GetElement( this.document.Form, "zip", iIndex );
				szError = CheckZip( theElement.value );
				if( szError.length > 1 )
				{
					alert( szError );
					return false;
				}
				else
				{
					if( szError == "F" )
					{
						fIsEmpty = false;
					}
				}
				
				if( fIsEmpty )
				{
					if( iIndex == 0 )
					{
						alert( IDS_EMPTY_START_ADDRESS_TAB );
					}
					else if( iIndex == ( iTabCount - 1 ) )
					{
						alert( IDS_EMPTY_END_ADDRESS_TAB );
					}
					else
					{
						alert( IDS_EMPTY_ADDRESS_TAB );
					}
					return false;
				}
				fIsEmpty = true;
			}
			else		// Currently only AddressTab and PlaceTab available.
			{
				theElement = GetElement( this.document.Form, "place", iIndex );
				szError = CheckPlace( theElement.value );
				
				if( szError.length > 1 )
				{
					alert( szError );
					return false;
				}
				else
				{
					if( szError == "F" )
					{
						fIsEmpty = false;
					}
				}
				if( fIsEmpty )
				{
					if( iIndex == 0 )
					{
						alert( IDS_EMPTY_START_PLACE_TAB );
					}
					else if( iIndex == ( iTabCount - 1 ) )
					{
						alert( IDS_EMPTY_END_PLACE_TAB );
					}
					else
					{
						alert( IDS_EMPTY_PLACE_TAB );
					}
					return false;
				}
				fIsEmpty = true;
			}
		}
		iIndex++;
	}	// end while
	return true;
}


			function updateModule( p_iModule, p_iUpdate )
			{
				with( document.Form )
				{
					// fm[ p_iModule ].value = p_iUpdate
					var theElement = GetElement( document.Form, "fm", p_iModule );
					theElement.value = p_iUpdate;
					ff.value = 0;
					submit();
				}
			}

			function changeOrder( p_iDir, p_iIndex )
			{
				with( document.Form )
				{
					var theElement
					if( p_iDir > 0 )
					{
						// ord[ p_iIndex - 1 ].value = p_iIndex
						theElement = GetElement( document.Form, "ord", p_iIndex - 1 );
						theElement.value = p_iIndex;
					}
					else
					{
						// ord[ p_iIndex - 1 ].value = -p_iIndex
						theElement = GetElement( document.Form, "ord", p_iIndex - 1 );
						theElement.value = -p_iIndex;
					}
					ff.value = 0;
					submit();
				}
			}

			function onFormSubmit()
			{
				with( document.Form )
				{
					var theElement;

					theElement = GetElement( document.Form, "tab", 0 );
					theElement.value = "1" + "";

					theElement = GetElement( document.Form, "tab", 1 );
					theElement.value = "1" + "";
					ff.value = 1;
				}
				return CheckFields();
			}


	function switchTab( p_iIndex, p_szTab )
	{
		with( document.Form )
		{
			var iIndex = p_iIndex;
			if( ( iIndex == 1 ) &&
				( 2 != 2 ) &&
				( 0 == 0 ) &&
				( 0 == 0 ) )
			{
				iIndex += 1;
			}
			if( iIndex > 0 )
			{
				iIndex = iIndex - 0;
			}

			// tab[ iIndex ].value = p_szTab
			var theElement = GetElement( document.Form, "tab", iIndex );
			theElement.value = p_szTab;
			ff.value = 0;
			submit();
		}
	}

	function Clear( p_iIndex, p_iTab )
	{
		with( document.Form )
		{
			var iIndex = p_iIndex;
			if( ( p_iIndex == 1 ) &&
				( 2 != 2 ) &&
				( 0 == 0 ) &&
				( 0 == 0 ) )
			{
				iIndex += 1;
			}
			if( iIndex > 0 )
			{
				iIndex -= 0;
			}
			if( p_iTab == 1 )
			{
				var theElement;
				// street[ iIndex ].value = ""
				theElement = GetElement( document.Form, "street", iIndex );
				theElement.value = "";
				// city[ iIndex ].value = ""
				theElement = GetElement( document.Form, "city", iIndex );
				theElement.value = "";
				// state[ iIndex ].selectedIndex = 0
				theElement = GetElement( document.Form, "state", iIndex );
				theElement.selectedIndex = 0;
				// zip[ iIndex ].value = ""
				theElement = GetElement( document.Form, "zip", iIndex );
				theElement.value = "";
			}
			else
			{
				// place[ iIndex ].value = ""
				var theElement = GetElement( document.Form, "place", iIndex );
				theElement.value = "";
			}
		}
	}

	function listPlaceSelect( p_iType, p_iIndex )
	{
		var iIndexSelect = p_iIndex;
		if( iIndexSelect >= 2 )
		{
			iIndexSelect -= 2;
		}
		with( document.Form )
		{
			// var idx = Select[ iIndexSelect ].selectedIndex
			var theElement = GetElement( this.document.Form, "Select", iIndexSelect );
			var idx = theElement.selectedIndex;
			if( p_iType == 1 )
			{
				// street[ p_iIndex ].value = szStreet[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "street", p_iIndex );
				theElement.value = szStreet[ iIndexSelect ][ idx ];

				// city[ p_iIndex ].value = szCity[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "city", p_iIndex );
				theElement.value = szCity[ iIndexSelect ][ idx ];

				// state[ p_iIndex ].value = szState[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "state", p_iIndex );
				theElement.value = szState[ iIndexSelect ][ idx ];

				// zip[ p_iIndex ].value = szZip[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "zip", p_iIndex );
				theElement.value = szZip[ iIndexSelect ][ idx ];
			}
			else
			{
				// place[ p_iIndex ].value = szPlace[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "place", p_iIndex );
				theElement.value = szPlace[ iIndexSelect ][ idx ];

				// E[ iIndexSelect ].value = EID[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "E", iIndexSelect );
				theElement.value = EID[ iIndexSelect ][ idx ];

				// GEC[ iIndexSelect ].value = szGEC[ iIndexSelect ][ idx ]
				theElement = GetElement( this.document.Form, "GEC", iIndexSelect );
				theElement.value = szGEC[ iIndexSelect ][ idx ];
			}
			theElement = GetElement( this.document.Form, "Lat", iIndexSelect );
			theElement.value = dLat[ iIndexSelect ][ idx ];
			theElement = GetElement( this.document.Form, "Long", iIndexSelect );
			theElement.value = dLong[ iIndexSelect ][ idx ];
		}
	}

//-->
