//////////////////////////////////////////////////////////////////////////////////////////////////////////
// INFOSOFT SA DE CV
// Fecha: 03-16-2005
// Updates:08-22-2005,2006-01-05,2010-09-29
// Author:Rodolfo Machon
// Nombre del archivo: gdfl.js
// Description: Save(),Clear(),Add(),Modify(),Remove(),Search(),MoveUp(),PassBack(),GetBack(),OpenWindow()
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var openwindow;
var openWindow =new Object();
function ConstructTable(){
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");
	var select_values	= parent.list.document.detail.dsv.value.split("~~");
	var labels_values	= parent.list.document.detail.dlv.value.split("~~");
	var elements		= parent.list.document.detail.del.value.split("~~");
	var select_fields	= parent.list.document.detail.dsf.value.split(",");
	var labels_fields	= parent.list.document.detail.dlf.value.split(",");
	var T  			= parent.list.document.getElementById('t1');
	var header_length	= (grid_header.length*1);
	var Cells 		= new Array(header_length+2);
	var fields		= new Array(header_length);	
	var column_width	= new Array(header_length);	
	var column_type		= new Array(header_length);
	var column_events	= new Array(header_length);
	var column_elements	= new Array(header_length);	
	var NewRow		= T.insertRow(0);
	var k			= 0;
	var l			= 0;
	NewRow.style.cssText 	= parent.list.document.detail.tdheader.value;
	if(parent.list.document.detail.counter.value=="ON"){Cells[k] = NewRow.insertCell(k);Cells[k].innerHTML = "NO.";k++;l++;}
	for (j=k;j<grid_header.length;j++){
		record			= grid_header[j-1].split("|");
		Cells[j]  		= NewRow.insertCell(j);
		fields[j]		= record[0];
		Cells[j].innerHTML	= record[1];
		column_width[j]		= record[2];
		column_type[j]		= record[3];
		column_events[j]	= record[4];
		column_elements[j]	= record[5];
		l++;
	}
	if(parent.list.document.detail.dlt.value=="ON"){Cells[l] = NewRow.insertCell(l);Cells[l].innerHTML = "<a href='javascript:MarkAll()'>DELETE</a";}
	for (var i=1;i<select_values.length;i++){	
		k		= 0;
		l		= 0;
		var status	= true;
		var svalues 	= new Object;
		var lvalues 	= new Object;
		var srecord	= select_values[i-1].split("|");
		var lrecord	= labels_values[i-1].split("|");		
		NewRow		= T.insertRow(i);
		if(navigator.appName=='Microsoft Internet Explorer'){
			//NewRow.attachEvent('onmouseover',Hilite);
			//NewRow.attachEvent('onmouseout',Restore);		
		}else{
			//NewRow.addEventListener("mouseover", Hilite, false);
			//NewRow.addEventListener("mouseout", Restore, false);
		}
		NewRow.style.cssText 	= parent.list.document.detail.tdbody.value;
		for (j=0;j<srecord.length;j++){if(srecord[j]==""){srecord[j]="&nbsp;"};svalues[select_fields[j]] = srecord[j];}
		for (j=0;j<lrecord.length;j++){if(lrecord[j]==""){lrecord[j]="&nbsp;"};lvalues[labels_fields[j]] = lrecord[j];}
		if(parent.list.document.detail.counter.value=="ON"){
			Cells[k] = NewRow.insertCell(k);
			if(parent.list.document.detail.component.value=="gdfl"){Cells[k].innerHTML = "&nbsp;&nbsp;<a id=a"+i+" href='javascript:MoveUp("+i+","+status+")'>"+i+"</a>";}
			if(parent.list.document.detail.component.value=="srch"){Cells[k].innerHTML = "&nbsp;&nbsp;<a id=a"+i+" href='javascript:GridPassBack("+i+")'>"+i+"</a>";}
			k++;
			l++;
		}
		for (j=k;j<grid_header.length;j++){
			var inHTML  	= ""; 
			var checked	= "";
			var link	= "";
			var elementos	= column_elements[j].split(",");
			if(svalues[fields[j]]){inHTML = svalues[fields[j]]}else{inHTML = lvalues[fields[j]]}
			for (x=0;x<elementos.length;x++){
				if(elementos[0]!='NO'){
					for (y=0;y<elements.length-1;y++){
						var element_members = elements[y].split("|");
						if(elementos[x]==element_members[0]){
							var event  = "";
							var params = "";						
							var element_type   = element_members[1];
							var element_data   = element_members[2];
							var element_events = element_members[3].split("^^");
							for (z=0;z<element_events.length-1;z++){
								var events = element_events[z].split("^");
								event += " "+events[0];
							}
							if(element_type=='input'){
							
							}else if(element_type=='link'){
								link += "&nbsp;<a name='"+element_members[0]+"__"+i+"' href='#' "+event+">"+inHTML+"</a>";
							}else if(element_type=='select'){
								
							}else if(element_type=='textarea'){}
						}
					}
					inHTML=link;
				}
			}			
			Cells[j]  		= NewRow.insertCell(j);
			Cells[j].innerHTML	= inHTML;
			l++;
		}
		if(parent.list.document.detail.dlt.value=="ON"){Cells[l] = NewRow.insertCell(l);Cells[l].innerHTML = "<input type=checkbox name="+i+">";}
	}
}
function Save(){
	if((parent.list.document.data.div.value !="")||(parent.list.document.data.duv.value!="")||(parent.list.document.data.ddv.value!="")){
		parent.list.document.data.submit();
	}
	else {
		alert("No New Records to send");
	}
}
function Clear(form){
	var name ="";
	qty=parent.form.document.master.elements.length;
	for (i=0;i<qty;i++){
		if (eval("parent.form.document."+form+".elements["+i+"].type")!="hidden"){
			if (eval("parent.form.document."+form+".elements["+i+"].type")!="button"){			
				name= eval("parent.form.document."+form+".elements["+i+"].name");
				if(eval("parent.form.document."+form+"."+name+"[0]")){
					eval("parent.form.document."+form+"."+name+"[0].selected=true");
				}
				else{
					eval("parent.form.document."+form+".elements["+i+"].value=''");
				}
			}
		}

	}
	if(parent.form.document.getElementById('add')){parent.form.document.getElementById('add').style.visibility='visible';}	
	if(parent.form.document.getElementById('modify')){parent.form.document.getElementById('modify').style.visibility='hidden';}
	if (parent.list.document.detail.passback.value!=""){
		if(parent.form.document.getElementById('passback')){parent.form.document.getElementById('passback').style.visibility='hidden';}
	}	
}
function Add(){
	var msg_empty		= parent.form.document.master.msg_empty.value;
	var needed_fields	= parent.list.document.detail.dnf.value.split(",");
	var insert_fields	= parent.list.document.detail.dif.value.split(",");
	var insert_values	= parent.list.document.data.div.value;
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");
	var Cells 			= new Array(grid_header.length+2);
	var trows 			= parent.list.document.getElementById('t1').rows;
	var nr				= (trows.length*1);
	var T  				= parent.list.document.getElementById('t1');	
	var NewRow			= T.insertRow(trows.length);
	var status			= "false";
	var fields_missing 	= "false";
	var CC				= "";
	for (i=0;i<needed_fields.length;i++){
		var valor = eval("parent.form.document.master."+needed_fields[i]+".value");
		if (valor == ""){fields_missing = "true";}
	}
	NewRow.style.cssText 	= parent.list.document.detail.tdbody.value;
	if( fields_missing != "true" ){
		k = 0;
		l = 0;
		parent.form.parent.form.document.master.i4_count.value = nr;
		if(parent.list.document.detail.counter.value=="ON"){Cells[0] = NewRow.insertCell(0);Cells[0].innerHTML = "&nbsp;&nbsp;<a id=a"+nr+" href='javascript:MoveUp("+nr+","+status+")'>"+nr+"</a>";k++;l++}			
		for (i=k;i<grid_header.length;i++){
			record		= grid_header[i-1].split("|");
			Cells[i]	= NewRow.insertCell(i);
			if (eval("parent.form.document.master."+record[0]+"[0]")){
				field_value=eval("parent.form.document.master."+record[0]+"[parent.form.document.master."+record[0]+".selectedIndex].value");
			}else{field_value=eval("parent.form.document.master."+record[0]+".value");}
			Cells[i].innerHTML  = field_value;
			l++;
		}
		if(parent.list.document.detail.dlt.value=="ON"){Cells[l] = NewRow.insertCell(l);Cells[l].innerHTML = "<input type=checkbox name="+nr+">";}			
		parent.list.document.detail.count.value = nr;
		for (y=0;y<insert_fields.length;y++){
			if (eval("parent.form.document.master."+insert_fields[y]+"[0]")){
				campo=eval("parent.form.document.master."+insert_fields[y]+"[parent.form.document.master."+insert_fields[y]+".selectedIndex].value");
			}else{campo=eval("parent.form.document.master."+insert_fields[y]+".value");}
			CC+=campo+"|";
		}
		insert_values+=CC+"~~";
		parent.list.document.data.div.value=insert_values;
		Clear('master');
	}else{alert(msg_empty);}
}
function Modify(){	
	var id			= parent.form.document.master.i4_count.value;
	var trows 		= parent.list.document.getElementById('t1').rows;
	var z			= trows[id].cells;
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");	
	var x			= 0;
	var CC			= "";
	var field_value		= "";
	if(parent.form.document.master.status.value=="true" ){
		var update_fields	= parent.list.document.detail.duf.value.split(",");
		var select_values	= parent.list.document.detail.dsv.value.split("~~");
		var update_values	= parent.list.document.data.duv.value.split("~~");
		var select_update_values= parent.list.document.data.dsu.value.split("~~");		
		var new_update		= "";
		var new_select_update	= "";
		for (var i=0;i<update_fields.length;i++){
			if (eval("parent.form.document.master."+update_fields[i]+"[0]")){
				campo=eval("parent.form.document.master."+update_fields[i]+"[parent.form.document.master."+update_fields[i]+".selectedIndex].value");
			}else{campo=eval("parent.form.document.master."+update_fields[i]+".value");}
			CC+=campo+"|";
		}
		for(i=0;i<select_update_values.length-1;i++){
			if(select_update_values[i]==select_values[id-1]){
				update_values[i]=CC;
				select_update_values[i]=select_values[id-1];
				x=1;
			}
			new_select_update+=select_update_values[i]+"~~";
			new_update+=update_values[i]+"~~";			
		}
		if (x==0){new_update+=CC+"~~";new_select_update+=select_values[id-1]+"~~";}
		parent.list.document.data.duv.value = new_update;
		parent.list.document.data.dsu.value = new_select_update;
	}else {
		var insert_fields	= parent.list.document.detail.dif.value.split(",");		
		var insert_values	= parent.list.document.data.div.value.split("~~");
		var new_insert		= "";
		for (i=0;i<insert_fields.length;i++){
			if (eval("parent.form.document.master."+insert_fields[i]+"[0]")){
				campo=eval("parent.form.document.master."+insert_fields[i]+"[parent.form.document.master."+insert_fields[i]+".selectedIndex].value");
			}else{campo=eval("parent.form.document.master."+insert_fields[i]+".value");}
			CC+=campo+"|";
		}
		for(i=0;i<insert_values.length-1;i++){
			id_compare=insert_values[i].split("|");
			if(id == id_compare[0]){insert_values[i]=CC;x=1}
			new_insert+=insert_values[i] + "~~";
		}
		if (x==0){new_insert+=CC+"~~";}		
		parent.list.document.data.div.value=new_insert;
    	}
	for (i=1;i<grid_header.length;i++){
		record	= grid_header[i-1].split("|");
		if (eval("parent.form.document.master."+record[0]+"[0]")){
			field_value=eval("parent.form.document.master."+record[0]+"[parent.form.document.master."+record[0]+".selectedIndex].value");
		}else{field_value=eval("parent.form.document.master."+record[0]+".value");}
		z[i].innerHTML=field_value;
	}
	Clear('master');
} 
function Remove(){
	var select_fields	= parent.list.document.detail.dsf.value.split(",");
	var delete_fields	= parent.list.document.detail.ddf.value.split(",");	
	var select_values	= parent.list.document.detail.dsv.value.split("~~");
	var insert_values 	= parent.list.document.data.div.value.split("~~");
	var delete_values	= parent.list.document.data.ddv.value;
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");	
	var j			= (grid_header.length*1);
	var T  			= parent.list.document.getElementById('t1');
	var new_insert		= "";
	for (var i = T.rows.length-1; i != 0; i--) {
		if (T.rows[i].cells[j].firstChild.checked==true) {
			var aix 	= "a"+i;
			var aid 	= parent.list.document.getElementById(aix);
			var exist 	= aid.getAttribute("href").split(',');
			var slv	  = "";
			if (exist[1]=="true)"){
				var record = select_values[i-1].split('|');
				for(k=0;k<record.length;k++){
					for(l=0;l<delete_fields.length;l++){
						if(select_fields[k]==delete_fields[l]){
							slv = slv+record[k]+"|";
						}
					}
				}
				delete_values += slv+"~~";
			}else{
				for(k=0;k<insert_values.length-1;k++){
					var record1 = insert_values[k].split('|');					
					if(record1[0]!=i){
						new_insert += insert_values[k]+"~~";
					}
				}
			}
			T.deleteRow(i);
		}
	}
	parent.list.document.data.ddv.value = delete_values;
	parent.list.document.data.div.value = new_insert;
}
function Search(){
	var lan			= parent.list.document.data.lan.value;
	var appid		= parent.list.document.data.appid.value;
	var clase		= parent.list.document.data.clase.value;
	var id			= parent.list.document.data.id.value;
	var search_fields	= parent.list.document.detail.dnf.value.split(",");
	var dff			= "";
	var dfv			= "";
	for (y=0;y<search_fields.length;y++){
		var campo	= "";
		if (eval("parent.form.document.master."+search_fields[y]+"[0]")){
			campo=eval("parent.form.document.master."+search_fields[y]+"[parent.form.document.master."+search_fields[y]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.master."+search_fields[y]+".value");}
		if(campo!=""){
			dff+=search_fields[y]+",";
			dfv+=campo+"|";
		}
	}
	var frame = "parent.list.location.href='gdl.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&search_fields="+dff+"&search_values="+dfv+"'";
	eval(frame);
}
function FirstPage(){
	var lan			= parent.list.document.data.lan.value;
	var appid		= parent.list.document.data.appid.value;
	var clase		= parent.list.document.data.clase.value;
	var id			= parent.list.document.data.id.value;	
	var page		= 1;
	var limit		= parent.list.document.detail.limit.value;
	var search_fields	= parent.list.document.detail.dnf.value.split(",");
	var psbk		= parent.list.document.detail.passback.value.split(",");
	var opfr		= parent.list.document.detail.opener_form.value.split(",");
	var fldf		= parent.list.document.detail.field_focus.value.split(",");
	var dff			= "";
	var dfv			= "";
	for (y=0;y<search_fields.length;y++){
		var campo	= "";
		if (eval("parent.form.document.master."+search_fields[y]+"[0]")){
			campo=eval("parent.form.document.master."+search_fields[y]+"[parent.form.document.master."+search_fields[y]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.master."+search_fields[y]+".value");}
		if(campo!=""){
			dff+=search_fields[y]+",";
			dfv+=campo+"|";
		}
	}
	var frame = "parent.list.location.href='gdl.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&search_fields="+dff+"&search_values="+dfv+"&passback="+psbk+"&opener_form="+opfr+"&field_focus="+fldf+"&page="+page+"&limit="+limit+"'";
	eval(frame);
}
function BeforePage(){
	var lan			= parent.list.document.data.lan.value;
	var appid		= parent.list.document.data.appid.value;
	var clase		= parent.list.document.data.clase.value;
	var id			= parent.list.document.data.id.value;	
	var page		= parent.list.document.detail.page.value;
	var limit		= parent.list.document.detail.limit.value;
	var search_fields	= parent.list.document.detail.dnf.value.split(",");
	var psbk		= parent.list.document.detail.passback.value.split(",");
	var opfr		= parent.list.document.detail.opener_form.value.split(",");
	var fldf		= parent.list.document.detail.field_focus.value.split(",");
	var dff			= "";
	var dfv			= "";
	for (y=0;y<search_fields.length;y++){
		var campo	= "";
		if (eval("parent.form.document.master."+search_fields[y]+"[0]")){
			campo=eval("parent.form.document.master."+search_fields[y]+"[parent.form.document.master."+search_fields[y]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.master."+search_fields[y]+".value");}
		if(campo!=""){
			dff+=search_fields[y]+",";
			dfv+=campo+"|";
		}
	}
	if(page>1){
		page 	  = (page*1)-1;
		var frame = "parent.list.location.href='gdl.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&search_fields="+dff+"&search_values="+dfv+"&passback="+psbk+"&opener_form="+opfr+"&field_focus="+fldf+"&page="+page+"&limit="+limit+"'";
		eval(frame);
	}
}
function NextPage(){
	var lan			= parent.list.document.data.lan.value;
	var appid		= parent.list.document.data.appid.value;
	var clase		= parent.list.document.data.clase.value;
	var id			= parent.list.document.data.id.value;	
	var page		= (parent.list.document.detail.page.value*1)+1;
	var limit		= parent.list.document.detail.limit.value;
	var search_fields	= parent.list.document.detail.dnf.value.split(",");
	var psbk		= parent.list.document.detail.passback.value.split(",");
	var opfr		= parent.list.document.detail.opener_form.value.split(",");
	var fldf		= parent.list.document.detail.field_focus.value.split(",");
	var dff			= "";
	var dfv			= "";
	for (y=0;y<search_fields.length;y++){
		var campo	= "";
		if (eval("parent.form.document.master."+search_fields[y]+"[0]")){
			campo=eval("parent.form.document.master."+search_fields[y]+"[parent.form.document.master."+search_fields[y]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.master."+search_fields[y]+".value");}
		if(campo!=""){
			dff+=search_fields[y]+",";
			dfv+=campo+"|";
		}
	}
	var frame = "parent.list.location.href='gdl.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&search_fields="+dff+"&search_values="+dfv+"&passback="+psbk+"&opener_form="+opfr+"&field_focus="+fldf+"&page="+page+"&limit="+limit+"'";
	eval(frame);
}
function LastPage(){
	var lan			= parent.list.document.data.lan.value;
	var appid		= parent.list.document.data.appid.value;
	var clase		= parent.list.document.data.clase.value;
	var id			= parent.list.document.data.id.value;	
	var page		= parent.list.document.detail.pend.value;
	var limit		= parent.list.document.detail.limit.value;
	var search_fields	= parent.list.document.detail.dnf.value.split(",");
	var psbk		= parent.list.document.detail.passback.value.split(",");
	var opfr		= parent.list.document.detail.opener_form.value.split(",");
	var fldf		= parent.list.document.detail.field_focus.value.split(",");
	var dff			= "";
	var dfv			= "";
	for (y=0;y<search_fields.length;y++){
		var campo	= "";
		if (eval("parent.form.document.master."+search_fields[y]+"[0]")){
			campo=eval("parent.form.document.master."+search_fields[y]+"[parent.form.document.master."+search_fields[y]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.master."+search_fields[y]+".value");}
		if(campo!=""){
			dff+=search_fields[y]+",";
			dfv+=campo+"|";
		}
	}
	var frame = "parent.list.location.href='gdl.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"&search_fields="+dff+"&search_values="+dfv+"&passback="+psbk+"&opener_form="+opfr+"&field_focus="+fldf+"&page="+page+"&limit="+limit+"'";
	eval(frame);
}
function MoveUp(id,status){
	var select_fields	= parent.list.document.detail.dsf.value.split(",");
	var labels_fields	= parent.list.document.detail.dlf.value.split(",");
	//var select_values	= parent.list.document.detail.dsv.value;
	var select_values   = parent.list.document.detail.dsv.value.replace(new RegExp( "\\n", "g" ),"\\n");
	var insert_values	= parent.list.document.data.div.value;
	var update_values	= parent.list.document.data.duv.value;
	var labels_values	= parent.list.document.detail.dlv.value.split("~~");
	var href			= "";
	if(status == true){
		select_update_values	= select_values + update_values;
		datos 			= select_update_values.split("~~");
	}else{	datos = insert_values.split("~~");}
	cu=datos[id-1].split("|");
	for (var i=0;i<select_fields.length;i++){
		//alert(select_fields[i]);		
		if (eval("parent.form.document.master."+select_fields[i]+"[0]")){
			idx=0;
			listlength = eval("parent.form.document.master."+select_fields[i]+".options.length");
			for (var j=0;j<listlength;j++){
				opt=eval("parent.form.document.master."+select_fields[i]+".options["+j+"].value");
				if ( opt== cu[i]){idx = j;}
			}
			eval("parent.form.document.master."+select_fields[i]+"["+idx+"]"+".selected=true");
		}else{ eval("parent.form.document.master."+select_fields[i]+".value=\""+cu[i]+"\""); }
	}
	cu=labels_values[id-1].split("|");
	for (i=0;i<labels_fields.length-1;i++){
		//alert(labels_fields[i]);
		if (eval("parent.form.document.master."+labels_fields[i]+"[0]")){
			idx=0;
			listlength = eval("parent.form.document.master."+labels_fields[i]+".options.length");
			for (j=0;j<listlength;j++){
				opt=eval("parent.form.document.master."+labels_fields[i]+".options["+j+"].value");
				if ( opt== cu[i]){idx = j;}
			}
			eval("parent.form.document.master."+labels_fields[i]+"["+idx+"]"+".selected=true");
		}else{ eval("parent.form.document.master."+labels_fields[i]+".value=\""+cu[i]+"\""); }
	}
	parent.form.document.master.i4_count.value=id;
	parent.form.document.master.status.value=status;
	//parent.form.document.all.add.style.visibility='hidden';
	if(parent.form.document.getElementById('add')){parent.form.document.getElementById('add').style.visibility='hidden';}
	//parent.form.document.all.modify.style.visibility='visible';
	if(parent.form.document.getElementById('modify')){parent.form.document.getElementById('modify').style.visibility='visible';}
	if (parent.list.document.detail.passback.value!=""){
		//parent.form.document.all.passback.style.visibility='visible';
		if(parent.form.document.getElementById('passback')){parent.form.document.getElementById('passback').style.visibility='visible';}
	}
} 
function PassBack(form,field_focus){
	count  = parent.form.document.master.i4_count.value;
	if(count>0){
		select_fields = parent.list.document.detail.dsf.value;
		fields	= select_fields.split(",");
		reg	= parent.list.document.detail.dsv.value.split("~~");
		values  = reg[count-1].split("|");
		for (i=0;i<fields.length;i++){
			if (eval(form+"."+fields[i])){
				eval(form+"."+fields[i]+".value='"+values[i]+"'");
			}
		}
		if(field_focus!=""){eval(form+"."+field_focus+".focus()");}
		//parent.form.document.all.passback.style.visibility='hidden';
		if(parent.form.document.getElementById('passback')){parent.form.document.getElementById('passback').style.visibility='hidden';}
		parent.window.close();
		
	}else{alert('Please Select a Record')}
}
function GetBack(component,clase,getback,opener_form,left,top,id_field,field_focus){
	var lan		= parent.list.document.data.lan.value;
	var appid	= parent.list.document.data.appid.value;
	var id		= "";
	if(id_field!=""){
		id = eval("parent.form.document.master."+id_field+".value");
		if(id==""){
			//alert('Please Choose ID Firts');
			return;
		}
	}
	if (!openwindow || openwindow.closed){
		//win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&clase="+clase+"&getback="+getback+"&opener_form="+opener_form+"&id_field="+id_field+"&id="+id+"&field_focus="+field_focus+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=yes,toolbar=no,menu=no')";
		win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&getback="+getback+"&opener_form="+opener_form+"&id_field="+id_field+"&id="+id+"&field_focus="+field_focus+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=yes,toolbar=no,menu=no')";		
		openwindow=eval(win);
	}else{openwindow.focus()}
}
function OpenWindow(component,clase,left,top,id_field){
	var lan		= parent.list.document.data.lan.value;
	var appid	= parent.list.document.data.appid.value;
	var id		= eval("parent.list.document.detail."+id_field+".value");
	if (!openwindow || openwindow.closed){
		//win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";		
		openwindow=eval(win);
	}
	else{openwindow.focus()}
}
function GridOpenWindow(objRef,fldRef){
	var lan		 = parent.list.document.data.lan.value;
	var appid	 = parent.list.document.data.appid.value;
	var select_values= parent.list.document.detail.dsv.value.split("~~");
	var select_fields= parent.list.document.detail.dsf.value.split(",");	
	var component	 = "";
	var clase	 = "";
	var left	 = "";
	var top		 = "";
	var id		 = "";
	var id_field	 = "";
	var objIndx  	 = objRef.name.split("__");
	var references   = parent.list.document.detail.del.value.split("~~");
	for (var i=0;i<references.length;i++){
		var reference = references[i].split("|");
		if(objIndx[0]==reference[0]){
			var event	= reference[3].split("^^");
			var emembers	= event[0].split("^");
			var cmembers	= emembers[1].split(",");
			component	= cmembers[0];
			clase		= cmembers[1];
			left		= cmembers[2];
			top		= cmembers[3];
			id_fields	= cmembers[4];
		}
	}
	var id_field	= id_fields.split(";");
	var select_value= select_values[objIndx[1]-1];
	var record	= select_value.split("|");
	for (i=0;i<record.length;i++){
		for (j=0;j<id_field.length;j++){
			if(id_field[j]==select_fields[i]){
				id+=record[i]+"|";
			}
		}
	}
	if(id!=""){id=id.substr(0,id.length-1)}
	if (!openwindow || openwindow.closed){
		win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width=600,height=400,scrollbars=no,toolbar=no,menu=no')";		
		openwindow=eval(win);
	}else{openwindow.focus()}	
}
//funcion corregida para aceptar mas paramentros de la ventana a abrir
function GridOpenWindow2(objRef,fldRef){
	var lan		 = parent.list.document.data.lan.value;
	var appid	 = parent.list.document.data.appid.value;
	var select_values= parent.list.document.detail.dsv.value.split("~~");
	var select_fields= parent.list.document.detail.dsf.value.split(",");	
	var component	 = "";
	var clase	 = "";
	var left	 = "";
	var top		 = "";
	var id		 = "";
	var id_field	 = "";
	var width	 = "";
	var height	 = "";
	var scrollbars   = "";
	var objIndx  	 = objRef.name.split("__");
	var references   = parent.list.document.detail.del.value.split("~~");
	for (var i=0;i<references.length;i++){
		var reference = references[i].split("|");
		if(objIndx[0]==reference[0]){
			var event	= reference[3].split("^^");
			var emembers	= event[0].split("^");
			var cmembers	= emembers[1].split(",");
			component	= cmembers[0];
			clase		= cmembers[1];
			left		= cmembers[2];
			top		= cmembers[3];
			id_fields	= cmembers[4];
			width	 	= cmembers[5];
			height	 	= cmembers[6];
			scrollbars   	= cmembers[7];
		}
	}
	var id_field	= id_fields.split(";");
	var select_value= select_values[objIndx[1]-1];
	var record	= select_value.split("|");
	for (i=0;i<record.length;i++){
		for (j=0;j<id_field.length;j++){
			if(id_field[j]==select_fields[i]){
				id+=record[i]+"|";
			}
		}
	}
	if(id!=""){id=id.substr(0,id.length-1)}
	if (!openwindow || openwindow.closed){
		//win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width="+width+",height="+height+",scrollbars="+scrollbars+",toolbar=no,menu=no')";
		win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width="+width+",height="+height+",scrollbars="+scrollbars+",toolbar=no,menu=no')";		
		openwindow=eval(win);
	}else{openwindow.focus()}	
}
function ShowCalendar(form,datetype,separator){
	var appid	= document.data.appid.value;
	if (!openwindow || openwindow.closed){
		win ="window.open('/"+appid+"/libraries/html/clnd1.html?pbf="+form+"&datetype="+datetype+"&separator="+separator+"','Calendar','left=200,top=200,width=250,height=250,scrollbars=no,toolbar=no,menu=no')";
		openwindow=eval(win);
	}else{openwindow.focus()}
}
function ShowClock(form){
	var appid	= document.data.appid.value;
	if (!openwindow || openwindow.closed){
		win ="window.open('/"+appid+"/libraries/html/clock.html?pb="+form+"','Calendar','left=200,top=200,width=150,height=125,scrollbars=no,toolbar=no,menu=no')";
		openwindow=eval(win);
	}else{openwindow.focus()}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Auxiliar Functions
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function MarkAll(){
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");	
	var j			= (grid_header.length*1);	
	var T  			= parent.list.document.getElementById('t1');
	var trows 		= T.rows;
	var new_insert		= "";
	for (i = trows.length-1; i != 0; i--) {
		if (T.rows(i).cells(j).firstChild.checked) {
			T.rows(i).cells(j).firstChild.checked=false;			
		}else{T.rows(i).cells(j).firstChild.checked=true}
	}
}
function ValId(pos,name,empty,exist){
	var data=0;
	var value;
	var select_values	= parent.list.document.detail.dsv.value;
	var update_values	= parent.list.document.data.duv.value;
	var insert_values	= parent.list.document.data.div.value;
	var list  		= select_values+update_values+insert_values;

	if (eval("parent.form.document.master."+name+"[0]")){
		value=eval("parent.form.document.master."+name+"[parent.form.document.master."+name+".selectedIndex].value");
	}
	else{
		value=eval("parent.form.document.master."+name+".value");
	}
	if (!value){
		alert(empty);
		return false;
	}
	data = list.split("~~");
	for (i=0;i<data.length;i++){
		field = data[i].split("|");
		if (field[pos] == value){
			alert(exist);
			return false;
		}
	}
	return true;	
}
function ReloadOpener(){
	var lan		= parent.list.document.data.lan.value;
	var appid	= parent.list.document.data.appid.value;
	var clase	= parent.list.document.data.clase.value;	
	var abridor	= parent.list.document.detail.opener_form.value;
	var id		= parent.form.document.data.id.value;
	yo = abridor+".location.href='menul.exe?lan="+lan+"&appid="+appid+"&clase=user_menus&id="+id+"'";
	//alert(yo);
	eval(yo);
	//var i8_cont_id=document.form.i8_contribuyente_id.value;
	//eval("this.location.href='##appidf_100.pl?lan=##lan&appid=##appid&org_name=##org_name&i8_file_id=##i8_file_id&i8_contribuyente_id="+i8_cont_id+"'");	
}
function Hilite(){
	//var tname=event.srcElement.tagName;
	//var eName = event.srcElement;
	//eName.bgColor = "#D5D5D5";
	//var trName=eName.parentElement;
	//trName.style.backgroundColor = "#D5D5D5";
	//trName.style.cursor = "hand";
}
function Restore(){
	//var eName = event.srcElement;
	//var trName=eName.parentElement;
	//trName.style.cursor = "";
	//trName.style.backgroundColor = "#FFFFFF";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function GridOpenWindowPl(objRef,fldRef){
	var lan		 = parent.list.document.data.lan.value;
	var appid	 = parent.list.document.data.appid.value;
	var select_values= parent.list.document.detail.dsv.value.split("~~");
	var select_fields= parent.list.document.detail.dsf.value.split(",");	
	var component	 = "";
	var clase	 = "";
	var left	 = "";
	var top		 = "";
	var id		 = "";
	var id_field	 = "";
	var objIndx  	 = objRef.name.split("__");
	var references   = parent.list.document.detail.del.value.split("~~");
	for (var i=0;i<references.length;i++){
		var reference = references[i].split("|");
		if(objIndx[0]==reference[0]){
			var event	= reference[3].split("^^");
			var emembers	= event[0].split("^");
			var cmembers	= emembers[1].split(",");
			component	= cmembers[0];
			clase		= cmembers[1];
			left		= cmembers[2];
			top		= cmembers[3];
			id_fields	= cmembers[4];
		}
	}
	var id_field	= id_fields.split(";");
	var select_value= select_values[objIndx[1]-1];
	var record	= select_value.split("|");
	for (i=0;i<record.length;i++){
		for (j=0;j<id_field.length;j++){
			if(id_field[j]==select_fields[i]){
				id+=record[i]+"|";
			}
		}
	}
	if(id!=""){id=id.substr(0,id.length-1)}
	if (!openwindow || openwindow.closed){
		win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width=600,height=400,scrollbars=no,toolbar=no,menu=no')";
		openwindow=eval(win);
	}else{openwindow.focus()}	
}