<!--   hide this script from non-javascript-enabled browsers

// >>> Start Form-Field Feedback Indictor <<<
// test the browser to make sure it's ok
var browserName = navigator.appName;
var browserVer = parseInt(navigator.appVersion);
var browserOK = (((browserName == "Netscape") && (browserVer >= 3)) || 
	((browserName == "Microsoft Internet Explorer") && (browserVer >= 4)));

// the prefix to use for the status image names
var image_prefix = "img_";
var option_image_prefix = "imo_";
// the length of the data type designator
var dt_prefix_len = 3;
// flag indicating if a form can be validated
var okToValidate = true;

// set up the images
if (browserOK) {
	emptyImg = new Image();
	emptyImg.src = "img/spacer.gif";
	warnImg = new Image();
	warnImg.src = "img/warn.gif";
	reqImg = new Image();
	reqImg.src = "img/req.gif";
}


// walk through the images on a page and update each one based 
// on its associated form item
function initImgForm(formname) {
	var i;

	if (browserOK) {
		for (i = 0; i < document.images.length; i++) {
			// the image name is in a format 'img_dat_fieldname'
			// where 'img_' is the image_prefix value and 'dat' is the data type designator
			// the 'fieldname' is the name of the control the image is assocated with
			var cur_image = document.images[i].name;
			var cur_image_prefix = cur_image.substring(0, image_prefix.length);
			var fieldname_loc = image_prefix.length + dt_prefix_len + 1;
			var data_type = cur_image.substring(image_prefix.length, fieldname_loc - 1);
			
			if ((cur_image_prefix) && (cur_image_prefix == image_prefix)) {
				var this_ctrl_name = cur_image.substring(fieldname_loc);
				var this_ctrl = eval("document.forms." + formname + "." + this_ctrl_name);
				
				fieldImg(this_ctrl, data_type);
			}
		}
	}
}


// set the image associated with a form item
function fieldImg(ctrl, dtype) {
	if (browserOK) {
		var img = image_prefix + dtype + "_" + ctrl.name;
		
		if (ctrl.value != "" && ctrl.value != null) {
			if (showWarn(ctrl, dtype)) {
				// the field value is questionable, show warning
				document.images[img].src = warnImg.src;
			} else {
				// the field value is reasonably valid, so hide the image
				document.images[img].src = emptyImg.src;
			}
		} else if (ctrl.type.substring(0,6) == "select") {
			// this is a select object
			// if the image is a notreq image, then no action can be taken to the select control
			if (ctrl.selectedIndex != 0) {
				// an item has been selected from the select field, so hide the image
				document.images[img].src = emptyImg.src;
			} else {
				// the field is empty so display the required image
				document.images[img].src = reqImg.src;
			}
		} else {
			if (dtype.substring(0,1) == "n") {
				// this field is not required and empty, but should be validated
				document.images[img].src = emptyImg.src;
			} else {
				// the required field is empty so display the required image
				document.images[img].src = reqImg.src;
			}
		}
	}
}


// check a control to see if it's value is questionable
function showWarn(ctrl, data_type) {
	var warnStatus = false;

	// data_type defines the control/field's data type.
	// If the control has an image associated with it, the field is
	// required by default.  If the data type begins with an 'n' the field
	// is not required, but requires validation.
	// Any other data types passed that are not defined here are insignificant
	// and will not get a warning status.
	if (data_type == "int" || data_type == "nin") { // integer-numeric field
		warnStatus = (!(checkNum(ctrl.value)));
	}
	if (data_type == "dbl" || data_type == "ndb") { // double-float-currency field
		warnStatus = (!(checkFloat(ctrl.value)));
	}
	if (data_type == "eml" || data_type == "nem") { // E-mail field
		warnStatus = (!(checkEmail(ctrl.value)));
	}
	if (data_type == "pas" || data_type == "npa") { // password field
		warnStatus = (ctrl.value.length < 4);
	}
	if (data_type == "dat" || data_type == "nda") { // date field
		warnStatus = (!(checkDate(ctrl.value)));
	}
	if (data_type == "ssn" || data_type == "nss") { // SSN field
		warnStatus = (!(checkSSN(ctrl.value)));
	}
	if (data_type == "phn" || data_type == "nph") { // phone number field
		warnStatus = (!(checkPhone(ctrl.value)));
	}
	if (data_type == "str" || data_type == "nst") { // string field
		warnStatus = (!(checkString(ctrl.value)));
	}

	return warnStatus;
}


// walk through the images on a page and validate that there
// are no warning or required images.  if so, prevent form submit.
// images that have a prefix of option_image_prefix are form validated, but
// ignored for data type validation or initialization.
function validateForm(formname) {
	var i;
	
	if ((browserOK) && (okToValidate)) {
		for (i = 0; i < document.images.length; i++) {
			var cur_image = document.images[i].name;
			var cur_image_prefix = cur_image.substring(0, image_prefix.length);
			if ((cur_image_prefix) && ((cur_image_prefix == image_prefix) || (cur_image_prefix == option_image_prefix))) {
				var cur_image_src = document.images[i].src;
				if ((cur_image_src == reqImg.src) || (cur_image_src == warnImg.src)) {
					alert("Error submitting form:  one or more fields do not have valid data.");
					return false;
				}
			}
		}
	}
	if (document.frmOrderRequest.passwd)
	{
	if (document.frmOrderRequest.passwd.value != document.frmOrderRequest.cpasswd.value)
	{
		alert("Error submitting form:  Password confirmation does not match requested password.");
		return false;
	}
	if (document.frmOrderRequest.terms.value != 'Y')
	{
		alert("Error submitting form:  You must accept the terms before proceeding.");
		return false;
	}
	}
	
	// reset the form validation
	setFormValidation(true);
//	document.frmOrderRequest.submit();
	return true;
}

function validateForm2(formname) {
	var i;
	
	alert("Test");
	if ((browserOK) && (okToValidate)) {
		for (i = 0; i < document.images.length; i++) {
			var cur_image = document.images[i].name;
			var cur_image_prefix = cur_image.substring(0, image_prefix.length);
			if ((cur_image_prefix) && ((cur_image_prefix == image_prefix) || (cur_image_prefix == option_image_prefix))) {
				var cur_image_src = document.images[i].src;
				if ((cur_image_src == reqImg.src) || (cur_image_src == warnImg.src)) {
					alert("Error submitting form:  one or more fields do not have valid data.");
					return false;
				}
			}
		}
	}
	
	// reset the form validation
	setFormValidation(true);
//	document.frmOrderRequest.submit();
	return true;
}


// set the status of the form validation flag
function setFormValidation(isOK) {
	okToValidate = isOK;
}


// set a field as not required (set to a empty image, or back to a req image)
function setFieldNotRequired(img, isNotReq) {
	if (isNotReq) {
		document.images[img].src = emptyImg.src;
	} else {
		document.images[img].src = reqImg.src;
	}
}
// >>> End Form-Field Feedback Indictor



// >>> Start Field Validation Functions <<<
// check a string to make sure it's only numbers
function checkNum(checkText) {
	var i = 0;
	var len = checkText.length;
	var ch;

	// walk through a string and fail if
	// we find anything not between "0" and "9" 
	while (i < len) {
		ch = checkText.substring(i, i+1);
		if ((ch < "0") || (ch > "9")) {
			return false;
		}
		i++;
	}
	
	return true;
}


// check a string to make sure it's only numbers and float characters
function checkFloat(checkText) {
	var i = 0;
	var len = checkText.length;
	var ch;

	// walk through a string and fail if
	// we find anything not between "0" and "9" or ("." and "," and "-")
	while (i < len) {
		ch = checkText.substring(i, i+1);
		if ((ch < "0") || (ch > "9")) {
			if ((ch != ".") && (ch != ",") && (ch != "-")) {
				return false;
			}
		}
		i++;
	}
	
	return true;
}


// check a string to make sure it is a valid date format
function checkDate(checkText) {
	var pos;
	var i;
	var ch;
	var delimcnt = 0;
	var len = checkText.length;
	
	if (len < 8) return false;
	
	// check for '/' delimiters in the date
	pos = checkText.indexOf("/");
	while ( pos != -1 ) {
   		delimcnt++;
		if (delimcnt == 1) {
			// get the month
			var mo = checkText.substring(0, pos);
			var pos1 = pos + 1;
		} else if (delimcnt == 2) {
			// get the day
			var da = checkText.substring(pos1, pos);
			// get the year
			var yr = checkText.substring(pos + 1, checkText.length);
		}
   		pos = checkText.indexOf("/", pos+1);
	}
	
	if (delimcnt != 2) {
		return false;
	}
	
	// check the month for 1 or 2 numbers
	if ((mo.length < 1) || (mo.length > 2)) {
		return false;
	}
	i = 0;
	while (i < mo.length) {
		ch = mo.substring(i, i+1);
		if ((ch < "0") || (ch > "9")) {
			return false;
		}
		i++;
	}
	
	// check the day for 1 or 2 numbers
	if ((da.length < 1) || (da.length > 2)) {
		return false;
	}
	i = 0;
	while (i < da.length) {
		ch = da.substring(i, i+1);
		if ((ch < "0") || (ch > "9")) {
			return false;
		}
		i++;
	}
	
	// check the year for 4 numbers
	if (yr.length != 4) {
		return false;
	}
	i = 0;
	while (i < yr.length) {
		ch = yr.substring(i, i+1);
		if ((ch < "0") || (ch > "9")) {
			return false;
		}
		i++;
	}
	
	return true;
}


// check a string to make sure it is a valid SSN format
function checkSSN(checkText) {
	var i;
	var ch;
	var len = checkText.length;
	
	if (len < 11) return false;
	
	i = 0;
	while (i < len) {
		ch = checkText.substring(i, i+1);
		// check for the - delimiter
		if ((i == 3) || (i == 6)) {
			if (ch != "-") {
				return false;
			}
		} else if ((ch < "0") || (ch > "9")) {
			// check for all numbers
			return false;
		}
		i++;
	}
	
	return true;
}


// check a string to make sure it is a valid phone number format (with area code)
function checkPhone(checkText) {
	var i;
	var ch;
	var len = checkText.length;
	
	if (len < 12) return false;
	
	i = 0;
	while (i < len) {
		ch = checkText.substring(i, i+1);
		// check for the - delimiter
		if (i == 3 || i == 7) {
			if (ch != "-") {
				return false;
			}
		} else if ((ch < "0") || (ch > "9")) {
			// check for all numbers
			return false;
		}
		i++;
	}
	
	return true;
}


// check a string to make sure it is all alpha characters or ("-" and "'" and " ")
function checkString(checkText) {
	var ch;
	var len = checkText.length;
	
	for (i = 0; i < len; i++) {
    	ch = checkText.substring(i, i + 1).toLowerCase();
        if (!(((ch >= "a") && (ch <= "z")) || 
			(ch == "-") || (ch == "'") || (ch == " "))) {
        		return false;
        }
	}
	
	return true;
}


// check a string for a well-formed e-mail address
// in the format:  user@domain.com
function checkEmail(emailAddr) {
        var i;
		
        // check for @
        i = emailAddr.indexOf("@");
        if (i == -1) {
                return false;
        }
        
        // separate the user name and domain
        var username = emailAddr.substring(0, i);
        var domain = emailAddr.substring(i + 1, emailAddr.length)

        // look for spaces at the beginning of the username
        i = 0;
        while ((username.substring(i, i + 1) == " ") && (i < username.length)) {
                i++;
        }
        // remove any found
        if (i > 0) {
                username = username.substring(i, username.length);
        }

        // look for spaces at the end of the domain
        i = domain.length - 1;
        while ((domain.substring(i, i + 1) == " ") && (i >= 0)) {
                i--;
        }
        // remove any found
        if (i < (domain.length - 1)) {
                domain = domain.substring(0, i + 1);
        }

        // make sure neither the username nor domain is blank
        if ((username == "") || (domain == "")) {
                return false;
        }

        // check for bad characters in the username
        var ch;
        for (i = 0; i < username.length; i++) {
                ch = username.substring(i, i + 1).toLowerCase();
                if (!(((ch >= "a") && (ch <= "z")) || 
                        ((ch >= "0") && (ch <= "9")) ||
                        (ch == "_") || (ch == "-") || (ch == "."))) {
                                return false;
                }
        }

        // check for bad characters in the domain
        for (i = 0; i < domain.length; i++) {
                ch = domain.substring(i, i + 1).toLowerCase();
                if (!(((ch >= "a") && (ch <= "z")) || 
                        ((ch >= "0") && (ch <= "9")) ||
                        (ch == "_") || (ch == "-") || (ch == "."))) {
                                return false;
                }
        }

        var aSuffix = new Array("com","edu","org","gov","mil","ca","net","ws","tv","cc","au","us","uk","jp","de","ca","be","vu","il","ph","vg","dk","ms","nz","biz");
        var bFoundSuffix = false;
        i = 0;
        while (i < aSuffix.length) {
                if (("." + aSuffix[i]) == domain.substring(domain.length - aSuffix[i].length - 1, domain.length).toLowerCase()) {
                        return true;
                }
                i++;
        }
        // we would have exited if we'd found a good suffix, so return false
        return false;
}


// main calling function to validate an E-mail address
function emailOK(emailAddr) {
        if (!(checkEmail(emailAddr))) {
                alert("Please check the e-mail address you entered, it is not in the right format.");
        }
}
// >>> End Field Validation Functions

// stop hiding -->
