/**************************************************************************
** $Id: global.js,v 1.8 2007/02/06 06:25:40 helenf Exp $
**
** Copyright (c) 2000-2006 MassMedia Studios Pty Ltd.
** 68-72 Wentworth Ave, Surry Hills, NSW 2010, Australia.
** All rights reserved.
**
** This software is the confidential and proprietary information of 
** MassMedia Studios Pty Ltd. ("Confidential Information").  You shall not
** disclose such Confidential Information and shall use it only in
** accordance with the terms of the license agreement you entered into
** with MassMedia Studios Pty Ltd.
** ------------------------------------------------------------------------
** 
** Author: Helen Fu
** Release notes:
**
**************************************************************************/

/*-------------------------- GLOBAL --------------------------*/

function toggleTab(currentTab) {
	myAnchors = document.links; // all links..
	for(var i=0; i < myAnchors.length; i++) { // for all links..
		if(myAnchors[i].className.indexOf("tab") != -1) { // links that have "tab" as part of their classnames..
			myId = myAnchors[i].id;
			infoId = "info" + myId.substring(3);
			myInfo = document.getElementById(infoId); // matching information div..
			if(myInfo != null && typeof(myInfo) != "undefined") { // if the info div exists..
				if(myId.substring(3) == currentTab) { // and the current link is the same as the selected link..
					myAnchors[i].className = "tabSelected";  // tab selected..
					myInfo.className = "show"; // show matching info div..
				} else {
					myAnchors[i].className = "tabDefault"; // tab deselected..
					myInfo.className = "hide"; // hide info div..
				}
			}
			
		}
	}
}

/* Browser Detection */
function dom_browser() {
	// browser identification based on dom capabilities
	this.myNav = this.navigator;
	this.version = this.navigator.appVersion;
	this.name = this.navigator.appName;
	this.userAgt = this.navigator.userAgent;
	this.ns4 = (document.layers) ? true : false;
	this.ns6 = (this.navigator.userAgent.indexOf("Netscape6") != -1) ? true : false;
	this.dom = (document.getElementById) ? true : false;
	this.ie4 = (document.all) ? true : false;
	this.mac = (this.version.indexOf("Mac") != -1) ? true : false;
	this.ie = (this.version.indexOf("MSIE") != -1) ? true : false;
	this.windows = (this.version.indexOf("Windows") != -1) ? true : false;
	this.hasPlugins = (this.navigator.plugins) ? true : false;
	this.ie6 = (this.version.indexOf("MSIE") != -1 && this.version.indexOf("6") != -1) ? true : false; 
	
	this.ie55 = (this.version.indexOf("MSIE 5.5") != -1) ? true : false;
	this.ie5 = (this.version.indexOf("MSIE 5.01") != -1) ? true : false;
	this.ns = (this.userAgt.indexOf("Netscape") != -1) ? true : false;
	this.ff = (this.userAgt.indexOf("Firefox") != -1) ? true : false;
	this.safari = (this.userAgt.indexOf("Safari") != -1) ? true : false;
}

dom_browser();

/*-------------------------- FORM ELEMENT VALUES --------------------------*/

function checkValue(myElement,initialVal) {
	if(myElement != null && typeof(myElement) != "undefined") {
		if(myElement.value == initialVal) {
			myElement.value = "";
		} else if (myElement.value == "") {
			myElement.value = initialVal;
		} else {
			// do nothing
		}
	}
}

/*-------------------------- DEPT DETAILS TOGGLE DIV --------------------------*/

function showHideDept(myDept) { /* changed 2007-01-08 - round 1 revisions */
	myObj = document.getElementById(myDept);
	myLink = document.getElementById(myDept + "link");
	if(myObj != null && typeof(myObj) != "undefined" && myLink != null && typeof(myLink) != "undefined") {
		if(myObj.className == "hide") {
			myObj.className = "show";
			myLink.className = "iconMinus"; 
		} else {
			myObj.className = "hide";
			myLink.className = "iconPlus";
		}
	}
}

/*-------------------------- INCREASE / DECREASE FONT SIZE --------------------------*/

// on page load... set initial font size...
function setupFontSize() {
	try
	{
		myObj = document.body;
		myCookie = getCookie("WCCFontSize");
		if(myObj != null && typeof(myObj) != "undefined" && myCookie == null) {
		// if object exists and cookie not set then...
		myObj.style.fontSize = "0.7em";
		} else if(myObj != null && typeof(myObj) != "undefined") {
		// if object exists and cookie is set...
		myObj.style.fontSize = myCookie;
		}
	}
	catch(err){}
}

// set cookie for storing document font size...
function setCookie(cName,cValue,cExpiryDays) {
 var expDate = new Date();
 expDate.setDate(expDate.getDate()+cExpiryDays);
 document.cookie = cName + "=" + escape(cValue) + ((cExpiryDays == null) ? "" : ";expires=" + expDate);
}

// get value of cookie if it exists...
function getCookie(cName) {
 if(document.cookie.length > 0) { // if there are cookies...
  cStart = document.cookie.indexOf(cName + "="); // get index of where cookie value starts...
  if(cStart != -1) {
   cStart = cStart + cName.length + 1;
   cEnd = document.cookie.indexOf(";",cStart);
   if(cEnd == -1) cEnd = document.cookie.length;
   return unescape(document.cookie.substring(cStart,cEnd));
  }
 }
 return null;
}

// change font size.. increase or decrease font size...
function changeFont(myDir) {
 myObj = document.body;
 if(myObj != null && typeof(myObj) != "undefined") {
  tempFont = parseFloat(myObj.style.fontSize);
  if(myDir == "increase" && tempFont < 1) {
   myObj.style.fontSize = (tempFont + 0.1) + "em";
  } else if(myDir == "decrease" && tempFont > 0.5) {
   myObj.style.fontSize = (tempFont - 0.1) + "em";
  } else {
   // don't change font...
  }
  // set cookie to remember font size for 30 days..
  setCookie("WCCFontSize",myObj.style.fontSize,30); 
  navResize(); // reset height of wrapper containers..
 }
}

// to resize wrapper for nav items when font size increases...
function navResize() {
	myDivs = document.getElementsByTagName("div"); // all divs in site..
	for(var i = 0; i < myDivs.length; i++) {
		if(myDivs[i].id.indexOf("ItemsMenu") != -1) { // "ItemsMenu" divs..
			myDivs[i].style.height = "auto"; // reset height..
			var oh = myDivs[i].offsetHeight; // find offset height...
			myDivs[i].style.height = oh + "px"; // set to new height..
			var myWrapper = document.getElementById("TransMenu" + myDivs[i].id.substring(9,myDivs[i].id.length)); // get wrapper object..
			if(myWrapper != null && typeof(myWrapper) != "undefined") { // if wrapper element exists..
				myWrapper.style.height = oh + "px"; // set wrapper element to have new height..
			}
		}
	}
}

/*-------------------------- PRINT AND SEND TO FRIEND --------------------------*/

// opens up the send to friend page in a popup window...
function openPage(myPage) {
	switch (myPage) {
		case "s2fPage":
			myS2FWin = window.open('/SendToFriend.asp','myS2FWin','width=592,height=520,scrollbars=no,resizeable=no,menubar=no,statusbar=no');
			myS2FWin.focus();
			break;
		default:
			myPrintWin = window.open(myPage,'myPrintWin','width=656,height=500,scrollbars=yes,resizeable=no,menubar=no,statusbar=no');
			myPrintWin.focus();
			break;
	}
}

// brings up the print dialog box when clicking the print icon...
function printPage() {
	this.print();
}


/*-------------------------- RESET NAVIGATION CLASS --------------------------*/

// to reset class to open for current links if they have subnavs...

function setNavClass(val) {
        var isIE = document.all?true:false;
        theLi = document.getElementById(val);
        if(isIE){        
           theLi.setAttribute("className","selSection");}
        else{
           theLi.setAttribute("class","selSection");}
}


