﻿
function DetectPopUpType() {
   varHYPname = document.getElementsByTagName("a"); 
   for(varInt = 0; varHYPname.length > varInt; varInt++) {
      varHYPattrib = varHYPname.item(varInt); 
      if(varHYPattrib.className.indexOf("popupURL") != -1)varHYPattrib.onclick = function() {
         CreatePopupWindow(this.href, true, this.className, this.title); 
         return false; 
         }
      if(varHYPattrib.className.indexOf("popupIMG") != -1)varHYPattrib.onclick = function() {
         CreatePopupWindow(this.href, false, this.className, this.title); 
         return false; 
         }
      }
   }
function ClosePopupWindow() {
   Set_Backgroud_Opacity(0, "myPopMask"); 
   Set_Backgroud_Opacity(0, "myPopContainer");
   if(document.getElementById("myPopElement") != null){
       var ElementName = document.getElementById("myPopElement")
       document.getElementById("myPopContainer").removeChild(ElementName); 
       document.getElementsByTagName("body").item(0).removeChild(document.getElementById("myPopContainer")); 
       document.getElementsByTagName("body").item(0).removeChild(document.getElementById("myPopMask")); 
   }
   if(window.removeEventListener)window.removeEventListener("resize", ClosePopupWindow, false); 
   else if(window.detachEvent)window.detachEvent("onresize", ClosePopupWindow); 
   }
function CreatePopupWindow(PopupSource, IsURLpopup, WidthAndHeight, PopupTitle) {
   if(window.attachEvent)window.attachEvent("onresize", ClosePopupWindow); 
   else if(window.addEventListener)window.addEventListener("resize", ClosePopupWindow, false); 
   if(document.getElementById("myPopContainer"))ClosePopupWindow(); 
   varNewDiv = document.createElement("div"); 
   varNewDiv.setAttribute("id", "myPopContainer"); 
   if(PopupTitle) {
      varNewHR = document.createElement("h1"); 
      varNewHR.appendChild(document.createTextNode(PopupTitle)); 
      varNewDiv.appendChild(varNewHR); 
      }
   document.getElementsByTagName("body").item(0).appendChild(varNewDiv); 
   varNewDiv = document.createElement("div"); 
   varNewDiv.setAttribute("id", "myPopMask"); 
   varNewDiv.onclick = ClosePopupWindow; 
   document.getElementsByTagName("body").item(0).appendChild(varNewDiv); 
   Set_Popup_Mask(); 
   if(WidthAndHeight) {
      _WidthSetting = WidthAndHeight.indexOf("w"); 
      _HeightSetting = WidthAndHeight.indexOf("h"); 
      _ActualWidth = WidthAndHeight.slice(_WidthSetting + 1, _HeightSetting); 
      _ActualHeight = WidthAndHeight.slice(_HeightSetting + 1); 
      }
   else {
      _ActualWidth = "576"; 
      _ActualHeight = "375"; 
      }
   if(IsURLpopup) {
      _NewURLpopup = document.createElement("iframe"); 
      _NewURLpopup.setAttribute("id", "myPopElement"); 
      _NewURLpopup.setAttribute("src", PopupSource);
      _NewURLpopup.width = _ActualWidth; 
      _NewURLpopup.height = _ActualHeight; 
      _NewURLpopup.frameBorder = 0; 
      _NewURLpopup.marginWidth = 0; 
      _NewURLpopup.scrolling = "auto"; 
      _NewURLpopup.style.backgroundColor = "white"; 
      document.getElementById("myPopContainer").appendChild(_NewURLpopup); 
      Position_Popup_Window(); 
      }
   else {
      _NewIMGpopup = document.createElement("img"); 
      _NewIMGpopup.setAttribute("id", "myPopElement"); 
      if(PopupTitle) {
         _NewIMGpopup.setAttribute("title", PopupTitle); 
         _NewIMGpopup.setAttribute("alt", PopupTitle); 
         }
      _NewIMGpopup.onload = Position_Popup_Window; 
      _NewIMGpopup.setAttribute("src", PopupSource); 
      document.getElementById("myPopContainer").appendChild(_NewIMGpopup); 
      }
   }
function Position_Popup_Window() {
   if(document.getElementById("myPopElement")) {
      _OffsetHeight = document.getElementById("myPopContainer").offsetHeight; 
      _OffsetWidth = document.getElementById("myPopContainer").offsetWidth; 
      _PUwidth = (document.documentElement.clientWidth / 2) - (_OffsetWidth / 2); 
      _PUheight = (document.documentElement.clientHeight / 2) - (_OffsetHeight / 2); 
      _PUheight = _PUheight + document.documentElement.scrollTop; 
      document.getElementById("myPopContainer").style.left = _PUwidth + "px"; 
      document.getElementById("myPopContainer").style.top = _PUheight + "px"; 
      Create_Popup_Footer(); 
      Set_Backgroud_FadeOut("myPopContainer", 0, 100, 100); 
      Set_Backgroud_FadeOut("myPopMask", 0, 80, 100); 
      }
   else {
      setTimeout(Position_Popup_Window, 500); 
      }
   }
function Set_Popup_Mask() {
   _width = document.documentElement.clientWidth; 
   _height = document.documentElement.clientHeight; 
   if(document.documentElement.scrollHeight > _height)_height = document.documentElement.scrollHeight; 
   document.getElementById("myPopMask").style.width = _width + "px"; 
   document.getElementById("myPopMask").style.height = _height + "px"; 
   document.getElementById("myPopMask").style.left = "0"; 
   }
function Create_Popup_Footer() {
   varNewDiv = document.createElement("div"); 
   varNewDiv.setAttribute("id", "myPopFooter"); 
   varNewDiv.style.width = document.getElementById("myPopElement").offsetWidth + "px"; 
   _newUL = document.createElement("ul"); 
   _newLI = document.createElement("li"); 
   _newHYP = document.createElement("a"); 
   _newHYP.setAttribute("href", "#"); 
   _newHYP.onclick = ClosePopupWindow; 
   _newHYP.appendChild(document.createTextNode("X")); 
   _newLI.appendChild(_newHYP); 
   _newUL.appendChild(_newLI); 
   varNewDiv.appendChild(_newUL); 
   document.getElementById("myPopContainer").appendChild(varNewDiv); 
   }
function Set_Backgroud_FadeOut(varElementName, varFadeIncrement, negmR, varFO_1) {
   var _Value1 = Math.round(varFO_1 / 100); 
   var _intB = 0; 
   if(varFadeIncrement > negmR) {
      for(varInt = varFadeIncrement; varInt >= negmR; varInt--) {
         setTimeout("Set_Backgroud_Opacity(" + varInt + ",'" + varElementName + "')", (_intB * _Value1)); 
         _intB++; 
         }
      }
   else if(varFadeIncrement < negmR) {
      for(varInt = varFadeIncrement; varInt <= negmR; varInt++) {
         setTimeout("Set_Backgroud_Opacity(" + varInt + ",'" + varElementName + "')", (_intB * _Value1)); 
         _intB++; 
         }
      }
   }
function Set_Backgroud_Opacity(varBackgroudOpacity, varElementName) {
   var _NewStyle = document.getElementById(varElementName).style; 
   _NewStyle.opacity = (varBackgroudOpacity / 100); 
   _NewStyle.filter = "alpha(opacity=" + varBackgroudOpacity + ")"; 
   }
var _IsLoading = window.onload; 
window.onload = function() {
   if(_IsLoading)_IsLoading(); 
   DetectPopUpType(); 
   }


