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 = '406px';
	w.style.height = '134px';
	//w.style.border = '2px 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';
		w.style.left = (this.left-406)+'px';
		w.style.top = this.top+'px';
	}
	
	var t = document.createElement('div');
	t.id = this.id+'_title';
	//t.style.borderBottom = '1px dashed #000';
	t.style.textAlign = 'right';
	t.style.fontWeight = 'bold';
	t.style.fontSize = '16px';
	//t.innerHTML = this.title;
	//t.style.background = '#628db4';
	t.style.width = '406px';
	t.style.height = '49px';
	t.style.backgroundImage = 'url(images/login_bg1.jpg)';
	t.onmouseover = function() {this.style.cursor = 'move';};
	t.onmousedown = methodize(this.startMove, this);
	t.onmouseup = methodize(this.stopMoving, this);
	
	w.appendChild(t);
	
	var b = document.createElement('img');
	b.setAttribute("src", "images/login_bg7.png");
	b.setAttribute("border", "0");
	b.setAttribute("alt", "close");
	b.style.position = 'relative';
	b.style.right = '5px';
	b.style.top = '5px';
	b.onmouseover = function() {this.style.cursor = 'pointer';};
	b.onclick = function() {this.parentNode.parentNode.style.display = 'none';};
	
	t.appendChild(b);
	
	var c = document.createElement('div');
	c.id = this.id+'_content';
	//c.style.minHeight = '75px';
	c.style.width = '406px';
	c.style.height = '67px';
	c.style.fontSize = '13px';
	//c.style.padding = '3px';
	//c.style.padding = '0 15px 0 15px';
	c.innerHTML = this.msg;
	//c.style.background = '#dfe3e8';	
	c.style.backgroundImage = 'url(images/login_bg2.jpg)';	
	
	w.appendChild(c);
	
	
	var tmp = document.createElement('div');
	//tmp.style.background = '#dfe3e8';
	tmp.style.backgroundImage = 'url(images/login_bg5.jpg)';	
	tmp.style.textAlign = 'center';
	tmp.style.width = '406px';
	tmp.style.height = '21px';
	//tmp.style.padding = '3px 0 3px 0';
	
	var acc = document.createElement('a');
	acc.setAttribute('href', 'register.php');
	
	var b2 = document.createElement('img');
	b2.setAttribute("src", "images/login_bg6.jpg");
	b2.setAttribute("height", "16");
	b2.setAttribute("width", "123");
	b2.setAttribute("border", "0");
	b2.setAttribute("alt", "create new account");
	//b2.onmouseover = function() {this.style.cursor = 'pointer';};
	//b2.onclick = function() {this.parentNode.parentNode.style.display = 'none';};
	
	acc.appendChild(b2);
	
	tmp.appendChild(acc);
	
	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;
}