﻿$(function() {
	$("#accordian-nav").ul_quickNav({
		menu_width: '237',
		menu_height: 'auto',
		menu_margin: '0',
		menu_text_size: '11',
		menu_text_color: '#fff',
		menu_background_color: 'transparent',
		menu_border_size: '0',
		menu_border_color: 'transparent',
		menu_border_style: 'none',
		menu_background_hover_color: 'transparent',
		directory: 'images'
	});
});

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function SubmitOnEnter(myfield, e) {
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;
	if (keycode == 13)
	{
		SearchSite();
		return false;
	}
	else
		return true;
}

function SearchSite() {
	document.location.href='http://www.water.wa.gov.au/Search+results/default.aspx?q=' + URLEncode(document.getElementById('q').value);
}

function inputFocus() {
	document.getElementById('query-input').style['background'] = '';
}

function inputBlur() {
	var queryInput = document.getElementById('query-input');
	if (!queryInput.value) {
		queryInput.style['background'] =
			'white url(http://www.google.com/coop/images/'
			+ 'google_custom_search_watermark.gif) no-repeat 0% 50%';
	}
}

function init() {
	google.search.CustomSearchControl.attachAutoCompletion(
		'004903818199354613481:vw2jpldij_k',document.getElementById('query-input'),'two-page-form');
	inputBlur();
}

function submitQuery() {
	window.location = '/Search+results/default.aspx?q='
		+ encodeURIComponent(document.getElementById('query-input').value);
	return false;
}

