function getStyle(oElm, strCssRule) {
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if(oElm.currentStyle){
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    return strValue;
}


function getHttpObject() {
   var xmlhttp;
   /*@cc_on
   
   @if (@_jscript_version >= 5) 
	   try {
	     xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch (e) {
	      try {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	      } catch (e) {
	        xmlhttp = false;
	      }
	   }
	@else
	  xmlhttp = false;
	@end @*/
	
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	   try {
	     xmlhttp = new XMLHttpRequest();
	   } catch (e) {
	     xmlhttp = false;
	   }
	}
	
	return xmlhttp;
}

var http = getHttpObject();

function showPopUp() {
  if (http.readyState == 4) {
    results = http.responseText.split(",");
    if (results[0] != "invalid") {
      strId = results[0];
      strShort = results[1];
      strLong = results[2];
      
      var bubble = document.getElementById("bubble");
      // set body //
      if(document.all){
         document.getElementById('bubble_mid').innerText = strShort;
      } else{
         document.getElementById('bubble_mid').textContent = strShort;
      }
      var hot = document.getElementById("hotspot_community_" + strId);
      var t = getStyle(hot, "top");
      var l = getStyle(hot, "left");
      bubble.style.top = (parseInt(t) - 40) + "px";
      bubble.style.left = (parseInt(l) - 2) + "px";
      
    }
  }
}

function OverSpot(spotId) {
   http.open("GET", "getPopInfo.php?id="+ spotId, true);
   http.onreadystatechange = showPopUp;
   http.send(null);
}



function checkMouseOver(evt) {
  var evt = (evt) ? evt : ((window.event) ? window.event : null);
  var objectID = (evt.target) ? evt.target.id : ((evt.srcElement) ?evt.srcElement.id : null);
  if (objectID.indexOf("hotspot_community") != -1) {
     var elem = document.getElementById(objectID);
     elem.style.cursor = "pointer";
     elem.style.cursor = "hand";
     strId = objectID.substring(objectID.lastIndexOf("_")+1, objectID.length);
     OverSpot(strId);
  }
  return;
}

function checkMouseOut(evt) {
  var evt = (evt) ? evt : ((window.event) ? window.event : null);
  var objectID = (evt.target) ? evt.target.id : ((evt.srcElement) ?evt.srcElement.id : null);
  if (objectID.indexOf("hotspot_community") != -1) {
     var bubble = document.getElementById("bubble");
     bubble.style.top = "-999px";
  }
  return;
}

function checkMouseClick(evt) {
  var evt = (evt) ? evt : ((window.event) ? window.event : null);
  var objectID = (evt.target) ? evt.target.id : ((evt.srcElement) ?evt.srcElement.id : null);
  if (objectID.indexOf("hotspot_community") != -1) {
     strId = objectID.substring(objectID.lastIndexOf("_")+1, objectID.length);
     window.location = "community_detail.php?id=" + strId;
  }
  return;
}







/* register events */
document.onmouseover = checkMouseOver;
document.onmouseout = checkMouseOut;
document.onclick = checkMouseClick;