var IE5 = (document.layers == undefined);
//var ListLen;
var oldcolor;
var hicolor='yellow';

function CkBoxes(fld, sel)
{
   var fm = document.forms[0];
   var selfld = eval("fm.subsel" + sel); //fm.SelId;
   var slist = eval("fm.Sellist" + sel);
   var ListLen = eval("fm.Sellist" + sel + ".length")

   fm.TableId.value = sel;

   ckVal = fld.value.replace(/[\s\.-]/g, "_")
   if (fld.checked == true)
   {
      if (IE5 == true)
      {
         if (ListLen > 1)
         {
            if (selfld.value != -1)
            {
               sval = selfld.value.replace(/[\s\.-]/g, "_")
               eval("L" + sel + sval + ".style.backgroundColor=oldcolor");
            }
            
            for (x=0; x< ListLen; x++)
               if (slist[x].value == ckVal)
               {
                  oldcolor = eval("L" + sel + ckVal + ".style.backgroundColor");
                  eval("L" + sel + ckVal + ".style.backgroundColor=hicolor")
               }
         }
         else
         {
            eval("L" + sel + ckVal + ".style.backgroundColor=hicolor")
         }
      }
      fld.checked = true
      selfld.value = fld.value
   }
}

function DoSelect(ckVal, sel)
{
   var fm = document.forms[0];
   var selfld;
   var slist;
   eval("selfld=fm.subsel" + sel);
   eval("slist=fm.Sellist" + sel);
  
   ckVal2 = ckVal.replace(/[\s\.-]/g, "_")

   if (slist == undefined)
   {
      if (selfld.value != -1 && IE5 == true)
      {
         sval = selfld.value.replace(/[\s\.-]/g, "_")
         eval("L" + sel + sval + ".style.backgroundColor=oldcolor");
      }

      oldcolor = eval("L" + sel + ckVal2 + ".style.backgroundColor");
      eval("L" + sel + ckVal2 + ".style.backgroundColor=hicolor")
      selfld.value = ckVal

      return false;
   }
   
   var ListLen = eval("fm.Sellist" + sel + ".length")

   fm.TableId.value = sel;

   if (ListLen > 1)
   {
      if (selfld.value != -1 && IE5 == true)
      {
         sval = selfld.value.replace(/[\s\.-]/g, "_")
         eval("L" + sel + sval + ".style.backgroundColor=oldcolor");
      }
      
      for (x=0; x< ListLen; x++)
         if (slist[x].value == ckVal2)
         {
            if (IE5)
            {
               oldcolor = eval("L" + sel + ckVal2 + ".style.backgroundColor");
               eval("L" + sel + ckVal2 + ".style.backgroundColor=hicolor")
            }
            slist[x].checked = true;
         }
   }
   else
   {
      if (IE5)
         eval("L" + sel + ckVal2 + ".style.backgroundColor=hicolor");
      slist.checked = true;
   }
   selfld.value = ckVal
   return false;
}

function doview(pg, sel)
{
   dogo(pg, "View", sel);
}

function doadd(pg, sel)
{
   eval("document.forms[0].subsel" + sel + ".value = -2;");
   document.forms[0].SelId.value = -2;
   dogo(pg, "Add", sel)
}

function doedit(pg, sel)
{
   dogo(pg, "Edit", sel);
}

function dodel(pg, sel)
{
   if (!confirm("Are you sure you wish to delete the selected record?"))
      return false;
   dogo(pg, "Delete", sel);
}

function dogo(pg, act, sel)
{
   var fm = document.forms[0];
   var selfld = eval("fm.subsel" + sel);

   if (selfld.value == -1)
   {
      alert("You must select a row before you can select " + act + ".");
      return false;
   }
   fm.SelId.value = selfld.value;
   fm.action = pg;
   fm.Act.value = act;
   fm.TableId.value = sel;
   fm.submit();
}

