function chng(x) {
if(x==0) valact()
if(x==6) cusfind(x)
if(x==17 || x==20 || x==22) sumadc()
}
function exswap()
{
	return
}
function punt(h)
{
	sig=""
	if (h/1 <0) { sig="-" ;h *= -1 }
	h = h/1 + .005
	h=h + ""
	sp=h.split(".")
	dc=sp[1]
	dc=dc.substr(0,2)
	zz=sp[0].toString()
	r=zz.length
	xx=""
	for (t=r;t>3;t -=3) xx= "," + zz.substr(t-3,3)+ xx
	if(r<4) xx= zz.substr(0,r)
	else xx= zz.substr(0,t)+ xx
	return(sig+xx+"."+sp[1])
}
function punto(h)
{
	sig=""
	if (h=="") return "0.00"
	if (h/1 <0) { sig="-" ;h *= -1 }
	h = h/1 + .005
	h=h + ""
	sp=h.split(".")
	dc=sp[1]
	dc=dc.substr(0,2)
	zz=sp[0].toString()
	return(sig+zz+"."+sp[1])
}

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 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(prc[id[indx]])
				document.pordrform.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.pordrform.elements[nn-1].value=id[i]
				document.pordrform.elements[nn].value=itm[id[i]]
				document.pordrform.elements[nn+2].value=punt(prc[id[indx]])
				document.pordrform.elements[nn+3].value=punt(prc[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 (q=0;q<id.length;q++)
		{
			item=itm[id[q]]
			item=item.toLowerCase()
			c1=item.indexOf(itl)
			if (c1 > -1)
			{
				indx=q
				document.pordrform.elements[nn-1].value=id[q]
				document.pordrform.elements[nn].value=itm[id[q]]
				document.pordrform.elements[nn+2].value=punt(prc[id[indx]])
				document.pordrform.elements[nn+3].value=punt(prc[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 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
	prc=document.pordrform.elements[fld+2].value
	document.pordrform.elements[fld+3].value=punto(qty*prc)
	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(prc[e.value])
	document.pordrform.elements[fld+4].value=punt(prc[e.value])
	document.pordrform.elements[fld+2].value=1
	document.pordrform.elements[fld+2].focus()
	document.pordrform.elements[fld+2].select()
	totline(rrow)
}
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 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 sumadc()
{
	swapin()
	sumaor=0
	sumarc=0
	sumadb=0
	for(i=0;i<nrd;i++)
	{

		row=nhd+ncd*i
		if(document.pordrform.elements[row].value!="")
		{
			sumaor +=(document.pordrform.elements[row+2].value/1)
			sumarc +=(document.pordrform.elements[row+3].value/1)
			sumadb +=(document.pordrform.elements[row+6].value/1)
		     //   sumacr +=(document.pordrform.elements[row+4].value/1)
		}
	}
	document.pordrform.NETO.value=punto(sumadb)
	//taxes=punto(sumadb*document.pordrform.elements[17].value/100)
	document.pordrform.TORDER.value=sumaor
	document.pordrform.TRECE.value=sumarc
	//delivery= document.pordrform.elements[20].value
	//document.pordrform.DELIVERY.value= punto(delivery/1)
	//total=(sumadb/1 + taxes/1 + delivery/1)
	//document.pordrform.TOTAL.value=punto(total/1)
	//document.pordrform.elements[21].value=punto(total/1)
	//document.pordrform.elements[23].value=punto(total-document.pordrform.elements[22].value/1)
}
if(document.pordrform.elements[0].value!="")
{
	sumadc()
	if(document.pordrform.elements[26].value=="50")
	{
		document.pordrform.elements[340].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
		}
	}
	else 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
}
itl=""
