

/* ----- OLD CHANGE PAGE AJAX CODE ----- */
function change_page(url, id) {
	var http_request=false;

	if (window.XMLHttpRequest) {http_request = new XMLHttpRequest();}
	else if (window.ActiveXObject) {
		try {http_request = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e) {http_request= new ActiveXObject("Microsoft.XMLHTTP");}
		}

	if (!http_request) {
		alert("This page requires Ajax functionality. Supported Broswers include: IE5, IE6, IE7, Firefox 1, Firfox 2, Safari, Opera, Maxthon, Flock, Camino, Konqueror or any browser made after 2000."); 
		return false;
		}

	http_request.onreadystatechange = function () {
		if (http_request.readyState==4) {
			document.getElementById(id).innerHTML='';
			document.getElementById(id).innerHTML=http_request.responseText;
			}
		}
	http_request.open('GET', url, true);
	http_request.send(null);
	}




/* ----- TOGGLE LISTS ----- */
function toggle(element) {
	image_element=element.childNodes[0];
	menu_element=element.parentNode.parentNode;
	if (window.ActiveXObject) {menu_element=menu_element.childNodes[1];}
	else {menu_element=menu_element.childNodes[2];}
	
	if (menu_element.style.display=="none" || menu_element.style.display=="" ) {
		menu_element.style.display="block";
		image_element.src="images/list_open.png";
		}
	else {
		menu_element.style.display="none";
		image_element.src="images/list_closed.png";
		}
	}




/* ----- HIDE THE STATE BOX AND SHOW THE MAP OF MEXICO ----- */
function close_state() {
	document.getElementById('state_box').style.display = "none";
	document.getElementById('map').style.display = "block";
	}




/* ----- HIDE THE MAP OF MEXICO AND LOAD A STATE ----- */
function load_state(state) {
	var http_request=false;

	try {http_request = new XMLHttpRequest();}
	catch(e) {
		try {http_request = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e) {http_request= new ActiveXObject("Microsoft.XMLHTTP");}
		}

	if (!http_request) {
		alert("This page requires Ajax functionality. Supported Broswers include: IE5, IE6, IE7, Firefox 1, Firfox 2, Safari, Opera, Maxthon, Flock, Camino, Konqueror or any browser made after 2000."); 
		return false;
		}
	
	http_request.onreadystatechange = function () {
		if (http_request.readyState==4) {
			if (http_request.responseText != "") {
				// Hide the map of Mexico
				document.getElementById('map').style.display = "none";
				document.getElementById('city').style.display = "none";
				
				// Show to box with the state in it, put the state image in it, and clear the city list
				document.getElementById('state_box').style.display = "block";
				document.getElementById('state').innerHTML = "<img src='images/" + state.toLowerCase() + ".png' alt='" + state + "' />";
				document.getElementById('city').innerHTML = "";
				
				// Add the city icons to the map
				cities = http_request.responseText.split('\n');

				for (var i=0; i < cities.length; i++) {
					if (cities[i].length >3) {

						var vars = cities[i].split("/");
						var city_name=vars[0];
						var city = vars[0].replace(/ /g, "");
						
						var x = vars[1];
						var y = vars[2].replace(",", "");
						
						
						// Create the city icons
						var newImageBox = document.createElement('div');
						newImageBox.setAttribute("id", city+"_iconbox");
						document.getElementById('state').appendChild(newImageBox);
						
						document.getElementById(city+"_iconbox").style.position="absolute"; 
						document.getElementById(city+"_iconbox").style.right = (document.getElementById('state').offsetWidth - x - 10) + "px";
						document.getElementById(city+"_iconbox").style.top = y + "px";
						document.getElementById(city+"_iconbox").style.cursor = "pointer";
						
						document.getElementById(city+"_iconbox").innerHTML="<img src='images/building.png' alt='" + city + "' id='" + city + "_icon' onkeypress='get_buildings(\""+city+"_iconbox\", \"" +state+"\", \""+city+"\")'  onfocus=\"document.getElementById('" + city + "_label').style.display = 'block' \"  onblur=\"document.getElementById('" + city + "_label').style.display = 'none' \" onmouseup='get_buildings(\""+city+"_iconbox\", \"" +state+"\", \""+city+"\")'  onmouseover=\"document.getElementById('" + city + "_label').style.display = 'block' \"  onmouseout=\"document.getElementById('" + city + "_label').style.display = 'none' \" />";
						document.getElementById(city+"_iconbox").style.display="block";
						document.getElementById(city+"_iconbox").childNodes[0].display="block";
						
						// Create the label icon
						var newBox = document.createElement('div');
						newBox.setAttribute("id", city + "_label");
						document.getElementById('state').appendChild(newBox);
						
						newBox.innerHTML = city_name;
						
						document.getElementById(city + "_label").style.position = "absolute";
						document.getElementById(city + "_label").style.right = (document.getElementById('state').offsetWidth - x + 20) + "px";
						document.getElementById(city + "_label").style.top =  y + "px";
						
						document.getElementById(city + "_label").style.display = "none"; 
						document.getElementById(city + "_label").style.backgroundColor = "#dda"; 
						document.getElementById(city + "_label").style.color = "black"; 
						document.getElementById(city + "_label").style.padding = "5px;";
						
						
						// newBox.setAttribute("style", "right: " + (newImage.parentNode.offsetWidth - x + 20) + "px; top: " + y + "px;");
						// newImage.style.right  = document.getElementById('state').offsetWidth - x - 10 + "px;";
						}
					}
				}
			}
		}
	var url = 'pages/get_state.php?state='+state;
	http_request.open('GET', url, true);
	http_request.send(null);
	}




/* ------ SHOW / HIDE CITY / STATE LABELS ----- */
function show_label(id) {document.getElementById(id).style.display="block";}
function hide_label(id) {document.getElementById(id).style.display="none";}




/* ----- CREATE BUILDING LINKS FOR A CITY ----- */
function get_buildings(box_id, state, city) {
	var http_request=false;
	
	try {http_request = new ActiveXObject("Msxml2.XMLHTTP");}
	catch(e) {
		try {http_request= new ActiveXObject("Microsoft.XMLHTTP");}
		catch(e) {http_request = new XMLHttpRequest();}
		}
	
	if (!http_request) {
		alert("This page requires Ajax functionality. Supported Broswers include: IE5, IE6, IE7, Firefox 1, Firefox 2, Safari, Opera, Maxthon, Flock, Camino, Konqueror or any browser made after 2000."); 
		return false;
		}
	
	http_request.onreadystatechange = function () {
		if (http_request.readyState==4) {
			var boxRight = parseInt(document.getElementById(box_id).style.right.replace("px", ""));
			var boxTop = document.getElementById(box_id).style.top.replace("px", "");
			
			document.getElementById('city').style.top = boxTop + "px";
			document.getElementById('city').style.display = "block";
			document.getElementById('city').style.width = "210px";			
			document.getElementById('city').style.marginLeft = (650 - boxRight + 5) + "px";
			document.getElementById('city').innerHTML = http_request.responseText;
			}
		}
	
	var url = 'pages/get_city.php?state=' + state + '&city=' + city;
	http_request.open('GET', url, true);
	http_request.send(null);
	}







