//==========================================================================
//
// Javascript routines for WEB INVENTORY PRODUCT MANAGER
//
//==========================================================================

//--------------------------------------------------------------------------
//
// Event handler to load menu upon load of the page.  The resize handler
// must be set to account for Netscape 4 resize problems.
//
//--------------------------------------------------------------------------
function onLoad()
{
  loadMenus();
  window.onresize = onResize;
}

//--------------------------------------------------------------------------
//
// Event handler for window resizing.  Netscape 4 loses it's javascript
// menus when resizing, so we have to reload the location.  This workaround
// is not optimal.
//
//--------------------------------------------------------------------------
function onResize()
{
  if (navigator.appName == 'Netscape') {
    //loadMenus();
    window.history.go(0);
  }
}

//--------------------------------------------------------------------------
//
// Set the location.  This is used to set the home location but won't cause
// the HREF text to be coloured as 'visited', so that all the menu options
// remain the same colour.
//
//--------------------------------------------------------------------------
function setLocation(locName)
{
  window.location = locName;
}

//--------------------------------------------------------------------------
//
// Load all the menus.  This creates all the menus, sets their properties
// and saves them in a menu container.
//
//--------------------------------------------------------------------------

function loadMenus()
{
  addStoresMenu();
  addGalleriesMenu();
  addProductsMenu();
  addSuppliersMenu();
  addInstructionsMenu();
  addInstructions1Menu();
  setMenuProperties();
  saveMenus();
}
//--------------------------------------------------------------------------
//
// Create the Stores menu.
//
//--------------------------------------------------------------------------
function addStoresMenu()
{
  if (!window.menuStores) {
    window.menuStores = new Menu();
    with (window.menuStores) {
      addMenuItem("Modify", "location='store_modify1.php'");
      addMenuItem("Display Options", "location='display_options1.php'");
      addMenuItem("View Site", "window.open('view_store_site.php')");
      addMenuItem("Image Upload", "imageUpload()");
    }
  }
}

//--------------------------------------------------------------------------
//
// Add the Gallery menu.
//
//--------------------------------------------------------------------------
function addGalleriesMenu()
{
  if (!window.menuGalleries) {
    window.menuGalleries = new Menu();
    with (window.menuGalleries) {
      addMenuItem("Add", "location='gallery_addrecord1.php'");
      addMenuItem("Modify", "location='gallery_modrecord1.php'");
      addMenuItem("Delete", "location='gallery_delrecord1.php'");
      addMenuItem("Import", "location='gallery_import1.php'");
      addMenuItem("View Active-Inactive", "location='list_galleries_active.php'");
      addMenuItem("View by Gallery", "window.open('gallery_select.php')");
    }
  }
}

//--------------------------------------------------------------------------
//
// Add the Product menu.
//
//--------------------------------------------------------------------------
function addProductsMenu()
{
  if (!window.menuProducts) {
    window.menuProducts = new Menu();
    with (window.menuProducts) {
      addMenuItem("Add", "location='product_gallery_add.php'");
      addMenuItem("Modify", "location='product_gallery_modify.php'");
      addMenuItem("Delete", "location='product_gallery_delete.php'");
      addMenuItem("Copy", "location='product_copy1.php'");
      addMenuItem("Transfer", "location='product_transfer1.php'");
      addMenuItem("View Product", "location='gallery_view_product1.php'");
    }
  }
}

//--------------------------------------------------------------------------
//
// Add the Supplier menu.
//
//--------------------------------------------------------------------------
function addSuppliersMenu()
{
  if (!window.menuSuppliers) {
    window.menuSuppliers = new Menu();
    with (window.menuSuppliers) {
      addMenuItem("Add", "location='supplier_addrecord1.php'");
      addMenuItem("Modify", "location='supplier_modrecord1.php'");
      addMenuItem("Delete", "location='supplier_delrecord1.php'");
      addMenuItem("View by Supplier", "window.open('supplier_select.php')");
      addMenuItem("Inventory Reports", "location='inv_report1.php'");
    }
  }
}

//--------------------------------------------------------------------------
//
// Add the Instructions menu.
//
//--------------------------------------------------------------------------
function addInstructionsMenu()
{
  if (!window.menuInstructions) {
    window.menuInstructions = new Menu();
    with (window.menuInstructions) {
      addMenuItem("Help", "location='instructions.php'");
      addMenuItem("Bug Report", "location='bug_report.php'");
      addMenuItem("Contact", "location='contact.php'");
    }
  }
}

//--------------------------------------------------------------------------
//
// Add the alternate Instructions menu (when user is not logged in)
//
//--------------------------------------------------------------------------
function addInstructions1Menu()
{
  if (!window.menuInstructions1) {
    window.menuInstructions1 = new Menu();
    with (window.menuInstructions1) {
      addMenuItem("Logging In", "location='instruct_login.php'");
      addMenuItem("Contact", "location='contact.php'");
    }
  }
}

//--------------------------------------------------------------------------
//
// Set menu properties.  This must be done after creation of the various
// menus, and assumes that menuInstructions is one of them.
//
//--------------------------------------------------------------------------
function setMenuProperties()
{
    // these styles will be used by other menu items
    window.menuInstructions.menuItemBorder=0;
    window.menuInstructions.fontSize=12;
    window.menuInstructions.menuItemHeight=18;
    window.menuInstructions.menuItemIndent=10;
    window.menuInstructions.menuItemWidth=150;

    // this is how the styles are passed to the other options
    window.menuInstructions.prototypeStyles = window.menuInstructions;
}

//--------------------------------------------------------------------------
//
// Saves the menus to a menu container. This must be done after creation of
// the various menus, and assumes that menuInstructions is one of them.
//
//--------------------------------------------------------------------------
function saveMenus()
{
  window.menuInstructions.writeMenus();
}

//--------------------------------------------------------------------------
//
// Log the user in by calling logout.php page, which will then redirect
// itself back to index.php.
//
//--------------------------------------------------------------------------
function loginUser()
{
  window.location = 'login.php';
}

//--------------------------------------------------------------------------
//
// Log the user out by calling the logout.php page, which will then redirect
// itself back to index.php.
//
//--------------------------------------------------------------------------
function logoutUser()
{
  if (confirm('Do you wish to log out?'))
    window.location = 'logout.php';
}

//--------------------------------------------------------------------------
//
// Displays a colour selection window like a dialog box.
//
//--------------------------------------------------------------------------
function selectColour(colourType) {
  winParms = "toolbar=no,status=no,directories=no,location=no,scrollbars=yes,resizable=yes,width=350,height=275";
  win = window.open("colour_pick.php?colour_type=" + colourType, "colourPicker", winParms);
  win.focus();
}

//--------------------------------------------------------------------------
//
// Displays a window of 1536 colours plus some black and white
//
//--------------------------------------------------------------------------
function showAllColours() {
  winParms = "toolbar=no,status=no,directories=no,location=no,scrollbars=yes,resizable=yes";
  win = window.open("1536colours.html", "1536colours", winParms);
  win.focus();
}

//--------------------------------------------------------------------------
//
// Displays an image upload window like a dialog box.
//
//--------------------------------------------------------------------------
function imageUpload() {
  winParms = "toolbar=no,status=no,directories=no,location=no,scrollbars=yes,resizable=yes,width=550,height=450";
  win = window.open("image_upload1.php", "imageUpload", winParms);
  win.focus();
}

//--------------------------------------------------------------------------
//
// Displays an image in a window like a dialog box.
//
//--------------------------------------------------------------------------
function imageView(imageName) {
  winParms = "toolbar=no,status=no,directories=no,location=no,scrollbars=yes,resizable=yes,width=550,height=450";
  win = window.open("", "imageView", winParms);
  win.document.writeln("<HTML>");
  win.document.writeln("<HEAD>");
  win.document.writeln("<LINK REL=\"stylesheet\" type=\"text/css\" HREF=\"wipm.css\">");
  win.document.writeln("<TITLE>Image View</TITLE>");
  win.document.writeln("</HEAD>");
  win.document.writeln("<BODY>");
  win.document.writeln('<BR><BR><CENTER><IMG SRC="' + imageName + '"></CENTER>');
  win.document.writeln("</BODY>");
  win.document.writeln("</HTML>");
  win.document.close();
  win.focus();
}


//--------------------------------------------------------------------------
