function show_tab(selectedtab) {
  var currdiv;
  tablist = new Array ("layer","overview","help","search","q","about");
  for(tabidx in tablist) {
    divname = tablist[tabidx] + "div"
    currdiv = top.document.getElementById(divname);
    if ( tablist[tabidx] == selectedtab ) {
      currdiv.style.visibility = 'visible';
      top.document.getElementById(tablist[tabidx]).style.background="#c0c9c0";
      }
    else {
      currdiv.style.visibility = 'hidden';
      top.document.getElementById(tablist[tabidx]).style.background="#f0f0f0";
      }
  }
}

function set_target(clickfrm) {
  mfrm=top.frames['mapdisplay'].document.forms['mapform'];
  switch (clickfrm) {
  case 2: top.frames['mapdisplay'].document.getElementById("messagescrn").style.visibility = 'visible';
          mfrm.target = top.frames['mapdisplay'].name;
          mfrm.action = "/imap/genmap.php";
          mfrm.submit();
          break;
  case 3: top.frames['searchwin'].location.href='/imap/feature_zoom.php';
          show_tab("search");
          break;
  case 4:  mfrm.elements['z'] = 2;
           mfrm.target = top.frames['mapdisplay'].name;
           mfrm.action = "/imap/genmap.php";
           newex=parseFloat(mfrm.ex.value)/2;
           newey=parseFloat(mfrm.ey.value)/2;
           if(newex>150 && newex<300000) {
             mfrm.x.value = parseFloat(mfrm.x.value);
             mfrm.y.value = parseFloat(mfrm.y.value);
             mfrm.ex.value = newex;
             mfrm.ey.value = newey;
             }
           else {
             alert('attempted extent (' + newex + ' meters) exceeds allowable limit');
             newex=parseFloat(mfrm.ex.value)*2;
             newey=parseFloat(mfrm.ey.value)*2;
             }
           mfrm.submit();
           break;
  case 5:  mfrm.elements['z'] = 4;
           mfrm.target = top.frames['mapdisplay'].name;
           mfrm.action = "/imap/genmap.php";
           newex=parseFloat(mfrm.ex.value)*2;
           newey=parseFloat(mfrm.ey.value)*2;
           if(newex>150 && newex<300000) {
             mfrm.x.value = parseFloat(mfrm.x.value);
             mfrm.y.value = parseFloat(mfrm.y.value);
             mfrm.ex.value = newex;
             mfrm.ey.value = newey;
             mfrm.submit();
             }
           else
             alert('attempted extent (' + newex + ' meters) exceeds allowable limit');
             newex=parseFloat(mfrm.ex.value)/2;
             newey=parseFloat(mfrm.ey.value)/2;
           mfrm.submit();
           break;
  }
 }

function preload() {

  if (window.top != window.self) { window.open("/imap/index.html","_top",""); }

  imgsrc = new Array ("i_zi_out.png","i_zi2x_out.png","i_p_out.png","i_zo2x_out.png","i_zo_out.png","i_q_out.png","i_zi_in.png","i_zi2x_in.png","i_p_in.png","i_zo2x_in.png","i_zo_in.png","i_q_in.png","i_r_out.png","i_r_in.png");
  img = new Array();
  for(ctr in imgsrc) {
    img[ctr] = new Image();
    img[ctr].src = "/imap/icons/" + imgsrc[ctr];
    }

  setaction("zoom in box");
  show_tab('layer');
  }

function setaction(click_function) {
  document.zoom_in.src="/imap/icons/i_zi_out.png";
  document.zoom_out.src="/imap/icons/i_zo_out.png";
  document.pan.src="/imap/icons/i_p_out.png";
  document.zoom_in_2x.src="/imap/icons/i_zi2x_out.png";
  document.zoom_out_2x.src="/imap/icons/i_zo2x_out.png";
  document.query.src="/imap/icons/i_q_out.png";
  document.reset.src="/imap/icons/i_r_out.png";
  func=window.parent.frames['mapdisplay'].document.forms['mapform'].elements['z'];
  mapobj=window.parent.frames['mapdisplay'].document.getElementById('map');
  mapobj.style.cursor='crosshair';
  switch (click_function) {
    case "zoom in box" : func.value = 1 ;
               document.zoom_in.src="/imap/icons/i_zi_in.png";
               break;
    case "pan" : func.value = 3;
               document.pan.src="/imap/icons/i_p_in.png";
               mapobj.style.cursor='move';
               break;
    case "zoom out box" : func.value = 5;
               document.zoom_out.src="/imap/icons/i_zo_in.png";
               break;
    case "query" : func.value = 6
               document.query.src="/imap/icons/i_q_in.png";
               mapobj.style.cursor='help';
               break;
    case "reset" : document.reset.src="/imap/icons/i_r_in.png";
                   mfrm=top.frames['mapdisplay'].document.forms['mapform'];
                   mfrm.z.value = 7;
                   mfrm.target = top.frames['mapdisplay'].name;
                   mfrm.action = "/imap/genmap.php";
                   mfrm.submit();
                   setaction('zoom in box');
                   break;
   case "redraw" :
    }
  }

function setquery(lyr) {
  qlyr = top.frames['mapdisplay'].document.forms['mapform'].elements['q']
  var qicon = "document.q" + qlyr.value + ".src=\"/imap/icons/off.png\"";
  eval(qicon);
  var oicon = "document.q" + lyr + ".src=\"/imap/icons/on.png\"";
  eval(oicon);
  qlyr.value = lyr;
  }

function setlayer(name) {
  qlyr = top.frames['mapdisplay'].document.forms['mapform'].elements[name]
  lyrstate = qlyr.value
  switch (lyrstate) {
    case "Y" : var newicon = "document.d" + name + ".src=\"/imap/icons/off.png\"";
               eval(newicon);
               qlyr.value = "N";
               break;
    case "N" : var newicon = "document.d" + name + ".src=\"/imap/icons/on.png\"";
               eval(newicon);
               qlyr.value="Y";
               break;
    }
  }

