/*
******************************************************************************************
PM_FUNCIONES.JS
FECHA CREACION		 : 13/03/2007
FECHA ACTUALIZACION  : 27/03/2007
DETALLE DE LA PAGINA: ESTA PAGINA CONTIENE EL CODIGO JAVAscript A UTILIZAR EN TODO EL MÓDULO 
DE ADMINISTRACIÓN
******************************************************************************************
*/

var nav4 = window.Event ? true : false;
var Depa=""
var Prov=""
var Dist=""

/* Movemos la ventana */
//self.moveTo(0,0)
/* Maximizamos la ventana según la resolución de pantalla */
//self.resizeTo(screen.availwidth,screen.availheight)


function pm_js_valida_numero(evt)
{	
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
var key = nav4 ? evt.which : evt.keyCode;	
return (key <= 13 || (key >= 48 && key <= 57));
}

function pm_js_fecha_actual()
{
var now = new Date()
var dia = now.getDay()
var mes = now.getMonth()
var anio = now.getYear()
var fecha

fecha = now.getDate() + " de "

//El nombre del mes
if(mes==0){
 fecha=fecha + "Enero"
}else if(mes==1){
 fecha=fecha + "Febrero"
}else if(mes==2){
 fecha=fecha + "Marzo"
}else if(mes==3){
 fecha=fecha + "Abril"
}else if(mes==4){
 fecha=fecha + "Mayo"
}else if(mes==5){
 fecha=fecha + "Junio"
}else if(mes==6){
 fecha=fecha + "Julio"
}else if(mes==7){
 fecha=fecha + "Agosto"
}else if(mes==8){
 fecha=fecha + "Setiembre"
}else if(mes==9){
 fecha=fecha + "Octubre"
}else if(mes==10){
 fecha=fecha + "Noviembre"
}else{
 fecha=fecha + "Diciembre"
}

if (anio < 1900)
		{
		anio =anio + 1900;
		
		}

fecha = fecha + " del " + anio
return fecha;
}

function pm_js_Permut (flag,img) {
   if (document.images) {
        if (document.images[img].permloaded) {
            if (flag==1) document.images[img].src = document.images[img].perm.src
            else document.images[img].src = document.images[img].perm.oldsrc
        }
   }
}

function pm_js_preloadPermut (img,adresse) {
   if (document.images) {
        img.onload = null;
        img.perm = new Image ();
        img.perm.oldsrc = img.src;
        img.perm.src = adresse;
        img.permloaded = true;
   }
}

function pm_js_abrir_sub_ventanas(Pagina,Alto,Ancho)
{
  window.open(Pagina,'','height=' + Alto + ',width=' + Ancho + ',resizable=0,noresize=yes,toolbar=0,location=no,directories=0,status=yes,menubar=0,scrollbars=yes')
}

function pm_js_abrir_imagenes(Pagina,Alto,Ancho)
{
  window.open(Pagina,'','height=' + Alto + ',width=' + Ancho + ',resizable=0,noresize=yes,toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=0')
}

function detectKey() 
{
 /*Este es el F5
 if(window.event && window.event.keyCode == 116){
 window.event.keyCode = 0;
 return false;
 }*/
 
 /*Este es el F11*/
 if(window.event && window.event.keyCode == 122){
 window.event.keyCode = 0;
 return false;
 }
 
 if(window.event && window.event.keyCode == 18){
 window.event.keyCode = 0;
 return false;
 }
 
 if(window.event && window.event.keyCode == 37){
 window.event.keyCode = 0;
 return false;
 }

}

document.onkeydown = detectKey;

function click(){
/*
if(event.button==2){
alert('Copyright Oficina Nacional de Gobierno Electrónico e Informática');
}*/

}

document.onmousedown=click





/*Menú desplegable*/
var enablepersist="on" 
var collapseprevious="no"

if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(classname){
ccollect=new Array()
var inc=0
var alltags=document.all? document.all : document.getElementsByTagName("*")
for (i=0; i<alltags.length; i++){
if (alltags[i].className==classname)
ccollect[inc++]=alltags[i]
}
}

function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(cid){
if (typeof ccollect!="undefined"){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
getElementbyClass("switchcontent")
if (enablepersist=="on" && typeof ccollect!="undefined"){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
}


if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

/*******/


function Buscar(Entidad)
{
if (document.frm_busqueda.txt_parrafo_busq.value==""){
 document.frm_busqueda.txt_parrafo_busq.value="%"
 document.frm_busqueda.submit()
}else{
 document.frm_busqueda.submit()
}


}


function Enviar()
{
if (document.frm_contactenos.txt_nombres.value==""){
 alert("Debe de escribir su nombre")
 document.frm_contactenos.txt_nombres.focus()
}else if (document.frm_contactenos.txt_email.value==""){
 alert("Debe de escribir su correo")
 document.frm_contactenos.txt_email.focus()
}else if (document.frm_contactenos.Tipo.value==""){
 alert("Debe seleccionar un tipo de mensaje")
 document.frm_contactenos.Tipo.focus()
}else if (document.frm_contactenos.txt_asunto.value==""){
 alert("Debe de escribir el asunto")
 document.frm_contactenos.txt_asunto.focus()  
}else if (document.frm_contactenos.txt_sugerencia.value==""){
 alert("Debe de escribir el comentario")
 document.frm_contactenos.txt_sugerencia.focus()  
}else{
 document.frm_contactenos.submit()
}


}

function pm_js_abrir_sub_ventanas(Pagina,Alto,Ancho)
{
  window.open(Pagina,'','height=' + Alto + ',width=' + Ancho + ',resizable=0,noresize=yes,toolbar=0,location=no,directories=0,status=0,menubar=0,scrollbars=yes')
}

nereidFadeObjects = new Object();
nereidFadeTimers = new Object();

/* object - image to be faded (actual object, not name);
 * destop - destination transparency level (ie 80, for mostly solid)
 * rate   - time in milliseconds between trasparency changes (best under 100)
 * delta  - amount of change each time (ie 5, for 5% change in transparency)
 */

function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
    if (object != "[object]"){  //do this so I can take a string too
        setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
        return;
    }
        
    clearTimeout(nereidFadeTimers[object.sourceIndex]);
    
    diff = destOp-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > destOp){
        direction = -1;
    }
    delta=Math.min(direction*diff,delta);
    object.filters.alpha.opacity+=direction*delta;

    if (object.filters.alpha.opacity != destOp){
        nereidFadeObjects[object.sourceIndex]=object;
        nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
    }
}

function Historial(num_id_entidad,str_ent_nombre)
{
window.open('lisHistoricosFechas.asp?Entidad=' + num_id_entidad + '&Nombre=' + str_ent_nombre,'','resizable=no,menubar=no,location=no,toolbar=no,status=no,scrollbars=yes,directories=no,width=488,height=432,left = 0,top = 25');
}

function Vincular(Nombre)
{
  window.open(Nombre,'','resizable=no,menubar=no,location=no,toolbar=no,status=no,scrollbars=yes,directories=no,width=487,height=512,left = 0,top = 25');
}
