function chng(x) {
if(x==0) valact()
if(x==6) cusfind(x)
if(x==17 || x==20 || x==22) if(document.pordrform.elements[x].value!=" ") sumadc()
}
//function exswap()
//{
	//return
//}
function cons(xx) { botonpres=xx.value }
function obs(x)
{
	if(document.pordrform.elements[0].value!="") document.pordrform.elements[25].focus()
}
	
function closeform()
{
        swapin()
        fld=0
        if(botonpres=="Consultar")
        {
                for(i=0;i<nhd+ncd;i++) if( document.pordrform.elements[i].value!="") fld=1
                if(fld==0) document.pordrform.elements[0].value=""
                return true
        }
        else
        {
                ll=document.pordrform.elements[0].value
		if (ll.length <6) document.pordrform.elements[26].value="00"
                for (row=0;row<nhd;row++)
                {
                        if(document.pordrform.elements[row].type=="select-one")
                        document.pordrform.elements[row].disabled=false
                        else document.pordrform.elements[row].readOnly=false
                }
                for (row=0;row<lin;row++)
                for (col=0;col<ncd;col++)
                {
                        rrw=nrd*ncd+nhd+row*(ncd+1)+col
                        if(document.pordrform.elements[rrw].type=="select-one")
                        document.pordrform.elements[rrw].disabled=false
                        document.pordrform.elements[rrw].readOnly=false
                }
		return true
        }

	return true
}
function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.pordrform.elements[row].value)-1
if(document.pordrform.elements[row+1].value !="")
if(document.pordrform.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.pordrform.elements[nhd+i*ncd+j].value=document.pordrform.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.pordrform.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.pordrform.elements[nhd+i*ncd+j].value=document.pordrform.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.pordrform.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.pordrform.elements[i].value=""
	if(document.pordrform.elements[i].type=="checkbox")
		document.pordrform.elements[i].checked=false
}
document.pordrform.elements[i++].disabled=false
document.pordrform.elements[i++].disabled=true
document.pordrform.elements[0].readOnly=false
tp=0
for (j=i;j< document.pordrform.elements.length;j++)
if(document.pordrform.elements[j].type=="text") document.pordrform.elements[j].value=""
swapout()
}
function totline(rrow)
{
        fld=nhd+nrd*ncd+rrow*(ncd+1)+3
        qty=document.pordrform.elements[fld].value
        prec=document.pordrform.elements[fld+2].value
        document.pordrform.elements[fld+3].value=punto(qty*prec)
	sumadc()
}
function cuenta(rrow)
{
        fld=nhd+nrd*ncd+rrow*(ncd+1)+1
        e=document.pordrform.elements[fld]
        document.pordrform.elements[fld+1].value=itm[e.value]
        document.pordrform.elements[fld+3].value=punt(prr[e.value])
        document.pordrform.elements[fld+4].value=punt(prr[e.value])
        document.pordrform.elements[fld+2].value=1
        document.pordrform.elements[fld+2].focus()
        document.pordrform.elements[fld+2].select()
	totline(rrow)
}
function cusfind (x)
{
	cust=document.pordrform.elements[x].value
	if(cust!="" && cust!=" " && document.pordrform.elements[0].value !="")
	{
		custom=cus[cust]
		var res=custom.split("^")
		document.pordrform.elements[9].value=res[1]
		document.pordrform.elements[10].value=res[3]
		document.pordrform.elements[12].value=res[2]
		document.pordrform.elements[13].value=res[4]
		document.pordrform.elements[15].value=res[6]
		document.pordrform.elements[16].value=res[5]
		document.pordrform.elements[18].value=res[7]
		document.pordrform.elements[19].value=res[8]
	}
	else
	{
		document.pordrform.elements[9].value=""
		document.pordrform.elements[10].value=""
		document.pordrform.elements[12].value=""
		document.pordrform.elements[13].value=""
		document.pordrform.elements[15].value=""
		document.pordrform.elements[16].value=""
		document.pordrform.elements[18].value=""
		document.pordrform.elements[19].value=""
	}
}
function punt(h)
{
	sig=""
	if (h/1 <0) { sig="-" ;h *= -1 }
        h = h/1 + .005
        h=h + ""
        sp=h.split(".")
        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+"."+sp[1])
}
function desc(ev,row) {
        var unic = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode
        nn=nrd*ncd+nhd+row*(ncd+1)+2
        zr=document.pordrform.elements[nn].value
        if (unic==40 && itl!="")
	for (i=indx+1; i<id.length;i++)
	{
		item=itm[id[i]]
		item=item.toLowerCase()
		c1=item.indexOf(itl)
		if (c1 > -1)
		{
			indx=i
				document.pordrform.elements[nn-1].value=id[i]
				document.pordrform.elements[nn].value=itm[id[i]]
				document.pordrform.elements[nn+2].value=punt(prr[id[indx]])
				document.pordrform.elements[nn+3].value=punt(prr[id[indx]])
			i=id.length
		}
	}
        if (unic==38 && itl!="")
	for (i=indx-1;i>=0;i--)
	{
		item=itm[id[i]]
		item=item.toLowerCase()
		c1=item.indexOf(itl)
		if (c1 > -1)
		{
			indx=i
				document.pordrform.elements[nn-1].value=id[i]
				document.pordrform.elements[nn].value=itm[id[i]]
				document.pordrform.elements[nn+2].value=punt(prr[id[indx]])
				document.pordrform.elements[nn+3].value=punt(prr[id[indx]])
			i=-1
		}
	}
        if (unic!=38 && unic!=40)
        {
		if (unic==8 && itl=="")
		{
			document.pordrform.elements[nn].value=""
			document.pordrform.elements[nn-1].value=""
			document.pordrform.elements[nn+1].value=""
			document.pordrform.elements[nn+2].value=""
			document.pordrform.elements[nn+3].value=""
			document.pordrform.elements[nn+4].value=""
			sumadc()
			itl=""
			return
		}
		if (unic>31 && unic <123)
		{
		itl=itl+String.fromCharCode(ev.charCode)
		if (itl!="")
		{
			itl=itl.toLowerCase()
		ffo=0
		for (i=0;i<id.length;i++)
		{
			item=itm[id[i]]
			item=item.toLowerCase()
			c1=item.indexOf(itl)
			if (c1 > -1)
			{
				indx=i
				document.pordrform.elements[nn-1].value=id[i]
				document.pordrform.elements[nn].value=itm[id[i]]
				document.pordrform.elements[nn+2].value=punt(prr[id[indx]])
				document.pordrform.elements[nn+3].value=punt(prr[id[indx]])
				i=id.length
				ffo=1
			}
		}
		if (ffo==0)
		{
			document.pordrform.elements[nn].value="Not Found " + itl.substr(0,itl.length-1)
			document.pordrform.elements[nn-1].value=""
			document.pordrform.elements[nn+1].value=""
			document.pordrform.elements[nn+2].value=""
			document.pordrform.elements[nn+3].value=""
			document.pordrform.elements[nn+4].value=""
			itl=""
		}
		}
		}
	}
}
function clit(tt,row) {
nn=nrd*ncd+nhd+row*(ncd+1)+3
if (itl!="")
{
	tt.value=itm[id[indx]]
	document.pordrform.elements[nn].value=1
	totline(row)
	itl=""
}
//else document.pordrform.elements[nn-1].value=""

}

function punto(h)
{
        sig=""
        if (h/1 <0) { sig="-" ;h *= -1 }
        h = h/1 + .005
        h=h + ""
        sp=h.split(".")
        sp[1]=sp[1].substr(0,2)
        return(sig+sp[0]+"."+sp[1])
}

function paymnt()
{
	vari="../pymnt.htm"
	if(document.pordrform.elements[0].value!="")
var obj_calwindow = window.open(vari,"","width=920,height=320,top=300,left=170,menubar=no,titlebar=no,scrollbars=no,resizable=no,mimimizable=no,dialog=no")
}
function delivery()
{
	vari="../deliv.htm"
var obj_calwindow = window.open(vari,"","width=500,height=280,top=300,left=120,menubar=no,titlebar=no,scrollbars=no,resizable=no,mimimizable=no,dialog=no")
}
function sumadc()
{
        swapin()
        sumadb=0
        sumacr=0
        for(i=0;i<nrd;i++)
        {

                row=nhd+ncd*i
                if(document.pordrform.elements[row].value!="")
                {
                        sumadb +=(document.pordrform.elements[row+5].value/1)
                     //   sumacr +=(document.pordrform.elements[row+4].value/1)
                }
        }
        document.pordrform.NETO.value=punt(sumadb)
        deliver= document.pordrform.elements[20].value
        taxes=punt((sumadb/1+deliver/1)*document.pordrform.elements[17].value/100 +.0005)
        document.pordrform.TAXES.value=taxes
        document.pordrform.DELIVERY.value= punt(deliver/1)
        total=(sumadb/1 + taxes/1 + deliver/1)
        document.pordrform.TOTAL.value=punt(total/1)
        document.pordrform.elements[21].value=punto(total/1)
}
if(document.pordrform.elements[0].value!="")
{
	sumadc()
	if(document.pordrform.elements[26].value=="50")
	{
		document.pordrform.elements[341].disabled = true
		for (row=0;row<nhd;row++)
		{
			if(document.pordrform.elements[row].type=="select-one")
			document.pordrform.elements[row].disabled=true
			else document.pordrform.elements[row].readOnly=true
		}
		for (row=0;row<lin;row++)
		for (col=0;col<ncd;col++)
		{
			rrw=nrd*ncd+nhd+row*(ncd+1)+col
			if(document.pordrform.elements[rrw].type=="select-one")
			document.pordrform.elements[rrw].disabled=true
			document.pordrform.elements[rrw].readOnly=true
		}
	}
	document.pordrform.elements[340].disabled = false
	document.pordrform.elements[4].readOnly = true
	document.pordrform.elements[5].readOnly = true
}
else 
{
	//document.pordrform.elements[26].value = "00"
	document.pordrform.elements[341].disabled = true
}
var itl=""
