//////////////////////////////////////////////////////////////////////////////////////////////////////////
// INFOSOFT SA DE CV
// Date:   2006-05-04
// Updates:2006-05-04
// Author:Rodolfo Machon
// File Name: ltmd.js
// Description:
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var openwindow1;
var indx1;
function ConstructTable(){
	var grid_header		= document.detail.dgh.value.split("~~");
	var grid_values		= document.detail.dgv.value.split("~~");
	var select_values	= document.detail.dsv.value.split("~~");
	var labels_values	= document.detail.dlv.value.split("~~");
	var elements		= document.detail.del.value.split("~~");
	var select_fields	= document.detail.dsf.value.split(",");
	var labels_fields	= document.detail.dlf.value.split(",");
	var T  			= 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;
	var h			= 0;
	var ghl			= grid_header.length;	
	NewRow.style.cssText 	= document.detail.tdheader.value;
	if(document.detail.counter.value=="ON"){Cells[k] = NewRow.insertCell(k);Cells[k].innerHTML = "NO.";k++;l++;}else{ghl--;}
	for (j=k;j<ghl;j++){
		if(k==0){h=j}else{h=j-1}
		var record		= grid_header[h].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(document.detail.dlt.value=="ON"){Cells[l] = NewRow.insertCell(l);Cells[l].innerHTML = "DELETE";}	
	for (var i=1;i<grid_values.length;i++){	
		k		= 0;
		l		= 0;
		var status	= true;
		var svalues 	= new Object;
		var lvalues 	= new Object;
		var srecord	= grid_values[i-1].split("|");
		NewRow		= T.insertRow(i);
		NewRow.style.cssText 	= document.detail.tdbody.value;
		for (j=0;j<srecord.length;j++){
			svalues[select_fields[j]] = srecord[j];
		}
		if(document.detail.counter.value=="ON"){
			Cells[k] = NewRow.insertCell(k);
			if(document.detail.component.value=="gdfl"){Cells[k].innerHTML = "&nbsp;&nbsp;<a name=a"+i+" href='javascript:MoveUp("+i+","+status+")'>"+i+"</a>";}
			if(document.detail.component.value=="srch"||document.detail.component.value=="list"){Cells[k].innerHTML = "&nbsp;&nbsp;<a name=a"+i+" href='javascript:GridPassBack("+i+")'>"+i+"</a>";}
			k++;
			l++;
		}
		for (j=k;j<ghl;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(document.detail.dlt.value=="ON"){Cells[l] = NewRow.insertCell(l);Cells[l].innerHTML = "<input type=checkbox name="+i+">";}
	}
}
function OpenWindow(component,clase,left,top,id_field){
	alert("");
	var lan		= document.data.lan.value;
	var appid	= document.data.appid.value;
	var id		= eval("parent.list.document.detail."+id_field+".value");
	if (!openwindow1 || openwindow1.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=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		openwindow1=eval(win);
	}
	else{openwindow1.focus()}
}
function OpenWindow1(component,clase,getback,opener_form,left,top,id_field,field_focus,id){
	var lan		= document.data.lan.value;
	var appid	= document.data.appid.value;
	if(id_field!=""){
		var grid_values= document.detail.dsv.value.split("~~");
		var select_fields= document.detail.dsf.value.split(",");
		var select_value = grid_values[indx1-1];
		var record	 = select_value.split("|");
		var idf		 = id_field.split(",");
		id		 = "";
		for (i=0;i<select_fields.length;i++){
			for (j=0;j<idf.length;j++){
				if(idf[j]==select_fields[i]){
					id+=record[i]+"|";
				}
			}
		}
	}
	if (!openwindow1 || openwindow1.closed){
		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+"&field_focus="+field_focus+"&id="+id+"','"+component+clase+"','left="+left+",top="+top+",width=100,height=100,scrollbars=no,toolbar=no,menu=no')";
		openwindow1=eval(win);
	}else{openwindow1.focus()}
	close();
}
function GridPassBack(indx){

	var pbf		   		= "";
	var passback_fields	= document.detail.dpf.value.split(",");
	
	var psback	   		= document.detail.passback.value.split(",");
	var select_values  	= document.detail.dsv.value.split("~~");
	var OpenerForm     	= document.detail.opener_form.value;
	
	var OFV		   		= OpenerForm.split("|")
	var FieldFocus     	= document.detail.field_focus.value;
	
	var select_value   	= select_values[indx-1];
	var record	   		= select_value.split("|");
	indx1=indx;
	if(OFV.length>1){
		OpenWindow1(OFV[0],OFV[1],OFV[2],OFV[3],OFV[4],OFV[5],OFV[6],OFV[7],record[0]);
		//parent.window.close();
		return;
	}
	for (i=0;i<record.length;i++){
		for (j=0;j<psback.length;j++){
			var pb	= psback[j].split("|");	
			if(pb[0]==passback_fields[i]){
				if(pb.length>1){pbf=pb[1]}else{pbf=pb[0]}
				if(eval(OpenerForm+"."+pbf)){
					eval(OpenerForm+"."+pbf+".value='"+record[i]+"'");
					
				}
			}
		}
	}
	if(FieldFocus!=""){
		if(eval(OpenerForm+"."+FieldFocus)){
			eval(OpenerForm+"."+FieldFocus+".focus()");
			eval(OpenerForm+"."+FieldFocus+".onchange()");
		}
	}
	if(parent.opener.parent){parent.opener.parent.close()}
	
	parent.close();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Auxiliar Sub-Routines
function Hilite(){
	//var tname=event.srcElement.tagName;
	var eName = event.srcElement;
	//eName.bgColor = "#D5D5D5";
	//var trName=eName.parentElement;
	var trName=eName;	
	trName.style.backgroundColor = "#D5D5D5";
	//trName.style.cursor = "hand";
}
function Restore(){
	var eName = event.srcElement;
	//var trName=eName.parentElement;
	var trName=eName;	
	//trName.style.cursor = "";
	trName.style.backgroundColor = "#FFFFFF";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////