var mypets = null;
var mypets1 = null;
var msj = "© 2009 ***** Universidad Ricardo Palma *****\n         Developed by the Oficic ";
document.onkeydown = function(){
    /*if(window.event && window.event.keyCode == 112) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 113) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 114) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 115) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 116) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 117) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 118) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 119) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 120) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 121) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 122) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 123) {
        window.event.keyCode = 505;
    }
    if(window.event && window.event.keyCode == 505) {
        alert(msj);
        return false;
    }*/

    }
function maximize(){
    window.moveTo(0,0);
    if (document.all) {
        top.window.resizeTo(screen.availWidth,screen.availHeight);
    }else if (document.layers||document.getElementById) {
        if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
            top.window.outerHeight = screen.availHeight;
            top.window.outerWidth = screen.availWidth;
        }
    }
    document.oncontextmenu=inhabilitar ;
    // document.onselectstart = inhabilitar;
    document.ondragstart = inhabilitar ;
}

function inhabilitar(){
    return false ;
}
function MM_swapImgRestore() {
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() {
    var d=document; if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
            }
    }
}
function MM_findObj(n, d) {
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() {
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
        }
}

function keyhandler(e) {
    if (document.layers)
        Key = e.which;
    else
        Key = window.event.keyCode;

    if (Key != 0)
        alert("Key pressed! ASCII-value: " + Key);
}

function handlePress(e) {
    var AshiftPressed = (window.Event) ? e.modifiers & Event.SHIFT_MASK : e.shiftKey;
    var ctrlPressed = (window.Event) ? e.modifiers & Event.CONTROL_MASK : e.ctrlKey;
    var altPressed = (window.Event) ? e.modifiers & Event.ALT_MASK : e.altKey;
    if (shiftPressed) {
        alert("La tecla Shift esta deshabilitada en estas página");
        e.cancelBubble = true;
        return false;
    }
    if (ctrlPressed) {
        alert("La tecla Control esta deshabilitada en estas página");
        e.cancelBubble = true;
        return false;
    }
    if (altPressed) {
        alert("La tecla Alt esta deshabilitada en estas página");
        e.cancelBubble = true;
        return false;
    }
    else return true;
}

function noLeftClick(evt){
    evt = (evt)?evt:(window.event)?window.event:"";
    if (evt) {
        var elem = (evt.target)?evt.target:evt.srcElement;
        if (evt.button==2) {
            alert(msj);
            return false;
        }
        if (evt.button==3) {
            alert(msj);
            return false;
        }
    }
}

function fechahora(){
    var today = new Date();
    document.write(today.getFullYear());
}

function set(){
    if(document.getElementById("usuario").value.length<=0){
        alert("Debe ingresar un usuario");
        return false;
    }else{
        if (document.getElementById("clave").value.length<=0){
            alert("Debe ingresar su contraseña");
            return false;
        }else{
            var strURL = "http://test.urp.edu.pe/Intranet/IdentificarUsuarioServlet";
            //strURL += "?usuario="+document.getElementById("usuario").value+"&clave="+document.getElementById("clave").value;
            /* window.open(strURL,"mywindow","menubar=0,resizable=0,scrollbars=1,maximizable=0");
                  document.form1.action=strURL;
                document.form1.submit();*/
            var p="?usuario="+document.form1.usuario.value+"&clave="+document.form1.clave.value;
            window.open(strURL+p,'window','top=0,left=0,width=800,height=600,resizable=yes,scrollbars=yes,menubar=no,location=no');
           CerrarVentana('divintranet');

        }
    }
}

function usuarioEnter(myfield,e){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13)
    {
        if(myfield.value!=""){
            document.getElementById("clave").focus();
        }
        return false;
    }
    else return true;
}

function onSubmitForm(form){
    if(document.getElementById("usuario").value.length<=0  || document.getElementById("clave").value.length<=0){
        alert("Falta llenar un campo ");
        return false;
    }else{
        CerrarVentana('divintranet');
        form.setAttribute("action", "http://test.urp.edu.pe/Intranet/IdentificarUsuarioServlet");
        window.open('',form.target,'top=0,left=0,width=800,height=600,menubar=no,location=no,resizable=yes,scrollbars=yes');
        return true;
    }
}

function CargarIntranet(){
    bloquear();
    document.getElementById("divintranet").innerHTML="";
    new Ajax.Request('paginasinternas/intranet/login_i.html',{
        method: 'get',
        onSuccess:function(t){
            var div= document.getElementById("divintranet");
            div.innerHTML= t.responseText;
            div.style.visibility= "visible";
        }
    });
}

function CerrarVentana(ventana){
    document.getElementById(ventana).style.display="none";
    var el = document.getElementById("divBloqueo");
    var padre = el.parentNode;
    padre.removeChild(el);

}

function submitenteri(myfield,event){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (event) keycode = event.which;
    else return true;
    if (keycode == 13){
        if(document.getElementById("usuario").value.length<=0){
            alert("Debe Ingresar su Usuario");
            return;
        }
        if(myfield.value.length>0){
            set();
            return false;
        }
        else{
            alert("Debe ingresar su Contraseña");
        }
    }
    else return true;
}

function submitenterav(myfield,event){
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (event) keycode = event.which;
    else return true;
    if (keycode == 13){
        if(document.getElementById("username").value.length<=0){
            alert("Debe Ingresar su Usuario");
            return;
        }
        if(myfield.value.length>0){
            setav();
            return false;
        }
        else{
            alert("Debe ingresar su Contraseña");
        }
    }
    else return true;
}

function setav(){
    if(document.getElementById("username").value.length<=0  || document.getElementById("password").value.length<=0){
        alert("Falta llenar un campo ");
        return false;
    }else{
        var strURL = "http://aulavirtual1.urp.edu.pe/scripts/moodle/login/index.php";
        //strURL += "?username="+document.getElementById("usuario").value+"&password="+document.getElementById("clave").value;
        //window.open(strURL,"_blank");
        document.formav.action=strURL;
        document.formav.submit();
        CerrarVentana('divintranet');
    }
}

function bloquear(){

    var alto = obtenerAlto();
    var ancho= obtenerAncho();
    var eDivBloqueo=document.createElement("div");
    eDivBloqueo.setAttribute("id","divBloqueo");
    var cssTxt="position: absolute; top:0px; left:0px; width:"+ancho+"px; height:"+alto+"px; z-index:1000; background-color:black; filter: alpha(opacity=80); -moz-opacity:.55;opacity:.55;";
    eDivBloqueo.style.cssText=cssTxt;
    document.getElementById("divintranet").style.display="";
    document.body.appendChild(eDivBloqueo);
}

function obtenerAncho(){
    return Math.max(
        Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
        Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
        Math.max(document.body.clientWidth, document.documentElement.clientWidth)
        );
}

function obtenerAlto(){
    return Math.max(
        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
        );

}

function CargarAulaVirtual(){
    bloquear();
    new Ajax.Request('paginasinternas/intranet/login_av.html',{
        method: 'get',
        onSuccess:function(t){
            var div= document.getElementById("divintranet");
            div.innerHTML= t.responseText;
            div.style.visibility= "visible";
        }
    });
}

function CargarContenidoPortal(){
    //Cuerpo
    new Ajax.Request('paginasinternas/urp/cuerpoPortal.jsp',{
        method:"post",
        evalScripts: true,
        onSuccess: function(transport){
            document.getElementById("cuerpoPortal").innerHTML=transport.responseText;
            cargarEfectos();
        }
    });
}

function cargarEfectos(){
    var sagscroller2=new sagscroller({
        id:'mysagscroller2',
        mode: 'auto',
        pause: 7000,
        animatespeed: 400 //<--no comma following last option
    });

    mypets=new ddtabcontent("pettabs")
    mypets.setpersist(true)
    mypets.setselectedClassTarget("link")
    mypets.init(8000)

    mypets1=new ddtabcontent("pettabs1")
    mypets1.setpersist(true)
    mypets1.setselectedClassTarget("link")
    mypets1.init(5000)

    jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox()
    })
}

function cargarPaginaCalendario(page){
    mypets.cancelautorun();
    mypets1.cancelautorun();
    var div="contenido";
    new Ajax.Request(page,{
        method:"post",
        onSuccess: function(t){
            document.getElementById(div).innerHTML=t.responseText;
            botonprincipal = document.getElementById("boton32");
            showMenu('galeriaimagenes',botonprincipal);
        },
        onFailure:function(t){
        //alert(t.responceText);
        }
    });
}


