/*Seccion de empleados*/
var divActual="";
/**********************/

function LTrim( str ) {
	var resultStr = "";
	var i = len = 0;
	if (str+"" == "undefined" || str == null)
	return null;
	str += "";
	if (str.length == 0)
	resultStr = "";
	else {
		len = str.length;
		while ((i <= len) && (str.charAt(i) == " "))
		i++;
		resultStr = str.substring(i, len);
	}
return resultStr;
}

function RTrim( str ) {
	var resultStr = "";
	var i = 0;
	if (str+"" == "undefined" || str == null)
	return null;
	str += "";
	if (str.length == 0)
	resultStr = "";
	else {
	i = str.length - 1;
	while ((i >= 0) && (str.charAt(i) == " "))
		i--;
		resultStr = str.substring(0, i + 1);
	}
return resultStr;
}

function Trim( str ) {
	var resultStr = "";
	resultStr = LTrim(str);
	resultStr = RTrim(resultStr);
	return resultStr;
}

function EsNumero(numstr) {
	if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")
		return false;
	var esValido = true;
	var decCount = 0;
	numstr += "";
	for (i = 0; i < numstr.length; i++) {
		if (numstr.charAt(i) == ".")
		decCount++;
		if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") ||
		(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
			esValido = false;
			break;
		} else if ((numstr.charAt(i) == "-" && i != 0) ||
		(numstr.charAt(i) == "." && numstr.length == 1) ||
		(numstr.charAt(i) == "." && decCount > 1)) {
			esValido = false;
			break;
		}
	}
	return esValido;
}
//No permite la captura de letras ni de cualquier otro caracter q no se a un numero decimal, entero positivo o negativo y fraccionario
//Actualizado para FireFox   SoloNumeros(event,this.value);
function SoloNumeros(Evento,numero,TipoDato){
	//46='.'//45='-'//13=Enter 47='/ '
	numero+="";
	var puntos=0;
	var menos=0;
	var diagonal=0;
	var Valido=true;
	var i=0;
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	//alert(Valor);
	do{
    	//if(TipoDato=='DECIMAL'){ 
	    	if(numero.charAt(i)==".")puntos++;
	    //}
	    if(numero.charAt(i)=="-")menos++;
	    if(TipoDato=='ENTERO')puntos=1;
	    if(TipoDato=='FECHA'){
		    puntos=1;
		    menos=1;
		    if(numero.charAt(i)=="/")diagonal++;
		    if((diagonal>=2 && Valor==47)) return false;
	    }
	    /*if(TipoDato=='HORA'){
		    puntos=1;
		    menos=1;
		    if(numero.charAt(i)==":")dospuntos++;
		    if((dosPuntos>=1 )) return false;
	    }*/
    	if((puntos>0 && Valor==46)|| (menos>0 && Valor==45)) Valido=false;
    	i++;
	}while(i<numero.length)
	if(Valido)
	    return ((Valor==0 || Valor==8 || Valor==46||Valor==45||Valor==13||Valor==47)||((Valor >= 48 && Valor <= 57))); 
	else return Valido;
}
function EsMail(_email) {
	var emailReg = /^[a-z][a-z-_0-9\.]+@[a-z-_=>0-9\.]+\.[a-z]{2,3}$/i
	return emailReg.test(_email);
}
function EncriptaForm(forma){	
	//alert(1)
	for(intElemento=0;intElemento<forma.length;intElemento++){
		if((forma.elements[intElemento].type!="button" && forma.elements[intElemento].type!="submit") && forma.elements[intElemento].value!=""){
			valorEncriptado=bwfEncripta('ProcesamientoCasolaOutNomina',forma.elements[intElemento].value);
			forma.elements[intElemento].value=valorEncriptado;
		}
	}
	return true;
}
//Si presionas Enter pasa al siguiente elemento del formulario
function SiguienteTexto(form,field){
	var next=0, found=false
	var f=form
	if(event.keyCode!=13) return;
	for(var i=0;i<f.length;i++) {
		if(field.name==f.item(i).name){
			next=i+1;
			found=true
			break;
		}
	}
	while(found){
		if( f.item(next).disabled==false && f.item(next).type!='hidden'){
			f.item(next).focus();
			break;
		}
		else{
			if(next<f.length-1)
			next=next+1;
			else
			break;
		}
	}
}
//SiguienteTexto(this.form,this)

function popup(Pagina,Titulo,Ancho,Alto,Herramientas,Menu,Scroll,Maximizar,Estatus) 
{
	var ventana=window.open(Pagina, Titulo, 'width=' + Ancho + ',height=' + Alto + ',location=no,toolbar=' + Herramientas + ',menubar=' + Menu + ',scrollbars=' + Scroll + ',resizable=' + Maximizar + ',status=' + Estatus + ',dependent=yes');
	if(!ventana) alert('Es posible que OutNom no pueda abrir la pagina a causa de un bloqueador de popups.\nSi utilizas alguna aplicación de este tipo, intenta inhabilitarla para abrir la ventana.');
}
function popup_post(forma,Ancho,Alto,Herramientas,Menu,Scroll,Maximizar,Estatus){
	 formulario = eval(forma)
   window.open("", "popup","width="+Ancho+",height="+Alto+",location=no,toolbar="+Herramientas+",menubar="+Menu+",scrollbars="+Scroll+",resizable="+Maximizar+",status="+Estatus + ',dependent=yes');
   formulario.target = "popup";
   formulario.submit();
}
function recargarFrame(destino,formulario,frame) {
	var valor='';
	if (window.event.keyCode=='13'){
		for(objeto=0;objeto<document.forms[formulario].elements.length;objeto++){
			valor=valor+'&'+document.forms[formulario].elements[objeto].name+'='+document.forms[formulario].elements[objeto].value;
		}
		//alert(destino +'\n'+valor);
	 window.frames[frame].location.href=destino+'&'+valor;
	}
}
function VerificaFecha(str){
 if(str!=""){
	var fecha=new String(str);
	if(fecha.length==10 && fecha.split("/")[0]<=31 && fecha.split("/")[1]<=12&&fecha.split("/")[2]*1>1900) return true;
	else {
		alert ("Fecha Invalida, el formato debe ser dd/mm/aaaa");
		return false;
	}
 }
 else return true;
}
function DiferenciaDias(FechaDesde,FechaHasta){
	var re_date = /^(\d+)\/(\d+)\/(\d+)$/;
	var Temporal=new String(FechaDesde);
	FechaArray=Temporal.split("/");
	FechaDesde=FechaArray[1]+"/"+FechaArray[0]+"/"+FechaArray[2];
	if (!re_date.exec(Temporal)) return alert("Formato inválido en Fecha Desde: "+ Temporal);
	Temporal=FechaHasta;
	FechaArray=Temporal.split("/");
	FechaHasta=FechaArray[1]+"/"+FechaArray[0]+"/"+FechaArray[2];
	if (!re_date.exec(Temporal)) return alert("Formato inválido en Fecha Hasta: "+ Temporal);
	var FechaD= new Date(FechaDesde);
	var FechaH= new Date(FechaHasta);
	if (FechaD>FechaH) return alert('La Fecha Desde debe ser menor a la Fecha Hasta');
	//FechaDesde=FechaD.getMonth()+"/"+FechaD.getDate()+"/"+FechaD.getFullYear();
	//FechaHasta=FechaH.getMonth()+"/"+FechaH.getDate()+"/"+FechaH.getFullYear();
	var DiaDif=(Math.round((Date.parse(FechaHasta)-Date.parse(FechaDesde))/(24*60*60*1000))*1);
	//alert (DiaDif);
	return DiaDif+1;
}
function InavilitaForma(Formulario){
    var forma=document.forms[Formulario];
    for(Objeto=0;Objeto<forma.elements.length;Objeto++){
        forma.elements[Objeto].disabled=true;
    }
}
function oculta_elemento(elemento) {
  var trObj = (document.getElementById) ? document.getElementById(elemento) : eval("document.all['" + elemento + "']");
  if (trObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
    }
    else {
	    trObj.style.display="none";
    }
  }
}

/****Funciones de empleados*******/
function Tabulador(formulario,Valor){
    if(Valor==1){
        document.forms[formulario].sueldo_mensual.readOnly=false;
        document.forms[formulario].sueldo_mensual.className='Txt';
        document.forms[formulario].sueldo_mensual.tabIndex=25;
        document.forms[formulario].sueldo_administrativo.ReadOnly=false;
        document.forms[formulario].sueldo_administrativo.className='Txt';
        document.forms[formulario].sueldo_administrativo.tabIndex=26;
        document.forms[formulario].sobresueldo.readOnly=false;
        document.forms[formulario].sobresueldo.className='Txt';
        document.forms[formulario].sobresueldo.tabIndex=27;
        document.forms[formulario].sueldo_mensual.focus();
            
        document.getElementById('flstabulador').disabled=true;
        document.forms[formulario].tabulador.tabIndex=0;
        document.forms[formulario].nivel_tabulador.tabIndex=0;
        document.forms[formulario].nivel_sueldo.tabIndex=0;
        document.forms[formulario].tabulador.disabled=true;
        document.forms[formulario].nivel_tabulador.disabled=true;
        document.forms[formulario].nivel_sueldo.disabled=true;
        document.forms[formulario].tabulador.className='TxtSoloLectura';
        document.forms[formulario].nivel_tabulador.className='TxtSoloLectura';
        document.forms[formulario].nivel_sueldo.className='TxtSoloLectura';
    }
    if(Valor==2){
        document.forms[formulario].sueldo_mensual.readOnly=true;
        document.forms[formulario].sueldo_mensual.className='TxtSoloLectura';
        document.forms[formulario].sueldo_mensual.tabIndex=0;
        document.forms[formulario].sueldo_administrativo.readOnly=true;
        document.forms[formulario].sueldo_administrativo.className='TxtSoloLectura';
        document.forms[formulario].sueldo_administrativo.tabIndex=0;
        document.forms[formulario].sobresueldo.readOnly=true;
        document.forms[formulario].sobresueldo.className='TxtSoloLectura';
        document.forms[formulario].sobresueldo.tabIndex=0;
        
        document.getElementById('flstabulador').disabled=false;
        document.forms[formulario].tabulador.tabIndex=25;
        document.forms[formulario].nivel_tabulador.tabIndex=26;
        document.forms[formulario].nivel_sueldo.tabIndex=27;
        document.forms[formulario].tabulador.disabled=false;
        document.forms[formulario].nivel_tabulador.disabled=false;
        document.forms[formulario].nivel_sueldo.disabled=false;
        document.forms[formulario].tabulador.className='Txt';
        document.forms[formulario].nivel_tabulador.className='Txt';
        document.forms[formulario].nivel_sueldo.className='Txt';
        document.forms[formulario].tabulador.focus();
    }
    if(Valor==3){
        document.forms[formulario].sueldo_mensual.readOnly=true;
        document.forms[formulario].sueldo_mensual.className='TxtSoloLectura';
        document.forms[formulario].sueldo_mensual.tabIndex=0;
        document.forms[formulario].sueldo_administrativo.readOnly=true;
        document.forms[formulario].sueldo_administrativo.className='TxtSoloLectura';
        document.forms[formulario].sueldo_administrativo.tabIndex=0;
        document.forms[formulario].sobresueldo.readOnly=true;
        document.forms[formulario].sobresueldo.className='TxtSoloLectura';
        document.forms[formulario].sobresueldo.tabIndex=0;
        
        document.getElementById('flstabulador').disabled=true;
        document.forms[formulario].tabulador.tabIndex=0;
        document.forms[formulario].sobresueldo.tabIndex=0;
        document.forms[formulario].nivel_sueldo.tabIndex=0;
        document.forms[formulario].tabulador.disabled=true;
        document.forms[formulario].nivel_tabulador.disabled=true;
        document.forms[formulario].nivel_sueldo.disabled=true;
        document.forms[formulario].tabulador.className='TxtSoloLectura';
        document.forms[formulario].nivel_tabulador.className='TxtSoloLectura';
        document.forms[formulario].nivel_sueldo.className='TxtSoloLectura';
    }
}
function SD_SH(formulario,Valor){
    if(Valor!=0){
        document.forms[formulario].sueldo_diario.value=FormatoMoneda(Valor/30,2,'.','');
        document.forms[formulario].sueldo_hora.value= FormatoMoneda(document.forms[formulario].sueldo_diario.value/8,2,'.','');
    }
    else{
        document.forms[formulario].sueldo_diario.value=0;
        document.forms[formulario].sueldo_hora.value=0;
    }
}

function Mostrar(divId,primercampo,frm_Load,ref){  
	
	var objMostrar=(document.getElementById)? document.getElementById(divId) : eval("document.all['" + divId + "']");
    var objOcultar=(document.getElementById)? document.getElementById(divActual) : eval("document.all['"+divActual+"']");
    
    var EtiquetaSel=(document.getElementById)? document.getElementById('l'+divId): eval("docuemtn.all['l"+ divId+"']");
	var EtiquetaUnSel=(document.getElementById)? document.getElementById('l'+divActual): eval("docuemtn.all['l"+ divActual+"']");
	
    if(objMostrar.style.display=='none'){
	    objOcultar.style.display='none';
	    objMostrar.style.display='';
	    EtiquetaSel.className='MenuSel';
	    EtiquetaUnSel.className='Opciones';
	    if(primercampo!=null && primercampo!='') primercampo.focus();
	    if(frm_Load!=null){
		    //frame=(document.getElementById)? document.getElementById(frm_Load) : eval("document.all['"+ frm_Load + "']");
		    if(ref!=null) frames[frm_Load].location.href=ref;
	    }
	    divActual=divId;
	   
    }
	return false;
}
function PermiteLiga(){
    if(document.empleados.motivo.value==''){
       // alert('El campo Motivo no puede estar en blanco'); 
        return false;
    }
    return true;
}
function armaCadena(mlt){
	var respuesta="";
	for(contador=0; contador<mlt.options.length; contador++){
		if(mlt.name!="grupos"){
			if(mlt.options[contador].selected){
				respuesta =respuesta +mlt.options[contador].value+",";
			}
		}
		else{
			if(mlt.options[contador].text){
				respuesta =respuesta +mlt.options[contador].value+ ',';
			}
		}
			
	}
	return respuesta.substring(0,respuesta.length-1);
}
function mover(origen,destino) {
	//alert(1);
  var desde=(document.getElementById)? document.getElementById(origen) : eval("document.all['"+origen+"']");
  var hasta=(document.getElementById)? document.getElementById(destino) : eval("document.all['"+destino+"']");
  for(var contador=0; contador<desde.options.length; contador++) {
    if(desde.options[contador].selected && desde.options[contador].value != "") {
       var temporal = new Option();
       temporal.value = desde.options[contador].value;
       temporal.text = desde.options[contador].text;
	   hasta.options[hasta.options.length] = temporal;	
	   desde.options[contador].value = "";
	   desde.options[contador].text = "";
	   desde.options[contador]=null;
   }
 }
}
function PasarValor(valor1,valor2,destino,opt) {
 str=PreparaCadena(valor1,valor2);
 if(str!=0){
	separador=obtenseparador(opt);
    if(destino.value==""){ 
        destino.value = str;
	}
	else {
		 destino.value=destino.value+ separador +str;
    }
 }
 else{
	 alert('Debe insertar un valor');
 }
}
function PreparaCadena(val1,val2){
	if(val2!="") return val1+'='+'\''+val2+'\'';
	else return 0;
}
function obtenseparador(opciones){
  if(opciones[0].checked){
  	return " AND ";
  }
  else{
    return " OR "
  } 
}	
/************************************************************************/        
/*Menu emergente                                                        */   
/*Desarrollado por Max Daniel Jimenez Z.                                */
/************************************************************************/                                       
function MuestraMenu(ev){
    if(navigator.userAgent.indexOf('MSIE')>=0){
        var derecha=document.body.clientWidth-event.clientX                                                                                                                                                                                                                             
	    var inferior=document.body.clientHeight-event.clientY                                                                                                                                                                                                                         
	    if (derecha<menu.offsetWidth)                                                                                                                                                                                                                                                  
		    menu.style.left=document.body.scrollLeft+event.clientX-menu.offsetWidth                                                                                                                                                                                                       
	    else                                                                                                                                                                                                                                                                                
		    menu.style.left=document.body.scrollLeft+event.clientX                                                                                                                                                                                                                           
	    if (inferior<menu.offsetHeight)                                                                                                                                                                                                                                                
		    menu.style.top=document.body.scrollTop+event.clientY-menu.offsetHeight                                                                                                                                                                                                        
	    else                                                                                                                                                                                                                                                                                
		    menu.style.top=document.body.scrollTop+event.clientY                                                                                                                                                                                                                             
	    menu.style.visibility="visible" 
	    return false; 
    }
    else{//Si es Firefox o NetScape
        event=ev;  
        var derecha=document.body.clientWidth-event.pageX;
        var inferior=document.body.clientWidth-event.pageY;
        if (derecha<menu.offsetWidth)
            menu.style.left=event.pageX-menu.offsetWidth
        else 
            menu.style.left=event.pageX
        if (inferior<menu.offsetHeight)
            menu.style.top=event.pageY-menu.offsetWidth
        else 
            menu.style.top=event.pageY
        menu.style.visibility="visible"
        return false; 
    }                                                                                                                                                                                                                                                          
	                                                                                                                                                                                                                                                                      
}                                                                                                                                                                                                                                                                    
function OcultaMenu(){   
	var menu=(document.getElementById)? document.getElementById('menu'): eval("document.all['menu']")
    menu.style.visibility="hidden";
}                                                                                                                                                                                                                                                                                   
function CambiaColor(ev){ 
    if(navigator.userAgent.indexOf('MSIE')>=0){                                                                                                                                                                                                                                                         
	    if (event.srcElement.className=="item"){ 
    	        event.srcElement.className="itemSel";
	    }
	    else{
    	        event.srcElement.className="item"
	    } 
    }
    else{
        event=ev;
        if(event.target.className=="item"){
            event.target.className="itemSel"
        }
		else{
			event.target.className="item"
			    
        }
    }
	
}
function ArmaFecha(Evento,valor,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	//alert(Valor);
	if(Valor>=48 && Valor<=57 || (Valor==8 || Valor==0 || Valor==9) ){
		if(Valor!=8 && Valor!=0 && Valor!=9){
			if(elemento.value.length==2){
				if(elemento.value>31){
					elemento.value='';
					return false;
				}
				else elemento.value=elemento.value+'/';
			}
			if(elemento.value.length==5){
				if(parseInt(elemento.value.split("/")[1])>12){
					elemento.value=elemento.value.split("/")[0]+'/';
					return false;
				}
				else elemento.value=elemento.value+'/';
			}
		}
	}
	else return false;
}
function ArmaHora(Evento,valor,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	var Respuesta=true;
	if(SoloNumeros(Evento,valor,'ENTERO')){
		var ValorTecla=new String(String.fromCharCode(Valor));
		switch(valor.length){
			case 2: 
				if(elemento.value>24){
					elemento.value='';
					return false;
				}
			    else elemento.value=elemento.value+":";
				break;
			case 5:
				if(parseInt(elemento.value.split(":")[1])>60){
					elemento.value=elemento.value.split(":")[0]+':';
					return false;
				}
				else return true;
		}
	}
	else Respuesta=false;
	return Respuesta;
}
function RFCMoral(Evento,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	var Respuesta=true;
	var ValueElemento=new String(elemento.value);
	//alert( Valor);
	if(Valor==0 || Valor==8) return true;
	if(ValueElemento.length<=2){
		if((Valor >= 65 && Valor <= 90)||(Valor >= 97 && Valor <= 122)|| Valor==241 || Valor==209 ){
			var TeclaPulsada=new String(String.fromCharCode(Valor));
			//if(Valor==192)TeclaPulsada='Ñ';
			if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
			else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			return false;
	    }
	    else return false;
	}
	else{
		if(ValueElemento.length<=7){
			return SoloNumeros(Evento,elemento.value);
		}
		else{
			if(ValueElemento.length<=12){
				var TeclaPulsada=new String(String.fromCharCode(Valor));
				if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
				else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
				
			}
			return false;
			
		}
	}
}
function RFCFisica(Evento,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	var Respuesta=true;
	var ValueElemento=new String(elemento.value);
	//alert(ValueElemento.length);
	if(Valor==0 || Valor==8) return true;
	if(ValueElemento.length<=3){
		if((Valor >= 65 && Valor <= 90)||(Valor >= 97 && Valor <= 122)|| Valor==241 || Valor==209 ){
			var TeclaPulsada=new String(String.fromCharCode(Valor));
			//if(Valor==192)TeclaPulsada='Ñ';
			if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
			else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			return false;
	    }
	    if(Valor==0) return true;
			else return false;
	}
	else{
		if(ValueElemento.length<=9){
			return SoloNumeros(Evento,elemento.value,elemento);
		}
		else{
			if(ValueElemento.length<=12){
				var TeclaPulsada=new String(String.fromCharCode(Valor));
				if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
				else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			}
			return false;	
		}
	}
}
function RFCAmbos(Evento,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	var Respuesta=true;
	var ValueElemento=new String(elemento.value);
	//alert(ValueElemento.length);
	if(Valor==0 || Valor==8) return true;
	if(ValueElemento.length<=3){
		if((Valor >= 65 && Valor <= 90)||(Valor >= 97 && Valor <= 122)|| Valor==241 || Valor==209 ){
			var TeclaPulsada=new String(String.fromCharCode(Valor));
			//if(Valor==192)TeclaPulsada='Ñ';
			if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
			else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			return false;
	    }
	    if(Valor==0 || EsNumero(String.fromCharCode(Valor))) return true;
		else return false;
	}
	else{
		if(ValueElemento.length<=9){
			return SoloNumeros(Evento,elemento.value,elemento);
		}
		else{
			if(ValueElemento.length<=12){
				var TeclaPulsada=new String(String.fromCharCode(Valor));
				if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
				else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			}
			return false;	
		}
	}
}

function CURP(Evento,elemento){
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
	var Respuesta=true;
	var ValueElemento=new String(elemento.value);
	if(Valor==0 || Valor==8) return true;
	//alert(ValueElemento.length);
	if(ValueElemento.length<=3){
		if((Valor >= 65 && Valor <= 90)||(Valor >= 97 && Valor <= 122)|| Valor==241 || Valor==209 ){
			var TeclaPulsada=new String(String.fromCharCode(Valor));
			//if(Valor==192)TeclaPulsada='Ñ';
			if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
			else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			return false;
	    }
	    else return false;
	}
	else{
		if(ValueElemento.length<=9){
			return SoloNumeros(Evento,elemento.value,elemento);
		}
		else if(ValueElemento.length==10){
			if(Valor==104 || Valor==109 || Valor==77 || Valor==72){
				var TeclaPulsada=new String(String.fromCharCode(Valor));
				elemento.value=elemento.value+TeclaPulsada.toUpperCase();
				return false;
			}
			else return false;
		}
		else{
			if(ValueElemento.length<=17){
				var TeclaPulsada=new String(String.fromCharCode(Valor));
				if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
				else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			}
			return false;	
		}
	}
}
function MaxLengthTextarea(elemento,etiqueta_cuantos){
	var MaxLength=elemento.getAttribute? parseInt(elemento.getAttribute("maxlength")) : ""
	var intRestan=elemento.value.length-MaxLength;
	if (elemento.getAttribute && elemento.value.length>MaxLength) elemento.value=elemento.value.substring(0,MaxLength);
	if(etiqueta_cuantos){
		var Etiqueta=(document.getElementById)? document.getElementById('desc_Maxlength'): eval("document.all['desc_Maxlength']");
		var strTexto=elemento.value.length+'/'+MaxLength;
		Etiqueta.innerHTML=strTexto;
	}
}
function txtMayusculas(Evento,elemento){
	var Valor='';
	if(navigator.userAgent.indexOf('MSIE')>=0) Valor=Evento.keyCode;
	else Valor=Evento.which;
    
  //alert (txt);
	var Respuesta=true;
	var ValueElemento=new String(elemento.value);
	if((Valor >= 65 && Valor <= 90)||(Valor >= 97 && Valor <= 122)|| Valor==241 || Valor==209 ){
			var TeclaPulsada=new String(String.fromCharCode(Valor));
			if(elemento.value=='') elemento.value=TeclaPulsada.toUpperCase();
			else elemento.value=elemento.value+TeclaPulsada.toUpperCase();
			return false;
    }
    else return true;
}
function txtCadenaMayusculas(elemento){
	var texto=elemento.value;
	elemento.value=texto.toUpperCase();
}
/*Genera una cadena con el formato de moneda funciona correctamente hasta el 999,999,999,999,999*/
function FormatoMoneda(Num,addDecimales,sep_decimales,sep_miles){ 
	var Redondeo=1;
	var strTemp="";
	var intNumeros="";
	var intValorTmp="";
	var valorNeg=false;
	if(sep_decimales==null)sep_decimales=".";
	if(sep_miles==null)sep_miles=",";
	for(var intPos=1;intPos<=addDecimales;intPos++){
		Redondeo+="0";
	}  
	valor = String (Math.round(Num * Redondeo) / Redondeo); 
	/*Verifica q el numero no sea negativo*/
	dot = valor.indexOf("-");
	if(dot!= -1){ 
		 valor=String(valor*-1);
		 valorNeg=true;
	}                                                                                                                                           
	dot = valor.indexOf(".");                                                                                                                                                                                                
	if(dot == -1){                                                                
		valor += ".0";                                                               
	}	                                                                            
	temp = valor.split("."); 
	/*Agrega el separador de miles si es necesario*/   
	if(temp[0].length>3){
		for(var intPos=temp[0].length-1;intPos>=0;intPos--){
			var strTemp=temp[0].substr(intPos,1);
			
			intNumeros++;
			if(intNumeros>3){
				intValorTmp=String(strTemp)+sep_miles+intValorTmp;
				intNumeros=1;
			}
			else intValorTmp=strTemp+String(intValorTmp);
		}
	    valor=String(intValorTmp)+sep_decimales+temp[1];	
	}
	/*Agrega Cero a la parte decimal si la cantidad de decimales no es igual a la solicitada*/                                                  
	addDecimals = addDecimales - temp[1].length;                                        
	for(i=1; i<= addDecimals; i++){                                               
		valor += "0";                                                                
	}                                                                            
	if(valorNeg)valor="-"+valor;//Era valor negativo                                                                          
	return valor;                                                        
}; 
function CargaDescripcion(Src){
	ajxCargaAsincrona(Src,'carga_info');
	return;
}                                                                            
function CargaInicio(forma,elementos){
	var formulario=document.forms[forma];
	if(elementos!=''){
		var arrElementos=elementos.split(',');
		for(intObj=0;intObj<arrElementos.length;intObj++){
			formulario.elements[arrElementos[intObj]].focus();
			formulario.elements[arrElementos[intObj]].select();
		}
	}
	/*Regresamos el foco al primer campo activo*/
	for(intObj=0;intObj<formulario.length;intObj++){
		if(formulario.elements[intObj].disabled==false && formulario.elements[intObj].type!='hidden' && formulario.elements[intObj].readOnly!=true && formulario.elements[intObj].className.toLowerCase()!='txtsololectura'){
			formulario.elements[intObj].focus();
			if(formulario.elements[intObj].type=='text') formulario.elements[intObj].select();
			return;
		} 
	}
}
function ObtenPosicionAbsoluta(element) {
  if (typeof element == "string")
    element = (document.getElementById)? document.getElementById(element): eval("document.all['"+element+"']");
    //alert(element);
  if (!element) return { top:0,left:0 };
  
  var y = 0;
  var x = 0;
  while (element.offsetParent) {
    x += element.offsetLeft;
    y += element.offsetTop;
    element = element.offsetParent;
  }
  return {top:y,left:x};
}        
function ObtenAnchoyAlto(element) {
  if (typeof element == "string")
    element = (document.getElementById)? document.getElementById(element): eval("document.all['"+element+"']");
    
  if (!element) return { width:0,height:0 };
  
  var w =  element.offsetWidth;;
  var h = element.offsetHeight;

  return {width:w,height:h};
}    
function esVisible(objeto){
	var obj= (document.getElementById)? document.getElementById(objeto) : eval("document.all['"+objeto+"']");
	if(obj.style.display=='') return true;
	else return false;
	
}       
function CargaPagina(pagina,contenedor){
	var frame= (document.getElementById)? document.getElementById(contenedor) : eval("document.all['"+contenedor+"']");
	frame.src=pagina;
}
/*acomoda un Select Multiple mostrando primero los seleccionados*/
function OrdenaSelectMultiple(idObj){
	var obj= (window.document.getElementById)? window.document.getElementById(idObj):eval("window.document.all['"+idObj+"']");
	var strSeleccionados='';
	var strNoSeleccionados='';
	var strText='';
	var strValue='';
	var intOptions=0;
	
	
	for(var intTmp=0;intTmp<obj.options.length;intTmp++){
		strText=obj.options[intTmp].text;
		strValue=obj.options[intTmp].value;
		if(obj.options[intTmp].selected){
			if(Trim(strSeleccionados)!="")strSeleccionados=strSeleccionados+',';
			strSeleccionados=strSeleccionados+strValue+'|'+strText;
		}
		else{
			if(Trim(strNoSeleccionados)!="")strNoSeleccionados=strNoSeleccionados+',';
			strNoSeleccionados=strNoSeleccionados+strValue+'|'+strText; 
		}
	}
	//Borra el contenido
	for(var intTmp=obj.options.length;intTmp>=0;intTmp--){
		obj.options[intTmp]=null;
	}
	//Generamos arreglos del contenido
	
	if(Trim(strSeleccionados)!='')strSeleccionados=strSeleccionados.split(',');
	if(Trim(strNoSeleccionados)!='')strNoSeleccionados=strNoSeleccionados.split(',');
	
	for(var intTmp=0;intTmp<strSeleccionados.length;intTmp++){
		var objOptions=new Option();
		var strTmp=strSeleccionados[intTmp].split('|');
		objOptions.value=strTmp[0];
		objOptions.text=strTmp[1];
		obj.options[intOptions]=objOptions;
		obj.options[intOptions].selected=true;
		intOptions++;
	}
	for(var intTmp=0;intTmp<strNoSeleccionados.length;intTmp++){
		var objOptions=new Option();
		var strTmp=strNoSeleccionados[intTmp].split('|');
		objOptions.value=strTmp[0];
		objOptions.text=strTmp[1];
		obj.options[intOptions]=objOptions;
		intOptions++;
	}
	
}    
function RedireccionaIframe(idFrame,destino){
	var Iframe=(document.getElementById) ? document.getElementById(idFrame) : eval("document.all['"+idFrame+"']");
	Iframe.src=destino;
}
function MostrarMsg(estaenpadre){
	if(estaenpadre==null || estaenpadre==false) elemento= (document.getElementById) ? document.getElementById('msg') : eval("document.all['msg']");
	else elemento= (parent.document.getElementById) ? parent.document.getElementById('msg') : eval("parent.document.all['msg']");
	if(elemento.style.visibility=='visible') elemento.style.visibility='hidden';
	else elemento.style.visibility='visible';
}                           
function EvalTipoArchivoUpload(Elemento,ElementoSubmit){
	var strExtensiones=Elemento.getAttribute("accept");
	var strArchivoExtension=Elemento.value;
	strArchivoExtension=(strArchivoExtension.substring(strArchivoExtension.lastIndexOf('.'))).toLowerCase();
	strExtensiones=strExtensiones.split('|');
	var blnPermitida=false;
	for(var intPos=0;intPos<strExtensiones.length;intPos++){
		if('.'+strExtensiones[intPos]==strArchivoExtension){
			blnPermitida=true;
			break;
		}
	}
	if(!blnPermitida){
		alert('Tipo de Archivo no valido. \n Solo se aceptan archivos del tipo: '+ strExtensiones.join());
		ElementoSubmit.disabled=true;
	}
	else ElementoSubmit.disabled=false;
}
function base64_encode(strCadena) {
   var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;
   do {
      chr1 = strCadena.charCodeAt(i++);
      chr2 = strCadena.charCodeAt(i++);
      chr3 = strCadena.charCodeAt(i++);
      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;
      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }
      output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 
      keyStr.charAt(enc3) + keyStr.charAt(enc4);   
   } while (i < strCadena.length);
   return output;
}

                                                                               
                                                                               
