/***************************************************************************************\
                                     PopupGeono.js
                        JavaScript template file for ArcIMS HTML Viewer
\***************************************************************************************/

/***************************************************************************************\
                                     Global variables
\***************************************************************************************/
                                     
var ie = (document.all)? true:false;
var ns4 = (document.layers)? true:false;
var ns6 = (document.getElementById)? true:false;
var IdIndexer = 0;
var ActiveMovingWindow;


/***************************************************************************************\
                           Popup Window with extended capabilities
\***************************************************************************************/
function create3DLayer(aName,aLeft,aTop,aWidth,aHeight,aZIndex,aVisible,aTitle,aContent,aURL,aButtonClose) {
  document.writeln('<div id="' + aName + '" class="PopupWindowFrame" style="left:' +
                    aLeft + 'px;top:' + 
                    aTop + 'px;width:' + 
                    aWidth + 'px;height:' + 
                    aHeight + 'px;z-index:' + 
                    aZIndex + ';visibility:' + (aVisible ? 'visible;' : 'hidden;') + '">');
  if (aTitle=="") aTitle = "GeoNo";
  if (aTitle!='') {
    document.writeln('  <div id="' + aName + 'Title" class="PopupWindowTitle">');
    document.writeln('    <table class="PopupWindowTitle" border="0px" cellpadding="0px" cellspacing="0px" height="19px">');
    document.writeln('      <tr>');
    document.writeln('        <td><img src="./Images/Logo.gif" border="0px" width="20px" height="19px" alt="GeoNo"></td>');
    document.writeln('        <td class="PopupWindowTitle">' + aTitle + '</td>');
    document.writeln('        <td><img id="CloseBtn' + IdIndexer + '_' + aName + '" src="./Images/Close1.gif" border="0px" width="21px" height="19px" alt="Lukk"></td>');
    document.writeln('      </tr>');
    document.writeln('    </table>');  
    document.writeln('  </div>');
  }
  var aHeightValue = (aButtonClose?(aHeight-41-(ie?27:17))+"px":(aHeight-41)+"px");
  var aClientHeight = (aHeight-(ie?33:25));
  var aWidthValue = (aWidth-10) + "px";
  var aContentHeight = 0;
  var aURLHeight = 0;
  var aButtonHeight = 0;
  var aTmpHeight = aClientHeight;
  if (aButtonClose) {aButtonHeight = 31;aTmpHeight -= aButtonHeight;}
  if (aContent!="") if (aURL!="") {aContentHeight = aTmpHeight / 3;aURLHeight = aTmpHeight - aContentHeight;} else aContentHeight = aTmpHeight; else if (aURL!="") aURLHeight = aTmpHeight;
  document.writeln('    <table border="0px" width="100%" height="' + aClientHeight + '" cellpadding="0px" cellspacing="0px" class="PopupWindowContent">');
  if (aContent!="") {                   //Content
    document.writeln('      <tr><td valign="top" class="PopupWindowContent" Style="width:100%;padding:5px;height:' + aContentHeight + 'px;"><div id="InfoContent" style="overflow:auto;">' + aContent + '</div></td>');//border:2px white inset;
    document.writeln('      </tr>');
  }
  if (aURL!="") {                       //URL
  document.writeln('      <tr><td valign="top" class="PopupWindowContent" Style="width:100%;padding: 0px 0px 0px 2px;">');
  document.writeln('          <iframe id="InfoURL" src="' + aURL + '" border="0px" marginwidth="0px" marginheight="0px" frameborder="0" scrolling="auto" style="align:center;overflow:auto;width:100%;height:' + aURLHeight + 'px;"></iframe>');
  document.writeln('        </td></tr>');
  }    
  if (aButtonClose) {                   //CloseButton
    document.writeln('      <tr>');
    document.writeln('        <td align= "center" valign="top" class="PopupWindowContent" Style="width:100%;padding:2px;height:' + aButtonHeight + 'px;">');
    document.writeln('<img id="CloseBtn' + (IdIndexer + 1) +'_' + aName + '" src="./Images/Lukk1.gif" border="0px" width="60px" height="28px" alt="Lukk">');
    document.writeln('</td>');
    document.writeln('      </tr>');
  }
  document.writeln('    </table>');
  document.writeln('</div>');
  var aCloseBtn = document.getElementById("CloseBtn" + IdIndexer + '_' + aName);
  var aTitleBar = document.getElementById(aName + 'Title');
  var aCloseButton = (aButtonClose?document.getElementById("CloseBtn" + (IdIndexer + 1) + '_' + aName):null);
  if (ie) {
    aCloseBtn.onmousedown = ButtonIsDownOrUp;
    aCloseBtn.onmouseup = ButtonIsDownOrUp;
    aCloseBtn.onclick = ButtonIsClicked;
    aTitleBar.onmousedown = MouseIsDownOnTitle;
    if (aButtonClose) {
      aCloseButton.onmousedown = ButtonIsDownOrUp;
      aCloseButton.onmouseup = ButtonIsDownOrUp;
      aCloseButton.onclick = ButtonIsClicked;
    }
 } else {
    aCloseBtn.addEventListener("mousedown", ButtonIsDownOrUp, false);
    aCloseBtn.addEventListener("mouseup", ButtonIsDownOrUp, false);
    aCloseBtn.addEventListener("click", ButtonIsClicked, false);
    aTitleBar.addEventListener("mousedown", MouseIsDownOnTitle, false);
    if (aButtonClose) {
      aCloseButton.addEventListener("mousedown", ButtonIsDownOrUp, false);
      aCloseButton.addEventListener("mouseup", ButtonIsDownOrUp, false);
      aCloseButton.addEventListener("click", ButtonIsClicked, false);
    }
  }
  IdIndexer ++;
  if (aButtonClose) IdIndexer ++;
  return document.getElementById(aName);
}

/***************************************************************************************\
                                     Hide a Popup window
\***************************************************************************************/
function HidePopupWindow(aElement) {
  while (aElement.className!="PopupWindowFrame") aElement = ie?aElement.parentElement:aElement.parentNode;
  if (aElement==null) return;
  aElement.style.visibility = "hidden";
}

/***************************************************************************************\
                                     Show a Popup window
\***************************************************************************************/
function ShowPopupWindow(aElement) {
  while (aElement.className!="PopupWindowFrame") aElement = ie?aElement.parentElement:aElement.parentNode;
  if (aElement==null) return;
  aElement.style.visibility = "visible";
}

/***************************************************************************************\
                                     Event: onMouseDown on the title bar
\***************************************************************************************/
function MouseIsDownOnTitle(e) {
  ActiveMovingWindow = ie?event.srcElement:e.target;
  while (ActiveMovingWindow.className!="PopupWindowFrame") ActiveMovingWindow = ie?ActiveMovingWindow.parentElement:ActiveMovingWindow.parentNode;
  if (ActiveMovingWindow==null) return;
  if (ie) {
    window.lastX=event.clientX; 
    window.lastY=event.clientY;
    document.onmousemove=MouseIsDownAndMovingOnTitle;
    document.onmouseup=MouseIsUpOnTitle;
  } else {
    window.lastX=e.clientX;
    window.lastY=e.clientY;
    window.onmousemove=MouseIsDownAndMovingOnTitle;
    window.onmouseup=MouseIsUpOnTitle;
  }
}

/***************************************************************************************\
                                     Event: onMouseMove on the title bar
\***************************************************************************************/
function MouseIsDownAndMovingOnTitle(e) {
  if (ActiveMovingWindow==null) return;
  var difX = ie?event.clientX-window.lastX:e.clientX-window.lastX;
  var difY = ie?event.clientY-window.lastY:e.clientY-window.lastY;
  ActiveMovingWindow.style.left = parseInt(ActiveMovingWindow.style.left) + difX;
  ActiveMovingWindow.style.top = parseInt(ActiveMovingWindow.style.top) + difY;
  window.lastX = ie?event.clientX:e.clientX;
  window.lastY = ie?event.clientY:e.clientY;
}

/***************************************************************************************\
                                     Event: onMouseUp on the title bar
\***************************************************************************************/
function MouseIsUpOnTitle(e) {
  if (ActiveMovingWindow==null) return;
  if (ie) document.onmousemove = null; else window.onmousemove = null;
  ActiveMovingWindow = null;
}

/***************************************************************************************\
                    Event: onMouseDown & onMouseUp on a close button
                                   change the icons
\***************************************************************************************/
function ButtonIsDownOrUp(e) {
  var Index = -1;
  var Chaine = ie?event.srcElement.src:e.target.src;
  var Root = Chaine.substr(0,Chaine.lastIndexOf("/"));
  Chaine = Chaine.substr(Chaine.lastIndexOf("/")+1);
  Root = Root.substr(Root.lastIndexOf("/")+1) + "/";
  if (Chaine.lastIndexOf("1")>=0) {
    Chaine = Chaine.substr(0,Chaine.lastIndexOf("1")) + "3.gif";
  } else {
    Chaine = Chaine.substr(0,Chaine.lastIndexOf("3")) + "1.gif";
  }
  Root = "./Images/";
  window.status = Root + Chaine;
  if (ie) event.srcElement.src = Root + Chaine; else e.target.src = Root + Chaine;
}

/***************************************************************************************\
                             Event: onClick on a close button
\***************************************************************************************/
function ButtonIsClicked(e) {
  var Chaine = ie?event.srcElement.id:e.target.id;
  Chaine = Chaine.substr(Chaine.lastIndexOf("_")+1);  
  document.getElementById(Chaine).style.visibility = "hidden";
}

/***************************************************************************************\
                             Update the title of current page 
\***************************************************************************************/
function ShowTitle(aTitle,aURL) {
  var tab = aTitle.split("|");
  var Chaine = "";
  if (tab.length==1) {
    Chaine = tab[0];
  }
  //18/12/06      Bugg      To Correct
  //parent.ContentHeader.main_menu_div.children(0).innerHTML = Chaine;
  //18/12/06      Bugg      End
  //parent.ContentHeader.main_menu_div.children(2).innerHTML = aURL;
}

