function popup (width, height, id, name, title) {
	this.width = width;
	this.height = height;
	this.id = id;
	this.name = name;
	this.title = title;
	this.init = init;
	this.set_title = set_title;
	this.get_title = get_title;
	this.set_id = set_id;
	this.get_id = get_id;
	this.set_name = set_name;
	this.get_name = get_name;
	this.pop_minimize = pop_minimize;
	this.pop_maximize = pop_maximize;
	this.pop_exit = pop_exit;
	this.traverse = traverse;
	this.toString = toString;
	//this.is_ie = is_ie;
}

function init (guts, amenu) {

	var p = document.createElement ('div');
	p.style.position = "absolute";
	//p.style.backgroundColor = "#FFFFFF";

	var xmenu = "";

	with (this) {
		p.id = (id != "" ? id : "foo");
		p.width = (width > 0 ? width : 400);
		p.height = (height > 0 ? height : 400);
		p.style.width = String (width) + "px";
		p.style.height = String (height) + "px";
                p.style.left = String (screen.availWidth / 2 - p.width / 2) + "px";
	        p.style.top = String (screen.availHeight / 2 - p.height / 2) + "px";
	        p.style.visibility = "visible";
	        p.style.zIndex = 999999;
                p.innerHTML = "foobarbaz";
                
                //alert (p);
		var xptr = "document.getElementById ('" + id + "')";
		
		//alert (xptr);

		xmenu += ("<table class = \"ptable\" id = \"ptable\">\n");
		xmenu += ("<tr id = \"ptrcmd\">\n");
		xmenu += ("<td id = \"pcmd_area\" class = \"pcmd_area\" valign = \"top\">\n");
		xmenu += ("<div id = \"picon\" class = \"picon\" onmousedown = \"javascript:pop_drag_trigger (" + xptr + ", event);\" onmouseup = \"javascript:pop_nodrag (" + xptr + ", event);\" onmouseout = \"javascript:pop_nodrag (" + xptr + ", event);\"></div>\n");
		xmenu += ("<div id = \"ptitle\" class = \"ptitle\"><span>&nbsp;&nbsp;&nbsp;</span><span>" + title + "</span></div>\n");
		xmenu += ("<div id = \"cmd_std\" class = \"cmd_std\">\n");
                xmenu += ("<input type = \"button\" id = \"cmd_min\" name = \"cmd_min\" class = \"popcmd\" value = \"_\" onclick = \"javascript:pop_minimize ();\" />\n");
		xmenu += ("<input type = \"button\" id = \"cmd_max\" name = \"cmd_max\" class = \"popcmd\" value = \"+\" onclick = \"javascript:pop_maximize ();\" />\n");
		xmenu += ("<input type = \"button\" id = \"cmd_exit\" name = \"cmd_exit\" class = \"popcmd\" value = \"X\" onclick = \"javascript:pop_exit (" + xptr + ");\" />\n");
		xmenu += ("</div>\n");
                xmenu += ("</td>\n");
		xmenu += ("<tr id = \"rmenu_area\">\n");
		xmenu += ("<td id = \"pmenu_area\" class = \"pmenu_area\" valign = \"top\">\n");
                xmenu += ("<div id = \"pmenu\" class = \"pmenu\">\n");
                xmenu += (amenu);
                xmenu += ("</div>\n");
                xmenu += ("</td>\n");
		xmenu += ("</tr>\n");
		xmenu += ("</tr>\n");
		xmenu += ("<tr id = \"ptrmain\">\n");
		xmenu += ("<td id = \"ptmain\" class = \"ptmain\">\n");
		xmenu += ("<div id = \"popmain\" class = \"popmain\" align = \"center\">\n");
		xmenu += (guts);
		xmenu += ("</div>\n");
		xmenu += ("</td>\n");
		xmenu += ("</tr>\n");
		xmenu += ("</table>\n");

	}
        	

	p.innerHTML = xmenu;

	var tmppop = document.createElement ('div');
	tmppop.appendChild (p);

	return tmppop.innerHTML;
	//alert (document.body.childNodes.length);
        //document.body.insertBefore (p, document.body.childNodes[0]);
        //var droot = (is_ie () ? document.body : document.documentElement.childNodes[1]);
        //alert (droot.childNodes[1]);
        //droot.insertBefore (p, droot.childNodes[0]);
}


function set_title (title) {
	this.title = title;
}

function get_title () {
	return this.title;
}

function set_id (id) {
	this.id = id;
}

function get_id () {
	return this.id;
}

function set_name (name) {
	this.name = name;
}

function get_name () {
	return this.name;
}

function pop_minimize () {

         var ptrms = document.getElementById ('ptrmain').style;

         try {
             ptrms.visibility = "collapse";
             ptrms.display = "none";
         } catch (ex) {
             ptrms.display = "none";
             //ptrms.visibility = "hidden";
         }
}

function pop_maximize () {

	var ptrms = document.getElementById ('ptrmain').style;
        ptrms.display = "";
        ptrms.visibility = "visible";
}

function pop_exit (pPtr) {

	//with (this) {
	     pPtr.style.display = "none";
	//}
}

function traverse (n, mtree, nx) {
	var x = n.childNodes;
	//var mtree = "";

	if (x.length <= 0) { alert (mtree); return; }

	//alert (mtree);

	for (var i = 0; i < x.length; i++) {
		if (x[i].nodeType == 3) { continue; }
		mtree += ((nx > 0 ? "\t" : "") + "+" + x[i].nodeName + "\t" + x[i].nodeType + "\n\n");
		traverse (x[i], mtree, (nx + 1));
	}

}

function toString (pPtr) {
	alert (pPtr.innerHTML);
}

function is_ie () {

         var bn = navigator.appName;
         return (bn.match (/netscape/i) == null);

}

