//////////////////////////////////////////////////////////////////////////////////////////////////////////
// INFOSOFT SA DE CV
// Fecha: 2011-02-06
// Updates:2011-02-06
// Author:Rodolfo Machon
// File Name: mdfg.js BSB v2.0
// Description:
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// VARIABLES
var GridId;
var exist;
var xmlHttp;
var xmlHttp2;
var xmlHttpStream;
var xmlHttpStream2;
var MasterFields;
var MasterValues;
var DetailFields;
var DetailValues;
var openwindow	= new Array(50);
if (window.ActiveXObject){
	var GridHeadXML   = new ActiveXObject("Microsoft.XMLDOM");
	var GridBodyXML   = new ActiveXObject("Microsoft.XMLDOM");
	var GridFootXML   = 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);
}else{
	alert('Your browser cannot handle this script');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
function GetPageData(){
	GetParams();
	GetMasterDetail(id);
}
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];
	app	    = ap[1];
	clase	    = cl[1];
	id	    = it[1];
	if(id!=""){GetMasterDetail(id)}
}
function Process(id_field){
	var iden = eval("document.mdfg."+id_field+".value");
	DeleteGrid();
	//alert(iden)
	GetMasterDetail(iden);	
}
function Save(){
	PassMasterToContainer();
	PassDetailToContainer();
	if(MasterValues==""){alert("NO DATA TO SEND");return}
	var str	 = "lan="+lan+"&app="+app+"&clase="+clase+"&id="+id+"&exist="+exist+"&master_fields="+MasterFields+"&master_values="+MasterValues+"&detail_fields="+DetailFields+"&detail_values="+DetailValues;
	var URL	 = "/cgi-bin/"+app+"/bin/mdwss.pl";
	xmlHttp  = GetXmlHttpObject(SC_Save);
	xmlHttp.open('POST',URL,true) ;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(str);
}
function GetMasterDetail(id){
	var URL	= "/cgi-bin/"+app+"/bin/mdfgp.exe?lan="+lan+"&app="+app+"&clase="+clase+"&id="+id;
	xmlHttp	= GetXmlHttpObject(SC_GetMasterDetail);
	xmlHttp.open("GET",URL,true) ;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(null);
}
function ConstructMaster(){
	var MD  = MasterData.split('~~');
	var msf = MD[0].split('{}');
	var msv = MD[1].split('[]');
	for (var i=0;i<msv.length-1;i++){
		if(document.getElementsByName(msf[i])[0]) {
			if (eval("document.mdfg."+msf[i]+".selectedIndex == 0")){
				var listlength = eval("document.mdfg."+msf[i]+".options.length");
				var idx=0;
				for (var j=0;j<listlength;j++){
					var opt=eval("document.mdfg."+msf[i]+".options["+j+"].value");
					if ( opt== msv[i]){idx = j;}
				}			
				eval("document.mdfg."+msf[i]+"["+idx+"]"+".selected=true");
			}else{
				eval("document.mdfg."+msf[i]+".value='"+msv[i]+"'");
			}
		}
	}
	var tmlf = MD[2].split('{}');
	var tmlv = MD[3].split('[]');
	for (var k=0;k<tmlv.length;k++){
		var mlf = tmlf[k].split('&&');
		var mlv = tmlv[k].split('**');
		for (var l=0;l<mlf.length-1;l++){
			if(document.getElementsByName(mlf[l])[0]) {
				if (eval("document.mdfg."+mlf[l]+".selectedIndex == 0")){			
					var listlength = eval("document.mdfg."+mlf[l]+".options.length");
					var idx=0;
					for (var m=0;m<listlength;m++){
						opt=eval("document.mdfg."+msf[l]+".options["+m+"].value");
						if ( opt== mlv[l]){idx = m;}
					}			
					eval("document.mdfg."+mlf[l]+"["+idx+"]"+".selected=true");
				}else{
					eval("document.mdfg."+mlf[l]+".value='"+mlv[l]+"'");
				}
			}
		}
	}
}
function ConstructDetail(){
	var DD  = DetailData.split('~~');
	var dsv = DD[0].split('{}');
	var dsv = DD[1].split('[]');
	if(id!=""){
		ConstructGridBodyData();
		exist=true
	}else{
		ConstructGridHeader();
		ConstructGridBody();
		exist=false;
		ConstructGridFooter();
	}
}
function ConstructGridHeader(){
	var HeaderTab = document.getElementById('header_tab');
	var RowStream	= GetRowDefinition('GridHeadXML','head').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	AddRow(-1,'',RowDef,RowStyle,HeaderTab);	
}
function ConstructGridBodyData (){
	var i		= 0;
	var GridTab 	= document.getElementById('Grid_tab');		
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	var DefRows	= RowStream[3];
	var DD  	= DetailData.split('~~');	
	var dsf 	= DD[0].split('{}');
	var dsv 	= DD[1].split('[]');
	var dlf 	= DD[2].split('{}');
	var dlv 	= DD[3].split('[]');
	for(i=1;i<dsv.length;i++ ) {
		AddRow(i,dsv[i-1],RowDef,RowStyle,GridTab);
		//CalculateRow(i,RowPro);
	}
	if((DefRows-dsv.length)>0){
		for(var j=i;j<=(DefRows-dsv.length)+2;j++ ) {
			AddRow(j,'',RowDef,RowStyle,GridTab);
		}
	}
}
function ConstructGridBody (){
	var GridTab = document.getElementById('Grid_tab');	
	var RowStream	= GetRowDefinition('GridBodyXML','body').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	var DefRows	= RowStream[3];
	for(var i=1;i<=DefRows;i++ ) {
		AddRow(i,'',RowDef,RowStyle,GridTab);
	}	
}
function ConstructGridFooter(){
	var FooterTab = document.getElementById('footer_tab');
	var RowStream	= GetRowDefinition('GridFootXML','foot').split("^^");
	var RowDef	= RowStream[0];
	var RowStyle	= RowStream[1];
	var RowPro	= RowStream[2];
	AddRow(-1,'',RowDef,RowStyle,FooterTab);
}
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 RowPro	= "";
	var RowStyle	= "";
	var DefRows	= "";	
	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="";var ECla="";
			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("class")[0]){ECla = NewColumnElements[k][l].getElementsByTagName("class")[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+" ";
				}
			}
			CInnerHTML  += ConstructElement(EControl,EName,EType,ESize,EMax,ECaption,EEventos,EVal,ECla);
		}
		RowDef += CInnerHTML+"~~";
		RowPro += CProcess+"~~";
	}
	if(GridSection.getElementsByTagName("style")[0]){RowStyle = GridSection.getElementsByTagName("style")[0].childNodes[0].nodeValue;}
	if(GridSection.getElementsByTagName("default_rows")[0]){DefRows = GridSection.getElementsByTagName("default_rows")[0].childNodes[0].nodeValue;}
	return RowDef+"^^"+RowStyle+"^^"+RowPro+"^^"+DefRows;
}
function AddRow(indx,Row,RowDef,RowStyle,objSection){
	var GridRow 	= objSection.insertRow(-1);
	var RowColsDef 	= RowDef.split("~~");
	var RowCols 	= Row.split("**");	
	var CCells  	= new Array(RowColsDef.length);
	//alert(RowColsDef)
	for(var a=0;a<RowColsDef.length-1;a++ ) {
		var $valor          = "";
		var NewCInnerHTML   = RowColsDef[a];
		if(RowCols[a]){$valor = RowCols[a]}else{$valor = ""}
		NewCInnerHTML = NewCInnerHTML.replace(/{value}/g,$valor);
		NewCInnerHTML = NewCInnerHTML.replace(/{indx}/g,indx);
		CCells[a] = GridRow.insertCell(a);
		CCells[a].innerHTML = NewCInnerHTML; 
	}	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 2
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;
}
function SC_GetMasterDetail(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		xmlHttpStream = xmlHttp.responseText;
		//document.write(xmlHttpStream);		
		var Data   = xmlHttpStream.split("^^");
		if(Data!=""){
			MasterData = Data[0];
			//alert(MasterData);			
			DetailData = Data[1];
			//alert(DetailData);
			GridHeader = Data[2];
			//alert(GridHeader);
			GridBody   = Data[3];
			//alert(GridBody);
			GridFooter = Data[4];
			//alert(GridFooter);
			id   	   = Data[5];
			//alert(id);			
			loadMasterDetailXML();
		}
	} 
}
function SC_Save(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
		xmlHttpStream = xmlHttp.responseText;
		//alert(xmlHttpStream);
		var Data   = xmlHttpStream.split("^^");		
		if(Data!=""){
			id_field= Data[0]; 			
			id    	= Data[1];
			exist 	= Data[2];
			eval("document.mdfg."+id_field+".value='"+id+"'")
			Process(id_field);
		}
	} 
}
function PassMasterToContainer(){
	var mif  = "";	
	var miv  = "";
	var MD   = MasterData.split('~~');
	var master_needed_fields =  MD[0].split('{}');
	for (i=0;i<master_needed_fields.length;i++){
		if(document.getElementsByName(master_needed_fields[i])[0]) {
			if (eval("document.mdfg."+master_needed_fields[i]+"[0]")){
				valor=eval("document.mdfg."+master_needed_fields[i]+"[document.mdfg."+master_needed_fields[i]+".selectedIndex].value");
			}else if(eval("document.mdfg."+master_needed_fields[i])){
				valor=eval("document.mdfg."+master_needed_fields[i]+".value");
			}
			mif+=master_needed_fields[i]+"{}";
			miv+=valor+"[]";
		}else{
			alert(master_needed_fields[i]+" Does Not Exist");
			return;
		}
	}
	MasterFields=mif;
	MasterValues=miv;
}
function PassDetailToContainer(){
	var div  = "";
	var Rows = GridId.rows;
	var DD   = DetailData.split('~~');	
	var detail_needed_fields = DD[0].split('{}');
	for(i=1;i<Rows.length;i++) {
		var riv  = "";
		for(j=0;j<detail_needed_fields.length;j++) {
			var dnf  = detail_needed_fields[j]+"__"+i;
			if(document.getElementsByName(dnf)[0]) {
				if (eval("document.mdfg."+dnf+"[0]")){
					valor = eval("document.mdfg."+dnf+"[document.mdfg."+dnf+".selectedIndex].value");
				}else if(eval("document.mdfg."+dnf)){
					valor = eval("document.mdfg."+dnf+".value");
				}
				riv+=valor+"[]";
			}
		}
		var empty = riv.replace(/\[]/g,'');
		if(empty != ""){div+=riv+"~~";}
	}
	DetailFields=DD[0];
	DetailValues=div;
}
function DeleteGrid(){
	var Rows = document.getElementById('Grid_tab').rows.length;
	if(Rows>0){
		for(var a=0;a<Rows;a++ ) {
			document.getElementById('Grid_tab').deleteRow(-1);
		}
	}
	//document.getElementById('header_tab').deleteTHead();
	//document.getElementById('footer_tab').deleteTFoot();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// LEVEL 3
function loadMasterDetailXML(){
	if (window.DOMParser){
		parser = new DOMParser();
		GridHeadXML    = parser.parseFromString(GridHeader,"text/xml");
		GridBodyXML    = parser.parseFromString(GridBody,"text/xml");
		GridFootXML    = parser.parseFromString(GridFooter,"text/xml");
		if(MasterData!=""){ConstructMaster()}
		ConstructDetail();
	}else {// Internet Explorer
		GridHeadXML.async = false;
		GridHeadXML.loadXML(GridHeader);
		GridBodyXML.async = false;
		GridBodyXML.loadXML(GridBody);
		GridFootXML.async  = false;
		GridFootXML.loadXML(GridFooter);
		if(MasterData!=""){ConstructMaster()}
		ConstructDetail();
	}
}
function ConstructElement(control,name,type,size,max,caption,events,val,clas){
	var line = "";
	if(control=="INPUT"){
		line += "<INPUT  ";
		line += "name="+name;
		if(type=="TEXT"){
			line += " type='text'";
			if(val!=""){line += " value='"+val+"'"}
			line += " size='"+size+"'";
			line += " maxlength='"+max+"'";
			line += " "+events;
			if(clas!=""){line += " class='"+clas+"'"}
		}
		if(type=="CHECKBOX"){
			line += " type='checkbox'";
			line += " "+events;
			if(clas!=""){line += " class='"+clas+"'"}
			line += " checked";
		}
		if(type=="HIDDEN"){
			line  = " type=hidden";
		}
		line += ">";
	}
	if(control=='LINK'){line += "<A name='"+name+"' href='#' "+events+">"+caption+"</A>";}
	if(control=='SELECT'){}
	if(control=='TEXTAREA'){}
	if(control=='TEXT'){
		line += caption;
	}
	return line;
}
// AUXILIAR
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.mdfg."+chk_name+".checked")){
			eval("document.mdfg.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.mdfg.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.mdfg."+chk_name+".checked")){
			eval("document.mdfg.ACC_"+Acce+"_"+chk_indx[1]+".value='"+ZDigits[i2_digitos]+"'")
		}else{
			if(RowRCD1[q+2]==""){RowRCD1[q+2]=ZDigits[i2_digitos]}
			if(eval("document.mdfg.ACC_"+AAccesorioMembers[1]+"_chk.checked")){eval("document.mdfg.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.mdfg."+chk_name+".checked")){
				if(chk_indx[0]=="TAR"){
					var TAR_Value = eval("document.mdfg.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.mdfg.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']/365)}
						      if(RowRCD1[1]>=90){TAR_ACC_Value = TAR_Value*(GridParams['M90']/365)}
						      if(RowRCD1[1]<1){TAR_ACC_Value = 0}
						}
						//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.mdfg.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.mdfg.ACC_"+AAccesorioMembers1[1]+"_chk.checked")){eval("document.mdfg.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'")}
					}
					eval("document.mdfg.TAR_"+Trib+"_"+a+".value='"+ZDigits[i2_digitos]+"'")
				}
				if(chk_indx[0]=="ACC"){eval("document.mdfg.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.mdfg.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.mdfg.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']/365)}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90']/365)}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0}
						}
						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.mdfg.ACC_"+Acce1+"_"+a+".value='"+NewACC_Value.toFixed(i2_digitos)+"'");
						if(eval("document.mdfg.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.mdfg.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.mdfg.STT_"+a+".value")*1;
						var AAccesorioMembers11	= AAccesorios[c].split(",");
						var Acce11		= AAccesorioMembers11[0].substr(5,3);
						var ACC_Value1 		= eval("document.mdfg.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']/365)}
						      if(RowRCD1[1]>=90){TAR_ACC_Value1 = STT_Value*(GridParams['M90']/365)}
						      if(RowRCD1[1]<1){TAR_ACC_Value1 = 0}
						}
						var NewACC_Value1= Math.abs(TAR_ACC_Value1);
						NewACC_Value1	 = Math.round(NewACC_Value1*DDigits[i2_digitos])/DDigits[i2_digitos]						
						//alert("document.mdfg.ACC_"+Acce11+"_"+a+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'");
						if(eval("document.mdfg.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.mdfg.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.mdfg.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.mdfg.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']/365)}
		      if(RowRCD1[1]>=90){TAR_ACC_Value1 = TAR_Value1*(GridParams['M90']/365)}
		      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.mdfg.ACC_"+AAccesorioMembers11[1]+"_chk.checked")){eval("document.mdfg.ACC_"+Acce11+"_"+chk_indx[2]+".value='"+NewACC_Value1.toFixed(i2_digitos)+"'")}
	}
	document.getElementById('Grid').deleteTFoot();
	ConstructGridFooter();
	GetTotal();	
}
function GetBack(component,clase,getback,opener_form,left,top,id_field,field_focus,search_fields,search_values){
	var id_value = "";
	var winame = component+clase;
	if(id_field!=""){
		id_value = eval("document.mdfg."+id_field+".value");
		if(id_value==""){
			alert('Please Choose ID Firts');
			return;
		}
	}
	if (!openwindow[winame] || openwindow[winame].closed){
		if(search_fields){
			win ="window.open('/cgi-bin/"+app+"/bin/"+component+".exe?lan="+lan+"&app="+app+"&clase="+clase+"&getback="+getback+"&opener_form="+opener_form+"&id="+id_value+"&field_focus="+field_focus+"&search_fields="+search_fields+"&search_values="+search_values+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		}else{
			win ="window.open('/cgi-bin/"+app+"/bin/"+component+".exe?lan="+lan+"&app="+app+"&clase="+clase+"&getback="+getback+"&opener_form="+opener_form+"&id="+id_value+"&field_focus="+field_focus+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		}
		openwindow[winame]=eval(win);
	}else{openwindow[winame].focus()}
}
function GridGetBack(objRef,fldRef){
	var id_value	   = "";
	var getback	   = "";
	var objIndx  	   = objRef.name.split("__");
	var reference 	   = fldRef.split("|");
	var idf_class      = reference[0];
	var component	   = reference[1];
	var clase	   = reference[2];
	var getback_fields = reference[3];
	var opener_form	   = reference[4];
	var left	   = reference[5];
	var top		   = reference[6];
	var id_filter	   = reference[7];
	var winame 	   = component+clase;	
	if(id_filter!=""){
		id_value = eval("document.mdfg."+id_filter+".value");
		if(id_value==""){
			alert('Please Choose ID Firts');
			return;
		}
	}
	var gbFlds  	= getback_fields.split(",");
	for (i=0;i<gbFlds.length;i++){
		gbFld = gbFlds[i]+"__"+objIndx[1];
		getback += gbFld+",";
	}
	getback = getback.substr(0,getback.length-1)
	if (!openwindow[winame] || openwindow[winame].closed){
		win ="window.open('/cgi-bin/"+app+"/bin/"+component+".exe?lan="+lan+"&app="+app+"&clase="+clase+"&getback="+getback+"&opener_form="+opener_form+"&id="+id_value+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		openwindow[winame]=eval(win);
	}else{openwindow[winame].focus()}	
}