/*  This code copyright iWeb Solutions Pty Ltd 
	
	iStore Version 1.1
	Modified: 25th February 2003
	By: r.breuer@iwebsolutions.com.au
*/

/*	BROWSER DETECTION OBJECT  */
function oBrowser() {
	var ua, s, i;
	this.isIE = false;
	this.isNS = false;
	this.ver = null;
	this.isWin = false;
	this.isMac = false;
 	ua = navigator.userAgent;
	this.isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows
	this.isMac = (navigator.appVersion.indexOf("Macintosh") != -1) ? true : false; // true if we're on windows
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.ver = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.ver = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
	s = "Netscape/";
    if ((i = ua.indexOf(s)) >= 0) {
		this.ver = parseFloat(ua.substr(i + s.length));
	}else{
	    this.ver = 6.1;
	}
    return;
  }
  s = "Mozilla/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.ver = parseFloat(ua.substr(i + s.length));
    return;
  }
}
var browser = new oBrowser(); //Set browser and version

/* Retrieves the base url from the current page */
function oBaseUrl(){
	var DocURL, protocolIndex, ServerIndex, BeginURL
	this.baseURL = null;
	DocURL = document.URL;
	protocolIndex=DocURL.indexOf("://",4);
	serverIndex=DocURL.indexOf("/",protocolIndex + 3);
	BeginURL=DocURL.indexOf("#",1) + 1;
	this.baseURL=DocURL.substring(BeginURL,serverIndex) + '/';
}

/*	WINDOW FUNCTIONS
	Usage:
		1. <a href="JavaScript:openWindowAtCentre('http://www.iwebsolutions.com.au','iWeb Solutions', 400, 200);">iWeb Solutions</a>
	->	2. <a href="http://www.heightdynamics.com.au" onclick="openScrollWindowAtCentre(this.href, 'Height Dynamics', 670, 700);return false;" onfocus="this.blur()">Height Dynamics</a><br>
*/
var oWin = null;
function openWindowAtCentre( location, name, sizeX, sizeY ) {
  var posx = (screen.availWidth-sizeX)/2;
  var posy = (screen.availHeight-sizeY)/2;
  var windowString = 'toolbar=no,location=no,menubar=no,status=no,resizable=no,directories=no,scrollbars=no,copyhistory=no,width='+sizeX+',height='+sizeY+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
  oWin = window.open(location, name, windowString);
  oWin.focus();
}
function openScrollWindowAtCentre( location, name, sizeX, sizeY ) {
  var posx = (screen.availWidth-sizeX)/2;
  var posy = (screen.availHeight-sizeY)/2;
  var windowString = 'toolbar=no,location=no,menubar=no,status=no,resizable=no,directories=no,scrollbars=yes,copyhistory=no,width='+sizeX+',height='+sizeY+',left='+posx+',top='+posy+',screenX='+posx+',screenY='+posy;
  oWin = window.open(location, name, windowString);
  oWin.focus();
}

/* Custom Functions */
function fbClose() {  //Hides the Feedback Window.
	oFeedback = document.getElementById('Feedback');
	oFeedback.style.visibility = "hidden";
	oFeedback.style.position = "absolute";
}
//*****************************************************************************
// Code modified form Mike Hall
// See http://www.brainjar.com/
//*****************************************************************************

var activeMenu = null;

function doMenu(event, menuType) {
	var oMenu;   // Holds all the objects associated to the current menu item.
	if (browser.isIE)  // Get the current menu item.
		oMenu = window.event.srcElement;
	else
		oMenu = event.currentTarget;
	oMenu.blur();
	if (oMenu == activeMenu) return false;  // Exit if this button is the currently active one.
	if (oMenu.subMenu == null) oMenu.subMenu = document.getElementById('sm' + oMenu.getAttribute("ID")); // Associate the sub menu to this menu item.
	initMenu(oMenu);  // initialise the sub menu.
	if (activeMenu != null) hideSubMenu(activeMenu); // Hide the current menu
	//  Show this menu items sub menu
	if (oMenu != activeMenu) {
		showSubMenu(oMenu, menuType);
		activeMenu = oMenu;
	} else activeMenu = null;
	return false;
}


function initPageMenus(Type){
/* Fix for netscape browsers to preposition the menus in the right position */
	var menuItems = null;
	var oMenu = null;
	var oSubMenu = null;
	var x, y;
	if (browser.isNS){
		oMenu = document.getElementById('navMenu');
		menuItems = oMenu.getElementsByTagName("A");
		for (i = 0; i < menuItems.length; i++){
			if (Type == 1) {
				x = getPageOffsetLeft(oMenu) + oMenu.offsetWidth;
				y = getPageOffsetTop(oMenu);
			} else {
				x = getPageOffsetLeft(oMenu);
				y = getPageOffsetTop(oMenu) + oMenu.offsetHeight;
			}
			oSubMenu = document.getElementById('sm' + menuItems[i].getAttribute("ID"));
			if (oSubMenu != null){
				oSubMenu.style.left = x + "px";
				oSubMenu.style.top  = y + "px";
			}
		}
	}
}

function initMenu(oMenu) {
	var menuItems;
	var width;
	// Set mouseout events for the menu item and sub menu.
	if (oMenu != null){
		if (oMenu.onmouseout == null) oMenu.onmouseout = itemMouseout;
	if (oMenu.subMenu != null){
		if (oMenu.subMenu.onmouseout == null) oMenu.subMenu.onmouseout = itemMouseout;
		// Set the width of the first sub menu item fix for IE
		if (browser.isIE) {
			menuItems = oMenu.subMenu.getElementsByTagName("A");
			width = menuItems[0].offsetWidth;
			menuItems[0].style.width = width +"px";
		}
	}
	}
}

function itemMouseout(event) {
	var oElement;
	if (activeMenu == null) return;
	if (browser.isIE)
		oElement = window.event.toElement;
	else if (event.relatedTarget != null)
		oElement = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
	if (getContainerWith(oElement, "DIV", "mnuContext") == null) {
		hideSubMenu(activeMenu);
		activeMenu = null;
	}
}

function showSubMenu(oMenu, Type) {
	var x, y;
	// Find the menu position.
	if (Type == 1) {
		x = getPageOffsetLeft(oMenu) + oMenu.offsetWidth;
		y = getPageOffsetTop(oMenu);
	} else {
		x = getPageOffsetLeft(oMenu);
		y = getPageOffsetTop(oMenu) + oMenu.offsetHeight;
	}

	// Adjust the position for IE and 
	if (browser.isIE && browser.isWin) {
		x += oMenu.offsetParent.clientLeft;
		y += oMenu.offsetParent.clientTop;
	}
	if (browser.isIE && browser.isMac) {
		x = Type == 1 ?	x - 20 : x - 3;
		y = y - 3;
	}
	if (oMenu.subMenu != null){
		// position the sub menu and then display it.
		oMenu.subMenu.style.left = x + "px";
		oMenu.subMenu.style.top  = y + "px";
		oMenu.subMenu.style.visibility = "visible";
	}
}

function hideSubMenu(menu) {
	if (menu == null || menu.subMenu == null) return;
	menu.subMenu.style.visibility = "hidden";
	menu.subMenu = null;
 }

function getContainerWith(node, tagName, className) {
	// Starting with the given node, find the nearest containing element
	// with the specified tag name and style class.
	while (node != null) {
		if (node.tagName != null && node.tagName == tagName && hasClassName(node, className)) return node;
		node = node.parentNode;
	}
	return node;
}

function hasClassName(el, name) {
	// Return true if the given element currently has the given class name.
	var i, list;
	list = el.className.split(" ");
	for (i = 0; i < list.length; i++)
		if (list[i] == name) return true;
	return false;
}
	
function getPageOffsetLeft(el) {
	// Return the x coordinate of an element relative to the page.
	var x;
	x = el.offsetLeft;
	if (el.offsetParent != null) x += getPageOffsetLeft(el.offsetParent);
	return x;
}

function getPageOffsetTop(el) {
  // Return the y coordinate of an element relative to the page.
	var y;
	y = el.offsetTop;
	if (el.offsetParent != null) y += getPageOffsetTop(el.offsetParent);
	return y;
}

