/*
  Global vars required to be set for operation of this lib.
  -----------------------------------------------------------

# setup colors for javascript code in file: estore.js
echo "<script>
        var menuAtt= new Array();
        menuAtt['selItemBGC']   = '$menuAtt[selItemBGC]';
        menuAtt['unSelItemBGC'] = '$menuAtt[unSelItemBGC]';
        menuAtt['hiLiteOn']     = '$menuAtt[hiLiteOn]';
        menuAtt['hiLiteOff']    = '$menuAtt[hiLiteOff]';
      </script>\n";

# setup curpage for javascript code in file: estore.js
echo "<script> curPage='$curPage'; </script>\n";

**/

var newBrowser = (document.getElementById); // new browse functionality
var divArrCnt=0;
var divArr = new Array();  // built as <div> are added

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function element_exists(id)
{ // make sure an element exists
  if (newBrowser) { if (document.getElementById(id)) return true; }
  else            { if (document.id) return true; }
  return false;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function id2obj(id)
{ return newBrowser ? document.getElementById(id) : document.id;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function id2StyleObj(id)
{ return newBrowser ? document.getElementById(id).style : document.id;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function momDivPageStyleObj(divName)
{ return id2StyleObj('momDivPage' + divName);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function set_visible(_a) { _a.visibility='visible'; _a.display='block'; }
function set_hidden(_a)  { _a.visibility='hidden';  _a.display='none';  }

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function set_search_box_background(c)
{ var id = 'searchInputBox';
  if (!element_exists(id))return;

  var _a = id2StyleObj(id);
  _a.background = c;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function mk_style_property_name(n)
{ // note style property names like border-top must get translated to borderTop
  var j = n.indexOf('-'); // cap letter after dash
  if (j!=-1)
  { n = n.replace('-',''); // rm dash
    var c=n.charAt(j).toUpperCase();
    n = n.substring(0,j) + c + n.substring(j+1);
  }
  return n;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function set_menuItem(id, state) // false=lowLite, true=hiLite
{ // the id has 'momDivPage' preface; change to 'menuItem' preface
  var i,n;

  id = id.replace('momDivPage', 'menuItem');

  if (!element_exists(id)) return;

  if (typeof window.app_hiLiteMenu_handler == 'function')
  { // function exists, so we can now call it
    // web application special hander.
    app_hiLiteMenu_handler(id, state);
    return;
  }

  var _a = id2StyleObj(id);

  //  _a.background  = state ? menuAtt['selItemBGC'] : menuAtt['unSelItemBGC'];
  //  _a.borderLeft  = state ? menuAtt['hiLiteOn']   : menuAtt['hiLiteOff'];

  // http://www.jibbering.com/faq/faq_notes/square_brackets.html
  // note style property names like border-top must get translated to borderTop
  if (state) // set in all attributes
       for (i=0; i<menuAttHiLiteOn.length; i++)
       {  n = mk_style_property_name(menuAttHiLiteOn[i][0]);
         _a[n] = menuAttHiLiteOn[i][1];
       }
  else for (i=0; i<menuAttHiLiteOff.length; i++)
       {  n = mk_style_property_name(menuAttHiLiteOff[i][0]);
          _a[n]= menuAttHiLiteOff[i][1];
       }
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function  hiLiteMenuItem(id) { set_menuItem(id, true); } // 0=lowLite, 1=hiLite
function lowLiteMenuItem(id) { set_menuItem(id, false);} // 0=lowLite, 1=hiLite

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function dhtmlObjShowClose(id)
{ set_hidden( id2StyleObj(id) );
  lowLiteMenuItem(id);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function toggle_visibility(id, menuItemFlag)
{ // toggle visibility
  if (!element_exists(id)) return;

  var _a = id2StyleObj(id);
  if (_a.display=='none')
  { set_visible(_a);
    if (menuItemFlag) hiLiteMenuItem(id);
  }
  else set_hidden(_a);
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function dhtmlObjShow(id) // open and close div.
{ // toggle visibility
  toggle_visibility(id, false); // menuItemFlag; false=is not a menu item;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function dhtmlObjShow2(id)
{ for (var i=0; i<divArrCnt; i++) // loop on all content <div>
  {  // close all other divides
     set_hidden( momDivPageStyleObj( divArr[i] ) );
     // clear all menu high-lights
     lowLiteMenuItem( 'menuItem' + divArr[i] );
  }
  // toggle visibility
  toggle_visibility(id, true); // menuItemFlag; true=is a menu item
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function close_div(id)
{ // close momPage divide
  set_hidden( momDivPageStyleObj( id ) );
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function open_div(id)
{ // set visibility of any div id
  if (!element_exists(id)) return;
  var _a = id2StyleObj(id);
  set_visible(_a);
}


//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function close_all_div()
{ // close all other divides
  for (var i=0; i<divArrCnt; i++) // loop on all content <div>
  {  close_div( divArr[i] )
     lowLiteMenuItem( 'momDivPage'+divArr[i] ) // GLA - 3/30/2008
  }
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function open_all_div()
{
  for (var i=0; i<divArrCnt; i++) // loop on all content <div>
  {  // skip certain div
     //if ( divArr[i] == 'Shop'   ) continue;
     if ( divArr[i] == 'google' ) continue;
     if ( divArr[i] == 'admin'  ) continue;

     set_visible( momDivPageStyleObj( divArr[i] ) );
     hiLiteMenuItem( 'momDivPage'+divArr[i] );
  }
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function open_list_of_div(list)
{ var i;
  // loop on all menuItem div to set-in menuItem attributes for initial load condition.
  // note: a horz. menu TAB emulation requires <TD> cell border control that is programed for each web app. in func. app_hiLiteMenu_handler().
  for (i=0; i<divArrCnt; i++)  // loop on all menuItem div to setin menuItem attributes.
    lowLiteMenuItem('menuItem' + divArr[i]);
  lowLiteMenuItem('lastBlankMenuItem');   //blank <TD> cell to extend horz. tabular underline full page width
  lowLiteMenuItem('firstBlankMenuItem');

  var a = list.split(',');
  for (i=0; i<a.length; i++) // loop on list of content <div>
  {  // skip certain div
     if ( a[i] == '') continue;  // blank for any reason

     a[i] = a[i].replace('momDivPage', ''); // strip it then prepend in next line

     set_visible( momDivPageStyleObj( a[i] ) );
     hiLiteMenuItem( 'momDivPage'+a[i] );
  }
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function search_go()
{ var o1 = document.productMenuForm.dbName;
  var o3 = document.productMenuForm.contentBlkName;

  location= curPage + '?'+
           'dbName='     + o1.options[o1.selectedIndex].text +
           '&contentBlkName=' + o3.value +
           '&iGroup=all' +
           '&searchFor=' + document.productMenuForm.searchFor.value;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function folder_go()
{ var o1 = document.productMenuForm.dbName;
  var o2 = document.productMenuForm.iFolder;
  var o3 = document.productMenuForm.contentBlkName;

  var iG_selection = o2.options[o2.selectedIndex].text;
  if ( iG_selection.indexOf('select ?') != -1  ) iG_selection = '';

  //special case of 'All' item in a particular store
  if (iG_selection.indexOf('All') != -1 )
  { // force view All items if the selected store/database.
    document.productMenuForm.searchFor.value = '.';
    search_go();
    return;
  }

  location= curPage + '?'+
           'dbName='  + o1.options[o1.selectedIndex].text +
           '&contentBlkName=' + o3.value +
           '&iGroup=' + iG_selection;
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function database_change()
{ // force view All items if the selected store/database.
  document.productMenuForm.searchFor.value='.';
  search_go();
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function content_block_change() { document.contentBlockForm.submit(); }

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function content_block_change2( blkName )
{ document.contentBlockForm.contentBlkName.value = blkName;
  content_block_change();
}

//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
function lk(descrip) // put a link image infront of huperlink text
{ document.write( '<img src=images/go.gif>'+ descrip.replace(/ /, '&nbsp;') );
}

/* end of file */