var x = document.getElementById("customers").rows[1].cells.length
var y = document.getElementById("customers").rows.length;
//alert(y + "  " + x)

for (i=0;i<y;i++) if(document.getElementById("customers").rows[i].cells.length >2)
{
e=document.getElementById("customers").rows[i].cells.item(2).innerHTML
ee=e.substr(1,21)
if(ee=="&nbsp;TODAS LAS RUTAS") toru=i
}
//alert("toru="+toru)
//alert(document.getElementById("customers").rows[2].cells.item(2).innerHTML)
//alert(document.getElementById("customers").rows[toru].cells.item(2).innerHTML)
//alert(document.getElementById("customers").rows[toru+2].cells.item(2).innerHTML)
//alert(6+document.getElementById("customers").rows[toru+6].cells.item(2).innerHTML)
//alert(document.getElementById("customers").rows[y-2].cells.item(2).innerHTML)


var prp = new Array()
var rmn = new Array()
for (i=3;i<x-3;i++)
{
	e=document.getElementById("customers").rows[1].cells.item(i).innerHTML
	ee=e.substr(6,e.length-12)
	//alert("ee="+ee)
	if(ee!="NETO")
	{
	//for (j=toru+6;j<y-1;j++) 
		p=document.getElementById("customers").rows[y-2].cells.item(i).innerHTML
		pp=p.substr(7,p.length-14)*1
		prp[i] =pp/1
		//alert("TD="+pp+" RM="+prp[i])
		p=document.getElementById("customers").rows[toru+2].cells.item(i).innerHTML
		pp=p.substr(7,p.length-14)*1
		prp[i] -=pp/1
		//alert("VL="+pp+" RM="+prp[i])
		p=document.getElementById("customers").rows[toru].cells.item(i).innerHTML
		pp=p.substr(7,p.length-14)
		rmn[i]=prp[i]-pp/1
		//alert("RM="+pp+" RM="+rmn[i])
		p=document.getElementById("customers").rows[y-1].cells.item(i)
		p.innerHTML=punto0(rmn[i])+"&nbsp;"
		if(ee!="UND"&&ee!="TUNDS"&&ee!="NETO") for(j=2;j<toru-1;j++) 
		{
			r=document.getElementById("customers").rows[j].cells.item(2).innerHTML
			rr=r.substr(7,r.length-13)
			if(rr!="TOTAL RUTA")
			{
				z=document.getElementById("customers").rows[j].cells.item(i)
				p=z.innerHTML
				pp=p.substr(6,p.length-13)*1
				prp[i] -=pp
				//alert(i +" prp="+prp[i]+" pp=" + pp+" pp+prp="+(pp+prp[i]))
				if(pp && prp[i]>=0) z.style.backgroundColor = "greenyellow"
				else if(pp && prp[i]<0) z.style.backgroundColor = "Aqua"
				if(pp && prp[i]<0 && (prp[i]+pp)>0) z.style.backgroundColor = "LightSalmon"
			}
		}
	}
	//alert(i + " ee=:" + ee+":")

}
function punto0(h)
{
        if (h/1 ==0) return ""
        sig=""
        if (h/1 <0) { sig="-" ;h *= -1 }
        h = h/1 + .5
        h=h + ""
        sp=h.split(".")
        if(sp[1]==undefined) sp[1]="0000"
        return(sig+sp[0])
}

