function chng(x) {
if(x==0) valact()
if(x==8) sumadc()
if(x==6) sumadc()
}
function lockform()
{
	if(document.docvtform.elements[1].value!="")
	if(document.docvtform.elements[11].value=="02")
	{
		document.docvtform.elements[687].style.visibility = "visible"
		document.docvtform.elements[11].disabled=false
		document.docvtform.elements[11].value="01"
	}
	else
	{
		document.docvtform.elements[687].style.visibility = "visible"
		//document.docvtform.elements[11].disabled=true
		document.docvtform.elements[11].value="02"
	}
}
function cons(xx) { botonpres=xx.value }
function closeform()
{
        swapin()
        fld=0
        if(botonpres=="Consultar")
        {
                for(i=0;i<nhd+ncd;i++) if( document.docvtform.elements[i].value!="") fld=1
                if(fld==0) document.docvtform.elements[0].value=""
                return true
        }
	return true
}
function pago(rrow)
{
reg=nhd+nrd*ncd+rrow*(ncd+1)
fp=document.docvtform.elements[reg+10]
if(fp.value=="CR" || fp.value=="VL") {document.docvtform.elements[reg+9].value="";document.docvtform.elements[reg+9].readOnly=true }
else document.docvtform.elements[reg+9].readOnly=false
if(document.docvtform.elements[reg+4].value=="")
{
	alert ("LOS PAGOS DEBE EFECTUARSE A TRAVES DEL BOTON \rPAGOS DEL DIA")
	fp.value=""
	document.docvtform.elements[reg+11].value=""
	document.docvtform.elements[reg+10].value=""
	document.docvtform.elements[reg+2].value=""
	document.docvtform.elements[reg+1].value=""
	document.docvtform.elements[reg].value=""
}
}
function cambfp(rrow)
{
reg=nhd+nrd*ncd+rrow*(ncd+1)
fp=document.docvtform.elements[reg+10]
if(fp.value=="CR" || fp.value=="VL") { document.docvtform.elements[reg+9].value="";document.docvtform.elements[reg+9].readOnly=true }
else document.docvtform.elements[reg+9].readOnly=false
sumadc()
}
function cliok(rrow)
{
reg=nhd+nrd*ncd+rrow*(ncd+1)
cli=document.docvtform.elements[reg+1].value
if(cli!="") document.docvtform.elements[reg+2].value=cl[cli]
else document.docvtform.elements[reg+2].value=""
}
function prod(rrow)
{
reg=nhd+nrd*ncd+rrow*(ncd+1)
cli=document.docvtform.elements[reg+1].value
cod=document.docvtform.elements[reg+4].value
if(cli!="")
{
if(np[cli+cod]!=undefined) document.docvtform.elements[reg+6].value=np[cli+cod]
else document.docvtform.elements[reg+6].value=pr[cod]
document.docvtform.elements[reg+5].value=un[cod]
if(document.docvtform.elements[reg+7].value!="") totlin(rrow)
}
else 
{
document.docvtform.elements[reg+4].value=""
document.docvtform.elements[reg+5].value=""
document.docvtform.elements[reg+6].value=""
}
}
function totlin(rrow)
{
reg=nhd+nrd*ncd+rrow*(ncd+1)
prc=document.docvtform.elements[reg+6].value
if(document.docvtform.elements[reg+5].value=="KILOS") cant=document.docvtform.elements[reg+8].value
else cant=document.docvtform.elements[reg+7].value
document.docvtform.elements[reg+9].value=prc*cant
}
function punto(h)
{
        sig=""
        if (h/1 <0) { sig="-" ;h *= -1 }
        h = h/1 + .005/1
        h=h + ""
        sp=h.split(".")
        if(sp[1]==undefined) sp[1]="00"
        sp[1]=sp[1].substr(0,2)
        zz=sp[0].toString()
        r=zz.length
        xx=""
        for (i=r;i>3;i -=3) xx= "." + zz.substr(i-3,3)+ xx
        if(r<4) xx= zz.substr(0,r)
        else xx= zz.substr(0,i)+ xx
        return(sig+xx)
}

function sumadc()
{
        swapin()
        sumakg=0
        sumavt=0
        sumaef=0
        sumach=0
        sumape=0
        sumapc=0
        sumapt=0
        sumatr=0
        sumaun=0
	j=document.docvtform.elements[10].value
        var els = j.split("|")
        for (i=4;i<=100;i+=5) if(els[i]!=undefined)
	{
		if(els[i+1]=="EF") sumape +=els[i]/1
		if(els[i+1]=="CH") sumapc +=els[i]/1
		if(els[i+1]=="TR") sumapt +=els[i]/1
	}
        swapout()
        for(i=0;i<nrd;i++)
        {
                row=nhd+ncd*i
                if(document.docvtform.elements[row].value!="")
                {
                        sumaun +=(document.docvtform.elements[row+6].value/1)
                        sumakg +=(document.docvtform.elements[row+7].value/1)
                        sumavt +=(document.docvtform.elements[row+8].value/1)
                        fp=document.docvtform.elements[row+10].value
                        if(fp=="TR") sumatr +=document.docvtform.elements[row+9].value/1
                        if(fp=="CH") sumach +=document.docvtform.elements[row+9].value/1
                        if(fp=="EF") sumaef +=document.docvtform.elements[row+9].value/1
                }
        }
        document.docvtform.K.value=punto(sumakg)
        document.docvtform.V.value=punto(sumavt)
        document.docvtform.docvtH12.value=sumaef-document.docvtform.elements[6].value-document.docvtform.elements[8].value
	document.docvtform.E.value=0
        document.docvtform.E.value=punto(sumape/1+sumaef/1-document.docvtform.elements[6].value/1-document.docvtform.elements[8].value/1)
        document.docvtform.docvtH13.value=sumach
        document.docvtform.docvtH14.value=sumatr
        document.docvtform.C.value=punto(sumach/1+sumapc/1)
        document.docvtform.T.value=punto(sumatr+sumapt/1)
        document.docvtform.R.value=punto(sumavt-sumaef-sumach)
}

function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.docvtform.elements[row].value)-1
if(document.docvtform.elements[row+1].value !="")
if(document.docvtform.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.docvtform.elements[nhd+i*ncd+j].value=document.docvtform.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.docvtform.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.docvtform.elements[nhd+i*ncd+j].value=document.docvtform.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.docvtform.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.docvtform.elements[i].value=""
	if(document.docvtform.elements[i].type=="checkbox")
		document.docvtform.elements[i].checked=false
}
document.docvtform.elements[i++].disabled=false
document.docvtform.elements[i++].disabled=true
document.docvtform.elements[0].readOnly=false
tp=0
for (j=i;j< document.docvtform.elements.length;j++)
if(document.docvtform.elements[j].type=="text") document.docvtform.elements[j].value=""
swapout()
}
function paymnt()
{
        vari="../pymnt.htm"
        if(document.docvtform.elements[0].value!="")
var obj_calwindow = window.open(vari,"","width=720,height=320,top=300,left=170,menubar=no,titlebar=no,scrollbars=no,resizable=no,mimimizable=no,dialog=no")
}
if(document.docvtform.elements[0].value) sumadc()
if(document.docvtform.elements[11].value=="02")
{
document.docvtform.elements[687].style.visibility = "hidden"
document.docvtform.elements[11].disabled=true
}
        document.docvtform.K.readOnly=true
        document.docvtform.V.readOnly=true
        document.docvtform.E.readOnly=true
        document.docvtform.C.readOnly=true
        document.docvtform.T.readOnly=true
        document.docvtform.R.readOnly=true
