/*
Template: login.js
Purpose:  Provides JavaScript required by login screen.
Author:   Gerry Stanford 
Date Written: April of 2008
*/

function validateEmailFormat(eml) {
	if (eml.indexOf("@") == -1 || eml.indexOf(".") == -1) return false;
	else return true;
}

function CF_onError(form_object, input_object, object_value, error_message) {
	alert(error_message);
	return false;   
}
	
function CF_hasValue(obj, obj_type)	{
	if (obj_type == "TEXT")	{
		if (obj.value.length == 0) return false;
		else return true;
	}
}
	
function  CF_checkForm(CF_this)	{
	
	// Check User Name 
	val = trim(CF_this.UserID.value);
	if (!val.length) { alert('Your user name is required'); return false; }
	else if (!validateEmailFormat(val)) {
		alert('The user name does not appear to be formatted correctly. Please try again.');
		return false;
	}
	// Check Password (presence) 
	if  (!CF_hasValue(CF_this.Password, "TEXT" )) {
		if  (!CF_onError(CF_this, CF_this.Password, CF_this.Password.value, "A password is required!"))	{
			return false;
		}
	}
	// Check Password (length) 
	else if (CF_this.Password.value.length < 6)	{
		alert("Passwords must be at least 6 characters long!")
		return false;
	}
	// Check Password (content) 
	else {
		var PassChar = 0
		var PassFlag = "True"
		
		for (var plh = 0; plh <= CF_this.Password.value.length - 1; plh++) {
			PassChar = CF_this.Password.value.charCodeAt(plh)
			if ((PassChar <= 47) || 
			    (PassChar >= 58 && PassChar <= 64) || 
			    (PassChar >= 91 && PassChar <= 96) || 
			    (PassChar >= 123)) {
				PassFlag = "False"
			}
		}
		if (PassFlag == "False") {
			alert("Password must be comprised of letters and numbers only!")
			return false;
		}			
	}
	return true;
}
