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

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

}

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

function paymnt()
{
	vari="../pymnt.htm"
	if(document.orderform.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.orderform.elements[row].value!="")
                {
                        sumadb +=(document.orderform.elements[row+5].value/1)
                     //   sumacr +=(document.orderform.elements[row+4].value/1)
                }
        }
        document.orderform.NETO.value=punt(sumadb)
        deliver= document.orderform.elements[20].value
        taxes=punt((sumadb/1+deliver/1)*document.orderform.elements[17].value/100 +.0005)
        document.orderform.TAXES.value=taxes
        document.orderform.DELIVERY.value= punt(deliver/1)
        total=(sumadb/1 + taxes/1 + deliver/1)
        document.orderform.TOTAL.value=punt(total/1)
        document.orderform.elements[21].value=punto(total/1)
}
if(document.orderform.elements[0].value!="")
{
	sumadc()
	if(document.orderform.elements[26].value=="50")
	{
		document.orderform.elements[341].disabled = true
		for (row=0;row<nhd;row++)
		{
			if(document.orderform.elements[row].type=="select-one")
			document.orderform.elements[row].disabled=true
			else document.orderform.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.orderform.elements[rrw].type=="select-one")
			document.orderform.elements[rrw].disabled=true
			document.orderform.elements[rrw].readOnly=true
		}
	}
	document.orderform.elements[340].disabled = false
	document.orderform.elements[4].readOnly = true
	document.orderform.elements[5].readOnly = true
}
else 
{
	//document.orderform.elements[26].value = "00"
	document.orderform.elements[343].disabled = true
document.orderform.elements[21].readOnly = false
document.orderform.elements[23].readOnly = false
}
var itl=""
