
//  Copyright (c) 2001 - 2005 Province of British Columbia, Canada
//  All Rights Reserved
//
//  This material is owned by the Government of British Columbia and protected
//  by copyright law. It may not be reproduced or redistributed in whole or in
//  part without the prior written permission of the Province of British Columbia.

var dHidden = parent.frames["hiddenFrame"];
var dMap = parent.frames["mapFrame"];
var dTools = parent.frames["toolFrame"];
var dStatus = parent.frames["statusFrame"];
idImageOn = new Image();
idImageOn.src = "images/thmIdOn13x13.gif";
selImageOn = new Image();
selImageOn.src = "images/layerSelectOn13x13.gif";
selImageOff = new Image();
selImageOff.src = "images/layerSelectOff13x13.gif";
layerOff = new Image();
layerOff.src = "images/layeroff12x12.gif";
layerOn = new Image();
layerOn.src = "images/layeron12x12.gif";
labelOn = new Image();
labelOn.src = "images/labelon19x12.gif";
labelOff = new Image();
labelOff.src = "images/labeloff19x12.gif";
function setScroll() {
  if (document.documentElement && document.documentElement.scrollTop) {
    scrollPos = document.documentElement.scrollTop;
  } else if (document.body && document.body.scrollTop) {
    scrollPos = document.body.scrollTop;
  }
}
function doScroll(pos) {
  if (document.documentElement && document.documentElement.scrollTop) {
    document.documentElement.scrollTop = pos;
  } else if (document.body) {
    document.body.scrollTop = pos;
  }
}
function refreshMap() {
  dMap.refreshMap();
}
function zoomToScale(scale,adjust) {
  dMap.zoomToScale(scale,adjust);
}
function openFolder(foid) {
  setScroll();
  self.location.href = url + "?open=" + foid + "&pos=" + scrollPos;
}
function closeFolder(foid) {
  setScroll();
  self.location.href = url + "?close=" + foid + "&pos=" + scrollPos;
}
function folderVis(foid, onOff) {
  setScroll();
  dHidden.location.href = "imfSetFolderVisibility.jsp?foid=" + foid + "&vis=" + onOff + "&pos=" + scrollPos;
}
function setAutoRefresh(flag) {
  setScroll();
  if (flag) {
    dHidden.location.href = "imfSetAutoRefresh.jsp?auto=true&pos=" + scrollPos;
  } else {
    dHidden.location.href = "imfSetAutoRefresh.jsp?auto=false&pos=" + scrollPos;
  }
}
function setLabelVisibility(loid, iname) {
  setScroll();
  var vis = document.images[iname].src == labelOff.src;
  if (vis) {
    setImage(iname, labelOn.src);
  } else {
    setImage(iname, labelOff.src);
  }
  dHidden.focus();
  dHidden.location.href = "imfShowLabels.jsp?loid=" + loid + "&vis=" + vis + "&pos=" + scrollPos;
}
function setGroupLabelVisibility(goid, iname) {
  setScroll();
  var vis = document.images[iname].src == labelOff.src;
  if (vis) {
    setImage(iname, labelOn.src);
  } else {
    setImage(iname, labelOff.src);
  }
  dHidden.focus();
  dHidden.location.href = "imfShowGroupLabels.jsp?goid=" + goid + "&vis=" + vis + "&pos=" + scrollPos;
}
function setLayerVisibility(loid, iname, foid) {
  var vis = (document.images[iname].src.indexOf(layerOff.src) != -1);
  if (vis) {
    document.images[iname].src = layerOn.src;
  } else {
    document.images[iname].src = layerOff.src;
  }
  setScroll();
  dHidden.focus();
  dHidden.location.href = "imfSetLayerVisibility.jsp?loid=" + loid + "&vis=" + vis + "&foid=" + foid + "&pos=" + scrollPos;
}
function setLayerLegendVisibility(loid,vis) {
  setScroll();
  dHidden.focus();
  dHidden.location.href = "imfSetLayerLegendVisibility.jsp?loid=" + loid + "&vis=" + vis + "&pos=" + scrollPos;
}
function setGroupLegendVisibility(goid,vis) {
  setScroll();
  dHidden.focus();
  dHidden.location.href = "imfSetGroupLegendVisibility.jsp?goid=" + goid + "&vis=" + vis + "&pos=" + scrollPos;
}
function setGroupVisibility(goid, iname, foid) {
  var vis = (document.images[iname].src.indexOf(layerOff.src) != -1);
  if (vis) {
    document.images[iname].src = layerOn.src;
  } else {
    document.images[iname].src = layerOff.src;
  }
  setScroll();
  dHidden.focus();
  dHidden.location.href = "imfSetGroupVisibility.jsp?goid=" + goid + "&vis=" + vis + "&foid=" + foid + "&pos=" + scrollPos;
}
function setImage(iname, isrc) {
  for (var i = 0; i < document.images.length; i++) {
    if (document.images[i].name == iname) {    
      document.images[i].src = isrc;
    }
  }
}
function setActiveLayer(loid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == idImageOn.src) {
      setImage(document.images[i].name,idImageOff.src);
    }
  }
  setImage(iname, idImageOn.src);
  dHidden.focus();
  dTools.butClick("Identify");
  dHidden.location.href = "imfSetActiveLayer.jsp?loid=" + loid + "&foid=" + foid + "&pos=" + scrollPos;
}
function setIdentifyLayer(loid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == idImageOn.src) {
      setImage(document.images[i].name,idImageOff.src);
    }
  }
  setImage(iname, idImageOn.src);
  dHidden.focus();
  dTools.butClick("Identify");
  dHidden.location.href = "imfSetActiveIdentifyLayer.jsp?loid=" + loid + "&foid=" + foid + "&pos=" + scrollPos;
}
function setActiveGroup(goid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == idImageOn.src) {
      setImage(document.images[i].name,idImageOff.src);
    }
  }
  setImage(iname, idImageOn.src);
  dHidden.focus();
  dTools.butClick("Identify");
  dHidden.location.href = "imfSetActiveLayerGroup.jsp?goid=" + goid + "&foid=" + foid + "&pos=" + scrollPos;
}
function setIdentifyGroup(goid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == idImageOn.src) {
      setImage(document.images[i].name,idImageOff.src);
    }
  }
  setImage(iname, idImageOn.src);
  dHidden.focus();
  dTools.butClick("Identify");
  dHidden.location.href = "imfSetActiveIdentifyGroup.jsp?goid=" + goid + "&foid=" + foid + "&pos=" + scrollPos;
}
function setSelectLayer(loid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == selImageOn.src) {
      document.images[i].src = selImageOff.src;
    }
  }
  setImage(iname, selImageOn.src);
  dHidden.focus();
  dTools.butClick("Select");
  dHidden.location.href = "imfSetActiveSelectLayer.jsp?loid=" + loid + "&foid=" + foid + "&pos=" + scrollPos;
}
function setSelectGroup(goid, iname, foid) {
  setScroll();
  for (i in document.images) {
    if (document.images[i].src == selImageOn.src) {
      document.images[i].src = selImageOff.src;
    }
  }
  setImage(iname, selImageOn.src);
  dHidden.focus();
  dTools.butClick("Select");
  dHidden.location.href = "imfSetActiveSelectLayerGroup.jsp?goid=" + goid + "&foid=" + foid + "&pos=" + scrollPos;
}
function openMetadataGroup(goid) {
  temp = "toolbar=no,menubar=yes,location=no,directories=no," +
         "status=no,scrollbars=yes,resizable=yes,copyhistory=no," +
         "width=400,height=400";
  window.open("imfMetadataGroup.jsp?goid=" + goid,"imfMetadata",temp);
}
function openMetadata(oid,isGroup) {
  temp = "toolbar=no,menubar=yes,location=no,directories=no," +
         "status=no,scrollbars=yes,resizable=yes,copyhistory=no," +
         "width=400,height=400";
  metaParam = "loid";
  if (isGroup) {
    metaParam = "goid";
  }
  window.open("imfMetadata.jsp?" + metaParam + "=" + oid,"imfMetadata",temp);
}
function openMetadataHandler(loid) {
  temp = "toolbar=no,menubar=yes,location=no,directories=no," +
         "status=no,scrollbars=yes,resizable=yes,copyhistory=no," +
         "width=400,height=400";
  window.open("imfMetadataHandler.jsp?loid=" + loid,"imfMetadata",temp);
}
function openLayerManager(page) {
  temp = "toolbar=no,menubar=no,location=no,directories=no," +
         "status=no,scrollbars=yes,resizable=yes,copyhistory=no," +
         "width=400,height=400";
  window.open(page,"imfLayerManager",temp);
}
function msg(msg) {
  self.status = msg;
}
function msg0() {
  msg("");
}
function msg1() {
  msg("Set the visibility of this layer.");
}
function msg2() {
  msg("Set the active layer.");
}
function msg3() {
  msg("Set the active layer.");
}
function zoomToTheme() {
  parent.frames.hiddenFrame.location.href = "imfApplyTheme.jsp?index=" + document.themeForm.themes.options[document.themeForm.themes.selectedIndex].value;
}

