
/*
 * Update the destination in the database so it 
 * doesn't show up in the destination tree.
 */
function markDestinationRemoved(destinationId)
{
    var request = newXMLHttpRequest();
    
    // No return values are handled.
    //var handler = getReadyStateHandler(request, onNewSubregionOptionList);    
    //request.onreadystatechange = handler;   
    
    var queryString = "?destinationId=" + destinationId;
    var url = getBaseURL() + "/MarkDestinationRemoved.do" + queryString;
    
    var asynchronous = true;
    request.open("GET", url, asynchronous);
    request.send(null);      
}

/*
 * Clear all destination ids from the list.
 */
function removeAllDestinationIds()
{
    destinationIdList.removeAll();
}

/*
 * Mark the destination for removal from display.
 */
function removeDestination(tableRowId, destinationId)
{
    // remove specified table row
    removeTableRow(tableRowId);
    
    // submit an AJAX request to update the destination's approval type
    markDestinationRemoved(destinationId);
}

/*
 * Remove the table row (with the input id) from the DOM document.
 */
function removeTableRow(tableRowId)
{
    var tableRow = document.getElementById(tableRowId);
    
    if (tableRow != null)
    {
        var tableRowParent = tableRow.parentNode;
        
        if (tableRowParent != null)
        {
            tableRowParent.removeChild(tableRow);
        }
    }
}

/*
 * Load the form and display the directions page.
 */
function showDirections()
{
    document.forms["DirectionsForm"].userDefinedAddressText.value = 
        document.forms["MapControlForm"].userDefinedAddress.value;
    
    // identify the destinations to be displayed
    document.forms["DirectionsForm"].destinationIdList.value = destinationIdList.toString();

    // submit the information to the directions page
    document.forms["DirectionsForm"].submit();
}

/*
 * Load the form and display the printable region page.
 */
function showPrintableRegion()
{
    // store map values for the printable map
    
    if (map != null)
    {
        var point = map.getCenter();
        document.forms["PrintableRegionForm"].mapCenterLatitude.value = point.lat();
        document.forms["PrintableRegionForm"].mapCenterLongitude.value = point.lng();    
        document.forms["PrintableRegionForm"].mapZoom.value = map.getZoom();
        document.forms["PrintableRegionForm"].userDefinedAddressText.value = 
            document.forms["MapControlForm"].userDefinedAddress.value;
    }
    
    // identify the destinations to be displayed
    document.forms["PrintableRegionForm"].destinationIdList.value = destinationIdList.toString();

    // submit the information to the printable map page
    document.forms["PrintableRegionForm"].submit();
}

/*
 * Add or remove the input id, depending on the clicked object state.
 */
function toggleDestinationId(clickedObject, id)
{
    var request = newXMLHttpRequest();
    var url = getBaseURL();
   
    if (clickedObjectStatesAddToMap(clickedObject))
    {   	
        destinationIdList.add(id);
        url += "/AddDestinationIdToSessionList.do";
    }
    else
    {
        destinationIdList.remove(id);
        url += "/RemoveDestinationIdFromSessionList.do";
    }
   
    var queryString = "?destinationId=" + id;
    url += queryString;
   
    var asynchronous = true;
    request.open("GET", url, asynchronous);
    request.send(null);     
} 

/*
 * Change the style of the destination list, depending on the checkbox state.
 */
function toggleScrollableList(checkbox)
{
   var treeFrameDiv = document.getElementById("TreeFrameDiv");

   if (checkbox != null && checkbox.checked)
   {   
      treeFrameDiv.setAttribute("class", "treeFrameScrollableDiv");     // Firefox
      treeFrameDiv.setAttribute("className", "treeFrameScrollableDiv"); // IE
   }
   else
   {
      treeFrameDiv.setAttribute("class", "treeFrameDiv");     // Firefox
      treeFrameDiv.setAttribute("className", "treeFrameDiv"); // IE
   }
} 

/*
 *
 */
function toggleShowHideText()
{
   anchor = document.getElementById("anchorShowHideStreetAddresses");
   
   if (anchor != null)
   {       
       if (anchor.innerHTML == "Show street addresses")
       {
           anchor.innerHTML = "Hide street addresses";
       }
       else
       {
           anchor.innerHTML = "Show street addresses";
       }           
   }
}
