
//Extra string adding to HBXPageName
var strExtraHBXPageName ='';

//TNSW : Check Active CMS Editor 
var CMS_Editor_Active = false
//var FlgEditorModeActive =typeof FlgEditorMode
if ((typeof FlgEditorMode) != 'undefined'){
	CMS_Editor_Active = true 
 }

// Display Country Selector 
var FlgDisplayCountrySelector = true;

// Display sIFR Colour Setting  
var FlgTNSWRegionColourSet =false;

/*sIFR */
// FlgAllowSIFRFont: default setting = false 
var FlgAllowSIFRFont = false;
var sIFRFontLocation='/TNSW/Templates/bliss.swf';

/*Upper Menu Links text*/
var strBookmarkPage = 'bookmark page';
var strPrintPage = 'print page';

//load LeftHandside Nav Maps
var FlgNavMapLoad = false;

//google Analytics 
var GoogleAnalyticsSiteID=''; 
var GoogleAnalyticsRegionID='';  
var GoogleAnalyticsSiteSectionID=''; 
var GoogleAnalyticsByDomainNameID='';


//activate google maps
var FlgLoadGoogleMaps = false;



function hideRollover(map_img_id)
{
// function is located in /TNSW/DesNavMenu/js/map.js
}

function showRollover(title,map_img_id,property_name)
{
// function is located in /TNSW/DesNavMenu/js/map.js
}


// social column - holiday Planner
var HolidayPlannerImg ="";
var HolidayPlannerURL="";

//1024 flash header 
var Templt1024HeaderFlashURL ="/Sites/SiteID3/objLib259/header_960x53_NSW.swf";


//TNSW : Implementing common javascript start function for all pages
function initPage() {
	//alert("onload")
	//google maps
	if (FlgLoadGoogleMaps){GLoad_Action();} 
	// Start the menu script
	startList();
	// Initiates the search form scripts
	initSearch();
	//Check Country Selector Display Status
	CountrySelector();
	
	//load LeftHandside Nav Maps
	if (FlgNavMapLoad){
	//alert('FlgNavMapLoad: '+FlgNavMapLoad);
	loadRollovers(FlgNavMapLoad);
	}
	
    //Load Google Map if it exists
   if (typeof googleMap_initialize == 'function') {
   		googleMap_initialize();
	}	
   // Start any image slide functionality (lists with class "imgslide") on the current page.
   initImgSlide();
   
    if ( window.getNextPhoto )
    {
        slide_node = document.getElementById("img_slide_div");
		if(slide_node)
		{
            getNextPhoto(1,global_total_results_available);
		}
	}
   
}


//Check Global Search 
function chkGlobalSearchResult()
{
	if (document.getElementById('searchtext').value==""){
	alert('Please enter a keyword');
	return false;
	}
	else{return true;}
}




function CountrySelector(){
	if (FlgDisplayCountrySelector){
        if (document.getElementById("CountrySelector") != null){
		   document.getElementById("CountrySelector").style.display="block";
		}
	}else {
		document.getElementById("CountrySelector").style.display="none";
	} 
}


/*ads - Display Flag: : default setting = false */
var flgDisplayAds = false;
var adsRightHandSide;
var adsLeftHandSide;
var adsFooter;	


/*ads - Code Generator*/
function genAdCode(adCode){
	//alert(flgDisplayAds+':'+adCode)
	/*var strAdScriptCode
	if (adCode!="" && flgDisplayAds && !CMS_Editor_Active){
	strAdScriptCode= '\<script language="JavaScript" src="http://adsfac.net/ffp.asp?loc='+adCode+'&ord=[timestamp]">\<\/script>'+'\n';
	strAdScriptCode += '\<noscript>'+'\n';
	strAdScriptCode += '<a target="_blank" href="http://adsfac.net/ffp.asp?loc='+adCode+'&clk=1"\><img border="0" src="http://adsfac.net/ffp.asp?loc='+adCode+'&bk=1&js=no&ord=[timestamp]"\></a>'+'\n';
	strAdScriptCode += '\<\/noscript>'
	document.writeln (strAdScriptCode)
	//alert(strAdScriptCode);
	}*/
}

/*TA Navigation Device*/
//flgDisplayTANav : default setting = false 
flgDisplayTANav = false;
//CIValue : default setting = english
CIValue =''	
	
function genTANavCode(){
var strTANavCode
	var strCI='';
	var TANavURL='';
	if (CIValue!=''){strCI = "?ci=" + CIValue; }
	
	//TANavURL= 'http://ta.onedigital.com.au/Overlay.axd'+strCI
	TANavURL= 'http://overlay.australia.com/Overlay.axd'+strCI
	
	if (flgDisplayTANav && !CMS_Editor_Active){
		//strTANavCode = '\<script language="JavaScript" src="'+ TANavURL +'">\<\/script>'+'\n';
		//document.writeln (strTANavCode)
		//alert(strTANavCode);
		
	}

}


// Check that the global search text field is not empty

// Triggers on global search form onsubmit event
function CheckGlobalSearch(form) {
	var input = document.getElementById('searchtext');
	if (input) {
		if (input.value == '') {
			alert('Please enter a keyword');
			return false;
		}
	}	
	return true;
}



//End TNSW

/* This is the SuckerFish menu fix applied to the main menu -  see: http://alistapart.com/articles/dropdowns/  */
var startList = function()
{

 //TNSW: Hide Header Logo Link if CMS Editor is Active 
if (CMS_Editor_Active){
   	document.getElementById('header-logo-home-link-div').style.display = 'none'; 
 }
//End TNSW
 if (document.all&&document.getElementById)
    {
        navRoot = document.getElementById("navMenu");
        if (navRoot)
        {
            for (i=0; i<navRoot.childNodes.length; i++)
            {
                node = navRoot.childNodes[i];

                if (node.nodeName=="LI")
                {
                    node.onmouseover=function()
                    {   
                        this.className+=" over";
                    }
    
                    node.onmouseout=function()
                    {
                        this.className=this.className.replace(" over", "");
                    }
                }
            }
        }
		
    }

    
}


window.onload=initPage;

window.onunload=windowUnload;

function windowUnload(){
    //UnLoad Google Map if it exists
   if (typeof googleMap_GUnload == 'function') {
		googleMap_GUnload();
   }	
}








// Random image loading ..
// Note, the function is called by startlist() onload.

// This script was supplied free by Hypergurl 
// http://www.hypergurl.com

// JavaScript to interpolate random images into a page.
var ic = 4;

// Number of alternative images
var xoxo = new Array(ic); 
// Array to hold filenames
xoxo[0] = new Image;
xoxo[1] = new Image;
xoxo[2] = new Image;
xoxo[3] = new Image;
//xoxo[0].src = "images/header_01.gif"; 
//xoxo[1].src = "images/header_02.gif"; 
//xoxo[2].src = "images/header_03.gif"; 
//xoxo[3].src = "images/header_04.gif"; 

function pickRandom(range) {
	if (Math.random)
		 var thisImage =  Math.round(Math.random() * (range-1));
        else {
		var now = new Date();
		thisImage = (now.getTime() / 1000) % range;
	}


	var headerImage = getElement('random-header-img');

	if(headerImage)
	{
		headerImage.src = xoxo[thisImage].src;
	}
	else
	{
		//alert("general.js - function pickRandom()");
	}

	return thisImage;
}








function getElement(id)
{
    //alert(id);
    if(document.all)
    {
        return eval("document.all['" + id + "']");
    }
    else
    {
        return document.getElementById(id);
    }
}   

function showElement(sub_menu_id)
{

    var sub_menu_list = getElement(sub_menu_id);

    if(sub_menu_list)
    {
        sub_menu_list.style.display = "block";
    }
}

function hideElement(sub_menu_id)
{
   //debugger

    var sub_menu_list = getElement(sub_menu_id);

    if(sub_menu_list)
    {
        sub_menu_list.style.display = "none";
    }
}

function checkAll(allcheck, theForm) 

    {
    
        for(i = 0; i < theForm.length; i++) 
        {
             if(allcheck.checked == 1)
             {
                 if(theForm.elements[i].type =="checkbox")
                 {
                     theForm.elements[i].checked = 1;            
                 }
             }    
        }
    } 

function addToFavorites(url, title)
{   
    if (window.sidebar) { // Mozilla Firefox Bookmark		
        window.sidebar.addPanel(title, url,"");
    }    
    else if(window.external) //IE
    {  
        window.external.AddFavorite(url,title);
    }
    else
    {
        alert("Sorry! Your browser doesn't support this function."); 
    } 

    return false;
}


function validate(f)
{
        var vFlag = true; //initalise vFlag 

        var form = f.elements //first get an array of all form elements.

        //the form elements that need validating have a div with an id name of 'fieldnameTip'.
        //so, to 'dynamically' find out which elements need validation, 'test' the existence
        //of a Div with the name 'fieldnameTip'. If the div exists, the form field needs validation. 
        for(i=0;i<form.length;i++)
        {   
            var fieldName = form[i].name;

            var baseFieldName = fieldName;

            //alert(baseFieldName);

            var tipDiv = getElement(baseFieldName+"Tip");

            if(tipDiv != null)
            {
                //div exists! so validate the element.
                if(checkForValue(form[i],baseFieldName,tipDiv) == false)
                {
                    vFlag = false;
                    //alert("vFlag is false");
                }
            }
        }
        if(vFlag) // If the function is going to return true
        {
            setTip("form-message-div","none");

        }
        else // If the function is going to return false
        {
            setTip("form-message-div","block");
                window.scrollTo(0,0);
                //alert("vFalg is false");
        }

        //alert("vFlag is " + vFlag);
        return vFlag;
}

function checkForValue(field,baseFieldName,tipDiv)
{
        //alert("checkForValue("+field+","+baseFieldName+","+tipDiv+")");

        var eFlag = true;
    
    // DEFINE THE RE AND StrING TO CHECK FOR A VALID EMAIL BELOW
    var reEmail = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/i;
    var email = field.value;
       
    // THE REGULAR EXPRESSION AND email ARE DEFINED AT THE START
    // OF THIS FUNCTION
    
    if((baseFieldName == 'email' || baseFieldName == 'to_email' || baseFieldName == 'from_email')  && !email.match(reEmail))
    {   
        setTip((baseFieldName+"Tip"),"block");
        eFlag = false;
    }
    else if(field.value != "")
    {   
        if(tipDiv != null)
        {   
            //alert("GOT HERE");
            setTip((baseFieldName+"Tip"),"none");
        }
    }
    else
    {   
        if(tipDiv != null)
        {   
            setTip((baseFieldName+"Tip"),"block");
        }
        //alert("field.value == ''");
        eFlag = false;
    }
    
    return eFlag;
}

function setTip(id,state)
{       
        //alert("setTip checking "+id+" : "+getElement(id));
        getElement(id).style.display = state;
}

//TNSW : Automatic sliding of destination images. 
//       Trigger on onload event.
var listClass = 'imgslide';
function initImgSlide() {
	var lists = document.getElementsByTagName('ul')
	if (lists.length != 0) {
		var list = null;
		// Check lists for the class name "imgslide"
		for (var i = 0; i < lists.length; i++) {
			if (lists[i].className == listClass) {
				list = lists[i];
				break;
			}
		}
		// If an element is found, start the slide
		if (list != null)
			startImgSlide(list);
	}
}
var currItm = 1;
var items, nrOfItems;
function startImgSlide(list) {
	items = list.getElementsByTagName('li')
	nrOfItems = items.length;
	// If there are more then 1 list item, start the slide
	if (nrOfItems > 1)
		window.setInterval('slideImages()', 8000);
}
function slideImages() {
	// Set current list item to first (1) or next 
	// index in list (current index + 1)
	currItm = (currItm == nrOfItems) ? 1 : (currItm + 1);
	// Hide all list items
	hideImages();
	// Show the current list item
	showImage((currItm - 1));
}
function hideImages() {
	for (var i = 0; i < nrOfItems; i++)
		items[i].style.display = 'none';
}
function showImage(index) {
	items[index].style.display = 'block';
}
// End TNSW

// Start TNSW

function initSearch() {
	if (document.getElementById('product-search')) {
		// Start the search checkbox script
		// startCheckBoxes();
		// Start the search location script
		initLocLists();
	}
}

// Starts the default checkbox behaviour
var chkList;
function startCheckBoxes() {
	var tables = document.getElementsByTagName('table')
	for (var i=0;i<tables.length;i++) {
		if (tables[i].className == 'search-checkbox-list') {
			chkList = new CheckBoxList(tables[i]);
			break;
		}
	}
	if (chkList)
		prepCheckBoxList();
}

function prepCheckBoxList() {
	for (var i=0;i<chkList.listItems.length;i++) {
		chkList.listItems[i].checkBoxObj.onclick = selectSpecific;
	}
	var allObj = chkList.getByLabel('all');
	if (allObj != null) {
		allObj.checkBoxObj.onclick = selectAll;
	}
}

function selectSpecific() {
	var allObj = chkList.getByLabel('all');
	if (allObj != null && this.checked) {
		if (allObj.checkBoxObj.checked) {
			allObj.checkBoxObj.checked = false;
		} 
	}
}

function selectAll() {
	var status;
	var allObj = chkList.getByLabel('all');
	if (allObj != null && this.checked) {
		for (var i=0;i<chkList.listItems.length;i++) {
			chkList.listItems[i].checkBoxObj.checked = false;
		}
		allObj.checkBoxObj.checked = true;
	}
}

/*
<table id="_ctl0_chkTypes" class="search-checkbox-list" cellspacing="0" cellpadding="0" border="0">
<tr>
<td>

<input id="_ctl0_chkTypes_0" type="checkbox" name="_ctl0:chkTypes:0" checked="checked" />
<label for="_ctl0_chkTypes_0">All</label>

</td><td>

<input id="_ctl0_chkTypes_2" type="checkbox" name="_ctl0:chkTypes:2" />
<label for="_ctl0_chkTypes_2">Festival</label>

</td><td><input id="_ctl0_chkTypes_3" type="checkbox" name="_ctl0:chkTypes:3" /><label for="_ctl0_chkTypes_3">Performance</label></td><td><input id="_ctl0_chkTypes_4" type="checkbox" name="_ctl0:chkTypes:4" /><label for="_ctl0_chkTypes_4">Sport</label></td>
</tr><tr>
<td>
<input id="_ctl0_chkTypes_1" type="checkbox" name="_ctl0:chkTypes:1" />
<label for="_ctl0_chkTypes_1">Exhibition/Show</label>
</td>
</tr>
</table>
*/

function CheckBoxList(table) {
	this.listObj = table;
	this.listItems = new Array;
	this.init = function() {
		var inputs = table.getElementsByTagName('input');
		for (var i=0;i<inputs.length;i++) {
			if (inputs[i].type == 'checkbox') {
				this.listItems.push(new CheckBox(inputs[i]));
			}
		}
	}
	this.getByLabel = function(value) {
		for (var i=0;i<this.listItems.length;i++) {
			if (this.listItems[i].labelObj.innerHTML.toLowerCase() == value.toLowerCase()) {
				return this.listItems[i];
				break;
			}
		}
		return null;
	}

	this.init();
}

var labels = null;
function CheckBox(input) {
	this.checkBoxObj = input;
	this.labelObj = null;
	this.init = function() {
		if (labels == null) {
			labels = document.getElementsByTagName('label');
		}
//		alert(labels[0].getAttribute('for'));
		for (var i=0;i<labels.length;i++) {
			var forValue = labels[i].getAttribute('for');
			if (forValue != null || forValue == this.checkBoxObj.id) {
				this.labelObj = labels[i];
				break;
			}
		}
	}
	this.checked = function() {
		return this.checkBoxObj.checked;
	}
	this.init();
}

var regList, areaList;
var areaFilterList;
var filterStatus;
// Find the region and area select lists
// and initialize the location scripts
function initLocLists() {
	var lists = document.getElementsByTagName('select');
	var exRegions = new RegExp('lstRegions');
	var exAreas = new RegExp('lstAreas');
	var filterStatId = 'filterstatus';
	for (var i = 0; i < lists.length; i++) {
		if (lists[i].id.match(exRegions)) {
			regList = lists[i];
		}
		if (lists[i].id.match(exAreas)) {
			areaList = lists[i];
		}
	}
	filterStatus = document.getElementById(filterStatId);
	// If the lists exist, prepare lists and attach events
	if (regList != null && areaList != null) {
		// If the onselect event is successfully attached to 
		// the region list then prepare the area list.
		if (prepRegionList()) {
			prepAreaList();
		}
		// If a region is selected by default but not area, filter area list.
		if (regList.selectedIndex > 0 && !areaList.selectedIndex) {
			filterAreaList(regList.options[regList.selectedIndex].value);
		}
	}
}
// Attach the onchange event
function prepRegionList() {
	return (regList.onchange = onRegionChange)
}
function prepAreaList() {
	areaFilterList = new FilterList(areaList);
	// Filter on item value, not name
	areaFilterList.match_value = true;
}
function onRegionChange() {
	var filter = regList.options[regList.selectedIndex].value;
	// Add whitespace to end of filter
	filter = filter + ' ';
	filterAreaList(filter);
}
function filterAreaList(filter) {
	if (areaFilterList != null) {
		areaFilterList.set(filter);
		if (filter != '') {
			setStatus('Filtered', true);
		} 
		else {
			resetList();
		}
	}
	else {
		// Try to init list if there is a area select obj.
		if (areaList != null) {
			prepAreaList();
			areaFilterList.set(filter);
		}
	}
}
function setStatus(text, resetLnk) {
	if (filterStatus != null) {
		if (text != null) {
			var str = text;
			if (resetLnk) {
				str += ' <a href="#" onclick="return resetList();">reset</a>';
			}
			str = '(' + str + ')';
		} 
		else {
			str = '';
		}
		filterStatus.innerHTML = str;
	}
}
function resetList() {
	areaFilterList.reset();
	setStatus();
	return false;
}

function FilterList(selectobj) {
	this.selectobj = selectobj;
	this.flags = 'i';
	this.match_text = true;
	this.match_value = false;
	// myfilterlist.hook = function() { }
	this.show_debug = false;
	this.init = function() {
		if (!this.selectobj) return this.debug('selectobj not defined');
		if (!this.selectobj.options) return this.debug('selectobj.options not defined');
		// Make a copy of the select list options array
		this.optionscopy = new Array();
		if (this.selectobj && this.selectobj.options) {
			for (var i = 0; i < this.selectobj.options.length; i++) {
				this.optionscopy[i] = new Option();
				this.optionscopy[i].text = selectobj.options[i].text;
				if (selectobj.options[i].value) {
					this.optionscopy[i].value = selectobj.options[i].value;
				} 
				else {
					this.optionscopy[i].value = selectobj.options[i].text;
				}
			}
		}
	}
	this.reset = function() {
		this.set('');
	}
	this.set = function(pattern) {
		var index = 0, regexp, e;
		if (!this.selectobj) return this.debug('selectobj not defined');
		if (!this.selectobj.options) return this.debug('selectobj.options not defined');
		this.selectobj.options.length = 0;
		try {
			regexp = new RegExp(pattern, this.flags);
		} 
		catch(e) {
			if (typeof this.hook == 'function') {
				this.hook();
			}
			return;
		}
		// Add empty option
		this.selectobj.options[0] = new Option('', '', false);
		for (var loop = 0; loop < this.optionscopy.length; loop++) {
			var option = this.optionscopy[loop];
			if ((this.match_text && regexp.test(option.text)) || (this.match_value && regexp.test(option.value))) {
				this.selectobj.options[(index++)+1] = new Option(option.text, option.value, false);
			}
		}
		if (typeof this.hook == 'function') {
			this.hook();
		}
	}
	this.set_ignore_case = function(value) {
		this.flags = (value)?'i':'';
	}
	this.debug = function(msg) {
		if (this.show_debug) {
			alert('FilterList: ' + msg);
		}
	}
	this.init();
}

function AddQueryString(actionValue,QueryString){
   var strOut='';
   if (actionValue.indexOf('aspx?')==-1){
      strOut=actionValue + '?' + QueryString;
   }else {
      strOut=actionValue + '&' + QueryString;
   }
   return strOut;
}
//Google Map keys
//Same keys and values have been defined in web.config as well so if you are changing any value here, please change in 
//web.confg file as well.

var googleMap_sydneycomkey ='gme-tourism'
var googleMap_VisitNSWcomKey = 'gme-tourism'
var googleMap_VisitNSWcomauKey = 'gme-tourism'

//
//var googleMap_sydneycomkey ='ABQIAAAA-9ixGtSUUKvOqhlR8fneyhQyJ8ehuBm5pSoacssQXNRZVGLriRQoIVAnrEKWlNfJSRS5796XYFCoPw'
//var googleMap_VisitNSWcomKey = 'ABQIAAAA-9ixGtSUUKvOqhlR8fneyhRpZp6omxt0dczBlZXVzZPWaBYniRSySdvQgyOf_v96uk8Gd1vixBHZsg'
//var googleMap_VisitNSWcomauKey = 'ABQIAAAA-9ixGtSUUKvOqhlR8fneyhSzw5htAAQmNzx1641IYyjkpCD_sxQNk3gOssx4gdM9DCoGBJ844U7oDg'





// End TNSW

/////////////




// Conversion Name:Sydney.com Visitors (All pages)

var ebRand = Math.random()+ ' ';
ebRand = ebRand * 1000000;
document.write('<scr'+'ipt src="HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID=39272&amp;rnd=' + ebRand + '"></scr' + 'ipt>');


// hide nav when 2 navs generated for crave design
function hideNav()
{
	jQuery.noConflict();
	jQuery('.div-nav:first').show();
	jQuery('.div-nav:last').hide(); 
}


//Start - Outrider SEO audit code.

var refr=escape(document.referrer); /* get the http referer and encode it */
var dom=location.hostname; /* get the host domain */
var stURL="http://link.decideinteractive.com/n/202/1092/www.tourism.nsw.gov.au/1lu7h4j;11;4;;6;;ci48g9;;;;;1;/i/c?0&pq=%2fseo&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;
}
 
//End - Outrider SEO audit code.

////////////////////

//<!-- COUNTRY DROPDOWN START -->
function showdetails(show)
{       
   itemToShow = document.getElementById(show);
   itemToShow.style.visibility = 'visible';        
}
function hidedetails(hide)
{
   itemToHide = document.getElementById(hide);
   itemToHide.style.visibility = 'hidden';        
}       

//<!-- COUNTRY DROPDOWN END -->

//PETERSKI Added 18Aug2010
// Description: check to see if Internet Explorer 7 is current browser
// If so add background image from body tag to HTML
// This will partially resolve zooming in issue, zooming out is still buggy

//var version=0;
//if(navigator.appName.indexOf("Internet Explorer") != -1)
//{
//	temp=navigator.appVersion.split("MSIE");
//	version=parseFloat(temp[1]);
//	if(version==7){
//	window.onload = function() { 
//		var backgroundImage = $('body').css('background-image')+ ' repeat-x'; //get body background image
//		$('html').css('background',backgroundImage); // assign body background image to html tah
//	} 
// }
//}




