document.onmousemove = getMouseXY;


function getMouseXY(e) {

	var IE = document.all?true:false;
	if (!IE) document.captureEvents(Event.MOUSEMOVE)
	var tempX = 0;
	var tempY = 0;

	if (IE) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else { 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  

	if(document.getElementById('posx')) document.getElementById('posx').value = tempX;
	if(document.getElementById('posy')) document.getElementById('posy').value = tempY;
	return true;
}


function objText(o)
{
	var s = new Array();
	s.push('{<br>');
	for ( var i in o )
		s.push("&nbsp;&nbsp;&nbsp;" + i + ": " + o[i] + "<br>");
	s.push('}');
	return s.join('');
}
function debug(msg)
{
	document.getElementById('debug').innerHTML += msg + "<br>";
}

function JSWindow(title, oContent, x, y, w)
{
	this.title = title;
	this.oContent = oContent;

	this.mx = 0;
	this.my = 0;

	this.oTable = document.createElement("table");
	this.oTable.style.cssText = "background-color: #f5f5ea; border: #ffffff 1px dashed; width: "+w+"px";
	this.oTable.style.zIndex = "255";
	this.oTable.style.position = "absolute";
	this.oTable.style.left = x + "px";
	this.oTable.style.top = y + "px";
	this.oTable.style.cursor = "default";
	this.oTable.jsWindow = this;

	document.body.appendChild(this.oTable);

	var oTR = this.oTable.insertRow(0);
//	oTR.className = "JSWindowTitleStyle";

	var oTD = oTR.insertCell(0);
	oTD.innerHTML = title;
	oTD.style.cssText = "padding: 4px; font: 110%";
	oTD.jsWindow = this;

	oTD = oTR.insertCell(1);
	oTD.innerHTML = "<img src='/img/close.gif'/>";
	oTD.style.cssText = "padding: 2px 4px 2px 0; text-align: right; margin-left: auto; vertical-align: middle";
	oTD.jsWindow = this;	
	oTD.onmousedown = JSWindow.prototype.onClose;
	
	oTR = this.oTable.insertRow(1);
	oTD = oTR.insertCell(0);
	oTD.colSpan = 2;
	oTD.style.cssText = "border-bottom: #ffffff 1px dashed";

	oTR = this.oTable.insertRow(2);
	oTD = oTR.insertCell(0);
	oTD.colSpan = 2;
	oTD.style.cssText = "padding: 2ex";
	oTD.appendChild(oContent);
}

JSWindow.prototype.bodyOnMouseMove = function(evt)
{
	var e = window.event ? window.event : evt;
	this.jsWindow.onMouseMove(e);
}
JSWindow.prototype.onMouseMove = function(evt)
{
	// if mouse not down, stop the move (for IE only)
	if ( (document.all) && !(evt.button & 1) )
	{
		this.onMouseUp();
		return;
	}
	if ( this.bDown )
	{
		this.dx = parseInt(this.oTable.style.left, 10) - evt.clientX;
		this.dy = parseInt(this.oTable.style.top, 10) - evt.clientY;
		this.bDown = false;
	}
	else
	{
		this.oTable.style.left = Math.max((this.dx + evt.clientX),0) + "px";
		this.oTable.style.top = Math.max((this.dy + evt.clientY),0) + "px";
	}
}
JSWindow.prototype.close = function()
{	
//	this.oContent.parentNode.removeChild(this.oContent);
	this.oContent.style.display = "none";
	this.oTable.style.display = "none";
	//this.oTable.parentNode.removeChild(this.oTable);
}
JSWindow.prototype.onClose = function()
{
	this.jsWindow.close();
}

function show_news(id,title) {

	var w = 500;
  var x = screen.availWidth;

	document.getElementById("news").style.width = w;
	document.getElementById("news").style.display = "block";
	new JSWindow(title, document.getElementById("news"), (x-w)/2, 40, w);

	makeRequestPost('news.php',"id="+id,"news");
}
function show_plan_help() {

	var w = 400;
  var x = screen.availWidth;

	document.getElementById("plan_choose").style.width = w;
	document.getElementById("plan_choose").style.display = "block";
	new JSWindow("Как правильно выбрать тарифный план?", document.getElementById("plan_choose"), (x-w)/2, 40, w);
}
function show_vopros(id,title) {

	var w = 420;
	var x = document.getElementById('posx').value;
	var y = document.getElementById('posy').value;

	document.getElementById("vopros").style.width = w;
	document.getElementById("vopros").style.display = "block";
	new JSWindow(title, document.getElementById("vopros"), x+20, y, w);

	makeRequestPost('vopros.php',"id="+id,"vopros");
}
function cms_info(cms) {

	var w = 400;
  var x = screen.availWidth;
	document.getElementById(cms).style.width = w;
	document.getElementById(cms).style.display = "block";
	new JSWindow("Конструкторы сайтов", document.getElementById(cms), (x-w)/2, 40, w);

}
