/*********** FORM VERIFICATION ******************/


var hstyle = {};
hstyle.E_COLOR = 'red';
hstyle.V_COLOR = 'white';

// text input (only) validator
//
hstyle.validateForm = function(formid) { 

	var form = document.getElementById(formid);
	
	var formState = true;
	for (var i = 0; i < form.elements.length; i++) { 
		var e = form.elements[i];
	        hstyle.setValid(e);
		
		// required anything
		if (hstyle.hasClass(e.className, 'required')) {
			if (!e.value) { 
				formState = false; 
				hstyle.setErrorInput(e, 'This field is required');
			}
		}
		// required email
		if (hstyle.hasClass(e.className, 'requiredEmail')) {
			var emailR = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
			if (e.value.search (emailR) == -1) { 
				formState = false; 
				hstyle.setErrorInput(e, 'A valid email is required');
			}
		}
	}
	return formState;
};

hstyle.setErrorInput = function(input, message) {
	input.style.background=hstyle.E_COLOR;
	input.title=message;
};

hstyle.setValid = function(input) { 
        input.style.background=hstyle.V_COLOR;
};

// element has class
//
hstyle.hasClass = function(isClass, hasClass) { 
	var pieces = isClass.split(" ");
	for (var i = 0; i < pieces.length; i++) { 
		if (pieces[i]==hasClass)
			return true;
	}
	return false;
};

