
// funciones front

/* 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 Contacto ***/
function validarContacto(form, msg){
	var ok = true;
	// empresa
	if(isWhitespace(form.empresa.value)){ ok=false; form.empresa.style.backgroundColor='#FFCCCC'; }else{ form.empresa.style.backgroundColor=''; }
	// nombre
	if(isWhitespace(form.nombre.value)){ ok=false; form.nombre.style.backgroundColor='#FFCCCC'; }else{ form.nombre.style.backgroundColor=''; }
	// email
	if(isEmail(form.email.value)){ ok=false; form.email.style.backgroundColor='#FFCCCC'; }else{ form.email.style.backgroundColor=''; }
	// mensaje
	if(isWhitespace(form.mensage.value)){ ok=false; form.mensage.style.backgroundColor='#FFCCCC'; }else{ form.mensage.style.backgroundColor=''; }

	if(ok==false){
		alert(msg);
		return false;
	}else{
		form.submit();
	}
}

/* muestra el email por pantall saltándose muchos SPAMbots */
function showEmail(usuario, dominio, extension){
	var direccion = usuario+'@'+dominio+'.'+extension;
	var html = '<a href="mailto:'+direccion+'" target="_blank">'+direccion+'</a>';
	document.write(html);
}
