String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//
function jFocus(lpVar){
	document.getElementById(lpVar).focus();
}
function jFocuz(lpVar){
	document.getElementById(lpVar).focus();
	document.getElementById(lpVar).select();
}
function jLen(lpVar){
	return lpVar.trim().length;
}
function gv(lpVar){
	return document.getElementById(lpVar).value;
}
function sv(lpVar,lpStr){
	document.getElementById(lpVar).value=lpStr;
}
function jVal(lpVar){
	if(jLen(lpVar)==0){
		return 0;
	}else{
		if(isNaN(lpVar)){
			return parseFloat("0");
		}else{
			return parseFloat(lpVar);
		}
	}
}
function GetTxt(lpVar){
	return document.getElementById(lpVar).value;
}
//
function GetFec(){
	var today = new Date(); 
	var dd = today.getDate(); 
	var mm = today.getMonth()+1;
	var yyyy = today.getFullYear();
	yyyy=yyyy-2000;
	if(dd<10){dd='0'+dd} 
	if(mm<10){mm='0'+mm} 
	return mm+'-'+dd+'-'+yyyy;
}
function jL(lpVar){	
	return lpVar.trim().length;
}
function GetFEC(){
	var today = new Date(); 
	var dd = today.getDate(); 
	var mm = today.getMonth()+1;
	var yyyy = today.getFullYear();
	yyyy=yyyy-2000;
	if(dd<10){dd='0'+dd} 
	if(mm<10){mm='0'+mm} 
	return dd+'-'+mm+'-'+yyyy;
}

function fKillerEx(lpIndex){
	var Rpta = confirm("Esta seguro que desea eliminar?")		
	if (Rpta==false){
		return;
	}
	document.getElementById("TxtRegID").value=lpIndex;
	document.getElementById("TxtAc").value="KILLER";
	document.getElementById("Frm").submit();
}
function CreateAJAX(){
        var xmlhttp=false;
        try {
               xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
               try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (E) {
                       xmlhttp = false;
               }
        } 
        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
               xmlhttp = new XMLHttpRequest();
        }
        return xmlhttp;
}
function GetHora(){
	var f= new Date();
	h=f.getHours()*3600;
	m=f.getMinutes()*60;
	s=f.getSeconds();
	return h+m+s;
}

//**************************************************************************
function GetKey(){
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	return k;
}
//**************************************************************************
function OpenWin(url,ancho,alto)
{
var xPos=(screen.width-ancho)/2; 
var yPos=(screen.height-alto)/2;
window.open(url, 1, 'location=no, directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, Left=' + xPos + ', Top=' + yPos + ',width=' + ancho + ',height=' + alto + '');       
}
function trimm(myString)
{
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
}
//**************************************************************************
function formato_numero(numero, decimales, separador_decimal, separador_miles){ 
    numero=parseFloat(numero);
if(isNaN(numero)){
return "";
}
if(decimales!==undefined){     
numero=numero.toFixed(decimales);
}
separador_decimal=".";
numero=numero.toString().replace(".", separador_decimal!==undefined ? 	separador_decimal : ",");
return numero;
}

function ff(numero, decimales, separador_decimal, separador_miles){ 
    numero=parseFloat(numero);
if(isNaN(numero)){
return "";
}
if(decimales!==undefined){     
numero=numero.toFixed(decimales);
}
separador_decimal=".";
numero=numero.toString().replace(".", separador_decimal!==undefined ? 	separador_decimal : ",");
return numero;
}
//**************************************************************************
function fSiguiente(){		
	document.getElementById("TxtAc").value="MSig";
	document.getElementById("Frm").submit();
}
function fAnterior(){
	document.getElementById("TxtAc").value="MAnt";
	document.getElementById("Frm").submit();
}
function fPrimero(){
	document.getElementById("TxtAc").value="MPri";
	document.getElementById("Frm").submit();
}
function fUltimo(){
	document.getElementById("TxtAc").value="MUlt";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fVolver(StrUrl){
	window.location = StrUrl;
}
function fBuscar(StrUrl){
	window.location = StrUrl;
}
//**************************************************************************
function fActivar(reg){	
	document.getElementById("TxtId").value=reg;	
	document.getElementById("TxtAc").value="AR";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fFiltrar(){	
	document.getElementById("TxtAc").value="F";
	document.getElementById("Frm").submit();
}
function fPDF(){
	document.getElementById("TxtAc").value="PDF";
	document.getElementById("Frm").submit();
}
function ffGuardar(){
	document.getElementById("TxtAc").value="G";
	document.getElementById("Frm").submit();
}
function fEnviarPDF(){
	var Rpta = confirm("Esta seguro que desea enviar un email?")		
	if (Rpta==true){
		document.getElementById("TxtAc").value="ENV_PDF";
		document.getElementById("Frm").submit();
	}
}
function fEliminar(){
	var Rpta = confirm("Esta seguro que desea eliminar?")		
	if (Rpta==true){
		document.getElementById("TxtAc").value="E";
		document.getElementById("Frm").submit();
	}
}
function fAnular(){
	var Rpta = confirm("Esta seguro que desea anular?")		
	if (Rpta==true){
		document.getElementById("TxtAc").value="A";
		document.getElementById("Frm").submit();
	}
}
function fValidar(){
	var Rpta = confirm("Esta seguro que desea validar?")		
	if (Rpta==true){
		document.getElementById("TxtAc").value="VAL";
		document.getElementById("Frm").submit();
	}
}

//------------------------------------------
function soloLetras(){
	 $(".lt").keydown(function (event) {
 	    var O=document.activeElement;var ti=O.tabIndex;	
		var k;k=(document.all) ? event.keyCode :event.which; 
		if(k==219){return false;
		}else{
			if(k==13){					
				GetNext(ti);return true;
			}
			return true;
		}
	});
}
function soloFechas(){
	 $(".fe").mask("99-99-99");
	 $(".fe").keydown(function (event) {
 	    var O=document.activeElement;var ti=O.tabIndex;	
		var k;k=(document.all) ? event.keyCode :event.which; 
		if(k==219){return false;
		}else{
			if(k==13){
				GetNext(ti);return true;
			}
			return true;
		}
	});
}
function FrmCls(lpF){
	frm = document.getElementById("Frm");
	if (!frm) return;var mayor=0;	
	for(i=0; i<frm.elements.length; i++){
		var t=frm.elements[i].type;
		if (  t=="text" || t=="password" ){			
			frm.elements[i].value="";
		}
		if ( t=="select-one"  ){			
			frm.elements[i].selectedIndex=0;
		}
		if ( t=="checkbox" ){
			frm.elements[i].checked=false;
		}		
	}	
	if(jLen(lpF)>0){
		jFocus(lpF);
	}
}
function GetNext(ti){
	frm = document.getElementById("Frm");
	if (!frm) return;var mayor=0;	
	for(i=0; i<frm.elements.length; i++){
		var t=frm.elements[i].type;
		if ( t=="checkbox" || t=="text" || t=="button" || t=="select-one" || t=="password" ){			
			if(frm.elements[i].disabled==false){					
				if(frm.elements[i].tabIndex==ti+1){
					frm.elements[i].focus();return;
				}else{
					mayor=frm.elements[i].tabIndex;
				}				
			}
		}		
	}
	if(mayor==ti)return;
}
//
function soloNumeros(){
	 $(".nd").keydown(function (event) { 
	 	var O=document.activeElement;var k;var v;v=trimm(O.value);
		var ti=O.tabIndex;		
		k=(document.all) ? event.keyCode :event.which;	
		if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) 
			|| k==110 || k==37 || k==39  || k==36 || k==35 || k==190){
			if(k==110 || k==190){
				if(v.length==0 ){
					return false;
				}else{
					if(v.indexOf(".")!=-1){
						return false;
					}
				}
			}				
			return true;
		}else{
			if(k==46 || k==9){
				return true;
			}
			if(k==13){
				GetNext(ti);return true;
			}else{
				return false;
			}
		}
		//
	});
}
function soloEnteros(){
	 $(".ne").keydown(function (event) { 
	 	var O=document.activeElement;var k;var v;v=trimm(O.value);
		var ti=O.tabIndex;
		k=(document.all) ? event.keyCode :event.which;
		if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) || 
			k==37 || k==39 || k==46 || k==36 || k==35){
			return true;
		}else{
			if(k==46 || k==9){
				return true;
			}
			if(k==13){
				GetNext(ti);return true;
			}else{
				return false;
			}
		}
	});
}
function Inicializar(){
   soloLetras();
   soloNumeros();
   soloEnteros();
   soloFechas();
}

//------------------------------------------
/**************************************************************************
	onKeyDown="return SoloTexto(event);" 
***************************************************************************/
function SoloTexto(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		return true;
	}
}
function SoloTextoEx(e,Sig){	
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
			document.getElementById(Sig).focus();
			return true;
		}
		return true;
	}
}
function SoloTextoExF(e,Sig){	
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
			document.getElementById("TxtAc").value="F";
			document.getElementById("Frm").submit();
			return true;
		}
		return true;
	}
}
function SoloTextoEx2(e,Sig,Sig2){	
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
			if(document.getElementById(Sig).readOnly==false){
			document.getElementById(Sig).focus();
			}else{
			document.getElementById(Sig2).focus();
			}
			return true;
		}
		return true;
	}
}
/**************************************************************************
	onKeyDown="return SoloNum(this, event);"
***************************************************************************/
function SoloNum1(O,e){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;	
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) 
		|| k==110 || k==37 || k==39  || k==36 || k==35 || k==190){
		if(k==110 || k==190){
			if(v.length==0 ){
				return false;
			}else{
				if(v.indexOf(".")!=-1){
					return false;
				}
			}
		}				
		return true;
	}else{
		if(k==46 || k==9){
			return true;
		}
		if(k==13){
			return true;
		}else{
			return false;
		}
	}
}
function SoloNum(O,e,Sig){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;	
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) 
		|| k==110 || k==37 || k==39  || k==36 || k==35 || k==190){
		if(k==110 || k==190){
			if(v.length==0 ){
				return false;
			}else{
				if(v.indexOf(".")!=-1){
					return false;
				}
			}
		}				
		return true;
	}else{
		if(k==46 || k==9){
			return true;
		}
		if(k==13){
			document.getElementById(Sig).focus();
			return true;
		}else{
			return false;
		}
	}
}
//**************************************************************************
function SoloFec(O,e,Sig){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) 
		||  k==37 || k==39 || k==109 || k==36 || k==35){
		if(k==109){
			if(v.length==0 ){
				return false;
			}else{
				p1=v.indexOf("-");
				p2=v.lastIndexOf("-");
				if(p1==-1 && p2==-1){
					return true;
				}
				if(p1==p2){
					return true;
				}
				if(p1!=p2){
					return false;
				}
				if(v.indexOf("-")!=-1){
					return false;
				}
			}
		}
		return true;
	}else{
		if(k==46 || k==9){
			return true;
		}
		if(k==13){
			document.getElementById(Sig).focus();
			return true;
		}else{
			return false;
		}
	}
}
/**************************************************************************
	onKeyDown="return SoloEnteros(this, event);"
***************************************************************************/
function SoloEnteros(O,e){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) || k==37 || k==39){
		return true;
	}else{
		if(k==13){
			return true;
		}else{
			return false;
		}
	}
}
//**************************************************************************
function SoloEnterosEx(O,e,Sig){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) || 
		k==37 || k==39 || k==46 || k==36 || k==35 || k==9){
		return true;
	}else{
		if(k==13){
			document.getElementById(Sig).focus();
			return true;
		}else{
			return false;
		}
	}
}
//**************************************************************************
function SoloEnterosEx2(O,e,Sig,Sig2){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) || 
		k==37 || k==39 || k==46 || k==36 || k==35){
		return true;
	}else{
		if(k==13){
			if(document.getElementById(Sig).readOnly==false){
				document.getElementById(Sig).focus();
			}else{
				document.getElementById(Sig2).focus();
			}
			return true;
		}else{
			return false;
		}
	}
}
//**************************************************************************
function EsFecha(fecha){
	var dtCh= "-";
	var minYear=1900;
	var maxYear=2100;
	function isInteger(s){
		var i;
		for (i = 0; i < s.length; i++){
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		return true;
	}
	function stripCharsInBag(s, bag){
		var i;
		var returnString = "";
		for (i = 0; i < s.length; i++){
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}
	function daysInFebruary (year){
		return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
	function DaysArray(n) {
		for (var i = 1; i <= n; i++) {
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
		}
		return this
	}
	function isDate(dtStr){
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strDay=dtStr.substring(0,pos1)
		var strMonth=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		strYear=String(parseInt(strYear)+2000)
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)		
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}		
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr) +2000
		
		if (pos1==-1 || pos2==-1){
			return false
		}
		if (strMonth.length<1 || month<1 || month>12){
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			return false
		}
		return true
	}
	if(isDate(fecha)){
		return true;
	}else{
		return false;
	}
}
function selecciona_value(objInput) { 
    var valor_input = objInput.value; 
    var longitud = valor_input.length; 

    if (objInput.setSelectionRange) { 
        objInput.focus(); 
        objInput.setSelectionRange (0, longitud); 
    } 
    else if (objInput.createTextRange) { 
        var range = objInput.createTextRange() ; 
        range.collapse(true); 
        range.moveEnd('character', longitud); 
        range.moveStart('character', 0); 
        range.select(); 
    } 
} 


function fRound(numero) {
	var original = parseFloat(numero);
	var result = Math.round(original * 100) / 100;
	return result;
}
function DG(lpStrDAT,lpIndex){
	var ip=lpStrDAT.indexOf("|");
	var A=lpStrDAT.substring(0,ip);	
	var B=lpStrDAT.substring(ip+1,jLen(lpStrDAT));
	if(lpIndex==1){
		return A;
	}else{
		return B;
	}
}
function CBO_CLS(lpCbo){
	var Cbo=document.getElementById(lpCbo);
	Cbo.options.length = 0;
}
function CBO_ADD(lpCbo,lpItem){
	var Cbo=document.getElementById(lpCbo);
	var i=Cbo.options.length;
	Cbo.options[i]= new Option (lpItem, lpItem);
}
function CBO_FILL(lpCbo,lpArr){
	var Cbo=document.getElementById(lpCbo);
	Cbo.options.length = 0;
	var Arr=lpArr.split("|");
	for(i=0;i<Arr.length;i++){
		Cbo.options[i]= new Option (Arr[i], Arr[i]);
	}
	if(Arr.length>0)Cbo.selectedIndex=0;
}
function AJ(URL){
	ajax=CreateAJAX();
	ajax.open("GET",URL,false);	
	ajax.send(null);
	var StrHtml=ajax.responseText;
	return StrHtml.trim();
}

function fFecServer(Lugar){
	var FEC_SERVER=document.getElementById("FEC_SERVER").value;
	document.getElementById(Lugar).value=FEC_SERVER;
	document.getElementById(Lugar).focus();
}
function snNum(O,e,Sig){	
	var k;
	var v;
	v=trimm(O.value);
	k=(document.all) ? e.keyCode :e.which;
	if((k>=48 && k<=57) || k==8 || (k>=96 && k<=105) || 
		k==37 || k==39 || k==46 || k==36 || k==35 || k==9){
		return true;
	}else{
		if(k==13){
			document.getElementById(Sig).focus();
			return true;
		}else{
			return false;
		}
	}
}
function KEY(e){
	var k=(document.all) ? e.keyCode :e.which;
	return k;
}
function _S(O){
	var s=O.value;
	s=s.trim()
	if(jL(s)==1)s="000"+s;
	if(jL(s)==2)s="00"+s;
	if(jL(s)==3)s="0"+s;
	O.value=s;
}
function _N(O){
	var s=O.value;
	s=s.trim()
	if(jL(s)==1)s="00000"+s;
	if(jL(s)==2)s="0000"+s;
	if(jL(s)==3)s="000"+s;
	if(jL(s)==4)s="00"+s;
	if(jL(s)==5)s="0"+s;
	O.value=s;
}
function SM(Cmd){
	if(Cmd!=undefined){
		document.getElementById("TxtAc").value=Cmd;
	}
	document.getElementById("Frm").submit();
}