
var d = new Date();
var timeFirst = d.getTime();

var preloadFlag = false;
var ver4 = true;
var currentSelectedButton = "pan";   //zoomin
var imgdir = "images/tb/";         //images/tb/
var imgext = ".jpg";
var cBtnType_Action = "action";
var cBtnType_Mode = "mode";
var mapSizeFull = false;

var ww = getWindow();


function changeAPI(API) {
  alert(API);
}

  function changeVisibility()
  {
   //parent.ToolbarFrame.document.getElementById("SelectBoxTypeDiv").style.visibility= "hidden";
   //parent.ToolbarFrame.document.getElementById("SelectBoxTypeDiv_hide").style.visibility= "hidden";
  }

function showFewerTools()
{
parent.document.getElementById("ToolbarFrame").src="toolbar_aerial_short.htm";
}


function showMoreTools()
{
parent.document.getElementById("ToolbarFrame").src="toolbar_aerial_long.htm";
}





  function changeSketchType(value){
    ww.sketchType = value;
    switch(ww.sketchType ){
    case "Line":
       ww.drawTB.activate(ww.esri.toolbars.Draw.POLYGON);
    break;
    case "Free":
      ww.drawTB.activate(ww.esri.toolbars.Draw.FREEHAND_POLYGON);
     break;
    //case "Box":
    //  ww.drawTB.activate(ww.esri.toolbars.Draw.EXTENT);
    // break;

    }

  }

  function mouseOver(imName, over) {
    if (!document.images) {return};

    whichIm = document.images[imName];

    if (over) {
      whichIm.src = imgdir + imName + "_over" + imgext;
      //alert(whichIm.src);
    } else {

      if (currentSelectedButton == imName)   {
        newimage = imgdir + imName + "_down" + imgext
        if (whichIm.src != newimage ) {
          whichIm.src = newimage;
        }
      } else {
        newimage = imgdir + imName + "_up" + imgext;   //implied '_up'
        if (whichIm.src != newimage ) {
          whichIm.src = newimage;
        }
             //alert ("mouseOut" + whichIm.src);
      }
    }

    return true;
  }  //of mouseOver() function




function toggleToolModeButtons(imName) {
  whichIm = document.images[imName];
  if (typeof whichIm == "undefined") return;

  var ww=getWindow();
  if (typeof ww == "undefined") return;

  if (typeof ww.clickFunction != "function")      return;


  if ( typeof parent.ToolbarFrame.document.getElementById("ShapeTypeDiv")  == "undefined") {
    parent.ToolbarFrame.document.getElementById("ShapeTypeDiv").style.visibility= "hidden";
   //ww.sketchGeometry = null;
  }


  if (parent.ToolbarFrame.document.getElementById("SelectBoxTypeDiv")) {
    parent.ToolbarFrame.document.getElementById("SelectBoxTypeDiv").style.visibility= "hidden";
  }



  //deselect last selected button
  if (currentSelectedButton != "") {

    if (typeof document.images[currentSelectedButton] != "undefined" )
    document.images[currentSelectedButton].src = imgdir + currentSelectedButton + "_up" + imgext;

    if (typeof document.images["layers"]  != "undefined") document.images["layers"].src = imgdir + "layers" + "_up" + imgext;
    if (typeof document.images["quick-start"]  != "undefined") document.images["quick-start"].src = imgdir + "quick-start" + "_up" + imgext;



  }


  // this is a mode button, it is permanently selected
  currentSelectedButton = imName;
  whichIm.src =  imgdir + imName + "_down" + imgext;
}



  function mouseDown(imName, down, btnType, thecode) {

  whichIm = document.images[imName];
  if (typeof whichIm == "undefined") return;

  var ww=getWindow();
  if (typeof ww == "undefined") return;

  if (typeof ww.clickFunction != "function")      return;

    if (down) {
      whichIm = document.images[imName];
      whichIm.src = imgdir + imName + "_down" + imgext;
   } else {



    if (btnType != cBtnType_Mode) {
      //This is an immediate action button, simply toggled down/up
      whichIm.src = imgdir + imName + "_up" + imgext;
    } else {
      toggleToolModeButtons(imName);

    }

   // alert("attachClick " + imName);
   
    if (thecode != null && thecode != "") {
		if (imName == "legend") show_legend();
		else if (imName == "quick-start") show_quickstart();
		else if (imName == "layers") show_toc();
		else if (imName == "state") createbystatewindow();
		else if (imName == "county") createbycountywindow();
    }
    else ww.clickFunction(imName);




    }

    return true;
  }





  function newImage(arg) {
    if (document.images) {
      rslt = new Image();
      rslt.src = arg;
      return rslt;
    }
  }








  function newGeoCommWindow(){
    open("http://www.geocommunicator.gov");
  }

  function loadKML(){
  }

  function selectByCounty(){
    var sizeWidth = 530;
    var sizeHeight = 377;
    var posLeft = (screen.width / 2) - (sizeWidth / 2);
    var posTop = (screen.height / 2) - (sizeHeight / 2) - 15;
    getWindow().countyWindow = window.open("/blmMap/bycountyselector.htm", "CountySelector", "status=1,width=" + sizeWidth + ",height=" + sizeHeight +",left=" + posLeft + ",top=" + posTop);
  }

  function selectByState(){
    var sizeWidth = 345;
    var sizeHeight = 377;
    var posLeft = (screen.width / 2) - (sizeWidth / 2);
    var posTop = (screen.height / 2) - (sizeHeight / 2) - 20;
    getWindow().stateWindow = window.open("/blmMap/bystateselector.htm", "StateSelector", "status=1,width=" + sizeWidth + ",height=" + sizeHeight +",left=" + posLeft + ",top=" + posTop);
  }



var preloadFlag = false;

function preloadImages() {
  preloadFlag = true;
}

function show_toc()  {
  parent.MapFrame.showTOC(true);
}

function show_legend()  {
  parent.TOCFrame.document.location=parent.MapFrame.commonApp+"legend.htm";
}

function show_metadata()  {
  parent.TOCFrame.document.location=parent.MapFrame.commonApp+"legend_report.htm";
}

function show_quickstart()  {
if (ww.currentMapView==ww.cMAPVIEW_AERIAL) {
  parent.TOCFrame.document.location=parent.MapFrame.commonApp+"quickstart_aerial.htm";
} else {
  parent.TOCFrame.document.location=parent.MapFrame.commonApp+"quickstart.htm";
 }
}

function setMap()  {
try{
  var listoptions = document.form1.thelist.options;
  var sKeyword = "";
  var sCaption = "";
  //note: start at 1 to ignore first item which is just instructions to user
  for (var iCnt=1; iCnt < listoptions.length; iCnt++)  {
    if ( listoptions[iCnt].selected ){
      sKeyword = listoptions[iCnt].value;
      sCaption = listoptions[iCnt].innerHTML;
    }
  }
  if (sKeyword != "" )
    top.parent.MapFrame.setNewMapView(sKeyword);
} catch(e){
alert(e.message);
}
}

function help() {

  open("Help.htm","","height=250, width=330,top=" + (screen.height/2 - 125) + ",left=" + (screen.width/2 - 165) + ",status=yes,toolbar=no,menubar=no,location=no,resizable=no scrollbars=no");   //
  /*var msg = "Map navigation using mouse and keyboard:\n\n" +
            "Drag to pan\n" +
            "SHIFT + drag to zoom in using selection box\n" +
            "SHIFT + click to re-center\n" +
            "SHIFT + double click to center and zoom in" +
            "Mouse scroll up to zoom in\n" +
            "Mouse scroll down to zoom out\n" +
            "Use arrow keys to pan\n" +
            "+ key to zoom in\n" +
            "- key to zoom out\n";
  alert(msg);*/
}


function createsearchwindow()  {
    //openwindow("bytwpselector.htm", 450,220);
    top.TOCFrame.document.location="/blmMap/bytwpselector.htm";
}


function createbystatewindow()  {
    //openwindow("bystateselector.htm", 180,240);
    top.TOCFrame.document.location="/blmMap/bystateselector.htm";
}


function createbycountywindow()  {
    //openwindow("bycountyselector.htm", 430,300);
    top.TOCFrame.document.location="/blmMap/bycountyselector.htm";
}



function getWindow() {
  var ww;
  if (typeof parent.parent.MapFrame != "undefined")
    ww = parent.parent.MapFrame;
  else {
    if (typeof window.top.MapFrame != "undefined")
      ww = window.top.MapFrame;
    else {
      if (opener) {
        //most geocomm gets here
        ww = opener.parent.MapFrame;
      }
      else {
        if (parent.MapFrame)
          ww = parent.MapFrame;
        else;
         //alert("Could not find MapFrame!");
      }
    }
  }
  return ww;
}


