// <script language=javascript>
// Functions (c) 2002 Martin Danko (mdanko@mcdanko.com)
<!-- Begin

//-------------------------------------------------------------------
// Trim functions
//   Returns string with no whitespace
//-------------------------------------------------------------------
function noWhite(string) {
	var temp = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	temp += splitstring[i];
	return temp;
}


//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed on left and right
//-------------------------------------------------------------------
function LTrim(str) {
	for (var i=0; str.charAt(i)==" "; i++);
	return str.substring(i,str.length);
	}
function RTrim(str) {
	for (var i=str.length-1; str.charAt(i)==" "; i--);
	return str.substring(0,i+1);
	}
function Trim(str) {
	return LTrim(RTrim(str));
	}


//-------------------------------------------------------------------
// Validate if number is in range
//-------------------------------------------------------------------
function valNumRange(s, low, high, len) {
	// remove spaces on form element
	// s.value = noWhite(s.value);
	// loose reference to the form
	s = s.value;
	// Test to see if the value converts to a number
	if (parseInt(s) > -1)
	{
		// Validate length
		if ( s.length != len ) { return false; }
				
		// Validate range
		if ( s > low-1 && s < high+1 ) { 
			return true; 
		}
			
	}
	return false;
}


//-------------------------------------------------------------------
// testDate
// Returns true or false if date is valid
//-------------------------------------------------------------------
function testDate( theYear, theMonth, theDay, requireIt ) {
		var theYearValue, theMonthValue, theDayValue;
		var dteTest;
		
		// store the values for reference later
		theYearValue  = theYear.options[theYear.selectedIndex].value;
		theMonthValue = theMonth.options[theMonth.selectedIndex].value;
		theDayValue   = theDay.options[theDay.selectedIndex].value;
        				
		// was the month, year or day specified?
		if ( theYearValue  != "?" ||
			 theMonthValue != "?" ||
             theDayValue   != "?" || 
             requireIt == true ) 
        {
			theMonthValue = theMonthValue - 1;
			dteTest = new Date(theYearValue%100, theMonthValue, theDayValue );
			if ( dteTest.getYear()  != theYearValue%100 || 
				 dteTest.getMonth() != theMonthValue || 
				 dteTest.getDate()  != theDayValue )
			{
			     theMonth.focus();	// set focus here, error will be sent later
				return ( false );
			}
			
		}
		return ( true );
}


//-------------------------------------------------------------------
// isValidEmail
// Returns true or false if email is valid
//-------------------------------------------------------------------
function isValidEmail( str ) {
    var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
    var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
    if (!reg1.test(str) && reg2.test(str)) 
    { // if syntax is valid
      return true;
    }
    return false;
}


//-------------------------------------------------------------------
// onlyNameChars
// Returns true or false if string contains only valid characters for
// name fields. Chars allowed are [a-zA-Z\-\] using a regex.
//-------------------------------------------------------------------
function onlyNameChars( str ) {
    var reg1 = /[^a-zA-Z\-]/;		// match any thing not a-z A-Z or "-"
    if ( reg1.test( str ) ) 
    { 
      return false;	// if syntax has invalid chars
    }
    return true;	// no invalid chars
}


//-------------------------------------------------------------------
// onlyNameCharsOrSpace
// Returns true or false if string contains only valid characters for
// name fields including space. Chars allowed are [a-zA-Z\s\-\] 
// using a regex.
//-------------------------------------------------------------------
function onlyNameCharsOrSpace( str ) {
    var reg1 = /[^a-zA-Z\s\-]/;		// match any thing not a-z A-Z or "-"
    if ( reg1.test( str ) ) 
    { 
      return false;	// if syntax has invalid chars
    }
    return true;	// no invalid chars
}



//-------------------------------------------------------------------
// onlyNumeric
// Returns true or false if string contains only numeric characters
//-------------------------------------------------------------------
function onlyNumeric( str ) {
    var reg1 = /[^0-9]/;		// match any thing not 0-9
    if ( reg1.test( str ) ) 
    { 
      return false;	// if syntax has invalid chars
    }
    return true;	// no invalid chars
}



//-------------------------------------------------------------------
// replaceChars
// Returns true or false if string contains only valid characters for
// name fields. Chars allowed are [a-zA-Z\-\] using a regex.
//-------------------------------------------------------------------
function replaceChars( str, src, dst ) {
	temp = "" + str;
	
	while ( temp.indexOf( src ) >-1 ) {
	pos = temp.indexOf( src );
	temp = "" + (temp.substring(0, pos) + dst +
    temp.substring((pos + src.length), temp.length));
    }
    
	return temp;
}



//-------------------------------------------------------------------
// hasAllPhone ( part1, part2, part3 )
// Returns true if all elements of a phone number are intact.
// If only part is intact, returns false if not required. Also
// ensures all values are numeric.
//-------------------------------------------------------------------
function hasAllPhone( part1, part2, part3, isRequired ) {

	// Are any of the elements populated?
	if ( part1.value.length > 0 || part2.value.length > 0 || part3.value.length > 0 ) {
		
		// One or more is filled in, now make sure none are missing!
		// Are any of the elements missing?
		if ( part1.value.length < 3 || part2.value.length < 3 || part3.value.length < 4 ) {
			// one or more is missing, return false
			return false;
		}
		
		// Now make sure they are all numeric
		if ( !onlyNumeric( part1.value ) || !onlyNumeric( part2.value ) ||
		     !onlyNumeric( part3.value ) ) {
			alert ( "Error: One or more non-numeric characters found in phone number field." );
			return false;
		}
	
	} else if ( isRequired ) {
		
		// All elements were required but were not there, return false!
		return false;
	
	}
	
	return true;
}	
				
	
// </script>
// End -->