webm_dialog = {
	stack: new Array(),
	return_page: null,
	hide_listener: null,
	hide_listener_dialog_id: null
};

/*
function dialog_lblock_show(param) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

//  if (w == null) w = 400;
//  if (h == null) h = 200;
w = 400;
h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
        y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
        y = (window_height - h) / 2 + window.pageYOffset;
  else
        y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog_lblock_layer");
  d.style.position = "absolute";
  d.style.left = 0;
  d.style.top = 0;
  d.style.width = document.body.scrollWidth+"px";
  d.style.height = dialog_compute_height()+"px";
  d.style.display = "";

  d.style.zIndex = 3;
  //d.style.display = "block";

  d = g("dialog_lblock_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  d.style.display = "";
  d.style.border = "1px solid #aaaaaa";

  d.style.left = "120px";
  d.style.top = "50px";
  d.style.width = "540px";
  d.style.height = "385px";
  d.style.zIndex = 4;
  d.style.display = "";
  //d.style.display = "block";

  d = g("dialog_lblock_body");
  d.innerHTML=("<iframe src=/webm/glearnblock.php?blockid="+param+" width=530 height=350 frameborder=0 scrolling=no></iframe>");
}
function dialog_lblock_hide() {
  d = g("dialog_lblock_window");
  d.style.display = "none";

  d = g("dialog_lblock_layer");
  d.style.display = "none";
}
function dialog_lblock_drag() {
}
*/

function dialog_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
	window_width = document.body.offsetWidth;
	window_height = document.body.offsetHeight;
  }
  else {
	window_width = window.innerWidth;
	window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog_header");
  d.innerHTML = title;

  d = g("dialog_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(1);
}

function dialog_hide() {
  return dialog_common_hide();
}

function dialog2_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog2_header");
  d.innerHTML = title;

  d = g("dialog2_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog2_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

webm_dialog.stack.push(2);
}

function dialog2_hide() {
  return dialog_common_hide();
}

function dialog3_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog3_header");
  d.innerHTML = title;

  d = g("dialog3_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog3_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(3)
}

function dialog3_hide() {
  return dialog_common_hide();
}

function dialog4_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog4_header");
  d.innerHTML = title;

  d = g("dialog4_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog4_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(4)
}

function dialog4_hide() {
  return dialog_common_hide();
}

function dialog5_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog5_header");
  d.innerHTML = title;

  d = g("dialog5_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog5_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(5)
}

function dialog5_hide() {
  return dialog_common_hide();
}

function dialog6_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog6_header");
  d.innerHTML = title;

  d = g("dialog6_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog6_window");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = "100%";
  d.style.height = "100%";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(6);
}

function dialog6_hide() {
  return dialog_common_hide();
}

function dialog7_show(title,w,h) {
  var window_width;
  var window_height;
  if (browser.isIE) {
        window_width = document.body.offsetWidth;
        window_height = document.body.offsetHeight;
  }
  else {
        window_width = window.innerWidth;
        window_height = window.innerHeight;
  }

  if (title == null) title = "Popup Window";
  if (w == null) w = 400;
  if (h == null) h = 200;

  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  d = g("dialog7_header");
  d.innerHTML = title;

  d = g("dialog7_layer");
  d.style.position = "absolute";
  d.style.left = "0px";
  d.style.top = "0px";
  d.style.width = document.body.scrollWidth + "px";
  d.style.height = dialog_compute_height() + "px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.zIndex = 10;

  d = g("dialog7_window");
  d.style.position = "absolute";
  d.style.left = x + "px";
  d.style.top = y + "px";
  d.style.width = w+"px";
  d.style.height = h+"px";
  //d.style.display = "block";
  d.style.visibility = "visible";
  d.style.border = "1px solid #aaaaaa";
  d.style.zIndex = 10;

  webm_dialog.stack.push(7)
}

function dialog7_hide() {
  return dialog_common_hide();
}

function dialog_common_hide() {
  if (webm_dialog.stack != null) {
    _dno = webm_dialog.stack.pop();
    if (_dno == 1) _dno = "";

    d = g("dialog"+_dno+"_window");
//    d.style.display = 'none';
	d.style.visibility = 'hidden';
	d.style.width = "1px";
	d.style.height = "1px";

    d = g("dialog"+_dno+"_layer");
//    d.style.display = 'none';
	d.style.visibility = 'hidden';

    d = g("dialog"+_dno+"_body");
//if (_dno != 6)

    if (webm_dialog.hide_handler != null &&
    	webm_dialog.hide_handler_dialog_id == webm_dialog.stack[webm_dialog.stack.length -1]) {
    	eval(webm_dialog.hide_handler);
    	webm_dialog.hide_handler = null;
    	webm_dialog.hide_handler_dialog_id = null;
    }

    d.innerHTML='';
    
  }
}

var stored_width = 0;
function dialog_common_makecenter(foreDiv, bgDiv)
{
  if (!foreDiv || !bgDiv) return;
//  if (foreDiv.style.display == "none" || bgDiv.style.display == "none") return;
  if (foreDiv.style.visibility == "hidden" || bgDiv.style.visibility == "hidden") return;

  var window_width = (browser.isIE) ? document.body.clientWidth : window.innerWidth;
  var window_height = (browser.isIE) ? document.body.clientHeight : window.innerHeight;
  
  var w = parseInt(foreDiv.style.width, 10); 
  var h = parseInt(foreDiv.style.height, 10);
  
  // center the dialog
  x = (window_width - w) / 2;
  if (browser.isIE)
	y = (window_height - h) / 2 + document.body.scrollTop;
  else if (browser.isNS)
	y = (window_height - h) / 2 + window.pageYOffset;
  else 
	y = (window_height - h) / 2;
  if (y < 10) y = 10;

  foreDiv.style.position = "absolute";
  foreDiv.style.top = y + "px";
  foreDiv.style.left = x + "px";
  foreDiv.style.width = w + "px";
  foreDiv.style.height = h + "px";
  
  bgDiv.style.position = "absolute";
  bgDiv.style.left = "0px";
  bgDiv.style.top = "0px";
  bgDiv.style.width = document.body.scrollWidth + "px";
  bgDiv.style.height = dialog_compute_height() + "px";
  bgDiv.style.zIndex = 10;
}

function dialog_compute_height()
{
	var window_height = (browser.isIE) ? document.body.clientHeight : window.innerHeight;
	return (document.body.scrollHeight > window_height)
		? document.body.scrollHeight
		: window_height;
}

// set the hide handler of the next to-be-opened dialog.
function dialog_set_next_hide_handler(js_handler) {
	webm_dialog.hide_handler = js_handler;
	did = webm_dialog.stack[webm_dialog.stack.length -1];
	webm_dialog.hide_handler_dialog_id = did;
}

function resizeAllDialogs()
{
	dialog_common_makecenter(g('dialog_window'), g('dialog_layer'));
	dialog_common_makecenter(g('dialog2_window'), g('dialog2_layer'));
	dialog_common_makecenter(g('dialog3_window'), g('dialog3_layer'));
	dialog_common_makecenter(g('dialog4_window'), g('dialog4_layer'));
	dialog_common_makecenter(g('dialog5_window'), g('dialog5_layer'));
//	dialog_common_makecenter(g('dialog6_window'), g('dialog6_layer'));
}

/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

var Drag = {

	obj : null,
	
	smartinit : function (o, oRoot)
	{
		this.init(o, oRoot, 0, null, 0, null);
		o.onmouseover = function() { o.style.cursor = 'move';};
		o.onmouseout = function() { o.style.cursor = '';};
	},

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};