lreg=nhd+nrd*ncd+lin*(ncd+1)
if(document.vouchform.elements[lreg].disabled==true) sumadc()
function chng(x) {
if(x==0) valact()
	if(x==1)
	{
		lreg=nhd+nrd*ncd+lin*(ncd+1)+1
		if(document.vouchform.elements[lreg].value!="")
		document.vouchform.elements[lreg].disabled=false
	}
	if(x==3)
	{
		tdc=document.vouchform.elements[3].value
		r=0
		lreg=nhd+r*ncd
		if(document.vouchform.elements[lreg].value=="")
		{
			while (td[tdc+r]!="")
			{
				td1=td[tdc+r]
				t=td1.split("|")
				lreg=nhd+r*ncd
				document.vouchform.elements[lreg].value=t[0]
				document.vouchform.elements[lreg+1].value=t[1]
				document.vouchform.elements[lreg+2].value=t[2]
				r++
			}
			swapout()
		}
	}
}
function cons(xx) { botonpres=xx.value }
function closeform()
{
	swapin()
	mesg=new Array("","Especificar Numero de Doc","Definir Fecha","Especificar Tipo","Cuadratura Falsa","Sin Valores")
	fld=0
	if(botonpres=="Consultar")
	{
		for(i=0;i<nhd;i++) if( document.vouchform.elements[i].value!="") fld=1
		if(fld==0) document.vouchform.elements[0].value="*"
		return true
	}
	else
	{
		swapin()
		sumadc()
		if(document.vouchform.TOTDEB.value==0 || document.vouchform.TOTHAB.value==0) fld=5
		if(document.vouchform.TOTDEB.value!=document.vouchform.TOTHAB.value) fld=4
		if(document.vouchform.elements[3].value=="") fld=3
		if(document.vouchform.elements[2].value=="") fld=2
		if(document.vouchform.elements[1].value=="") fld=1
		if (fld==0) for (i=0; i<nrd;i ++) if(document.vouchform.elements[nhd+i*ncd].value!="")
		{
			lreg=nhd+i*ncd
			cta=ct[document.vouchform.elements[lreg].value]
			c=cta.split("|")
			if (c[0]=="") { fld=6; mesg[6]="Cuenta no imputable en linea " + (1+i)/1}
			if (c[0]=="D" && document.vouchform.elements[lreg+3].value=="")
			{
				fld=7
				mesg[fld]="Cuenta Solo Debito en linea " + (1+i)/1
			}
			if (c[0]=="H" && document.vouchform.elements[lreg+4].value=="")
			{
				fld=8
				mesg[fld]="Cuenta Solo Credito en linea " + (1+i)/1
			}
			if (document.vouchform.elements[lreg+3].value=="" && document.vouchform.elements[lreg+4].value=="")
			{
				fld=9
				mesg[fld]="Linea "+ (1+i)/1 + " sin Cargo/Abono"
			}
			if (c[1]=="1" && document.vouchform.elements[lreg+5].value=="")
			{
				fld=10
				mesg[fld]="Analisis Incompleto linea " + (1+i)/1
			}
	
			//alert(cta+"+" + c[0]+ "-D" + document.vouchform.elements[lreg+3].value)
		}
	}
	if( fld >0)
	{
		alert ("Error "+fld + ": " + mesg[fld])
		return false
	}
	else return true
}
function exswap()
{
	return
}
function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.vouchform.elements[row].value)-1
if(document.vouchform.elements[row+1].value !="")
if(document.vouchform.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.vouchform.elements[nhd+i*ncd+j].value=document.vouchform.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.vouchform.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.vouchform.elements[nhd+i*ncd+j].value=document.vouchform.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.vouchform.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.vouchform.elements[i].value=""
	if(document.vouchform.elements[i].type=="checkbox")
		document.vouchform.elements[i].checked=false
}
document.vouchform.elements[i++].disabled=false
document.vouchform.elements[i++].disabled=true
document.vouchform.elements[0].readOnly=false
for (j=i;j< document.vouchform.elements.length;j++) if(document.vouchform.elements[j].type=="text") document.vouchform.elements[j].value=""
tp=0
swapout()
}
function sumadc()
{
	swapin()
	sumadb=0
	sumacr=0
	for(i=0;i<nrd;i++)
	{
		
		row=nhd+ncd*i
		if(document.vouchform.elements[row].value!="")
		{
			sumadb +=(document.vouchform.elements[row+3].value/1)
			sumacr +=(document.vouchform.elements[row+4].value/1)
		}
	}
	document.vouchform.TOTDEB.value=sumadb
	document.vouchform.TOTHAB.value=sumacr
}
function vd(rrow)
{
	row=nhd+nrd*ncd+rrow*(ncd+1)+5
	if(document.vouchform.elements[row].value != "")
	document.vouchform.elements[row].focus()
}
function vh(rrow)
{
	row=nhd+nrd*ncd+rrow*(ncd+1)+4
	if(document.vouchform.elements[row].value != "")
	document.vouchform.elements[row+2].focus()
}
function cuenta2(rrow)
{
	fld=nhd+nrd*ncd+rrow*(ncd+1)+2
	document.vouchform.elements[fld-1].value=document.vouchform.elements[fld].value
}
function cuenta(rrow)
{
	fld=nhd+nrd*ncd+rrow*(ncd+1)+1
	//ct0=ct[id[document.vouchform.elements[fld].value]]
	//ct1=ct0.split("|")
	document.vouchform.elements[fld+1].value=document.vouchform.elements[fld].value
}
function cta1(rrow,ev) {
	var unic = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode
	fld=nhd+nrd*ncd+rrow*(ncd+1)+2
	if(unic==38) { indx--; if(indx <0) indx=cli.length-1 }
	if(unic==40) { indx++; if(indx == cli.length) indx=0 }
	if(unic!=38 && unic!=40 && unic!=9)
	{
		if(unic >47 && unic <58 || unic>64 && unic <91 || unic==32)
		zr=zr+String.fromCharCode(unic)
		if(unic==8 && l>0) zr=zr.substr(0,l-1)
		indx=-1
		for (i=0;i<ct.length;i++)
		{
			itt=ct[i]
			itt=itt.toUpperCase()
			zr=zr.toUpperCase()
			l=zr.length
			if(zr==itt.substr(zr,l)) { indx=i ; i=cli.length }
		}
		if(indx== -1) document.vouchform.guia1H05.value=zr
		else document.guia1form.vouchH05.value=cli[indx]
	}
	else if(zr!="") document.vouchform.guia1H05.value=cli[indx]
	else document.vouchform.guia1H05.value=""
}
