<!--

function overImg(id)
{
	if (document.getElementById(id) != null)
	{	
		obj = document.getElementById(id);	
		obj.src = '/img/' + id + '_in.gif';
		obj = document.getElementById('rateBuildingHeader');
		if (id == 'thumbup')
		{
			obj.innerHTML = "I like this building";
		}
		else
		{
			obj.innerHTML = "I don't like this building";
		}
	}		
}	
	
function outImg(id)
{	
		
	if (document.getElementById(id) != null)
	{	
		obj = document.getElementById(id);	
		obj.src = '/img/' + id + '.gif';
		obj = document.getElementById('rateBuildingHeader');	
		obj.innerHTML = "Rate this building";
	}		
}	


function ajaxFunction(rating, key)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) 
		{
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e)
			{
				// Something went wrong
				//alert("Error creating Ajax object!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			//alert(ajaxRequest.responseText);
			if (!parseResponse(ajaxRequest.responseText))
				;
		}
	}
	
	var queryString = "/functions/ajax/ratebuilding.htm?key=" + key + "&rate=" + rating;
	ajaxRequest.open("GET", queryString, true);
	ajaxRequest.send(null);
}


// Process ajax response
function parseResponse(response)
{
	if (response.length < 1) { return false; } 
	
	//Splits the response up in key pairs
  indx = 1;
	keypairs = new Object();
	while (response.indexOf('&') > -1)
	{
		keypairs[indx] = response.substring(0,response.indexOf('&'));
		response = response.substring((response.indexOf('&')) + 1);
		indx++;
	}
	//Go though key pairs
	for (indx in keypairs)
	{
		keyName = keypairs[indx].substring(0,keypairs[indx].indexOf('=')); // Left of '=' is name.
		keyValue = keypairs[indx].substring((keypairs[indx].indexOf('=')) + 1); // Right of '=' is value.
		processKeyPair(keyName, keyValue);
	}
	
	
	function processKeyPair(keyName, keyValue)
	{
		tag = keyName;
		txt = keyValue;
		switch (tag)
		{
			case 'up': 
				if (document.getElementById('cntBuildingRatedUp') != null)
					{	
						obj = document.getElementById('cntBuildingRatedUp');	
						obj.innerHTML = txt;
					}	
			break;
			
			case 'down': 
				if (document.getElementById('cntBuildingRatedDown') != null)
					{	
						obj = document.getElementById('cntBuildingRatedDown');	
						obj.innerHTML = txt;
					}	
			break;
			
			case 'rated':
				if (document.getElementById('rateBuildingHeader') != null)
					{	
						obj = document.getElementById('rateBuildingHeader');	
						obj.innerHTML = 'Thanks for rating!';
					}
				//Disable voting
				if (document.getElementById('imgRateBuildingUp') != null)
					{	
						obj = document.getElementById('imgRateBuildingUp');	
						action = 'off';
						if (txt == 'up') action = 'in';
						obj.innerHTML = "<img src=\"/img/thumbup_" + action + ".gif\" alt=\"Thumb up\" border=\"0\" width=\"28\" height=\"33\">";
					}
				if (document.getElementById('imgRateBuildingDown') != null)
					{	
						obj = document.getElementById('imgRateBuildingDown');	
						action = 'off';
						if (txt == 'down') action = 'in';
						obj.innerHTML = "<img src=\"/img/thumbdown_" + action + ".gif\" alt=\"Thumb up\" border=\"0\" width=\"28\" height=\"33\">";
					}
				
				
				break;
			
			case 'message': 
				if (txt == 'err')
				{
					if (document.getElementById('buildingRating') != null)
					{	
						obj = document.getElementById('buildingRating');	
						obj.innerHTML = 'sorry, an unexpected error occurred';
					}		
					alert('sorry, an unexpected error occurred');
				}
				else
				alert(txt);
			break;
		}
	}
}


//-->