function methodize(func, scope)
{
    return (function() { func.call(scope); });
}

function msgWin(id, title, msg, buttonText, parent, xPos, yPos)
{
	this.id = id;
	this.title = title;
	this.msg = msg;
	this.parent = parent;
	this.left = xPos;
	this.top = yPos;
	
	this.buttonText = buttonText;
	
	this.moving = 0;
	this.offsetLeft = 0;
	
	this.create();
}


msgWin.prototype.create = function()
{
	var w = document.createElement('div');
	w.id = this.id;
	w.style.width = '457px';
	w.style.border = '0px solid #000';
	w.style.position = 'absolute';
	
	if(!this.left)
	{
		w.style.left = '50%';
		w.style.top = '50%';
		w.style.marginLeft = '-150px';
		w.style.marginTop = '-50px';
	}
	else
	{
		w.style.left = this.left+'px';
		w.style.top = this.top+'px';
	}
	
	var t = document.createElement('div');
	t.id = this.id+'_title';
	t.style.borderBottom = '0px dashed #000';
	t.style.textAlign = 'center';
	t.style.fontWeight = 'bold';
	t.style.fontSize = '16px';
	t.innerHTML = this.title;
	//t.style.background = '#628db4';
//	t.onmouseover = function() {this.style.cursor = 'move';};
//	t.onmousedown = methodize(this.startMove, this);
//	t.onmouseup = methodize(this.stopMoving, this);
	
	w.appendChild(t);
	
	var c = document.createElement('div');
	c.id = this.id+'_content';
	c.style.minHeight = '328px';
	c.style.fontSize = '13px';
	//c.style.padding = '3px';
	c.innerHTML = this.msg;
	//c.style.background = '#dfe3e8';	
	
	w.appendChild(c);
	
	
	var tmp = document.createElement('div');
	//tmp.style.background = '#dfe3e8';
	//tmp.style.backgroundImage="url(images/popupBody.png)"
  tmp.style.textAlign = 'center';
//	tmp.style.padding = '3px 0 3px 0';
	
	
	var b = document.createElement('input');
	b.type = 'button';
//	b.value = this.buttonText;
	b.value = '';	
	b.style.width = '16px';
	b.style.height = '16px';
	b.style.position = 'relative';
	b.style.top = '-347px';
	b.style.left = '210px';
	b.style.backgroundImage="url(images/popupCloseButton.png)";
	b.style.backgroundRepeat="no-repeat"
	b.style.backgroundColor="transparent";
	b.style.border = '0px solid #000';
	b.onmouseover = function() {this.style.cursor = 'pointer';};
	b.onclick = function() {this.parentNode.parentNode.style.display = 'none';};
	
	tmp.appendChild(b);
	
	w.appendChild(tmp);
	
	if(this.parent)
		document.getElementById(this.parent).appendChild(w);
	else
		document.body.appendChild(w);
	
	return;
}

msgWin.prototype.hide = function()
{
	document.getElementById(this.id).style.display = 'none';
	
	return;
}

msgWin.prototype.show = function()
{
	document.getElementById(this.id).style.display = 'inline';
}

msgWin.prototype.startMove = function()
{
	this.moving = 1;
	
	document.getElementById(this.id).parentNode.onmousemove = methodize(this.stopMove, this);
	document.getElementById(this.id).parentNode.onmouseup = methodize(this.stopMove, this);
	
	var el = document.getElementById(this.id);
	
	el.style.zIndex = 2;

	if(el.style.left.indexOf("%") != -1)
		var l = screen.width/2+parseInt(el.style.marginLeft);
	else
		var l = parseInt(el.style.left);	
	
	this.offsetLeft = xMousePos - l;
}

msgWin.prototype.stopMove = function()
{
	if(!this.moving)
		return;
	
	var el = document.getElementById(this.id);
	
	el.style.margin = '0';
	el.style.padding = '0';
	el.style.left = (xMousePos - this.offsetLeft)+"px";
	el.style.top  = (yMousePos - 10)+"px";
}

msgWin.prototype.stopMoving = function()
{
	this.moving = 0;
	
	document.getElementById(this.id).style.zIndex = 1;
	
	return;
}