
function validar() {

	document.experiencias.expNombre.value = trim(document.experiencias.expNombre.value)
	document.experiencias.expEmail.value = trim(document.experiencias.expEmail.value)
	document.experiencias.expComentario.value = trim(document.experiencias.expComentario.value)

	if (document.experiencias.expNombre.value == "") { alert("Por favor, ingresá tu nombre.") ; document.experiencias.expNombre.focus() ; return false; }
	if (valid_email(document.experiencias.expEmail.value) == false) { alert("La dirección de email no es válida.") ; document.experiencias.expEmail.focus() ; return false; }
	if (document.experiencias.expComentario.value == "") { alert("Por favor, ingresá tus comentarios.") ; document.experiencias.expComentario.focus() ; return false; }

	document.experiencias.submit();

}


// Quita espacios sobrantes
function trim(strTxt){
	var pos1 = 0;
	var pos2 = strTxt.length-1;
	var i;
    for (i=0; i<strTxt.length; i++){
		if (strTxt.charAt(i) == ' ') pos1 = pos1 + 1;
		else break;
	}
	if (pos1 != (pos2+1))
		for (i=strTxt.length-1; i>0; i--){
			if (strTxt.charAt(i) == ' ') pos2 = pos2 - 1
			else break;
		}
	return strTxt.substring(pos1,pos2+1);
}

// Validacion del campo email
function valid_email(s) {
    var strOk="@_-.ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" 
    var strValor=s.toUpperCase();
    var i=0;
    var arrobas=0;
    for (i=0; i<strValor.length;i++){
        if (strOk.indexOf(strValor.charAt(i))==-1){
            return false;
            break;
        }
        if (strValor.charAt(i)=="@"){
            if (i<1 || i==strValor.length-1){
                return false;
            }
            if (strValor.charAt(i-1)=="."){
                return false;
            }
            arrobas++;
        }
        if (strValor.charAt(i)=="."){
            if (i<1 || i==strValor.length-1){
                return false;
            }
            if (strValor.charAt(i-1)=="." ||
                strValor.charAt(i-1)=="@"){
                return false
            }
        }
    }
    if (arrobas != 1){
        return false;
    }
	return true;
}

