﻿/* ##################################### 
   ----- DD Nav
   ##################################### */
function showItNow(id) {
	getElement(id).style.display = 'block';
	fixSelects('visible');
}

function hideItNow(id) {
	getElement(id).style.display = 'none';
	clearTimeout(timer2ID);
	fixSelects('hidden');
}

function clearTimer2(id) {
	if(document.all && !document.compatMode) showMenu(id);
	else clearTimeout(timer2ID);
}

function showMenu(id) {
	if(document.all && !document.compatMode) getElement(id).style.display = 'block';
	else timer1ID = window.setTimeout(function(){showItNow(id);}, 150);
}
function hideMenu(id) {
	if(document.all && !document.compatMode) getElement(id).style.display = 'none';
	else if(timer1ID) clearTimeout(timer1ID); timer2ID = window.setTimeout(function(){hideItNow(id);}, 150);
}

var timer1ID=false, timer2ID=false;
if(document.addEventListener) window.event=new Object(); // DOM2 event handling setup (emulate IE's window.event object)
function updateEvent(event){ // DOM2 event handling (emulate IE's window.event object)
	for (i in event) window.event[i]=event[i]; window.event.clientX=event.pageX; window.event.clientY=event.pageY; window.event.srcElement=event.target; }
function addEvent(elem, eventName, functionName, eventPhase) {
  var r = true;
  if (elem.attachEvent) r = elem.attachEvent('on'+eventName, functionName);
  else if (elem.addEventListener) elem.addEventListener( eventName, functionName, eventPhase );
  else eval('elem.on' + eventName + ' = ' + functionName);
  return r;
}
function removeEvent(elem, eventName, functionName, eventPhase) {
  var r = true;
  if (elem.detachEvent) r = elem.detachEvent('on'+eventName, functionName);
  else if (elem.removeEventListener) elem.removeEventListener( eventName, functionName, eventPhase );
  else eval('elem.on' + eventName + ' = function(){ return; }');
  return r;
}
function showMenuHandler(event) {
  if(document.addEventListener) window.event.srcElement=event.target; //updateEvent(event);
  var id=window.event.srcElement.id.substring(0,window.event.srcElement.id.length-4);
  if(id) showMenu(id);
  return true;
}
function hideMenuHandler(event) {
  if(document.addEventListener) window.event.srcElement=event.target; //updateEvent(event);
  var id=window.event.srcElement.id.substring(0,window.event.srcElement.id.length-4);
  if(id) hideMenu(id);
  return true;
}
function addListeners() {
  var e, el, navElems = new Array('whatson', 'living', 'dining', 'visitors');
  for (e in navElems){ if((el=getElement(navElems[e] + 'DDlink'))){ addEvent(el, 'mouseover', showMenuHandler, false); 
	  addEvent(el, 'mouseout', hideMenuHandler, false); } }
}
addEvent(window, 'load', addListeners, true);

function oasisAd(s,w,h) {
	var now = new Date(); 
	var rnd = now.getTime(); 
	document.write('<'+'script type="text/javascript" src="http://ads.ourbrisbane.com/oasisi-j.php?s='+s+'&w='+w+'&h='+h+'&rnd='+rnd+'"></'+'script>');
}

// Hide select form elements from IE
function fixSelects(visibility) {
  if (document.all) { // bug fix for IE drop-down menu rendering -- hide SELECT elements while menu is visible 
	var formvisibility = (visibility == 'visible') ? 'hidden':'inherit'; 
	for (var j=0; j<document.forms.length; j++) {
	  for (var k=0; k<document.forms[j].elements.length; k++){ 
		if(document.forms[j].elements[k].options) { 
		  document.forms[j].elements[k].style.visibility = formvisibility;
		  if(document.forms[j].elements[k].parentNode){ // if possible shaddow the SELECT elements with grey background
			if(document.forms[j].elements[k].parentNode.tagName!='SPAN' && document.forms[j].elements[k].parentNode.id!='ob_selShaddow_'+j+'_'+k) document.forms[j].elements[k].outerHTML='<span id="ob_selShaddow_'+j+'_'+k+'">'+document.forms[j].elements[k].outerHTML+'</span>';
			document.forms[j].elements[k].parentNode.style.cssText=(formvisibility=='hidden')? 'background-color:#eee;' : '';
		  }
		}
	  }
	}
  }
}

/* ####################################
   ----- DI Tracking Code for HEAD section (3/3/2006)
   #################################### */
var refr=escape(document.referrer); /* get the http referer and encode it */
var dom=location.hostname; /* get the host domain */
var stURL="http://au.decdna.net/n/2002/9606/transactions.brisbane.qld.gov.au.au/9ef7c4760025030000000006000000000311d6720000000000000000000000000000000100/i/c?0&pq=%2f&1pixgif&referer=" + refr;
if ( (refr && refr.search(dom) == -1) && (location.href.toUpperCase().indexOf("247SEO=N") == -1) ) /* if the referrer is external preload the image request and does not contain 247SEO argument = "N" */
{
	imageTR = new Image();
	imageTR.src = stURL;
}

/* ####################################
   ----- V2 scripts
   #################################### */
   
var islandAd = false;
   
function launchEmail() {
  var webMail = window.open('http://webmail.ourbrisbane.com/webmail/index.php','webMail','height=530,width=790,status=no,toolbar=no,menubar=no,location=no,resizable=yes');
  if (webMail) webMail.focus();
}

// Single Sign On User Details
var SSOUserDebug=false, ssodstyle='overflow:auto; width:95%; padding:10px; border:1px dotted #ccc;';
var ob_user_name=new String, httpProtocol=window.location.protocol.toLowerCase();
/* Get document information */
var escRef=escape(window.document.referrer), uniqueNum=Date.parse(new Date())+Math.floor(Math.random()*1000);
document.write('<scri'+'pt type="text/javascript" src="'+httpProtocol+'//transactions.brisbane.qld.gov.au/global/scripts/entitieslookup.js"></scr'+'ipt>');
var escKeywords=new String, meta=false;
if(document.getElementsByTagName) meta=document.getElementsByTagName("META"); // W3CDOM
else if(document.all) meta=document.all.tags("META"); // DHTML DOM
if(meta) for(var i=0;i<meta.length;i++) if(meta[i].name.toUpperCase()=="KEYWORDS") escKeywords=escape(meta[i].content.toLowerCase());
/* Get USER DETAILS */
document.write('<scri'+'pt type="text/javascript" src="https://transactions.brisbane.qld.gov.au/customise/include?action=echo_js&ref='+escRef+'&unique='+uniqueNum+'&words='+escKeywords+'"></scr'+'ipt>');
if(SSOUserDebug) document.write('<DIV STYLE="'+ssodstyle+'">'+"<STRONG>SSO User Details - DEBUG INFO</STRONG><BR /><BIG><PRE> Protocol = "+httpProtocol+" \n escaped Referrer = "+escRef+" \n Unique Number = "+uniqueNum+" \n escaped Keywords = "+escKeywords+"</PRE></BIG></DIV>");

// Outbound link tracking
var trackURL=window.location.protocol+'//transactions.brisbane.qld.gov.au/user/SingleSignOn?action=redirect&ref='+escape(window.location)+'&url=';
function trackStatus(){ window.status=this.href.substr(trackURL.length); return true; }
function clearStatus(){ window.status=""; return true; }
function trackLocation(){ window.location=trackURL+this.href; return false; }
function goTo(linkURL) { window.location=trackURL+linkURL;}
function attachLinkTrack(){
  /* DEBUG NOTE: set trackDebug=true to see which links are being tracked */
  var trackDebug=false, trackDebugCss="border:1px dashed red; background-color:yellow;", domainsSrc=new String;
  var an=document.links, re=new RegExp('\\.','g'), notrack=new Boolean;
  /* Enter any domains to exclude from outbound link tracking in the domains array below.
   * The domains array should contain Sting objects similar to 'domain.name.com'.
   * NOTE: Subdomains DO NOT need to be entered explicitly! */
  var domains=['transactions.brisbane.qld.gov.au'
              ,'directory.ourbrisbane.com'
              ,'ads.ourbrisbane.com'
              ,'activebrisbane.ourbrisbane.com'
              ,'yourtv.com.au'
              ,'yourmovies.com.au'
              ,'seek.com.au'
              ,'ourcommunity.com.au'
              ,'volunteeringqueensland.org.au'];
  /* Convert domains array elements to RegExp objects capable of matching the domain AND 
   * ANY subdomains INCLUDING the 'www.' subdomain 
   * DEBUG NOTE: set trackDebug=true to see source of domains RegExps at bottom of page */
  var percent=new RegExp("%","g");
  var percent25=new RegExp("%25","g");
  for(var j=0;j<domains.length;j++){ domains[j]=new RegExp("^https?:\\/\\/(\\w+\\.)*"+domains[j].replace(re,"\\.")+"(\\/)?",'i'); if(trackDebug) domainsSrc+=domains[j].source+"\n"; }
  if(trackDebug) document.write("<BR /><BR /><STRONG>No-Track Domains - RegExp Source</STRONG><BR /><BIG><PRE>"+domainsSrc+"</PRE></BIG><BR /><BR />");
  for(var i=0;i<an.length;i++){
    if(an[i].href && an[i].href.substr(0,4)=='http'){ // if anchor has an href starting with 'http'
      if (document.all) notrack=percent.test(an[i].href) && !percent25.test(an[i].href);
      else notrack=false;
      for(var j=0;j<domains.length;j++) if(domains[j].test(an[i].href)){ notrack=true; break; } // check for matches against domains array
      if(!notrack){ // if link is not to a domain listed in domains array,'track it baby'
        if(trackDebug) an[i].style.cssText=trackDebugCss;
		if(!an[i].onclick) an[i].onclick=trackLocation;
	    else{ an[i].onmouseover=trackStatus; an[i].onmouseout=clearStatus; an[i].href=trackURL+an[i].href; }	
      }
    }
  }
}

//************
//  helpers (generic implementations) - REVIEW
//************
//returns an object correctly referenced for Netscape4, IE4 & W3C compliant browsers
function getElement(id, path) {  //path only needed by netscape4
  var obj,i; if(!path)path=document;
  if(document.getElementById) obj=document.getElementById(id); //W3C DOM
  else if(document.all) obj=document.all[id]; //DHTML DOM
  else if (!(obj=path.id)&&document.layers) for(i=0;!obj&&path.layers&&i<path.layers.length;i++) obj=getElement(id,path.layers[i].document); //NS4 DOM
  if(!obj) for(i=0;!obj&&i<path.forms.length;i++)obj=path.forms[i].elements[id]; //Last resort: check form elements
  return obj;
}

// Sets the text of a layer for Netscape4, IE4 & W3C compliant browsers
function layerHTML(layer,html) {
	if(!(obj=getElement(layer))) return false;
	else with (obj)
		if (document.layers) { 
			document.writeln(html); 
			document.close();
		}else innerHTML = html;
	return true;
}

/* sets an element's css display property to block or none
 * usage: displayElement('elementId','off') */
function displayElement(elemId,v){
  if(v=='undefined' || v==null) v='1';
  dVal=(v=='hide' || v=='none' || v=='off' || ((v-0)<1) || v===false)?'none':'block';
  if(getElement(elemId)){ 
	var styleObj=getElement(elemId).style;
	styleObj.display=dVal; 
	return true; 
  }
  else return false;
}

function toggleDisplayElement(elemId){
  if(getElement(elemId)){ 
	var styleObj=getElement(elemId).style;
    if(styleObj.display!='none') displayElement(elemId,0);
	else displayElement(elemId,1);
	return true; 
  }
  else return false;
}

//positions layer (div) in relation to a marker graphic of same name+"Marker"
function positionToMarker(divId, offsetTop, offsetLeft) {
  marker=getElement(divId+'Marker','document.images');
  if (marker==null || marker+''=='undefined') return;  //exit if no marker;
  target=getElement(divId,'document.layers');
  if (document.layers) {  //NS4
    target.visibility='visible';
    target.top=marker.y+offsetTop;
    target.left=marker.x+offsetLeft;
  }
  else {  //W3C (test for IE4)
    while (marker.offsetParent) {  //add all parent offsets together to give total offset
      offsetTop+=marker.offsetTop;
      offsetLeft+=marker.offsetLeft;
      marker=marker.offsetParent;
    }
    target.style.visibility='visible';
    target.style.top=offsetTop;
    target.style.left=offsetLeft;
  }
}

//*************
//  Header
//*************
//checks form field - used in Header Search form
function IsString(sVal,sMsg){ if(sVal==""){ alert(sMsg); return false; } return true; }

//***************
// window Pop-ups
//***************
function screenOffset(axis,pixels){
  var percentOffset=(10/100); // percent offset from axis
  var axisDimension=new Number;
  if(axis=='x')axisDimension=screen.availWidth;
  if(axis=='y')axisDimension=screen.availHeight;
  return Math.ceil((axisDimension-pixels)*percentOffset);
}

function popUpWin(URL,winWidth,winHeight,winType,strWinName){
  var winOpts=new String,oNewWin=new Object,oDate=new Date;
  var xPos=new Number,yPos=new Number;
  (!winWidth)?winWidth=680:winWidth-=0;
  (!winHeight)?winHeight=520:winHeight-=0;
  switch(winType){
    case "console":
      winOpts="resizable";
      if(!strWinName)strWinName='newConsoleWin';
      break;
    case "fixed":
      winOpts="status";
      if(!strWinName)strWinName='newFixedWin';
      break;
    case "noFeatures":
      winOpts="scrollbars";
      if(!strWinName)strWinName="noFeatures";
      break;
    case "elastic":
      winOpts="menubar,scrollbars,resizable,status";
      if(!strWinName)strWinName='newElasticWin';
      break;
    default:
      winOpts="toolbar,menubar,scrollbars,resizable,location,status,directories";
      if(!strWinName)strWinName='ourbrisbaneWin';
      break;
  }
  if(window.screenX){
    xPos=screenOffset('x',window.screenX)+window.screenX;
    yPos=screenOffset('y',window.screenY)+window.screenY;
  }else if(window.screenLeft){
    xPos=screenOffset('x',window.screenLeft)+window.screenLeft;
    yPos=screenOffset('y',window.screenTop)+window.screenTop;
  }
  if(screen.availWidth<(xPos+winWidth))xPos=screen.availWidth-winWidth;
  if(screen.availHeight<(yPos+winHeight))yPos=screen.availHeight-winHeight;
  winOpts+=",x="+xPos+",left="+xPos+",y="+yPos+",top="+yPos+",height="+winHeight+",width="+winWidth;
  oNewWin=window.open(URL,strWinName,winOpts);
  oNewWin.focus();
  return oNewWin;
}

// onMouseOver="self.status=this.title;return true;" onMouseOut="self.status='';return true;" 
function titleStatus(){ window.status=this.title; return true; }

/**
 * Link title to status
 *
 * Sets the status bar message (displayed on hover) for links to their title attribute
 *
 * @author Christopher Hopper <christopher.hopper@brisbane.qld.gov.au>
 * @param mixed id The id of the container object or the container object itself
 * @return boolean true on success, false on failure setting focus
 */
function linkTitle2Status(id){
	var i,j; 
	var o=(typeof(id)=='object')? id : ((typeof(id)=='string')? getElement(id): null);
	if(o&&o.title&&o.tagName=='A'){ o.onmouseover=titleStatus; o.onmouseout=clearStatus; }
	if(o&&document.getElementById){ //W3C DOM
		for(i=0;o.hasChildNodes()&&i<o.childNodes.length;i++){
			if(o.childNodes[i].nodeType==1){ 
				if(o.childNodes[i].title&&o.childNodes[i].tagName=='A'){ o.childNodes[i].onmouseover=titleStatus; o.childNodes[i].onmouseout=clearStatus; }
				else if(o.childNodes[i].hasChildNodes()) linkTitle2Status(o.childNodes[i]);
			}
		} 
	}else if(o&&document.all){ //DHTML DOM
		for(i=0;o.all.length&&i<o.all.length;i++){ 
			if(o.all[i].nodeType==1){ if(o.all[i].title&&o.all[i].tagName=='A'){ o.all[i].onmouseover=titleStatus; o.all[i].onmouseout=clearStatus; } }
		}
	}else if(o&&document.layers){ //NS4 DOM 
		for(i=0;o.document.links&&i<o.document.links.length;i++){ if(o.document.links[i].title){ o.document.links[i].onmouseover=titleStatus; o.document.links[i].onmouseout=clearStatus; } } //traverse links
		for(i=0;o.document.layers&&i<o.document.layers.length;i++) linkTitle2Status(o.document.layers[i]); //traverse child layers
	}
	return;
}

/**
 * ARRAY object extensions
 * Array Extensions  v1.0.6
 * documentation: http://www.dithered.com/javascript/array/index.html
 * license: http://creativecommons.org/licenses/by/1.0/
 * code by Chris Nott (chris[at]dithered[dot]com)
 */
var undefined;
function isUndefined(property) {
  return (typeof property == 'undefined');
}

// Array.concat() - Join two arrays
if (isUndefined(Array.prototype.concat) == true) {
  Array.prototype.concat = function (secondArray) {
     var firstArray = new Array();
     for (var i = 0; i < this.length; i++) {
        firstArray[i] = this[i];
     }
     for (var i = 0; i < secondArray.length; i++) {
        firstArray[firstArray.length] = secondArray[i];
     }
     return firstArray;
  };
}

// Array.pop() - Remove the last element of an array and return it
if (isUndefined(Array.prototype.pop) == true) {
  Array.prototype.pop = function() {
  	var lastItem = undefined;
    if ( this.length > 0 ) {
        lastItem = this[this.length - 1];
        this.length--;
    }
    return lastItem;
  };
}

// Array.push() - Add an element to the end of an array
if (isUndefined(Array.prototype.push) == true) {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}

// Array.shift() - Remove the first element of an array and return it
if (isUndefined(Array.prototype.shift) == true) {
  Array.prototype.shift = function() {
  	var firstItem = this[0];
  	for (var i = 0; i < this.length - 1; i++) {
  		this[i] = this[i + 1];
  	}
  	this.length--;
  	return firstItem;
  };
}

// Array.unshift - Add an element to the beginning of an array
if (isUndefined(Array.prototype.unshift) == true) {
  Array.prototype.unshift = function(the_item) {
  	for (loop = this.length-1 ; loop >= 0; loop--) {
  		this[loop+1] = this[loop];
  	}
  	this[0] = the_item;
  	return this.length;
  };
}

/**
 * Attach stylesheet
 *
 * Attaches a stylesheet to the head section of the document via the link tag
 * Useful in particular for styles that should only be applied if JS is enabled (eg to hide elements)
 *
 * @author Nicolas Haase <nicolas.haase@team.ourbrisbane.com>
 * @param string loc The location of the stylesheet to be attached
 * @param string id (optional) An id to give to the stylesheet
 * @param string media (optional) The media for the stylesheet, eg print, defaults to all
 * @return boolean true on success, false if browser doesn't support method
 */

function attachStyle(loc,id,media) {
	id = (id)?id:'attachedStyle';
	if (self.id) return false; // Already exists
	if (!document.getElementsByTagName) return false;
	var head = document.getElementsByTagName("head")[0];
	var style = document.createElement('link');
	style.id = id;
	style.type = 'text/css';
	style.rel = 'stylesheet';
	style.media = (media)?media:'all';
	style.href = loc;
	head.appendChild(style);
}

function setStyle(element, style) {
	element = $(element);
	for (name in style)
	  element.style[name] = style[name];
}

function getStyle(element, style) {
	element = $(element);
	var value = element.style[style];
	if (!value) {
		if (document.defaultView && document.defaultView.getComputedStyle) {
			var css = document.defaultView.getComputedStyle(element, null);
			value = css ? css.getPropertyValue(style) : null;
		} else if (element.currentStyle) {
			value = element.currentStyle[style];
		}
	}
}

function getTagNodes(tag,elem) {
	var searchIn = (elem) ? getElement(elem) : document.body;
	var allTags = searchIn.getElementsByTagName(tag);
	return allTags;
}

function createLink(href,txt) {
	var theLink = document.createElement('a');
	theLink.href = href;
	var theTxt = document.createTextNode(txt);
	theLink.appendChild(theTxt);
	return theLink;
}

function $() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = document.getElementById(element);
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

var OB_log = {
	logDiv: document.createElement('div'),
	display: true,
	position: 'absolute',
	height: '',
	reverseOrder: false,
	create: function() {
		this.logDiv.style.background = '#eee';
		this.logDiv.style.position = OB_log.position;
		this.logDiv.style.padding = '1em';
		this.logDiv.style.border = '1px solid #000';
		this.logDiv.style.top = '0px';
		this.logDiv.style.right = '0px';
		this.logDiv.style.zIndex = 100;
		if(this.height != '') { // if a height is set, we get a scrolling div
			this.logDiv.style.height = this.height+'px';
			this.logDiv.style.overflow = 'auto';
			this.reverseOrder = true;
		}
		document.body.appendChild(OB_log.logDiv);
	},
	write: function(msg) {
		if(!this.display) return;
		this.create();
		this.logDiv.innerHTML = (this.reverseOrder) ? (msg += '<br />' + this.logDiv.innerHTML) : (this.logDiv.innerHTML += msg += '<br />');
	},
	divide: function() {
		this.write('<p align="center"><font size="-2">############</font></p>');
	},
	clear: function() {
		this.logDiv.innerHTML = '';
	}
}

/* DEPRECATED FUNCTIONS - delete when all references are removed
 * used on some pages - find and remove */
function popWin(URL,winWidth,winHeight,winType,strWinName){ return !popUpWin(URL,winWidth,winHeight,winType,strWinName);}
function popUp(URL, height, width, name, properties) { if (!name)name=false; return !popUpWin(URL,width-0,height-0,'',name); }
function MM_openBrWindow(URL, name, properties){ return !popUpWin(URL,0,0,'',name); }
function OB_openBrWindow(URL, name, properties){ return !popUpWin(URL,0,0,'',name); }
function MM_setTextOfLayer(objName,x,newText) { layerHTML(objName,unescape(newText)); }
function MM_findObj(n, d) { return getElement(n, d); }

//***************
//  MM Functions
//***************
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);
