//
//Function to handle Date Picker
//
$(function(){
    return;
    $('.datinp').datepicker({
        defaultDate: $(this).val(),
        dateFormat: 'yy-mm-dd'
    });
});
//
// get next/previous siblings from dd options
//
function getsib(naver,nexpre) {
    return;
    seler='#'+naver;
    optsel=$("'"+seler+"'  option:selected").attr('id');
    nexid=optsel;
    switch (nexpre){
        case 'next':
            nexts= gelid(optsel).nextSibling;
            if (nexts != null){
                for (idx=0;idx<5;idx++){
                    ns= nexts.nodeType;
                    if (ns==1){
                        nexid=nexts.id;
                        break;
                    }
                    nexts= nexts.nextSibling;
                    if (nexts==null){
                        break;
                    }
                }  // end for
            }
            break;      // end case
        case 'prev':
            nexts= gelid(optsel).previousSibling;
            if( nexts != null){
                for (idx=0;idx<5;idx++){
                    ns= nexts.nodeType;
                    if (ns==1){
                        nexid=nexts.id;
                        break;
                    }  // end if
                    nexts= nexts.previousSibling;
                    if (nexts == null){
                        break;
                    }
                }  // endfor
            }
            break;      // end case
    }   // end case
    return (nexid);
}
///
//
//Function to handle Tabs click standard
//
function tabstdc(objid) {
//
/// cheeck if tab is clickabnle
//
/*
          if (oktab(objid) == false){                // in frmctl
            return
        }
*/
        tabid=objid.length-1
        pretab=objid.substr(0,tabid);
        pretab=strepl(pretab,'toptab$tmdiv','pf1')
        reltab=strepl(objid,'toptab$tmdiv','pf1');
        selnavid=$("select[id*='"+reltab+"']");
/*
        reltab='nav';
///        selnavid=$("select[@id*=reltab]");
*/
        lsel=selnavid.length;
        for (irx=0;irx<lsel;irx++){
             selnav=selnavid[irx].id;
             if (selnav.indexOf('nav') >-1){
                onselectc(selnav,selnav);
             }
           }  // end for
/*//
// function to replace strings
//
    sephay=haystk.split(needle);
*/
////        tabstd(objid);
   tabvis(objid,'visible');     //// frmctl.js  make tab visible and the rest invisible
  return;
}
////
//Function to handle change event on navigation selection
//
function onselectc(objid,objname) {
    curval=gelid('keyval').content;
    newval=document.getElementById(objid).value;
    keys=objid.split('$');
    keysl=keys.length;
    primk=keys[keysl-1];
    flmain=keys[keysl-2];
    endsel=flmain+'$'+primk;
    selnavid=$("select[id$='"+endsel+"']");
    allsel=selnavid.length;
    nav=keys[keysl-3];
////    tab=keys[keysl-5];
    switch (nav){
        case 'navrec':
            for (idx=0;idx<allsel;idx++){
                selid=selnavid[idx].id;
                selids=selid.split('$');
                nvrc=selids[selids.length-3];
                if (nvrc=='navpag'){
                    selidx=document.getElementById(objid).selectedIndex;
//// input field for page size
                    pagcn=gelid('pf1$tab1$pagsiz').value;
                    if (pagcn<1){
                        return;
                    }
                    newidx=Math.floor(selidx/pagcn);
                    document.getElementById(selid).selectedIndex=newidx;
                    continue;                      // next select
                }                                      // finished
                document.getElementById(selid).value=newval;
            }
              fndrefresh(newval,selnavid)                      // in nav.js
/*
               if ( newval !=curval){
                    gelid('keyval').content=newval;
                    Refresh();                           // form dependant  get a new records
               }
*/
                break;
          case 'navpag':
            for (idx=0;idx<allsel;idx++){
                selid=selnavid[idx].id;
                document.getElementById(selid).value=newval;
              }
            opti=objid+dolar+newval;
////            gelid('keyval').content=newval;
            dispag(objid,opti);                             // selectively display  nav.js
             break;                                      // end case
    }  /// endswitch
/// make equal navs                          form depenedant
/////            seteqnav(newval,curtab);                // form dependant equate nav selects
/// make equal navs             form depenedant
    return (null);
}
//
//Function to display selected tr on detail
//
function fndrefresh(newvl,selnav) {
    curvl=gelid('keyval').content;
   if ( newvl !=curvl){
        gelid('keyval').content=newvl;
        Refresh();                           // form dependant  get a new records
        return (null);
   }
    allsel=selnav.length;
    for (isx=0;isx<allsel;isx++){
        navid=selnav[isx].id;
    }
return (null);
}
//
//Function to display selected tr on detail
//
function motrclk(objid,pname) {
    keys=objid.split('$');
    kedl=keys.length;
    kyval=keys[kedl-1];
    prmkey=keys[kedl-2];
    flmain=keys[kedl-3];
   gelid('primak').content=prmkey;
   gelid('mainfl').content=flmain;
    endsel='navrec$'+flmain+'$'+prmkey;
    nxtab= gelid('nextab').content;
    selnavid=$("select[id$='"+endsel+"']")
    sels=selnavid.length;
    for (idx=0;idx<sels;idx++){
        nxtsel=selnavid[idx].id;
        document.getElementById(nxtsel).value=kyval;
        if (nxtsel.indexOf(nxtab) !=-1){
            onsel=nxtsel;
        }
    }
    fndrefresh(kyval,selnavid);                                 // in nav.js
    visible(nxtab,'visible');                                            // in frmctl
    gelid('actpag').content=nxtab;
///    seteqnav(newval,curtab);                // form dependant equate nav selects
    return (null);
}
//
//*** nav

//
//Function to display selected tr on detail from 2ndary  file
//
function motrtxclk(objid,pname) {
    keys=objid.split('$');
    $("#tridStatus").attr('content',objid);
    valkey=$("#valkey").attr('content')+'$'+keys[3];
    $("#valkey").attr('content',valkey);
    onselectc('navrec','navrec');
    return (null);
}
//
//Function to display selected tr on detail
//
function movrtr(objid,pname) {
    keys=objid.split('$');
    return (null);         /// testing
    tfoot=$("#"+keys[0]+'tfoot').attr("title");
    recctl=tfoot.split(',');
    maxpag=Math.round(recctl[1])+1;
    botmes=(Math.round(keys[3].slice(2,5))+1)+' of page '+(Math.round(keys[4].slice(2,3))+1)+' of ' +maxpag+"    pages ";
    botid=keys[0]+'status';
    $('#'+botid).text('row '+botmes);
    return (null);
}
//
//Function to call  secondary file data
//
function mclkdf(objid,pname) {
    keys=objid.split('$');
    lenpri=keys.length;
    primk=keys[lenpri-1];
    nxtfrm='nextform';
////    $("#navrec").val(primk);
///    $("#tridStatus").attr('content',objid);
    gelid('tridStaus').content=objid;
    nxtfrm=gelid(nxtfrm).content;
    key=gelid('primak').content;
    primak='runmfrm.php'+'?primak='+nxtfrm+'$'+primk;
    location.href=primak;
    return false;
}
function dispag(objid,page) {
    blank='';
    navids=objid.split(dolar);
    goodtr=document.getElementById(objid).value;
/////    devtab=document.getElementById(objid).parentNode.id
    elemsc=navids.length;
    nav=dolar+navids[elemsc-3];
    beforn=objid.split(nav);
     tfot=$("tfoot [id*='"+beforn[0]+"']").attr("id");
     tfot=uparent(tfot,dolar,1);
    pagsiz=getfoot('pagsiz',tfot);                        ///util.js
    trid=uparent(tfot,dolar,1)+'$tbody';
    tbtr=$("tbody tr[id*='"+trid+"']");
    godtr=trid+beforn[1]+'$'+goodtr;
    trl=tbtr.length;
    gotgod=0;
    for (inx=0; inx<trl; inx++)  // in the loop
    {                                      // in the loop
         curelm=tbtr[inx].id;
         curobj=document.getElementById(curelm);
             if (curelm  == godtr ) {
                 gotgod=1;
                 visinvis(curobj,'visible');              // util.js
                 continue;
             }          // look for the 1st good one
          if ( gotgod<1) {
              visinvis(curobj,'invisible');                // util.js
              continue;
          }
                 gotgod++;
                 visinvis(curobj,'visible');          // util.js
          if ( gotgod >pagsiz) {
              visinvis(curobj,'invisible');          // util.js
              continue;
          }
         }
    return;
}
///
//*** nav
//
//Function to handle Navigation arrows click
//
function movenav(selid,movtyp) {
        dolar='$';
         switch(movtyp){
             case'tabnav':
                 nlis=gelid(selid).childNodes;
                 totopt=(nlis.length-1)/2-1;                // the count starts with 0 !!!
                 curidx=gelid(selid).selectedIndex;
                  if (curidx>=totopt){
                      gelid(selid).selectedIndex=-1;
                  }                        /// set the top of the select
                  gelid(selid).selectedIndex++;
                  selnid=selid;
                  break;
              default:                   // arrows navigation
                     selhref=selid;
                     arrows=selid.split(dolar);
                     keyl=arrows.length;
                     fpnl=arrows[keyl-1];              // first.previous.next.last
                     selkey=gelid('mainfl').content+dolar+gelid('primak').content;
                     selnid=selhref.replace(fpnl,selkey);
                     nlis=document.getElementById(selnid).childNodes;
                     totopt=(nlis.length-1)/2-1;                // the count starts with 0 !!!
                     curidx=document.getElementById(selnid).selectedIndex;
                     newidx=curidx;
                      switch(fpnl){
                          case'cmdfirst':
                              newidx=0;
                              break;
                          case'cmdprev':
                               if (curidx>0){
                                   newidx=curidx-1;
                               }
                              break;
                          case'cmdnext':
                               if (curidx<totopt){
                                   newidx=curidx+1;
                               }
                              break;
                          case'cmdlast':
                              newidx=totopt;
                              break;
                      }
                      document.getElementById(selnid).selectedIndex=newidx;
                      newval=document.getElementById(selnid).value;
//
// end of arrow selection
                     break
         }
    return selnid;
}
//
//Function to handle Navigation arrows click
//
function navclk(objid,parent) {
/*     enable-disable temporary
    if (chktbs(objid,parent) != true){
           mesagw(objid+' is disabled');
        return;
    }
    variab='.'+objid;
//    enab=$('#'+objid+"Status").attr('content');
    enab=gelid(objid+'Status').content;
    mesagw(' enab'+enab);
    switch(enab){
        case 'enable':
            np=$(variab).attr('href');
              break;
    }
    */
    selnid=movenav(objid,'arrows');
    onselectc(selnid,selnid);
    return false;
}
//
//Function to handle Navigation arrows click
//
function navsable(work) {
    navt='navtol';
///    navdivs=$("div[class='"+navt+"']").attr('id');
    navdivs=$("div[class='"+navt+"']");
    navs=navdivs.length;
    show='invis';
    switch(work){
        case 'able':
            remad='remove'
             break;
        case 'disable':
            remad='add';
             break;
           }
///    alert(work+' in navsable nav.js'+navs+remadd);
     for (inv=0;inv<navs;inv++){
          addat(navdivs[inv].id,'class',show,remad);                                       /// util.js                          }
     }
return;
///function addat (objid,att,val,remadd) {

}
