//*
// Globar variable for browser type
//*
//      bv = parseInt(navigator.appVersion);
//      bt = navigator.appName;
      xmlHttp=null;
      debug=0;
      bt = navigator.appName;
      brw="ff";
      if (bt == 'Microsoft Internet Explorer')
      {
        brw='ms';
      }
      dolar='$';                // fileds separator
////     frmnam='';                  // inherent form name for getid
// This function loads xml document 
//*
//*
//// Browser fix for attributes
//* obj-- Objct
//* att== atribute name
function getat (obj,att)
{
 val="";
 attl=att.toLowerCase(); 
 if (brw == "ff")
 {
    val=obj.getAttribute(att);
    return(val);
 }
 switch (att)
 {
   case "class":
/*
       objid='#'+obj.id;
        val= $(objid).attr('class');
///       alert(attl+' util.getatt clas'+cls+' objid '+objid);
      break;
*/
     if (brw=="ff")
      {
       val=obj.getAttribute(att);
      }
      else
      {
//for IE
///       val=obj.attributes[3].value;
       val=obj.className;
      }
    break;
   case "id":
    val=obj.attributes[18].value;
    break;
   case "title":
     if (brw=="ff")
      {
       val=obj.getAttribute(att);
      }
      else
      {
       val=obj.attributes[43].value;
      }
    break;
   case "value":
     if (brw=="ff")
      {
       val=obj.getAttribute(att);
      }
      else
      {
       val=obj.attributes[105].value;
      }
    break;
 }
return(val);
}
//*
//// Browser fix for attributes
//* obj-- Objct
//* att== atribute name
function setat (obj,att,val)
{
 attl=att.toLowerCase(); 
 if (brw=="ff")
  {
      obj.setAttribute(att,val);
      return(val);
  }
 switch (att)
 {
   case "class":
//*** This object cannot be made visible
//    
    if (getat(obj,"class") == "invisp")
    {
         return (null);
         break;
    }                               // end of permanent invisibility
// let get the current class
      curcls=getat(obj,att);
      fond=curcls.search(val);
////      alert(val+' getat looking for existing string'+curcls);
      if (fond>-1){
          break;                          // do ntothing its already there
      }
      newcls=curcls+'  '+val;
    if (brw=="ff")
     {
      obj.setAttribute(att,newcls);
     }
     else
     {
// for IE
      obj.className=newcls;
     }
    break;                               // end of class case
   case "id":
    obj.attributes[18].value=val;
    break;
   case "name":
    obj.attributes[18].value=val;
    break;
   case "title":
    val=obj.attributes[43].value=val;
    break;
   case "value":
    val=obj.attributes[105].value=val;
    break;
 }
return(val);
}
//*
//// Browser fix for attributes add a new class for existing class
//* obj-- Objct
//* att== atribute name
function addat (objid,att,val,remadd) {
     obj=gelid(objid);
     attl=att.toLowerCase();
     newcls=val;
      curcls=getat(obj,attl);
////  curobj=document.getDocumentById(curelm);
 switch (att)  {
   case "class":
//
//*** This object cannot be made visible ever !!!
//
    if (curcls  == "invisp")  {
         return (null);
         break;
    }                               // end of permanent invisibility
          switch(remadd){
              case 'remove':
                   newcls=curcls.replace(val,' ');
                   break;
              default:                   
// let get the current class
              found=curcls.search(val);
              if (found>-1){
                   break;                          // do ntothing its already there
                   return newcls;
                   }
              newcls=curcls+'  '+val;
          }
      }             // end of attribute switch
    if (brw=="ff") {
      obj.setAttribute(att,newcls);
     }
     else  {
      obj.attributes[3].value=newcls;
     }
return newcls;
}//*
//**** Set Field value
//* filobj   file object node
function  refFv(filobj)        //Load the value into the screen 
{
vaload=filobj.text;           /// value to load
if (brw == 'ff')              //browser differences
  {
   vaload=filobj.textContent; /// value to load
  }
//
//**** See if a simple field or a compound field
//
obj=null;
objf=gelid(filobj.tagName);
//**
//**** No elements found on screen
//**   
if (objf == null)
 {
    return(null);
 }
 switch (objf.tagName)      // switch 1
 {
  case "TD":
 /////// compound field
   selinp=objf.childNodes;
   lentd=selinp.length;
   tdcls=getat(objf,"class");
   for (ifx=0;ifx<lentd;ifx++)
   {
    if (selinp[ifx].tagName == "INPUT")
     {
       obj=selinp[ifx];
       setFv(obj,vaload);        
       return (vaload); 
       break;      // break for
     }             // end if INPUT
    if (selinp[ifx].tagName == "SELECT")
     {
       obj=selinp[ifx];
       valu=getOptval(obj,vaload);
       setFv(obj,vaload);        
       return (valu); 
       break;      // break for
     }             // end if SELECT
   }               // end for
     break;        // break case "TD"
  case "INPUT":
   obj=objf;
   break;
  case "SELECT":
   obj=objf;
   break;
 }                 // end switch  1
   if (obj!=null)
   {
    setFv(obj,vaload);        
    } 
    else
    {
    setFv(objf,vaload);        
    }
return(vaload);
}
//*
//*
////  Set the field value
//*
function setFv(opt,val)
{
if (opt == null)
{
  return (null);
}
//*         
//Regular Text element
//*         
     if (opt.nodeName=="INPUT")
     {
       opt.setAttribute('value',val);
       return (val);
     }
//*
// Select drop down list element
//*
     if (opt.nodeName=="SELECT")
     {
        looks=opt.childNodes.length;
        for (ibx=0; ibx<looks; ibx++)
        {                           // for loop
         cn=opt.childNodes[ibx];
         if (cn.id==val)   
         {                
             brwd=1;             // browser differences
              if (brw == 'ff')   //browser differences
               {
                 brwd=brwd+1;
               }
             opt.selectedIndex=ibx-brwd;
             break;             // for loops
         }                                 
         else
         {
             continue;          // for loop
         }
        }                           // for ibx loop
       return (opt.nodeValue);
     }
return (null);
}

Date.prototype.getJulian = function() {
    return Math.floor((this / 86400000) - (this.getTimezoneOffset()/1440) + 2440587.5);
}
//
// function to replace strings
//
function strepl(haystk,needle,replac){
    sephay=haystk.split(needle);
    sect=sephay.length;
    if (sect<2){
        return haystk;
    }
    newhay=haystk;
    for (idx=0; idx<sect;idx++){
        newhay=newhay.replace(needle,replac);
    }
return newhay;
}
//
// function to move up the parent ladder
//
function uparent(haystk,needle,replac){
    separ=haystk.split(needle);
    sepl=(separ.length)-replac-1;
    newhay='';
    sepdlr=needle;
    for (itx=0; itx<=sepl; itx=itx+1) {
        if(itx == sepl){
            sepdlr='';
        }
        newhay=newhay+separ[itx]+sepdlr;
///        alert(itx+'  ipx in uparent new hay '+sepdlr);
    }
 return newhay;
}
//
// general getElemntby id
//
function gelid(objid){
    newid=frmnam+objid;
    document.getElementById(newid);
return document.getElementById(newid);
}
//
// general right hand side message
//
///Dialog Box Open Function
function openDialog(){
    if (gelid('mesagbox') == null){
        return;
    }
    cls=getat(gelid('msgwnd'),'class').search('invis');
    if (cls>-1){
        return
    }
    msgtext=gelid('mesagbox').content;
    msw='msgwnd$message';
    allopt=gelid(msw).childNodes;
    newpl=allopt.length;
    for (inx=0; inx<newpl; inx++) { // in the loop
        if (allopt[inx].nodeType !=1){
            continue;
        }
        oldopt=allopt[inx];
        oldval=Math.floor(allopt[inx].value);
        break;
    }
    newopt=oldopt.cloneNode(true)
    newopt.value=Math.floor(oldval+10);
    newopt.textContent=msgtext;
    if (brw !='ff'){
        newopt.innerText=msgtext;
    }
    newid=newopt.id.split(dolar);
    newopt.id=newid[0]+dolar+newid[1]+dolar+newid[2]+dolar+newopt.value;
    gelid(msw).insertBefore(newopt,oldopt);
    gelid(msw).selectedIndex=0;     // select the last addition
    gelid('mesagbox').content='';      // clean  the mesage
    return;
}
function mesagw(messag){
    if (gelid('mesagbox') == null){
        return;
    }
    cls=getat(gelid('msgwnd'),'class').search('invis');
    if (cls>-1){
        return
    }
    gelid('mesagbox').content=gelid('mesagbox').content+messag;
 return;
}
//
// Functio to upload file
//
function upload(messag){
    filnam=gelid('userfile').value;
    opmode= $("#opmode").attr('value');
    $("#parent").val(filnam);
    $("#opmode").val('upload');
   sndata=prepsnd(filnam);     /// prepare data to send
    $("#opmode").val(opmode);
             $.ajax({
          type:'POST',
          data: sndata,
          dataType: "text",
          url: 'php/ajxrwd.php?id='+primak,
          success: function(msg){
            showmsg=parseincom(msg,'upload');
            mesagw(showmsg);
             openDialog();
                 }
             });

return (null);
}
//
/// function to set the record number from
// pagsiz,pagcnt,mxrwcnt,reccnt,addcnt,delcnt,orgcnt
//
function setrowcnt(objid){
    vars=objid.split('$');
    table=vars[0];
    table=gelid('mainfl').content;
    newrow=vars[3].substr(2);
    pagcnt=vars[4].substr(2);
    newrow=Math.round(newrow);
    pagsiz=getfoot('pagsiz',table);
    posit=getfoot('pagsiz',table)*pagcnt+newrow+1;
    recpos='Record '+posit+' of '+getfoot('mxrwcnt',table);
   $('#recstatus').text(recpos);
return (null);
}
//
/// function to get values from tfooter
// pagsiz,pagcnt,mxrwcnt,reccnt,addcnt,delcnt,orgcnt
//
function getfoot(valnam,footid){
    tfoot=document.getElementById(footid).title;
    vart=tfoot.split(',');
   switch(valnam)    {
       case'pagsiz':
           ret=vart[0];
           break;
       case'pagcnt':
           ret=vart[1];
           break;
       case'mxrwcnt':
           ret=vart[2];
           break;
       case'reccnt':
           ret=vart[3];
           break;
       case'addcnt':
           ret=vart[4];
           break;
       case'delcnt':
           ret=vart[5];
           break;
       case'orgcnt':
           ret=vart[6];
           break;
   }
return (Math.round(ret));
}
//
/// function to set values to tfooter always increase by one
// pagsiz,pagcnt,mxrwcnt,reccnt,addcnt,delcnt,orgcnt
//
function setfoot(valnam,footid){
    tfoot=document.getElementById(footid).title;
    vart=tfoot.split(',');
    varl=vart.length;
   switch(valnam)    {
       case'pagsiz':
           vart[0]=vart[0]+1;
           ret=vart[0];
           break;
       case'pagcnt':
           vart[1]=vart[1]+1;
          ret=vart[1];
           break;
       case'mxrwcnt':
           vart[2]=getfoot(valnam,footid)+1;
           ret=vart[2];
           break;
       case'reccnt':
           vart[3]=vart[3]+1;
           vart[3]=getfoot(valnam,footid)+1;
           ret=vart[3];
           break;
       case'addcnt':
           vart[4]=vart[4]+1;
           vart[4]=getfoot(valnam,footid)+1;
           ret=vart[4];
           break;
       case'delcnt':
           vart[5]=vart[5]+1;
           ret=vart[5];
           break;
       case'orgcnt':
           vart[6]=vart[6]+1;
           ret=vart[6];
           break;
   }
   tit='';
   for (ivx=0;ivx<=varl;ivx++){
       if ( ivx>=7 ){
           break;
       }
       tit=tit+vart[ivx]+',';
   }
  document.getElementById(footid).title=tit;
   return ret;
}
//
//Function to handle Tabs click end (visble/invisible util.js
//
function tabstd(objid) {
    tabcnt=objid.split('$');
    if (tabcnt.length<2) {
        return;
    }
    pag=tabcnt[2];
    ind=pag.substr(3,1);                         // curent tab #
   $("#"+pag).removeClass('invis');                   // remove the invisible  class
   gelid('actpag').content=tabcnt[2];              // set the current tab id
  for (idx=0;idx<12;idx++){                                  // maximum 12 tabs for a form
      if (idx==ind){
          continue;
      }
      pag='tab'+idx;
      makadc(pag,'invis');                                         // frmctl.js for making visible/invisible
  }
return;
}
///
//Function to get  navigation selection values
//
function getcurnav(objid){
     actpag=gelid('actpag').content;              // get the current tab id
     navpag=actpag+'$nav';
     sels=$("select[id*='"+navpag+"']");
     if (sels.length<1){
        selval=null;
     }
     else {
     selval=gelid(sels[0].id).value;              // get the current navigation value
     }
return selval;
}
//
//Function to get fields values
//
function getfldval(fldnam,filnam,decmal){
      field=filnam+'$'+fldnam
      sls=$("input[id$='"+field+"']").val();
      return Math.floor(sls);
///    amt=Math.floor(gelid('sslamt').value*100);
return;
}
//
//Function to get fields values from labels/selects/input (lsi)
//
function getlsi(fldnam,filnam,decmal,lsi){
      field=filnam+'$'+fldnam
      switch(lsi){
          case 'input':
              sls=$("input[id$='"+field+"']").val();
              break;
          case 'select':
              sls=$("select[id$='"+field+"']").val();
              break;
          case 'label':
              sls=$("label[id$='"+field+"']").text();
              break;
      }
      return Math.floor(sls);
///    amt=Math.floor(gelid('sslamt').value*100);
return;
}
//
//Function to set label values
//
function setlbval(fldnam,filnam,decmal){
      field=filnam+'$'+fldnam;
      sls=$("label[id$='"+field+"']").attr('id');
//      label='#'+sls;
///      label='#'+'pf1$tab2$rhs$rhsd$div$fldval$sales$stotal';
///      alert(label+' found the right label'+decmal);
///                  optsel=$("#navrec option:selected");
///      $(label).text(decmal);
////      $("#sls").attr('text',decmal);
     document.getElementById(sls).textContent=decmal;
      return;
}
//
// Function to set metatnav  vaklues
//
function setmtab(tabs,metval,keyt){
    return;
    metid='nav' +tabs+keyt;
    gelid(metid).content=metval;              // get the current navigation value
    return;
}
//
// Functio to set startiung navigation metatgs
//
function       setbegnav(acpag) {
    pagact=gelid(acpag).content;              // get the current tab id
    navpag=pagact+'$nav';
    selnavid=$("select[id*='"+navpag+"']").attr('id');
    begval=gelid(selnavid).value;              // get the current navigation value
    return begval;
}
//
// Functio to set caption data for form
//
function       setcapt(newcapt) {
    frmnam=gelid('frmnam').content;              // get the current tab id
    fulnam=frmnam+'$caption';
    $("div[id*='"+fulnam+"']").text(newcapt);
    return ;
}
//  onclick="mclkdf(this.id,this.parentNode.id)"
//Function to make invisible and visible by adding the  invis class
//
function visinvis(obj,vis){
    if (obj == null){
        return;
    }
    blnk='';
/*
 showmsg=obj.id+' in visinv '+vis;
mesagw(showmsg);
openDialog();
*/
    cld=getat(obj,'class');
    cls=cld.replace(/invis/g,blnk);
///    alert(' fixed class'+cls);
    switch (vis){
        case 'invisible':
                setat(obj,'class',cls+' invis');               //add invis
            break;
        case 'visible':
                 setat(obj,'class',cls);                   //make visible
            break;
    }
    return (null);
}
