// <![CDATA[
$(function() {
    //Menu Superior
    $('li a').each(function(){
        var $page = location.toString();
        var arrayUrl= $page.split("/");
        var num=arrayUrl.length;
        var pagina=arrayUrl[num-1];
        var $href =  $(this).attr('href');
        if ( pagina==$href  ) {
            $(this).parent().addClass('current_page_item');
        } else {
            $(this).parent().removeClass('current_page_item');
        }
    });
    $("#tabs").tabs();

    //Acoredeon

    $(".accordion h2:first").addClass("active");
    $(".accordion div:not(:first)").hide();

    $(".accordion h2").click(function(){
        $(this).next("div").slideToggle("slow")
        .siblings("div:visible").slideUp("slow");
        $(this).toggleClass("active");
        $(this).siblings("h2").removeClass("active");
    });
 $("#content").load("ris/tablas.html");
    // radius Box
    $('.box_radius').css({
        "border-radius":"8px",
        "-moz-border-radius":"8px",
        "-webkit-border-radius":"8px"
    });
	
    // Slider script
    $('#slideshow').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 5000,
        pager:  '#slider_nav',
        pagerAnchorBuilder: function(idx, slide) {
            // return sel string for existing anchor
            return '#slider_nav li:eq(' + (idx) + ') a';
        }
    });

    $('#slideshow2').cycle({
        fx:     'fade',
        speed:  'slow',
        timeout: 4000
    // pager:  '#slider_nav',
    //   pagerAnchorBuilder: function(idx, slide) {
    // return sel string for existing anchor
    //  return '#slider_nav li:eq(' + (idx) + ') a';
    //}
    });
    //CARGADOR AJAX
    $('#cargando_imagen')
    .ajaxStart(function(){
        
        $(this).show();
    })
    .ajaxStop(function(){
        $(this).hide();
    });

    //AFRICA
    $('#oculto').hide();//Parrafo = 1 (Ocultar)
    $('.mas').click(function(){
        $('#oculto').fadeIn("slow");
        $(this).hide();
    })
    // contact form
    $('#contactform').submit(function(){
        var action = $(this).attr('action');
        if($('#acepto').attr('checked')){
            if($('#nombre').val()=='' || $('#email').val()==''|| $('#tema').val()==''|| $('#message').val()==''){
                alert("El formulario debe estar correctamente comlpetado");
                return false;
          
            }else{
                if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($('#email').val()))){
                    alert("Ingrese un Email Valido");
                    return false;
                }else{
                    $('#respuesta').load(action,{
                        name: $('#nombre').val(),
                        email: $('#email').val(),
                        subject: $('#tema').val(),
                        message: $('#message').val()
                    });
                    $('form')[0].reset()
                }
            }
        }else{
            alert("Debe aceptar la politica de pivacidad");
            $('#acepto').focus();
            return false;
        }
        return false;
    });
//Solucion ZINDEX IE7
    var zIndexNumber = 1000;
    $('div').each(function() {
            $(this).css('zIndex', zIndexNumber);
            zIndexNumber -= 10;
    });

});

function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

function handleNavLibIng(ini,idm){
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'libros',
        'idm':'ing'
    })
    return false;
}

function handleNavLibEsp(ini,idm){
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'libros',
        'idm':'esp'
    })
    return false;
}

function handleNavPerIng(ini,idm){
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'personal',
        'idm':'ing'
    })
    return false;
}

function handleNavPerEsp(ini,idm){
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'personal',
        'idm':'esp'
    })
    return false;
}

function handleNewsIng(ini,idm){
    $('div .right').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'noticias',
        'idm':'ing'
    })
    
    return false;
}

function handleNewsEsp(ini,idm){
    $('div .right').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'noticias',
        'idm':'esp'
    })
    
    return false;
}

function handleWNewsIng(ini,idm){
    $('div .right').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'worldNews',
        'idm':'ing'
    })

    return false;
}

function handleWNewsEsp(ini,idm){
    $('div .right').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'worldNews',
        'idm':'esp'
    })

    return false;
}

function handlePub(ini,idm){
    var year=$('#anoPub').text();
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'publicaciones',
        'idm': year
    })
    return false;
}

function loadCur(idm, tipo){
    $('div .right').load('funciones/getData.php',{
        'fstItem': tipo,
        'tabla':'masycur',
        'idm':idm
    })
  
}

function handleTesis(ini,idm){
    $('#cuerpo1').load('funciones/getData.php',{
        'fstItem':ini,
        'tabla':'tesis',
        'idm': 'idm'
    })
    return false;
}

function loadLink(idm, tipo){
    $('div .right').load('funciones/getData.php',{
        'fstItem': tipo,
        'tabla':'links',
        'idm':idm
    })

}

function decimal(e){
    var key //= (window.event) ? event.keyCode : e.which;
    if (window.event)
        key = event.keyCode
    else
        key = e.which
    if (!(key==8 )){
        if( key < 46 || key > 57){//si no es numero
            if (window.event) //IE
                window.event.returnValue = null;
            else //Firefox
                e.preventDefault();
        }else{
            return;
        }
    }else{
        return;
    }
};
function entero(e){
    var key //= (window.event) ? event.keyCode : e.which;
    if (window.event)
        key = event.keyCode
    else
        key = e.which
    if ( key > 47 && key < 58 || key == 8 )
        return; // if so, do nothing
    else // otherwise, discard character
    if (window.event) //IE
        window.event.returnValue = null;
    else //Firefox
        e.preventDefault();
};
//PROMETHEUS
Number.prototype.decimal = function (num) {
    pot = Math.pow(10,num);
    return parseInt(this * pot) / pot;
}

function calcPrometheus(){
    var il28 = $('#il28').val();
    var fib = $('#fib').val();
    var hcv = $('#hcv').val();
    var level = $('#level').val();
    var edad = $('#edad').val();
    var sex = $('#sex').val();
    var race = $('#race').val();
    var vih = $('#vih').val();
    //comprobaciones
    if (il28==""){
        alert("Fill all Fields");
        $('#il28').focus();
        return false;
    }
    if (fib==""){
        alert("Fill all Fields");
        $('#fib').focus();
        return false;
    }else if(fib < 3 || fib > 75){
        alert("Liver stiffness. Value off of Range (3-75)");
        $('#fib').select();
        $('#fib').focus();
        return false;
    }
    if (hcv==""){
        alert("Fill all Fields");
        $('#hcv').focus();
        return false;
    }
    if (level==""){
        alert("Fill all Fields");
        $('#level').focus();
        return false;
    }else if(level < 1 || level > 10){
        alert("HCV-RNA Value off of Range (1-10)");
        $('#level').select();
        $('#level').focus();
        return false;
    }
    if (edad==""){
        alert("Fill all Fields");
        $('#edad').focus();
        return false;
    }else if(edad < 18 || edad > 75){
        alert("Age Value off of Range (18-75)");
        $('#edad').select();
        $('#edad').focus();
        return false;
    }
    if (sex==""){
        alert("Fill all Fields");
        $('sex').focus();
        return false;
    }
    if (race==""){
        alert("Fill all Fields");
        $('race').focus();
        return false;
    }
    if (vih==""){
        alert("Fill all Fields");
        $('vih').focus();
        return false;
    }
    var calculo=-(13.94 + (-1.549 * hcv)+(-1.682 * level)+(-0.084 * fib)+(-1.772*il28));
    var log= Math.exp(calculo);
    var percent=(1/(1+log))*100
    $('#resultado').html("Probability of SVR: " + percent.decimal(2) + " %") ;
    j=document.forms[0].il28.selectedIndex;
    $('#il28Text').val(document.forms[0].il28[j].text);
    $('#prometheus').val(percent.decimal(2));
    var params = $('#prometeo').serialize();
    $.post("funciones/loadPrometheus.php", params);
}

// ]]>
