YAHOO.connects = function()
{
var $D = YAHOO.util.Dom;
var $E = YAHOO.util.Event;
var $C = YAHOO.util.Connect;
var $ = $D.get;
return {
  action : function()
  {
    var d = window.document.forms['navinfo'];
    var event = $E.getEvent();
    var sendRequest = function(e)
    {
      if (event.type != 'load')
          var element = $E.getTarget(e);
      var success = function(o)
      {
        var debug = 1;
        var results = o.responseText.split("|");
        if (results[1].substr(0,5) == "ERROR" && debug)
            alert(results[1]);
        var d = window.document.forms['navinfo'];
        if (event.type != 'load'){
            action = element.id.substr(0,6);
            idx    = element.id.substr(6);
        }else{
            action = 'load';
            idx = 0;
        }
        switch(action)
        {
          case 'edtrec':
            resetPanBut();
          case 'delete':
            if (d.delflg.value == 'false')
                break;
          case 'load':
          case 'next':
            if (action == 'next')
            {
               document.getElementById('prev').setAttribute('class','on');
               document.getElementById('prev').setAttribute('className','on');
               document.getElementById('prev').disabled = false;
            }
          case 'prev': 
            if (action == 'prev')
            {
               document.getElementById('next').setAttribute('class','on');
               document.getElementById('next').setAttribute('className','on');
               document.getElementById('next').disabled = false;
            }
            YAHOO.contain.resize.findList.hide();
            YAHOO.contain.resize.findLike.hide();
            d.addupd.value = "Update";
            d.addupd.title = "Update this record";
            var rx = 1;
            rx = readRec(results,rx);
            if (d.fndbeg.value == "BEG")
            {
                document.getElementById('prev').setAttribute('class','off');
                document.getElementById('prev').setAttribute('className','off');
                document.getElementById('prev').disabled = true;
            }
            if (d.fndend.value == "END")
            {
                document.getElementById('next').setAttribute('class','off');
                document.getElementById('next').setAttribute('className','off');
                document.getElementById('next').disabled = true;
            }
          case 'addlin':
            if (action == "addlin")
            {
                addlin(idx);
                rx=1;
            }
            var maxlnid = document.getElementById('reclin').maxlnid.value-1;
            var tabbod = document.getElementById('tabbod');
            creAddLine(d.invid.value,tabbod,maxlnid);
            break;
          case 'updlin':
                rx=1;
                YAHOO.contain.resize.btnConfirm.setBody('   Update was Successful   ');
                YAHOO.contain.resize.btnConfirm.render(document.body);
                YAHOO.contain.resize.btnConfirm.show();
                YAHOO.contain.resize.btnConfirm.cfg.setProperty('x',400);
                YAHOO.contain.resize.btnConfirm.cfg.setProperty('y',300);
                setTimeout("YAHOO.contain.resize.btnConfirm.hide()",2000);
            break;
          case 'dellin':
            if (d.delflg.value == 'true')
            {
                rx=1;
                var el = document.getElementById('reclin'+idx);
                el.parentNode.removeChild(el);
            }
            break;
        case 'find':
            YAHOO.contain.resize.findList.hide();
            document.getElementById('fndlik').value = "";
            YAHOO.contain.resize.findLike.cfg.setProperty('context',['find','tl','br']);
            YAHOO.contain.resize.findLike.show();
            break;
        case 'fndprv':
        case 'fndnxt':
            d.addupd.value = "Update";
            d.addupd.title = "Update this record";
        case 'fndlik':
            var rx = 1;
            d.fndtot.value = results[rx++];
            d.fndbeg.value = results[rx++];
            d.fndend.value = results[rx++];
            if (d.fndtot.value == -1)
            {			//just edit found record
                readRec(results,rx);
                var maxlnid = document.getElementById('reclin').maxlnid.value-1;
                var tabbod = document.getElementById('tabbod');
                creAddLine(d.stkid.value,tabbod,maxlnid);
            }
            else			//display edit list
            {
                var newform = document.createElement('FORM');
                var newtab  = document.createElement('TABLE');
                var newtbod = document.createElement('TBODY');
                newtab.appendChild(newtbod);
                newform.appendChild(newtab);
                for (x=0;x<d.fndtot.value;x++)
                { 
                    var tr = document.createElement('TR');
                    var td1 = document.createElement('TD');
                    td1.setAttribute('class','list');
                    td1.setAttribute('className','list');
                    var inp1 = document.createElement('INPUT');
                    inp1.setAttribute('style','height:12px');
                    inp1.setAttribute('id','edtrec'+x);
                    inp1.setAttribute('type','checkbox');
                    inp1.setAttribute('value',escape(results[rx+1]));
                    inp1.onclick = new Function("YAHOO.contain.resize.findList.hide();");
                    var inp2 = document.createElement('INPUT');
                    inp2.setAttribute('id','invid'+x);
                    inp2.setAttribute('type','hidden');
                    inp2.setAttribute('value',escape(results[rx]));
                    var td2= document.createElement('TD');
                    td2.setAttribute('class','list');
                    td2.setAttribute('className','list');
                    td2.innerHTML = results[rx++];
                    var td3 = document.createElement('TD');
                    td3.setAttribute('class','list');
                    td3.setAttribute('className','list');
                    td3.innerHTML = results[rx++];
                    var td4 = document.createElement('TD');
                    td4.setAttribute('class','list');
                    td4.setAttribute('className','list');
                    td4.innerHTML = results[rx++];
                    td1.appendChild(inp1);
                    td1.appendChild(inp2);
                    tr.appendChild(td1);
                    tr.appendChild(td2);
                    tr.appendChild(td3);
                    tr.appendChild(td4);
                    newtbod.appendChild(tr);
                }
                var tr = document.createElement('TR');
                tr.setAttribute('align','left');
                //create TD for buttons
                var td = document.createElement('TD');
                td.setAttribute('colSpan','4');
                td.setAttribute('style','text-align:center;width:400px;');
                tr.appendChild(td);
                //add prev button
                var but = document.createElement('button');
                but.setAttribute('id','fndprv');
                but.setAttribute('type','button');
                if (d.fndbeg.value == "BEG")
                {
                    but.setAttribute('class','off');
                    but.setAttribute('className','off');
                    but.setAttribute('disabled','disabled');
                }
                but.innerHTML = "Prev";
                td.appendChild(but);
                //add next button
                var but = document.createElement('button');
                but.setAttribute('id','fndnxt');
                but.setAttribute('type','button');
                if (d.fndend.value == "END")
                {
                    but.setAttribute('class','off');
                    but.setAttribute('className','off');
                    but.setAttribute('disabled','disabled');
                }
                but.innerHTML = "Next";
                td.appendChild(but);
                //add close button
                var but = document.createElement('button');  
                but.setAttribute('type','button');
                but.innerHTML = "Close";
                but.onclick = new Function("YAHOO.contain.resize.findList.hide();");
                td.appendChild(but);
                newtbod.appendChild(tr);
                YAHOO.contain.resize.findList.setBody(newform);
                YAHOO.contain.resize.findList.render(document.body);
                for (x=0;x<d.fndtot.value;x++)
                    YAHOO.util.Event.addListener('edtrec'+x,"click",sendRequest);
                YAHOO.util.Event.addListener('fndprv',"click",sendRequest);
                YAHOO.util.Event.addListener('fndnxt',"click",sendRequest);
                YAHOO.contain.resize.findList.cfg.setProperty('context',['find','tl','bl']);
                YAHOO.contain.resize.findList.show();
            }
            break;
          case 'addnew':
            init();
            resetPanBut();
            d.addupd.value = "Add This";
            d.addupd.title = "Add this record";
            break;
          case 'addupd':
            if (d.addupd.value == "Add This")
            {
                d.addupd.value = "Update";
                d.addupd.title = "Update this record";
                document.getElementById('invid').value = results[1];
                document.getElementById('reclin').maxlnid.value = 1;
            }
            else
            {
                YAHOO.contain.resize.btnConfirm.setBody('   Update was Successful   ');
                YAHOO.contain.resize.btnConfirm.render(document.body);
                YAHOO.contain.resize.btnConfirm.show();
                setTimeout("YAHOO.contain.resize.btnConfirm.hide()",2000);
            }
            break;
        }
    };	//end success
    var failure = function(o)
    {
      alert('no connection to server');
    };	//end failure
    if (event.type != 'load'){
        idx = element.id.substr(6);
        action = element.id.substr(0,6);
    }else{
        idx = 0;
        action = 'load';
    }
    //create url for passing to the php Ajax interceptor
    var url = 'deinvdemo.php';
    switch(action)
    {
        case 'load':
            var pvars = 'ajax=true&action=load';
            break;
          case 'addupd':
              var errlist = '';
              errlist = checkErrors();
              if (errlist.length > 0)
                  alert(errlist);
              if (d.addupd.value == "Add This" && d.title.value.length == 0)
                  alert('You must first enter a title');
              var pvars = 'ajax=true&action='+action+'&addupd='+escape(d.addupd.value)+'&invid='+d.invid.value+'&title='+escape(d.title.value)+'&invdate='+escape(d.invdate.value)+'&duedate='+escape(d.duedate.value)+'&paydate='+escape(d.paydate.value)+'&company='+escape(d.company.value)+'&terms='+escape(d.terms.value)+'&ponum='+d.ponum.value+'&sonum='+d.sonum.value+'&status='+d.status.value+'&amtdue='+escape(d.amtdue.value)+'&confirm='+d.confirm.value;
              break;
          case 'delete':
              if (confirm('Are you sure you want to delete "'+d.title.value+'"? Yes = OK, No = Cancel'))
              {
                  d.delflg.value = true;
                  var pvars = 'ajax=true&action='+action+'&invid='+d.invid.value+'&title='+escape(d.title.value)+'&delflg='+d.delflg.value;
              }
              else
              {
                  d.delflg.value = false;
                 var pvars = 'ajax=true&action='+action+'&delflg='+d.delflg.value;
              }
              break;
          case 'edtrec':
              var pvars = 'ajax=true&action='+action+'&invid='+escape(document.getElementById('invid'+idx).value);
              break;
          case 'fndlik':
              if (YAHOO.util.Event.getCharCode(e) != 13)
                  return;
              YAHOO.contain.resize.findLike.hide();
              var pvars = 'ajax=true&action='+action+'&fndlik='+document.getElementById('fndlik').value;
              break;
          case 'fndprv':
              var pvars = 'ajax=true&action='+action+'&fndbeg='+document.getElementById('fndbeg').value;
              break;
          case 'fndnxt':
              var pvars = 'ajax=true&action='+action+'&fndend='+document.getElementById('fndend').value;
              break;
          case 'addnew':
          case 'next':
          case 'prev':
          case 'find':
              var pvars = 'ajax=true&action='+action+'&invid='+escape(d.invid.value)+'&title='+escape(d.title.value);
              break;
              case 'dellin':
                  if (confirm('Are you sure you want to delete line# '+(parseInt(idx)+1)+'? Yes = OK, No = Cancel'))
                  {
                      d.delflg.value = true;
                      //var pvars = 'ajax=true&action='+action+'&invid='+document.getElementById('invid'+idx).value+'&lineid='+document.getElementById('lineid'+idx).value+'&delflg='+d.delflg.value;
                      var pvars = 'ajax=true&action='+action+'&invid='+document.getElementById('invid').value+'&lineid='+document.getElementById('lineid'+idx).value+'&delflg='+d.delflg.value;
                  }
                  else
                  {
                      d.delflg.value = false;
                      var pvars = 'ajax=true&action='+action+'&delflg='+d.delflg.value;
                  }
                  break;
              case 'updlin':
              case 'addlin':
                  if (document.getElementById('invid').value == 0)
                      alert('You must first \'Add This\' invoice above.');
                  else
                  {
                      var pvars = 'ajax=true&action='+action+'&invid='+document.getElementById('invid').value
+'&lineid='+document.getElementById('lineid'+idx).value+'&lineno='+document.getElementById('lineno'+idx).value+'&paytype='+document.getElementById('paytype'+idx).value+'&quantity='+document.getElementById('quantity'+idx).value+'&description='+escape(document.getElementById('description'+idx).value)+'&hours='+document.getElementById('hours'+idx).value+'&rate='+document.getElementById('rate'+idx).value+'&amount='+document.getElementById('amount'+idx).value;
                   }
      }
      var callback = 
      {
        success : success,
        failure : failure
      };	//end callback 
      var cObj = $C.asyncRequest('POST',url,callback,pvars);
    };	//end sendRequest
    if (event.type == 'load')
        sendRequest();
    else if (this.type == 'text')
        $E.on(this,'keypress',sendRequest);
    else if (this.type == 'file')
        $E.on(this,'change',sendRequest);
    else
        $E.on(this,'click',sendRequest); 
  }	//end action
  };	//end return
}();	//end connects

YAHOO.util.Event.addListener(window, 'load', YAHOO.connects.action);
YAHOO.util.Event.addListener(window, 'load', initPanels);
YAHOO.util.Event.onAvailable('find',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('fndlik',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('next',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('prev',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('addnew',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('addupd',YAHOO.connects.action);
YAHOO.util.Event.onAvailable('delete',YAHOO.connects.action);

function init()
{
    var d = window.document.forms['navinfo'];
    d.addupd.value = "Add This";
    d.invid.value = 0;
    d.title.value = "";
    d.invdate.value = "";
    d.duedate.value = "";
    d.paydate.value = "";
    d.company.value = "";
    d.terms.value = "";
    d.ponum.value = 0;
    d.sonum.value = 0;
    d.status.value = 1;
    d.amtdue.value = 0;
    if (document.getElementById('reclin'))
    {
        var el = document.getElementById('reclin');
        el.parentNode.removeChild(el);
    }
    var tabbod = reclinForm();
    addLineHead(tabbod);
    creAddLine(0,tabbod,-1);
}

YAHOO.namespace("contain.resize");
function initPanels()
{
YAHOO.contain.resize.btnConfirm = new YAHOO.widget.ResizePanel("btnConfirm", { effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, width:"auto", constraintoviewport: true, underlay:"shadow", close:true, visible:false, x:400, y:30, close:false, draggable:true, modal:false });
YAHOO.contain.resize.btnConfirm.setHeader('');

YAHOO.contain.resize.findLike = new YAHOO.widget.ResizePanel("findLike", { effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, width:"auto", constraintoviewport: true, underlay:"shadow", close:true, visible:false, draggable:true, modal:false });
YAHOO.contain.resize.findLike.setHeader('Find invoice like:');
YAHOO.contain.resize.findLike.setBody('<div>Enter title: <input id="fndlik" name="fndlik" size="30");/></div>');
YAHOO.contain.resize.findLike.render(document.body);

YAHOO.contain.resize.findList = new YAHOO.widget.ResizePanel("findList", {effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}, width:"auto", constraintoviewport: true, underlay:"shadow", close:true, visible:false, draggable:true, modal:false });

YAHOO.contain.resize.findList.setHeader('Invdemo List');
init();
}

function checkVal(id,type)
{
   var el = document.getElementById(id).value;
   if (type == "int" || type == "float")
   {
       var num = parseFloat(el)
       if(isNaN(num))
       {
           alert('Please enter a valid number');
           document.getElementById(id).value = 0;
           return false;
       }
   }
   else if (type == "date")
   {
       var pos1=el.indexOf('/');
       var pos2=el.lastIndexOf('/');
       if (pos1 < 1 || pos2 < 1 || pos1 == pos2)
       {
           alert('Please enter a valid date (mm/dd/yyyy)');
           document.getElementById(id).value = "";
           return false;
       }
       var mth  = Number(el.substr(0,pos1));
       var day  = Number(el.substr(pos1+1,pos2-pos1-1));
       var year = Number(el.substr(pos2+1));
       if (mth == mth.NaN || day == day.NaN || year == year.NaN)
       {
           alert('Please enter a valid numeric date (mm/dd/yyyy)');
           document.getElementById(id).value = "";
           return false;
       }
       if (mth < 1 || mth > 12)
       {
           alert('Invalid month - please enter a valid date (mm/dd/yyyy)');
           document.getElementById(id).value = "";
           return false;
       }
       if (day < 1 || day > 31)
       {
           alert('Invalid day - please enter a valid date (mm/dd/yyyy)');
           document.getElementById(id).value = "";
           return false;
       }
       if (year > 99 && (year < 1900 || year > 2050 ))
       {
           alert('Invalid year - please enter a valid date (mm/dd/yyyy)');
           document.getElementById(id).value = "";
          return false;
       }
       return true;
   } 
}

function resetPanBut()
{
    document.getElementById('prev').setAttribute('class','on');
    document.getElementById('prev').setAttribute('className','on');
    document.getElementById('prev').disabled = false;
    document.getElementById('next').setAttribute('class','on');
    document.getElementById('next').setAttribute('className','on');
    document.getElementById('next').disabled = false;
    YAHOO.contain.resize.findList.hide();
    YAHOO.contain.resize.findLike.hide();
}

function readRec(results,rx)
{
    var d = window.document.forms['navinfo'];
    d.addupd.value = results[rx++];
    d.tabtot.value = results[rx++];
    d.fndbeg.value = results[rx++];
    d.fndend.value = results[rx++];
    d.invid.value = results[rx++];
    d.title.value = results[rx++];
    d.invdate.value = results[rx++];
    d.duedate.value = results[rx++];
    d.paydate.value = results[rx++];
    d.company.value = results[rx++];
    d.terms.value = results[rx++];
    d.ponum.value = results[rx++];
    d.sonum.value = results[rx++];
    d.status.value = results[rx++];
    d.amtdue.value = results[rx++];
    rx = loadSelects(results,rx);
    if (document.getElementById('reclin'))
    {
        var el = document.getElementById('reclin');
        el.parentNode.removeChild(el);
    }
    var tabbod = reclinForm();
    addLineHead(tabbod);
    rx = readReclines(tabbod,results,rx);
    return rx;
}

function loadSelects(results,rx)
{
    var d = window.document.forms['navinfo'];
    return rx;
}

function getTD(label)
{
    var td = document.createElement('TD'); 
    if (label.length > 0)
        td.innerHTML = label+":&nbsp;";
    return td;
}

function getINP(id,size,res,type,cls)
{
    var inp = document.createElement('INPUT');
    inp.setAttribute('id',id);
    inp.setAttribute('type',type);
    inp.setAttribute('size',size);
    inp.setAttribute('value',res);
    inp.setAttribute('class',cls);
    inp.setAttribute('className',cls);	//IE requires classname and 'class' is a reserved word
    return inp;
}

function checkErrors(){
    var d = window.document.forms['navinfo'];
    var errlist = '';
    errlist = checkStr(errlist,d.title.id,d.title.value);
    errlist = checkStr(errlist,d.company.id,d.company.value);
    errlist = checkStr(errlist,d.terms.id,d.terms.value);
    return errlist;
}
function checkStr(errlist,id,str){
    if (str.length > 0){
        if (str[0] == ' ')
            errlist=errlist+id+' has leading blank\n';
        if (str[str.length-1] == ' ')
            errlist+=id+' has terminal blank\n';
        words = new Array();
        var idx,lstcom;
        idx = lstcom = 0;
        for (x=0;x<str.length;x++){
            //if (x < str.length && str[x] == ' ' && str[x+1] == ' ')
            //    errlist+=id+' has doubled blanks\n';
            if (str[x] == ','){
                if (x == 0)
                    errlist+=id+' has leading comma\n';
                if (x > 0 && str[x-1] == ' ')
                   errlist+=id+' has blank preceeding comma\n';
                if (x > 0 && str[x-1] == ',')
                   errlist+=id+' has doubled commas\n';
                if (x == str.length-1)
                    errlist+=id+' has terminal comma\n';
                if (id == 'keywords' && x < str.length && str[x+1] == ' ')
                    errlist+=id+' has blank following comma\n';
                words[idx++] = str.substr(lstcom,x-lstcom);
                lstcom = x+1;
            }
        }
        if (id == 'keywords'){
            words[idx++] = str.substr(lstcom,x-lstcom);
            for (y=0;y<idx-1;y++){
                for (z=y+1;z<idx;z++){
                    if (words[y] == words[z])
                        errlist+=words[y]+' dupe at '+y+'-'+z+'\n';
                }
            }
        }
    }
    return errlist;
}
function readReclines(tabbod,results,rx)
{
    document.getElementById('reclin').maxlnid.value = results[rx++];
    for (x=0;x<document.getElementById('reclin').maxlnid.value;x++)
    {
        var tr = document.createElement('TR');
        tr.setAttribute('id','reclin'+x);
        tabbod.appendChild(tr);
        var td  = getTD('');var inp = getINP('lineid'+x,0,results[rx++],'hidden','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('lineno'+x,1,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('paytype'+x,1,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('quantity'+x,1,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('description'+x,28,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('hours'+x,1,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('rate'+x,1,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td  = getTD('');var inp = getINP('amount'+x,2,results[rx++],'text','datent');
        td.appendChild(inp);tr.appendChild(td);
        var td = document.createElement('TD');
        td.setAttribute('id','buttd'+x);
        tr.appendChild(td);
        var but = document.createElement('button');
        but.setAttribute('id','updlin'+x);
        but.setAttribute('type','button');
        but.innerHTML = "Upd";
        td.appendChild(but);
        YAHOO.util.Event.onAvailable('updlin'+x,YAHOO.connects.action);
        var but = document.createElement('button');
        but.setAttribute('id','dellin'+x);
        but.setAttribute('type','button');
        but.innerHTML = "Del";
        td.appendChild(but);
        YAHOO.util.Event.onAvailable('dellin'+x,YAHOO.connects.action);
        tr.appendChild(td); 
    }
    return rx;
}

function reclinForm()
{
    var lineform = document.createElement('FORM');
    lineform.setAttribute('id','reclin');
    document.getElementById('lineanchor').appendChild(lineform);
    var hidinp = document.createElement('INPUT');
    hidinp.setAttribute('type','hidden');
    hidinp.setAttribute('id','maxlnid');
    lineform.appendChild(hidinp);
    var lintab = document.createElement('TABLE');
    lintab.setAttribute('class','datent');
    lintab.setAttribute('className','datent');
    var tabbod = document.createElement('TBODY');
    tabbod.setAttribute('id','tabbod');
    lineform.appendChild(lintab);
    lintab.appendChild(tabbod);
    return tabbod;
}

function addLineHead(tabbod)
{
    var tr = document.createElement('TR');
    tabbod.appendChild(tr);
    var td  = getTD('');var inp = getINP('',0,'','hidden','colhed');
    inp.setAttribute('readonly','readonly');td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',1,'Line#','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',1,'Type','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',1,'Qty','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',28,'Description','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',1,'Hours','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',1,'Rate','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',2,'Amt','text','colhed');
    td.appendChild(inp);tr.appendChild(td);
    var td  = getTD('');var inp = getINP('',9,'Action','text','colhed');
    inp.setAttribute('readonly','readonly');td.appendChild(inp);tr.appendChild(td);
}

function addlin(idx)
{
    var el = document.getElementById('buttd'+idx);
    par = el.parentNode;
    par.removeChild(el);
    var td = document.createElement('TD');
    td.setAttribute('id','buttd'+idx);
    document.getElementById('reclin'+idx).appendChild(td);
    var but = document.createElement('button');
    but.setAttribute('id','updlin'+idx);
    but.setAttribute('type','button');
    but.innerHTML = "Upd";
    td.appendChild(but);
    YAHOO.util.Event.onAvailable('updlin'+idx,YAHOO.connects.action);
    var but = document.createElement('button');
    but.setAttribute('id','dellin'+idx);
    but.setAttribute('type','button');
    but.innerHTML = "Del";
    td.appendChild(but);
    YAHOO.util.Event.onAvailable('dellin'+idx,YAHOO.connects.action);
    document.getElementById('reclin'+idx).appendChild(td);
}

function creAddLine(keyval,tabbod,maxlnid)
{
    document.getElementById('reclin').maxlnid.value = parseInt(document.getElementById('reclin').maxlnid.value)+1;
    maxlnid++;
    var tr = document.createElement('TR');
    tabbod.appendChild(tr);
    tr.setAttribute('id','reclin'+maxlnid);
    var td = getTD('');var inp = getINP('lineid'+maxlnid,0,'0','hidden','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('lineno'+maxlnid,1,0,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('paytype'+maxlnid,1,1,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('quantity'+maxlnid,1,0,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('description'+maxlnid,28,'','text','datent');
       td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('hours'+maxlnid,1,0,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('rate'+maxlnid,1,0,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = getTD('');var inp = getINP('amount'+maxlnid,2,0,'text','datent');
    td.appendChild(inp);tr.appendChild(td);
    var td = document.createElement('TD');
    td.setAttribute('id','buttd'+maxlnid);
    tr.appendChild(td);
    var but = document.createElement('button');
    but.setAttribute('id','addlin'+maxlnid);
    but.setAttribute('type','button');
    but.innerHTML = "Add";
    td.appendChild(but);
    YAHOO.util.Event.onAvailable('addlin'+maxlnid,YAHOO.connects.action);
}
