function showHint(hintId)
{
	document.getElementById(hintId).style.display = "inline-block";
}

function hideHint(hintId)
{
	document.getElementById(hintId).style.display = "none";
}

function xmlHttpFactory()
{
	try
	{
		// Firefox, Opera 8.0+, Safari, IE 7+
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		// older browsers
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				return false;
			}
		}
	}
	return xmlHttp;
}

function processContactSubmission()
{	
	// get the xmlHttpRequest object
	xmlHttp = xmlHttpFactory();
	uip = document.getElementById('userInteractionPoint');
	xmlHttp.onreadystatechange=function()
	{
		if (xmlHttp.readyState==1)
		{
			
			uip.innerHTML = "<p>Sending...</p>";
		}
		if (xmlHttp.readyState==4)
		{
			if (xmlHttp.status == 200)
			{
				try
				{
					response = eval("(" + xmlHttp.responseText + ")");
					message = response.html;
					uip.innerHTML = "<p>" + message + "</p>";
				}
				catch (e)
				{
					alert('A technical problem occurred.  Please contact me by phone!');
				}
			}
		}
	}
	// set the important variables for the xmlHttpRequest
	url = "index.php?section=contact&ajaxRequest=processContactSubmission";
	name = encodeURIComponent(document.getElementById("contactForm-name").value);
	phone = encodeURIComponent(document.getElementById("contactForm-phone").value);
	params = "name="+name+"&phone="+phone;
	
	// run the xmlHttpRequest
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
}

function loadGoogleMap()
{
	ajaxRequest = xmlHttpFactory();
	ajaxRequest.open("GET", "index.php?section=contact&ajaxRequest=contactInfoAsJson", false);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajaxRequest.setRequestHeader("Connection", "close");
	ajaxRequest.send(null);
	contact = eval("("+ajaxRequest.responseText+")");
	if (GBrowserIsCompatible())
	{
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(35.9175, -79.0357), 13);
		infoWindowHtml = '<address>'+contact.name+'<br />'+contact.address1+'<br />'+contact.city+', '+contact.state+' '+contact.zip+'<br /></address><p><a href="http://maps.google.com/maps?f=d&hl=en&saddr=&daddr='+encodeURIComponent(contact.address1)+','+encodeURIComponent(contact.city)+','+encodeURIComponent(contact.state)+','+encodeURIComponent(contact.zip)+'&ie=UTF8&z=15&om=1&iwloc=addr">Get directions</a></p>';
		marker = new GMarker(new GLatLng(35.9175, -79.0357));
		marker.bindInfoWindowHtml(infoWindowHtml);
		map.addOverlay(marker);
		marker.openInfoWindow(infoWindowHtml);
		window.setTimeout(function()
		{
			map.zoomIn();
		}, 2000);
		window.setTimeout(function()
		{
			map.zoomIn();
			map.addControl(new GSmallZoomControl());
			map.addControl(new GMapTypeControl());
		}, 3500);
		map.disableDragging();
	}
}

function GetPublication(id)
{
	ajax = xmlHttpFactory();
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState == 1)
		{
			// loading
		}
		if (ajax.readyState == 4)
		{
			// received response
			if (ajax.status == 200)
			{ // 200 OK
				response = eval("(" + ajax.responseText + ")");
				if (response.publication)
				{
					document.getElementById('EditPublication').scrollIntoView();
					document.getElementById('EditPublication').getElementsByTagName('ol')[0].className = '';
					chooser = document.getElementById('EditPublication-chooser')
					for (i in chooser.options)
					{
						try
						{
							if(chooser.options[i].value == id)
							{
								chooser.selectedIndex = chooser.options[i].index;
								break;
							}
						}
						catch (e)
						{
							continue;
						}
					}
					for (i in response.publication)
					{
						try
						{
							document.getElementById('EditPublication-'+i).value = response.publication[i];
						}
						catch (e)
						{
							continue;
						}
					}
				}
				else if (response.error)
				{
					alert(response.error);
				}
				else alert(response);
			}
			else alert("There was a problem:\n" + ajax.resonseText);
		}
	}
	// set the important variables for the xmlHttpRequest
	pId = encodeURIComponent(id);
	url = "index.php?section=honorsAndPublications&ajaxRequest=getPublicationById&id="+pId;
	
	// run the xmlHttpRequest
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
