function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure ) {
    var cookie_string = name + "=" + escape ( value );
    if ( exp_y ) {
        var expires = new Date ( exp_y, exp_m, exp_d );
        cookie_string += "; expires=" + expires.toGMTString();
    }
    if ( path ) cookie_string += "; path=" + escape ( path );
    if ( domain ) cookie_string += "; domain=" + escape ( domain );
    if ( secure ) cookie_string += "; secure";
    document.cookie = cookie_string;
}

function delete_cookie ( cookie_name ) {
    var cookie_date = new Date ( );  // current date & time
    cookie_date.setTime ( cookie_date.getTime() - 1 );
    document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function get_cookie ( cookie_name ) {
    var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
    if ( results )
        return ( unescape ( results[1] ) );
    else
        return null;
}

function toggleChk( chk_name, all ) {
    var cBox = document.getElementsByName(chk_name);
    for (i=0; i<cBox.length; i++){
        if (cBox[i].type == 'checkbox') {
            if (cBox[i].checked && !all) 
                cBox[i].checked = false
            else
                cBox[i].checked = true
        }
    }
}

function preselectCheckBox ( chk_name, cookie_name ) {
    var chkBox = document.getElementsByName(chk_id);
    var idArr = get_cookie(cookie_name).split('-');
    for (i=0; i<idArr.length; i++){
       //if(chkBox[i].value = ) 
    }
}

function ventana(pagina,nombre,posicion_x,posicion_y,ancho,alto)
{
// alert("pagina: " + pagina + "\nnombre: " + nombre);
 eval("page" + nombre + " = window.open('" + pagina + "', '" + nombre + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+ ancho +",height="+ alto +",top = " + posicion_y + ", left=" + posicion_x + "');");
}

function acerca()
{
  var x,y,ancho,alto;

  ancho=344;
  alto=200;
  x=(screen.width-ancho)/2;
  y=(screen.height-alto)/2;
  ventana('html/acerca.html','acerca',x,y,ancho,alto);
}
function cerrar(tiempo)
{
  window.setTimeout("top.window.close();", 1000*tiempo);
}

function confirma(mensaje, funcion) {
  if(confirm(mensaje)) {
	    eval(funcion);
	    return true;
  } else {
	    return false;
  }
}

function toggleLayer(whichLayer) {
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = style2.display? "":"block";
    } else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = style2.display? "":"block";
    } else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = style2.display? "":"block";
    }
}

function setLayer(whichLayer, state) {
    // state can take 2 values: block or none
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        style2.display = state;
    } else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = state;
    } else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = state;
    }
}

// Los tabs se agrupan dentro de un tag 
function setTab(idTab,tab,forma) {
	var tabs = document.getElementById(idTab).getElementsByTagName('td');
	for(var i=0;i<tabs.length;i++){
		if(tabs[i].className=='tabCurrent') tabs[i].className="tab";
		if(tabs[i].getAttribute('id')==tab) tabs[i].className="tabCurrent";
	}
	var fs = document.getElementsByTagName('div');
	for(var i=0;i<fs.length;i++){
		if(fs[i].getAttribute('id')) {
			if(fs[i].getAttribute('id').substring(0,5)=='form_') setLayer(fs[i].getAttribute('id'),'none');
		}
		setLayer(forma,'block');
	}
} 
function reinicio()
{
		top.location="acceso.php";
}
 
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

// Para cachar el tabulador y cambiar de tab
var tabBarId;
var tabId;
var formId;
var nextId;
function nextTab(objref, tbbId, tbId, fId, nId) {
    objref.onkeydown = langTabCheck;  
    tabBarId= tbbId;
    tabId= tbId;
    formId= fId;
    nextId= nId;
}
function langTabCheck(e) {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    switch(KeyID) {
    case 9:
        setTab(tabBarId, tabId, formId);
        document.getElementById(nextId).focus();
    }
}
var change = false;
function setExit() { change = true; }
function exitGET() {
    if(change) {
        if(!confirm('No ha guardado los cambios Desea salir del editor?')) return false;
    }
}
function exitPost() {
    if(change) {
        alert("Si cambia de pantalla puede perder sus datos capturados. Para conservarlos regrese a esta pantalla con el control 'back' de su navegador.");     
    }
}

