

// request

function ajaxMap(globalMenuLinkId, menu, time, base) {

  // loading
	if (document.getElementById("imgMap")) document.getElementById("tdMap").innerHTML = '<span class="spanLoading">loading</span>';
	
	// reset temp (user can mouseover any dot)
  templogId = 0;
	
	// set vars
	var url  = 'ajax/ajaxMap.php';
	url     += "?menuLinkId="+globalMenuLinkId;
	url     += "&menu="+menu;
	url     += "&time="+time;
	url     += "&base="+base;

	// send request
	httpRequest("GET",url,1,mapResponse);
	
}

// response

var countUnique = 1;

function mapResponse() {
  if (request.readyState == 4) {
	  stopDots();
	  if (request.status == 200) {
      var mytext = request.responseText;
      if (mytext == 0) {
			  document.getElementById("tdMap").innerHTML = '';
        ajaxError("There was an error attempting to retrieve map data.");
			}
			else {
			
			  // ajax values
			  var a = mytext.indexOf('***');
			  var imageUrl = mytext.substr(0, a);
        var a = a + 3;
        var imageMap = mytext.substr(a);

				// set image map html
				var mapString  = '<map id="mapgrid'+countUnique+'" name="mapgrid'+countUnique+'">';
				mapString += imageMap;
				mapString += '</map>';
					
				document.getElementById("divImageMap").innerHTML = mapString;
					
				var tmp = new Date();
        var tmp = "?"+tmp.getTime();
					
				// insert image map and image html
			  if (!document.getElementById("imgMap")) {
				  document.getElementById("tdMap").innerHTML = '<img id="imgMap" src="'+imageUrl+tmp+'" alt="" usemap="#mapgrid'+countUnique+'" onload="hideLoading(\''+imageUrl+tmp+'\');" />';
				}
				
				// swamp image map and image content
				else {
					document.getElementById("imgMap").setAttribute("usemap", "#mapgrid"+countUnique);
			    document.getElementById("imgMap").src = imageUrl+tmp;
				}
				
				// increment image map id
				countUnique++;
				
		  }
		}
		else {
		  ajaxError("A communications problem occured attempting to retrieve map data.");
		}
  }
}

function setTdBackground(myid, url) {
  document.getElementById(myid).style.backgroundImage = "url("+url+")";
}

function hideLoading(url) {
  setTdBackground("tdMap", url);
}
