﻿// AJAX Request Business Information PopUp

//getXmlHttpRequestObject() gets the right request object based on client browser
function getXmlHttpRequestObject() 
{
    if (window.XMLHttpRequest) 
        {		
            return new XMLHttpRequest(); //Not IE	
        } 
        else if(window.ActiveXObject) 
        {	
            return new ActiveXObject("Microsoft.XMLHTTP"); //IE
        } 
        else 
        {		
            //Display your error message here. 			
            alert("Your browser doesn't support the XmlHttpRequest object.  Better upgrade to IE7.");	
        }
}

//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();

//Called every time our XmlHttpRequest objects state changes.
function handlePopUp() 
{	
    //Check to see if the XmlHttpRequests state is finished.	
    if (receiveReq.readyState == 4) 
    {		
        //Set the contents of our span element to the result of the asyncronous call.		
        //document.getElementById('popUpDisplay').innerHTML = receiveReq.responseText;
//        var myOutput = document.getElementById('popUpDisplay');
//        var mySpan = document.createElement('span');
//        mySpan.innerHtml = receiveReq.responseText;
//        myOutput.appendChild(mySpan);

        var returnHtml = receiveReq.responseText;
        var myOutput = document.getElementById('popUpDisplay');
        myOutput.innerHTML = returnHtml;
    }
}

//Legacy PopUp Information
function displayPopUp(x)
{
    //Set Page TO Get
    var strPage = "/maps/popup.aspx?id=" + x;


    //Get Web Information
    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
        receiveReq.open("GET", strPage, true);			
        receiveReq.onreadystatechange = handlePopUp; 		
        receiveReq.send(null);
    }
    
    //Postion Window
    var objDiv = document.getElementById("building" + x);
    var objWindow = document.getElementById('popUpDisplay');
    
    //Find Div X,Y
    var divx = objDiv.style.left;
    var divy = objDiv.style.top;
    
    //Find Div Size
    var div_w = objDiv.style.width; 
    var div_h = objDiv.style.height;
       
    divx = parseInt(divx.replace("px", ""));
    divy = parseInt(divy.replace("px", ""));
    div_w = parseInt(div_w.replace("px", ""));
    div_h = parseInt(div_h.replace("px", ""));
    
    var new_x = divx; 
    var new_y = divy - 85;
 
    //Unhide Popup
    objWindow.style.display = "block";
    
    //Set Location
    //1. Check Up
    if (new_y <= min_y)
    {
        new_y = divy + div_h + 5;
    }
    
    //2. Check Right
    if ((new_x + 200) >= max_x)
    {
        new_x = new_x - 205;
        new_y = divy;
    }
    
    //3. Check Bottom
    if ((new_y + 80) >= max_y)
    {
        new_y = divy - 85;
    }
    
    objWindow.style.left = new_x + "px";
    objWindow.style.top = new_y + "px";
}

function hidePopUp(x)
{
    var myOutput = document.getElementById('popUpDisplay');
    myOutput.style.display = "none";
    myOutput.innerHTML = "";
    
}
