/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function retornoError(id,opcion)
{
    var ctrl = document.getElementById(id);
    ctrl.style.color='#ff0000';
    switch (opcion) {
        case "requerido":            
            ctrl.innerHTML="&nbsp;Dato obligatorio";
            break;
        case "numerico":
            ctrl.innerHTML="&nbsp;Error : El dato no es un numero";
            break;
        case "mayor":
            ctrl.innerHTML="&nbsp;Error : Litros cargados exceden litros pedidos";
            break;
        default:
            ctrl.innerHTML="";
            break;
    }
}

function validacionDato (id,validar)
{
    var ctrl = document.getElementById(id);
    var claserror = '1px solid red';
    var normal = '1px solid #8181F7';
    var retorno;
    switch (validar) {
        case "vacia":
            if (ctrl.value.length==0)
                {                   
                    ctrl.style.border=claserror;
                    ctrl.focus();
                    this.retornoError(id+'e', 'requerido')
                    retorno=false;
                }
                else{                   
                   ctrl.style.border=normal;
                   this.retornoError(id+'e', '')
                   retorno=true;
                }
            break;
        case "numerico":
            if(isNaN(ctrl.value)){
                ctrl.className=cajaerror;
                ctrl.focus();
                this.retornoError(id+'e', 'numerico')
                retorno=false;
            }
            else{
                ctrl.className=cajanormal;
                this.retornoError(id+'e', '')
                retorno=true;
            }
            break;

            case "nronovacia":
                if (ctrl.value.length==0)
                {
                    ctrl.className=cajaerror;
                    ctrl.focus();
                    this.retornoError(id+'e', 'requerido')
                    retorno=false;
                }
                else if (isNaN(ctrl.value))
                {
                    ctrl.className=cajaerror;
                    ctrl.focus();
                    this.retornoError(id+'e', 'numerico')
                    retorno=false;
                }
                else {
                   ctrl.className=cajanormal;
                   this.retornoError(id+'e', '')
                   retorno=true;
                }
            break;

        default:
            break;
    }
    return retorno;
}

function comparaValores(valor1,valor2,compara)
{
    var v1=document.getElementById(valor1);
    var v2=document.getElementById(valor2);
    switch (compara.value) {
        case "menor":
            if(v1.value<v2.value)
                {

                }
                else {

                }
            break;
        default:
            break;
    }

}

function rtrim(s) {
	return s.replace(/\s+$/,"");
}
function juntar(s)
{
    return s.replace(/ /g, '');
}

function retornaNumeros(n)
{
   return n.replace(/[^0-9|.|-]/g, '');
}


function campoNumerico(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;
    patron = /\d/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}


function alfaNumerico(e) {
    tecla = (document.all)?e.keyCode:e.which;
    if (tecla==8) return true;    
    patron=/\w/;
    te = String.fromCharCode(tecla);
    return patron.test(te);
}

function acceptNum(evt){
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57, '.' = 46
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}



String.prototype.reverse=function(){return this.split('').reverse().join('');};
function numberblog(e)
{
    function f()
    {
        this.value=this.value.reverse().replace(/[^0-9.]/g,'').replace(/\.(?=\d*[.]\d*)/g,'').reverse();
    }
    e.onkeyup=f
    e.onkeydown=f
    e.onkeypress=f
    e.onmousedown=f
    e.onmouseup=f
    e.onclick=f
    e.onchange=f
    e.onblur=f
}


var nav4 = window.Event ? true : false;
function IsNumber(evt){
// Backspace = 8, Enter = 13, ‘0′ = 48, ‘9′ = 57, ‘.’ = 46
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key >= 48 && key <= 57) || key == 46);
}

function obligatariofn(id)
{
   var ctrl = document.getElementById(id);  
       if(ctrl.value.length==0)
       {
           ctrl.style.borderBottom='1px dotted #FF0000';
           ctrl.focus();
           this.retornoError('retornoerror', 'requerido');
           return false;
       }
       else {
         ctrl.style.borderBottom='1px dotted #6E6E6E';
         this.retornoError('retornoerror', '')
         return true;
       }
}

function validarMail(email) {
	var retorno=true;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email)) retorno=false;
	return retorno;
}


function aj(){
    var strNombre = document.getElementById('nombre').value.trim();
    var strApellido = document.getElementById('apellido').value.trim();
    var strTelefono = document.getElementById('telefono').value.trim();
    var strEmail = document.getElementById('email').value.trim();
    var strPais = document.getElementById('pais').value.trim();
    var strUsuario = document.getElementById('usuario').value.trim();
    var strClave1 = document.getElementById('clave1').value.trim();
    var strClave2 = document.getElementById('clave2').value.trim();
 
    var campoVacio=( 
                    ( ( strNombre.length > 1 )      * 1   ) + 
                    ( ( strApellido.length > 1 )       * 2   ) +
                    ( ( strTelefono.length > 1 )       * 4   ) +
                    ( ( strEmail.length > 1 ) * 8   ) +
                    ( ( strPais > 0 )       * 16  ) +
                    ( ( strUsuario.length > 1 ) * 32  ) +
                    ( ( strClave1.length > 1 )    * 64  ) +
                    ( ( strClave2.length > 1 )  * 128 ) +
                    ( ( strClave1 == strClave2 ) * 256 ) 
                    );

    if(campoVacio!=511) { 
        if(campoVacio==255){ 
            alert('La contraseña no coincide con la verificación');
        } else {
            alert('Debe completar todos los campos para continuar.');
        }
    } else {
        if(validarMail(strEmail)){
            var params = "no=" + strNombre + 
                        "&ap=" + strApellido + 
                        "&te=" + strTelefono +
                        "&em=" + strEmail +
                        "&pa=" + strPais +
                        "&us=" + strUsuario +
                        "&c1=" + strClave1 +
                        "&c2=" + strClave2;
            var answer = confirm ("¿Está seguro de que la información es correcta?")
            if (answer)
            cargaPaginaPost('index.php?controlador=jueces&accion=aj',params,'carga');
            else
            return;
        } else {
            alert('La dirección de correo electrónico no es válida');
        }
    }
}

function fj(ij){
    if(ij>0)cargaPaginaPost('index.php?controlador=jueces&accion=fichaJuez','ij='+ij,'carga');
}

function ccj(ij){
    var strClave1 = document.getElementById('clave1').value.trim();
    var strClave2 = document.getElementById('clave2').value.trim();
    var campoVacio=( 
                    ( ( strClave1.length > 1 )    * 1  ) +
                    ( ( strClave2.length > 1 )  * 2 ) +
                    ( ( strClave1 == strClave2 ) * 4 ) 
                    );
    if(campoVacio!=7) { 
        if(campoVacio==3){ 
            alert('La contraseña no coincide con la verificación');
        } else {
            alert('Debe completar todos los campos para continuar.');
        }
    } else {
        params="c1="+strClave1+"&c2="+strClave2+"&ij="+ij;
        var answer = confirm ("¿Está seguro que desea cambiar la contraseña?")
        if (answer)
            cargaPaginaPost('index.php?controlador=jueces&accion=ccj',params,'carga');
        else
        return; 
    }
}

function dc(d){
    var a=document.getElementById('anio').value;
    if((a > 2009) && (a < 2030)) {
        params="a="+a;
        cargaPaginaPost('index.php?controlador=conf&accion='+d,params,'carga');
    } else {
        alert('El año debe ser un número igual o mayor a 2010');
    }
}

