
/**************************************************************************
** $Id: global.js,v 1.8 2006/12/21 22:47:58 helenf Exp $
**
** Copyright (c) 2000-2005 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:
** Sections: global
**
**************************************************************************/

/*-------------------------- GLOBAL --------------------------*/

/**********************************************************/
/* Added by ADD, Study Group 
/* Function: SendFriend
/* Purpose: Opens pop-up form to send page to a friend passing 
/*          the referrer in the querystring.
/**********************************************************/             
function SendFriend(strURL, strName, intWidth, intHeight)
{
    var sw = screen.availWidth;
    var sh = screen.availHeight;
    var left = (sw-intWidth)/2;
    var top = (sh-intHeight)/2;
    var url = strURL + '?url=' + window.location.toString();
   
    windowHandle = window.open(url, strName,"width=" + intWidth + ", height="+intHeight+", location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes, left="+left+", top="+top+"");
    windowHandle.focus();
}

/********************************************************/

// opens up the send to friend page in a popup window...
function openPage(myPage) {
	switch (myPage) {
		case "s2fPage":
			myS2FWin = window.open('SendToFriend.aspx','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();
}

//commented out by Riaz L. 17/5/11. Testing CMS 10.0 clashes
/*
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();
*/

// adjust the vertical height of the text inside the main nav buttons...
function adjustNavText() {
	firstButton = true; // whether it is the first button..
	spanList = new Array();
	spanList = document.getElementsByTagName("span"); // look for all spans...
	for(var i=0; i < spanList.length; i++) {
		if(spanList[i].className == "buttonText") { // if it is a span inside a main nav button...
			if(spanList[i].scrollHeight < 14) { // and it's height is less that 14px (1 line)...
				spanList[i].style.paddingTop = "10px"; // set padding top to 10px...
			} else {
				spanList[i].style.paddingTop = "4px"; // otherwise set padding top to 4px..
			}
		}
	}
}


/*-------------------------- INCREASE / DECREASE FONT SIZE --------------------------*/

// on page load... set initial font size...
function setupFontSize() {
	try
	{
		myObj = document.body;
		myCookie = getCookie("CSUFontSize");
		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 (isNaN(tempFont)) {
	  tempFont = 0.7;
  }
  if(myDir == "increase" && tempFont < .8) {
   myObj.style.fontSize = (tempFont + 0.1) + "em";
  } else if(myDir == "decrease" && tempFont > 0.6) {
   myObj.style.fontSize = (tempFont - 0.1) + "em";
  } else {
   // don't change font...
  }
  // set cookie to remember font size for 30 days..
  setCookie("CSUFontSize",myObj.style.fontSize,30); 
 }
}


/*-------------------------- RESET NAVIGATION CLASS --------------------------*/

// to reset class to open for current links if they have subnavs...
function setNavClass(val,type) {
        var isIE = document.all?true:false;
        theLi = document.getElementById(val);
		
		if(type == 1)
		{
			if(isIE){        
			if(theLi.getAttribute("className") == "current")
					theLi.setAttribute("className","open");}
			else{
			if(theLi.getAttribute("class") == "current")
					theLi.setAttribute("class","open");}
		}
		else
		{
			if(isIE){        
			if(theLi.getAttribute("className") == "open")
					theLi.setAttribute("className","current");}
			else{
			if(theLi.getAttribute("class") == "open")
					theLi.setAttribute("class","current");}
		}			
}

/******************************************************************************/
function restrictinput(maxlength,e,placeholder)
{
 if (window.event&&event.srcElement.value.length>=maxlength)
  return false
 else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength)
 {
  var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
  if (pressedkey.test(String.fromCharCode(e.which)))
  e.stopPropagation()
 }
}
function countlimit(maxlength,e,placeholder)
{
 var theform=eval(placeholder)
 var lengthleft=maxlength-theform.value.length
 var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
 if (window.event||e.target&&e.target==eval(placeholder))
 {
  if (lengthleft<0)
   theform.value=theform.value.substring(0,maxlength)
   placeholderobj.innerHTML=lengthleft
 }
}
function displaylimit(theform,thelimit,thetext)
{
var ns6=document.getElementById&&!document.all
var limit_text='<b><span id="'+theform.toString()+'">'+thelimit+'</span></b> '+ thetext;
 if (document.all||ns6)
  document.write(limit_text)
  if (document.all)
  {
   eval(theform).onkeypress=function()
   
   { 
   return restrictinput(thelimit,event,theform)
   }
   eval(theform).onkeyup=function()
   { 
    countlimit(thelimit,event,theform)
   }
  }
  else if (ns6)
  {
   document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) },true); 
   document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
  }
}
/*****************************************************************************/


/*-------------------------- FAQ QUESTION AND ANSWERS --------------------------*/

// setup initial answer set on FAQ page...
function setupAnswers(ansDisplay) {
	myAnswer = "answer" + ansDisplay;
	myDiv = document.getElementById(myAnswer);
	if(myDiv != null && typeof(myDiv) != "undefined") {
		myDiv.className = "show"; // show answer...
	}
}

// switch answers for faq questions..
function switchAnswer(ansDisplay) {
	myCurrentAns = "answer" + ansDisplay; // current answer to display..
	myDivArry = document.getElementsByTagName("div"); // array of divs..
	for(var i=0; i < myDivArry.length; i++) { // for each div..
		if(myDivArry[i].id.indexOf("answer") != -1) { // check if "answer" div..
			myTempObj = myDivArry[i]; // answer div object..
			if(myTempObj != null && typeof(myTempObj) != "undefined") {
				if(myTempObj.id == myCurrentAns) { // if this div is the current answer then...
					myTempObj.className = "show"; // show div..
				} else {
					myTempObj.className = "hide"; // hide div..
				}
			}
		}
	}
}


/*-------------------------- Google Maps functions --------------------------*/

    // class for holding map co-ordinates & map details
    function myMapObject(longitude,latitude, balloonText, mapId, zoom, markerLng, markerLat, markerText) 
    {
    this.longitude = longitude;
    this.latitude = latitude;
    this.balloonText = balloonText;
    this.mapId = mapId;
    this.zoom = zoom;
    this.markerLng = markerLng;
    this.markerLat = markerLat;
    this.markerText = markerText;
    }
    
    var objectArrayIndex = 0;
    var myObjectArray = new Array();
    
   //adds map values to map array for one marker on a map only
    function setMapObject(longitude,latitude, balloonText,mapId, zoom) 
    {
       myObjectArray[objectArrayIndex++] = new myMapObject(longitude,latitude, balloonText, mapId, zoom, null, null, '');
    }
 
    //used to add more than one marker to a map array
    function setMarkerObject(longitude,latitude, balloonText,mapId, zoom, markerLng, markerLat, markerText) 
    {
       myObjectArray[objectArrayIndex++] = new myMapObject(longitude,latitude, balloonText,mapId, zoom, markerLng, markerLat, markerText);
    }
       
    //loops through array using values to display Google maps
    function showObjectArray(object, length) 
    {
        for (var i=0; i<length; i++) 
        {
        displayMap(object[i].mapId, object[i].longitude, object[i].latitude, object[i].balloonText, object[i].zoom, object[i].markerLng, object[i].markerLat, object[i].markerText);
        }
    }
   
     
    // function provided by Google to display maps 
    function displayMap(sMap, iLongitude, iLatitude, sText, iZoom, iMarkerLng, iMarkerLat, sMarkerText) 
    {
      if (GBrowserIsCompatible()) 
      {
        var map = new GMap2(document.getElementById(sMap));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());

        map.setCenter(new GLatLng(iLatitude, iLongitude, false), iZoom);
        map.addOverlay(createMarker(new GLatLng(iLatitude, iLongitude, false),"<strong>" + sText + "</strong>"));
        if(iMarkerLng != null)
        {
        map.addOverlay(createMarker(new GLatLng(iMarkerLat, iMarkerLng, false), "<strong>" + sMarkerText + "</strong>"));
       }
      }
    }
    
    function createMarker(point, blurb) 
    {
          var marker = new GMarker(point);
          GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(blurb);
      });
      return marker;
}


