var height = 300;
var width = 400;
var url = "http://www.bluefishhosting.com/cgi-bin/affiliates/clickthru.cgi?id=0catch&campaign=0catchpops";

var dialog = new popupDialog(height, width, url);
document.body.appendChild(dialog);
dialog.center();

document.onmousedown = dialog.startDrag;
document.onmousemove = dialog.dragMove;
document.onmouseup = dialog.endDrag;


function popupDialog(height, width, url) {
    var dialog = document.createElement("div");
    dialog.id = "0catchpopdiv";
    dialog.style.height	= height + "px";
    dialog.style.width = width + "px";
    dialog.style.border = "#333333 1px solid";
    dialog.style.position = "absolute";
    
    var html = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
    html += "<tr>";
    html += "<td id=\"dragHere\" height=\"30px\" align=\"right\" style=\"background-color: #336699; cursor: move; border-bottom: #333333 1px solid;\">";
    html += "<input type=\"button\" value=\"  +  \" onClick=\"dialog.maximize(this)\" style=\"margin: 5px; cursor: pointer;\" title=\"Maximize\">";
    html += "<input type=\"button\" value=\"  x  \" onClick=\"dialog.close()\" style=\"margin: 5px; cursor: pointer;\" title=\"Close\">";
    html += "</td>";
    html += "</tr>";
    html += "</table>";
    html += "<iframe src=\"" + url + "\" style=\"width:100%; height:100%;\" frameborder=\"no\"></iframe>";
    
    dialog.innerHTML = html;
    
    dialog.center = function () {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	} else if( document.documentElement &&
		   ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	}
	var newLeft = myWidth/2 - width/2;
	var newTop = myHeight/3 - height/2;
        newTop = newTop + 100;
	this.style.left = newLeft + "px";
	this.style.top = newTop + "px";
    }
	
    dialog.maximize = function (el) {
	this.style.left	= "0";
	this.style.top = "0";
	this.style.width = "100%";
	this.style.height = "100%";
	el.value = "  -  ";
	el.onclick = function() { dialog.minimize(el) };
	el.title = "Minimize";
    }
	
    dialog.minimize = function (el) {
	this.style.width = width + "px";
	this.style.height = height + "px";
	el.value = "  +  ";
	el.onclick = function() { dialog.maximize(el) };
	el.title = "Maximize";
	this.center();
    }
	
    dialog.close = function () {
	document.body.removeChild(this);
    }
    
    dialog.startDrag = function(event) {
	var src;
	if (!event) var event = window.event;
	if (document.all) src = event.srcElement; else src = event.target;
	if (src.id == "dragHere") {
	    dialog.drag = true;
	    if (document.all) {
		dialog.X = event.offsetX;
		dialog.Y = event.offsetY;
	    }
	    else {
		dialog.X = event.layerX;
		dialog.Y = event.layerY;
	    }
	}
    }
    
    dialog.dragMove = function(event) {
	if (dialog.drag) {
	    if (!event)
		event = window.event;
	    dialog.style.left = (event.clientX - dialog.X) + "px";
	    dialog.style.top = (event.clientY - dialog.Y) + "px";
	}
    }
	
    dialog.endDrag = function() {
	dialog.drag = false;
	dialog.X = undefined;
	dialog.Y = undefined;
    }
	
    return dialog;
}
