/* start global variable & array declarations */

var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0
var ie4 = (document.all) ? 1:0
var isOp = (window.opera) ? 1:0


var subNav = 1;
var myArrowStr = 0;
var theBreadCrumb;

var dirStart = 0; /* dev var to set array index for top level nav select */
var setFlag = 0; /* var to check for sidenav */

/* path to utility images used in script */
/* link seperator for breadcrumb script */

var imagePath = 'http://www.yarracity.vic.gov.au/images/'   
var crmbSeprator = '&nbsp;&nbsp;<img src="' + imagePath + 'icn_dngbat_dot.gif" alt=" | " width="11" height="12" />&nbsp;'

theMainNav = new Array("neighbourhood","community","council","services","publications","environment","payments","info")

	
var theCol = "#FFCCFF";
var rolloverCol = "#096"; /* navbar rollover color */
var selectCol = "#096";   /* navbar hilite color */
var ssSelectCol = "#096"; /* css selection hilite color */

/* call needed functions */

makeCrumb();
styleInsert();

/* start navigation functions */
/* function for writing breadcrumbs (breadcrumbs) */
/* function for highlighting nav (hiLiteMe) */

function makeCrumb() {
if(w3c) {
    sURL = new String(); bits = new Object();
    var x = 0; var stop = 0;
    document.theBreadCrumb = '&nbsp;<a href="/">Home</a>' ;
    sURL = location.href;
    sURL = sURL.slice(8,sURL.length);
    chunkStart = sURL.indexOf("/");
    sURL = sURL.slice(chunkStart+1,sURL.length)
	while(!stop)	{
    	chunkStart = sURL.indexOf("/");
      	if (chunkStart != -1)	{
			bits[x] = sURL.slice(0,chunkStart)
        	sURL = sURL.slice(chunkStart+1,sURL.length);
      		} else {stop = 1;}
      	x++;
    	}
    	for(var i in bits)	{
    	document.theBreadCrumb += crmbSeprator + '<a href="';
    	for(y=1;y<x-i;y++)	{
    		document.theBreadCrumb += 'http://www.yarracity.vic.gov.au/';
      		}
      	document.theBreadCrumb += bits[i] + '/">' + bits[i] + '</a>';
    	}
    	theTitle = document.title; 
		removeString = new Array("The City of Yarra", "City of Yarra", "City of Yarra - ");
    	for (y=0;y<removeString.length;y++) {
    		c = theTitle.indexOf(removeString[y])
    		if ((c<4) && (c>-1))	{
    			theTitle = theTitle.replace(removeString[y]," ")
    			}
    		}
		document.theBreadCrumb += crmbSeprator + theTitle;
	}
	if (bits[dirStart]) {
		theString = (bits[dirStart].substring(0,4)) + "Row";
		makeNavStyle( theString );
		}
}


function makeNavStyle(theNavItem) {
		document.setFlag=theNavItem;
		theStyleStr = '<style>'
		theStyleStr += '#' + theNavItem + '{';
		theStyleStr +=  'background-color: ' + selectCol + '; color: transparent;}</style>'
		document.write(theStyleStr);
}


function hiLiteMe(theRow,status) {
	h = document.getElementById(theRow);
	if (document.setFlag != theRow && h != null)	{
		 (status == 'on') ? h.style.background = rolloverCol : h.style.background = "#004737";	
	}
}
	

   
/* start utility scripts */

/* change layer visibility (show & hide) */
/* image rollover (changeImage) */
/* pop window with called window (popimage) */
/* pop window and write image to it (popTheWin) - requires container htm */

function visi(nr) {
	visObj = new getMyObj(nr);
	alert(visObj.tostring())
	if (w3c)	{
		vista = (document.getElementById(nr).style.visibility == 'hidden') ? 'visible' : 'hidden'; 
		document.getElementById(nr).style.visibility = vista;
	}
	else if (ie4)	{
		vista = (document.all[nr].style.visibility == 'hidden') ? 'visible': 'hidden'; 
		document.all[nr].style.visibility = vista;
	} 
}

function toggle( targetId ) {
	if (w3c) {
  		target = new getMyObj(targetId);
		if (target.style.display == "none") {
			target.style.display = "";
  			} else {
			target.style.display = "none";
		}
  	}
}

function flipIt(parentID, childID) {
if (w3c) {
	Store = '<a href="javascript:' +  "flipIt('Me', 'theList')" + ';">';
	Store +=  '<img src="http://www.yarracity.vic.gov.au/images/btn_xpnd.gif" width="13" height="13" alt="Show Menu" border="0">'
	Store += '&nbsp;<strong>Show this section</strong></a>';
	reStore = '<a href="javascript:' +  "flipIt('Me', 'theList')" + ';">';
	reStore +=  '<img src="http://www.yarracity.vic.gov.au/images/btn_mnmse.gif" width="13" height="13" alt="(x)" border="0">'
	reStore += '&nbsp;<strong>In this section:</strong></a>';
	theChild = new getMyObj(childID);
	if (theChild.style.display == "none") {
		toggle(childID);
		document.getElementById(parentID).innerHTML = reStore;
		} else { 
		toggle(childID);
		document.getElementById(parentID).innerHTML = Store;
		}
	}
}
  
function show(id) {
	var Obj = new getMyObj(id)
	if (ns4) {Obj.visibility = "show"}
	else Obj.style.visibility = "visible"
}

function hide(id) {
	var Obj = new getMyObj(id)
	if (ns4) {Obj.visibility = "hide"}
	else Obj.style.visibility = "hidden"
}

function changeImage(layer,imgName,imgObj)	{
	if (document.images)	{
		if (document.layers && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
		else document.images[imgName].src = eval(imgObj+".src")
	}
}

function popimage(image_name, width, height)	{
		newwindow=window.open('http://www.yarracity.vic.gov.au/images/' + image_name + ".gif","", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=" + (width + 4) + ",height=" + (height + 4));
}

/* object access functions */
/* getmyobj is base function and getmyobjn4 is for finding nested div in netscape */
 
function getMyObj(name)	{
	if (w3c)	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
		}
	else if (ie4)	{
		this.obj = document.all[name];
        this.style = document.all[name].style;
        }
   else if (ns4)	{
		this.obj = getMyObjN4(document,name);
        this.style = this.obj;
        }
}

function getMyObjN4(obj,name)	{
	var x = obj.layers;
    var foundLayer;
    for (var i=0;i<x.length;i++)	{
		if (x[i].id == name)
		foundLayer = x[i];
		else if (x[i].layers.length)
		var tmp = getMyObjN4(x[i],name);
		if (tmp) foundLayer = tmp;
		}
	return foundLayer;
}

 /*  Following function is a fix for an IE Mac bug where GIFs passed to 
 a dynamically generated window don't load properly ... calls a html file
 and writes the image into the page */
 
function popTheWin(thePath, theImage, theWidth, theHeight, theTitle)
	{
	image_path = thePath; image_name = theImage;
	image_width = theWidth; image_height = theHeight;
	win_title = theTitle;
	galWin=window.open('http://www.yarracity.vic.gov.au/container.asp','','toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=no,resizable=no,copyhistory=no,innerwidth=' + (parseInt(image_width) + 20) + ',innerheight=' + (parseInt(image_height) + 20));
	}

/* cookie scripts for setting style sheet */

function styleHiLite(theId) {
if(w3c) {
	h=document.getElementById(theId)
	StyleStr = '<style>'
	StyleStr += '#' + theId + '{\n';
	StyleStr +=  'background-color: ' + ssSelectCol + '; color: transparent;}\n</style>'
	document.write(StyleStr);
	}
}
   

function styleInsert() {
	if (document.cookie.indexOf('style=1')>=0)	{
		theStyleString =  '<link rel="stylesheet" type="text/css" href="/yarragives/include/css/yarra_small.css" />\n'
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarra_main.css" title="Normal text" />\n'; 
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarra_large.css" title="Large text" />\n';
		document.write(theStyleString);
		styleHiLite('Style1');
		} else if (document.cookie.indexOf('style=3')>=0) {
        theStyleString =  '<link rel="stylesheet" type="text/css" href="/yarragives/include/css/yarra_large.css" />\n';
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarra_main.css" title="Normal text" />\n'; 
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarra_small.css" title="Small text" />\n';
		document.write(theStyleString);
		styleHiLite('Style3');
			} else {
 		theStyleString =  '<link rel="stylesheet" type="text/css" href="/yarragives/include/css/yarra_main.css" />\n';
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarra_large.css" title="Large text" />\n'; 
		theStyleString += '<link rel="alternate stylesheet" type="text/css" href="/yarragives/include/css/yarr_small.css"  title="Small text" />\n';    document.write(theStyleString);
		styleHiLite('Style2');
		}
}

function setStyle (newstyle) {
	var expdate = new Date();
	expdate.setTime(expdate.getTime() + (1000*3600*24*365));
	document.cookie = 'style=' + newstyle + '; expires=' + expdate.toGMTString() + '; path=/';
	alert ('This style choice will persist for a year unless changed.\n You may need to reload the page.');
	self.location = self.location;
}

/* frontage validator for search */

function FrontPage_Form1_Validator(theForm)	{
	if (theForm.CiRestriction.value == "")	{
    	alert("Please enter a value for the \"Search Box\" field.");
    	theForm.CiRestriction.focus();
    	return (false);
  	}

  	if (theForm.CiRestriction.value.length > 100)	{
    	alert("Please enter at most 100 characters in the \"Search Box\" field.");
    	theForm.CiRestriction.focus();
    	return (false);
  	}
  return (true);
}

function DoctorElements()
	{
		var i,j;
		for (i=0; i < document.forms[0].elements.length-1; i++)
			switch (String(document.forms[0].elements[i].name).substring(0,3))
			{
				case "chk":
					if (document.forms[0].elements[i].checked)
						document.forms[0].elements[i].value = "Yes";
					else {
						document.forms[0].elements[i].checked = true;
						document.forms[0].elements[i].value = "No";
					}
					break;
			}
	}

   
