// JavaScript Document

// Script Source: CodeLifter.com
// Copyright 2003

var popup_dragging = false;
var popup_target;
var popup_mouseX;
var popup_mouseY;
var popup_mouseposX;
var popup_mouseposY;
var popup_oldfunction;


function popup_mousedown(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

function popup_mousedown_window(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  if ( ie && window.event.button != 1) return;
  if (!ie && e.button            != 0) return;

  popup_dragging = false;
  popup_target   = this['target'];
  popup_mouseX   = ie ? window.event.clientX : e.clientX;
  popup_mouseY   = ie ? window.event.clientY : e.clientY;

  if (ie)
       popup_oldfunction = document.onselectstart;
  else popup_oldfunction = document.onmousedown;

  if (ie)
       document.onselectstart = new Function("return false;");
  else document.onmousedown   = new Function("return false;");
}


function popup_mousemove(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);
  var mouseX  = ie ? window.event.clientX : e.clientX;
  var mouseY  = ie ? window.event.clientY : e.clientY;

  if (!popup_dragging) return;

  element.style.left = (element.offsetLeft+mouseX-popup_mouseX)+'px';
  element.style.top  = (element.offsetTop +mouseY-popup_mouseY)+'px';

  popup_mouseX = ie ? window.event.clientX : e.clientX;
  popup_mouseY = ie ? window.event.clientY : e.clientY;
}

function popup_mouseup(e)
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById(popup_target);

  if (!popup_dragging) return;

  popup_dragging = false;

  if (ie)
       document.onselectstart = popup_oldfunction;
  else document.onmousedown   = popup_oldfunction;
}

function popup_exit()
{
  var ie      = navigator.appName == "Microsoft Internet Explorer";
  var element = document.getElementById('popup');
  var popcover      = document.getElementById('popcover');
  popcover.style.display='none';

//  popup_mouseup(e);
  element.style.display = 'none';
}

function appendElement(node,tag,id,classname,htm) {
  var ne = document.createElement(tag);
  if(id) ne.id=id;
  if(classname) ne.className=classname;
  if(htm) ne.innerHTML = htm;
  node.appendChild(ne);
}


function popup_show(id, drag_id, exit_id, position, x, y, position_id, aframeurl)
{

  if (document.getElementById(id)) {
    el = document.getElementById(id);
    el.parentNode.removeChild(el);
  }

  if (document.getElementById('popcover')) {
    el = document.getElementById('popcover');
    el.parentNode.removeChild(el);
  }
  
        appendElement(document.body,'div','popcover','popcover','&nbsp;');

        var popcover      = document.getElementById('popcover');
        popcover.onclick = popup_exit;
	      zBrowser=(navigator.userAgent).toUpperCase();
	       if(zBrowser.indexOf('MSIE')!=-1||zBrowser.indexOf('NETSCAPE')!=-1||zBrowser.indexOf('SAFARI')!=-1||zBrowser.indexOf('FIRE')!=-1||zBrowser.indexOf('CAMINO')!=-1){

          appendElement(document.body,'div','popup','popup','<IFRAME NAME="SubContentFrame" ID="SubContentFrame" allowtransparency="true" background-color="transparent" style="background-color:transparent;" WIDTH="550" HEIGHT="315" SRC="about:blank" SCROLLING=auto ALIGN="CENTER" NORESIZE frameborder=0 marginheight=0 marginwidth=0></IFRAME><br /><a href="JavaScript:popup_exit();" style="color:white;font-weight:bold;font-family:arial;font-size:12px;">CLOSE [X]</a>');
	       }
	       else{
          appendElement(document.body,'div','popup','popup','<LAYER ID="SubContentFrame" NAME="SubContentFrame" allowtransparency="true" background-color="transparent" style="background-color:transparent;" SRC="about:blank" WIDTH="550" HEIGHT="315" frameborder=0 marginheight=0 marginwidth=0 ALIGN="CENTER" scrolling=auto></LAYER><br /><a href="JavaScript:popup_exit();" style="color:white;font-weight:bold;font-family:arial;font-size:12px;">CLOSE [X]</a>');
	       }



  var element      = document.getElementById(id);
//  var drag_element = document.getElementById(drag_id);
//  var exit_element = document.getElementById(exit_id);
//  var popcover      = document.getElementById('popcover');

  var width        = window.innerWidth  ? window.innerWidth  : document.body.clientWidth;
  var height       = window.innerHeight ? window.innerHeight : document.body.clientHeight;

  popcover.style.position='absolute';
  popcover.style.display='block';
  popcover.style.top='0px';
  popcover.style.left='0px';
  popcover.style.width='100%';
  popcover.style.height=document.body.scrollHeight;


  element.style.position = "absolute";
  element.style.display  = "block";

  if (position == "element" || position == "element-right" || position == "element-bottom")
  {
    var position_element = document.getElementById(position_id);

    for (var p = position_element; p; p = p.offsetParent)
      if (p.style.position != 'absolute')
      {
        x += p.offsetLeft;
        y += p.offsetTop;
      }

    if (position == "element-right" ) x += position_element.clientWidth;
    if (position == "element-bottom") y += position_element.clientHeight;

    element.style.left = x+'px';
    element.style.top  = y+'px';
  }

  if (position == "screen-center")
  {

    element.style.left = (document.body.scrollLeft+(width -element.clientWidth )/2+x)+'px';
    element.style.top  = (document.body.scrollTop +(height-element.clientHeight)/2+y)+'px';
    if ((document.body.scrollTop +(height-element.clientHeight)/2+y)<0) {
      element.style.top='0px';
    }
    if ((document.body.scrollLeft+(width -element.clientWidth )/2+x)<0) {
      element.style.left='0px';
    }
  }

//  drag_element['target']   = id;
//  drag_element.onmousedown = popup_mousedown_window;

//  exit_element.onclick     = popup_exit;
  document.getElementById('SubContentFrame').src=aframeurl;

}


if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousedown', popup_mousedown);
else document.addEventListener('mousedown', popup_mousedown, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmousemove', popup_mousemove);
else document.addEventListener('mousemove', popup_mousemove, false);

if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent   ('onmouseup', popup_mouseup);
else document.addEventListener('mouseup', popup_mouseup, false);


PositionX = 0;
PositionY = 0;
defaultWidth  = 800;
defaultHeight = 561;
var AutoClose = false;
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=auto,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=auto,width=200,height=50,left='+PositionX+',top='+PositionY;



function openPopup(aframeurl) {
  zBrowser=(navigator.userAgent).toUpperCase();
  zPlatform=(navigator.platform).toUpperCase();
  if (zBrowser.indexOf('MSIE')!=-1 && zPlatform.indexOf('MAC')!=-1) {
	 window.open(aframeurl, "_popup", "width=800,height=600,scrollbars=yes,scrollbar=yes,address=no");		
  }
  else {
    popup_show('popup', 'popup_drag', 'popup_exit', 'screen-center',0,0,'', aframeurl);
  }

}
