// Function to add page to user's Favourites
function addBookmark(title,url) 
{
    if (window.sidebar)
    {         
        window.sidebar.addPanel(title, url,""); 
    } 
    else if(document.all) 
    {
        window.external.AddFavorite( url, title);
    } 
    else if(window.opera && window.print)
    {
        return true;
    }
}

// Generic popup window function
function OpenPopup(url, width, height)
{
	var popupFeatures;
	var newWindow;
	
	popupFeatures = 'width=' + width + ',height=' + height;
	popupFeatures = popupFeatures + ',location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes';
	
	newWindow = window.open(url, 'popupWindow', popupFeatures);
	
	if (window.focus)
	{
		newWindow.focus()
	}
	
	return false;
}

// Function to retrieve an object element
function GetObject(id)
{
	if (document.getElementById)
	{
		return document.getElementById(id);
	}
	else if (document.all)
	{
		return document.all[id];
	}
}

// Function to show/hide block-level description items with the 
// minus-before, plus-before icons
function ToggleShowHideBlock (senderId, targetId, strSenderMessage, blnPrintable)
{
    var sender = GetObject(senderId);
  	var target = GetObject(targetId);

    if (sender && target)
    {
        if (sender.className.match ('minus-before'))
        {
            sender.className = 'plus-before';
            sender.innerHTML = 'Show ' + strSenderMessage;

            target.className = 'noshow';
        }
        else 
        {
            sender.className = 'minus-before';
            sender.innerHTML = 'Hide ' + strSenderMessage;
            
            target.className = 'show';
        }

        if (!blnPrintable)
        { 
            sender.className += " noprint";  
        }
    }
} 

// Function to show/hide block-level elements
function ShowHide(targetId)
{
	var target = GetObject(targetId);
	
	if (target)
	{
		var show = (target.style.display == 'none' ? true : false);
		
		if (show)
		{
			target.style.display = 'block';
		}
		else
		{
			target.style.display = 'none';
		}
	}
	
	return false;
}

// Function to show/hide inline elements
function InlineShowHide(targetId)
{
	var target = GetObject(targetId);
	
	if (target)
	{
		var show = (target.style.display == 'none' ? true : false);
		
		if (show)
		{
			target.style.display = 'inline';
		}
		else
		{
			target.style.display = 'none';
		}
	}
	
	return false;
}

// Function to show/hide collapsing menus
function ShowHideMenu(sender, targetId)
{
	var target = GetObject(targetId);
	
	if (target)
	{
		var show = (target.style.display == 'none' ? true : false);
		
		if (show)
		{
			SetClassName(sender, '');
			target.style.display = 'block';
		}
		else
		{
			SetClassName(sender, 'closed');
			target.style.display = 'none';
		}
	}
	
	return false;
}


// Function to set the class attribute of an element
function SetClassName(element, className)
{
	if (element != null)
	{
		element.className = className;
	}
}


/********************************************************************************
* Functions to load, cache and rotate the banner image
********************************************************************************/
// set up some global variables
var _BannerImage;
var _CachedBannerImage = new Image();
var _CanRotate = false;

/*	Function to initialize the current image to be rotated	*/
function InitRotateImage(element)
{
	_BannerImage = element;
	
	// ensure that we're ready to start rotating images
	_CanRotate = typeof(_BannerImage) != 'undefined';
	_CanRotate = _CanRotate && (typeof(_RotatingImages) != 'undefined');
	_CanRotate = _CanRotate && (_RotatingImages.length > 0);
}

// Script to rotate through banner images
// expects _RotatingImages array to have been declared and defined
function LoadImageIntoCache()
{
	if (!_CanRotate)
	{
		return;
	}
	
	if (_BannerImage && _CachedBannerImage)
	{
		var index = Math.floor(Math.random() * _RotatingImages.length);
		
		_CachedBannerImage.src = _RotatingImages[index];		// load cached image
		_CachedBannerImage.onload = function () {SwapImages()};	// swap cached image when loaded
	}
}

function SwapImages()
{
	var canApplyFilter = _BannerImage.filters;

	if (canApplyFilter)
	{
		_BannerImage.filters.item(0).apply();
	}
	
	_BannerImage.src = _CachedBannerImage.src;
	
	if (canApplyFilter)
	{
		_BannerImage.filters.item(0).play();
	}
	
	setTimeout("LoadImageIntoCache()", 8000);
}

window.onload = function() {LoadImageIntoCache()}



var openMenuId = '';		/* id of currently open menu element */
var isMenuActive = false;	/* mouse is currently over the open menu? */

/********************************************************************************
* HideDropMenu(menuName)
********************************************************************************/
function HideDropMenu(menuId)
{
	if (!isMenuActive && openMenuId == menuId)
	{
		var menu = GetObject(menuId);

		if (menu)
		{
			menu.style.display = 'none';
			openMenuId = '';
		}			
	}
}


/********************************************************************************
* ShowDropMenu(menuHeader, menuId)
********************************************************************************/
function ShowDropMenu(menuHeader, menuId) {
	// if a menu is currently open, close it
	if (openMenuId != '' && openMenuId != menuId) {
		var menu = GetObject(openMenuId);
		
		if (menu)
		{
			menu.style.display = 'none';
			openMenuId = '';
		}
	}
	
	// open the new menu
 	var menu = GetObject(menuId);
	if (menu)
	{
		var show = (menu.style.display == 'none' ? true : false);
		
		if (show)
		{
			menu.style.top = CalculateSumOffset(menuHeader, 'offsetTop') + 25 + 'px';
			menu.style.left = CalculateSumOffset(menuHeader, 'offsetLeft') + 'px';
			menu.style.display = 'block';
			openMenuId = menuId;
			isMenuActive = true;
		}
		else
		{
			isMenuActive = false;
			setTimeout("HideDropMenu('" + menuId + "')", 500);
		}
	}
}

/********************************************************************************
* DropMenuMouseEventHandler(menuName, activateMenu)
********************************************************************************/
function DropMenuMouseEventHandler(menuId, activateMenu) 
{
	isMenuActive = activateMenu;
	if (!activateMenu) setTimeout("HideDropMenu('" + menuId + "')", 500);
}


/********************************************************************************
* CalculateSumOffset(element, offsetName)
********************************************************************************/
function CalculateSumOffset(element, offsetName)
{
	var totalOffset = 0;
	do
	{
		totalOffset += eval('element.' + offsetName);
		element = eval('element.offsetParent');
	} while (element != null);
	return totalOffset;
}

// The following JavaScript function is used to launch an iDelve Map in a new window
// Open map popup
// [USAGE] javascript:MapPopup()
//
function MapPopup()
{
	window.open('http://www.westernaustralia.com/watc/Controls/Utility/MapView.aspx?view=v&type=&id=', 'idm', 'height=640, width=800, location=no, menubar=no, status=no, titlebar=no, scrollbars=yes, resizable=yes');
}

// The following Javascript function is used to launch the Currency Converter in a new window
// Open currency calculator popup using
// [USAGE] javascript:CurrencyPopup()
//
function CurrencyPopup()
{
	window.open('http://www.westernaustralia.com/watc/Controls/Utility/CurrencyPopup.asp', '_blank', 'height=400, width=670, location=no, menubar=no, status=no, titlebar=no, scrollbars=yes, resizable=yes');
}



