

var theZindex = 1000;

// Browser safe opacity handling function

function setOpacity(winID,value) {
 document.getElementById(winID).style.opacity = value / 10;
 document.getElementById(winID).style.filter = 'alpha(opacity=' + value * 10 + ')';
}

function fadeInMyPopup(winID) {
 for( var i = 0 ; i <= 100 ; i++ )
   setTimeout( 'setOpacity("' + winID + '",' + (i / 10) + ')' , 3 * i );
}

function fadeOutMyPopup(winID) {
 for( var i = 0 ; i <= 100 ; i++ ) {
   setTimeout('setOpacity("' + winID + '",' + (10 - i / 10) + ')' , 3 * i);
 }

 setTimeout('closeMyPopup("' + winID + '")', 300 );
}

function closeMyPopup(winID) {
 document.getElementById(winID).style.display = "none"
}

function fireMyPopup(winID,thewidth,theheight) {

// Determine how much the visitor had scrolled

var scrolledX, scrolledY;
if( self.pageYOffset ) {
  scrolledX = self.pageXOffset;
  scrolledY = self.pageYOffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
  scrolledX = document.documentElement.scrollLeft;
  scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
  scrolledX = document.body.scrollLeft;
  scrolledY = document.body.scrollTop;
}

// Determine the coordinates of the center of the page

var centerX, centerY;
if( self.innerHeight ) {
  centerX = self.innerWidth;
  centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
  centerX = document.documentElement.clientWidth;
  centerY = document.documentElement.clientHeight;
} else if( document.body ) {
  centerX = document.body.clientWidth;
  centerY = document.body.clientHeight;
}

var leftOffset = scrolledX + (centerX - thewidth) / 2;
var topOffset = scrolledY + (centerY - theheight) / 2;

 setOpacity(winID,0);
 theZindex++;
 document.getElementById(winID).style.zIndex = theZindex;
 document.getElementById(winID).style.width = thewidth + "px";
 document.getElementById(winID).style.height = theheight + "px";
 document.getElementById(winID).style.top = topOffset + "px";
 document.getElementById(winID).style.left = leftOffset + "px";
 document.getElementById(winID).style.display = "block";
 fadeInMyPopup(winID);
}

