// Search place name functionality using CGNS data.
function searchPlaceName()
{
    document.getElementById("imgLoadingPlacename").style.display = "";

    // Comment out the following line for Apache port forwarding to handle the request.
    // This avoids the cross-domain issue.
    var url = "./jsp/processCGNS.jsp?placename=" + document.getElementById("txtPlaceName").value + "&lang=" + strLang;

    // Create a new XML HTTP object for AJAX operation.
    var oTempXmlHttp = getNewXmlHTTPObject();

    // Call the server side code to process the place name results.
    // The "oXmlHTTP" object is from the xmlHTTP.js file. When the eval operation
    // occurs, it needs this object to retrieve the response. Thiss allows the code to be asyncronis
    if (!isXmlHTTPNull(oTempXmlHttp))
        doXMLRequest(oTempXmlHttp, url, "post", true, "processCGNSResponse(oXmlHTTP.responseText)", "document.getElementById('imgLoadingPlacename').style.display = 'none'");

    oTempXmlHttp = null;
}

// Process the CGNS xml data.
function processCGNSResponse(pObjResponse)
{
    var strHtml = pObjResponse;

    // Check to see if there are any results returned.
    if (strHtml.replace(/\r\n/g, "").length > 0)
        createDivZoomToPlaceName(strHtml);
    else
        createDivZoomToPlaceName("No matching results");

    document.getElementById("imgLoadingPlacename").style.display = "none";
}

function createDivZoomToPlaceName(pHtml)
{
    var divZoomToPlaceName = document.createElement("div");

    // Remove the div if exists already.
    removeDiv("divPlaceNameResults");

    divZoomToPlaceName.id = "divPlaceNameResults";
    divZoomToPlaceName.name = "divPlaceNameResults";

    divZoomToPlaceName.className = "placeNameResults";

    divZoomToPlaceName.style.left = "38%";
    divZoomToPlaceName.style.top = document.getElementById("txtPlaceName").offsetParent.offsetTop + "px";

    strHtml = "<div style='float: right; padding-left: 5px'>";
    strHtml = strHtml + createCloseButton("onclick", "closePlaceNameResults()");
    strHtml = strHtml + "</div>";
    strHtml = strHtml + "<div class='placeNameResultsContents'>" + pHtml + "</div>";

    divZoomToPlaceName.innerHTML = strHtml;

    document.body.appendChild(divZoomToPlaceName);
}

function closePlaceNameResults()
{
    removeDiv("divPlaceNameResults");
}

// Reset place name.
function clearPlaceName()
{
    document.getElementById("txtPlaceName").value = "";

    // Remove the div.
    removeDiv("divPlaceNameResults");
}

function zoomToPlaceName(pLat, pLng, pZoom)
{
    // Clear the filter text.
    if (highlightCharts.length > 0)
        clearFilterText();

    // Set the center and zoom of the map.
    oGMap.setCenter(new GLatLng(pLat, pLng), pZoom);

    // Remove the div.
    removeDiv("divPlaceNameResults");
}