/**************************************************************************
** $Id: ourbrisbane.js 15709 2008-10-21 07:46:40Z sanjays $
**
** 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
** Release notes:
**
**************************************************************************/

/*-------------------------- 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();

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


/*-------------------------- OTHER --------------------------*/

// this function is emtashtash
function toggleFS(groupId){
	// go thru the group, hide all associated ids, then go thru it again, and show checked
	var chGroup = document.getElementsByName(groupId);
	var fgroup;
	if (chGroup){
		for (var j=0; j<chGroup.length; j++){
			// get fgroup elements
			fgroups = String(chGroup[j].getAttribute("fgroup")).split(",");
			for (var i=0; i<fgroups.length; i++){
				if (document.getElementById(fgroups[i]))
					document.getElementById(fgroups[i]).style.display = 'none';
			}
		}
		for (var j=0; j<chGroup.length; j++){
			// get fgroup elements
			fgroups = String(chGroup[j].getAttribute("fgroup")).split(",");
			for (var i=0; i<fgroups.length; i++){
				if (document.getElementById(fgroups[i]))
					if (chGroup[j].checked) document.getElementById(fgroups[i]).style.display = 'block';
			}
		}
	}
}



function relElements(){
	prepareDefaults();
	var rels = document.getElementsByTagName("input"); // to be globalized
	for (var i=0; i<rels.length; i++){
			// make a lookup list, now its just defualt
			if (String(rels[i].getAttribute("rel")) == "default"){
				// call function for default handling 
				handleDefault(rels[i]);
			}
	}
	
}
function handleDefault(o){

	// set title to default text, check onblur and onfocus, change value AND classname
	var dValue = o.getAttribute("defvalue");
	var bfFunc = o.getAttribute("beforefocus");
	var bbFunc = o.getAttribute("beforeblur");
	var dClassname = o.className;
	if (o.value == "" || o.value == dValue){
		o.className += " light";
		o.value = dValue;
	} 
	o.onfocus = function(){
		if (bfFunc) eval(bfFunc);
		if (o.value == dValue) o.value = "";
		o.className = dClassname;
	}
	o.onblur = function(){
		if (bbFunc) eval(bbFunc);
		if (o.value == "" || o.value == dValue){
			o.className += " light";
			o.value = dValue;
		}

	}
	
}
var oldClass;
function toggleDisable(fId, chId){
	f = document.getElementById(fId);
	ch = document.getElementById(chId);
	if (f && ch){
		oldClass= f.className;
		if(ch.checked) {  f.value=''; f.disabled = true; f.className += ' disabled';}
		else {f.disabled = false; f.className = oldClass;}
	}
}
function toggleSelect(sElem){
	// go thru selem, find twin attributes, hide all, then show the current selection
	for (var j=0; j<sElem.options.length; j++){
		
		if (document.getElementById(sElem.options[j].getAttribute("twin"))){
			document.getElementById(sElem.options[j].getAttribute("twin")).style.display = "none";
		}
	}
	// show distinct
	var id = sElem.options[sElem.selectedIndex].getAttribute("twin");
	if (document.getElementById(id))
		document.getElementById(id).style.display = "block";
}
/*-------------------------- PRELOADS --------------------------*/

function prepareGroup(){
	// add attribute fgroup to each checkbox as required
	if (document.getElementById('sub_thisweekend'))
		document.getElementById('sub_thisweekend').setAttribute("fgroup","info,fgroup1,bSub");
	if (document.getElementById('sub_majorevents'))
		document.getElementById('sub_majorevents').setAttribute("fgroup","info,fgroup1,bSub");
	if (document.getElementById('sub_special'))
		document.getElementById('sub_special').setAttribute("fgroup","info,fgroup1,fgroup2,bSub");		
	if (document.getElementById('sub_shoppingdining'))
		document.getElementById('sub_shoppingdining').setAttribute("fgroup","info,fgroup1,bSub");
}
function preloadGroups(){
	prepareGroup();
	// find groups and checkboxes, and assign onclicks
	var chGroup = document.getElementsByName('sub_group');
	if (chGroup){
		for (var j=0; j<chGroup.length; j++){
			// call function
			toggleFS('sub_group');
			chGroup[j].onclick = function(){
				toggleFS('sub_group');
			}
		}
	}
}
function prepareSuburb(){
	// add attribute twin to selected options
	if (document.getElementById('suburb')){
		document.getElementById('suburb').options[1].setAttribute("twin","sCityField");
		document.getElementById('suburb').options[2].setAttribute("twin","sNotListed");
	}
}
function preloadSuburb(){
	prepareSuburb();
	var sSuburb = document.getElementById('suburb');
	if (sSuburb){
		toggleSelect(sSuburb);
		sSuburb.onchange = function(){
			toggleSelect(this);
		}
	}
}

function prepareDefaults(){
	// add attribute rel=default and defValue to all fields required
	if (document.getElementById('iY')){
		document.getElementById('iY').setAttribute("rel","default");
		document.getElementById('iY').setAttribute("defvalue","I'd rather not say!");
		document.getElementById('iY').setAttribute("beforefocus","changeMaxSize(this,4)");
		document.getElementById('iY').setAttribute("beforeblur","changeMaxSize(this)");
	}
}
addLoadEvent(relElements);
addLoadEvent(function(){
	toggleDisable('iY','chY');
});
addLoadEvent(preloadGroups);
addLoadEvent(preloadSuburb);

/*------------------UI Specific -------------------------*/
function changeMaxSize(d,s){
	if (s)	d.maxLength = s;
	else d.maxLength = '500';
	
}
