// JavaScript Document
function validarForm(formulario){
	var tamano=formulario.elements.length;
	for (i=0;i<tamano;i++){
		var nombre_campo=formulario.elements[i].name;
		var tipo_campo=formulario.elements[i].type;
		var valor=formulario.elements[i].value;
		var titulo_campo=formulario.elements[i].title;
		if((tipo_campo!="hidden")&&(titulo_campo!="opcional")){
			if((tipo_campo=="text")||(tipo_campo=="textarea")||(tipo_campo=="password")){
				if((valor=="")||(valor==titulo_campo)){
					var mensaje="&nbsp;Please enter your "+titulo_campo;
					var contenedor_error="error";
					document.getElementById(nombre_campo).style.borderStyle="solid";
					document.getElementById(nombre_campo).style.borderColor="#900";
					document.getElementById(nombre_campo).style.borderWidth="3px";
					document.getElementById(contenedor_error).innerHTML=mensaje;
					document.getElementById(contenedor_error).style.display="inline";
					document.getElementById(contenedor_error).style.textAlign="center";
					/*alert("Por favor, ingrese un valor para el campo '"+titulo_campo+"'");*/
					document.getElementById(nombre_campo).focus();
					return false;
				}
				else{
					reset_campo(nombre_campo);					
				}
				if(titulo_campo=="Email"){
					validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
					strEmail = document.getElementById("email").value;
					if (strEmail.search(validRegExp) == -1) {
						var mensaje="&nbsp;Please enter a valid Email address";
						var contenedor_error="error";
						document.getElementById(nombre_campo).style.borderStyle="solid";
						document.getElementById(nombre_campo).style.borderColor="#900";
						document.getElementById(nombre_campo).style.borderWidth="3px";
						document.getElementById(contenedor_error).innerHTML=mensaje;
						document.getElementById(contenedor_error).style.display="inline";
						//alert('Por favor, ingrese una dirección de Email válida');
						document.getElementById("email").focus();
						return false;
					}
					else{
						reset_campo(nombre_campo);
					}
				}
			}
		}
	}
	formulario.submit();
	
}
function reset_campo(id){
	var mensaje="";
	var contenedor_error="error";
	document.getElementById(id).style.border="none";
	document.getElementById(contenedor_error).innerHTML=mensaje;
	document.getElementById(contenedor_error).style.display="none";
}
function reset_all(formulario){
	var tamano=formulario.elements.length;
	for (i=0;i<tamano;i++){
		var nombre_campo=formulario.elements[i].name;
		var tipo_campo=formulario.elements[i].type;
		var valor=formulario.elements[i].value;
		var titulo_campo=formulario.elements[i].title;
		if((tipo_campo!="hidden")&&(titulo_campo!="opcional")&&(tipo_campo!="submit")&&(tipo_campo!="reset")){
			var mensaje="";
			var contenedor_error="error_"+nombre_campo;
			document.getElementById(nombre_campo).style.border="none";
			document.getElementById(contenedor_error).innerHTML=mensaje;
			document.getElementById(contenedor_error).style.display="none";
		}
	}
}
