function updateSelectField(select_form, current_field) {
	var field_found = 0;
	
	for (x = 0; x <= select_form.length; x++) {
		if (select_form.options[x].value == current_field) {
		field_found = x;
		break;
		}
	}
	select_form.options.selectedIndex = field_found;
}

function validate_activity_selection(theform) {
	
	var age = theform.age_group.options[theform.age_group.options.selectedIndex].value;
	var subject = theform.subject_specific.options[theform.subject_specific.options.selectedIndex].value;
	
	if (age == "") {
		alert("Por favor, seleccione un grupo de edad");
		theform.age_group.focus();
		return false;
	}
	else if (subject == "") {
		alert("Por favor, seleccione un tema");
		theform.subject_specific.focus();
		return false;
	}
	else return true;

}

function validateComment(theform) {

var comment = theform.comment.value;

//g = perform a global match
//cleaning empty space and emoticons code
var comment_cleaned = comment.replace(/\s+/g, '');
var real_comment_length = comment_cleaned.length;

if (comment == "") {
	alert("Please insert your comment");
	theform.comment.focus();
	return false;
}
else if ((real_comment_length < 15) || (comment.length < 15)) {
	alert("Su comentario tiene " + real_comment_length + " caracteres, y el mínimo corresponde a 15.\nPor favor, amplíe su comentario.");
	theform.comment.focus();
	return false;
}
else if (comment == comment.toUpperCase()) { //avoiding all upper case posts

	alert("Por favor, no ponga todo en mayúscula; esto se considera gritar.");
	theform.comment.focus();
	return false;	
}

return true;
}

function add_starter(theform) {
	
if (theform.starters.value) { 
	if (theform.comment.value == "") theform.comment.value = theform.starters.value;
	else theform.comment.value = theform.comment.value + "\n\n" + theform.starters.value;
	theform.comment.focus();
}

}


function validate_registration(theform) {
	
	var username = theform.username.value;
	var emailaddress = theform.emailaddress.value;
	var password = theform.password.value;
	var password2 = theform.password2.value;
	var timezone = theform.timezone.options[theform.timezone.options.selectedIndex].value;
	var terms=theform.terms;
	
	if ((username == "" ) || (username.length > 30 )) {
		alert("Su nombre de usuario está vacío o sobrepasa el máximo de 30 caracteres");
		theform.username.focus();
		return false;
	} 
	else if ((emailaddress == "") || (emailaddress.length > 100 )) {
		alert("Su dirección de correo electrónico está vacía o sobrepasa el máximo de 100 caracteres");
		theform.emailaddress.focus();
		return false;
	}
	
	else if ((password == "") || (password.length > 20 )) {
		alert("Su contraseña está vacía o sobrepasa el máximo de 20 caracteres");
		theform.password.focus();
		return false;
	} 
	
	else if (password != password2) {
		alert("La confirmación de su contraseña no corresponde a su primera contraseña");
		theform.password2.focus();
		return false;
	}
	
	else if (timezone == "") {
		alert("Por favor, seleccione su zona horaria");
		theform.timezone.focus();
		return false;
	}
	
	else if (terms.checked == false) {
		alert("Debe leer y aceptar nuestros términos y condiciones antes de firmar");
		theform.terms.focus();
		return false;
	}
	
	else return true;
	
}

function toggleDisplay(divID) {
	if (divID.style.display == "none") divID.style.display = "block";
	else divID.style.display = "none";
}
