// brief	return object for multiple browser support
// author 	olov@olovsundstrom.com, Kråmagnom 2006
// version	1
function getObj(id) {
	if (document.getElementById) {					// FF
		return document.getElementById(id);
	}
	else if (document.all) {						// IE
		return document.all[id];
	}
}

// brief	validate a form
// author 	olov@olovsundstrom.com, Kråmagnom 2006
// version 	1
function validateForm() {
	
	var settings = new validationSettings();
	var valid = true;
	var errmess = "";
		
	// Password
	if (settings.password1 && settings.password2) {
		
		xObj1 = getObj(settings.password1);
		xObj2 = getObj(settings.password2);
		
		if ((xObj1.value == "" && settings.password_notnull) || (xObj1.value != xObj2.value)) {
			if (settings.password_color) {
				xObj1.style.backgroundColor = settings.password_color;
				xObj2.style.backgroundColor = settings.password_color;
			}
			if (settings.password_mess) errmess += "\n -" + settings.password_mess;
			valid = false;
		} else {
			xObj1.style.backgroundColor = settings.returncolor;
			xObj2.style.backgroundColor = settings.returncolor;
		}
	}
	// Email
	if (settings.email) {
		xObj = getObj(settings.email);
		if ((xObj.value == "") || (xObj.value.indexOf("@") == -1)) {
			if (settings.email_color) xObj.style.backgroundColor = settings.email_color;
			if (settings.email_mess) errmess += "\n -" + settings.email_mess;
			valid = false;
		} else {
			xObj.style.backgroundColor = settings.returncolor;
		}
		
	}
	// Notnull
	notnull = false;
	for (i=0; i<settings.notnull.length; i++) {
		xObj = getObj(settings.notnull[i]);
			if (xObj.value == "") {
				notnull = true;
				if (settings.notnull_color) xObj.style.backgroundColor = settings.notnull_color;
				valid = false;
			} else {
				xObj.style.backgroundColor = settings.returncolor;
			}
	}
	if (notnull && settings.notnull_mess) errmess += "\n -" + settings.notnull_mess;

	if (errmess.length > 0) {
		errmess = settings.mess_head + "\n" + errmess + "\n\n" + settings.mess_foot;
		alert(errmess);
	}
	
	return valid;
}

