	var request = false;
	try {
    	request = new XMLHttpRequest();
   	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
     	} catch (othermicrosoft) {
       		try {
         	request = new ActiveXObject("Microsoft.XMLHTTP");
       		} catch (failed) {
         		request = false;
       		}  
     	}
	}
	
	if (!request)
		alert("Error initializing XMLHttpRequest!");

	function getCityState() {
		var zipcode = document.getElementById("czipcode").value;
		if (zipcode.length > 0) {  
			var url = "/scripts/zipcode.cfm?zipcode=" + escape(zipcode);
			request.open("GET", url, true);
			request.onreadystatechange = updatePage;
			document.getElementById("exec").style.visibility = "visible";
			request.send(null);
		}
	}

	function updatePage() {
		if (request.readyState == 4) {
			document.getElementById("exec").style.visibility = "hidden";
			if (request.status == 200) {
				var response = request.responseText.split("|");
				document.getElementById("vcity").value = response[0];
				document.getElementById("cstate").value = response[1];
			} else
			//alert("status is " + request.status);
			alert("Invalid zipcode.");
		}
	}
	
	function getCity(searchString,inp,id) {
		var sugItems = document.getElementById(id);
		if(searchString.length > 0) {
			// request cities.cfm passing searchString as an URL parameter
			var url = "/scripts/cities.cfm?city=" + escape(searchString);
			request.open("GET", url, true);
			document.getElementById("exec").style.visibility = "visible";
			request.send(null);
			// gives the request object an event handler
			request.onreadystatechange = function() {
				if ((request.readyState == 4) && (request.status == 200)) {
					document.getElementById("exec").style.visibility = "hidden";
					// creates an array from returned list
					var arr = request.responseText.split('|');
					if ((arr.length) && (request.responseText.length)) {
						// formats array as an HTML table and shows the DIV
						sugItems.innerHTML = htmlFormat(arr,inp,id);
						sugItems.style.display = 'block';
					}
					// No items found? Hides the DIV
					//else sugItems.style.display = 'none';
					else {
						sugItems.innerHTML = htmlNoMatch("No matches found");
						sugItems.style.display = 'block';
					}
					return;
				}
			}
		}
		// Empty searchString? Hides the DIV
		else sugItems.style.display = 'none';
		return;
	}
	
	function htmlFormat(arr,inp,id) {
		// formats arr as an HTML table
		var output = '<table class="light">';
		for (var i=0;i<arr.length;i++) {
			output = output + '<tr onclick="getData(this,\'' + inp + '\',\'' + id + '\');">' + '<td width=230 bgcolor=#ffffff onmouseover="this.style.backgroundColor=\'#66ccff\'; this.style.cursor=\'pointer\';" onmouseout="this.style.backgroundColor=\'#ffffff\';">' + arr[i] + '</td>' + '</tr>';
		}
		output = output + '</table>';
		return output;
	}
	
	function htmlNoMatch(txt) {
		// formats arr as an HTML table
		var output = '<table class="light">';
		output = output + '<tr>' + '<td width=230 bgcolor=#ffffff onmouseover="this.style.backgroundColor=\'#66ccff\'; this.style.cursor=\'pointer\';" onmouseout="this.style.backgroundColor=\'#ffffff\';">' + txt + '</td>' + '</tr>';
		output = output + '</table>';
		return output;
	}
	
	function getData(obj,inp,id) {
		// finds all TDs inside obj
		var arrTD = obj.getElementsByTagName('TD');
		// assigns TD value to form field
		//document.getElementById('vcity').value = arrTD[0].innerHTML.split(" - ")[0];
		document.getElementById(inp).value = arrTD[0].innerHTML;
		// hides the DIV
		document.getElementById(id).style.display = 'none';
	}

	function hidediv() {
		document.getElementById(id).style.display = 'none';	
	}

	function getRating(name,rating) {
		//alert(name + ";" + rating);
		// request rating.cfm passing vars as URL parameters
		var url = "/scripts/rating.cfm?n=" + name + "&r=" + rating;
		//alert(url);
		request.open("GET", url, true);
		request.send(null);
		// gives the request object an event handler
		request.onreadystatechange = function() {
			if ((request.readyState == 4) && (request.status == 200)) {
				if (request.responseText.length) {
					//alert(request.responseText);
					var RatRes = document.getElementById('RatingResult');
					var NumericValue = parseFloat( request.responseText );
					RatRes.innerHTML = "Average Rating: " + NumericValue.toFixed(1)
				}
				else {
					RatRes.innerHTML = "There was an error rating this item."
				}
				return;
			}
		}
		return;
	}
