var popupDiv={
imagefiles:[
'images/min.gif',
'images/close.gif',
'images/restore.gif',
'images/resize.gif',
'images/trans_close.gif'
], //Path to 4 images used by script, in that order

width:0,
height:0,
movetype : 0,
detail : 0,
resizeWin : 0,
showcontrols : 1,
minimizeorder: 0,
color : "#0000FF",
retFxn: "",
zIndexvalue:1000,
tobjects: [], //object to contain references to dhtml window divs, for cleanup purposes
lastactivet: {}, //reference to last active DHTML window

init:function(t){

    var domwindow=document.createElement("div"); //create dhtml window div
    domwindow.id=t;
    domwindow.className="popupDiv";
  with ( domwindow.style ){
    position="absolute";
    display="none";
    backgroundColor="#F8F8F8";
    height=this.height +"px";
    width=this.width +"px";
  }
    var domwindowdata='';
  domwindowdata+='<iframe class="drag-shim" style="position:absolute;top:0;left:0;z-index:1" scrolling="no" frameborder="0"></iframe>';
  domwindowdata+='<div class="drag-container" style="position:relative;z-index:100">';
    domwindowdata+='<div class="drag-handle" >';
    domwindowdata+=     'DHTML Window';
  domwindowdata+=     '<div class="drag-controls" style="position:absolute;z-index:150">';
  if (this.detail) domwindowdata+=                 '<img class="drag-close" src="'+this.imagefiles[4]+'" title="Close" />';
     else domwindowdata+=                 '<img class="close" src="'+this.imagefiles[1]+'" title="Close" />';
    domwindowdata+=     '</div>';
    domwindowdata+='</div>';
    domwindowdata+=     '<div class="drag-contentarea" style="clear:both"></div>';
  domwindowdata+=           '<div class="drag-resizearea" style="position:relative;z-index:100;width:20px;float:right;width:16px !important;cursor:nw-resize;background: transparent url('+this.imagefiles[3]+') center right no-repeat;">&nbsp;</div>';
  domwindowdata+=     '</div>';
  domwindowdata+='</div>';
  domwindowdata+='</div>';
    domwindow.innerHTML=domwindowdata;
    document.body.appendChild(domwindow);
    //this.zIndexvalue=(this.zIndexvalue)? this.zIndexvalue+1 : 100 //z-index value for DHTML window: starts at 0, increments whenever a window has focus
    var t=document.getElementById(t);
    var divs=t.getElementsByTagName("div");
    for (var i=0; i<divs.length; i++){ //go through divs inside dhtml window and extract all those with class="drag-" prefix
        if (/drag-/.test(divs[i].className))
            t[divs[i].className.replace(/drag-/, "")]=divs[i]; //take out the "drag-" prefix for shorter access by name
    }
    var imgs=t.getElementsByTagName("img");
    for (var i=0; i<imgs.length; i++){ //go through frms inside dhtml window and extract all those with class="drag-" prefix
        if (/drag-/.test(imgs[i].className))
            t[imgs[i].className.replace(/drag-/, "")]=imgs[i]; //take out the "drag-" prefix for shorter access by name
    }
    var frms=t.getElementsByTagName("iframe");
    for (var i=0; i<frms.length; i++){ //go through frms inside dhtml window and extract all those with class="drag-" prefix
        if (/drag-/.test(frms[i].className))
            t[frms[i].className.replace(/drag-/, "")]=frms[i]; //take out the "drag-" prefix for shorter access by name
    }
  with (t.container.style){
        border="2px solid " + this.color;
        if ( !this.showcontrols ) border="1px solid #666666";
        backgroundColor="#dddddd";
  }
  with (t.handle.style){
      padding="2px 0 3px 0";
      if (this.detail) textIndent="4px"; else textIndent="8px";
      font="bold 12px/1em Arial";
      backgroundColor=this.color;
      color="white";
      overflow="hidden";
      width="auto";
      height="16px";
  }

  with (t.controls.style){
      position="absolute";
      right="1px";
      top="2px";
      height="16px";
  }

  with (t.contentarea.style){
      backgroundColor="white";
      color="black";
      padding="2px";
      overflow="auto";
  }

  with (t.resizearea.style){
      if ( !this.resizeWin ) display="none";
      else {
          backgroundColor="#F8F8F8";
          height="16px";
          if (ie) backgroundPosition="center right";
             else backgroundPosition="bottom right";
      }
  }

  if (this.detail){
     var tStyle = t.handle.style;
     tStyle.background="#3f93f9";
     with (t.container.style){
        border="4px solid #3f93f9";
        borderTop="2px solid #3f93f9";
     }
     var tStyle = t.contentarea.style;
     if (ie) {
        tStyle.borderTop="1px solid #3f93f9";
     }
  }

    //t.style.zIndex=this.zIndexvalue //set z-index of this dhtml window
    
    // Set ncHeight
    if ( !this.showcontrols )
	    t.ncHeight=6;
	else
	    t.ncHeight=parseInt(t.handle.style.height) + 13;
	if ( this.detail ) t.ncHeight += ((ie)?3:2);
	
    t.handle._parent=t; //store back reference to dhtml window
    t.resizearea._parent=t; //same
    t.controls._parent=t; //same
    t.container._parent=t; //same
    t.shim._parent=t; //same
    t.onclose=function(){
    return true;
  } //custom event handler "onclose"
//  t.onmousedown=function(){popupDiv.setfocus(this)} //Increase z-index of window when focus is on it
    t.handle.onmousedown=popupDiv.setupdrag; //set up drag behavior when mouse down on handle div
    t.resizearea.onmousedown=popupDiv.setupdrag; //set up drag behavior when mouse down on resize div
    t.controls.onclick=popupDiv.enablecontrols;
    t.show=function(){popupDiv.show(this);} //public function for showing dhtml window
    t.hide=function(){popupDiv.hide(this);} //public function for hiding dhtml window
    t.close=function(){popupDiv.close(this);} //public function for closing dhtml window (also empties DHTML window content)
    t.setSize=function(w, h){popupDiv.setSize(this, w, h);} //public function for setting window dimensions
    t.moveTo=function(x, y){popupDiv.moveTo(this, x, y);} //public function for moving dhtml window (relative to viewpoint)
    t.isResize=function(bol){popupDiv.isResize(this, bol);} //public function for specifying if window is resizable
    t.isScrolling=function(bol){popupDiv.isScrolling(this, bol);} //public function for specifying if window content contains scrollbars
    t.load=function(contenttype, contentsource, title){popupDiv.load(this, contenttype, contentsource, title);} //public function for loading content into window
    this.tobjects[this.tobjects.length]=t;
    return t; //return reference to dhtml window div
},

disableSelection:function(t) {
    t.onselectstart = function() {
        return false;
    };
    t.unselectable = "on";
    t.style.MozUserSelect = "none";
    t.style.cursor = "default";
},

open:function(t, contenttype, contentsource, title, attr, recalonload){

    var d=popupDiv; //reference dhtml window object
    var xpos;
  var ypos;
    function getValueInt(Name){
        var config=new RegExp(Name+"=([^,]+)", "i"); //get name/value config pair (ie: width=400px,)
        return (config.test(attr))? parseInt(RegExp.$1) : 0; //return value portion (int), or 0 (false) if none found
    }
    function getValueString(Name){
        var config=new RegExp(Name+"=([^,]+)", "i"); //get name/value config pair
        return (config.test(attr))? RegExp.$1 : ''; //return value portion (string), or null if
    }
    this.detail=getValueInt("detail");
    this.showcontrols=getValueInt("controls");
    this.resizeWin=getValueInt("resize");
    this.color=getValueString("color");
    this.retFxn=getValueString("retFxn");

    if (document.getElementById(t)==null)
        t=this.init(t); //return reference to dhtml window div
    else
    t=document.getElementById(t);
    xpos=getValueInt("center")? "middle" : getValueInt("left"); //Get x coord of window
    ypos=getValueInt("center")? "middle" : getValueInt("top"); //Get y coord of window
      t.style.height=getValueInt("height")+"px";
      t.style.width=getValueInt("width")+"px";
  t.setSize(getValueInt(("width")), (getValueInt("height"))); //Set dimensions of window
  this.setfocus(t);
    t.moveTo(xpos, ypos); //Position window
    if (typeof recalonload!="undefined" && recalonload=="recal" && this.scroll_top==0){ //reposition window when page fully loads with updated window viewpoints?
        if (window.attachEvent && !window.opera) //In IE, add another 400 milisecs on page load (viewpoint properties may return 0 b4 then)
            this.addEvent(window, function(){setTimeout(function(){t.moveTo(xpos, ypos);}, 400);}, "load");
        else
            this.addEvent(window, function(){t.moveTo(xpos, ypos)}, "load");
    }
    t.isResize(getValueInt("resize")); //Set whether window is resizable
    t.isScrolling(getValueInt("scrolling")); //Set whether window should contain scrollbars
    if ( !getValueInt("controls") ) {
       t.handle.style.display="none";
       t.contentarea.style.border="none";
    }
    t.style.visibility="visible";
    t.style.display="block";
    t.contentarea.style.display="block";
    t.load(contenttype, contentsource, title);
    t.scroll=document.getElementById("placeholder");
    if ( t.id=="VEMap" ) this.disableSelection(t);
    return t;
},

setSize:function(t, w, h){ //set window size (min is 100px wide by 10px tall)
    t.style.width=Math.max(parseInt(w), 20)+"px";
    t.contentarea.style.height=Math.max(parseInt(h),10)+"px";
    if ( !t.controls ) t.contentarea.style.height = "0px";
    t.shim.style.width=Math.max(parseInt(w), 20)+"px";
	  t.shim.style.height=(t.ncHeight+Math.max(parseInt(h),10))+"px";
},

moveTo:function(t, x, y){ //move window. Position includes current viewpoint of document
    this.getviewpoint(); //Get current viewpoint numbers
    t.style.left=(x=="middle")? (this.docwidth-parseInt(t.style.width))/2+"px" : this.scroll_left+parseInt(x)+"px";
    t.style.top=(y=="middle")? (this.docheight-parseInt(t.style.height))/2+"px" : this.scroll_top+parseInt(y)+"px";
},

isResize:function(t, bol){ //show or hide resize inteface
    t.resizeBool=(bol)? 1 : 0;
},

isScrolling:function(t, bol){ //set whether loaded content contains scrollbars
    t.contentarea.style.overflow=(bol)? "auto" : "hidden";
},

load:function(t, contenttype, contentsource, title){ //loads content into window plus set its title (3 content types: "inline", "iframe", or "ajax")
    if (t.isClosed){
        alert("DHTML Window has been closed, so no window to load contents into. Open/Create the window again.");
        return;
    }
    var contenttype=contenttype.toLowerCase(); //convert string to lower case
    if (typeof title!="undefined")
        t.handle.firstChild.nodeValue=title;
    if (contenttype=="inline")
        t.contentarea.innerHTML=contentsource;
    else if (contenttype=="div"){
        var inlinedivref=document.getElementById(contentsource);
        t.contentarea.innerHTML=(inlinedivref.defaultHTML || inlinedivref.innerHTML); //Populate window with contents of inline div on page
        if (!inlinedivref.defaultHTML)
            inlinedivref.defaultHTML=inlinedivref.innerHTML; //save HTML within inline DIV
        inlinedivref.innerHTML=""; //then, remove HTML within inline DIV (to prevent duplicate IDs, NAME attributes etc in contents of DHTML window
        inlinedivref.style.display="none"; //hide that div
    }
    else if (contenttype=="iframe"){
        t.contentarea.style.overflow="hidden"; //disable window scrollbars, as iframe already contains scrollbars
        if (!t.contentarea.firstChild || t.contentarea.firstChild.tagName!="IFRAME") //If iframe tag doesn't exist already, create it first
            t.contentarea.innerHTML='<iframe src="" frameborder="0" scrolling="no" style="margin:0; padding:0; width:100%; height: 100%" name="_iframe-'+t.id+'"></iframe>';
            window.frames["_iframe-"+t.id].location.replace(contentsource); //set location of iframe window to specified URL
        }
    else if (contenttype=="ajax"){
        this.ajax_connect(contentsource, t); //populate window with external contents fetched via Ajax
    }
    t.contentarea.datatype=contenttype; //store contenttype of current window for future reference
    t.contentarea.contentsource=contentsource;
},

setupdrag:function(e){
    var d=popupDiv; //reference dhtml window object
    var t=this._parent; //reference dhtml window div
    d.etarget=this; //remember div mouse is currently held down on ("handle" or "resize" div)
    if (!e) e=window.event;
    d.initmousex=e.clientX; //store x position of mouse onmousedown
    d.initmousey=e.clientY;
    d.initx=parseInt(t.offsetLeft); //store offset x of window div onmousedown
    d.inity=parseInt(t.offsetTop);
    d.width=parseInt(t.offsetWidth); //store width of window div
    d.contentheight=parseInt(t.contentarea.offsetHeight); //store height of window div's content div
    d.containerheight=parseInt(t.style.height);
    document.onmousemove=d.getdistance; //get distance travelled by mouse as it moves

    document.onmouseup=function(){
            t.contentarea.style.backgroundColor="white";
            t.contentarea.style.visibility="visible";
        d.stop(t);
    }
},

getdistance:function(e){
    var d=popupDiv;
    var etarget=d.etarget;
    if (!e) e=window.event;
    d.distancex=e.clientX-d.initmousex; //horizontal distance travelled relative to starting point
    d.distancey=e.clientY-d.initmousey;
    if (etarget.className=="drag-handle") //if target element is "handle" div
        d.move(etarget._parent, e);
    else if (etarget.className=="drag-resizearea"){ //if target element is "resize" div
        d.resize(etarget._parent, e);
        }
    return false; //cancel default dragging behavior
},

getviewpoint:function(){ //get window viewpoint numbers
    var ie=document.all && !window.opera;
    var domclientWidth=document.documentElement && parseInt(document.documentElement.clientWidth) || 100000; //Preliminary doc width in non IE browsers
    this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body; //create reference to common "body" across doctypes
    this.scroll_top=(ie)? this.standardbody.scrollTop : window.pageYOffset;
    this.scroll_left=(ie)? this.standardbody.scrollLeft : window.pageXOffset;
    this.docwidth=(ie)? this.standardbody.clientWidth : (/Safari/i.test(navigator.userAgent))? window.innerWidth : Math.min(domclientWidth, window.innerWidth-16);
    this.docheight=(ie)? this.standardbody.clientHeight: window.innerHeight;

},

move:function(t, e){
    t.style.left=popupDiv.distancex+popupDiv.initx+"px";
    t.style.top=popupDiv.distancey+popupDiv.inity+"px";
},

resize:function(t, e){
    nWid=nHt=10;
    var xdis=Math.max(popupDiv.width+popupDiv.distancex, nWid)+"px";
    t.contentarea.style.height=Math.max(popupDiv.contentheight+popupDiv.distancey, nHt)+"px";
    t.style.height=Math.max(popupDiv.containerheight+popupDiv.distancey,nHt)+"px";
    t.shim.style.width=t.style.width=xdis;
    if (ie) t.contentarea.style.width=parseInt(xdis)-4+"px";
    if ( t.map !== undefined && t.map!=null ){
      t.map.style.height=parseInt(t.style.height)-42+"px";
      t.map.style.height=popupDiv.mapheight+popupDiv.distancey+"px";
      t.scroll.style.width=parseInt(t.style.width)-(ie?68:64)+"px";
      t.scroll.style.overflow="hidden";
      t.shim.style.height=t.style.height;
    }
},

enablecontrols:function(e){
    var ie=document.all && !window.opera;
    var d=popupDiv;
    var sourceobj= (ie) ? window.event.srcElement : e.target; //Get element within "handle" div mouse is currently on (the controls)
    if (/Close/i.test(sourceobj.getAttribute("title"))) //if this is the "close" control
        d.close(this._parent);
    return false;
},

close:function(t){

    try{
        var closewinbol=t.onclose();
    }
    catch(err){ //In non IE browsers, all errors are caught, so just run the below
        var closewinbol=true;
 }
        if (typeof closewinbol=="undefined"){
            alert("An error has occured somwhere inside your \"onclose\" event handler");
            var closewinbol=true;
        }
    if (closewinbol){ //if custom event handler function returns true
        if (window.frames["_iframe-"+t.id]) //if this is an IFRAME DHTML window
            window.frames["_iframe-"+t.id].location.replace("about:blank");
        else
            t.contentarea.innerHTML="";
        t.style.display="none";
        t.isClosed=true; //tell script this window is closed (for detection in t.show())
        
        if ( !useVE && t.id === 'totdWin') {      
            var map = $find('GEMap');
            if ( map._bInitView ) map.init_view();
                else if ( !ge.getWindow().getVisibility() ) ge.getWindow().setVisibility(true);            
        }
        
        // If there is a close routine callback, then execute it
        if ( this.retFxn !== "" ) eval(this.retFxn);
    }
    return closewinbol;
},


setopacity:function(targetobject, value){ //Sets the opacity of targetobject based on the passed in value setting (0 to 1 and in between)
    if (!targetobject)
        { return; }
    if (targetobject.filters && targetobject.filters[0]){ //IE syntax
        if (typeof targetobject.filters[0].opacity=="number") //IE6
            targetobject.filters[0].opacity=value*100;
        else //IE 5.5
            targetobject.style.filter="alpha(opacity="+value*100+")";
        }
    else if (typeof targetobject.style.MozOpacity!="undefined") //Old Mozilla syntax
        targetobject.style.MozOpacity=value;
    else if (typeof targetobject.style.opacity!="undefined") //Standard opacity syntax
        targetobject.style.opacity=value;
},

setfocus:function(t){ //Sets focus to the currently active window
    this.zIndexvalue++;
    t.style.zIndex=this.zIndexvalue;
    t.isClosed=false; //tell script this window isn't closed (for detection in t.show())
    //this.setopacity(this.lastactivet.handle, 0.5) //unfocus last active window
    //this.setopacity(t.handle, 1) //focus currently active window
    this.lastactivet=t; //remember last active window
},


show:function(t){
    if (t.isClosed){
        alert("ERROR: Window closed.");
        return;
    }
    t.style.display="block";
    this.setfocus(t);
    t.state="fullview"; //indicate the state of the window as being "fullview"
},

hide:function(t){
    t.style.display="none";
},

stop:function(t){
    var d=popupDiv;
    document.onmousemove=null;
    document.onmouseup=null;

    if (d.distancex) {
    if (d.distancex!=0 && d.distancey!=0 ) { //if this is an IFRAME DHTML window
       if (d.etarget.className=="drag-resizearea"){
           var w=parseInt(t.style.width);
           detachEvents();
           initVE();
       }
       if (d.etarget.className=="drag-handle"){
          t.style.backgroundColor="white";
          t.contentarea.style.visibility="visible";
       }
    }
  }
  d.distancex=d.distancey=0;
  d.etarget=null; //clean up
},

addEvent:function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
    var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
    if (target.addEventListener)
        target.addEventListener(tasktype, functionref, false);
    else if (target.attachEvent)
        target.attachEvent(tasktype, functionref);
},

cleanup:function(){
    for (var i=0; i<popupDiv.tobjects.length; i++){
        popupDiv.tobjects[i].handle._parent=popupDiv.tobjects[i].resizearea._parent=
    popupDiv.tobjects[i].container._parent=popupDiv.tobjects[i].controls._parent=popupDiv.tobjects[i].shim._parent=null;
    }
    window.onload=null;
}

} //End popupDiv object

function closeAllPops(){
    var wins =  getElementsByClassName("popupDiv","div");
    for ( var i = 0; i < wins.length; ++i )
    {
        if ( wins[i] !== null )
        {
            if( !wins[i].isClosed )
            {
                if ( wins[i].id !== '' && 
                    wins[i].id !== 'totdWin' &&
                    wins[i].id !== 'tourWin'
                    )
                {
                    wins[i].close();
                    wins[i] = null;
                }
            }
        }
    }
}