String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//
function fEditar(lpIndex){
	var hw=document.getElementById("TxtHW").value;
	OpenWin("ventas_editar.php?I="+lpIndex+"&H="+hw,570,220);	
}
function CboTar_KeyPress(e){
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
			if(document.getElementById("CboBancos").disabled==false){
				document.getElementById("CboBancos").focus();
			}
		}
	}
}
//
function fLoad(){
	document.getElementById("TxtAc").value="UP";
	document.getElementById("Frm").submit();
}
//
function CboBan_KeyPress(e){
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
				document.getElementById("TxtOpe").focus();
		}
	}
}
//
function ChN_BAR_OnChange(){
	document.getElementById('TxtHora').value=0;
	jF("TxtCod");
}
//
function TxtCod_OnKeyUp(){
	if(document.getElementById("ChN_BAR").checked==false){
		document.getElementById('TxtHora').value=GetHora();
	}else{
		document.getElementById('TxtHora').value=0;
	}
}
function LSoloTextoEx(e,Sig){	
	var k;
	k=(document.all) ? e.keyCode :e.which; 
	if(k==219){
		return false;
	}else{
		if(k==13){
			if(document.getElementById("ChN_BAR").checked==false){
				document.getElementById(Sig).focus();
			}else{
				if(jLen(document.getElementById("TxtCod").value)==0){
					document.getElementById(Sig).focus();
				}else{
					var R=AjBuscar();
					if(R=="NR"){						
						alert("Codigo de producto no registrado");
						jFocus("TxtCod");
						document.getElementById("TxtCod").select();
					}else{
						document.getElementById("DivDatosProd").innerHTML=R;
						SetValores();
						if(document.getElementById("ChN_AUT").checked==true){
							document.getElementById("CmdAdd").click();
							
						}
					}
				}
			}
			return true;
		}
		return true;
	}
}
//


//**************************************************************************
function fFiltrar(){
	document.getElementById("TxtAc").value="F";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function AutoNumeracion(estado){
	
}
//**************************************************************************
function CalcularIMPORTE(){
	var Importe=document.getElementById("T_Importe").value;
	var stt=0;
	var igv=0;
	var tot=0;	
	var uno=0;
	if(Importe.trim().length==0) Importe="0";
	Importe=parseFloat(Importe);
	/*
	if(document.getElementById("ChN_INC").checked){
		stt=Importe;
		igv=stt * 0.18;
		igv=igv.toFixed(2);
		tot=parseFloat(stt) + parseFloat(igv);
	}else{
	*/
		uno=Importe / 118;
		//uno=uno.toFixed(2);
		igv=uno * 18;
		igv=igv.toFixed(2);
		stt=parseFloat(Importe) - parseFloat(igv);
		tot=parseFloat(stt)+parseFloat(igv);
	/*
	}
	*/
	document.getElementById("T_ST").value=formato_numero(stt,2,".");
	document.getElementById("T_IG").value=formato_numero(igv,2,".");
	document.getElementById("T_TO").value=formato_numero(tot,2,".");
	VUELTO();	
}
function fCls(){
	sv("TxtIdCliente","0");
	svv("TxtCliente,TxtDIR,TxtRuc,TxtTel,TxtEma,TxtDni");
	jF("TxtRuc");
}
//**************************************************************************
function fImporte(){
	var Pre=gv("TxtPre");
	var Can=gv("TxtCant");
	var Importe=0;
	Pre=jVal(Pre);
	Can=jVal(Can);
	Importe=Pre * Can;
	Importe=Importe.toFixed(2);
	document.getElementById("TxtImp").value=Importe;
}
//**************************************************************************
function fKiller(lpIndex){
	document.getElementById("Pro_TxtId").value=lpIndex;
	document.getElementById("TxtAc").value="KILLER";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fGetTabla(){	
//++
var Cod=gv("TxtCod");
var Des=gv("TxtDes");
var Mar="";
var Alm=gv("CboAlm");
Cod=Cod.replace("+", "@");
Des=Des.replace("+", "@");
//++
if((jL(Des) + jL(Cod))>2 ){	
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	ajax=CreateAJAX();
	var StrU="ajax_funciones.php?Cmd=VENTAS_PROD_FILTRAR&TxtPar="+Des+"&TxtPar2="+Alm+"&TxtPar3="+Mar+"&TxtPar4="+Cod;
	ajax.open("GET",StrU);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {
					var StrDatos=ajax.responseText;
					if(StrDatos.trim().length>0){			  
		   
					   StrDatos = replaceAll(StrDatos,"@", "<tr class=\"zz\" ");
					   StrDatos = replaceAll(StrDatos,"#", "</tr>");
					   StrDatos = replaceAll(StrDatos,";", "</td>");
					   StrDatos = replaceAll(StrDatos,"%", "<td>");
					   StrDatos = replaceAll(StrDatos,":", "ondblclick=");
						
						DivDatos.innerHTML = StrDatos;
			  			DivCaption.style.visibility="visible";
			   			DivDatos.style.visibility="visible";	
			   			document.getElementById("TAB_AJAX").scrollTop=0;
						
						PINTAR_ZZ();						
									   
					}else{
						DivCaption.style.visibility="hidden";
						DivDatos.style.visibility="hidden";	
					}
		   }
	}
	ajax.send(null);
}
//
function fGetTabla2(){	
	var Cli=gv("TxtCliente");
	if(jL(Cli)>0){	
		DivDatos = ge("TX_D");
		DivCaption = ge("TX_C");
		ajax=CreateAJAX();
		var StrU="aj.php?Cmd=02&P1="+Cli;
		ajax.open("GET",StrU);
			ajax.onreadystatechange=function() {	
			   if (ajax.readyState==4) {
					var StrDatos=ajax.responseText;
					if(jL(StrDatos)>0){			 
					   DivDatos.innerHTML = StrDatos;
					   DivCaption.style.visibility="visible";
					   DivDatos.style.visibility="visible";	
					   document.getElementById("TX_D").scrollTop=0;	
					   //
					   PINTAR();
					   //				  
					}else{
						DivCaption.style.visibility="hidden";
						DivDatos.style.visibility="hidden";	
					}
			   }
		}
	ajax.send(null);
	}
}
//
function PINTAR_ZZ(){
	//alert("OK1");
	$('.zz').focus(function() {	
		this.style.backgroundColor="#FFCC00";
	}).blur(function() {
	   this.style.backgroundColor="white";
	});
	$('.zz').keydown(function(e) {
		if(e.which == 40) {
			var r=this.id;
			r=r.replace("z","");
			r=parseInt(r)+1;
			try {
				document.getElementById("z"+r).focus();
				e.preventDefault();
			} catch (e) {
				
			}
		}
		if(e.which == 38) {
			var r=this.id;
			r=r.replace("z","");
			r=parseInt(r)-1;
			if(r==0){
				r=1;
			}
			document.getElementById("z"+r).focus();
			e.preventDefault();
		}
		if(e.which == 13) {
			this.ondblclick();
			e.preventDefault();
		}
		if(e.which == 27) {
			CerrarDIV();			
			e.preventDefault();
			sv("TxtHora","0");
		}
	});	
	//alert("OK2");
}
//
function PINTAR(){
	$('.xz').focus(function() {	
		this.style.backgroundColor="#FFCC00";
	}).blur(function() {
	   this.style.backgroundColor="white";
	});
	$('.xz').keydown(function(e) {
		if(e.which == 40) {
			var r=this.id;
			r=r.replace("c","");
			r=parseInt(r)+1;
			try {
			document.getElementById("c"+r).focus();
			e.preventDefault();
			} catch (e) {
				
			}
		}
		if(e.which == 38) {
			var r=this.id;
			r=r.replace("c","");
			r=parseInt(r)-1;
			if(r==0){
				r=1;
			}
			document.getElementById("c"+r).focus();
			e.preventDefault();
		}
		if(e.which == 13) {
			this.ondblclick();
			e.preventDefault();
		}
		if(e.which == 27) {
			CerrarDIV2();
			e.preventDefault();
			sv("TxtHoraC","0");
		}
	});
	
	//alert("OK");
}
//
}
function CerrarDIV(){
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	DivCaption.style.visibility="hidden";
	DivDatos.style.visibility="hidden";	
	document.getElementById("TxtDes").focus();
}
//**************************************************************************
function PP(Pre){
	var Mon=document.getElementById("CboMon").value;
	var Tca=document.getElementById("TxtTC").value;
	Mon=Mon.trim();Pre=Pre.trim();Tca=Tca.trim();
	if(Mon.length==0)Mon="SOLES";
	if(Pre.length==0)Pre="0";
	if(Tca.length==0)Tca="1";
	Pre=parseFloat(Pre);Tca=parseFloat(Tca);
	if(Mon=="DOLARES"){
		Pre=Pre / Tca;Pre=Pre.toFixed(2);		
	}	
	return Pre;
}
//
function AjBuscar(){
	var cod=document.getElementById("TxtCod").value;
	cod=cod.replace("+", "@");		
	ajax=CreateAJAX();
	var Z="";
	Z="ajbar.php?C=V&P1="+cod;
	//alert(Z);
	ajax.open("GET",Z,false);	
	ajax.send(null);
	var StrHtml=ajax.responseText;
	return StrHtml.trim();
}
//
function z(lpStrId){
	//if(lpStrId.trim().length>0){
	if(lpStrId>0){
	var Alm=document.getElementById("CboAlm").value;
	DivDatos = document.getElementById("DivDatosProd");
	ajax=CreateAJAX();
	var URL="ajax_funciones.php?Cmd="+
	        "VEN_GET_PROD_DATOS_X_ID&TxtPar="+lpStrId+"&TxtPar2="+Alm;
	ajax.open("GET", URL);	
	ajax.onreadystatechange=function() {
	   if (ajax.readyState==4) {			  
		   DivDatos.innerHTML = ajax.responseText
		   var Des=document.getElementById("Pro_TxtDes").value;
		   if(Des.trim().length==0){
			   svv("Pro_TxtId,Pro_TxtDes,Pro_TxtCod,Pro_TxtMarca,Pro_TxtPre");
			   svv("Pro_TxtPreM,TxtDes,TxtPre");			   
			   document.getElementById("TxtPreM").innerHTML="***";
			   svv("TxtCant,TxtImp,TxtCod");
			   alert("Codigo no registrado");
			   jF("TxtCod");
		   }else{
   			   SetValores();
		   }
		   DivDatos = document.getElementById("TAB_AJAX");
		   DivCaption = document.getElementById("TAB_CAPTION");
		   DivCaption.style.visibility="hidden";
		   DivDatos.style.visibility="hidden";
	   }
	}
    ajax.send(null);
	}
}



function SetValores(){
	sv("TxtCod",gv("Pro_TxtCod"));
	sv("TxtDes",gv("Pro_TxtDes"));
	sv("TxtPre",gv("TXT_PXU"));
	var s=gv("TXT_PXU");
	var z=gv("TXT_PXC");
	var o=gv("TXT_PXM");
	//
	document.getElementById("TxtPreM").innerHTML="<b>"+s+"</b>";
	document.getElementById("TxtPreC").innerHTML="<b>"+z+"</b>";
	document.getElementById("TxtSTOCK").innerHTML=o;
	sv("TxtCant","1");
	sv("TxtImp",gv("TxtPre"));
	jF("TxtCant");
}
//**************************************************************************
function fGetProdDatos(lpStrCod){
	if(lpStrCod.trim().length>0){
	DivDatos = document.getElementById("DivDatosProd");
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=VEN_GET_PROD_DATOS&TxtPar="+lpStrCod);	
	ajax.onreadystatechange=function() {
	   if (ajax.readyState==4) {			  
		   DivDatos.innerHTML = ajax.responseText
		   var Des=document.getElementById("Pro_TxtDes").value;
		   if(Des.trim().length==0){
			document.getElementById("Pro_TxtId").value="";
			document.getElementById("Pro_TxtDes").value="";
			document.getElementById("Pro_TxtMarca").value="";
			document.getElementById("Pro_TxtPreM").value="";
			document.getElementById("TxtDes").value="";
			document.getElementById("TxtPre").value="";
			document.getElementById("TxtPreM").innerHTML="***";
			document.getElementById("TxtCant").value="";
			document.getElementById("TxtImp").value="";
			document.getElementById("TxtCod").value="";
			//document.getElementById("TxtMarca").value="";
			alert("Codigo no registrado");
			document.getElementById("TxtCod").focus();
		   }else{
			//document.getElementById("TxtMarca").value=document.getElementById("Pro_TxtMarca").value;
			document.getElementById("TxtDes").value=document.getElementById("Pro_TxtDes").value;
			document.getElementById("TxtPre").value=PP(document.getElementById("Pro_TxtPre").value);
			document.getElementById("TxtPreM").innerHTML=PP(document.getElementById("Pro_TxtPreM").value);
			document.getElementById("TxtCant").value="1";
			document.getElementById("TxtImp").value=document.getElementById("TxtPre").value;
			document.getElementById("TxtPre").focus();
		   }
	   }
	}
    ajax.send(null);
	}
}
//**************************************************************************
function fGetRuc(lpStrPro,Obj){
	var StrProveedor=lpStrPro;
	ajax=CreateAJAX();
	ajax.open("GET", "ajax_funciones.php?Cmd=GET_RUC&TxtPar="+StrProveedor);	
	ajax.onreadystatechange=function() {
		   if (ajax.readyState==4) {			   	   
				   document.getElementById(Obj).value=ajax.responseText;
				   Obj=Obj+"_";
				   document.getElementById(Obj).value=ajax.responseText;
		   }
	}
    ajax.send(null);
}
//**************************************************************************
function fGetProveedor(lpStrRuc,Obj){
	var StrRucH=document.getElementById("TxtRuc_").value;
	var StrRuc=lpStrRuc;
	if(StrRuc!=StrRucH){
		ajax=CreateAJAX();
		ajax.open("GET", "ajax_funciones.php?Cmd=GET_PROVEEDOR&TxtPar="+StrRuc);	
		ajax.onreadystatechange=function() {
			   if (ajax.readyState==4) {
					   var StrPro=ajax.responseText;
					   if(StrPro.trim().length==0){
						   	alert("Numero de ruc no registrado");
						   	document.getElementById(Obj).value="";
						   	document.getElementById(Obj).focus();
					   }else{
							document.getElementById(Obj).value=StrPro;
					   }
			   }
		}
		ajax.send(null);
	}

}
//**************************************************************************
function fCancelarPHP(){	
	document.getElementById("TxtAc").value="C";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fCargar(){
	var A=document.getElementById("CboTemp").value;
	var B=document.getElementById("TxtTemp").value;
	if(A.trim().length==0){
		alert("Seleccione el comprobante correspondiente");
		document.getElementById("CboTemp").focus();
		return;
	}
	if(B.trim().length==0){
		alert("Ingrese la serie/numero correspondiente");
		document.getElementById("TxtTemp").focus();
		return;
	}
	document.getElementById("TxtAc").value="LOAD";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fAgregar(){
	var sa=jVal(document.getElementById("TxtSTOCK").innerHTML);
	var Pro_Id=gv("Pro_TxtId");
	var Pro_Cod=gv("Pro_TxtCod");
	var Pro_Des=gv("Pro_TxtDes");
	//
	var Cod=gv("TxtCod");
	var Des=gv("TxtDes");
	var Pre=gv("TxtPre");
	var PreM=document.getElementById("TxtPreM").innerHTML;
	var Can=jVal(gv("TxtCant"));
	//	
	Pro_Id=Pro_Id.trim().toUpperCase();
	Pro_Cod=Pro_Cod.trim().toUpperCase();
	Pro_Des=Pro_Des.trim().toUpperCase();
	
	Cod=Cod.trim().toUpperCase();
	Des=Des.trim().toUpperCase();
	
	if(Cod!=Pro_Cod){
		alert("El codigo del producto ha sido alterado");
		document.getElementById("TxtCod").focus();
		return;
	}
	if(Des!=Pro_Des){
		alert("La descripcion del producto ha sido alterada");
		document.getElementById("TxtDes").focus();
		return;
	}
	//
	Pre=Pre.trim();
	PreM=PreM.trim();
	if(jL(Pre)==0){
		alert("Ingrese el precio de venta");
		document.getElementById("TxtPre").focus();
		return;
	}
	
	Pre=jVal(Pre);
	PreM=jVal(PreM);
	if(PreM>Pre){
		var Rpta = confirm("El precio de venta ES MENOR al precio "+
						  "de venta minimo,¿Aun asi desea continuar?")		
		if (Rpta==false){
			document.getElementById("TxtPre").focus();
			return;
		}
	}
	if(Can>sa){
		return AF("Stock insuficiente, ingrese una "+
				  "cantidad igual o menor al stock actual","TxtCant");
	}
	//
	SM("ADD");
}
//**************************************************************************
function fGuardar(){
	var Alm=gv("CboAlm");
	var Fec=gv("TxtFec");
	var Cli=gv("TxtCliente");
	var Com=gv("CboCom");
	var Num=gv("TxtNum");
	var Ruc=gv("TxtRuc");
	var Ser=gv("TxtSer");
	var Tdp=gv("CboTdp");
	var Ban=gv("CboBancos");
	var Pagar=gv("TxtPagarCon");
	var Ope=gv("TxtOpe");
	//
	if(jL(Alm)==0){
		return !AF("Seleccione un almacen","CboAlm");
	}
	if(jL(Fec)==0){
		alert("Ingrese una fecha");
		document.getElementById("TxtFec").focus();
		return;
	}
	if(EsFecha(Fec)==false){
		alert("Fecha no valida, la fecha debe ser ingresada segun el formato");
		document.getElementById("TxtFec").focus();
		return;
	}	
	if(jL(Com)==0){
		alert("Seleccione un comprobante");
		document.getElementById("CboCom").focus();
		return;
	}
	if(document.getElementById("ChN_AUTO").checked==false){
		if(jL(Ser)==0){
			alert("Ingrese la serie del comprobante.");
			document.getElementById("TxtSer").focus();
			return;
		}
		if(jL(Num)==0){
			alert("Ingrese el numero de comprobante");
			document.getElementById("TxtNum").focus();
			return;
		}
	}		
	if(Tdp=="CONTADO"){		
		TOT=parseFloat(document.getElementById("T_TO").value);
		if(Pagar==0){
			//document.getElementById("TxtPagarCon").value=TOT;
			//alert("Ingrese un monto en *PAGAR CON*");
			document.getElementById("TxtPagarCon").value=TOT;
			//return;
		}		
		Pagar=parseFloat(document.getElementById("TxtPagarCon").value);
	
		if(Pagar<TOT){
			alert("El monto a pagar debe ser mayor o igual al TOTAL");
			document.getElementById("TxtPagarCon").focus();
			return;
		}
	}
	if(Tdp=="TARJETA"){		
		tar=document.getElementById("CboTar").value;
		if(jL(Cli)==0){
			alert("Seleccione el cliente");
			jFocus("CmdSel");
			return;
		}
		if(jL(tar)==0){
			alert("Seleccione la tarjeta correspondiente");
			document.getElementById("CboTar").focus();
			return;
		}
		ban=document.getElementById("CboBancos").value;
		if(jL(ban)==0){
			alert("Seleccione el banco correspondiente");
			document.getElementById("CboBancos").focus();
			return;
		}
	}
	if(Tdp=="DEPOSITO"){	
		if(jL(Cli)==0){
			alert("Seleccione el cliente");
			jFocus("CmdSel");
			return;
		}
		ban=document.getElementById("CboBancos").value;
		if(jL(ban)==0){
			alert("Seleccione el banco correspondiente");
			document.getElementById("CboBancos").focus();
			return;
		}
		if(jL(Ope)==0){
			alert("Ingrese el numero de operacion");
			jF("TxtOpe");
			return;
		}
	}
	if(Tdp=="CREDITO"){
		if(jLen(Cli)==0){
			alert("Seleccione el cliente");
			jFocus("CmdSel");
			return;
		}

	}
	if(Com=="FACTURA"){
		if(jL(Ruc)==0){
		alert("Seleccione un cliente que tenga ruc");
		document.getElementById("TxtRuc").focus();
		return;
		}
	}
	if(document.getElementById("CmdG").value=="Guardar"){
		var Rpta = confirm("Esta seguro que desea Guardar?")		
		if(Rpta==false){
			return;
		}
		var dat=AX("VEN_VAL_STOCK",gv("TxtHW"));
		var r=dat.split("|");
		if(r[1]=="OK"){
			SM("G");
		}else{
			if(r[1]=="MS"){
				alert(r[2]);
			}else{
				alert("Error de conexion");
			}
		}
	}else{
		var Rpta = confirm("Esta seguro que desea modificar?")		
		if(Rpta==false){
			return;
		}
		SM("M");
	}
	//document.getElementById("Frm").submit();
}
/**************************************************************************
	onkeypress="return pulsar(event);"
**************************************************************************/
function pulsar(e) { 	
	var tecla = (document.all) ? e.keyCode :e.which; 
	var Obj=event.srcElement.name;	
	if(Obj=="TxtNom"){
		if(tecla==13){			
			document.getElementById('CmdG').click();			
		}
	}	
	return (tecla!=13); 
} 
//**************************************************************************

function cCodUP(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;	
	if(k==40 || k==27 || k==13){
		
	}else{
		sv('TxtHora',GetHora());
	}
}
//**************************************************************************
function cDes(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	if(k==40){
		if(DivDatos.style.visibility!="hidden"){
			document.getElementById("z1").focus();
			event.preventDefault();			
		}
		return true;
	}
	if(k==13){
		jF("TxtPre");		
		DivCaption.style.visibility="hidden";
		DivDatos.style.visibility="hidden";	
		event.preventDefault();
		return true;
	}
}
function cDesUP(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;	
	if(k==40 || k==27 || k==13){
		
	}else{
		sv('TxtHora',GetHora());
	}
}
//**************************************************************************
function KeyRuc(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;

	if(k==13){
		var Ruc=gv("TxtRuc");
		if(jL(Ruc)==0){
			//jF("TxtDni");
		}else{
			GetCli(Ruc);			
		}
		event.preventDefault();
		return true;
	}
}

//**************************************************************************
function GetCli(Ruc){	
	Cad=AX("GET_CLIENTES",Ruc);
	//
	if(jL(Cad)>0){		
		S=Cad.split("|");
		Raz=S[0];
		Ruc=S[1];
		Dni=S[2];
		Dir=S[3];
		Tel=S[4];
		Ema=S[5];
		Con=S[6];
		ICl=S[7];
		//
		sv("TxtCliente",Raz);
		sv("TxtRuc",Ruc);
		sv("TxtDni",Dni);
		sv("TxtDIR",Dir);
		sv("TxtTel",Tel);
		sv("TxtEma",Ema);
		//sv("TxtCon",Con);
		sv("TxtIdCliente",ICl);
		//
		jF("TxtEma");		
	}else{
		//jF("TxtDni");
	}	
}
//**************************************************************************
function KeyDni(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;

	if(k==13){
		var Dni=gv("TxtDni");
		if(Dni.length==0){
			//jF("TxtCliente");			
		}else{		
			GetCli2(Dni);
		}
		event.preventDefault();
		return true;
	}
}
//**************************************************************************
function GetCli2(Dni){	
	Cad=AX("GET_CLIENTES2",Dni);
	//
	if(jL(Cad)>0){
		S=Cad.split("|");
		Raz=S[0];
		Ruc=S[1];
		Dni=S[2];
		Dir=S[3];
		Tel=S[4];
		Ema=S[5];
		Con=S[6];
		ICl=S[7];
		//
		sv("TxtCliente",Raz);
		sv("TxtRuc",Ruc);
		sv("TxtDni",Dni);
		sv("TxtDIR",Dir);
		sv("TxtTel",Tel);
		sv("TxtEma",Ema);
		//sv("TxtCon",Con);
		sv("TxtIdCliente",ICl);		
		//
		jF("TxtEma");		
	}else{
		//jF("TxtCliente");
	}	
}
//**************************************************************************
function fLimpiar(){
	sv("TxtCod","");
	sv("TxtDes","");
	sv("TxtPre","");
	sv("TxtCant","");
	sv("TxtImp","");
	document.getElementById("TxtPreC").innerHTML="0.00";
	document.getElementById("TxtPreM").innerHTML="0.00";
	document.getElementById("TxtSTOCK").innerHTML="0";
	jF("TxtCod");
}
//**************************************************************************
function f_CAL_IMP_TOT(){
	var tot=gv("T_TO");
	var env=gv("TxtEnv");
	var imp_tot=jVal(tot)+jVal(env);
	sv("TXT_TOT_IMP",imp_tot.toFixed(1));
	VUELTO();
}
//
function VUELTO(){	
	var StrTC=gv("TxtTC");
	var StrMon=gv("CboMon");
	var StrTot=gv("TXT_TOT_IMP");
	var StrPag=gv("TxtPagarCon");
	//
	StrTC=jVal(StrTC);
	StrTot=jVal(StrTot);
	StrPag=jVal(StrPag);
	if(StrMon=="DOLARES"){
		StrPag=StrPag * StrTC;
		StrPag=StrPag.toFixed(2);
	}
	var Vuelto=jVal("0");
	if(StrTot>StrPag){
		sv("TxtVuelto","0.0");
		return;
	}else{
		Vuelto=StrPag - StrTot;
	}
	Vuelto=Vuelto.toFixed(2);
	document.getElementById("TxtVuelto").value=Vuelto;
}
//
function TDP(){
	var StrTdp=document.getElementById("CboTdp").value;
	document.getElementById("TxtOpe").value="";
	document.getElementById("TxtOpe").readOnly=true;
	//Habilitar / Deshabilitar
	if(StrTdp=="CONTADO"){				
		document.getElementById("CboTar").value="";
		document.getElementById("CboTar").disabled=true;
		document.getElementById("CboBancos").value="";
		document.getElementById("CboBancos").disabled=true;
		document.getElementById("TxtPagarCon").disabled=false;
		document.getElementById("TxtPagarCon").value=document.getElementById("TXT_TOT_IMP").value;
		document.getElementById("CboMon").disabled=false;
		document.getElementById("CboMon").value="SOLES";							
	}
	if(StrTdp=="CREDITO"){
		document.getElementById("CboTar").value="";
		document.getElementById("CboTar").disabled=true;
		document.getElementById("CboBancos").value="";
		document.getElementById("CboBancos").disabled=true;
		document.getElementById("TxtPagarCon").disabled=true;
		document.getElementById("CboMon").disabled=true;
		document.getElementById("CboMon").value="SOLES";						
	}
	if(StrTdp=="TARJETA"){
		document.getElementById("CboTar").value="";
		document.getElementById("CboTar").disabled=false;
		document.getElementById("CboBancos").value="";
		document.getElementById("CboBancos").disabled=false;
		document.getElementById("TxtPagarCon").disabled=true;
		document.getElementById("TxtPagarCon").value=document.getElementById("TXT_TOT_IMP").value;
		document.getElementById("CboMon").disabled=true;
		document.getElementById("CboMon").value="SOLES";											
	}
	if(StrTdp=="DEPOSITO"){
		document.getElementById("CboTar").value="";
		document.getElementById("CboTar").disabled=true;
		document.getElementById("CboBancos").value="";
		document.getElementById("CboBancos").disabled=false;
		document.getElementById("TxtPagarCon").disabled=true;
		document.getElementById("TxtPagarCon").value=document.getElementById("TXT_TOT_IMP").value;
		document.getElementById("CboMon").disabled=true;
		document.getElementById("CboMon").value="SOLES";		
		document.getElementById("TxtOpe").readOnly=false;								
	}
	//
	if(StrTdp=="CONTADO"){
		document.getElementById("TxtPagarCon").readOnly=false;
		document.getElementById("TxtPagarCon").value=document.getElementById("TXT_TOT_IMP").value;		
		document.getElementById("TxtVuelto").value="0.0";
		document.getElementById("CboMon").disabled=false;
	}else{
		document.getElementById("TxtPagarCon").readOnly=true;
		document.getElementById("TxtPagarCon").value="0.0";
		document.getElementById("CboMon").disabled=true;
	}	
}
//
function cCod(e){	
	var k;
	k=(document.all) ? e.keyCode :e.which;
	DivDatos = document.getElementById("TAB_AJAX");
	DivCaption = document.getElementById("TAB_CAPTION");
	if(k==40){
		if(DivDatos.style.visibility!="hidden"){
			document.getElementById("z1").focus();
			event.preventDefault();
			
		}
		return true;
	}
	if(k==13){
		var Cod=gv("TxtCod");
		
		if(Cod==""){
			jF("TxtDes");
			return;
		}
		
		if(Cod=="0"){
			svv("Pro_TxtId,TxtCod,TxtDes,TxtPre,TxtCant,TxtImp,Pro_TxtCod,Pro_TxtDes");
			DivCaption.style.visibility="hidden";
			DivDatos.style.visibility="hidden";	
			//
			jF("CboCom");
		}else{
			GetCod(Cod);
		}
	}
}
//
function fVenTR(){
	var id=gv("TxtId");
	if(jVal(id)==0){
		sv("TxtSer","");
		sv("TxtNum","");
	}
	var tr=gv("VEN_TR");
	if(jVal(tr)>0){
		document.getElementById("ChN_AUTO").checked=true
		document.getElementById("TxtSer").readOnly=true;
		document.getElementById("TxtNum").readOnly=true;
		document.getElementById("TxtSer").style.background="#CCC";
		document.getElementById("TxtNum").style.background="#CCC";
	}else{
		if(document.getElementById("ChN_AUTO").checked==false){
			document.getElementById("TxtSer").readOnly=false;
			document.getElementById("TxtNum").readOnly=false;
			document.getElementById("TxtSer").style.background="#FFF";
			document.getElementById("TxtNum").style.background="#FFF";
		}else{
			document.getElementById("TxtSer").readOnly=true;
			document.getElementById("TxtNum").readOnly=true;
			document.getElementById("TxtSer").style.background="#CCC";
			document.getElementById("TxtNum").style.background="#CCC";			
		}
	}
}
function fcSer(){
	if(jVal(gv("TxtId"))==0){
		var ser=gv("TxtSer");
		if(jL(ser)==0)sv("TxtSer","001");
		if(jL(ser)==1)sv("TxtSer","00"+ser);
		if(jL(ser)==2)sv("TxtSer","0"+ser);
	}
}
function fcNum(){
	if(jVal(gv("TxtId"))==0){
		var num=gv("TxtNum");
		if(jL(num)==0)sv("TxtNum","000001");
		if(jL(num)==1)sv("TxtNum","00000"+num);
		if(jL(num)==2)sv("TxtNum","0000"+num);
		if(jL(num)==3)sv("TxtNum","000"+num);
		if(jL(num)==4)sv("TxtNum","00"+num);
		if(jL(num)==5)sv("TxtNum","0"+num);
	}
}