var clien=""
var text=""
function obr() {
                document.nwcotform.elements[6].value=""
                document.nwcotform.elements[7].value=""
                i=document.nwcotform.elements[2].value
                r=document.nwcotform.elements[5]
                for (j=r.length;j>1;j--) r.remove(j)
                //alert("ST:"+i+":l="+r.length)
                for (j in obra) if(j.indexOf(i)>=0)
                {
//                alert(j+ "=" + i + "="+ j.indexOf(i))
                        b=obra[j]
                        a=b.split("|")
                        var option = document.createElement("option")
                        option.value=j
                        option.text=a[0]
                        r.add(option)
                }
        }
function chng(x) {

if(x==5) {
                document.nwcotform.elements[6].value=""
                i=document.nwcotform.elements[x].value
                if(obra[i]!=undefined)
                {
                        b=obra[i]
                        a=b.split("|")
                        document.nwcotform.elements[6].value=a[1]
                        r=document.nwcotform.elements[2].value
                        document.nwcotform.elements[7].value=i
                }

        }

if(x==0) valact()
}
//function exswap()
//{
	//return
//}
function cons(xx) { botonpres=xx.value }
function closeform()
{
        swapin()
        fld=0
        if(botonpres=="Consultar")
        {
                for(i=0;i<nhd+ncd;i++) if( document.nwcotform.elements[i].value!="") fld=1
                if(fld==0) document.nwcotform.elements[0].value=""
                return true
        }
	return true
}
function insert(rrow)
{
row=nhd+nrd*ncd+rrow*(ncd+1)
rw=(document.nwcotform.elements[row].value)-1
if(document.nwcotform.elements[row+1].value !="")
if(document.nwcotform.elements[nhd+(nrd-1)*ncd].value=="")
{
	swapin()
	for(i=nrd-1;i>rw;i--) for (j=0;j<ncd;j++)
	document.nwcotform.elements[nhd+i*ncd+j].value=document.nwcotform.elements[nhd+i*ncd+j-ncd].value
	for (j=0;j<ncd;j++) document.nwcotform.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.nwcotform.elements[nhd+i*ncd+j].value=document.nwcotform.elements[nhd+i*ncd+j+ncd].value
	for (j=0;j<ncd;j++)
	document.nwcotform.elements[nhd+i*ncd+j].value=""
	swapout()
}
}
function clearform()
{
lreg=nhd+nrd*ncd+lin*(ncd+1)
for (i=0;i<lreg;i++)
{
	document.nwcotform.elements[i].value=""
	if(document.nwcotform.elements[i].type=="checkbox")
		document.nwcotform.elements[i].checked=false
}
document.nwcotform.elements[i++].disabled=false
document.nwcotform.elements[i++].disabled=true
document.nwcotform.elements[0].readOnly=false
tp=0
for (j=i;j< document.nwcotform.elements.length;j++)
if(document.nwcotform.elements[j].type=="text") document.nwcotform.elements[j].value=""
swapout()
}
function pru(ev) {
        var unic = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode
        //alert("PRU:"+unic + "-"+text)
        if(unic==38 || unic==40)
        {
                ij=ii
                i=ii
                while(ij==ii)
                {
                        if(unic==38) i--
                        if(unic==40) i++
                        if(i<1) { i=1;ij=0 }
                        if(i==rut.length) { i=rut.length-1;ij=0 }
                if(ij==ii)
                {
                        clien=rut[i]
                        clien=clien.toLowerCase()
                        if(clien.match(serc))
                        {
                                clien=rut[i]
                                rest=clien.split("\r",1)
                                document.nwcotform.elements[3].value=rest
                                document.nwcotform.elements[4].value=rut[i]
                                document.nwcotform.elements[2].value=inx[i]
                                ii=i
                                i=rut.length
                        }
                }
                }
        }
}
function prs(ev) {
        var unic = ev.keyCode ? ev.keyCode : ev.which ? ev.which : ev.charCode
        text=text+String.fromCharCode(unic)
        serc=text.toLowerCase()
        for (i=1;i<rut.length;i++)
        {
                clien=rut[i]
                clien=clien.toLowerCase()
                if(clien.match(serc))
                {
                        clien=rut[i]
                        rest=clien.split("\r",1)
                        document.nwcotform.elements[3].value=rest
			document.nwcotform.elements[4].value=rut[i]
			document.nwcotform.elements[2].value=inx[i]
                        ii=i
                        i=rut.length
                }
        }
}
document.nwcotform.elements[4].disabled=true
document.nwcotform.elements[6].disabled=true
