function confirmPassword(pass1, pass2) {
	if (pass1 == pass2) {
		return true;
	} else {
		alert("Your passwords do not match");
		return false;
	}
}


function uni_encode(not_encoded_string) {
	var encoded_string = "";

	for (var count = 0; count < not_encoded_string.length; count++) {
		if ((not_encoded_string.charCodeAt(count) < 48) || (not_encoded_string.charCodeAt(count) > 57)) {
			encoded_string += "zz" + not_encoded_string.charCodeAt(count) + "*";

			if (not_encoded_string.length-1 != count) {
				encoded_string += ",";
			}//if
		} else {
			encoded_string += not_encoded_string.charCodeAt(count);

			if (not_encoded_string.length-1 != count) {
				encoded_string += ",";
			}//if
		}//if
	}//while

	return encoded_string;
}//uni_encode


function passwordConfirm(password, passwordconfirm) {
	if (password != passwordconfirm) {
		alert("Your passwords do not match, please re-enter");
		return false;
	}
	return true;
}


function confirmF(msg) {
	if (confirm(msg)) 
		return true;

	return false;
}//confirmF


function isIE() {
//function returns true if is Internet Explorer
	if(navigator.userAgent.indexOf("MSIE") != -1) 
		return true;

	return false;
}


function isMac() {
	if(navigator.userAgent.indexOf("Mac") != -1) 
		return true;

	return false;
}


function keyHandler(e, type, otherCharacters, limit, field) {
//function uses keyHandlerLimit and keyHandlerTypes to restrict text input
//to either numbers or letters with optional limit on number of characters entered

	if (isIE()) {
		thisKey = window.event.keyCode;
	} else {
		thisKey = e.which;
	}

	if (thisKey >= 8 && thisKey <= 13) 
		return true;

	if (limit != "none") {
		if (keyHandlerLimit(limit, field)) 
			return keyHandlerTypes(e, type, otherCharacters);
	} else {
		return keyHandlerTypes(e, type, otherCharacters);
	}

	return false;
}//keyHandler


function keyHandlerLimit(limit, field) {
//function used by keyHandler to check to see if a limit has been exceeded,
//returns true if the limit has not been exceeded and false if it has

	if (field.length < limit) 
		return true;

	return false;
}


function keyHandlerTypes(e, type, otherCharacters){
//function used by keyHandler to check if the key pressed is of a certain type
//returns true if it is of that type and false if it isnt

	if (isIE()) {
		thisKey = window.event.keyCode;
	} else {
		thisKey = e.which;
	}

	if (otherCharacters != "none") {
		if (keyHandlerOtherCharacters(e, otherCharacters)) 
			return true;
	}

	if (type == "number") {
		if (thisKey >= 48 && thisKey <= 57) 
			return true;
	} else if (type == "letter") {
		if ((thisKey >= 65 && thisKey <= 90) || (thisKey >= 97 && thisKey <= 122)) 
			return true;
	} else if (type == "mixture") {
		if (thisKey >= 48 && thisKey <= 57) 
			return true;
		if ((thisKey >= 65 && thisKey <= 90) || (thisKey >= 97 && thisKey <= 122)) 
			return true;
	}

	return false;
}


function keyHandlerOtherCharacters(e, otherCharacters){
//function used by keyHandler to check if the key pressed is allowed based on a
//string of allowable characters passed to the function, returns true if key is found
//in string

	if (isIE()) {
		thisKey = window.event.keyCode;
	} else {
		thisKey = e.which;
	}

	var count = 0;

	for (var count = 0; count <= otherCharacters.length; count++) {
		if (thisKey == otherCharacters.charCodeAt(count)) 
			return true;
	}

	return false;
}


function verify(f){
// This is the function that performs form verification. It will be invoked
// from the onSubmit() event handler. The handler should return whatever
// value this function returns.

    var msg;
    var empty_fields = "";
    var errors = "";
    var count = 0;

    // Loop through the elements of the form, looking for all
    // text and textarea elements that don't have an "optional" property
    // defined. Then, check for fields that are empty and make a list of them.
    // Also, if any of these elements have a "min" or a "max" property defined,
    // then verify that they are numbers and that they are in the right range.
    // Put together error messages for fields that are wrong.

    for (var i = 0; i < f.length; i++) {

        var e = f.elements[i];

        if (((e.type == "text") || (e.type == "textarea") || (e.type == "file")) && !e.optional) {
            // first check if the field is empty

            if ((e.value == null) || (e.value == "") || isblank(e.value)) {
                empty_fields += "\n          " + e.name;
                continue;
            }

            // Now check for fields that are supposed to be numeric.

            if (e.numeric) {
				if (not_number(e.value)) {
					errors += "- The field " + e.name + " must be a number.\n";
					continue;
				}
            }
        } else  if (e.type == "select-one" && !e.optional && ((e.options[e.selectedIndex].value ==0) || (e.options[e.selectedIndex].value ==null))) {
			empty_fields += "\n          " + e.name;
			continue;
	  }
    }

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted.
    // Otherwise return true.

    if (!empty_fields && !errors) 
		return true;

    msg  = "______________________________________________________\n\n"
	msg += "The following fields require an entry:\n";
	msg += "______________________________________________________\n\n"

    if (empty_fields) {
		msg += empty_fields + "\n\n";
		alert(msg);
    }

	if (errors) {
		alert(errors);
	}

	return false;
} //end function verify()


function isblank(s){
// A utility function that returns true if a string contains only
// whitespace characters.

    for (var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) 
			return false;
    }

    return true;
} //end function isblank()


function getCookieData(labelName){

	var labelLen = labelName.length; // read cookie property only once for speed
	var cookieData = document.cookie;
	var cLen = cookieData.length;
	var i = 0;
	var cEnd;

	while ( i < cLen) {

		var j = i + labelLen;

		if (cookieData.substring(i, j) == labelName) {
			cEnd = cookieData.indexOf(";", j);
			if (cEnd ==- 1) {
				cEnd = cookieData. length;
			}
			return unescape(cookieData.substring(j + 1, cEnd));
		}
		i++;
	}

	return "";
}


function addNewSource(newSource, newID) {
			
	var newOption = document.createElement("OPTION");
	
	newOption.text = newSource;
	newOption.value = newID;
	newOption.selected = true;
	
	window.document.all.theSource.options.add(newOption);
	
	return true;
}
