// Search place name functionality using CGNS data.
function doSearchPlaceName(pStrError)
{
    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 strUrl = "./jsp/processCGNS.jsp";
    var strUrlParams = "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))
    {
        logMsg("Performing placename search. url: " + encodeURIComponent(strUrl + "?" + strUrlParams), "info", "sliderZoomToPlaceName.js (doSearchPlaceName)");
        doXMLRequest(oTempXmlHttp, strUrl, strUrlParams, "post", true, "application/x-www-form-urlencoded", "processCGNSResponse(pObjXmlHTTP.responseText, '" + pStrError + "')", "document.getElementById('imgLoadingPlacename').style.display = 'none'");
    }

    oTempXmlHttp = null;
}

// Process the CGNS xml data.
function processCGNSResponse(pObjResponse, pStrError)
{
    var strHtml = pObjResponse;

    // Check to see if there are any results returned.
    if (strHtml.replace(/\r\n/g, "").trim().length > 0)
    {
        strDivHtml = "<div style='float: right; padding-left: 5px'>";
        strDivHtml = strDivHtml + createCloseButton("onclick", "removePopUp(&quot;divPlaceNameResultsPopUp&quot;)");
        strDivHtml = strDivHtml + "<\/div>";
        strDivHtml = strDivHtml + "<div class='placeNameResultsContents'>" + strHtml + "<\/div>";

        // Create a div containing the results.
        var objDivPlaceNamePopUp = createDivPopUp(null, strDivHtml, "divPlaceNameResultsPopUp", "popUpPlaceNameResults", false, false)

        // Position the div.
        centerObjectWithin(objDivPlaceNamePopUp, (document.body || window));
    }
    else
        alert(pStrError);

    document.getElementById("imgLoadingPlacename").style.display = "none";
}

// Reset place name.
function clearPlaceName()
{
    document.getElementById("txtPlaceName").value = "";

    // Remove the div.
    removePopUp("divPlaceNameResultsPopUp");
}

function zoomToPlaceName(pNumLat, pNumLon, pNumScale)
{
    // Set the center and zoom of the map.
    doSetCenter(pNumLon, pNumLat, pNumScale);

    // Remove the div.
    removePopUp("divPlaceNameResultsPopUp");
}
