// **************************************************************************************************
/*
// used for the tree selection of habitats on the layers tab
function selectHabitat() {

  var a = new Array();
  var j=0;
  var item;

  for (i=0; i<document.getElementById("pHabitatLayer").length; i++) {

    if (document.getElementById("pHabitatLayer").options[i].selected) {
      item = document.getElementById("pHabitatLayer").options[i].value;    
      if (j>0 && a[j-1].length >= item.length && item.substring(0,item.length-2) != a[j-1].substring(0, a[j-1].length-2) ) j--; 
      else {
        if (item.indexOf(a[j-1]) != -1 || (j>0 && item.substring(0,item.length-2) == a[j-1].substring(0, a[j-1].length-2)) ) {
          alert("Items belonging to the same branch cannot be selected.");
          document.getElementById("pHabitatLayer").options[i].selected = false;
        }
      }
      a[j] = item;
      j++;
    }

  }  // for loop

  return true;
}
*/
// **************************************************************************************************
function habitatHelp() {

  var LeftPosition=(screen.width)?(screen.width-500)/2:100;
  var TopPosition=(screen.height)?(screen.height-580)/2:100;

  var settings='width='+ 500 + ',height='+ 580 + ',top=' + TopPosition + ',left=' + LeftPosition;

  habitatHelpWindow=window.open('','helpPopup',settings);
  habitatHelpWindow.focus();
  habitatHelpWindow.location='habitat_help.html';
  
}
// **************************************************************************************************
function changeHabitat(pType) {

  document.getElementById("gHabitat").value = document.getElementById("pHabitatGen").value;

  updateMap('habitat', document, ''); 

  document.getElementById("pg1SummaryFrame").src = document.getElementById("gCallSummary").value+
                                                                            "pHabitat="+document.getElementById("pHabitatGen").value+
                                                                            "&pRegion="+document.getElementById("gReportingRegion").value+
                                                                            "&pType="+document.getElementById("gReportingType").value;

  return true;
}
// **************************************************************************************************
function changeHabitatPage (pgNum, tabNum) {

  setPage(pgNum, tabNum);
  
}
// **************************************************************************************************
function changeHabitatState() {

  parent.document.getElementById("gReportingRegion").value = document.getElementById("pState").value;
  parent.document.getElementById("gReportingType").value = 'STATE';

  // when changing state selection - update map and the regions frame
  updateMap('state', document, '');

  // set regions for selected state
  if (parent.document.getElementById("gReportingRegion").value == document.getElementById("gNatMbr").value) {
    parent.document.getElementById("gReportingRegion").value = "NAT";
  }

  updateRegions(parent.document.getElementById("gReportingRegion").value);
  document.getElementById("gCurrentMbr").value = parent.document.getElementById("gReportingRegion").value;
  
  // **** TODO, set the type correctly
  document.getElementById("pg1SummaryFrame").src = document.getElementById("gCallSummary").value+
                                                                                       "pHabitat="+document.getElementById("pHabitatGen").value+
                                                                                       "&pRegion="+parent.document.getElementById("gReportingRegion").value+
                                                                                       "&pType=STATE";

  return true;
}
// **************************************************************************************************
function changeZoom(newExtDiff) {

  // zooming in to habitat level
  if (newExtDiff < 0.62) {
  
    // only if changing from either grid to habitat
    if (window.top.document.getElementById("gZoomLevel").value != "habitat") {
     
      window.top.document.getElementById("pHabitatGen").style.visibility = "hidden";
      window.top.document.getElementById("pHabitatGen").style.display = "none";

      window.top.document.getElementById("tdHabitat").style.visibility = "hidden";
      window.top.document.getElementById("tdHabitat").style.display = "none";

      window.top.document.getElementById("LegendRow").innerHTML = "<h3>Habitats Legend</h3>";

      window.top.document.getElementById("pg1LegendFrame").src = "/bin/mapserv46?map="+
                      window.top.mapframe.document.mapframeform.map.value+
                      "&mode=legend&layers=habitats";
                      
      window.top.document.getElementById("pg1SummaryFrame").style.height = "0";
      window.top.document.getElementById("pg1LegendFrame").style.height = "520";
     
      window.top.document.getElementById("gZoomLevel").value = "habitat";
    }
    
    window.top.document.getElementById("pg1SummaryFrame").src = "";

    layerText = layerText.replace(/grid10data/g, "habitats");
    layerText = layerText.replace(/grid50data/g,"habitats");
    layerText += " grid10line ";
      
  }
  
  // changing to 10K grid level
  else if (newExtDiff < 12.75) {
  
    // only if changing from habitat to grid
    if (window.top.document.getElementById("gZoomLevel").value == "habitat") {
      
      window.top.document.getElementById("pHabitatGen").style.display = "block";
      window.top.document.getElementById("pHabitatGen").style.visibility = "visible";
      window.top.document.getElementById("pHabitatGen").selectedIndex = 0;
     
      window.top.document.getElementById("tdHabitat").style.visibility = "visible";
      window.top.document.getElementById("tdHabitat").style.display = "block";

      window.top.document.getElementById("pg1SummaryFrame").style.height = "400";
      window.top.document.getElementById("pg1LegendFrame").style.height = "120";
     
    }

    if (window.top.document.getElementById("gZoomLevel").value != "10k") {  
    
      window.top.document.getElementById("LegendRow").innerHTML = "<h3>10km Grid Legend</h3>";
     
      window.top.document.getElementById("pg1LegendFrame").src = "/bin/mapserv46?map="+
                      window.top.mapframe.document.mapframeform.map.value+
                      "&mode=legend&layers=grid10data";
                      
      window.top.document.getElementById("gZoomLevel").value = "10k";
    }

    window.top.document.getElementById("pg1SummaryFrame").src = 
                      window.top.document.getElementById("gCallSummary").value+
                      "pHabitat="+window.top.document.getElementById("gHabitat").value+
                      "&pRegion="+window.top.document.getElementById("gReportingRegion").value+
                      "&pType="+window.top.document.getElementById("gReportingType").value;
     
    window.top.document.getElementById("pHabitatGen").value = window.top.document.getElementById("gHabitat").value;
     
    layerText = layerText.replace(/grid50data/g,"grid10data");
    layerText = layerText.replace(/habitats/g, "grid10data");
    layerText = layerText.replace(/grid10line/g, " ");
    
  }
    
  // changing to 50K grid level  
  else {
    
    // only if changing from habitat to grid
    if (window.top.document.getElementById("gZoomLevel").value == "habitat") {

      window.top.document.getElementById("pHabitatGen").style.display = "block";
      window.top.document.getElementById("pHabitatGen").style.visibility = "visible";
      window.top.document.getElementById("pHabitatGen").selectedIndex = 0;
     
      window.top.document.getElementById("tdHabitat").style.visibility = "visible";
      window.top.document.getElementById("tdHabitat").style.display = "block";
          
      window.top.document.getElementById("pg1SummaryFrame").style.height = "400";
      window.top.document.getElementById("pg1LegendFrame").style.height = "120";
     
    }
     
    if (window.top.document.getElementById("gZoomLevel").value != "50k") {
    
      window.top.document.getElementById("LegendRow").innerHTML = "<h3>50km Grid Legend</h3>";
      
      window.top.document.getElementById("pg1LegendFrame").src = "/bin/mapserv46?map="+
                    window.top.mapframe.document.mapframeform.map.value+
                    "&mode=legend&layers=grid50data";
                      
      window.top.document.getElementById("gZoomLevel").value = "50k";
    }

    window.top.document.getElementById("pg1SummaryFrame").src = 
                      window.top.document.getElementById("gCallSummary").value+
                      "pHabitat="+window.top.document.getElementById("gHabitat").value+
                      "&pRegion="+window.top.document.getElementById("gReportingRegion").value+
                      "&pType="+window.top.document.getElementById("gReportingType").value;

    window.top.document.getElementById("pHabitatGen").value = window.top.document.getElementById("gHabitat").value;
     
    layerText = layerText.replace(/grid10data/g,"grid50data");
    layerText = layerText.replace(/habitats/g, "grid50data");
    layerText = layerText.replace(/grid10line/g, " ");
  
  }

}
// **************************************************************************************************
function habitatCollapse() {

  if (document.getElementById("extent").style.display == "none") {
    document.getElementById("extent").style.display   = "block";
    document.getElementById("extent").style.visibility = "visible";
    document.getElementById("extentHeading").innerHTML  = "[-] Other habitat areas (click to collapse):";
  }
  else {
    document.getElementById("extent").style.display   = "none";
    document.getElementById("extent").style.visibility = "hidden";
    document.getElementById("extentHeading").innerHTML  = "[+] Click to view other habitat areas in selected region:";
  }

}
// **************************************************************************************************
function loadHabitats() {

  Menu_HideAll('SubMenu');
  Menu_ShowLevel('SubMenu', 'level0');
  domCollapse('menu2','span',0);

  document.getElementById("pHabitatGen").style.display = "block";
  document.getElementById("pHabitatGen").style.visibility = "visible";
  document.getElementById("pHabitatGen").selectedIndex = 2;

  document.getElementById("gHabitat").value = 'MANGROVE DOMINATED';
  document.getElementById("mapframe").src = "/bin/mapserv46?map=" + document.getElementById("gMapFile").value + "&layers=grid50data &mapfiltername=map_grid50data_filter&mapfiltername2=map_grid10data_filter&mapfilter=(name='MANGROVE DOMINATED')&mapfile_ext=111 -45 155 -9";

  document.getElementById("pg1SummaryFrame").src = document.getElementById("gCallSummary").value+"pHabitat=MANGROVE DOMINATED&pRegion=NAT&pType=STATE";
  updateRegions("NAT");

  document.getElementById("pg1LegendFrame").src = "/bin/mapserv46?map=" + document.getElementById("gMapFile").value + "&mode=legend&layers=grid50data";

  document.getElementById("LegendRow").innerHTML = "<h3>50km Grid</h3>";

}
// **************************************************************************************************

