//-------------------------------------------------------//
// Author:Rodolfo Machon
// Company:WebSoft, SA de CV 
// Nombre del archivo: mandamientos_qmdf.js
// Created: 2005-02-01
// Updates: 2016-08-04
// Copyright - All Rights Reserved
//-------------------------------------------------------//
//-------------------------------------------------------//
var openwindow;
var openwindow1;
var xmlHttp;
var xmlHttpStream;
var master_needed_fields;
var isIE 		= document.all?true:false;
var isNS 		= document.layers?true:false;
var DDigits  	= new Array("1","10","100","1000","10000","100000","1000000");
var i2_digitos 	= 2;
var i2_digitos1 = 2;
var i2_digitos2 = 2;
var months		= new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var numbers		= new makeArray0('','un','dos','tres','cuatro','cinco','seis','siete','ocho','nueve','diez','once','doce','trece','catorce','quince','dieciseis','diecisiete','dieciocho','diecinueve','veinte');
var numbers10	= new makeArray0('','diez','veinte','treinta','cuarenta','cincuenta','sesenta','setenta','ochenta','noventa');
var numbers20	= new makeArray0('','diez','veinti','treinta','cuarenta','cincuenta','sesenta','setenta','ochenta','noventa');
var numbers100	= new makeArray0('','cien','doscientos','trescientos','cuatrocientos','quinientos','seiscientos','setecientos','ochocientos','novecientos');
var Numbers100	= new makeArray0('','ciento','doscientos','trescientos','cuatrocientos','quinientos','seiscientos','setecientos','ochocientos','novecientos');
//-------------------------------------------------------//
window.onload = function(){

};
//-------------------------------------------------------//
//LEVEL 1
function ConstructTable(){
	var grid_header		= parent.list.document.detail.dgh.value.split("~~");	
	var grid_body		= parent.list.document.detail.dgv.value.split("~~");
	var T  				= parent.form.document.getElementById('t1');
	var header_length	= (grid_header.length*1);
	var Cells 			= new Array(header_length);
	var fields			= new Array(header_length);	
	var columns_width	= new Array(header_length);	
	var element_type	= new Array(header_length);
	var element_properties	= new Array(header_length);	
	var t_head			= T.createTHead();
	var Rw				= t_head.insertRow(0);

	for (j=0;j<grid_header.length-1;j++)	{
		record					= grid_header[j].split("|");
		Cells[j]  				= Rw.insertCell(j);
		Cells[j].innerHTML		= record[1];
		fields[j]				= record[0];
		columns_width[j]		= record[2];
		element_type[j]			= record[3];
		element_properties[j]	= record[4];		
	}
	var Rows = (parent.list.document.detail.t1BodyRows.value*1);
	for (var i=0;i<Rows+1;i++){	
		k 		= (i*1)+1;
		NewRow	= T.insertRow(i+1);
		for (j=0;j<grid_header.length-1;j++){
			var checked = "";
			var href    = "";			
			if(element_type[j]=="text"){
				href	= "";
			}else if(element_type[j]=="input_text"){
				href  = "<input type=text name="+fields[j]+"__"+k;
				href += " size="+columns_width[j];
				href += " maxlength="+fields[j].substr(1,1);
				href += " "+element_properties[j];
				href += ">";
			}else if(element_type[j]=="input_hidden"){
				href  = "<input type=hidden name="+fields[j]+"__"+k+">";
			}else if(element_type[j]=="checkbox"){
			
			}
			Cells[j]  			= NewRow.insertCell(j);
			Cells[j].innerHTML	= href;
		}
	}
	AddFooter();
}
function PopulatePage(){
	var id	= parent.list.document.data.id.value;
	if(id!="")	{
		ShowMaster();
		if(document.getElementById('t1').rows.length==0){ConstructTable()}
		PopulateTable();
		ProcessTable();
		ProcessPage();
		if(parent.list.document.data.target_id.value !=""){
			if(document.all.save){document.all.save.style.visibility='hidden';}
			if(document.all.preview){document.all.preview.style.visibility='visible';}
			if(document.all.actualizar){document.all.actualizar.style.visibility='visible';}
			if(document.all.memorandum){document.all.memorandum.style.visibility='visible';}			
			if(typeof window.ShowSuccesfull == 'function') {ShowSuccesfull()}
		}
	}		
}
function Save(){
	//alert("1");
	if(CheckMasterNeededFields()){
		//alert("2");		
		PassMasterToContainer();
		//alert("3");
		PassDetailToContainer();
		//alert("4");
		SaveClase();
		//parent.list.document.data.submit();
	}else{alert(parent.form.document.form.msg_empty.value);}
}
function Nuevo(){
	document.all.span2.style.visibility='hidden';	
	document.all.span3.style.visibility='hidden';	
	Clear('form');
	Clear('detail');
	parent.list.document.data.id.value ="";
	parent.list.document.detail.msf.value ="";
	parent.list.document.detail.mlf.value ="";
	parent.list.document.detail.msv.value ="";	
	parent.list.document.detail.mlv.value ="";
	parent.list.document.data.miv.value ="";
	parent.list.document.detail.dsv.value ="";
	parent.list.document.data.div.value ="";
	parent.list.document.data.exist.value ="false";	
}
//-------------------------------------------------------//
//LEVEL 2
function AddFooter(){
	var record	= "";
	var grid_header	= parent.list.document.detail.dgh.value.split("~~");
	var Cells 	= new Array(grid_header.length*1);	
	var T  		= parent.form.document.getElementById('t1');
	var newTFOOT	= T.createTFoot();
	NewRow   	= newTFOOT.insertRow(-1);
	//NewRow.style.cssText = parent.list.document.detail.tdbody.value;//"font-family:Arial,Helvetica,sans-serif;font-size:10px;font-style:normal;color:#000000;font-weight:normal;font-variant:normal;text-transform:none;text-align:left";
	for (j=0;j<grid_header.length-1;j++){
		record		 	= grid_header[j].split("|");		
		var field	 	= record[0];
		var columns_width	= record[2];
		var element_type  	= record[3];
		var element_properties	= record[4];
		href  = "<input type=text name="+field+"__foot";
		href += " size="+columns_width;
		href += " maxlength="+field.substr(1,1);
		href += " "+element_properties;
		href += " class=my_style>";		
		Cells[j]  		= NewRow.insertCell(j);
		Cells[j].innerHTML	= href;
	}	
}
function ShowMaster(){
	var msf = parent.list.document.detail.msf.value.split(',');
	var msv = parent.list.document.detail.msv.value.split('|');
	for (i=0;i<msf.length-1;i++){
		//alert(msf[i])		
		if (eval("parent.form.document.form."+msf[i]+"[0]")){
			//alert("parent.form.document.form."+msf[i]+".options.length");
			listlength = eval("parent.form.document.form."+msf[i]+".options.length");
			idx=0;
			for (j=0;j<listlength;j++){
				opt=eval("parent.form.document.form."+msf[i]+".options["+j+"].value");
				if ( opt== msv[i]){idx = j;}
			}			
			eval("parent.form.document.form."+msf[i]+"["+idx+"]"+".selected=true");
		}else{
			eval("parent.form.document.form."+msf[i]+".value=\""+msv[i]+"\"");
		}
	}
	tmlf = parent.list.document.detail.mlf.value.split('~~');
	tmlv = parent.list.document.detail.mlv.value.split('~~');
	for (h=0;h<tmlv.length-1;h++){
		mlf = tmlf[h].split(',');
		mlv = tmlv[h].split('|');
		for (i=0;i<mlf.length-1;i++){
		   //alert(mlf[i])					
			if (eval("parent.form.document.form."+mlf[i]+"[0]")){
				listlength = eval("parent.form.document.form."+msf[i]+".options.length");
				idx=0;
				for (j=0;j<listlength;j++){
					opt=eval("parent.form.document.form."+msf[i]+".options["+j+"].value");
					if ( opt== msv[i]){idx = j;}
				}			
				eval("parent.form.document.form."+msf[i]+"["+idx+"]"+".selected=true");
			}else{
				eval("parent.form.document.form."+mlf[i]+".value=\""+mlv[i]+"\"");
			}
		}
	}
}
function PopulateTable(){
	var sv 		 		= parent.list.document.detail.dsv.value.split("~~");
	var grid_header	 	= parent.list.document.detail.dgh.value.split("~~");
	var detail_if	 	= parent.list.document.detail.dif.value.split(",");	
	var header_length	= (grid_header.length*1);	
	var fields	 		= new Array(header_length);
	var Filas 			= (parent.list.document.detail.t1BodyRows.value*1);
	for (var i=1;i<sv.length;i++){
		var values = sv[i-1].split("|");
		if(i>=Filas){alert("Error:Este mandamiento excede la cantidad de lineas del recibo, por favor no lo procese"); return;}
		else{
			for (var j=0;j<detail_if.length;j++){
				//alert(detail_if[j])
				if(detail_if[j].substring(0,3)=="d82"){
					NewVal = Math.round(values[j]*DDigits[i2_digitos])/DDigits[i2_digitos];
					values[j] = NewVal.toFixed(i2_digitos); 
				}
				eval("document.form."+detail_if[j]+"__"+i+".value ='"+values[j]+"'");		
			}
		}
	}	
}
function ProcessTable(){
	var FP	 = parent.list.document.detail.dfp.value.split("~~");
	for (var i=0;i<FP.length-1;i++){
		var Members = FP[i].split("|");
		var Field   = Members[0];
		var Process = Members[1];
		var Footer  = Members[2];
		if(Process!=""){RunProcesses(Process);}
		if(Footer!=""){RunFooter(Field,Footer);}
	}
}
function CheckMasterNeededFields(){
	master_needed_fields = parent.list.document.detail.mif.value.split(',');
	var needed = true;
	for (i=0;i<master_needed_fields.length;i++){
		//alert(master_needed_fields[i]);
		if (eval("parent.form.document.form."+master_needed_fields[i]+"[0]")){		
			valor=eval("parent.form.document.form."+master_needed_fields[i]+"[parent.form.document.form."+master_needed_fields[i]+".selectedIndex].value");
		}else if(eval("parent.form.document.form."+master_needed_fields[i])){
			valor=eval("parent.form.document.form."+master_needed_fields[i]+".value");
		}else{
			alert(parent.form.document.form.msg_empty.value+master_needed_fields[i]);
			needed = false;
		}
	}
	return needed;
}
function PassMasterToContainer(){
	var miv  = "";
	id_field = parent.list.document.detail.id_field.value;
	parent.list.document.data.id.value = eval("parent.form.document.form."+id_field+".value");
	for (i=0;i<master_needed_fields.length;i++){
		if (eval("parent.form.document.form."+master_needed_fields[i]+"[0]")){
			campo=eval("parent.form.document.form."+master_needed_fields[i]+"[parent.form.document.form."+master_needed_fields[i]+".selectedIndex].value");
		}else{campo=eval("parent.form.document.form."+master_needed_fields[i]+".value");}
		miv+=campo+"|";
	}
	parent.list.document.data.miv.value=miv;
}
function PassDetailToContainer(){
	var div = "";
	var detail_needed_fields = parent.list.document.detail.dif.value.split(',');
	var Rows = (parent.list.document.detail.t1BodyRows.value*1);
	//alert(Rows);
	for(i=1;i<Rows;i++) {
		if(eval("parent.form.document.form."+detail_needed_fields[0]+"__"+i+".value")!=""){
			for(j=0;j<detail_needed_fields.length;j++) {		
				campo=eval("parent.form.document.form."+detail_needed_fields[j]+"__"+i+".value");
				div+=campo+"|";
			}
			div=div+"~~";
		}
	}
	//alert(div);
	parent.list.document.data.div.value=div;
}
function SaveClase(){
	var clase	= parent.list.document.data.clase.value;
	var miv		= parent.list.document.data.miv.value;
	var div		= parent.list.document.data.div.value;
	var exist	= parent.list.document.data.exist.value;
	var sid		= parent.list.document.data.id.value;
	var tidf	= parent.list.document.detail.target_id_field.value;
	var tid		= eval("parent.form.document.form."+tidf+".value");
	var str		= "clase="+clase+"&sid="+sid+"&tid="+tid+"&miv="+miv+"&div="+div;
	var URL		= "../bin/qmdp.pl";
	xmlHttp	= GetXmlHttpObject(stateChangedSaveClase);
	xmlHttp.open("POST",URL,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send(str);	
}
function stateChangedSaveClase(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    xmlHttpStream=xmlHttp.responseText;
	//document.write(xmlHttpStream);	
	var target  = xmlHttpStream.split("=");
	var rec_id 	= target[1].replace(/\D/g,'');
	//alert(target[0]+"<>"+target[1]);
	if(rec_id!==""){
		var target_id_field = parent.list.document.detail.target_id_field.value;
		var target_id		= target[1];
		//alert("parent.form.document.form."+target_id_field+".value="+target_id);
		eval("parent.form.document.form."+target_id_field+".value='"+target_id+"'")
		//alert(target_id_field);
		LoadClase(target_id_field);
	}else{alert("Error:"+xmlHttpStream)}} 
}
//-------------------------------------------------------//
//LEVEL 3
function RunProcesses(Process){
	var sv 		 = parent.list.document.detail.dsv.value.split("~~");
	for (var j=1;j<sv.length;j++){
		var NewProcess = Process.replace(/indx/g,j);
		eval(NewProcess);
	}
}
function RunFooter(Field,Footer){
	var sv 		 = parent.list.document.detail.dsv.value.split("~~");
	var FooterMembers= Footer.split(",");
	if(FooterMembers[0]=="label"){eval("document.form."+Field+"__foot.value='"+FooterMembers[1]+"'")}
	if(FooterMembers[0]=="function"){eval(FooterMembers[1]);}
}
//-------------------------------------------------------//
//LEVEL 4
function Multiply(CellQty,CellValue,CellSub){
	qty   = eval("document.form."+CellQty+".value");
	value = eval("document.form."+CellValue+".value");
	sub=qty*value;
	sub_formatted=Math.round(sub*DDigits[i2_digitos])/DDigits[i2_digitos];
	eval("document.form."+CellSub+".value='"+sub_formatted.toFixed(i2_digitos)+"'");	
}
function Sum(CellSub){
	var t	= 0;
	var Rows = (parent.list.document.detail.t1BodyRows.value*1);
	for (var j=1;j<=Rows+1;j++){
		var NewCellSub	= CellSub.replace(/indx/g,j);
		var sub		= eval("document.form."+NewCellSub+".value");
		//alert("document.form."+NewCellSub+".value");
		t = (t*1)+(sub*1);
	}
	t_formatted=Math.round(t*DDigits[i2_digitos])/DDigits[i2_digitos];
	
	var NewFooter = CellSub.replace(/indx/g,"foot");
	if(eval("document.form."+NewFooter)){
		eval("document.form."+NewFooter+".value='"+t_formatted.toFixed(i2_digitos1)+"'");
		//alert("document.form."+NewFooter+".value='"+t_formatted.toFixed(i2_digitos)+"'");
		
	}
}
function ConstructPeriods(Pers){
    var marr = ""
    if(Pers!=""){
	var qei	 = "";
	var qes	 = "";
        var Aper = Pers.split(',');
	var DL	 = (Aper.length-1);
        for (var i=0;i<DL;i++){
	    if(qei!=""){
		Year    = qei.substr(0,4);
		Month   = qei.substr(4,2);
		if(Month=="12"){NMonth="01";NYear=(Year*1)+1;Right=NYear+NMonth;next=Right;}else{next=(qei*1)+1}
		if(Aper[i]==next){
		    qes = Aper[i];
		}else{
		    if(qes!=""){
			Year    = qes.substr(0,4);
			Month   = qes.substr(4,2);
			if(Month=="12"){NMonth="01";NYear=(Year*1)+1;Right=NYear+NMonth;next=Right}else{next=(qes*1)+1}
			if(Aper[i]==next){
			    qes = Aper[i];
			}else{
			    Y  = qei.substr(0,4);
			    M  = qei.substr(4,2);
			    Y1 = qes.substr(0,4);
			    M1 = qes.substr(4,2);
			    LM = months[(M*1)-1];
			    LM1= months[(M1*1)-1];
			    if(qes!=""){
				marr += "("+LM+"/"+Y+" a "+LM1+"/"+Y1+"), ";
			    }else{
				marr += LM+"/"+Y+", ";			
			    }
			    qei = "";
			    qes = "";
			    qei = Aper[i];
			}
		    }else{
			Y  = qei.substr(0,4);
			M  = qei.substr(4,2);
			LM = months[(M*1)-1];
			marr += LM+"/"+Y+", ";
			qei = "";
			qei = Aper[i];
		    }
		}
	    }else{
		qei = Aper[i];
	    }
        }
	if(qei!==""){
	    Y  = qei.substr(0,4);
	    M  = qei.substr(4,2);
	    Y1 = qes.substr(0,4);
	    M1 = qes.substr(4,2);
	    LM = months[(M*1)-1];
	    LM1= months[(M1*1)-1];
	    if(qes!=""){
		marr += "("+LM+"/"+Y+" a "+LM1+"/"+Y1+"), ";
	    }else{
		marr += LM+"/"+Y+", ";			
	    }
	}
    }
    marr = marr.substring(0,marr.length-2);
    return marr;
}
function GridMultiply(objRef,CellQty,CellValue,CellSub){
	var objIndx  	= objRef.name.split("__");	
	var ColTotal	= CellSub+"_Total"
	qty   = eval("document.form."+CellQty+"__"+objIndx[1]+".value");
	value = eval("document.form."+CellValue+"__"+objIndx[1]+".value");
	sub=qty*value;
	sub_formatted=Math.round(sub*DDigits[i2_digitos])/DDigits[i2_digitos];
	eval("document.form."+CellSub+"__"+objIndx[1]+".value='"+sub_formatted.toFixed(i2_digitos)+"'");	
	var NCellSub = CellSub+"__indx";
	Sum(NCellSub);
}
function GridGetBack(objRef,fldRef){
	var id_value	= "";
	var id_value_master="";
	var id_value_detail="";
	var id_field	= "";
	var objIndx  	= objRef.name.split("__");
	var references  = parent.list.document.detail.dfr.value.split("~~");
	for (i=0;i<references.length;i++){
		var reference = references[i].split("|");
		if(fldRef==reference[0]){
			var component	= reference[1];
			var clase	= reference[2];
			var getback	= reference[3];
			var opener_form	= reference[4];
			var left	= reference[5];
			var top		= reference[6];
			id_field	= reference[7];
			var  filter	= reference[8];
			if(filter!=""){
				var fld=filter.split(",");
				var id_temp="";
				for(k=0;k<fld.length;k++){
					var tmp_id;
					tmp_id=eval("document.form."+fld[k]+"__"+objIndx[1]+".value");
					if(tmp_id ==""){alert('Please Choose ID Firts');return;}
					if(k==0){id_temp=tmp_id}else{id_temp+="|";id_temp+=tmp_id;}
					id_value_detail=id_temp;
				}
			}
		}
	}
	if(id_field!=""){
		var fltr=id_field.split(",");
		var id_temp="";
		for(k=0;k<fltr.length;k++){
			var tmp_id;
			tmp_id=eval("document.form."+fltr[k]+".value");
			if(tmp_id ==""){alert('Please Choose ID Firts');return;}
			if(k==0){id_temp=tmp_id;}else{id_temp+="|";id_temp+=tmp_id;}
			id_value_master=id_temp;
		}		
	}
	if(id_value_detail==""){id_value=id_value_master}
	if(id_value_master==""){id_value=id_value_detail}
	if(id_value_detail!="" && id_value_master!="" ){id_value=id_value_master+"|"+id_value_detail}
	var gbFlds  	= getback.split(",");
	getback		= "";
	for (i=0;i<gbFlds.length;i++){
		var difName = gbFlds[i].split(";");
		if (difName.length>1) {
			gbFld = difName[0]+"__"+objIndx[1]+"|"+difName[1]+"__"+objIndx[1];
			getback += gbFld+",";
		}else{
			gbFld = gbFlds[i]+"__"+objIndx[1];
			getback += gbFld+",";
		}
	}
	getback = getback.substr(0,getback.length-1)
	if (!openwindow || openwindow.closed){
		win ="window.open('../bin/"+component+".pl?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=eval(win);
	}else{openwindow.focus()}	
}
function GridClean(objRef,cols){
	var objIndx  	= objRef.name.split("__");
	var Columns  	= cols.split(",");
	for (var i=0;i<Columns.length;i++){
		eval("document.form."+Columns[i]+"__"+objIndx[1]+".value=''");
	}
	//Sum(CellSub,ColTotal);
}
function GetClase(){
	var clase	= parent.list.document.data.clase.value;	
	var id_field	= parent.list.document.data.id.value;
	if(id!=""){
		var frame = "parent.list.location.href='qmdx.pl?clase="+clase+"&id="+id+"'";
		eval(frame);
	}
}

//-------------------------------------------------------//
// AUXILIAR
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 Clear(formulario){
	var name ="";
	qty = eval("parent."+formulario+".elements.length");
	for (i=0;i<qty;i++){
		if (eval("parent."+formulario+".elements["+i+"].type")!="hidden"){
			if (eval("parent."+formulario+".elements["+i+"].type")!="button"){			
				name= eval("parent."+formulario+".elements["+i+"].name");
				if(eval("parent."+formulario+"."+name+"[0]")){					
					eval("parent."+formulario+"."+name+"[0].selected=true");
				}
				else{
					eval("parent."+formulario+".elements["+i+"].value=''");
				}
			}
		}
     }
}
function onlyDigits(e,decReq) {
	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 58) ? true:false;
	var dotOK = (key==46 && decReq=='decOK' && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
	window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
	e.which = (!isNum && !dotOK && isNS) ? 0:key;
	return (isNum || dotOK);
}
function Hilite(){
	var tname=event.srcElement.tagName;
	var eName = event.srcElement;
	var trName=eName.parentElement;
	eName.style.backgroundColor = "#D5D5D5";	
	trName.style.backgroundColor = "#D5D5D5";
	eName.style.cursor = "hand";
}
function Restore(Ref){
	var tname=event.srcElement.tagName;	
	var eName = event.srcElement;
	var trName=eName.parentElement;
	eName.style.backgroundColor = "#FFFFFF";
	trName.style.backgroundColor = "#FFFFFF";
	eName.style.cursor = "";	
}
function chequeAmount(input){
	//alert(input);
    var re=/^((\d*)|(\d*(\.\d{1,2})))$/;
    if (!re.test(input)){
        alert("Datos incorrectos en monto, no usar ','\n Ej: 1564.93");
    }else{
        var dollars     = Math.floor(input);
        var cents       = Math.round((input*100 - dollars*100));
        
	var thousands   = (dollars - dollars % 1000) / 1000;
        dollars        -= thousands * 1000;
        var hundreds    = (dollars - dollars % 100) / 100;
        dollars        -= hundreds * 100;
        var output      = '';
        output += (thousands > 0 ? fN(thousands) + ' mil ' : '') +
                    (hundreds > 0 ?  FN(hundreds,dollars) + ' ' : '') +
                    (dollars > 0 ? fN(dollars) + ' ' : '') +
                    'con '+cents + '/100 dolares';
        output          = output.toUpperCase();
        return output.substring(0,1).toUpperCase() + output.substring(1);
    }
}
function FN(i,b){
    if ((i == 1)&&(b > 0)){		
	return Numbers100[i];
    }else{
        if (i<20) return numbers100[i];
    }
    var tens = (i - i % 10) / 10, units = i - (i - i % 10);
    return numbers10[tens] + ((tens > 0 && units > 0) ? '-' : '') + numbers[units];
}
function fN(i) {
	//alert(i);
    if (i<=20) return numbers[i];
    var tens = (i - i % 10) / 10, units = i - (i - i % 10);
    if ( (i > 20)&&(i < 30) ){
            return numbers20[tens] + ((tens > 0 && units > 0) ? '' : '') + numbers[units];
    }
    if ((i>30)&&(i<100)){
            return numbers10[tens] + ((tens > 0 && units > 0) ? ' y ' : '') + numbers[units];
    }
    if (i>=100 && i<110){
	
            var str   = i+"";
            var hunds  = str.substr(0,1)
            tens   = str.substr(1,1)
	    
            units  = str.substr(2,1)
            //alert(hunds+"-"+tens+"-"+units)
            return Numbers100[hunds] + ((hunds > 0 && tens > 0) ? ' ' : ' ') + numbers100[tens] + ((tens > 0 && units > 0) ? ' y ' : '') + numbers[units];    
    }
    if (i>=110 && i<120){
	
            var str   = i+"";
            var hunds  = str.substr(0,1)
            tens   = 0;//str.substr(1,1)
	    
            units  = str.substr(1,2)
            //alert(hunds+"-"+tens+"-"+units)
            return Numbers100[hunds] + ((hunds > 0 && tens > 0) ? ' ' : ' ') + numbers100[tens] + ((tens > 0 && units > 0) ? ' y ' : '') + numbers[units];    
    }
    
    if ((i>=120 && i<130)||(i>=220 && i<230)||(i>=320 && i<330)||(i>=420 && i<430)||(i>=520 && i<530)||(i>=620 && i<630)||(i>=720 && i<730)||(i>=820 && i<830)||(i>=920 && i<930)){
	
            var str   = i+"";
            var hunds  = str.substr(0,1)
            tens   = str.substr(1,1)
	    
            units  = str.substr(2,1)
            //alert(hunds+"-"+tens+"-"+units)
            return Numbers100[hunds] + ((hunds > 0 && tens > 0) ? ' ' : ' ') + numbers20[tens] + ((tens > 0 && units > 0) ? '' : '') + numbers[units];    
    }
    if (i>=130 && i<=999){
	
            var str   = i+"";
            var hunds  = str.substr(0,1)
            tens   = str.substr(1,1)
	    
            units  = str.substr(2,1)
            //alert(hunds+"-"+tens+"-"+units)
            return Numbers100[hunds] + ((hunds > 0 && tens > 0) ? ' ' : ' ') + numbers10[tens] + ((tens > 0 && units > 0) ? ' y ' : '') + numbers[units];    
    }
    
    
}
function fN1(i) {
    if (i<10) return Numbers100[i];
    
}
function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
    this[i] = makeArray0.arguments[i];
}
function ShowCalendar(form,datetype,separator){
	if (!openwindow || openwindow.closed){
		win ="window.open('../libraries/html/clnd.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 Padg(objRef,form,field){
	var clase	= parent.list.document.data.clase.value;
	var field_name 	= objRef.name;
	var pers	= eval("parent.form.document.form."+field_name+".value");
	if (!openwindow1 || openwindow1.closed){
		win ="window.open('../bin/padg.pl?clase="+clase+"&form="+form+"&field="+field_name+"&pers="+pers+"','"+clase+"','left=200,top=200,width=350,height=350,scrollbars=yes,toolbar=no,menu=no,resizable=yes')";
		openwindow1=eval(win);
	}else{openwindow1.focus()}
}
function ShowClock(form){
	if (!openwindow || openwindow.closed){
		win ="window.open('../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()}
}
function GetBack(component,clase,getback,opener_form,left,top,id_field,field_focus){
	var id_value	= "";
	if(id_field!=""){
		var temp=id_field.split(",");
		for(var tmp=0;tmp<temp.length;tmp++){
			id_value += eval("parent.form.document.form."+temp[tmp]+".value");
			id_value+="|";
			if(id_value==""){
				alert('Please Choose ID Firts');
				return;
			}
			
		}
	}
	if (!openwindow || openwindow.closed){
		win ="window.open('../bin/"+component+".pl?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=eval(win);
	}else{openwindow.focus()}
}
//-------------------------------------------------------//
//verificar si son necesarias
