/*
 * Copyright 2009-2011 Okanagan Linux Solutions All Rights Reserved.
 * 
 * Permission is hereby granted, free of charge, to Allegretto Publishing Ltd., 
 * to deal in the Software without restriction, including without limitation 
 * the rights to use, copy, modify, merge, publish, distribute, sub-license,
 * and/or sell copies of the Software, subject to the following conditions:
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

function displayErrors(errors) {
	for (var i = 0; i < errors.length; i++) {		
		var error = errors[i];
		if (error.element) {			
			error.element.oldClassName = error.element.className;
			error.element.className = "error";			
		}
	}
}

function clearError(element) {
	if (element.oldClassName != null) {
		element.className = element.oldClassName;
	}
}

function validate() {
	var loginErrors = new Array();
	var error = new Error();
	
	error.element = document.getElementById("login");
	error.errors = new Array();
	if (error.element.value.length <= 0) {
		error.errors.push("Login Missing");
		loginErrors.push(error);
	}
		
	error = new Error();
	error.element = document.getElementById("password");
	error.errors = new Array();
//	var password = error.element.value;
	if (error.element.value.length <= 0) {
		error.errors.push("Password Missing");
		loginErrors.push(error);		
	}
	
	if (loginErrors != null && loginErrors.length <= 0) {
		return true;
	}
	
	else {
		displayErrors(loginErrors);
		return false;
	}
}
