// Set global variables
var currSize;
var classes = ["smallest", "smaller", "default", "larger", "largest"];


// Open/Create cookie - REVERT BACK TO WOG PARAMETER PRIOR TO DEPLOYMENT
var gatewayCookie = new Cookie(document, "cue", 240, "/", "qld.gov.au");

//document.cookie += "test" + "=" + escape('true');



//gatewayCookie.remove();
//gatewayCookie = new Cookie(document, "cue", 240, "/", "qld.gov.au");





// Used to optionally suppress HBX or urchin.js on some special pages
var suppressJSStats = false;


function get_random() {
    var ranNum= Math.round(Math.random()*10);
    return ranNum;
}



/*
	* 			SCRIPTS FOR COMMUNITY PARTNERSHIPS GRANT...
	* Description:	Functions used for the 'email this page' form
	*
	* Affiliated CSS:	qglayout.css - .red
*/


// --- Email this page ---
var cpgCookie = new Cookie(document, "cpg", 240, "/");

function init_url() {
  if (cpgCookie.load()) {	
	var blank = "";
	if (!cpgCookie.refer_url){
		return blank;
		}
	else{
		return cpgCookie.refer_url;
		}
  }
}

function setURL() {
	cpgCookie.refer_url = location.href;
	cpgCookie.store();
      window.location = "/communitypartnershipsgrant/emailpage.html"
}

 function doClear() {
	document.emailpage.emailto.value = "";
	document.emailpage.emailfrom.value = "";
	document.emailpage.toname.value = "";
	document.emailpage.fromname.value = "";
	document.emailpage.comments.value = "";
 }

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 

function postAction() {
	document.emailpage.recipientEmailCopy.value = document.emailpage.emailto.value;
}

function delete_referURL() {
	cpgCookie.remove();
}


// --- End email this page ---
/* END SCRIPTS FOR COMMUNITY PARTNERSHIPS GRANT */




/*
	* 			SCRIPTS FOR SSQ FORM VALIDATION...
	* Description:	Functions used for validating the SSQ form
	*
	* Affiliated CSS:	qglayout.css - #ssqFormIncomplete_Name, #ssqFormIncomplete_Address, #ssqFormIncomplete_Contact, #ssqFormIncomplete_Position
*/


// Validates the form before submitting
function ssqValidateForm(form) {

	if (document.ssqApply) {
		if (document.ssqApply.name.value == "") {
			document.getElementById("ssqFormIncomplete_Name").innerHTML="Please complete the required fields";
		} else { document.getElementById("ssqFormIncomplete_Name").innerHTML=""; }


		if ((document.ssqApply.address.value == "") || (document.ssqApply.postcode.value == "") || (document.ssqApply.state.value == "")) {
			document.getElementById("ssqFormIncomplete_Address").innerHTML="Please complete the required fields";
		} else { document.getElementById("ssqFormIncomplete_Address").innerHTML=""; }
	
		if (document.ssqApply.contactphone.value == "") {
			document.getElementById("ssqFormIncomplete_Contact").innerHTML="Please complete the required fields";
		} else { document.getElementById("ssqFormIncomplete_Contact").innerHTML=""; }

		if (!document.ssqApply.position1.checked && !document.ssqApply.position2.checked && !document.ssqApply.position3.checked && !document.ssqApply.position4.checked) {
			document.getElementById("ssqFormIncomplete_Position").innerHTML="Please complete the required fields";
		} else { document.getElementById("ssqFormIncomplete_Position").innerHTML=""; }

		if ((document.ssqApply.name.value == "") || (document.ssqApply.address.value == "") || (document.ssqApply.postcode.value == "") || (document.ssqApply.contactphone.value == "") || ((!document.ssqApply.position1.checked) && (!document.ssqApply.position2.checked) && (!document.ssqApply.position3.checked) && (!document.ssqApply.position4.checked))) {
			return false;
		}

	}


	 
	return true;

}

// Clears the error messages
function ssqFormClear() {
	document.getElementById("ssqFormIncomplete_Name").innerHTML="";
	document.getElementById("ssqFormIncomplete_Address").innerHTML="";
	document.getElementById("ssqFormIncomplete_Contact").innerHTML="";
	document.getElementById("ssqFormIncomplete_Position").innerHTML="";
}

/*  END SSQ FORM VALIDATION SCRIPTS */


function writeFeature() {
   var randomNo=get_random();

    var textFeature=new Array(10)
		textFeature[0] = "<a href=\"text.html\">Change text size</a>";
		textFeature[1] = "<a id=\"highlight\" href=\"text.html\">Change text size</a>";
		textFeature[2] = "<a href=\"text.html\">Text size</a>";
		textFeature[3] = "<a id=\"highlight\" href=\"text.html\">Text size</a>";
		textFeature[4] = "<a href=\"text.html\">Settings</a>";
		textFeature[5] = "<a id=\"highlight\" href=\"text.html\">Settings</a>";
		textFeature[6] = "<a href=\"text.html\">Preferences</a>";
		textFeature[7] = "<a id=\"highlight\" href=\"text.html\">Preferences</a>";
		textFeature[8] = "<a href=\"text.html\">Options</a>";
		textFeature[9] = "<a id=\"highlight\" href=\"text.html\">Options</a>";
		textFeature[10] = "<span class=\"textsize\"><a href=\"#\" title=\"Increase size of text\">Text size</a>&nbsp; <a href=\"javascript: fontUp();\"><img src=\"big.gif\" class=\"texticons\" border=\"0\" align=\"middle\"></a> <a href=\"javascript: fontDown();\" ><img src=\"small.gif\" border=\"0\" class=\"texticons\" align=\"middle\"></a></span>";

  
   document.write(textFeature[randomNo]);
  }



function smallestSize(){
	currSize = 0;
	document.body.className = classes[currSize];
	gatewayCookie.textSize = 0;
	gatewayCookie.store();
}


function smallerSize(){
	currSize = 1;
	document.body.className = classes[currSize];
	gatewayCookie.textSize = 1;
	gatewayCookie.store();
}

function defaultSize(){
	currSize = 2;
	document.body.className = classes[currSize];
	gatewayCookie.textSize = 2;
	gatewayCookie.store();
}

function largerSize(){
	currSize = 3;
	document.body.className = classes[currSize];
	gatewayCookie.textSize = 3;
	gatewayCookie.store();
}


function largestestSize(){
	currSize = 4;
	document.body.className = classes[currSize];
	gatewayCookie.textSize = 4;
	gatewayCookie.store();
}

// --- Imports the textsize style if present ---
function importTextStyleSheet() {

	if (gatewayCookie.load()) {
		
		if (gatewayCookie.textSize == 0) {
			document.write("<link rel=\"stylesheet\" href=\"/css/textSize/0.css\" type=\"text/css\">");
		} else if (gatewayCookie.textSize == 1) {
			document.write("<link rel=\"stylesheet\" href=\"/css/textSize/1.css\" type=\"text/css\">");
		} else if (gatewayCookie.textSize == 2) {
			document.write("<link rel=\"stylesheet\" href=\"/css/textSize/2.css\" type=\"text/css\">");		
		} else if (gatewayCookie.textSize == 3) {
			document.write("<link rel=\"stylesheet\" href=\"/css/textSize/3.css\" type=\"text/css\">");	
		} else if (gatewayCookie.textSize == 4) {
			document.write("<link rel=\"stylesheet\" href=\"/css/textSize/4.css\" type=\"text/css\">");	
		} else {}

	} 

}



/* Randomiser for Services Online */

	// Unique Random Numbers
	// -Picks a number of unique random numbers from an array
	// (c) 2002 Premshree Pillai
	// http://www.qiksearch.com
	// http://premshree.resource-locator.com
	// E-mail : qiksearch@rediffmail.com

function pickNums(nums, numArr)
{
	
	var pickArr=new Array();
	var tempArr=numArr;
	for(var i=0; i<nums; i++)
	{
		pickArr[pickArr.length]=tempArr[Math.round((tempArr.length-1)*Math.random())];
		var temp=pickArr[pickArr.length-1];
		for(var j=0; j<tempArr.length; j++)
		{
			if(tempArr[j]==temp)
			{
				tempArr[j]=null;
				var tempArr2=new Array();
				for(var k=0; k<tempArr.length; k++)
					if(tempArr[k]!=null)
						tempArr2[tempArr2.length]=tempArr[k];
				tempArr=tempArr2;
				break;
			}
		}
	}
	return pickArr;
}



function delete_cookie_text()
{


if (!gatewayCookie.load()) {
	window.location = "/my-community/delete-cookie.html";

}
else
{
	gatewayCookie.textSize = false;
	gatewayCookie.store();
	window.location = "/my-community/delete-cookie.html";

}
}

function delete_cookie_regions() {
	if (!gatewayCookie.load()) {
		window.location = "/my-community/delete-cookie.html";

	} else {
		gatewayCookie.region = "";
		gatewayCookie.weatherStation = "";
		gatewayCookie.stationID = "";
		gatewayCookie.store();
		window.location = "/my-community/delete-cookie.html";

	}
}





/*
	* 			SCRIPTS FOR REGIONAL CONTENT...
	* Description:	Scripts used to open and close DIV tags for regional content.
	*			Only loads when customer selects to opt in. Otherwise, will load
	*			nothing.
	*
	* Affiliated CSS:	qglayout.css - .boxesRegion
*/

// Opens DIV tag at the beginning
function writeDiv() {
	if (gatewayCookie.load() && gatewayCookie.region == "southCoast") {
		document.write('<div class=\"boxesContent\"><div class=\"boxesRegion\">');
	} else { document.write('<div class=\"boxes\">');	}
}

// Closes DIV tag at the end
function closeDiv() {
	if (gatewayCookie.load() && gatewayCookie.region == "southCoast") {
		document.write('</div>');} 
}



// Writes CSS script into the page
function writeRegionalCSS() {
	if (gatewayCookie.load()) {
			if (gatewayCookie.region) {
			 	document.write("<link rel=\"stylesheet\" href=\"css/regions/southCoast.css\" type=\"text/css\">"); 
			} else { document.write("<link rel=\"stylesheet\" href=\"css/regions/none.css\" type=\"text/css\">"); } 
	} else {document.write("<link rel=\"stylesheet\" href=\"css/regions/none.css\" type=\"text/css\">"); } 
}


// END REGIONAL FUNCTIONS





<!--

/*
	*	Description:	Functions used to store and read a cookie
	*	Date:					28 May 2004
	*	Author:				Taken from Example 16-1, JavaScript: The Definitive Guide (4th edn) 
									by David Flanagan. Copyright 2001 O'Reilly
*/

//	FUNCTION:			Cookie
//	DESCRIPTION:	Constructor function - Creates a Cookie object for the specified
// 								document, with a specified name and optional attributes.
// 	ARGUMENTS:		
//   	document:		The Document object for which the cookie is stored. Required.
//   	name:    		A string that specifies a name for the cookie. Required.
//   	hours:   		An optional number that specifies the number of hours from now
//             		after which the cookie should expire.
//   	path:    		An optional string that specifies the cookie path attribute.
//   	domain:  		An optional string that specifies the cookie domain attribute.
//   	secure:  		An optional boolean value that, if true, requests a secure cookie.
//	RETURNS:			New Cookie object
function Cookie(document, name, hours, path, domain, secure)
{
    // All the predefined properties of this object begin with '$'
    // to distinguish them from other properties, which are the values to
    // be stored in the cookie
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime(  ) + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}

//	FUNCTION:			store
//	DESCRIPTION:	This function is the store() method of the Cookie object			
// 	ARGUMENTS:		none
//	RETURNS:			nothing
Cookie.prototype.store = function (  ) {
    // First, loop through the properties of the Cookie object and
    // put together the value of the cookie. Since cookies use the
    // equals sign and semicolons as separators, we'll use colons
    // and ampersands for the individual state variables we store 
    // within a single cookie value. Note that we escape the value
    // of each state variable, in case it contains punctuation or other
    // illegal characters.
    var cookieval = "";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    // Now that we have the value of the cookie, put together the 
    // complete cookie string, which includes the name and the various
    // attributes specified when the Cookie object was created
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString(  );
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    // Now store the cookie by setting the magic Document.cookie property
    this.$document.cookie = cookie;
}

//	FUNCTION:			load
//	DESCRIPTION:	This function is the load(  ) method of the Cookie object			
// 	ARGUMENTS:		none
//	RETURNS:			false if cookie is empty, true if successfully read cookie
Cookie.prototype.load = function(  ) { 
    // First, get a list of all cookies that pertain to this document
    // We do this by reading the magic Document.cookie property
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    // Now extract just the named cookie from that list
    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   // Cookie not defined for this page
    start += this.$name.length + 1;  // Skip name and equals sign
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    // Now that we've extracted the value of the named cookie, we
    // must break that value down into individual state variable 
    // names and values. The name/value pairs are separated from each
    // other by ampersands, and the individual names and values are
    // separated from each other by colons. We use the split(  ) method
    // to parse everything.
    var a = cookieval.split('&');    // Break it into an array of name/value pairs
    for(var i=0; i < a.length; i++)  // Break each pair into an array
        a[i] = a[i].split(':');

    // Now that we've parsed the cookie value, set all the names and values
    // of the state variables in this Cookie object. Note that we unescape(  )
    // the property value, because we called escape(  ) when we stored it.
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }

    // We're done, so return the success code
    return true;
}

// This function is the remove(  ) method of the Cookie object
Cookie.prototype.remove = function(  ) {
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

    this.$document.cookie = cookie;
    window.location.reload();
}



// Simulates PHP's date function
Date.prototype.format = function(format) {
	var returnStr = '';
	var replace = Date.replaceChars;
	for (var i = 0; i < format.length; i++) {
		var curChar = format.charAt(i);
		if (replace[curChar])
			returnStr += replace[curChar].call(this);
		else
			returnStr += curChar;
	}
	return returnStr;
};
Date.replaceChars = {
	shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
	longMonths: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
	shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
	longDays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
	
	// Day
	d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
	D: function() { return Date.replaceChars.shortDays[this.getDay()]; },
	j: function() { return this.getDate(); },
	l: function() { return Date.replaceChars.longDays[this.getDay()]; },
	N: function() { return this.getDay() + 1; },
	S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
	w: function() { return this.getDay(); },
	z: function() { return "Not Yet Supported"; },
	// Week
	W: function() { return "Not Yet Supported"; },
	// Month
	F: function() { return Date.replaceChars.longMonths[this.getMonth()]; },
	m: function() { return (this.getMonth() < 11 ? '0' : '') + (this.getMonth() + 1); },
	M: function() { return Date.replaceChars.shortMonths[this.getMonth()]; },
	n: function() { return this.getMonth() + 1; },
	t: function() { return "Not Yet Supported"; },
	// Year
	L: function() { return "Not Yet Supported"; },
	o: function() { return "Not Supported"; },
	Y: function() { return this.getFullYear(); },
	y: function() { return ('' + this.getFullYear()).substr(2); },
	// Time
	a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
	A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
	B: function() { return "Not Yet Supported"; },
	g: function() { return this.getHours() == 0 ? 12 : (this.getHours() > 12 ? this.getHours() - 12 : this.getHours()); },
	G: function() { return this.getHours(); },
	h: function() { return (this.getHours() < 10 || (12 < this.getHours() < 22) ? '0' : '') + (this.getHours() < 10 ? this.getHours() + 1 : this.getHours() - 12); },
	H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
	i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
	s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
	// Timezone
	e: function() { return "Not Yet Supported"; },
	I: function() { return "Not Supported"; },
	O: function() { return (this.getTimezoneOffset() < 0 ? '-' : '+') + (this.getTimezoneOffset() / 60 < 10 ? '0' : '') + (this.getTimezoneOffset() / 60) + '00'; },
	T: function() { return "Not Yet Supported"; },
	Z: function() { return this.getTimezoneOffset() * 60; },
	// Full Date/Time
	c: function() { return "Not Yet Supported"; },
	r: function() { return this.toString(); },
	U: function() { return this.getTime() / 1000; }
}





/*
 * date:	2002-12-13
 * info:	http://inspire.server101.com/js/xc/
 */

var xcNode = [];

function xcSet(m, c) {
	if ((document.getElementById && document.getElementById(m) != null) && document.createElement && (navigator.userAgent.indexOf('MSIE 5.2') == -1 || navigator.userAgent.indexOf('Mac') == -1)) {
	m = document.getElementById(m).getElementsByTagName('ul');
	var d, p, x, h, i, j;
	for (i = 0; i < m.length; i++) {
		d = m[i].getAttribute('id');
		if (d) {
			x = xcCtrl(d, c, 'x', '[+]', 'Show', m[i].getAttribute('title')+' (expand menu)');
			x = xcCtrl(d, c, 'c', '[-]', 'Hide', m[i].getAttribute('title')+' (collapse menu)');

			p = m[i].parentNode;
			if (h = !p.className) {
				j = 2;
				while ((h = !(d == arguments[j])) && (j++ < arguments.length));
				if (h) {
					m[i].style.display = 'none';
					x = xcNode[d+'x'];
				}
			}

			p.className = c;
			p.insertBefore(x, p.firstChild);
		}
	}
}
}


function xcShow(m) {
	xcXC(m, 'block', m+'c', m+'x');
}


function xcHide(m) {
	xcXC(m, 'none', m+'x', m+'c');
}


function xcXC(e, d, s, h) {
	e = document.getElementById(e);
	e.style.display = d;
	e.parentNode.replaceChild(xcNode[s], xcNode[h]);
	xcNode[s].firstChild.focus();
}


function xcCtrl(m, c, s, v, f, t) {
	var a = document.createElement('a');
	a.setAttribute('href', 'javascript:xc'+f+'(\''+m+'\');');
	a.setAttribute('title', t);
	a.appendChild(document.createTextNode(v));

	var d = document.createElement('div');
	d.className = c+s;
	d.appendChild(a);

	return xcNode[m+s] = d;
}



/**
 * Open XC nav to the correct node on DOMLoad.
 * No longer need xcSet on body tag, if the page title matches the nav2 link text the node will automatically be opened.
 * This script assumes that the page title is the contents of the first oxcConf.pageHeadingTag element to 
 * occur within the oxcConf.contentSectionSelector element. This will usually be the first h1 within the #content element
 * but can be configured for different markup below.
 * 
 * @since 27/11/2008
 * @return true if node was found and expanded, false if an error occurred.
 */
openXCToCurrentPage = function () {
	// config
		oxcConf = {
			contentSectionSelector : '#content, #contentStory',
			pageHeadingTag         : 'h2',
			xcNavId                : 'nav2xc',
			linkTag                : 'a',
			xcNodeTag              : 'ul'
		};
	
	// get heading text
		pageTitle = $.trim($(oxcConf.contentSectionSelector).eq(0).find(oxcConf.pageHeadingTag+':first').text());
		
	// get matching link elements from nav2
		$('#'+oxcConf.xcNavId+' '+oxcConf.linkTag).each(function(){
			if ($.trim($(this).text()) == pageTitle) {
				
				// find matching adjacent ul node
					nodeToExpand = $(this).next(oxcConf.xcNodeTag);
					if (nodeToExpand.size() == 0) {
						// no child menu for this page, find first parent ul node instead
							nodeToExpand = $(this).parents(oxcConf.xcNodeTag+':first');
							if (nodeToExpand.size() == 0) {
								// no ul node found to expand
									return false;
							}
					}
					
					if (typeof nodeToExpand.attr('id') == 'undefined') {
						debug('DEBUG: All xc "'+oxcConf.xcNodeTag+'" nodes must have a unique id');
						return false;
					}
					// expand xc to corrent node
						xcSet(oxcConf.xcNavId, 'xc', nodeToExpand.attr('id'));
						return true;
			}
		});
	
	// no nav2 link matching page title found
		return false;
};
debug = function (message) {
	if (typeof window.console != 'undefined') {
		window.console.log(message);
	} else {
		window.status = message;
	}
};
// On document load
	$(openXCToCurrentPage);


