function chng(x) {
if(x==0) valact()
if(x==8) sumadc()
}
//function exswap()
//{
	//return
//}
function item2(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
document.dte33form.elements[row+1].value= document.dte33form.elements[row+2].value
if(document.dte33form.elements[row+1].value!="")
	{
		document.dte33form.elements[row+3].value=und[document.dte33form.elements[row+1].value]
		document.dte33form.elements[row+5].value=prc[document.dte33form.elements[row+1].value]
	}
	else
	{
		document.dte33form.elements[row+3].value=""
		document.dte33form.elements[row+4].value=""
		document.dte33form.elements[row+5].value=""
		document.dte33form.elements[row+6].value=""
		document.dte33form.elements[row+7].value=""
	}
sumadc()
}
function item1(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
document.dte33form.elements[row+2].value= document.dte33form.elements[row+1].value
if(document.dte33form.elements[row+1].value!="")
        {
                document.dte33form.elements[row+3].value=und[document.dte33form.elements[row+1].value]
                document.dte33form.elements[row+5].value=prc[document.dte33form.elements[row+1].value]
        }
        else
        {
                document.dte33form.elements[row+3].value=""
                document.dte33form.elements[row+4].value=""
                document.dte33form.elements[row+5].value=""
                document.dte33form.elements[row+6].value=""
		document.dte33form.elements[row+7].value=""
        }
sumadc()
}

function cons(xx) { botonpres=xx.value }
function closeform()
{
        swapin()
        fld=0
        if(botonpres=="Consultar")
        {
                for(i=0;i<nhd+ncd;i++) if( document.dte33form.elements[i].value!="") fld=1
                if(fld==0) document.dte33form.elements[0].value=""
                return true
        }
	return true
}
function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.dte33form.elements[row].value)-1
if(document.dte33form.elements[row+1].value !="")
if(document.dte33form.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.dte33form.elements[nhd+i*ncd+j].value=document.dte33form.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.dte33form.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.dte33form.elements[nhd+i*ncd+j].value=document.dte33form.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.dte33form.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.dte33form.elements[i].value=""
	if(document.dte33form.elements[i].type=="checkbox")
		document.dte33form.elements[i].checked=false
}
document.dte33form.elements[i++].disabled=false
document.dte33form.elements[i++].disabled=true
document.dte33form.elements[0].readOnly=false
tp=0
for (j=i;j< document.dte33form.elements.length;j++)
if(document.dte33form.elements[j].type=="text") document.dte33form.elements[j].value=""
swapout()
}
function sumadc()
{
        swapin()
        sumadb=0
        sumacr=0
        for(i=0;i<nrd;i++)
        {

                row=nhd+ncd*i
                if(document.dte33form.elements[row].value!="") sumadb +=document.dte33form.elements[row+6].value/1
        }
        document.dte33form.NT.value=punto0(sumadb)
        dscg=document.dte33form.dte33H08.value
	if(dscg/1 >50) document.dte33form.DS.value=dscg
	else document.dte33form.DS.value=punto0(dscg*document.dte33form.NT.value/100)
        document.dte33form.IV.value=punto0((sumadb/1-document.dte33form.DS.value/1)*.19)
        document.dte33form.TT.value=punto0((sumadb/1-document.dte33form.DS.value/1)*1.19)
}

function calc(rrow)
{
        row=nhd+nrd*ncd+rrow*(ncd+1)
        if(document.dte33form.elements[row+2].value/1)
        {
                cant=document.dte33form.elements[row+4].value/1
                unit=document.dte33form.elements[row+5].value/1
                desc=document.dte33form.elements[row+6].value/1
		mont=0
                if(!cant) cant=""
                if(!unit) unit=""
                if(!mont) mont=""
                if(!desc) desc=""
		if(desc>50) mont=cant*unit - desc
		else mont=cant*unit*(100-desc)/100
                document.dte33form.elements[row+4].value=cant
                document.dte33form.elements[row+5].value=unit
                document.dte33form.elements[row+6].value=desc
                document.dte33form.elements[row+7].value=punto0(mont)
        }
        else
        {
                document.dte33form.elements[row+4].value=""
                document.dte33form.elements[row+5].value=""
                document.dte33form.elements[row+6].value=""
                document.dte33form.elements[row+7].value=""
        }
sumadc()
}
function punto0(h)
{
        sig=""
        if (h/1 <0) { sig="-" ;h *= -1 }
        h = h/1 + .05
        h=h + ""
        sp=h.split(".")
        if(sp[1]==undefined) sp[1]=""
        sp[1]=sp[1].substr(0,4)
        return(sig+sp[0])
}
function refer()
{
	vari="../refer.htm"
        if(document.dte33form.elements[3].value!="")
        {
        alert(document.dte33form.elements[12].value)
                param="width=800,height=285,top=350,left=240,location=no,toolbar=no,menubar=no,titlebar=no,scrollbars=no,resizable=no,mimimizable=no,dialog=no"
                var obj_calwindow = window.open(vari,"",param)
        }
}
if(document.dte33form.elements[0].value=="") document.dte33form.elements[1].focus()
else sumadc()
