//////////////////////////////////////////////////////////////////////////////////////////////////////////
// INFOSOFT SA DE CV
// Date: 2005-02-01
// Updates:2005-02-03,2006-04-30
// Author:Rodolfo Machon
// File Name: mdfx.js
// Description:
//////////////////////////////////////////////////////////////////////////////////////////////////////////
var openwindow;
var openwindow1;
var master_needed_fields;
var isIE = document.all?true:false;
var isNS = document.layers?true:false;
var ZDigits  = new Array("0","0.0","0.00","0.000","0.0000","0.00000","0.000000");
var DDigits  = new Array("1","10","100","1000","10000","100000","1000000")
var i2_digitos = 2;
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 NewRow			= T.insertRow(0);
	NewRow.style.cssText 	= parent.list.document.detail.tdheader.value;
	for (j=0;j<grid_header.length-1;j++){
		record				= grid_header[j].split("|");
		Cells[j]  			= NewRow.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);
	//alert(Rows);
	for (var i=0;i<Rows+1;i++){	
		k = (i*1)+1;
		NewRow	= T.insertRow(i+1);
		//NewRow.attachEvent('onmouseover',Hilite);
		//NewRow.attachEvent('onmouseout',Restore);		
		//NewRow.style.cssText 	= parent.list.document.detail.tdbody.value;		
		for (j=0;j<grid_header.length-1;j++){
			var checked = "";
			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=1"+fields[j].substr(1,1);
				href += " "+element_properties[j];
				//href += " class=my_style>";
				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();
	if(parent.list.document.data.exist.value=="false"){document.all.save.style.visibility='visible';}
}
function PopulatePage(){
	var id	= parent.list.document.data.id.value;	
	if(id!=""){
		if(parent.list.document.data.exist.value=="true"){
			document.all.save.style.visibility='hidden';
			document.all.preview.style.visibility='visible';			
		}
		ShowMaster();
		//alert(document.getElementById('t1').rows.length);
		if(document.getElementById('t1').rows.length==0){ConstructTable()}
		PopulateTable();
		ProcessTable();
		ProcessPage();		
	}		
}
function Save(){
	if(CheckMasterNeededFields()){
		PassMasterToContainer();
		PassDetailToContainer();
		parent.list.document.data.submit();
	}else{alert(parent.form.document.form.msg_empty.value);}
}
function GetBack(component,clase,getback,opener_form,left,top,id_field,field_focus,search_fields,search_values){
	var lan		= parent.list.document.data.lan.value;
	var appid	= parent.list.document.data.appid.value;
	var id_value	= "";
	if(id_field!=""){
		id_value = eval("parent.form.document.form."+id_field+".value");
		if(id_value==""){
			alert('Please Choose ID Firts');
			return;
		}
	}
	if (!openwindow || openwindow.closed){
		if(search_fields){
			win ="window.open('/cgi-bin/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&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/"+appid+"/bin/"+component+".exe?lan="+lan+"&appid="+appid+"&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')";
		}
		//alert(win);
		openwindow=eval(win);
	}else{openwindow.focus()}
}
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";	
}
function SystemPrintPreview(OLECMDID){ 
	parent.form.document.all.save.style.visibility='hidden';	
	parent.form.document.all.preview.style.visibility='hidden';
	//parent.form.document.all.nuevo.style.visibility='hidden';	
	 //var OLECMDID = 10;/* OLECMDID values: *6- print *7- print preview *8- page setup (for printing) *1- open window  *4- Save As *10- properties  */
	 try{
			var PROMPT = 1; // 1 PROMPT & 2 DONT PROMPT USER 
			var oWebBrowser = document.getElementById("WebBrowser1");
			if(oWebBrowser == null)
			{
				var sWebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; 
				document.body.insertAdjacentHTML('beforeEnd', sWebBrowser); 
				oWebBrowser = document.getElementById("WebBrowser1");
			}
			oWebBrowser.ExecWB(OLECMDID,PROMPT);
	}
	catch(e){alert("Printing failed! " + e.message);}
	//parent.form.document.all.save.style.visibility='visible';	
	parent.form.document.all.preview.style.visibility='visible';
	//parent.form.document.all.nuevo.style.visibility='visible';	
}
function Process(id_field){
	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 		= eval("parent.form.document.form."+id_field+".value");
	parent.list.document.data.id.value = id;
	parent.form.document.form.guardar.focus();
	//alert();
	if(id!=""){
		parent.list.location.href='mdx.exe?lan='+lan+'&appid='+appid+'&clase='+clase+'&id='+id;		
		if(window.AfterProcces) {AfterProcces()}
	}
}
function ShowCalendar(form,datetype,separator){
	var appid	= parent.list.document.data.appid.value;	
	if (!openwindow || openwindow.closed){
		win ="window.open('/"+appid+"/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 appid	= parent.list.document.data.appid.value;
	var lan		= parent.list.document.data.lan.value;
	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('/cgi-bin/"+appid+"/bin/padg.pl?lan="+lan+"&appid="+appid+"&clase="+clase+"&form="+form+"&field="+field_name+"&pers="+pers+"','"+clase+"','left=200,top=200,width=560,height=350,scrollbars=yes,toolbar=no,menu=no,resizable=yes')";
		openwindow1=eval(win);
	}else{openwindow1.focus()}
}
function ShowClock(form){
	var appid	= parent.list.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()}
}
function GridGetBack(objRef,fldRef){
	var lan		= parent.list.document.data.lan.value;
	var appid	= parent.list.document.data.appid.value;
	var id_value	= "";
	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];			
		}
	}
	if(id_field!=""){
		id_value = eval("parent.form.document.form."+id_field+".value");
		if(id_value==""){
			alert('Please Choose ID Firts');
			return;
		}
	}
	var gbFlds  	= getback.split(",");
	getback		= "";
	for (i=0;i<gbFlds.length;i++){
		gbFld = gbFlds[i]+"__"+objIndx[1];
		getback += gbFld+",";
	}
	getback = getback.substr(0,getback.length-1)
	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="+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 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 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=''");
	}
}
function GetClase(){
	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_field	= parent.list.document.data.id.value;
	if(id!=""){
		var frame = "parent.list.location.href='mdx.exe?lan="+lan+"&appid="+appid+"&clase="+clase+"&id="+id+"'";
		eval(frame);
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Auxiliar Sub-Routines Level 1
function CheckMasterNeededFields(){
	master_needed_fields = parent.list.document.detail.mif.value.split(',');
	var needed = true;
	for (i=0;i<master_needed_fields.length;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);
	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+"~~";
		}
	}
	parent.list.document.data.div.value=div;
}
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 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++){
		if (eval("parent.form.document.form."+msf[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."+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++){
			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(){
	//Clear('list.document.detail');
	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:El mandamiento que desea generar excede la cantidad de filas permitidas en el recibo, Por favor genere dos mandamientos");return;}
		else
		{
			for (var j=0;j<detail_if.length;j++){
				//var NewVal = values[j];
				//alert(NewVal);
				//alert(detail_if[j].substring(0,3));
				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 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 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 = "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 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]);}
}
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");
		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_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;
}
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');
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','','','','','','','','');
function makeArray0() {
    for (i = 0; i<makeArray0.arguments.length; i++)
    this[i] = makeArray0.arguments[i];
}
function chequeAmount(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) {
    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){
            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 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;
}
var xmlHttpStream;
function stateChanged(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        xmlHttpStream=xmlHttp.responseText;
    } 
}
