
var defaultZip = "85001";
//Default ZipCodes within Maricopa Cities

var MaricopaCities = {
	Aguila: 85320, Anthem: 85087	,"Apache Junction": 85217	,Arlington: 85322	,Avondale: 85323
	,Buckeye: 85326
	,Carefree: 85377 ,Cashion: 85329 ,"Cave Creek": 85327	,Chandler: 85224
	,"Desert Hills" : 85086	
	,"El Mirage" : 85335	
	,"Fort McDowell": 85264
	,"Fountain Hills": 85269
	,"Gila Bend": 85337	,Gilbert: 85233	,Glendale: 85307, Goodyear: 85395 ,Guadalupe: 85283
	,Higley: 85236
	,Laveen: 85339	,"Litchfield Park": 85340	,"Luke AFB": 85309
	,Mesa: 85201
	,"New River": 85087
	,"Palo Verde": 85343	,"Paradise Valley": 85253	,Peoria: 85345, Phoenix: 85001
	,"Queen Creek": 85240
	,"Rio Verde": 85263
	,Scottsdale: 85250	,"Sun City": 85351	,"Sun City West": 85375	,Surprise: 85374
	,Tempe: 85280	,Tolleson: 85353	,Tonopah: 85354	,"Tortilla Flat": 85290
	,Waddell: 85355	,Wickenburg: 85390
	,Youngtown: 85363
};

var offTimeOut = null;

function PrintablePage() {
	if (location.href.indexOf("XmlTemplate") == -1) {
	    location.href = location.href + '?XmlTemplate=/Templates/PrintTemplate.xml'
	}
}

function PrintablePage() {
	if (location.href.indexOf("XmlTemplate") == -1) {
	    location.href = location.href + '?XmlTemplate=/Templates/PrintTemplate.xml'
	}
}

function MenuOn(object,object2){
		
		var IE = document.all?true:false
		
		// Begin hiding of page elements that have a higher z-index than the menus
		select = document.all.tags("select");
		selectCount = select.length;
		if (selectCount > 0) {for (i=0;i<selectCount;i++) {select.item(i).style.visibility = 'hidden';}}
		
		applets = document.all.tags("applet");
		appletCount = applets.length;
		if (appletCount > 0) {for (i=0;i<appletCount;i++) {applets.item(i).style.visibility = 'hidden';}}
		
		objects = document.all.tags("object");
		objectsCount = objects.length;
		if (objectsCount > 0) {for (i=0;i<objectsCount;i++) {objects.item(i).style.visibility = 'hidden';}}
		// End hiding of page elements that have a higher z-index than the menus
		
		// Begin Menu Positioning Based on Mouse Position 
		
				var IE = document.all?true:false
				if (!IE) document.captureEvents(Event.MOUSEMOVE)
				//document.onmousemove = getMouseXY;
				var tempX = 0
				var tempY = 0
				
				function getMouseXY(e) {
					if (IE) { // grab the x-y pos.s if browser is IE
						tempX = event.clientX + document.body.scrollLeft
						tempY = event.clientY + document.body.scrollTop
					} else {  // grab the x-y pos.s if browser is NS
						tempX = e.pageX
						tempY = e.pageY
					}  
					// catch possible negative values in NS4
					if (tempX < 0){tempX = 0}
					if (tempY < 0){tempY = 0}  
					// show the position values in the form named Show
					// in the text fields named MouseX and MouseY
				
								if (document.getElementById && document.getElementById(object) != null){
										if(document.getElementById(object).style.visibility == 'hidden'){
											document.getElementById(object).style.top = tempY;
											document.getElementById(object).style.left = tempX-35;
										}
									}
								else if (document.layers && document.layers[object] != null){
										if(document.layers[object].visibility == 'hidden'){
											document.layers[object].top = tempY;
											document.layers[object].left = tempX-35;
										}
									}
								else if (document.all && document.all['DepartmentMenu'] != null){
										if(document.all[object].style.visibility == 'hidden'){
											document.all[object].style.top = tempY;
											document.all[object].style.left = tempX-35;
										}
									}
				
					//document.Show.MouseX.value = tempX
					//document.Show.MouseY.value = tempY
					return true
				}
		
		
		//   End Menu Positioning Based on Mouse Position
		
	if (document.getElementById && document.getElementById(object) != null){
				document.getElementById(object2).style.visibility = 'hidden';
				document.getElementById(object).style.visibility = 'visible';
		}
    else if (document.layers && document.layers[object] != null){
				document.layers[object2].visibility = 'hidden';
				document.layers[object].visibility = 'visible';
		}
    else if (document.all && document.all['DepartmentMenu'] != null){
				document.all[object2].style.visibility = 'hidden';
				document.all[object].style.visibility = 'visible';
		}
	
}
function MenuOff(){
   // window.clearTimeout(offTimeOut);
	if (document.getElementById && document.getElementById('DepartmentMenu') != null){
		document.getElementById('DepartmentMenu').style.visibility = 'hidden';
		document.getElementById('ServiceMenu').style.visibility = 'hidden';
		}
    else if (document.layers && document.layers['DepartmentMenu'] != null){
        document.layers['DepartmentMenu'].visibility = 'hidden';
        document.layers['ServiceMenu'].visibility = 'hidden';
		}
    else if (document.all && document.all['DepartmentMenu'] != null){
        document.all['DepartmentMenu'].style.visibility = 'hidden';
        document.all['ServiceMenu'].style.visibility = 'hidden';
		}
	
		// Begin reshowing of page elements that have a higher z-index than the menus
		select = document.all.tags("select");
		selectCount = select.length;
		if (selectCount > 0) {for (i=0;i<selectCount;i++) {select.item(i).style.visibility = 'visible';}}
		
		applets = document.all.tags("applet");
		appletCount = applets.length;
		if (appletCount > 0) {for (i=0;i<appletCount;i++) {applets.item(i).style.visibility = 'visible';}}
		
		objects = document.all.tags("object");
		objectsCount = objects.length;
		if (objectsCount > 0) {for (i=0;i<objectsCount;i++) {objects.item(i).style.visibility = 'visible';}}
		// End reshowing of page elements that have a higher z-index than the menus
}
function MousedOut() {
	if (!document.getElementById("DepartmentMenu").contains(event.toElement) && !document.getElementById("ServiceMenu").contains(event.toElement)){
		//offTimeOut = window.setTimeout("MenuOff()",500);
		MenuOff();
	}
}
function clearLMTO() {
		clearTimeout(timeoutFlag);
}
//if(document.getElementById('DepartmentMenu') != null || document.layers['DepartmentMenu'] != null || document.all['DepartmentMenu'] != null){
//document.onclick = MenuOff;
//}
var newwindow = null
function PopWindow(url,intHeight,intWidth) {
		newwindow = window.open(url,"feedback","toolbar=no,location=no,dependent=yes,resizable=no,alwaysRaised=yes,scrollbars=yes,directories=no,height=" + intHeight + ",width=" + intWidth + "");
		if (newwindow !=null) {
			var strWidth = screen.availWidth/2 - intWidth/2;
			var strHeight = screen.availHeight/2 - intHeight/2;
			newwindow.moveTo(strWidth,strHeight);
			newwindow.focus();
		}
}

//BEGIN HIGHLIGHTING

var google_text_color = '#000000';
var google_link_colors = new Array('#ffff66','#a0ffff','#99ff99','#ff9999','#ff66ff');

function init_google(){
	var pattern = /google\./i;
	//alert(pattern.exec(document.referrer));
	//if (pattern.exec(document.referrer) != null){
		var url_parts = document.location.href.split('?');
		if (url_parts[1]){ 
			var url_args = url_parts[1].split('&');
			for(var i=0; i<url_args.length; i++){
				var keyval = url_args[i].split('=');
				if (keyval[0] == 'q'){
					go_google(decode_url(keyval[1]));
					return;
				}
			}
		}
	//}
}

function decode_url(url){
	return unescape(url.replace(/\+/g,' '));
}

function go_google(terms){
	terms = terms.replace(/\"/g,"");
	var terms_split = terms.split(' ');
	var c = 0;
	for(var i=0; i<terms_split.length; i++){
		highlight_goolge(terms_split[i], document.body,google_link_colors[c]);
		c = (c == google_link_colors.length-1)?0:c+1;
	}
}

function highlight_goolge(term, container, color){
	var term_low = term.toLowerCase();

	for(var i=0; i<container.childNodes.length; i++){
		var node = container.childNodes[i];

		if (node.nodeType == 3){
			var data = node.data;
			var data_low = data.toLowerCase();
			if (data_low.indexOf(term_low) != -1){
				//term found!
				var new_node = document.createElement('SPAN');
				node.parentNode.replaceChild(new_node,node);
				var result;
				while((result = data_low.indexOf(term_low)) != -1){
					new_node.appendChild(document.createTextNode(data.substr(0,result)));
					new_node.appendChild(create_node_google(document.createTextNode(data.substr(result,term.length)),color));
					data = data.substr(result + term.length);
					data_low = data_low.substr(result + term.length);
				}
				new_node.appendChild(document.createTextNode(data));
			}
		}else{
			//recurse
			highlight_goolge(term, node, color);
		}
	}
}

function create_node_google(child, color){
	var node = document.createElement('SPAN');
	node.style.backgroundColor = color;
	node.style.color = google_text_color;
	node.appendChild(child);
	return node;
}
//END HIGHLIGHTING

var newwindow = null
			
function popWindow() {
newwindow = window.open("","pop","toolbar=yes, location=yes, resizable=yes, scrollbars=yes, width=700, height=450")
} 

//EgovCookie class 
function JSEgovCookie(name) { 
	this.Name = name;
	this.City = "Phoenix";
	this.Language = "en";
	this.Zip = "85001";
}
//Declare EgovCookie Properties and Methods
JSEgovCookie.prototype.CongressonalDistrict = null;
JSEgovCookie.prototype.JusticeOfThePeace = null;
JSEgovCookie.prototype.LegislativeDistrict = null;
JSEgovCookie.prototype.Regions = null;
JSEgovCookie.prototype.SchoolDistrict = null;
JSEgovCookie.prototype.StreetDir = null;
JSEgovCookie.prototype.StreetName = null;
JSEgovCookie.prototype.StreetNum = null;
JSEgovCookie.prototype.StreetSuffix = null;
JSEgovCookie.prototype.StreetType = null;
JSEgovCookie.prototype.SupervisorDistrict = null;
JSEgovCookie.prototype.VotingPrecinctName = null;

//Class for NameValue pairs
function Item(name, value) { 
	this.Name = name;
	this.Value = value;
}

//overrides the test method to check for equality
Item.prototype.test = function(obj) {
	if (obj["Name"] != null) { 
		if (obj["Name"].toUpperCase() == this.Name.toUpperCase()) return true;
	}
	return false;
};

//Extend the Array Object.
Array.prototype.Find = function(searchStr) {
	var result = null;
	for ( var i = 0; i < this.length; i++) {
		if (typeof(searchStr) == 'function' || typeof(searchStr) == "object") {
			if (searchStr.test(this[i])) {
				if (!result) result = [];
				result.push(this[i]);
			}
		} else if (this[i] === searchStr){
				if (!result) result = [];
				result.push(this[i]);
		}
	}
	return result;
}

//Static Class for reading and processing cookies
var CookieHelper = {
	ReadCookie: function(cookieName) {

		if (cookieName == null || cookieName == "") return;

		var cookie = "" + document.cookie;
		var idx1 = cookie.indexOf(cookieName);

		if (idx1 == -1) return "";
		var idx2 = cookie.indexOf(";", idx1);
		return unescape(cookie.substring(idx1 + cookieName.length + 1, idx2));
	}
	, ToObject: function(obj, cookieStr) {
		if (obj == null || cookieStr == null || cookieStr == "") return null;
		var tokens = new Array();
		tokens = cookieStr.split("&");

		if (tokens == null || tokens.length == 0) return;

		var idx1 = -1;

		var result;
		for (var prop in obj) {
			result = this._findCookieToken(tokens, prop.toString());
			if (result != null) {
				obj[prop] = result.substring(result.indexOf("=") + 1);
			}
		}

		return obj;
	}
	, _findCookieToken: function(array, searchStr) {
		var el;
		var idx;
		for (var i = 0; i < array.length; i++) {
			idx = array[i].indexOf("=");
			if (idx > -1) {
				el = array[i].substring(0, idx);
				if (el.toUpperCase() == searchStr.toUpperCase()) { 
					return array[i];
				}
			}
		}
		return null;
	}
}

//QueryString instance class
function QueryString(queryString) { 
	this.Items = new Array();
	this._getItems = function(qry) { 
		if (qry == null || qry == "") qry = document.location.search;
		if (qry == null || qry == "") return null;

		var pairs = qry.substring(1);
		if (pairs == null) return null;

		var tokens = pairs.split("&");

		if (tokens == null || tokens.length == 0) return null;

		this.Items = new Array();

		var item;
		var name;
		var value;
		var idx1 = -1;
		var idx2 = -1;
		for (var i = 0; i < tokens.length; i++) {
			idx1 = tokens[i].indexOf("=");
			if (idx1 > -1) {
				name = null;
				value = null;
				name = tokens[i].substring(0, idx1);
				if (tokens[i].length > idx1 + 1) {
					value = tokens[i].substring(idx1 + 1);
				}
				if (name != null) {
					this.Items.push(new Item(name, value));
				}
			}
		}
	}//End _getItems function

	this.GetItem = function(name) { 
			if (name == null || name == "") return null;
			return this.Items.Find(new Item(name,null));
	}
	
	this._getItems(queryString);
}//End QueryString function

