 /* **********************************************************************
 $Id: global.js,v 1.3 2007/09/10 06:13:49 helenf Exp $

 Copyright (c) 2000-2007 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 -> helen.fu at massmedia.com.au
 Created:				21 August 2007
 ------------------------------------------------------------------------
 Comments:	
 
 
 ********************************************************************** */
 
 /* DOM 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();
 
/* USED FOR FLASH HEADINGS */
function setupHeadings(myLevel) {
	var myElements = document.getElementsByTagName("H" + myLevel);
	if (myLevel == 1 || myLevel == 2) {
		var myFontSize = 21;
	} else {
		var myFontSize = 15;
	}
	for (var i=0; i < myElements.length; i++) {
		if (ie) {
			myHeight = myElements[i].offsetHeight + 1;
			myWidth = myElements[i].offsetWidth;
		} else {
			myHeight = myElements[i].clientHeight;
			myWidth = myElements[i].clientWidth;
		}
		myElements[i].id = "flashHeading" + myLevel + "_" + i;
		
		myColour = getStyle(myElements[i].id, "color");
		if (myColour.substr(0,4) == "rgb(") {
			myColour = rgbToHtmlColor(myColour);
			myColour = myColour.substr(1);
		} else if (myColour.substr(0,1) == "#") {
			// remove '#'..
			myColour = myColour.substr(1);
		} else {
			// default to black...
			myColour = "000000";
		}
		
		if (myWidth > 0 && myHeight > 0) {
			so = new SWFObject("common/flash/header.swf", myElements[i].id + "_flash", myWidth, myHeight, "7", "#ffffff");
			so.addParam("loop", "true");
			so.addParam("menu", "false");
			so.addParam("flashvars", "lcId=flashBanner&fontSize=" + myFontSize + "&swfString=" + escape(myElements[i].innerHTML) + "&swfHeight=" + myHeight + "&swfWidth=" + myWidth + "&swfColor=0x" + myColour);
			so.addParam("quality", "high");
			so.addParam("wmode", "transparent");
	   		so.write(myElements[i].id);
			
			myElements[i].style.padding = "0px";
			
			myElements[i].style.height = myHeight + "px";
			myElements[i].style.width = myWidth + "px";
			myElements[i].childNodes[0].style.padding = "0px";
			myElements[i].childNodes[0].style.width = myWidth + "px";

		} else {
			//alert("ignoring heading: " + myElements[i].innerHTML);
		}
		
	}
}

function getStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (x.currentStyle) { 
		var y = x.currentStyle[styleProp];
	} else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

//convert hsl to an html color string
function rgbToHtmlColor(myColour) {
	tempColour = myColour.split(",");
	r = parseInt(tempColour[0].substr(4));
	g = parseInt(tempColour[1]);
	b = parseInt(tempColour[2]);
	return "#" + toHex(r) + toHex(g) + toHex(b);
}

//convert decimal to hex
function toHex(decimal,places) {
   if (places == undefined || isNaN(places))  places = 2;
   var hex = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
   var next = 0;
   var hexidecimal = "";
   decimal = Math.floor(decimal);
   while (decimal > 0) {
      next = decimal % 16;
      decimal = Math.floor((decimal - next)/16);
      hexidecimal = hex[next] + hexidecimal;
   }
   while (hexidecimal.length<places) {
      hexidecimal = "0"+hexidecimal;
	}
   return hexidecimal;
}


/* FORM CHECKS - used on survey page */

// to show/hide a field depending on whether checkbox is selected..
function showField(currentFld,myFld) {
	var myCheckObj = currentFld;
	//var myField = document.forms[0].elements[myFld];
	var myField = document.getElementById(myFld);
	if (myField != null && typeof(myField) != "undefined") {
		if (myCheckObj.type == "checkbox") {
			if (myCheckObj.checked == true) {
				myField.className = myField.className.replace(/(hide)/,"show");
			} else {
				myField.className = myField.className.replace(/(show)/,"hide");
			}
		} 
	}
}

// to show/hide questions depending on which radio button is selected..
function showQuestions(myFld,myStatus) {
	var myField = document.getElementById(myFld);
	if (myField != null && typeof(myField) != "undefined") {
		if (myStatus == true) {
			myField.className = myField.className.replace(/(hide)/,"show");
		} else {
			myField.className = myField.className.replace(/(show)/,"hide");
		}
	}
}




