// JavaScript de SOMNIKA

/* FUNCIONES VALIDACIÓN FORMULARIOS */

var whitespace = " \t\n\r";
var reWhitespace = /^\s+$/

/** Verifica que no este vacio **/
function isEmpty(s){
	return ((s == null) || (s.length == 0)) 
}
 
/*** Verifica que no sean espacios en blanco o vacio ***/
function isWhitespace (s){
    return (isEmpty(s) || reWhitespace.test(s));
}
 
/*** corta espacios en blanco al principio y al final de una variable ***/
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	};
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

/*** Valida un email mediante expresiones regulares ***/
function validarEmail(valor) {
        if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
                return false;
        } else {
                return true;
        }
}
function isEmail(s){
	return (isWhitespace(s) || validarEmail(s));
}

/*** Validación del formulario de Cursos ***/
function validarContacto(form,lan){
	var ok = true;
	// nombre
	if(isWhitespace(form.nombre.value)){
		ok=false;
		form.nombre.style.backgroundColor='#e8f7ff';
	}else{ form.nombre.style.backgroundColor=''; }
	
	// email
	if(isEmail(form.email.value)){
		ok=false;
		form.email.style.backgroundColor='#e8f7ff';
	}else{ form.email.style.backgroundColor=''; }
	
	if(isWhitespace(form.consulta.value)){
		ok=false;
		form.consulta.style.backgroundColor='#e8f7ff';
	}else{ form.consulta.style.backgroundColor=''; }
	
	// mensaje
	if(isWhitespace(form.mensaje.value)){
		ok=false;
		form.mensaje.style.backgroundColor='#e8f7ff';
	}else{ form.mensaje.style.backgroundColor=''; }

	if(ok==false){
			if(lan=="es"){alert("Completa correctamente los campos indicados en azul.");}
			if(lan=="en"){alert("Fill out correctly fields in blue.");}
		return false;
	}else{
		form.submit();
	}
}

