/*
Filename:     popup.js
Description:  This file provides javascript functions for the dynamic drop-down menus
		    as adapated from the Apple's Developer Connection, the page being
		    http://developer.apple.com/internet/webcontent/hideshow_layer.html.

Author:       Greg Phillips
Copyright:    2004 Clariscope Creative
Created:      16 August 2004
Last Update:  2 September 2004
*/

function showMenu (targetObjectId, topMenuObjectId, topLevel, level) {

     // hide any currently-visible popups
	if (topLevel == level) {
	     hideCurrentMenu();
	}

     if ( level == 3 ) {
		l3MenuItemId = targetObjectId.substring(5, targetObjectId.length);
	     var l3MenuItem = document.getElementById(l3MenuItemId);
     }

     // get the elements themselves
     var targetMenu = document.getElementById(targetObjectId);
     var topMenu = document.getElementById(topMenuObjectId);

     //alert('topMenu.offsetLeft/Width = ' + topMenu.offsetLeft + '/' + topMenu.offsetWidth);

	// check the topMenu left (and if level==3, the width) to
	// find the new left of the targetMenu
     if (topMenu.offsetLeft) {
     	if (level == 2) {
		     var newXCoordinate = topMenu.offsetLeft + 0 + 'px';
		} else {
		  	var newXCoordinate = topMenu.offsetLeft + topMenu.offsetWidth - 5 + 'px';
	     }
	} else {
		var newXCoordinate = 150;
	     // adjust anything beyond 0 charsFromLeft
	     if (newXCoordinate) newXCoordinate = newXCoordinate - 3 + 'px';
     }

	// check the top and height to find the bottom = new top of the targetMenu
     if ( topMenu.offsetTop ) {
     	if (level == 2) {
		     var newYCoordinate = topMenu.offsetTop +
		     			      topMenu.offsetParent.offsetTop +
		     			      topMenu.offsetParent.offsetParent.offsetTop +
		     			      topMenu.offsetParent.offsetParent.offsetParent.offsetTop +
		     			      topMenu.offsetHeight + 2.9 + 'px';
		     //var newYCoordinate = topMenu.offsetTop + topMenu.offsetParent.offsetTop + topMenu.offsetParent.offsetParent.offsetTop + topMenu.offsetParent.offsetParent.offsetTop + topMenu.offsetHeight + 'px';
		} else {
		     var newYCoordinate = l3MenuItem.offsetTop + l3MenuItem.offsetParent.offsetTop + 4 + 'px';
	     }
	} else {
	     var newYCoordinate = '111px';
     }

     //alert("x = " + newXCoordinate + "; y = " + newYCoordinate);

     // re-position the target menu object
     moveObject(targetObjectId, newXCoordinate, newYCoordinate);

     // and make it visible
     if( changeObjectVisibility(targetObjectId, 'visible') ) {
          // if we successfully showed the popup
          // store its Id on a globally-accessible object
          window.currentlyVisibleL2Menu = targetObjectId;
          window.currentMenuLevel = 2;
		if ( level == 3 ) {
			if ( changeObjectVisibility(topMenuObjectId, 'visible') ) {
	               // if we successfully showed the popup
	               // store its Id on a globally-accessible object
		          window.currentlyVisibleL2Menu = topMenuObjectId;
		          window.currentlyVisibleL3Menu = targetObjectId;
	     	     window.currentMenuLevel = 3;
	     	}
	     }
          return true;
     } else {
          // we couldn't show the popup, boo hoo!
          return false;
     }
} // showMenu


function hideCurrentMenu() {
	// note: we've stored the currently-visible popup on the global object window.currentlyVisibleMenu

	if (window.currentlyVisibleL2Menu) {
	     changeObjectVisibility(window.currentlyVisibleL2Menu, 'hidden');
	     window.currentlyVisibleL2Menu = false;
     }

     if (window.currentlyVisibleL3Menu && !window.currentlyVisibleL2Menu) {
          changeObjectVisibility(window.currentlyVisibleL3Menu, 'hidden');
          window.currentlyVisibleL3Menu = false;
     }
} // hideCurrentMenu


// this function handles the presentation of non-menu divs already in a containing div
function showDiv(targetObjectId) {

     // hide any currently-visible popups
	if ( window.currentlyVisibleDiv ) {
	     hideCurrentDiv();
	}

     // get the elements themselves
	//var targetDiv = document.getElementById(targetObjectId);

     // and make it visible
     if( changeObjectDisplay(targetObjectId, 'block') ) {
          // if we successfully showed the div
          // store its Id on a globally-accessible object
          window.currentlyVisibleDiv = targetObjectId;
          return true;
     } else {
          // we couldn't show the popup, boo hoo!
          return false;
     }

} // showDiv

function hideCurrentDiv() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
	if ( window.currentlyVisibleDiv ) {
	     changeObjectDisplay(window.currentlyVisibleDiv, 'none');
	     window.currentlyVisibleDiv = false;
	}
} // hideCurrentDiv

function popWin(arg) {

	where = arg;

	newLocD = window.open(where, "locDirWindow", "width=820, height=610,resizable=yes,scrollbars=yes");

} // end popWin

function popNewWin(arg) {
	where = arg;
	
	window.open(where, 'FetchPetCare', 'width=820, height=610, resizable=yes, scrollbars=yes, toolbar=yes, location=yes, status=yes, menubar=yes');
	return false;
}

