var idTimm=0;	       //contador para 'seguirMsg()'
var segs=0; 		   //cant. de segundos para 'seguirMsg()'
var auxobjId=""; 	   //var. aux para 'seguirMsg()'
var timmID=0;          //var. que contiene el id de timeOut del mensajeT
var arrNR = new Array; //variable tipo array que contiene los valores de los numero romanos del uno al diez
var accEnCurso=false;	//variable util para cuando se quiere establecer que hay una acción en curso y así evitar que el usuario haga otra cosa mientras tanto
var accNombre="";		//el nombre de la accion en curso
/* TIPOS DE MENSAJES

msg = mensaje por defecto
busc = muestra la lupita que "busca"
work = muestra los engranajes que "trabajan"
alert = alerta, recuadro azul
load = muestra el logo "cargando" */

arrNR[0]='I';
arrNR[1]='II';
arrNR[2]='III';
arrNR[3]='IV';
arrNR[4]='V';
arrNR[5]='VI';
arrNR[6]='VII';
arrNR[7]='VIII';
arrNR[8]='IX';
arrNR[9]='X';

function alertError(texto,objError,modo)
{ //para el manejo de error del lado del cliente
    try {
        switch (modo){
            case(1): //NO muestra window.alert
                //Ver que hacemos
            break;

            case(100): //ERROR de sistema
                window.alert (texto+" \r\n "+objError.message);
            break;

            default: //muestra un window.alert con el texto y el message del objError
                window.alert (texto+" \r\n "+objError.message);
            break;

        }
        return true;
    }catch(anye){
        //???? si falla este tamos mal
        window.alert ("ERROR DE ERROR - "+anye.message);
        return false;
    }
}

function MOC(num,id)
{
    var obj = document.getElementById(id);
    var valor = '';
    
    switch(num)
    {
        case (1):
            valor = '';
        break;
        
        default:
            valor = 'none';
        break;
    }

    obj.style.display=valor;
}

function seguirMsg(ini)
{
    try {
        if (ini==1)
            contI=0;

        //cuenta segundos antes de sacar el mensaje de pantalla (usada desde 'ponermsgT()')
    	if (contI>=segs)
    	{
    		sacarmsg(auxobjId);
    		contI=0;
    		window.clearTimeout(timmID);
    		timmID=0;
    		return true;
    	}
    	contI++;
        timmID=window.setTimeout('seguirMsg()',1000);
    	return false;
	}catch(anye){
        alertError("Error siguiendo mensaje",anye,100);
        return false;
	}
}

function ponermsg(msg,objid,tipo)
{  //esta funcion busca el obj con el id pasado por parametro y pone el contenido de msg en el
    try {
    	var objmsg = document.getElementById(objid);
        var msgbody = document.getElementById(objid+"-body");
    	msgbody.innerHTML=tipoMensaje(msg,tipo);
    	objmsg.style.display='';
    	posiCent(objmsg,'SI');
    	try {
    		window.clearTimeout(timmID);    	
      	}catch(anye){ /*mmmm, no se*/}
        return true;
	}catch(anye){
        alertError("Error colocando cuadro de mensaje",anye,100);
        return false;
	}
}

function ponermsgT(segun,msg,objid,tipo)
{ //esta funcion es la misma que ponermsg pero con un temporizador para sacar el mensaje ('seguirMsg()')
    try {
    	var objmsg = document.getElementById(objid);
        var msgbody = document.getElementById(objid+"-body");

    	msgbody.innerHTML=tipoMensaje(msg,tipo);
    	posiCent(objmsg,'SI');
    	objmsg.style.display='inline';

        window.clearTimeout(timmID);
    	contI=0;
    	segs=segun;
    	auxobjId=objid;
    	seguirMsg(1);
    	return true;
	}catch(anye){
        alertError("Error colocando mensaje",anye,100);
        return false;
	}
}

function posiCent(obj,pa)
{ //devuelve las coordenadas y,x para que el objeto pasado se encuentre en el centro de la pantalla
  //según sus dimenciones. No olvidarme de la función 'parseInt' ya que px con numeros dan % ¿?
    try {
        var tope=0;
    	if (pa=='SI')
    	{
			if (esIE()){
	    		obj.style.position="absolute";
			}else{
	    		obj.style.position="fixed";
			}
    	}else{
    		obj.style.position="relative";
    	}

    	if (esIE())
    	{
    		obj.style.left=(document.documentElement.offsetWidth/2)-(parseInt(obj.style.width)/2);
    		obj.style.top=parseInt(distXY("Y"))+30;

    	}else{
    	    var body = document.getElementsByTagName('body')[0];
    	    var ancho=window.getComputedStyle(body, null).width;//PORQUE EL FF6.0 NO SOPORTA MÁS EL DOCUMENT.WIDTH \m/_
    	    
    		//obj.style.left=(document.width/2)-(parseInt(obj.style.width)/2)+"px";
    		obj.style.left=(parseInt(ancho)/2)-(parseInt(obj.style.width)/2)+"px";
    		obj.style.top=parseInt((distXY("Y"))+30)+"px";

    	}
    }catch(anye){
        alertError("Error posicionando cuadro de mensaje",anye,100);
        return false;
    }
}

function tipoMensaje(txtMsg,tipo) //esta función establece el tipo de mensaje (estilo)
{
    try {
        var sal="";

        switch (tipo)
        {
            case ('msg'):
                sal=" class='msg'>"+txtMsg;
                break;

            case ('busc'):
                sal=" class='busca'>"+txtMsg;
                break;

            case ('work'):
                sal=" class='work'>"+txtMsg;
                break;

            case ('alert'):
                sal=" class='alert'>"+txtMsg;
                break;

            case ('load'):
                sal=" class='load'>"+txtMsg;
                break;

            default:
                sal=" class='msg'>"+txtMsg;
                break;
        }
        sal="<div width='100%' "+sal+"</div>";
        return sal;
    }catch(anye){
        alertError("Error colocando el tipo de mensaje",anye,100);
        return "<p>"+txtMsg+"</p>";
    }
}

function sacarmsg(objid)
{
    //esta función blanquea el objeto con el id pasado
    var obj = document.getElementById(objid);
    var msgbody = document.getElementById(objid+"-body");

    msgbody.innerHTML='&nbsp;';
    obj.style.display='none';
}
function cerrarMsg(objid)
{
    if(timmID!=0)
    {
        sacarmsg(objid);
    }
}


function puntero(num,obj) //esta funcion cambia el puntero del mouse por la 'manito'
//segun el navegador que se esté utlizando
{

    switch (num)
    {
        case 0:
            obj.style.cursor='default';
            break;
        
        case 1:
            if (esIE())
            {
                obj.style.cursor='hand';    
            }else{
                obj.style.cursor='pointer';
            }            
            break;
    }
}

function esIE() //verifica si el navegador actual es IE
{
    var nn = window.navigator.userAgent.toLowerCase();
    if (nn.indexOf('msie')!=-1)
    {
        return true;
    }    else    {
        return false;
    }
}

function esIE8()
{
	if (esIE()){
	    var nn = new String(toLower(window.navigator.userAgent));
	    if (nn.indexOf('msie 8')!=-1){
	    	return true;
	    }else{
	    	//no es 8
	    	return false;
	    }
	}else{
		// no es ie
		return false;
	}
}

function esGeckoComp()
{
	var esComp=false;

	if (esNS()){
		esComp=true;
	}

	if (esFX()){
		esComp=true;
	}
	
	if (esOpera()){
		esComp=true;
	}
	
	if (esChrome()){
		esComp=true;
	}
	
	return esComp;
}

function esNS() //verifica si el navegador actual es NS
{
    var nn = window.navigator.userAgent.toLowerCase();
    if (nn.indexOf('netscape')!=-1)
    {
        return true;
    }    else    {
        return false;
    }
}

function esChrome() //verifica si el navegador actual es Chrome
{
    var nn = window.navigator.userAgent.toLowerCase(); 

    if (nn.indexOf('chrome')!=-1)
    {
        return true;    
    }    else    {
        return false;
    }
}

function esOpera() //verifica si el navegador actual es Opera
{
    var nn = window.navigator.userAgent.toLowerCase();
    if (nn.indexOf('opera')!=-1)
    {
        return true;
    }    else    {
        return false;
    }
}

function esFX() //verifica si el navegador actual es FireFox
{
    var nn = window.navigator.userAgent.toLowerCase();
    if ((nn.indexOf('firefox')!=-1) || (nn.indexOf('iceweasel')!=-1))
    {
        return true;
    }    else    {
        return false;
    }
}

function escap(texto)
{
    try {
    	var str = new String(texto);
    	var reemp="`";
    	var exp='';  // la creo
    	exp = /'/gi; // la seteo
    	texto =	str.replace(exp,reemp);
    	return texto;
    }catch(anye){
        alertError("Error 'escapando' valor ",anye,1);
        return texto;
    }
}

function esNum(valor)
//esta funcion regresa true si un valor es númerico y falso si no lo es.
{
	if (valor==""){
	    return false;
	}else{
	    if (isNaN(valor))
    	    return false;
	}
    return true;
}

function esNumEnt(valor)
//esta funcion regresa true si un valor es númerico es entero y falso si no lo es.
{
	if (!esNum(valor)){
		return false;	
	}else{
		if (parseInt(valor)!=valor){
			return false;
		}
	}
    return true;
}

function esNumRoman(valor)
{
    var esNR = false;

    var str = new String(valor);
    var txt=str.toUpperCase();

    for (num in arrNR)
    {
        if (arrNR[num]==txt)
        {
            esNR=true;
            break;
        }
    }
    return esNR;
}

function distXY(coor)
{
  //regresa la cantidad en pixeles que esta desplazada la pagina hacia abajo y hacia a la derecha
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }

  switch (coor)
  {
    case('X'):
    case('x'):
        return scrOfX;
    break;

    case('Y'):
    case('y'):
        return scrOfY;
    break;
  }
}

function enaDesa(num,idObj) //intenta habilitar / deshabilitar un obj. html segun su id
{
	try {
		var obj = document.getElementById(idObj);
		switch(num)
		{
			case (1):
				obj.disabled=false;
			break;

			default:
				obj.disabled=true;
			break;
		}

		return true;
	}catch(anye){
		window.alert ("Error habilitando / deshabilitando ! - "+anye.message);
		return false;
	}
}

//EN TODAS las pagina que se incluya existirá esta funcion de accionFAIL por las dudas
function accionFAIL(texto)
{ //por si falla 'algo'
    try {
        ponermsgT(30,texto,'mensaje','alert');
        return true;
    }catch(anye){
        alertError("Error procesando archivo - "+texto,anye);
        return false;
    }
}

//##################################
// Teclas
function queTecla(e)
//esta función regresa el codigo de tecla presionado
{
	var codTecla=0;
	if (esIE())
	{
		codTecla=window.event.keyCode;
	}else{
		codTecla=e.keyCode;
	}

	return codTecla;
}

function queCar(e)
//esta función regresa el codigo de caracter
{
	var codTecla=0;
	if (esIE())
	{
		codTecla=window.event.charCode;
	}else{
		codTecla=e.charCode;
	}

	return codTecla;
}

function ctrlTecla(e)
{ //indica si la tecla "control" está presionada
	var tP = false;
	if (esIE())
	{
		tP=window.event.ctrlKey;
	}else{
		tP=e.ctrlKey;
	}
	
	return tP;
}


function altTecla(e)
{ //indica si la tecla "Alt" está presionada
	var tP = false;
	if (esIE())
	{
		tP=window.event.altKey;
	}else{
		tP=e.altKey;
	}
	
//	window.alert ("tecla alt."+tP);
	return tP;
}
// FIN Teclas
//###################################

//##################################
//funciones de Mouse
function mouseOv(obj,tipoEfe)
{
    try {
        switch(tipoEfe)
        {
            case (1): //seteo con un marco
                obj.style.backgroundColor="#999999";
                obj.style.border="1px solid";
            break;
            
            case (2):
                obj.style.backgroundColor="#d1d1d1";
            break;

            case (10): //estilo con negrita
                obj.style.fontWeight='bold';
            break;

            case (20):
                obj.style.textDecoration='underline';
            break;

            default:
//                obj.style.backgroundColor="#d1d1d1";
            break;
        
        }
        puntero(1,obj);
        return true;
    }catch(anye){
        window.alert ("Error mouseOv - "+anye.message);
        return false;
    }
}

function mouseOut(obj,tipoEfe)
{
    try {
        switch(tipoEfe)
        {
            case (1):
                obj.style.backgroundColor='transparent';
		    //obj.style.backgroundColor='#eeeeee';
                obj.style.border="none";
            break;

            case (2):
                obj.style.backgroundColor="#f1f1f1";
            break;

            case (10):
                obj.style.fontWeight='';
            break;

            case (20):
                obj.style.textDecoration='';
            break;

            default:
//                obj.style.backgroundColor='transparent';
		    //obj.style.backgroundColor='#eeeeee';
            break;
        }
        puntero(0,obj);
    }catch(anye){
        window.alert ("Error mouseOut - "+anye.message);
        return false;
    }
}

function mouseOutC(obj,color,tipoEfe)
{
    try {
        switch(tipoEfe)
        {
            case (1):
                obj.style.backgroundColor=color;
            break;

            default:
                obj.style.backgroundColor=color;
                obj.style.border="none";
            break;
        }
        puntero(0,obj);
    }catch(anye){
        window.alert ("Error mouseOutC - "+anye.message);
        return false;
    }
}
// Fin mouse
//##########################################

//acciones
function verifAccEnCurso()
{ //verifica si la variabla accEnCurso es true indicando que hay una acción previa en curso, de ser así emite un mensaje
	if (accEnCurso){
		if (accNombre != "" && accNombre != undefined){
			window.alert (" "+accNombre+" en curso, espere...");
		}else{
			window.alert (" Acción previa en curso, espere...");		
		}
		return false;	
	}else{
		return true;
	}
}

function accIni(nombreAccion)
{ //"inicio" de una accion
	try {
		accNombre=nombreAccion;
		accEnCurso=true;
		return true;
	}catch(anye){
		accNombre="";	
		accEnCurso=true;	
		return true;
	}
}

function accEnd()
{ //"fin" de una acción
	accNombre="";
	accEnCurso=false;
}

/*	###############################
	###			Texto 			###
	###############################	*/
function cambiarEnterXEspacio(str)
{
    var textoes="";

    textoes=escape(str);
    var str2 = new String(textoes);
    exp = /%0A/gi;

    resp = str2.replace(exp,'%20');

    var textoSal = "";
    textoSal=unescape(resp);

    return textoSal;
}

function cambiarEnterXBr(str)
{
    try {
		var textoes="";

		textoes=escape(str);
		var str2 = new String(textoes);
		exp = /%0A/gi;

		resp = str2.replace(exp,'<br>');

		var textoSal = "";
		textoSal=unescape(resp);

		return textoSal;

	}catch(anye){
		alertError("Error función EnterXBr",anye);
		return false;
	}
}

function cambiarBrXEnter(str)
{
	try {
		var textoes="";

		textoes=escape(str);
		var str2 = new String(textoes);
//		exp = /<br>/gi;
		exp = /%3Cbr%3E/gi;

		resp = str2.replace(exp,'%0A'); //%0A

		var textoSal = "";
		
		textoSal=unescape(resp);
		//textoSal=decodeURIComponent(resp); prueba

		return textoSal;
	}catch(anye){
		alertError("Error función BrXEnter",anye);
		return false;
	}
}

function toUpper(valor)
{


    var str = new String(valor);
    return str.toUpperCase();
}

function toLower(valor)
{
    var str = new String(valor);
    return str.toLowerCase();
}

function trim(str) {
    var s = new String(str);

    while (s.substring(0,1) == ' '||s.charCodeAt(0)==160) {
        s = s.substring(1,s.length);
    }

    while (s.substring(s.length-1,s.length) == ' '||s.charCodeAt(s.length)==160) {
        s = s.substring(0,s.length-1);
    }

    return s;
}

function esVacio(obj)
{
	if (obj.value=='')
	{
		return true;
	}else{
		return false;
	}
}

function tieneEspacio(texto)
{
    var obj = new String(texto);
	if (obj.indexOf(' ')!=-1)
	{
		return true;
	}else{
		return false;
	}
}

/* #################################
   ##	funciones en desuso       ##
   #################################  */
function innerNBSP(idObj)
{ //coloca ' &nbsp; ' en el obj segun el id del mismo pasado
    try {
        var obj = document.getElementById(idObj);
        obj.innerHTML='&nbsp;';
        return true;
    }catch(anye){
        //alertError("Error insertando 'nbsp'",anye);
        return false;
    }
}

function enfocar(ObjId)
{
    //enfoca el objeto con el id pasado
    var obj = document.getElementById(ObjId);
    obj.focus();
}

/*SITIO EWAY*/
//OBTIENE EL ALTO DE LA VENTANA, RESTA FOOTER Y HEADER PARA SETEAR EL ALTO DEL CONTENIDO
function altoContenido()
{
	try {
		var contenido = document.getElementById("contenido");
		var header = document.getElementById("header");
		var footer = document.getElementById("footer");
		var alt1,alt2,alt3

		if(header.offsetHeight){
			alt1=header.offsetHeight;
		}else if(header.style.pixelHeight){
			alt1=header.style.pixelHeight;
		}

		if(footer.offsetHeight){
			alt2=footer.offsetHeight;
		}else if(footer.style.pixelHeight){
			alt2=footer.style.pixelHeight;
		}
		
		if(contenido.offsetHeight){
			alt3=contenido.offsetHeight;
		}else if(contenido.style.pixelHeight){
			alt3=contenido.style.pixelHeight;
		}
		
		if(alt3<=obtAlto()-alt1-alt2-10)
			contenido.style.height=obtAlto()-alt1-alt2-10;
			
		return true;
	}catch(anye){
		alertError("Error seteando el alto del contenido",anye);
		return false;
	}
}




/*
function
{
	try {

		return true;
	}catch(anye){
		alertError("",anye);
		return false;
	}
}*/

