
var origAddress;
var origCity;
var origZip;
var theValue;
var theMessage;
var theAddress;

var isIE = false;
		if (navigator.userAgent.indexOf('MSIE') > -1) {
			isIE = true;
		}
// Initialize the temporary Panel to display while waiting for external content to load
YAHOO.wait = 
		new YAHOO.widget.Panel("wait",  
			{ width:"240px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:4,
			  modal:true,
			  visible:false
			} 
		);

YAHOO.wait.setHeader("Loading, please wait...");
YAHOO.wait.setBody('<img src="images/rel_interstitial_loading.gif" />');
YAHOO.wait.render(document.body);

// Initialize the temporary Panel to display while waiting for external content to load
YAHOO.result = 
		new YAHOO.widget.Panel("result",  
			{ width:"240px", 
			  fixedcenter:true, 
			  close:false, 
			  draggable:false, 
			  zindex:4,
			  modal:true,
			  visible:false,
			  close: true
			} 
		);

	var directorCallBack = {
		success:function(transaction) {
			
			resetDists();
			var directorResults = transaction.responseText;

			var dirHtml = '';
			//debug alert below
			//alert("got a response " +transaction.responseText);
			try {
				var dirJSON = YAHOO.lang.JSON.parse(directorResults);
			} catch (e) {
				dirHtml = 'The director lookup service is currently unavailable';
			}
			//alert(dirJSON.value);
			if (dirJSON.value != "") {
				theValue = dirJSON.value;
				// check if the address was found outside of the district
				if (dirJSON.value == null) {
					YAHOO.result.setHeader("District search results");
					YAHOO.result.setBody("Address found outside of the district");
					YAHOO.result.render(document.body);
					YAHOO.result.show();
					YAHOO.wait.hide();
				}
			} 
			//alert(dirJSON.message);
			if (dirJSON.message != "") {
				var theMessage = dirJSON.message;
				// see if the address could not be found.
				if (theMessage == "Address Could Not Be Located") {
					YAHOO.result.setHeader("District search results");
					YAHOO.result.setBody(theMessage);
					YAHOO.result.render(document.body);
					YAHOO.result.show();
					YAHOO.wait.hide();
				}
			}
			//alert(dirJSON.address);
			if (dirJSON.address != "") {
				var theAddress = dirJSON.address;
			}
			
			var theDirCell = document.getElementById("dist"+theValue);
			theDirCell.className = "myDirector";
			
			document.getElementById("text"+theValue).style.fontWeight = "bold";
			var anchor = '#anchor'+theValue;
			window.location.hash = anchor;
			
			YAHOO.result.setHeader("District search results");
			YAHOO.result.setBody("This address is located in District " + theValue + "\n"
								 + theAddress);
			YAHOO.result.render(document.body);
			YAHOO.result.show();
			YAHOO.wait.hide();
		},
		failure : function(transaction) {

			content.innerHTML = transaction.responseText;

			//content.innerHTML = "CONNECTION FAILED!";
			YAHOO.wait.hide();
		}
	}



function getTheDirector(address, city, zip) {
	origAddress = address;
	origCity = city;
	origZip = zip;
	makeDirCall(address, city,zip);
}

function resetDists() {
	// reset dist a - o
	document.getElementById("distA").className = "sideBoxTable";
	document.getElementById("distB").className = "sideBoxTable";
	document.getElementById("distC").className = "sideBoxTable";
	document.getElementById("distD").className = "sideBoxTable";
	document.getElementById("distE").className = "sideBoxTable";
	document.getElementById("distF").className = "sideBoxTable";
	document.getElementById("distG").className = "sideBoxTable";
	document.getElementById("distH").className = "sideBoxTable";
	document.getElementById("distI").className = "sideBoxTable";
	document.getElementById("distJ").className = "sideBoxTable";
	document.getElementById("distK").className = "sideBoxTable";
	document.getElementById("distL").className = "sideBoxTable";
	document.getElementById("distM").className = "sideBoxTable";
	document.getElementById("distN").className = "sideBoxTable";
	document.getElementById("distO").className = "sideBoxTable";
	
	document.getElementById("textA").style.fontWeight = "normal";
	document.getElementById("textB").style.fontWeight = "normal";
	document.getElementById("textC").style.fontWeight = "normal";
	document.getElementById("textD").style.fontWeight = "normal";
	document.getElementById("textE").style.fontWeight = "normal";
	document.getElementById("textF").style.fontWeight = "normal";
	document.getElementById("textG").style.fontWeight = "normal";
	document.getElementById("textH").style.fontWeight = "normal";
	document.getElementById("textI").style.fontWeight = "normal";
	document.getElementById("textJ").style.fontWeight = "normal";
	document.getElementById("textK").style.fontWeight = "normal";
	document.getElementById("textL").style.fontWeight = "normal";
	document.getElementById("textM").style.fontWeight = "normal";
	document.getElementById("textN").style.fontWeight = "normal";
	document.getElementById("textO").style.fontWeight = "normal";
	
	// clear form inputs
	document.getElementById('address').value = "";
	document.getElementById('city').value = "";
	document.getElementById('zip').value = "";
	//clear out the values of the previous serach if there were any
	anchor = '';
	theValue = '';
}

function makeDirCall(address, city, zip) {
	var transaction = YAHOO.util.Connect.asyncRequest('GET', '/elbert/WhoIsMyDirector/directorSearch.cfm?address='+address+'&city='+city+'&zip='+zip, directorCallBack, null);
	//var transaction = YAHOO.util.Connect.asyncRequest('GET', 'http://localhost:8080/WhoIsMyDirector/directorSearch.cfm?address=12985%20Jasmine%20Crt&city=Thornton&zip=80602', directorCallBack, null);
	//var transaction = YAHOO.util.Connect.asyncRequest('GET', '/elbert/WhoIsMyDirector/directorSearch.cfm?address='+address+'&city='+city+'&zip='+zip, directorCallBack, null);
	// Show the Panel
	YAHOO.wait.show();
}



