/******************************************************************************
 * This function is passed a form parameter.  It calls all the validation 
 * functions for each of the fields on the form. If all called
 * validation functions return true, this function will return true, otherwise
 * it will return false.
 *****************************************************************************/ 
function validate_zipcode(form) {
  
		// Call zip code functions
		if (form.weatherzip.value != "") {
			if (!(isZipCode(form.weatherzip, "Zip Code"))) return false;
		}
		
  }

/******************************************************************************
 * This function is passed a field and string parameter.  It checks the
 * Zip Code field for valid values.  If the zip code is valid, 
 * this function returns true, otherwise it returns false.
 *****************************************************************************/ 
function isZipCode(gField, msgString) {
		var inputStr = gField.value
		var text = "You did not fill in " + msgString + " correctly:"
			
	
	//check that the length of the string is twelve
	if (!(checkLength(inputStr, 5, 5))) {
		// there are not enough integers or too many to form a valid phone number
		alert(text + "\n\nYou need to enter 5 numbers.")
		gField.focus();
		gField.select();
		scrollBy(0,-50);
		return false
	}
	
	if (!(mask(inputStr, '#'))) {
		// there is a non-numeric character in one of the component values
		alert(text + "\n\nThere is an incorrect alpha character in this field. \nYou must enter 5 numbers.");
		gField.focus();
		gField.select();
		scrollBy(0,-50);
		return false
	}
	
		
	// everything is correct - return true	
	return true;
	
} // end of isZipCode()


/******************************************************************************
 * This function is passed a string and a masking value.  Based on the
 * masking value (alpha, numeric, or alpha-numeric), it calls the corresponding
 * function to evaluate whether the input string matches the input mask type.
 *****************************************************************************/
function mask (InString, MskChar)  {
		// If the string is supposed to be a decimal number
		// check that the decimal point is in the right place
		
		if (MskChar=='%') {
			if (!(InString.indexOf(".")==-1)) {
				// Find out where the decimal point is
				decStr = InString.substring(InString.indexOf("."), InString.length);
				if (decStr.length > 3) {
					alert("Decimal point was not correctly entered.");
					return false;
				}
			}
		}

		for (Count=0; Count<InString.length; Count++)  {
                StrChar = InString.substring(Count, Count+1);
				// Number
                if (MskChar=='#') {
						if (isNumberChar(StrChar) == false) {
								return false;
						}
					}
				// Decimal Number
				else if (MskChar=='%') {
						if(isDecNumberChar(StrChar) == false) {
                                return false;
						}
				}
					
				/* Let's comment the rest out because we only check for numerics
				else if (MskChar=='?') {
					    if(isAlphabeticChar(StrChar) == false) {
                                return false;
						}
				}
                else if (MskChar=='!') {
                        if(isNumOrChar(StrChar) == false) {
                                return false;
						}
				}
				else if (MskChar=='@') {
						if(isNotSpecial(StrChar) == false) {
								return false;
						}
				}
				
				*/
            
				else return false;
        }
        return true;
}

/******************************************************************************
 * This function is passed a string and iterates through each character
 * in the string to check whether or not it is an numeric character.
 * If each character is a number, this functions returns true, otherwise
 * it returns false.
 *****************************************************************************/ 
function isNumberChar (InString)  {
		if(InString.length!=1)
			return (false);
        RefString="1234567890";
        if (RefString.indexOf (InString, 0)==-1){
			return false;
		}
		else {
			return true;
		}
}

/******************************************************************************
 * This function is passed a string and iterates through each character
 * in the string to check whether or not it is a numeric character or decimal.
 * If each character is a number, this functions returns true, otherwise
 * it returns false.
 *****************************************************************************/ 
function isDecNumberChar (InString)  {
		if(InString.length!=1)
			return (false);
        RefString=".1234567890";
        if (RefString.indexOf (InString, 0)==-1){
			return false;
		}
		else {
			return true;
		}
}

/******************************************************************************
 * This function is passed a string, a MinLength and MaxLength. 
 * If the string length falls between the MinLength and MaxLength, this
 * returns true, otherwise it returns false.
 ******************************************************************************/ 
function checkLength(InString, MinLength, MaxLength) {
	if (InString.length >= MinLength && InString.length <= MaxLength) {
		return true;
	}
	else {
		return false;
	}
}

/******************************************************************************
 * This function is passed a string to be displayed in the message box to the  
 * user. If the user clicks OK to confirm the action, this function returns 
 * true, otherwise it returns false.
 ******************************************************************************/ 
function confirmAction(InString) {
	if (confirm(InString)) {
		return true;
	}
	else {
		return false;
	}
}