// ############################################################################
// ##
// ##  CUSTOM WEBSITE FUNCTIONS
// ##  (i.e. not standard white site functions)
// ##
// ############################################################################

// Put custom functions for your website here.

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 // SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 // http://www.opensource.org/licenses/mit-license.php
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;


// ====================
// Function:    imageSwap
//
// Purpose:     Swaps an image used on rollover
//
// Input:       
//
// Output:      
//
// Assumptions: 
//
// History:     Inherited from functionality transferred from original tccv website
// ====================
function imageSwap(layerID,ImageName,newImage) {
	if (document.getElementById) {
		document.images[ImageName].src = newImage;
	}else if (document.all) {
		if (layerID != '') {
			document.all[layerID].document.images[ImageName].src = newImage;
		}
	} else if (document.layers) {
		if (layerID != '') {
			document.layers[layerID].document.images[ImageName].src = newImage;
		}
	}
}

// ====================
// Function:    getObj
//
// Purpose:     Returns string for access to passed in object style attributes
//
// Input:       ID of object
//
// Output:      Returns string for access to passed in object style attributes
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function getObj(name) 
{
	if (document.getElementById) 
	{
		this.obj = document.getElementById(name);
		//Removed the .style on the next line *** this.style = document.getElementById(name).style;
		this.style = document.getElementById(name);
	} 
	else if (document.all) 
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} 
	else if (document.layers) 
	{
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

// ====================
// Function:    ReturnWindowHight
//
// Purpose:     Returns the height of the client window
//
// Input:       None
//
// Output:      Returns the height of the client window
//
// Assumptions: -
//
// History:     SC 2006-05-15
//              AT 2008-09-10 Added missing function that missing from PositionFooter() - which was causing JS errors
// ====================
function ReturnWindowHeight(windowRef) 
{
	var intHeight = -1;
	if (!windowRef) {
		windowRef = window;
	}
	if (typeof(windowRef.innerWidth) == 'number') {
		intHeight = windowRef.innerHeight;
	}
	if (windowRef.document.body && typeof(windowRef.document.body.clientWidth) == 'number') {
		intHeight = windowRef.document.body.clientHeight;
	}

	//if (height == 0) {
	//	intHeight = window.innerHeight;
	//}
	return intHeight;
}

// ====================
// Function:    GetObjectHeight
//
// Purpose:     Returns the height of any passed in block level object
//
// Input:       ID of item
//
// Output:      Returns the height of any passed in block level object
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function GetObjectHeight(objectRef)
{
	var intHeight = -1;

	if (document.getElementById)
	{
		if (document.getElementById(objectRef))
		{
			intHeight = eval(document.getElementById(objectRef).offsetHeight);
		}
	}
	else if (document.all)
	{
		if (document.all[objectRef])
		{
			intHeight = document.all[objectRef].scrollHeight;
		}
	}
	else if (document.layers)
	{
		if (document[objectRef])
		{
			intHeight = document[objectRef].clip.bottom;
		}
	}

	return intHeight;
}

// ====================
// Function:    SetUniformHeight
//
// Purpose:     Sets a number of page objects to a uniform height, being the
//              maximum height of any of the given objects.
//
// Input:       strPageObjects - Comma separated list of object IDs that should
//              be set to a uniform height.
//
// Output:      Updates the height of the given objects.
//
// Assumptions: GetObjectHeight()
//
// History:     20060823 RW Created
// ====================
function SetUniformHeight(strPageObjects) {
	intMaxHeight = 0;

	if (strPageObjects) {
		arrPageObjects = strPageObjects.split(",");
	}

	if (arrPageObjects) {
		// Find the height of the tallest object.
		for (i = 0; i < arrPageObjects.length; i++) {
			intThisHeight = GetObjectHeight(arrPageObjects[i]);
			if (intThisHeight > intMaxHeight) {
				intMaxHeight = intThisHeight;
			}
		}

		// Set all the objects to the same (maximum) height if a height larger
		// than 0 was found.
		if (intMaxHeight > 0 ) {
			for (i = 0; i < arrPageObjects.length; i++) {
				//if (blnIE)  {
				//	strMaxHeight = intMaxHeight;
				//} else {
					strMaxHeight = intMaxHeight + 'px';
				//}
				if(document.getElementById(arrPageObjects[i])) {
					document.getElementById(arrPageObjects[i]).style.height = strMaxHeight;
				}
			}
		}
	}
}

// ====================
// Function:    PositionFooter
//
// Purpose:     Positions the footer at the bottom of the screen if the content 
//		        of the screen does not cause the screen to scroll
//
// Input:       None
//
// Output:      None
//
// Assumptions: -
//
// History:     SC 2006-05-15
// ====================
function PositionFooter() {


	// Get height of Content
	var intContentHeight = GetObjectHeight("page-align");
	
	// Get height of Window
	var intWindowHeight = ReturnWindowHeight();
	
	// Get height of Footer
	var intFooterHeight = GetObjectHeight("footer");

	// Setup Object References
	objFooter = new getObj('footer');
	objWrapper = new getObj('page-wrapper-inner');
	
	// Compare heights
	if ( intWindowHeight > intContentHeight ) 
	{
	
		// Move the footer only if it the page content is smaller than the window height
		//Removed the .style since it was causing an error *** objWrapper.style.height = eval(intWindowHeight - intFooterHeight) + "px";
		objWrapper.height = eval(intWindowHeight - intFooterHeight) + "px";
		
		objFooter = new getObj('footer');
		//objFooter.style.position = "absolute";
		objFooter.position = "absolute";
		//objFooter.style.left = "0px";
		objFooter.left = "0px";
		//objFooter.style.top = eval(intWindowHeight - intFooterHeight) + "px";
		objFooter.top = eval(intWindowHeight - intFooterHeight) + "px";
	}
	
	//objFooter.style.visibility = "visible";
	objFooter.visibility = "visible";

}


// ====================
// Function:    textSizer
//
// Purpose:     resize the body text for vision impared
//
// Input:       None
//
// Output:      None
//
// Assumptions: -
//
// History:     AS 2008-04-14: Amended from Original concept found on http://www.dynamicdrive.com Coded by: Taewook Kang (txkang.REMOVETHIS@hotmail.com)
//              AT 2008-09-04: Updated the code to save the selected preference in a cookie
//              AT 2009-02-13: Commented "for ( var j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = sizes[ startSz ];" due to calendar month view size problems
// ====================
//Affected tags. Add or remove from list:
var tgs = new Array( 'td','tr');

//Different font sizes:
var sizes = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = (readCookie('txtsize')==null)?2:readCookie('txtsize');

function textSizer( trgt, incr ) {
	if (!document.getElementById) return
	var cEl = null;
	var sz = startSz;
	
	sz = 1*sz + 1*incr;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
	createCookie('txtsize',sz);
	
	setSize(trgt);
}

function setSize( trgt ) {
    if ( !trgt ) {
        trgt = "body";
    }

	if ( !( cEl = document.getElementById( trgt ) ) ) {
		cEl = document.getElementsByTagName( trgt )[ 0 ];
	}

	cEl.style.fontSize = sizes[ startSz ];

	for ( var i = 0 ; i < tgs.length ; i++ ) {
		var cTags = cEl.getElementsByTagName( tgs[ i ] );
		//for ( var j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = sizes[ startSz ];
	}
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

// ####################################
// Toggle images on and off (including CSS background images)
// ####################################

var gstrImagesStatus = "";
var garrCSSBackgroundImages = new Array();

// ====================
// Function:    ToggleImages
//
// Purpose:     Switches images on and off. It's like using the browser's 
//              disable image function, but quicker and doesn't require a
//              page load.
//
// Input:       -
//
// Output:      Switches images off if they are on, or back on if they have
//              been switched off (including CSS background images if the 
//              RemoveCSSBackgroundImages and ResetCSSBackgroundImages 
//              functions exist).
//
// Assumptions: -
//
// History:     20080911 RW Created
//
// Notes:       Could be improved with a cookie that remembers the setting from
//              page to page.
// ====================
function ToggleImages() {

    if (gstrImagesStatus == "off") {
		arrSpans = document.getElementsByTagName('span');
        for (i=0; i < arrSpans.length; i++) {
			oSpan = arrSpans[i];
			if ( oSpan.className == "AltText" ) {
				// replace back span tag with img tag
				oImg = document.createElement("img");
				oImg.alt = oSpan.innerHTML;
				oImg.src = oSpan.title;
				
				pnode = oSpan.parentNode;
				pnode.removeChild(oSpan);
				pnode.appendChild(oImg);
				// when we remove a span tag then length of arrSpans array is decreased which has the same effect as incrementing i
				i--;
			}
		}
		// restore displaying background images if ResetCSSBackgroundImages function exists
        if (ResetCSSBackgroundImages) {
            ResetCSSBackgroundImages();
        }
        gstrImagesStatus = "on";
    } else {
		arrImageTags = document.images; // Same effect as document.getElementsByTagName('img')
		for (i=0; i < arrImageTags.length; i++) {                        
		    if (arrImageTags[i] && !ToggleImages_IgnoreImages(arrImageTags[i]) ) {
				strAltText = arrImageTags[i].alt;
				if (!strAltText) {
				    strAltText = 'Unknown image.';
				}
				// replace img tag with span tag
				oSpan = document.createElement("span");
				oSpan.className = "AltText";
				oSpan.title = arrImageTags[i].src;
				oSpan.appendChild(document.createTextNode(strAltText));
				
				pnode = arrImageTags[i].parentNode;
				pnode.removeChild(arrImageTags[i]);
				pnode.appendChild(oSpan);
				// when we remove an image tag then length of arrImageTags array is decreased which has the same effect as incrementing i
				i--;
		    }            
        }
 		// hide background images if RemoveCSSBackgroundImages function exists
       if (RemoveCSSBackgroundImages) {
            RemoveCSSBackgroundImages();
        }
        gstrImagesStatus = "off";
    }

}

function ToggleImages_IgnoreImages(oImg) {
	if (oImg) {
		if (oImg.src.indexOf('secure-au.imrworldwide.com') > -1) {
			return true;
		}
		if (oImg.src.indexOf('cgi-bin') > -1) {
			return true;
		}
	}
	return false;
}

// ====================
// Function:    RemoveCSSBackgroundImages
//
// Purpose:     Sets the background-image property to 'none' for any elements
//              in the page that have it set. Also populates an array with the
//              background image URLs (if the array exists) so that they can
//              be restored if needed.
//
// Input:       -
//
// Output:      Switches all CSS background images off.
//
// Assumptions: Global: garrCSSBackgroundImages (array)
//
// History:     20080911 RW Created
// ====================
function RemoveCSSBackgroundImages() {
    arrAllElements = document.getElementsByTagName('*');
    for (var i = 0; i < arrAllElements.length; i++) {
        if (garrCSSBackgroundImages) {
            garrCSSBackgroundImages[i] = arrAllElements[i].style.backgroundImage;
        }
        arrAllElements[i].style.backgroundImage = 'none';
    }
}

// ====================
// Function:    ResetCSSBackgroundImages
//
// Purpose:     Reloads CSS background images from a global array.
//
// Input:       -
//
// Output:      Switches CSS background images back on if they were switched
//              off.
//
// Assumptions: Global: garrCSSBackgroundImages (array containing background
//              images that were switched off). Normally this is created by
//              RemoveCSSBackgroundImages()
//
// History:     20080911 RW Created
// ====================
function ResetCSSBackgroundImages() {
    // This function can't run without garrCSSBackgroundImages, and we assume that if 
    // garrCSSBackgroundImages has something in it then RemoveCSSBackgroundImages() was run.
    if (garrCSSBackgroundImages && garrCSSBackgroundImages.length > 0) { 
        arrAllElements = document.getElementsByTagName('*');
        for (var i = 0; i < arrAllElements.length; i++) {
            arrAllElements[i].style.backgroundImage = garrCSSBackgroundImages[i];
        }
    }
}

// ====================
// Function:    FloatingDiv
//
// Purpose:     Make a div always visible on the page with a smooth floating effect.
//
// Input:       id - ID of the div 
//              sx - x co-ordinate of where to float the div
//              sy - y co-ordinate of where to float the div
//
// Output:      -
//
// Assumptions: -
//
// History:     20090626 RW Included from http://www.javascript-fx.com/submitscripts/float/float.html
// ====================
function FloatDiv(id, sx, sy) {
    var ns = (navigator.appName.indexOf("Netscape") != -1);
    var d = document;
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function() {
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}


function getWindowDimension(strPlane) {
  var dimension = 0;
  
  switch (strPlane.toLowerCase()) {
    case "width" :
          if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            dimension = window.innerWidth;
          } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
            //IE 6+ in 'standards compliant mode'
            dimension = document.documentElement.clientWidth;
          } else if( document.body && ( document.body.clientWidth ) ) {
            //IE 4 compatible
            dimension = document.body.clientWidth;
          }
        break;
    case "height" :
          if( typeof( window.innerHeight ) == 'number' ) {
            //Non-IE
            dimension = window.innerHeight;
          } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            dimension = document.documentElement.clientHeight;
          } else if( document.body && ( document.body.clientHeight ) ) {
            //IE 4 compatible
            dimension = document.body.clientHeight;
          }
        break;
  }
  return dimension;
}



// ############################################################################
// ##
// ##  STANDARD WHITE SITE FUNCTIONS
// ##
// ############################################################################

// ####################################
// Navigation
// ####################################

// ====================
// Function:    NavPullDown
//
// Purpose:     Go to a URL that is selected from a form a pull-down form field
//
// Input:       strFormName - The ID of the form being used to select naviation
//              strFieldName - The ID of the field with URL select options
//
// Output:      Navigates to selected URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function NavFormSelect(strFormName,strFieldName)
{
	intSelected = document[strFormName].elements[strFieldName].options.selectedIndex;
	strURL = document[strFormName].elements[strFieldName].options[intSelected].value;
	document[strFormName].elements[strFieldName].options.selectedIndex = 0;
	if (strURL != "")
	{
		location.href = strURL;
	}
}

// ====================
// Function:    InitNav
//              Note: InitNav must be called after menu list is created.
//
// Purpose:     Assigns classes to certain events for Internet Explorer 6.
//              (IE6 does not fully support CSS standards.)
//
// Input:       -
//
// Output:      -
//
// Assumptions: -
//
// History:     200512 Code from htmldog.com
//              200512 RW Turned into a function for nicer modularity
// ====================
function InitNav(strListID) {
	sfHover = function() {
	    var el = document.getElementById(strListID);
	    if ( el ) {
		    var sfEls = el.getElementsByTagName("LI");
		    for (var i=0; i<sfEls.length; i++) {
			    sfEls[i].onmouseover=function() {
				    this.className+=" sfhover";
			    }
			    sfEls[i].onmouseout=function() {
				    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			    }
		    }
		}
	}
	// Only executes in IE
	if (window.attachEvent) {
		window.attachEvent("onload", sfHover);
	}
}



function SetDefaultFieldValue(strForm,strElement,strValue,blnFocus) {

	var strSubscribeValue = document.forms[strForm].elements[strElement].value;

	if ( blnFocus ) {

		if ( strSubscribeValue == strValue ) {
			document.forms[strForm].elements[strElement].value = "";
		}

	} else {

		if ( strSubscribeValue == "" ) {
			document.forms[strForm].elements[strElement].value = strValue;
		}

	}

}
	
	
// ####################################
// Windows & Alerts
// ####################################

// ====================
// Function:    Popup
//
// Purpose:     Open a popup window with a series of option settings.
//
// Input:       strPage - The URL of the page to open in the popup window.
//              intWidth - The window width in pixels 
//              intHeight - The window height in pixels
//              strID - The ID of the popup window. (This is important if the
//                window may be called on by other functions or if there are
//                multiple popup windows in a site.)
//              strScrollbars - Switch visible scrollbars on/off ("yes"/"no")
//              strLocation - Switch visible location bar on/off ("yes"/"no")
//              strToolbar - Switch visible toolbar on/off ("yes"/"no")
//              strStatus - Switch visible status bar on/off ("yes"/"no")
//              strResizable - Window is resizable or not ("yes"/"no")
//
// Output:      Window opens containing the specified URL.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function Popup(strPage,intWidth,intHeight,strID,strScrollbars,strLocation,strToolbar,strStatus,strResizable)
{
	if (!strPage)
	{
		strPage = "/";
	}
	if (!intWidth)
	{
		intWidth = 500;
	}
	if (!intHeight)
	{
		intHeight = 320;
	}
	if (!strID)
	{
		strID = "PopupWindow";
	}
	if (!strScrollbars)
	{
		strScrollbars = "yes";
	}
	if (!strLocation)
	{
		strLocation = "no";
	}
	if (!strToolbar)
	{
		strToolbar = "no";
	}
	if (!strStatus)
	{
		strStatus = "no";
	}
	if (!strResizable)
	{
		strResizable = "yes";
	}
	//if (isLoaded == 0)
	//{
	//	location.reload();
	//}
	idPopup = window.open(strPage,strID,"width="+intWidth+",height="+intHeight+",scrollbars="+strScrollbars+",location="+strLocation+",toolbar="+strToolbar+",status="+strStatus+",resizable="+strResizable);
	if (window.focus)
	{
		idPopup.focus();
	}
	return false;
}

// ====================
// Function:    PopdownLink
//
// Purpose:     Open a link in a popup window in a specified main window and
//              close the popup window. If the specified link window does not
//              exist it is created. If no window is specified the link is
//              targeted to the original opener of the popup window.
//
// Input:       strURL - The URL of the page to open
//              strWindowID - The ID of the window in which to open the link
//
// Output:      Navigates to selected URL in selected window and closes current
//              window.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
//              2004 Multiple window targets added. (Previously could only
//                   target the opener.)
// ====================
function PopdownLink(strURL,strWindowID)
{
	if (!strWindowID)
{
		top.opener.location.href = strURL;
}
	else
{
		if (strWindowID.location)
	{
			strWindowID.location.href = strURL;
	}
		else
	{
			window.open(strURL,strWindowID);
	}
}
	top.close();
}

// ====================
// Function:    RequireKeywords
//
// Purpose:     Checks any search form to make sure keywords are entered before
//              the form can be submitted. 
//
// Input:       strFormName - The ID of the form with the keywords field in it
//              strFieldName - The ID of the keywords field within the form 
//
// Output:      Give an error if no keywords are presented.
//
// Assumptions: -
//
// History:     20040109 RW Created to replace local code in site templates.
// ====================
function RequireKeywords(strFormID,strFieldName)
{
	if (document.forms[strFormID].elements[strFieldName].value.length <= 3)
	{
		alert("Please alter your requested keyword(s) in the search form.\nThe search phrase must be 3 characters or more in length.")
		return false;
	}
}

// ====================
// Function:    CS
//
// Purpose:     Display a "coming soon" message for sections of a website that
//              have not been created yet. This function is sometimes used in
//              development to make links active before a site is finished.
//
//              Note: This is an evil funciton, it should not be used! It
//              encourages bad development habits.
//
// Input:       -
//
// Output:      Show a "coming soon" message.
//
// Assumptions: -
//
// History:     DDSN created back in the Distant Past
// ====================
function CS()
{
	alert("That function is coming soon.");
}

// ####################################
// Image Manipulation
// ####################################

// ====================
// Function:    ImageSwap
//
// Purpose:     Swap any image to another.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//
// Output:      Swaps images.
//
// Assumptions: Images with all specified IDs exist and are pre-loaded.
//
// History:     DDSN created back in the Distant Past
// ====================
function ImageSwap(strImageID,strNewImageSrc)
{
	if (document.images)
	{
		document.images[strImageID].src = eval(strNewImageSrc+".src");
	}
}

// ====================
// Function:    ImageSwapFX
//
// Purpose:     Swap any image to another using an optional fade effect. Can
//              also be called with the transition effect disabled, i.e. just
//              swap the images.
//
// Input:       strImageID - ID of the image being swapped
//              strNewImageSrc - Source of the new image being loaded
//              blnDisableTrans - Switch the transition off or on (1/0)
//
// Output:      Swaps images with optional fade effect.
//
// Assumptions: - Images with all specified IDs exist and are pre-loaded.
//              - Requires fading transition style to be set first on image tag
//              - Only works for IE5.5+ but falls back nicely
//              - Javascript Globals: blnToggleTrans
//
// History:     2003 DDSN Created
//              2004 Updated with more standard naming structures
// ====================
function ImageSwapFX(strImageID,strNewImageSrc,blnDisableTrans)
{
	if (blnDisableTrans || !document.images[strImageID].filters || blnIE50)
	{
		if (document.images)
		{
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
	}
	else
	{
		// After setting Apply, changes to the object are not displayed
		// until Play is called.
		document.images[strImageID].filters[0].Apply();

		if (blnToggleTrans)
		{
			blnToggleTrans = 0;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
		else
		{
			blnToggleTrans = 1;
			document.images[strImageID].src = eval(strNewImageSrc+".src");
		}
		document.images[strImageID].filters[0].Play();
	}
}

// ####################################
// Layer Manipulation
// ####################################

// ====================
// Function:    LayerVisibility
//
// Purpose:     Turn visibility of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerVisibility(strLayerID,strState)
{
	if (blnNS4)
	{
		if (document.layers[strLayerID])
		{
			document.layers[strLayerID].visibility = strState;
		}
	}
	else if (blnDOM)
	{
		if (document.getElementById(strLayerID))
		{
			document.getElementById(strLayerID).style.visibility = strState;
		}
	}
	else if (blnIE)
	{
		if (document.all[strLayerID])
		{
			document.all[strLayerID].style.visibility = strState;
		}
	}
}


// ====================
// Function:    LayerDisplay
//
// Purpose:     Turn display of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerDisplay(strLayerID,strState)
{
	if (blnNS4)
	{
		if (document.layers[strLayerID])
		{
			document.layers[strLayerID].display = strState;
		}
	}
	else if (blnDOM)
	{
		if (document.getElementById(strLayerID))
		{
			document.getElementById(strLayerID).style.display = strState;
		}
	}
	else if (blnIE)
	{
		if (document.all[strLayerID])
		{
			document.all[strLayerID].style.display = strState;
		}
	}
}


// ====================
// Function:    LayerVisibility
//
// Purpose:     Turn visibility of any layer on or off.
//
// Input:       strLayerID - ID of the layer being altered
//              strState = "visible" or "hidden"
//
// Output:      Turns specified layer on or off.
//
// Assumptions: Specified layer exists in document hierarchy.
//
// History:     DDSN created back in the Distant Past
// ====================
function LayerVisibility(strLayerID,strState)
{
	if (blnNS4)
	{
		if (document.layers[strLayerID])
		{
			document.layers[strLayerID].visibility = strState;
		}
	}
	else if (blnDOM)
	{
		if (document.getElementById(strLayerID))
		{
			document.getElementById(strLayerID).style.visibility = strState;
		}
	}
	else if (blnIE)
	{
		if (document.all[strLayerID])
		{
			document.all[strLayerID].style.visibility = strState;
		}
	}
}

// ====================
// Function:    toggleElement
//
// Purpose:     Turn visibility of any element on or off.
//
// Input:       strDivId - ID of the element being altered
//              strDisplayVal = "block", "inline" or "none"
//
// Output:      Turns specified element on or off.
//
// Assumptions: Specified element exists in document hierarchy.
//
// History:     RW Created 2006-07-20
// ====================
function toggleElement(strDivId,strDisplayVal)
{
	if (!strDisplayVal)
	{
		strDisplayVal = document.getElementById(strDivId).style.display;

		switch (strDisplayVal)
		{
			case "block" :
				strDisplayVal = "none";
				break;
			case "inline" :
				strDisplayVal = "none";
				break;
			case "none" :
				strDisplayVal = "block";
				break;
			case "" :
				break;
		}
	}
	document.getElementById(strDivId).style.display = strDisplayVal;
}

// ====================
// Function:    toggleElementOnOff
//
// Purpose:     Turn visibility of any element on or off.
//
// Input:       strDivId - ID of the element being altered
//              strDisplayVal = "block", "inline" or "none"
//
// Output:      Turns specified element on or off.
//
// Assumptions: Specified element exists in document hierarchy.
//
// History:     AT Created 2009-01-28
// ====================

function toggleElementOnOff()
{
	if (document.getElementById("footersurvey").style.display == 'none')
	{
		document.getElementById("footersurvey").style.display = 'block';
		document.getElementById("footersurvey").style.position = 'relative';
	}
	else
	{
		document.getElementById("footersurvey").style.display = 'none';
		document.getElementById("footersurvey").style.position = 'relative';
	}
	return;
}

// ####################################
// Printing
// ####################################

// ====================
// Function:    LoadVBPrinter
//
// Purpose:     Load Visual Basic printing commands for VB enabled browsers.
//
// Input:       -
//
// Output:      Loads (writes out) visual basic printing functions.
//
// Assumptions: Javascript Globals: blnIE, blnCanPrint, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
function LoadVBPrinter()
{
	if (blnIE && !blnCanPrint && !blnMac) with (document)
	{
		writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
		writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
		writeln('Sub window_onunload');
		writeln('    On Error Resume Next');
		writeln('    Set WB = nothing');
		writeln('End Sub');
		writeln('Sub vbPrintPage');
		writeln('    OLECMDID_PRINT = 6');
		writeln('    OLECMDEXECOPT_DONTPROMPTUSER = 2');
		writeln('    OLECMDEXECOPT_PROMPTUSER = 1');
		writeln('    On Error Resume Next');
		writeln('    WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
		writeln('End Sub');
		writeln('<' + '/SCRIPT>');
	}
}

// ====================
// Function:    PrintPage
//
// Purpose:     Opens the print dialog window or shows a fallback message for
//              unsupported browsers
//
// Input:       -
//
// Output:      Opens the print dialog window or shows a fallback message for
//              unsupported browsers.
//
// Assumptions: Javascript Globals: blnCanPrint, blnIE, blnMac
//
// History:     DDSN created back in the Distant Past
// ====================
function PrintPage()
{
	if (blnCanPrint)
	{
		window.print();
	}
	else if (blnIE && !blnMac)
	{
		vbPrintPage();
	}
	else
	{
		alert("Your web browser does not appear to support the automatic\nPrint function. To print this page, please select the \"Print\"\noption from the \"File\" menu of your web browser.");
	}
}

// ====================
// Function:    getElementsByClassName
//
// Purpose:     Gets all elemets on a page depending by class
//
// Input:       -
//
// Output:      array of elements
//
// Assumptions: NIL
//
// History:     Source: http://snipplr.com/view.php?codeview&id=1696
// ====================
function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}



// ====================
// Functions:    hasClass, addClass,removeClass
//
// Purpose:     add, remove or detect a class name
//
// Input:       -
//
// Output:      hasClass = true/false; others: NIL
//
// Assumptions: NIL
//
// History:     Source: http://www.openjs.com/scripts/dom/class_manipulation.php
// ====================
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}




// Load Visual Basic printing commands for VB enabled browsers
//LoadVBPrinter()

// ####################################
// Fun Stuff / Easter Eggs
// ####################################

// No easter eggs currently present. :-)
