var map;
var map_s;
var didClickStar = false;
var defaultWhat = "Keyword, Name, Phone or Address";
var defaultWhere = "City, County or Zip";

window.onscroll = reposition;

//Pre-load things
var preLoadImages = new Array("/images/star_big_off.png", 
							  "/images/star_big_n.png", 
							  "/images/star_off.png", 
							  "/images/star_on.png",
							  "/images/layout/home/0/people_on.png",
							  "/images/layout/home/1/people_on.png",
							  "/images/layout/home/2/people_on.png",
							  "/images/layout/home/3/people_on.png",
							  "/images/layout/home/4/people_on.png",
							  "/images/layout/home/5/people_on.png",
							  "/images/layout/home/0/business_off.png",
							  "/images/layout/home/1/business_off.png",
							  "/images/layout/home/2/business_off.png",
							  "/images/layout/home/3/business_off.png",
							  "/images/layout/home/4/business_off.png",
							  "/images/layout/home/5/business_off.png");

for (i = 0; i < preLoadImages.length; i++)
{
	preload_image = new Image(25,25); 
	preload_image.src = preLoadImages[i];
}

function clearField(domid)
{
	var dom = document.getElementById(domid);
	if (domid == "what" && dom.value == defaultWhat)
	{
		dom.value = "";
	}
	else if (domid == "where" && dom.value == defaultWhere)
	{
		dom.value = "";
	}
}

function showField(domid)
{
	var dom = document.getElementById(domid);
	if (dom.value == "")
	{
		if (domid == "what")
		{
			dom.value = defaultWhat;
		}
		else if (domid == "where")
		{
			dom.value = defaultWhere;
		}	
	}
}

function addComment(id, adid)
{
	var comments = document.getElementById('proofComments').value;
	var domid = document.getElementById('proofView');
	var ajaxRequest = getAjaxRequest();
	var queryString = "?id=" + id + "&adid=" + adid + "&comments=" + escape(comments);
	ajaxRequest.open("GET", "/users/update-proof.php" + queryString, false);
	ajaxRequest.send(null);
	domid.innerHTML = ajaxRequest.responseText;
	Effect.Appear(domid, { duration: 0.25 });
}

function approveAd(id, adid)
{
	alert("Thank you, your ad is now approved and the corrections will be made if necessary");
	addComment(id, adid)
}

function showProof(id, adid)
{
	var domid = document.getElementById('proofView');
	
	var ajaxRequest = getAjaxRequest();
	var queryString = "?id=" + id + "&adid=" + adid;
	ajaxRequest.onreadystatechange = function ()
									 {
										if(ajaxRequest.readyState == 4)
										{
											domid.style.display = "none";
											domid.innerHTML = ajaxRequest.responseText;
											Effect.Appear(domid, { duration: 0.25 });
										}
									 }
	ajaxRequest.open("GET", "/users/get-proof.php" + queryString, true);
	ajaxRequest.send(null);
	
	domid.style.display = "none";
	domid.innerHTML = "<img src=\"/images/ajax-loading.gif\" title=\"Loading...\" alt=\"Loading...\" />";
	Effect.Appear(domid, { duration: 0.25 });
}

function updateMetaData(id, column, isCheckBox)
{
	var value = "";
	if (isCheckBox)
	{
		value = document.getElementById(column).checked ? "1" : "0";
	}
	else
	{
		value = document.getElementById(column).value;
	}
	
	var ajaxRequest = getAjaxRequest();
	var queryString = "?id=" + id + "&column=" + column + "&value=" + value;
	ajaxRequest.open("GET", "/users/update-metadata.php" + queryString, false);
	ajaxRequest.send(null);
}

function showFaceBook(domid, name)
{
	var div = document.getElementById(domid);
	if (div.innerHTML == "")
	{
		//If there's nothing there then let's get it...
		var ajaxRequest = getAjaxRequest();
		var queryString = "?name=" + name;
		ajaxRequest.onreadystatechange = function ()
										 {
											if(ajaxRequest.readyState == 4)
											{
												//Show the data
												div.innerHTML = formatFaceBookResult(ajaxRequest.responseText, domid);
												Effect.SlideDown(domid, { duration: 0.5 });
											}
										 }
		ajaxRequest.open("GET", "/search/facebook.php" + queryString, true);
		ajaxRequest.send(null);
		
		//Show a status bar while we wait for the data to come back
		div.innerHTML = "<div align=\"center\"><img src=\"/images/ajax-loading.gif\" title=\"Loading...\" alt=\"Loading...\" /></div>";
		div.style.display = "block";
	}
	else if (div.style.display == "none")
	{
		//If there's already something in the div and it's hidden, then just show it instead of getting the data again...
		Effect.SlideDown(domid, { duration: 0.5 });
	}
}

function formatFaceBookResult(dataStr, domid)
{
	var data = eval('(' + dataStr + ')');
			
	var result = "<div class=\"faceBookSnapInTitle\">" +
					"<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">" +
						"<tr>" +
							"<td align=\"left\" class=\"faceBookSnapInTitleText\">Facebook Results</td>" +
							"<td align=\"right\"><a href=\"javascript:hideFaceBook('" + domid + "')\" class=\"faceBookSnapInTitleText\" />Hide</a></td>" +
						"</tr>" +
					"</table>" +
				"</div><div class=\"facebookSnapIn\">";
	
	if (data.data.length > 0)
	{
		result += "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100%\">";

		for (i = 0; i < data.data.length; i++)
		{
			var name = data.data[i].name;
			var id = data.data[i].id;
			var url = "http://www.facebook.com/profile.php?id=" + id
			
			if (i % 3 == 0)
			{
				if (i > 0)
				{
					result += "</tr>";
				}
				result += "<tr valign=\"middle\">";
			}
			
			
			result += "<td>" +
							"<a href=\"" + url + "\" target=\"_blank\"><img src=\"https://graph.facebook.com/" + id + "/picture\"/></a>" +
							"<a href=\"" + url + "\" target=\"_blank\" class=\"faceBookSnapInLink\">" + name + "</a>" +
					  "</td>";
		}
		result += "</tr></table>";
	}
	else
	{
		result += "No results found...";
	}
	
	result += "</div>"
	
	return result;
}

function hideFaceBook(domid)
{
	Effect.SlideUp(domid, { duration: 0.5 });
}


function addReview(domid, businessid)
{
	var result = "<div style=\"padding:4px\"><textarea class=\"reviewCommentBox\" rows=\"4\" cols=\"20\" id=\"" + domid + "_comment\" /></textarea><br>" +
				 "<span class=\"addRating\">Name:</span> <input class=\"reviewNameBox\" type=\"text\" size=\"10\" maxlength=\"32\" id=\"" + domid + "_name\" />" +
				 "&nbsp;<input class=\"reviewSubmitButton\" type=\"button\" value=\"Submit\" onclick=\"doAddReview('" + domid + "','" + businessid + "')\" />" +
				 "&nbsp;<input class=\"reviewSubmitButton\" type=\"button\" value=\"Cancel\" onclick=\"cancelReview('" + domid + "')\" /></div>";
	
	var reviewEntryDiv = document.getElementById(domid);
	
	reviewEntryDiv.style.display = "none";
	reviewEntryDiv.innerHTML = result;
	Effect.SlideDown(reviewEntryDiv, { duration: 0.25 });
}

function cancelReview(domid)
{
	var reviewEntryDiv = document.getElementById(domid);
	Effect.SlideUp(reviewEntryDiv, { duration: 0.25 });
	//reviewEntryDiv.innerHTML = "";
}

function doAddReview(domid, businessid)
{
	var reviewDiv = document.getElementById(domid);
	var reviewName = document.getElementById(domid + "_name").value;
	var reviewComment = document.getElementById(domid + "_comment").value;
	
	if (reviewName != "" && reviewComment != "")
	{	
		reviewName = escape(reviewName);
		reviewComment = escape(reviewComment);
		
		var ajaxRequest = getAjaxRequest();
		var queryString = "?businessid=" + businessid + "&name=" + reviewName + "&comment=" + reviewComment + "&limit=10";
		ajaxRequest.onreadystatechange = function ()
										 {
											if(ajaxRequest.readyState == 4)
											{
												var containerDivId = businessid + "_review_reviews";
												var containerDiv = document.getElementById(containerDivId);
												containerDiv.innerHTML = ajaxRequest.responseText;
												Effect.SlideDown(containerDiv, { duration: 0.5 });
											}
										 }
		ajaxRequest.open("GET", "/search/add-review.php" + queryString, true);
		ajaxRequest.send(null);
		
		//reviewDiv.style.display = "none";
		//reviewDiv.innerHTML = "<div class=\"addRating\" align=\"center\">Thank you!</div>";
		//Effect.Appear(reviewDiv, { duration: 0.25 });
	}
	else
	{
		alert("Please enter your comments and your name!");
	}
}

function addRating(domid, businessid)
{
	if (!didClickStar)
	{
		document.getElementById(domid).innerHTML = getStars(domid, businessid, 0);
	}
}

function hoverStars(domid, businessid, star)
{
	if (!didClickStar)
	{
		document.getElementById(domid).innerHTML = getStars(domid, businessid, star);
	}
}

function clickStar(domid, businessid, star)
{
	didClickStar = true;
	var ratingDiv = document.getElementById(domid);
	
	var ajaxRequest = getAjaxRequest();
	var queryString = "?businessid=" + businessid + "&star=" + star;
	ajaxRequest.onreadystatechange = function ()
									 {
										if (ajaxRequest.readyState == 4)
										{
											ratingDiv.style.display = "none";
											ratingDiv.innerHTML = ajaxRequest.responseText;
											Effect.Appear(ratingDiv, { duration: 0.25 });
											didClickStar = false;
										}
									 }
	ajaxRequest.open("GET", "/search/update-rating.php" + queryString, true);
	ajaxRequest.send(null);
	
	//if (didClickStar)
	//{
		//ratingDiv.style.display = "none";
		//ratingDiv.innerHTML = "<div class=\"addRating\">Thank you!</div>";
		//Effect.Appear(ratingDiv, { duration: 0.25 });
	//}
}

function getStars(domid, businessid, star)
{
	var result = "<div style=\"padding:4px\" onmouseout=\"addRating('" + domid + "','" + businessid + "')\" >" +
				 "<span class=\"star\" onmouseup=\"clickStar('" + domid + "','" + businessid + "','1')\" onmouseover=\"hoverStars('" + domid + "','" + businessid + "','1')\" ><img src=\"/images/star_big_" + (star >= 1 ? "on" : "off") + ".png\" /></span>" +
			     "<span class=\"star\" onmouseup=\"clickStar('" + domid + "','" + businessid + "','2')\" onmouseover=\"hoverStars('" + domid + "','" + businessid + "','2')\" ><img src=\"/images/star_big_" + (star >= 2 ? "on" : "off") + ".png\" /></span>" +
			     "<span class=\"star\" onmouseup=\"clickStar('" + domid + "','" + businessid + "','3')\" onmouseover=\"hoverStars('" + domid + "','" + businessid + "','3')\" ><img src=\"/images/star_big_" + (star >= 3 ? "on" : "off") + ".png\" /></span>" +
			     "<span class=\"star\" onmouseup=\"clickStar('" + domid + "','" + businessid + "','4')\" onmouseover=\"hoverStars('" + domid + "','" + businessid + "','4')\" ><img src=\"/images/star_big_" + (star >= 4 ? "on" : "off") + ".png\" /></span>" + 
			     "<span class=\"star\" onmouseup=\"clickStar('" + domid + "','" + businessid + "','5')\" onmouseover=\"hoverStars('" + domid + "','" + businessid + "','5')\" ><img src=\"/images/star_big_" + (star >= 5 ? "on" : "off") + ".png\" /></span>" + 
			     "</div>";
	return result;
}

function newsScroll(newsid)
{
	var newsDiv = document.getElementById('news');
	var ajaxRequest = getAjaxRequest();
	var queryString = "?newsid=" + newsid;
	ajaxRequest.open("GET", "/search/get-news.php" + queryString, false);
	ajaxRequest.send(null);
	newsDiv.style.display = "none";
	newsDiv.innerHTML = ajaxRequest.responseText;
	Effect.Appear(newsDiv, { duration: 0.25 });
}

function showMapTab(tab)
{
	var mapDiv = document.getElementById('sideBarMap');
	var headingDiv = document.getElementById('sideBarOtherHeadings');
	var cityDiv = document.getElementById('sideBarCities');
	var mapTab = document.getElementById('mapTab');
	var cityTab = document.getElementById('cityTab');
	var headingTab = document.getElementById('headingTab');

	if (tab == "map")
	{
		headingDiv.style.display = "none";
		cityDiv.style.display = "none";
		Effect.SlideDown(mapDiv, { duration: 0.25 });
		mapTab.className = "mapToolBarTabOn";
		cityTab.className = "mapToolBarTabOff";
		headingTab.className = "mapToolBarTabOff";
	}
	else if (tab == "cities")
	{
		mapDiv.style.display = "none";
		headingDiv.style.display = "none";
		Effect.SlideDown(cityDiv, { duration: 0.25 });
		mapTab.className = "mapToolBarTabOff";
		cityTab.className = "mapToolBarTabOn";
		headingTab.className = "mapToolBarTabOff";
	}
	else if (tab == "headings")
	{
		mapDiv.style.display = "none";
		cityDiv.style.display = "none";
		Effect.SlideDown(headingDiv, { duration: 0.25 });
		mapTab.className = "mapToolBarTabOff";
		cityTab.className = "mapToolBarTabOff";
		headingTab.className = "mapToolBarTabOn";
	}
}

function hideProfile(domid)
{
	Effect.SlideUp(domid, { duration: 0.5 });
}

function showProfile(domid, businessid, where, whatUnclean)
{
	var div = document.getElementById(domid);
	if (div.innerHTML == "")
	{
		//If there's nothing there then let's get it...
		var ajaxRequest = getAjaxRequest();
		var queryString = "?businessid=" + businessid + "&where=" + where + "&domid=" + domid + "&what=" + whatUnclean;
		ajaxRequest.onreadystatechange = function ()
										 {
											if(ajaxRequest.readyState == 4)
											{
												//Show the data
												div.innerHTML = ajaxRequest.responseText;
												Effect.SlideDown(domid, { duration: 0.5 });
											}
										 }
		ajaxRequest.open("GET", "/search/search-profile-snapin.php" + queryString, true);
		ajaxRequest.send(null);
		
		//Show a status bar while we wait for the data to come back
		//div.innerHTML = "<div align=\"center\"><img src=\"/images/ajax-loading.gif\" title=\"Loading...\" alt=\"Loading...\" /></div>";
		//div.style.display = "block";
	}
	else if (div.style.display == "none")
	{
		//If there's already something in the div and it's hidden, then just show it instead of getting the data again...
		Effect.SlideDown(domid, { duration: 0.5 });
	}
}


function onSearchTab(tab, photo)
{
	if (tab == "business")
	{
		document.getElementById('searchbox-business-tab').innerHTML = "<img src=\"/images/layout/home/" + photo + "/business_on.png\" title=\"Search For a Business\" alt=\"Search For a Business\" class=\"searchbox-tab\" onclick=\"onSearchTab('business','" + photo + "')\" />";
		document.getElementById('searchbox-person-tab').innerHTML = "<img src=\"/images/layout/searchbox/people_off.png\" title=\"Search For a Person\" alt=\"Search For a Person\" class=\"searchbox-tab\" onclick=\"onSearchTab('person','" + photo + "')\" />";
		document.getElementById('searchbox').innerHTML = getSearchBox(tab, photo);
	}	
	else if (tab == "person")
	{
		document.getElementById('searchbox-business-tab').innerHTML = "<img src=\"/images/layout/searchbox/business_off.png\" title=\"Search For a Business\" alt=\"Search For a Business\" class=\"searchbox-tab\" onclick=\"onSearchTab('business','" + photo + "')\" />";
		document.getElementById('searchbox-person-tab').innerHTML = "<img src=\"/images/layout/home/" + photo + "/people_on.png\" title=\"Search For a Person\" alt=\"Search For a Person\" class=\"searchbox-tab\" onclick=\"onSearchTab('person','" + photo + "')\" />";
		document.getElementById('searchbox').innerHTML = getSearchBox(tab, photo);
	}

}


//This code mirrors the HTML on search-user-interface.php
function getSearchBox(mode, photo)
{
	var currentWhatValue = document.getElementById('what').value;
	var currentWhereValue = document.getElementById('where').value;
	
	var result = "<form method=\"post\">" +
					"<input type=\"hidden\" id=\"type\" name=\"type\" value=\"" + mode + "\" />" +
					"<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\" width=\"100\">" +
						"<tr>" +
							"<td class=\"searchbox-text-big\" align=\"left\">" +
								(mode == "business" ? "What" : "Who") +
							"</td>" +
							"<td class=\"searchbox-text-big\" align=\"left\">" +
								"Where" +
							"</td>" +
							"<td>" +
							"</td>" +
						"</tr>" +
						"<tr valign=\"middle\">" +
							"<td width=\"50%\">" +
								"<input type=\"text\" size=\"16\" id=\"what\" name=\"what\" class=\"searchbox-field\" onFocus=\"clearField('what')\" onBlur=\"showField('what')\" value=\"" + currentWhatValue + "\" />" +
							"</td>" +
							"<td width=\"50%\">" +
								"<input type=\"text\" size=\"16\" id=\"where\" name=\"where\" class=\"searchbox-field\" onFocus=\"clearField('where')\" onBlur=\"showField('where')\" value=\"" + currentWhereValue + "\" >" +
							"</td>" +
							"<td width=\"0%\">" +
								"<button type=\"submit\" class=\"searchbox-button\"><img src=\"/images/layout/home/" + photo + "/search-button.png\" border=\"0\" /></button>" +
							"</td>" +
						"</tr>" +
					"</table>" +
				"</form>";
	return result;
}

function reposition()
{
	var el = document.getElementById('mapSideBar');
	if (el != null)
	{
		var ScrollTop = document.body.scrollTop;
		if (ScrollTop == 0) {
			if (window.pageYOffset) 
				ScrollTop = window.pageYOffset;
			else 
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
		}
		if (ScrollTop > 257) 
		{
			el.style.top = (ScrollTop + 10) + "px";
		}
		else 
		{
			el.style.top = "257px";
		}
	}
}

function focusPin(lat, lng, searchResultsId)
{
	m = getMap(searchResultsId);
	if (m)
	{
		var point = new GLatLng(lat, lng);
		m.panTo(point);
	}
}

function getMap(searchResultsId)
{
	return map;
	
	if (searchResultsId == 1)
	{
		return map;
	}
	else
	{
		return map_s;
	}
}

function initialize(points, doPinMouseOverScroll)
{	
	map = new GMap2(document.getElementById("map_p"));
	map.setCenter(new GLatLng(35.121032, -120.600357), 13);
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	addPoints(map, points, true, doPinMouseOverScroll);
	/*if (secondaryPoints != undefined && secondaryPoints != "")
	{
		map_s = new GMap2(document.getElementById("map_s"));
		map_s.setCenter(new GLatLng(48.44086024724348, -122.33493089675903), 13);
		map_s.addControl(new GSmallMapControl());
		map_s.addControl(new GMapTypeControl());
		addPoints(map_s, secondaryPoints, true);
	}*/
}

function addPoints(map, points, moveToPoint, doPinMouseOverScroll)
{
	var pinpoints = eval('(' + points + ')');
	if (pinpoints.length > 0) 
	{
		var centroidX = 0;
		var centroidY = 0;
		for (var i = 0; i < pinpoints.length; i++) 
		{
			//Dither the points so they aren't always stacked on top of each other...
			var lat = pinpoints[i][0] + ((Math.random() - .5) / 10000);
			var lng = pinpoints[i][1] + ((Math.random() - .5) / 10000);
			addPin(map, lat, lng, pinpoints[i][2], pinpoints[i][3], doPinMouseOverScroll);
			
			centroidX += parseFloat(pinpoints[i][0]);
			centroidY += parseFloat(pinpoints[i][1]);
		}
		
		centroidX = centroidX / pinpoints.length;
		centroidY = centroidY / pinpoints.length;
		
		if (moveToPoint)
		{
			var point = new GLatLng(pinpoints[0][0], pinpoints[0][1]);
			map.panTo(point);
		}
	}
}

function addPin(map, lat, lng, i, domid, doPinMouseOverScroll)
{
	var marker = createMarker(new GLatLng(lat, lng), i, domid, doPinMouseOverScroll);
	map.addOverlay(marker);
}

function createMarker(point, index, domid, doPinMouseOverScroll)
{						
	// Create a base icon for all of our markers that specifies the
	// shadow, icon dimensions, etc.
	var baseIcon = new GIcon(G_DEFAULT_ICON);
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(12, 34);

	var letteredIcon = new GIcon(baseIcon);
	letteredIcon.image = "http://www.citybooks.com/images/pins/" + index + ".png";
	markerOptions = { icon:letteredIcon };
	var marker = new GMarker(point, markerOptions);

	GEvent.addListener(marker, "mouseover", function() { document.getElementById(domid).setAttribute("class", "listing-on"); if (doPinMouseOverScroll) { window.location = "#" + domid + "_anchor"; } });
	GEvent.addListener(marker, "mouseout", function() { document.getElementById(domid).setAttribute("class", "listing-off"); });
	
	//We'll just display what's in the listings in the baloon - keep it simple :)
	var divWithContent = document.getElementById(domid);
	if (divWithContent != null)
	{
		var content = document.getElementById(domid).innerHTML;
		//We need to take out the onclick and onmouseover handlers
		//Just replace the handlers. It won't make sense in JavaScript/HTML, but that's OK...
		content = content.replace(/onclick/g, "nop");
		content = content.replace(/onmouseover/g, "nop");
		var baloon = "<div style=\"width:220px\">" + content + "</div>";
		
		GEvent.addListener(marker, "click", function() {
	        marker.openInfoWindowHtml(baloon);
	    });
	}
		
	return marker;
}

function loadAds(domid, ads, id)
{
	var element = document.getElementById(domid);
	if (element.style.display == "none")
	{
		if (element.innerHTML == "")
		{
			var adids = "[" + ads + "]";
			adids = eval('(' + adids + ')');
			var result = "<div id=\"" + id + "_showAd\">" + getAdImage(adids[0], id, 350) + "</div>";
			if (adids.length > 1) 
			{
				result += "<hr><div class=\"adStrip\" align=\"center\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\"><tr>";
				for (i = 0; i < adids.length; i++) 
				{
					result += "<td align=\"center\"><img src=\"" + getAdURL(adids[i], id) + "\" width=\"75\" style=\"cursor:pointer\" onclick=\"showAd('" + adids[i] + "','" + id + "')\" /></td>";
				}
				result += "</tr></table></div>";
			}
			
			element.innerHTML = result;
		}	
		element.style.display = "none";
		//Effect.BlindDown(domid, {duration: .5});
		Effect.Grow(domid, {direction: 'top-right'});
		document.getElementById(domid + "_header").innerHTML = "Hide Ads";
	}
	else
	{
		//Effect.BlindUp(domid, {duration: .5});
		Effect.Shrink(domid, {direction: 'bottom-left'});
		document.getElementById(domid + "_header").innerHTML = "View Ads";
	}
}

function getAdImage(adid, id, width)
{
	var adUrl = getAdURL(adid, id);
	return "<a href=\"" + adUrl + "\" target=\"_blank\"><img src=\"" + adUrl + "\" width=\"" + width + "\" border=\"0\"/></a>";
}

function getAdURL(adid, id)
{
	return "/ads-archive/" + id + "/" + adid + ".jpg";
}

function showAd(adid, id, domid)
{
	
	if (domid == "undefined")
	{
		domid = id + "_showAd";
	}
	//Effect.BlindUp(domid, { duration: .25 });
	document.getElementById(domid).style.display = "none";
	document.getElementById(domid).innerHTML = getAdImage(adid, id, 350);
	Effect.BlindDown(domid, { duration: .25 });
}

/*	var ajaxRequest = getAjaxRequest();
	queryString = "?name=" + name;
	ajaxRequest.open("GET", "/yellowiki/name/name-insert.php" + queryString, false); //synchronous call
	ajaxRequest.send(null);
	*/

// Create a function that will receive data sent from the server
function getDataFunc(divid, ajaxRequest, doAppend)
{
	return function(){
				if(ajaxRequest.readyState == 4)
				{
					var ajaxDisplay = document.getElementById(divid);
					if (doAppend)
					{
						ajaxDisplay.innerHTML += ajaxRequest.responseText;
					}
					else
					{
						ajaxDisplay.innerHTML = ajaxRequest.responseText;	
					}
				}
			}	
}

function getAjaxRequest()
{
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		return ajaxRequest;
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			return ajaxRequest;
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				return ajaxRequest;
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	return false;
}
