<!--

//
// Basic class for form validation
//

function FormValidator(formID)
{
	this.element = document.getElementById(formID);
	this.rules   = {};
	this.equalClauses = {};
}

FormValidator.prototype.addRule = function(elName, func)
{
	this.rules[elName] = func;
}

FormValidator.prototype.removeRule = function(elName)
{
	this.rules[elName] = null;
}

FormValidator.prototype.elementsEqual = function(el1, el2)
{
	return (this.element.elements[el1].value == this.element.elements[el2].value);
}

FormValidator.prototype.addEqualClause = function(el1, el2)
{
	this.equalClauses[el1] = el2;
}

FormValidator.prototype.validate = function()
{
	var valid = true;
	
	// Rules
	for (var ix in this.rules) {
		var el = this.element.elements[ix];
		if (this.rules[ix](el) == false) {
			el.style.border = '2px solid #cc0000';
			valid = false;
		}
		else {
			el.style.border = '';
		}
	}
	
	// Equal Clauses (retype x, etc.)
	for (var ix in this.equalClauses) {
		var el2 = this.element.elements[this.equalClauses[ix]];
		if (!this.elementsEqual(ix, this.equalClauses[ix])) {
			el2.style.border = '2px solid #cc0000';
			valid = false;
		}
		else {
			el2.style.border = '';
		}
	}
	
	if (!valid) {
		alert('There were errors in your submission. Please review all red-outlined entries.');
	}
	return valid;
}

//
// Misc form validation functions
//

function fvNotEmpty(el)
{
	return (el.value.length > 0);
}

// 
// Other functions
//

function registerPopup()
{
	window.open('register.php?do=join', 'RegJoin', 'width=400,height=400,resizable=yes,scrollbars=yes');
	return false;
}

function profilePopup()
{
	window.open('register.php?do=profile', 'RegProfile', 'width=400,height=400,resizable=yes,scrollbars=yes');
	return false;
}

function forgotPopup()
{
	window.open('register.php?do=forgotpass', 'RegForgot', 'width=400,height=400,resizable=yes,scrollbars=yes');
	return false;
}

-->
