/* Last Modified: 10/27/99 9:30am - mft */

/* ============================================================= */

//Purpose: Check if a string is a valid zipcode (5 or 9 digit)
//Input: robjZip: field where the zipcode was entered
//Output: false if not a valid zipcode, true if it is a valid zipcode

function isValidZip(robjZip) {
	var strZip = robjZip.value;
	var blnZip = true;

	if (strZip.length == 5) {
		if (!(isInteger(robjZip.value))) {
			blnZip = false;
		}
	} else if (strZip.length == 9) {
		if (!(isInteger(robjZip.value))) {
			blnZip = false;
		} else {
			robjZip.value = strZip.substring(0,5) + "-" + strZip.substring(5,9);
		}
	} else if (strZip.length == 10) {
		if ((isInteger(strZip.substring(0,5))) && (strZip.substring(5,6) == "-") && (isInteger(strZip.substring(6,10)))) {
			robjZip.value = strZip.substring(0,5) + "-" + strZip.substring(6,10);
		} else {
			blnZip = false;
		}
	} else {
		blnZip = false;
	}

	if (blnZip == false) {
		alert('Please enter a valid zip code.\nIf you enter a 9 digit zip code please use a \'-\' before the last 4 digits.');
		robjZip.focus();
	}
	return blnZip;
}

/* ============================================================= */

//Purpose: Check if a string is a valid zipcode (5 digit)
//Input: robjZip: field where the zipcode was entered
//Output: false if not a valid zipcode, true if it is a valid zipcode

function isValidZip5(robjZip) {
	var strZip = robjZip.value;
	var blnZip = true;

	if (strZip.length == 5) {
		if (!(isInteger(robjZip.value))) {
			blnZip = false;
		}
	} else {
		blnZip = false;
	}

	if (blnZip == false) {
		alert('Please enter a valid 5-digit zip code.');
		robjZip.focus();
	}
	return blnZip;
}

/* ============================================================= */

//Purpose: Check if a string is a valid zipcode (4 digit)
//Input: robjZip: field where the zipcode was entered
//Output: false if not a valid zipcode, true if it is a valid zipcode

function isValidZip4(robjZip) {
	var strZip = robjZip.value;
	var blnZip = true;

	if (strZip.length == 4) {
		if (!(isInteger(robjZip.value))) {
			blnZip = false;
		}
	} else {
		blnZip = false;
	}

	if (blnZip == false) {
		alert('Please enter a valid 4-digit postal code.');
		robjZip.focus();
	}
	return blnZip;
}

/* ============================================================= */

