if(document.ventaform.ventaD0011.value=="L")
{
 document.ventaform.B3.disabled=true
 document.ventaform.B2.disabled=true
}
zz=document.ventaform.elements[1].value
xx=zz.substr(0,10)
zz=today(xx,0)
if (zz!=xx) document.ventaform.B2.disabled=true
if(document.ventaform.elements[0].value=="") document.ventaform.B3.disabled=true
if(document.ventaform.elements[0].value=="") document.ventaform.elements[0].focus()
else document.ventaform.elements[1].focus()
function chng(x) {
if(x==0) valact()
if(x==6) sumadc()
if(x==8) sumadc()
}
function exswap()
{
	return
}
function cons(xx) { botonpres=xx.value }
function closeform()
{
        swapin()
        fld=0
        if(botonpres=="Consultar")
        {
                for(i=0;i<nhd;i++) if( document.ventaform.elements[i].value!="") fld=1
                if(fld==0) document.ventaform.elements[0].value="*"
                return true
        }
	return true
}
function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.ventaform.elements[row].value)-1
if(document.ventaform.elements[row+1].value !="")
if(document.ventaform.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.ventaform.elements[nhd+i*ncd+j].value=document.ventaform.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.ventaform.elements[nhd+i*ncd+j].value=""
	swapout()
}
else alert ("NO PERMITE NUEVA INSERCION")
else
{
	swapin()
	for(i=rw; i<nrd-1;i++) for (j=0;j<ncd;j++)
	document.ventaform.elements[nhd+i*ncd+j].value=document.ventaform.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.ventaform.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.ventaform.elements[i].value=""
	if(document.ventaform.elements[i].type=="checkbox")
		document.ventaform.elements[i].checked=false
}
document.ventaform.elements[i++].disabled=false
document.ventaform.elements[i++].disabled=true
document.ventaform.elements[0].readOnly=false
tp=0
for (j=i;j< document.ventaform.elements.length;j++)
if(document.ventaform.elements[j].type=="text") document.ventaform.elements[j].value=""
swapout()
}

lreg=nhd+nrd*ncd+lin*(ncd+1)
if(document.ventaform.elements[0].value!="") sumadc()
function sumatt()
{
	var ttl = new Array()
	swapin()
	for(j=0;j<ncd;j++) ttl[j]=0
	for(i=0;i<nrd;i++)
	{
		
		row=nhd+ncd*i
		if(document.ventaform.elements[row].value!="")
		{
			if( document.ventaform.elements[row +1].value!="") ttl[1]++
			for(j=2;j<ncd;j++) ttl[j] += (document.ventaform.elements[row +j].value/1)
		}
	}
	row=nhd+ncd*(nrd+lin+1)-5
	for(j=1;j<ncd;j++) if(ttl[j]) document.ventaform.elements[row +j].value=punto(ttl[j])+ " "
}
function sumadc()
{
	swapin()
	sumakg=0
	sumavt=0
	sumaef=0
	sumach=0
	for(i=0;i<nrd;i++)
	{
		
		row=nhd+ncd*i
		if(document.ventaform.elements[row].value!="")
		{
			sumakg +=(document.ventaform.elements[row+12].value/1)
			sumavt +=(document.ventaform.elements[row+13].value/1)
			fp=document.ventaform.elements[row+15].value
			if(fp=="CH") sumach +=(document.ventaform.elements[row+14].value/1)
			if(fp=="EF") sumaef +=(document.ventaform.elements[row+14].value/1)
		}
	}
	document.ventaform.TOTKGS.value="TK: " +punto(sumakg)
	document.ventaform.TOTVTA.value="VT: " +punto(sumavt)
	document.ventaform.TOTEFE.value="EF: " +punto(sumaef - document.ventaform.elements[6].value- document.ventaform.elements[8].value)
	document.ventaform.TOTCHE.value="CH: " + punto(sumach)
	document.ventaform.TOTCRE.value="CR: " +punto(sumavt-sumaef-sumach)
	sumatt()
}
function tkilos(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
sumakg =0
for (i=3;i<9;i++) if(document.ventaform.elements[row+i].value!="" )
	sumakg +=(document.ventaform.elements[row+i].value/1)
if(document.ventaform.elements[row+1].value!="")
	document.ventaform.elements[row+13].value=punto(sumakg)
	sumatt()
}
function lockform()
{
	if(document.ventaform.B2.disabled==true)
	{
	var passw=prompt("PASSWORD:")
	if (passw=="*********")
	document.ventaform.B2.disabled=false
	else alert ("Incorrecta !!!")
	}
	else
	{
		document.ventaform.DOCventa0011.value="L"
		document.ventaform.ventaD0011.value="L"
		document.ventaform.B3.disabled=true
	}
}
function punto(h)
{
	if(h<1000) return(h)
	zz=h.toString()
	r=zz.length
	xx=""
	for (i=r;i>3;i -=3) xx= "." + zz.substr(i-3,3)+ xx
	xx= zz.substr(0,i)+ xx
	return(xx)
}
