//////////////////////////////////////////////////////////////////////////////////////////////////////////
// WEBSOFT SA DE CV
// Fecha: 2006-04-10
// Updates:2006-08-19,2006-10-22,2006-12-23,2010-09-27,2015-11-02
// Author:Rodolfo Machon
// File Name: bsws.js
// Copyright - All Rights Reserved
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES
var lan;
var appid;
var clase;
var id;
var xmlHttp;
var xmlHttpStream;
var GridFormat;
var GridData;
var i2_dias_mora;
var d82_multa_minima;
var i2_digitos;
var RowRCD   = new Array();
var RowVTar  = new Array();
var RowITar  = new Array();
var RowDataStruct  = new Array("PER","DIM","FIE","INT","MUL");
var RowDataStruct1 = new Array("PER","DIM","TAR","VAL","FIE","INT","MUL");
var ZDigits  = new Array("0","0.0","0.00","0.000","0.0000","0.00000","0.000000");
var DDigits  = new Array("1","10","100","1000","10000","100000","1000000")
var GridParams	= new Object();
var OpenWindows  = new Object();
var openwindow;
var openwindow1;
var FITariff	= "";
//vars geb
var Total_temp=0;
var total_multa=0;
var multa_cero=0;
function GetXmlHttpObject(handler){
	var objXmlHttp=null;	
	if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		objXmlHttp = new XMLHttpRequest();
		objXmlHttp.onload=handler;
		objXmlHttp.onerror=handler; 		
	}
	if(window.ActiveXObject){// code for IE6, IE5
		objXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		objXmlHttp.onreadystatechange=handler;
	}
	if(objXmlHttp==null){alert("Your Browser Does Not Suppport AJAX")}
	return objXmlHttp;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 1
function GetPageParams(){
	GetParams();
	GetGrid();	
}
function ConstructPage(){
	var Gens  		= Generales.split("|");
	i2_dias_mora	= Gens[0];
	d82_multa_minima= Gens[1];
	i2_digitos		= Gens[2];
	balance_type	= Gens[3];
	ConstructPageHeader();
	ConstructPageGrid();
	enableButtons();	
}
function Pago(){
	//var value			= "";
	var st 				= disableButtons();	
	var dt_vencimiento	= document.form.dt_vencimiento.value;
	var dt_futuro		= document.form.dt_futuro.value;
	var dt_corte		= document.form.dt_corte.value;	

	DeleteGrid();
	document.getElementById('Grid').deleteTHead();
	document.getElementById('Grid').deleteTFoot();
	document.form.tp.value="AFUTURO";
	GetGrid();
}
function ClearGrid(chk){
	if(chk==true){
		DeleteGrid();
		document.getElementById('Grid').deleteTHead();
		document.getElementById('Grid').deleteTFoot();
		GetGrid();
	}else{
		DeleteGrid();
		document.getElementById('Grid').deleteTFoot();
		ConstructGridFooter();
		//GetTotal();
	}
}
function ClearRow(objRef){
	var chk_name	= objRef.name;
	var chk_indx	= objRef.name.split("_");
	var Rows	= GridData.split("~~");
	var RowColsData	= GetRowColsData(Rows[chk_indx[1]-1]).split("^^");
	var RowRCD1	= RowColsData[0].split("|");
	var RowVTar1	= RowColsData[1].split("|");
	var RowITar1	= RowColsData[2].split("|");
	var ATributos	= Tributos.split("|");
	for (var p=0;p<ATributos.length-1;p++ ) {
		var ATributoMembers = ATributos[p].split(",");
		var Trib = ATributoMembers[0].substr(0,8);
		if(!eval("document.form."+chk_name+".checked")){
			eval("document.form.TAR_"+Trib+"_"+chk_indx[1]+".value='"+ZDigits[i2_digitos]+"'")
		}else{
			for(var r=0;r<RowITar1.length;r++){
				if(RowITar1[r].substr(0,8)==Trib){
					if(RowVTar1[r]==""){RowVTar1[r]=ZDigits[i2_digitos]}
					eval("document.form.TAR_"+Trib+"_"+chk_indx[1]+".value='"+RowVTar1[r]+"'")
				}	
			}
		}
	}
	var AAccesorios = Accesorios.split("|");
	for (var q=0;q<AAccesorios.length-1;q++ ) {
		var AAccesorioMembers = AAccesorios[q].split(",");
		var Acce = AAccesorioMembers[0].substr(5,3);
		if(!eval("document.form."+chk_name+".checked")){
			eval("document.form.ACC_"+Acce+"_"+chk_indx[1]+".value='"+ZDigits[i2_digitos]+"'")
		}else{
			if(RowRCD1[q+2]==""){RowRCD1[q+2]=ZDigits[i2_digitos]}
			if(eval("document.form.ACC_"+AAccesorioMembers[1]+"_chk.checked")){eval("document.form.ACC_"+Acce+"_"+chk_indx[1]+".value='"+RowRCD1[q+2]+"'")}
		}
	}
	
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	CalculateRow(chk_indx[1],RowPro);
	
	document.getElementById('Grid').deleteTFoot();
	ConstructGridFooter();
	//GetTotal();
}
function ClearColumn(objRef){
	var chk_name = objRef.name;
	var chk_indx = objRef.name.split("_");
	var Rows     = document.getElementById('Grid').rows.length;
	if(Rows>0){
		var Trib      = "";
		var Acce      = "";
		var tindex    = "";
		var aindex    = "";		
		var Rows1     = GridData.split("~~");
		var RowStream = GetRowDefinition('GridBodyXML','body').split("^^");
		var RowDef    = RowStream[0];
		var RowStyle  = RowStream[1];
		var RowPro    = RowStream[2];
		
		var OTributo  = new Object();
		var ATributos = Tributos.split("|");
		for (var p=0;p<ATributos.length-1;p++ ) {
			var ATributoMembers = ATributos[p].split(",");
			
			OTributo[ATributoMembers[1]] = ATributoMembers[0];
			//alert(OTributo[ATributoMembers[1]]+"<>"+ATributoMembers[0])
			if(chk_indx[1]==ATributoMembers[1]){tindex=p;}
			//alert(ATributoMembers[1]+"="+ATributoMembers[0]+"="+chk_indx[1])
		}

		var OAccesorio	= new Object();
		var AAccesorios	= Accesorios.split("|");
		for (var q=0;q<AAccesorios.length;q++ ) {
			var AAccesorioMembers = AAccesorios[q].split(",");
			OAccesorio[AAccesorioMembers[1]] = AAccesorioMembers[0].substr(5,3);
			if(chk_indx[1].substr(0,3)==AAccesorioMembers[0].substr(5,3)){aindex=q;}			
		}
		
		if(chk_indx[0]=="TAR"){Trib = OTributo[chk_indx[1]]}
		if(chk_indx[0]=="ACC"){Acce = OAccesorio[chk_indx[1]]}
		for(var a=1;a<Rows-1;a++ ) {
			var RowColsData	= GetRowColsData(Rows1[a-1]).split("^^");
			var RowRCD1	= RowColsData[0].split("|");
			var RowVTar1	= RowColsData[1].split("|");
			var RowITar1	= RowColsData[2].split("|");
			if(!eval("document.form."+chk_name+".checked")){
				if(chk_indx[0]=="TAR"){
					var TAR_Value = eval("document.form.TAR_"+Trib+"_"+a+".value");
					for (var b=0;b<AAccesorios.length-1;b++ ) {
						var TAR_ACC_Value	= 0;
						var AAccesorioMembers1	= AAccesorios[b].split(",");
						var Acce1		= AAccesorioMembers1[0].substr(5,3);
						var ACC_Value 		= eval("document.form.ACC_"+Acce1+"_"+a+".value")*1;
						if(Acce1=="FIE"){TAR_ACC_Value = TAR_Value*GridParams[Acce1];}
						if(Acce1=="INT"){TAR_ACC_Value = RowRCD1[1]*TAR_Value*(GridParams[Acce1]/365);}
						if(Acce1=="MUL"){
							//alert();
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value = TAR_Value*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value = TAR_Value*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value = 0;multa_cero=1}
						}
						//var NewACC_Value = Math.abs(ACC_Value-TAR_ACC_Value);
						var NewACC_Value = Math.abs(ACC_Value-TAR_ACC_Value);
						NewACC_Value	 = Math.round(NewACC_Value*DDigits[i2_digitos])/DDigits[i2_digitos]
						//alert(RowRCD1[1]+"<=>"+TAR_Value+"<=>"+ACC_Value+"<=>"+TAR_ACC_Value+"<=>document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers1[1]+"_chk.checked")){eval("document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'")}
					}
					eval("document.form.TAR_"+Trib+"_"+a+".value='"+ZDigits[i2_digitos]+"'")
				}
				if(chk_indx[0]=="ACC"){eval("document.form.ACC_"+Acce+"_"+a+".value='"+ZDigits[i2_digitos]+"'")}
			}else{
				var TAR_Value1 = "";
				if(chk_indx[0]=="TAR"){
					for(var r=0;r<RowITar1.length;r++){
						if(RowITar1[r].substr(0,8)==Trib){
							if(RowVTar1[r]==""){RowVTar1[r]=ZDigits[i2_digitos]}
							eval("document.form.TAR_"+Trib+"_"+a+".value='"+RowVTar1[r]+"'")
							TAR_Value1 = RowVTar1[r];
						}	
					}
					for (var c=0;c<AAccesorios.length-1;c++ ) {
						var TAR_ACC_Value1	= 0;
						var AAccesorioMembers11	= AAccesorios[c].split(",");
						var Acce11		= AAccesorioMembers11[0].substr(5,3);
						var ACC_Value1 		= eval("document.form.ACC_"+Acce11+"_"+a+".value")*1;
						if(Acce11=="FIE"){TAR_ACC_Value1 = TAR_Value1*GridParams[Acce11];}
						if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*TAR_Value1*(GridParams[Acce11]/365);}
						if(Acce11=="MUL"){
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0;;multa_cero=1}
						}
						var NewACC_Value1	= Math.abs(ACC_Value1+TAR_ACC_Value1);
						NewACC_Value1	 = Math.round(NewACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos]
						//alert(RowRCD1[1]+"<=>"+TAR_Value+"<=>"+ACC_Value+"<=>"+TAR_ACC_Value+"<=>document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
					}
				}
				if(chk_indx[0]=="ACC"){
					for (var c=0;c<AAccesorios.length-1;c++ ) {
						var STT_Value			= eval("document.form.STT_"+a+".value")*1;
						var AAccesorioMembers11	= AAccesorios[c].split(",");
						var Acce11				= AAccesorioMembers11[0].substr(5,3);
						var ACC_Value1 			= eval("document.form.ACC_"+Acce11+"_"+a+".value")*1;
						if(Acce11=="FIE"){TAR_ACC_Value1 = STT_Value*GridParams[Acce11];}
						if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*STT_Value*(GridParams[Acce11]/365);}
						if(Acce11=="MUL"){
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = STT_Value*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = STT_Value*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0;multa_cero=1}
						}
						var NewACC_Value1= Math.abs(TAR_ACC_Value1);
						NewACC_Value1	 = Math.round(NewACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos]						
						//alert("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
					}					
				}				
			}
			CalculateRow(a,RowPro);
		}
		document.getElementById('Grid').deleteTFoot();
		ConstructGridFooter();
		//GetTotal();		
	}
}
function ClearColumnByName(name){
	var chk_name = name;
	var chk_indx = name.split("_");
	var Rows     = document.getElementById('Grid').rows.length;
	if(Rows>0){
		var Trib      = "";
		var Acce      = "";
		var tindex    = "";
		var aindex    = "";		
		var Rows1     = GridData.split("~~");
		var RowStream = GetRowDefinition('GridBodyXML','body').split("^^");
		var RowDef    = RowStream[0];
		var RowStyle  = RowStream[1];
		var RowPro    = RowStream[2];
		
		var OTributo  = new Object();
		var ATributos = Tributos.split("|");
		for (var p=0;p<ATributos.length-1;p++ ) {
			var ATributoMembers = ATributos[p].split(",");
			
			OTributo[ATributoMembers[1]] = ATributoMembers[0];
			//alert(OTributo[ATributoMembers[1]]+"<>"+ATributoMembers[0])
			if(chk_indx[1]==ATributoMembers[1]){tindex=p;}
			//alert(ATributoMembers[1]+"="+ATributoMembers[0]+"="+chk_indx[1])
		}

		var OAccesorio	= new Object();
		var AAccesorios	= Accesorios.split("|");
		for (var q=0;q<AAccesorios.length;q++ ) {
			var AAccesorioMembers = AAccesorios[q].split(",");
			OAccesorio[AAccesorioMembers[1]] = AAccesorioMembers[0].substr(5,3);
			if(chk_indx[1].substr(0,3)==AAccesorioMembers[0].substr(5,3)){aindex=q;}			
		}
		
		if(chk_indx[0]=="TAR"){Trib = OTributo[chk_indx[1]]}
		if(chk_indx[0]=="ACC"){Acce = OAccesorio[chk_indx[1]]}
		for(var a=1;a<Rows-1;a++ ) {
			var RowColsData	= GetRowColsData(Rows1[a-1]).split("^^");
			var RowRCD1	= RowColsData[0].split("|");
			var RowVTar1	= RowColsData[1].split("|");
			var RowITar1	= RowColsData[2].split("|");
			if(!eval("document.form."+chk_name+".checked")){
				if(chk_indx[0]=="TAR"){
					var TAR_Value = eval("document.form.TAR_"+Trib+"_"+a+".value");
					for (var b=0;b<AAccesorios.length-1;b++ ) {
						var TAR_ACC_Value	= 0;
						var AAccesorioMembers1	= AAccesorios[b].split(",");
						var Acce1		= AAccesorioMembers1[0].substr(5,3);
						var ACC_Value 		= eval("document.form.ACC_"+Acce1+"_"+a+".value")*1;
						if(Acce1=="FIE"){TAR_ACC_Value = TAR_Value*GridParams[Acce1];}
						if(Acce1=="INT"){TAR_ACC_Value = RowRCD1[1]*TAR_Value*(GridParams[Acce1]/365);}
						if(Acce1=="MUL"){
							//alert();
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value = TAR_Value*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value = TAR_Value*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value = 0;multa_cero=1}
						}
						//var NewACC_Value = Math.abs(ACC_Value-TAR_ACC_Value);
						var NewACC_Value = Math.abs(ACC_Value-TAR_ACC_Value);
						NewACC_Value	 = Math.round(NewACC_Value*DDigits[i2_digitos])/DDigits[i2_digitos]
						//alert(RowRCD1[1]+"<=>"+TAR_Value+"<=>"+ACC_Value+"<=>"+TAR_ACC_Value+"<=>document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers1[1]+"_chk.checked")){eval("document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'")}
					}
					eval("document.form.TAR_"+Trib+"_"+a+".value='"+ZDigits[i2_digitos]+"'")
				}
				if(chk_indx[0]=="ACC"){eval("document.form.ACC_"+Acce+"_"+a+".value='"+ZDigits[i2_digitos]+"'")}
			}else{
				var TAR_Value1 = "";
				if(chk_indx[0]=="TAR"){
					for(var r=0;r<RowITar1.length;r++){
						if(RowITar1[r].substr(0,8)==Trib){
							if(RowVTar1[r]==""){RowVTar1[r]=ZDigits[i2_digitos]}
							eval("document.form.TAR_"+Trib+"_"+a+".value='"+RowVTar1[r]+"'")
							TAR_Value1 = RowVTar1[r];
						}	
					}
					for (var c=0;c<AAccesorios.length-1;c++ ) {
						var TAR_ACC_Value1	= 0;
						var AAccesorioMembers11	= AAccesorios[c].split(",");
						var Acce11		= AAccesorioMembers11[0].substr(5,3);
						var ACC_Value1 		= eval("document.form.ACC_"+Acce11+"_"+a+".value")*1;
						if(Acce11=="FIE"){TAR_ACC_Value1 = TAR_Value1*GridParams[Acce11];}
						if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*TAR_Value1*(GridParams[Acce11]/365);}
						if(Acce11=="MUL"){
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0;;multa_cero=1}
						}
						var NewACC_Value1	= Math.abs(ACC_Value1+TAR_ACC_Value1);
						NewACC_Value1	 = Math.round(NewACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos]
						//alert(RowRCD1[1]+"<=>"+TAR_Value+"<=>"+ACC_Value+"<=>"+TAR_ACC_Value+"<=>document.form.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
					}
				}
				if(chk_indx[0]=="ACC"){
					for (var c=0;c<AAccesorios.length-1;c++ ) {
						var STT_Value			= eval("document.form.STT_"+a+".value")*1;
						var AAccesorioMembers11	= AAccesorios[c].split(",");
						var Acce11				= AAccesorioMembers11[0].substr(5,3);
						var ACC_Value1 			= eval("document.form.ACC_"+Acce11+"_"+a+".value")*1;
						if(Acce11=="FIE"){TAR_ACC_Value1 = STT_Value*GridParams[Acce11];}
						if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*STT_Value*(GridParams[Acce11]/365);}
						if(Acce11=="MUL"){
						      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = STT_Value*(GridParams['M89'])}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = STT_Value*(GridParams['M90'])}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0;multa_cero=1}
						}
						var NewACC_Value1= Math.abs(TAR_ACC_Value1);
						NewACC_Value1	 = Math.round(NewACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos]						
						//alert("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'");
						if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.form.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
					}					
				}				
			}
			CalculateRow(a,RowPro);
		}
		document.getElementById('Grid').deleteTFoot();
		ConstructGridFooter();
		//GetTotal();		
	}
}
function ChangeCell(objRef){
	var tindex	= "";
	var LTributo	= "";
	var chk_name	= objRef.name;
	var chk_indx	= objRef.name.split("_");
	var Rows	= GridData.split("~~");
	var RowColsData	= GetRowColsData(Rows[chk_indx[2]-1]).split("^^");
	var RowRCD1	= RowColsData[0].split("|");
	var RowVTar1	= RowColsData[1].split("|");
	var RowITar1	= RowColsData[2].split("|");
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];	
	CalculateRow(chk_indx[2],RowPro);
	var TAR_Value1 = eval("document.form.STT_"+chk_indx[2]+".value");	
	var AAccesorios	= Accesorios.split("|");	
	for (var c=0;c<AAccesorios.length-1;c++ ) {
		var TAR_ACC_Value1	= 0;
		var AAccesorioMembers11	= AAccesorios[c].split(",");
		var Acce11		= AAccesorioMembers11[0].substr(5,3);
		var ACC_Value1 		= eval("document.form.ACC_"+Acce11+"_"+chk_indx[2]+".value")*1;
		if(Acce11=="FIE"){TAR_ACC_Value1 = TAR_Value1*GridParams[Acce11];}
		if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*TAR_Value1*(GridParams[Acce11]/365);}
		if(Acce11=="MUL"){
		      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M89'])}
		      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90'])}
		      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0}
		}
		var NewACC_Value1	= Math.round(TAR_ACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos];
		//alert(NewACC_Value1);
		if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){
			eval("document.form.ACC_"+Acce11+"_"+chk_indx[2]+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")
		}
	}
	document.getElementById('Grid').deleteTFoot();
	ConstructGridFooter();
	//GetTotal();	
}
function ChangeCellByName(name){
	var tindex	= "";
	var LTributo	= "";
	var chk_name	= name;
	var chk_indx	= name.split("_");
	var Rows	= GridData.split("~~");
	var RowColsData	= GetRowColsData(Rows[chk_indx[2]-1]).split("^^");
	var RowRCD1	= RowColsData[0].split("|");
	var RowVTar1	= RowColsData[1].split("|");
	var RowITar1	= RowColsData[2].split("|");
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];	
	CalculateRow(chk_indx[2],RowPro);
	var TAR_Value1 = eval("document.form.STT_"+chk_indx[2]+".value");	
	var AAccesorios	= Accesorios.split("|");	
	for (var c=0;c<AAccesorios.length-1;c++ ) {
		var TAR_ACC_Value1	= 0;
		var AAccesorioMembers11	= AAccesorios[c].split(",");
		var Acce11		= AAccesorioMembers11[0].substr(5,3);
		var ACC_Value1 		= eval("document.form.ACC_"+Acce11+"_"+chk_indx[2]+".value")*1;
		if(Acce11=="FIE"){TAR_ACC_Value1 = TAR_Value1*GridParams[Acce11];}
		if(Acce11=="INT"){TAR_ACC_Value1 = RowRCD1[1]*TAR_Value1*(GridParams[Acce11]/365);}
		if(Acce11=="MUL"){
		      if(RowRCD1[1]>=1 && RowRCD1[0]<90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M89'])}
		      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90'])}
		      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0}
		}
		var NewACC_Value1	= Math.round(TAR_ACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos];
		//alert(NewACC_Value1);
		if(eval("document.form.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.form.ACC_"+Acce11+"_"+chk_indx[2]+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
	}
	document.getElementById('Grid').deleteTFoot();
	ConstructGridFooter();
	//GetTotal();	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 2
function GetParams(){
    var query   = window.location.search.substring(1);
    var params	= query.split("&");
    var la      = params[0].split("=");
    var ap      = params[1].split("=");
    var cl      = params[2].split("=");
    var it      = params[3].split("=");    
    lan		= la[1];
    appid	= ap[1];
    clase	= cl[1];
    id		= it[1];    
}
function GetGrid(){
	var dtv = document.form.dt_vencimiento.value;
	var dtf = document.form.dt_futuro.value;
	var dtc = document.form.dt_corte.value;
	var dtc1 = document.form.dt_corte1.value;
	var URL	= "../bin/bswsp_30.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&dt_vencimiento="+dtv+"&dt_futuro="+dtf+"&dt_corte="+dtc+"&dt_corte1="+dtc1;
	//var URL = "/bin/bswsp_30.pl?lan=es&appid=RTM_LaHerradura&clase=inmueble&id=1000088&dt_vencimiento=2018-06-30&dt_futuro=&dt_corte=2009-06-30&dt_corte1=2009-06-01";
	//alert(URL);
	xmlHttp	= GetXmlHttpObject(StateChanged);
	xmlHttp.open("GET",URL,true) ;
	xmlHttp.send(null);
}
function ConstructPageHeader(){

}
function ConstructPageGrid(){
	GetGridParams();
	ConstructGridHeader();
	ConstructGridBody();
	ConstructGridFooter();
	//document.form.GridDatos.value = GridData;
}
function DeleteGrid(){
	var Rows = document.getElementById('Grid').rows.length;
	if(Rows>0){
		for(var a=1;a<Rows;a++ ) {
			document.getElementById('Grid').deleteRow(1);
		}
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 3
function ConstructGridHeader(){
	var GridHeader	 	= GridHeadXML.getElementsByTagName('head')[0];
	var HeaderCols 	 	= GridHeader.getElementsByTagName("columns")[0].childNodes[0].nodeValue;
	var Columns	 		= HeaderCols.split(",");
	var RowCells 	 	= new Array(Columns.length);	
	var NewColumn	 	= new Array(Columns.length);
	for(var a=0;a<Columns.length;a++ ) {
		var Column	= GridHeader.getElementsByTagName("column")[a];
		var ColumnName	= Column.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		for(var b=0;b<Columns.length;b++ ) {
			if(ColumnName==Columns[b]){
				NewColumn[b] = GridHeader.getElementsByTagName("column")[a];
			}
		}
	}
	var NewColumnElements	= new Array(Columns.length);
	for(var f=0;f<Columns.length;f++ ) {
		var Elements		= NewColumn[f].getElementsByTagName("elements")[0].childNodes[0].nodeValue.split(",");
		NewColumnElements[f]	= new Array(Elements.length);
		for(var g=0;g<Elements.length;g++ ) {
			var ElementL	= NewColumn[f].getElementsByTagName("element");
			for(var h=0;h<ElementL.length;h++ ) {			
				var ElementName	= ElementL[h].getElementsByTagName("name")[0].childNodes[0].nodeValue;
				if(Elements[g]==ElementName){
					NewColumnElements[f][g] = ElementL[h];
				}
			}
		}		
	}
	var Grid	= document.getElementById('Grid');	
	var newTHEAD= Grid.createTHead();
	var GridRow	= newTHEAD.insertRow(0);	
	var CCells 	= new Array(Columns.length);
	var p		= 0;
	for(var k=0;k<Columns.length;k++ ) {
		var CInnerHTML	= "";		
		var CName   = NewColumn[k].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		var CData   = NewColumn[k].getElementsByTagName("data")[0].childNodes[0].nodeValue;
		var CHeader = NewColumn[k].getElementsByTagName("header")[0].childNodes[0].nodeValue;
		var CType   = NewColumn[k].getElementsByTagName("type")[0].childNodes[0].nodeValue;
		var CWidth  = NewColumn[k].getElementsByTagName("width")[0].childNodes[0].nodeValue;
		Elements    = NewColumn[k].getElementsByTagName("elements")[0].childNodes[0].nodeValue.split(",");
		for(var l=0;l<Elements.length;l++ ) {
			var EName    = "";
			var EControl = "";
			var EType    = "";
			var ECaption = "";
			var ESize    = "";
			var EMax     = "";
			var EEventos = "";
			if(NewColumnElements[k][l].getElementsByTagName("name")[0]){EName = NewColumnElements[k][l].getElementsByTagName("name")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("control")[0]){EControl = NewColumnElements[k][l].getElementsByTagName("control")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("type")[0]){EType = NewColumnElements[k][l].getElementsByTagName("type")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("caption")[0]){ECaption = NewColumnElements[k][l].getElementsByTagName("caption")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("size")[0]){ESize = NewColumnElements[k][l].getElementsByTagName("size")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("maxlength")[0]){EMax = NewColumnElements[k][l].getElementsByTagName("maxlength")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("events")[0]){
				var EEvents  = NewColumnElements[k][l].getElementsByTagName("events")[0];
				for(var m=0;m<EEvents.childNodes.length;m++ ) {
					var Event  = EEvents.childNodes[m].nodeName;
					var Method = EEvents.childNodes[m].childNodes[0].nodeValue;
					EEventos  += Event+"="+Method+" ";
					//alert(EName+"=>"+Event+"="+Method)
				}
			}
			//alert(CName+"=>"+k+"<>"+l+"=>"+EControl+"=>"+EName+"=>"+EType+"=>"+ESize+"=>"+EMax+"=>"+ECaption+"=>"+EEventos);
			CInnerHTML  += ConstructElement(EControl,EName,EType,ESize,EMax,ECaption,EEventos);

		}
		if(CName=="tributos"){
			var ATributos = Tributos.split("|");
			for(var n=p;n<ATributos.length+p-1;n++ ) {
				var PTributo	    = ATributos[n-p].split(",");
				var NewCInnerHTML   = CInnerHTML.replace(/{tributo}/g,PTributo[1]);
				CCells[n]  	     	= GridRow.insertCell(n);
				CCells[n].innerHTML = NewCInnerHTML;
				//CCells[n].outerHTML = "<th>"+NewCInnerHTML+"</th>";
				CCells[n].setAttribute('width',CWidth[n])
			}
			p=n;
		}else if(CName=="accesorios"){
			var AAccesorios = Accesorios.split("|");

			for(var o=p;o<AAccesorios.length+p-1;o++ ) {
				var PAccesorio		= AAccesorios[o-p].split(",");
				var NewCInnerHTML1	= CInnerHTML.replace(/{accesorio}/g,PAccesorio[1]);
				CCells[o]  	     	= GridRow.insertCell(o);
				CCells[o].innerHTML	= NewCInnerHTML1;
				CCells[o].setAttribute('width',CWidth[o])
			}
			p=o;
		}else{
			CCells[p]  	    	= GridRow.insertCell(p);
			CCells[p].innerHTML = CInnerHTML;
			CCells[p].setAttribute('width',CWidth[p])
			p++;
		}
	}
}
function ConstructGridBody(){
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	var Rows	= GridData.split("~~");
	for(var i=1;i<Rows.length;i++ ) {
		AddRow(i,Rows[i-1],RowDef,RowStyle);
		CalculateRow(i,RowPro);
	}	
}
function ConstructGridFooter(){
	var z 		= 0;
	var RowStream	= GetRowDefinition('GridFootXML','foot').split("^^");
	var RowColsDef	= RowStream[0].split("~~");
	var RowColsPro  = RowStream[2].split("~~");
	var RowStyle	= RowStream[1];
	var FIT 	= Tributos.split("|");	
	var CCells  	= new Array(RowColsDef.length);	
	var Grid    	= document.getElementById('Grid');
	var Rows 	= document.getElementById('Grid').rows.length-1;
	var newTFOOT	= Grid.createTFoot();
	NewRow   	= newTFOOT.insertRow(-1);
	NewRow.style.cssText = RowStyle;
	for(var a=0;a<RowColsDef.length-1;a++ ) {
		var NewCInnerHTML = RowColsDef[a];
		var NewColsPro	  = RowColsPro[a];
		for(var c=z;c<FIT.length-1;c++ ) {
			var Ocurrence = NewCInnerHTML.indexOf("{TAR}");
			if(Ocurrence>=0){
				var FIT_c = FIT[c].split(",");
				NewCInnerHTML = NewCInnerHTML.replace(/{TAR}/g,FIT_c[0]);
				NewColsPro    = NewColsPro.replace(/{TAR}/g,FIT_c[0]);
				z++;
			}
		}
		CCells[a]  	     = NewRow.insertCell(a);
		CCells[a].innerHTML  = NewCInnerHTML;
		if(RowColsPro[a]!=""){
			var NEC = eval(NewColsPro)
			if(NEC==false){CCells[a].innerHTML=ZDigits[i2_digitos]}
		}
	}	
}
function GetGridParams(){
	var AAP = AccesoriosParams.split("~~");
	GridParams['M89']="0.05";
	GridParams['M90']="0.10";
	//alert(AccesoriosParams);
	for (var a=0;a<AAP.length;a++ ) {
		var AAPMembers = AAP[a].split("|");
		//alert(AAPMembers);
		if(AAPMembers.length>2){
			var M89 = AAPMembers[1].split("=");
			var M90 = AAPMembers[2].split("=");			
			GridParams['M89'] = M89[1];
			GridParams['M90'] = M90[1];
		}else{
			GridParams[AAPMembers[0]] = AAPMembers[1];
		}
	}
	GridParams['M89']="0.05";
	GridParams['M90']="0.10";
}
function GetTotal(){
	if(document.form.TTOT){
		var TMULTA = document.form.STA_MUL.value*1;
		var TOTAL1 = document.form.TTOT.value*1;
		var TOTAL=Math.round(TOTAL1*DDigits[i2_digitos])/DDigits[i2_digitos];
		var TDIM   = GetDiasMora();
		if(eval("document.form.ACC_MULTAS_chk.checked")){
			if (TDIM>0 && TMULTA==0) {
				TOTAL=TOTAL+2.86
			}	
		}else{
			TOTAL = 0.00;
			document.form.STA_MUL.value=0.00;
		}		
		document.form.us_total.value = TOTAL.toFixed(2);
		
	}else{document.form.us_total.value=ZDigits[i2_digitos]};
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 4
function AddRow(indx,Row,RowDef,RowStyle){
	var z = 0;
	var RowColsDef 	= RowDef.split("~~");
	var RowColsData	= GetRowColsData(Row).split("^^");
	RowRCD		= RowColsData[0].split("|");
	RowVTar		= RowColsData[1].split("|");
	RowITar		= RowColsData[2].split("|");
	var SRowITar	= RowITar.join(",");
	var Grid    	= document.getElementById('Grid');
	var GridRow 	= Grid.insertRow(indx);
	var CCells  	= new Array(RowColsDef.length);
	var ATributos 	= Tributos.split("|");
	GridRow.style.cssText = RowStyle;
	for(var a=0;a<RowColsDef.length-1;a++ ) {
		var NewCInnerHTML  = RowColsDef[a];
		for(var b=0;b<RowRCD.length-1;b++ ) {
			var NewDataStruct = "{"+RowDataStruct[b]+"}";
			var TReplace 	  = new RegExp(NewDataStruct, "g");
			NewCInnerHTML     = NewCInnerHTML.replace(TReplace,RowRCD[b]);
		}
		var Ocurrence = NewCInnerHTML.indexOf("{TAR}");
		if(Ocurrence>=0){
			var PTributo = ATributos[z].split(",");
			for(var d=0;d<RowITar.length-1;d++ ) {
				if(PTributo[0]==RowITar[d].substr(0,8)){
					NewCInnerHTML = NewCInnerHTML.replace(/{VAL}/g,RowVTar[d]);
					NewCInnerHTML = NewCInnerHTML.replace(/{TAR}/g,RowITar[d].substr(0,8));
				}
			}
			NewCInnerHTML = NewCInnerHTML.replace(/{VAL}/g,ZDigits[i2_digitos]);
			NewCInnerHTML = NewCInnerHTML.replace(/{TAR}/g,PTributo[0]);
			z++;
		}
		CCells[a]  	     	= GridRow.insertCell(a);
		CCells[a].innerHTML = NewCInnerHTML.replace(/{indx}/g,indx);
	}	
}
function CalculateRow(indx,RowPro){
	var RowColsPro = RowPro.split("~~");
	for(var a=0;a<RowColsPro.length-1;a++ ) {
		var NewColsPro = RowColsPro[a].replace(/{indx}/g,indx);
		if(RowColsPro[a]!=""){
			//alert(NewColsPro);
			eval(NewColsPro)
		};
	}
}
function GetRowDefinition(xml,part){
	var GridSection	 	= eval(xml+".getElementsByTagName('"+part+"')[0]");
	var SectionCols 	= GridSection.getElementsByTagName("columns")[0].childNodes[0].nodeValue;
	var Columns	 	= SectionCols.split(",");
	var RowCells 	 	= new Array(Columns.length);	
	var NewColumn	 	= new Array(Columns.length);
	for(var a=0;a<Columns.length;a++ ) {
		var Column	= GridSection.getElementsByTagName("column")[a];
		var ColumnName	= Column.getElementsByTagName("name")[0].childNodes[0].nodeValue;
		for(var b=0;b<Columns.length;b++ ) {
			if(ColumnName==Columns[b]){
				NewColumn[b] = GridSection.getElementsByTagName("column")[a];
			}
		}
	}
	var NewColumnElements	= new Array(Columns.length);
	for(var f=0;f<Columns.length;f++ ) {
		var Elements		= NewColumn[f].getElementsByTagName("elements")[0].childNodes[0].nodeValue.split(",");
		NewColumnElements[f]	= new Array(Elements.length);
		for(var g=0;g<Elements.length;g++ ) {
			var ElementL	= NewColumn[f].getElementsByTagName("element");
			for(var h=0;h<ElementL.length;h++ ) {			
				var ElementName	= ElementL[h].getElementsByTagName("name")[0].childNodes[0].nodeValue;
				if(Elements[g]==ElementName){
					NewColumnElements[f][g] = ElementL[h];
				}
			}
		}		
	}
	var RowDef	= "";
	var RowStyle	= GridSection.getElementsByTagName("style")[0].childNodes[0].nodeValue;
	var RowPro	= "";
	var p		= 0;
	for(var k=0;k<Columns.length;k++ ) {
		var CInnerHTML	= "";		
		var CProcess	= "";
		var CName	= NewColumn[k].getElementsByTagName("name")[0].childNodes[0].nodeValue;
		var CData	= NewColumn[k].getElementsByTagName("data")[0].childNodes[0].nodeValue;
		var CHeader	= NewColumn[k].getElementsByTagName("header")[0].childNodes[0].nodeValue;
		var CType	= NewColumn[k].getElementsByTagName("type")[0].childNodes[0].nodeValue;
		var CWidth	= NewColumn[k].getElementsByTagName("width")[0].childNodes[0].nodeValue;
		if(NewColumn[k].getElementsByTagName("process")[0]){CProcess = NewColumn[k].getElementsByTagName("process")[0].childNodes[0].nodeValue;}		
		Elements	= NewColumn[k].getElementsByTagName("elements")[0].childNodes[0].nodeValue.split(",");
		for(var l=0;l<Elements.length;l++ ) {
			var EName="";var EControl="";var EType="";var ECaption="";var ESize="";var EMax="";var EEventos="";var EVal="";
			if(NewColumnElements[k][l].getElementsByTagName("name")[0]){EName = NewColumnElements[k][l].getElementsByTagName("name")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("control")[0]){EControl = NewColumnElements[k][l].getElementsByTagName("control")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("type")[0]){EType = NewColumnElements[k][l].getElementsByTagName("type")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("caption")[0]){ECaption = NewColumnElements[k][l].getElementsByTagName("caption")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("size")[0]){ESize = NewColumnElements[k][l].getElementsByTagName("size")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("maxlength")[0]){EMax = NewColumnElements[k][l].getElementsByTagName("maxlength")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("value")[0]){EVal = NewColumnElements[k][l].getElementsByTagName("value")[0].childNodes[0].nodeValue;}
			if(NewColumnElements[k][l].getElementsByTagName("events")[0]){
				var EEvents  = NewColumnElements[k][l].getElementsByTagName("events")[0];
				for(var m=0;m<EEvents.childNodes.length;m++ ) {
					var Event  = EEvents.childNodes[m].nodeName;
					var Method = EEvents.childNodes[m].childNodes[0].nodeValue;
					EEventos  += Event+"="+Method+" ";
					//alert(EName+"=>"+Event+"="+Method)					
				}
			}
			//alert(CName+"=>"+k+"<>"+l+"=>"+EControl+"=>"+EName+"=>"+EType+"=>"+ESize+"=>"+EMax+"=>"+ECaption+"=>"+EEventos);
			//alert(ESize+"=>"+EMax);			
			CInnerHTML  += ConstructElement(EControl,EName,EType,ESize,EMax,ECaption,EEventos,EVal);
		}
		if(CName=="tributos"){
			var ATributos = Tributos.split("|");
			for(var n=p;n<ATributos.length+p-1;n++ ) {
				var PTributo	     = ATributos[n-p].split(",");
				var NewCInnerHTML    = CInnerHTML.replace(/{tributo}/g,PTributo[1]);
				RowDef += NewCInnerHTML+"~~";
				RowPro += CProcess+"~~";
			}
			p=n;
		}else if(CName=="accesorios"){
			var AAccesorios = Accesorios.split("|");
			for(var o=p;o<AAccesorios.length+p-1;o++ ) {
				var PAccesorio	     = AAccesorios[o-p].split(",");
				var CAccesorio	     = PAccesorio[0].substr(5,3)
				var NewCInnerHTML1   = CInnerHTML.replace(/{ACC}/g,CAccesorio);
				var NewCProcess1     = CProcess.replace(/{ACC}/g,CAccesorio);				
				RowDef += NewCInnerHTML1+"~~";
				RowPro += NewCProcess1+"~~";
			}
			p=o;
		}else{
			RowDef += CInnerHTML+"~~";
			RowPro += CProcess+"~~";
			p++;
		}
	}
	//alert(RowDef+"^^"+RowStyle+"^^"+RowPro)
	return RowDef+"^^"+RowStyle+"^^"+RowPro;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 5
function ConstructElement(control,name,type,size,max,caption,events,val){
	var line = "";
	if(control=="INPUT"){
		line += "<INPUT  ";
		//line += "name="+name+"_{indx}";
		line += "name="+name;
		if(type=="TEXT"){
			line += " type=text";
			if(val!=""){line += " value="+val;}
			line += " size="+size;
			line += " maxlength="+max;
			line += " "+events;
			line += " class=my_style0";
		}
		if(type=="CHECKBOX"){
			line += " type=checkbox";
			line += " "+events;
			line += " class=checkbox";
			line += " checked";
		}
		if(type=="HIDDEN"){
			line  = " type=hidden";
		}
		line += ">";
	}
	if(control=='LINK'){line += "<A name='"+name+"' href='#' "+events+" class=my_style>"+caption+"</A>";}
	if(control=='SELECT'){}
	if(control=='TEXTAREA'){}
	if(control=='TEXT'){
		line += caption;
	}
	return line;
}
function GetRowColsData(Row){
	var RowData = Row.split("&&");
	var VTariff = "";
	var ITariff = "";
	var RCD = "";
	var PER	= "";
	var DIM = "";
	var TAR = "";
	var VAL = "";	
	var FIE = 0;
	var INT = 0;
	var MUL = 0;
	for(var a=0;a<RowData.length-1;a++ ) {
		var ColsData = RowData[a].split("|");
		PER  	 = ColsData[0];
		DIM  	 = ColsData[1];
		ITariff += ColsData[2]+"|";
		VTariff += ColsData[3]+"|";
		FIE 	+= ColsData[4]*1;
		INT 	+= ColsData[5]*1;
		MUL 	+= ColsData[6]*1;
	}
	var IT_length  = ITariff.split("|").length;
	var FIT_length = FITariff.split("|").length;
	if(IT_length>=FIT_length){FITariff=ITariff}	
	RCD = PER+"|"+DIM+"|"+FIE.toFixed(i2_digitos)+"|"+INT.toFixed(i2_digitos)+"|"+MUL.toFixed(i2_digitos)+"|";
	return RCD+"^^"+VTariff+"^^"+ITariff;
}
function RowSum(indx,addends,sum){
	var Acumulated	= 0;
	var ExecStream 	= "";
	var IA 		= addends.substr(0,1);
	if(IA=="@"){
		var AD = addends.substr(2,addends.length-3).split(",");
		for (var a=0;a<AD.length;a++){
			var Value  = eval("document.form."+AD[a]+"_"+indx+".value");
			Acumulated = (Acumulated*1)+(Value*1);
		}
	}else{
		if(addends=="TAR"){
			var FIT = Tributos.split("|");	
			for (var b=0;b<FIT.length-1;b++){
				var FIT_c = FIT[b].split(",");
				var Value1 = eval("document.form."+addends+"_"+FIT_c[0]+"_"+indx+".value");				
				if((Value1*1)>0){Acumulated = (Acumulated*1)+(Value1*1);}
			}
		}
		if(addends=="ACC"){
			var AA = Accesorios.split("|");
			for (var c=0;c<AA.length-1;c++){
				var AAC	   = AA[c].split(",");
				var CA     = AAC[0].substr(5,3);
				var Value2 = eval("document.form."+addends+"_"+CA+"_"+indx+".value");
				if((Value2*1)>0){Acumulated = (Acumulated*1)+(Value2*1);}
			}
		}
	}
	ExecStream = "document.form."+sum+".value='"+Acumulated.toFixed(i2_digitos)+"'";
	eval(ExecStream);
}
function CalculateAccesorio(indx,acc,recell){
	var TAR_ACC_Value1 = 0;
	var TTValue	= 0;
	var AccChecked  = "";
	var RowsL	= GridData.split("~~");
	var RowTarData	= RowsL[indx-1].split("&&");
	var STT_Value	= eval("document.form.STT_"+indx+".value")*1;
	var DIM_Value	= eval("document.form.DIM_"+indx+".value")*1;
	
	var AAccesorios	= Accesorios.split("|");
	for (var q=0;q<AAccesorios.length;q++ ) {
		var AAccesorioMembers = AAccesorios[q].split(",");
		if(AAccesorioMembers[0].substr(5,3)==acc){AccChecked=AAccesorioMembers[1]}
	}
	var XTributos	= Tributos.split("|")
	for (var t=0;t<(XTributos.length-1);t++ ) {		
		TTributo = XTributos[t].split(",");
		TTValue	 = eval("document.form.TAR_"+TTributo[0]+"_"+indx+".value")*1
		for (var v=0;v<(RowTarData.length-1);v++ ){
			var TarData = RowTarData[v].split("|");
			if(TarData[2].substr(0,8)==TTributo[0]){
				if(acc=="FIE" && TarData[4]>0){
					//alert();
					//TAR_ACC_Value1 += Math.round((TTValue*GridParams['FIE'])*DDigits[i2_digitos])/DDigits[i2_digitos]
					TAR_ACC_Value1 += round(TTValue*GridParams['FIE']);
				}else{
					TAR_ACC_Value1+=0
				}
				if(acc=="INT" && TarData[5]>0){
					//TAR_ACC_Value1 += Math.round(DIM_Value*TTValue*(GridParams['INT']/365)*DDigits[i2_digitos])/DDigits[i2_digitos]
					TAR_ACC_Value1 += round(DIM_Value*TTValue*(GridParams['INT']/365));
				}else{
					TAR_ACC_Value1+=0
				}
				if(acc=="MUL" && TarData[6]>0){
				    if(DIM_Value>=1 && DIM_Value<90){
						//TAR_ACC_Value1 += Math.round(TTValue*GridParams['M89']*DDigits[i2_digitos])/DDigits[i2_digitos]
						TAR_ACC_Value1 += round(TTValue*GridParams['M89']);
					}
				    if(DIM_Value>=90){
						//TAR_ACC_Value1 += Math.round(TTValue*GridParams['M90']*DDigits[i2_digitos])/DDigits[i2_digitos]
						TAR_ACC_Value1 += round(TTValue*GridParams['M90']);
					}
				    if(DIM_Value<1){TAR_ACC_Value1 = 0}
				}else{TAR_ACC_Value1+=0}
			}
		}
	}
	//var NewACC_Value1	= Math.round(TAR_ACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos];
	var NewACC_Value1	= TAR_ACC_Value1;
	if(eval("document.form.ACC_"+AccChecked+"_chk.checked")){eval("document.form.ACC_"+acc+"_"+indx+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// AUXILIAR
function GetDiasMora(){
    var dim    = 0;
    var T1     = document.getElementById('Grid');
    var rows1  = T1.rows;
    for (var i=1;i<rows1.length-2;i++){
	var DM = eval("document.form.DIM_"+i+".value");
	if(DM>0){dim++}
    }
    return dim;
}
function ShowTarifa(objRef){
	var chk_name	= objRef.name;
	var chk_indx	= objRef.name.split("_");
	var Rows	= GridData.split("~~");
	var RowData 	= Rows[chk_indx[2]-1].split("&&");
	var colTarifa	= "";
	for(var a=0;a<RowData.length-1;a++ ) {
		var ColsData = RowData[a].split("|");
		if(ColsData[2].substr(0,8)==chk_indx[1]){
			colTarifa = ColsData[2];
		}
	}
	return colTarifa;
}
function GetTributo(tribId){
	var ATributos	= Tributos.split("|");
	for (var p=0;p<ATributos.length-1;p++ ) {
		var ATributoMembers = ATributos[p].split(",");
		var Trib = ATributoMembers[0].substr(0,8);
		if(tribId==Trib){description = ATributoMembers[1];}
	}
	return description
}
function ShowCalendar(form,datetype,separator){
	if (!openwindow || openwindow.closed){
		win ="window.open('../libraries/html/clnd_bsws.html?pbf="+form+"&datetype="+datetype+"&separator="+separator+"','Calendar','left=200,top=200,width=250,height=260,scrollbars=no,toolbar=no,menu=no')";
		openwindow=eval(win);
	}else{openwindow.focus()}
}
function OpenWindow(winame,comm,fields,values){
	var commands	= comm.split(",");
	var id_field	= document.form.id_field.value;
	var id		= eval("document.form."+id_field+".value");
	if (!openwindow || openwindow.closed){
		win ="window.open('../bin/"+commands[0]+".pl?lan="+lan+"&appid="+appid+"&clase="+commands[1]+"&id="+id+"&fields="+fields+"&values="+values+"','"+commands[0]+commands[1]+"','left="+commands[2]+",top="+commands[3]+",width=800,height=600,scrollbars=yes,toolbar=no,menu=no,statusbar=no')";
		openwindow=eval(win);
	}
	else{openwindow.focus()}
}
function ShowPago(chk){
	if(chk==true){
		document.all.CalendarLink.style.visibility='visible';
	}else{
		document.all.CalendarLink.style.visibility='hidden';
	}
}
function ShowComentario(chk){
	if(chk==true){
		document.all.Comentario.style.visibility='visible';
	}else{
		document.all.Comentario.style.visibility='hidden';
	}
}
function StateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		xmlHttpStream=xmlHttp.responseText;
		if(document.form.i8_user_id.value=='9999'){
			//document.write(xmlHttpStream);		
			//alert("Balance=>\n"+xmlHttpStream);
			//alert("Balance");		
			//return;			
		}
		var Grid   = xmlHttpStream.split("^^");
		GridData   = Grid[0];
		//alert(GridData);
		Tributos   = Grid[1];
		//alert(Tributos);
		Accesorios = Grid[2];
		//alert(Accesorios);
		Header 	   = Grid[3];
		//alert(Header);
		Body 	   = Grid[4];
		//alert(Body);
		Footer	   = Grid[5];
		//alert(Footer);
		Billing	   = Grid[6];
		//alert(Billing);
		AccesoriosParams = Grid[7];
		//alert(AccesoriosParams);		
		Generales  = Grid[8];
		//alert(Generales);
		Tarifas	   = Grid[9];
		//alert(Tarifas);		
		loadXML1();
	} 
}
if (window.ActiveXObject){
	var GridHeadXML = new ActiveXObject("Microsoft.XMLDOM");
	var GridBodyXML = new ActiveXObject("Microsoft.XMLDOM");
	var GridFootXML = new ActiveXObject("Microsoft.XMLDOM");
	var BillingXML  = new ActiveXObject("Microsoft.XMLDOM");
	var PropXML  = new ActiveXObject("Microsoft.XMLDOM");
}else if (document.implementation && document.implementation.createDocument){
	var GridHeadXML = document.implementation.createDocument("","",null);
	var GridBodyXML = document.implementation.createDocument("","",null);
	var GridFootXML = document.implementation.createDocument("","",null);
	var BillingXML  = document.implementation.createDocument("","",null);
	var PropXML	= document.implementation.createDocument("","",null);
}else{
	alert('Your browser cannot handle this script');
}
function loadXML1(){
	if (window.DOMParser){
		parser = new DOMParser();
		GridHeadXML=parser.parseFromString(Header,"text/xml");
		GridBodyXML=parser.parseFromString(Body,"text/xml");
		GridFootXML=parser.parseFromString(Footer,"text/xml");
		BillingXML=parser.parseFromString(Billing,"text/xml");
		ConstructPage();		
	}else {// Internet Explorer
		GridHeadXML.async=false;
		GridHeadXML.loadXML(Header);

		GridBodyXML.async=false;
		GridBodyXML.loadXML(Body);
		
		GridFootXML.async=false;
		GridFootXML.loadXML(Footer);
		
		BillingXML.async=false;
		BillingXML.loadXML(Billing);	

		ConstructPage(); 
	}
}
function GetFechaHoy(){
	var dia = today.getDate();
	var mes = (today.getMonth()*1)+1;
	var ano = today.getFullYear();
	if(String(dia).length<2){dia = "0"+dia}
	if(String(mes).length<2){mes = "0"+mes}
	return ano+"-"+mes+"-"+dia;
}
function round(n){
	return 	Number((precisionRound(n,4)).toFixed(i2_digitos));
}
function precisionRound(number, precision) {
  var factor = Math.pow(10, precision);
  return Math.round(number * factor) / factor;
}
//-----------------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------
function ColSum(T,C){
	var Rows 	= document.getElementById('Grid').rows.length-1;
	var t 		= 0;
	var total_multa = 0;
	var succ 	= false;
	var mul_min = d82_multa_minima*1;
	if(Rows>1){
		for(var a=1;a<Rows;a++ ) {
			sub = eval("document.form."+T+"_"+a+".value");
			if(sub==""){sub=0}
			if((sub*1)>0){t += (sub*1);}
		}
		if(C=="STA_MUL"){
			if(t<mul_min && t>0 ){
				t=mul_min;
			}
		}
		eval("document.form."+C+".value='"+t.toFixed(i2_digitos)+"'");
		succ = true;
	}	
	if(T=="STT" || T=="STA" || T=="TOT"  ){
		if(T=="TOT"){
			eval("document.form."+C+".value='"+Total_temp.toFixed(i2_digitos)+"'");
			eval("document.form.us_total.value='"+Total_temp.toFixed(i2_digitos)+"'");
			Total_temp=0;
		}		
		if(T=="STA"){
			if(total_multa <mul_min && total_multa>0){
				var multa=total_multa;
				eval("document.form."+C+".value='"+multa.toFixed(i2_digitos)+"'");
			}
		}
	}else{
		Total_temp=Total_temp+t;
		eval("document.form.us_total.value='"+Total_temp.toFixed(i2_digitos)+"'");
	}
	return succ;
}
//-----------------------------------------------------------------------------------------------
//Borrar
