String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
//**************************************************************************
function fFiltrar(){
	document.getElementById("TxtAc").value="F";
	document.getElementById("Frm").submit();
}
//**************************************************************************
function fCancelar(){
	fFecServer("TxtFec");
	document.getElementById("TxtNum").value="";
	document.getElementById("TxtCli").value="";
	document.getElementById("TxtTot").value="";
	document.getElementById("TxtAde").value="";
	document.getElementById("TxtAcu").value="";
	document.getElementById("TxtSal").value="";
	document.getElementById("TxtUsa").value="";
	document.getElementById("CboTad").value="";
	//
	document.getElementById("CmdG").disabled =false;
	document.getElementById("CmdE").disabled =true;
	document.getElementById("CmdG").value="Guardar";
	document.getElementById("TxtId").value="";
	document.getElementById("TxtAc").value="";
	document.getElementById("TxtFec").focus();
}
function CalSaldo(){
	var TOT=jVal(gv("TxtTve"));
	var ACU=jVal(gv("TxtAcu"));
	var Tot=jVal(gv("TxtTot"));
	var SAL=TOT -( ACU + Tot);
	SAL=SAL.toFixed(2);
	document.getElementById("TxtSal").value=SAL;
}
//
function fGuardar(){
	var Emp=gv("CboEmp");
	var Fec=gv("TxtFec");
	var Num=gv("TxtNum");
	var Cli=gv("TxtCli");
	var Cli=gv("TxtCli");
	var Mod=gv("CboTad");
	
	var TOT=jVal(gv("TxtTot"));
	var ADE=jVal(gv("TxtAde"));
	var ACU=jVal(gv("TxtAcu"));
	var AKU=jVal(gv("TxtAku"));
	var SAL=jVal(gv("TxtSal"));	
	var USA=jVal(gv("TxtUsa"));
	//
	if(jL(Emp)==0){
		alert("Seleccione una empresa");
		return jF("CboEmp");
	}
	if(Fec.trim().length==0){
		alert("Ingrese la fecha, segun el formato");
		document.getElementById("TxtFec").focus();
		return;
	}
	if(EsFecha(Fec)==false){
		alert("Fecha no valida, verifique el formato");
		document.getElementById("TxtFec").focus();
		return;
	}
	if(jLen(Num)==0){
		alert("Ingrese el numero de contrato");
		jFocus("TxtNum");return;
	}
	if(jLen(Cli)==0){
		alert("Seleccione el cliente correspondiente");
		jFocus("CmdSel");return;
	}	
	if(jLen(Mod)==0){
		alert("Seleccione la modalidad");
		jFocus("CboTad");return;
	}	
	if(TOT<=0){
		alert("El total debe ser mayor a cero");
		jFocus("TxtTot");
		return;
	}
	if(ADE > TOT){
		alert("El total debe ser mayor igual al adelanto");
		jFocus("TxtTot");
		return;
	}

	//
	if(document.getElementById("CmdG").value=="Guardar"){
		document.getElementById("TxtAc").value="G";
	}else{
		document.getElementById("TxtAc").value="M";
	}
	document.getElementById("Frm").submit();
}
//
function Cal(){
	var AKU=jVal(gv("TxtAku"));
	var TOT=jVal(gv("TxtTot"));
	var ADE=jVal(gv("TxtAde"));
	var SAL=0;
	var ACU=(AKU + ADE).toFixed(2);
	SAL=(TOT - ACU).toFixed(2);
	if(SAL<=0){
		document.getElementById("TxtSal").value=0;
	}else{
		document.getElementById("TxtSal").value=SAL;
	}
	document.getElementById("TxtAcu").value=ACU;
	
}