function confirmar(msg,url){
    if (confirm('¿ '+msg+' ?')){
        document.location = url;
    }
}

function mensaje(msg) {
	alert(msg);
}

// 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);
}


function vacio(dato,msg){
	var valor = trim(eval("document."+dato+".value"));
	if (valor==""){
		alert("El dato " + msg + " es obligatorio. Por favor escriba un valor.");
		eval("document."+dato+".focus();");
		return true;
	}
	return false;
}

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;
}

function verificar() {
	if(vacio('formulario.nombre','Nombre de Contacto') == true)
	{ return; }
	
	if(vacio('formulario.telefono','Teléfono fijo') == true)
	{ return; }
	
else
	if(valid_email(document.formulario.email.value)==true)
		{
		document.formulario.submit();
		}
	else
		{
		alert("El E-mail ingresado no es valido. Por favor escríbalo nuevamente.");
		eval("document.formulario.email.focus();");
		return;
		}
}
