var orderScript = '/order.php'
var selectedFirst;
var targetInput;
var loaded;
var baseX;
var baseY;
	function closeSelectWin(){
		var selectWin = document.getElementById('selectWin');
		selectWin.style.display='none';
	}	
function showDialog(name, content){
	if (document.documentElement && document.documentElement.scrollTop)
	var theTop = document.documentElement.scrollTop;
else if (document.body)
	var theTop = document.body.scrollTop;
if (document.documentElement && document.documentElement.scrollTop)
	var theLeft = document.documentElement.scrollLeft;
else if (document.body)
	var theLeft = document.body.scrollLeft;
	
	var _y=document.documentElement.clientHeight;
	if (_y < 1) {
		// for IE5, 5.5
		_y=document.body.offsetHeight;
	}
	var x = (document.body.clientWidth-400)/2;
	var y = theTop+_y/2;
	var Dialog = document.createElement('div');
	Dialog.className = 'dialog';
	Dialog.setAttribute('id', 'dialog');
	
	Dialog.style.left = parseInt(x)+'px';
	baseX = parseInt(x);
	Dialog.style.top = parseInt(y-400 / 2)+'px';
	baseY = parseInt(y-400 / 2);
	var DialogHead = document.createElement('div');
	DialogHead.className = 'head';
	var closeImg = document.createElement('img');
	closeImg.setAttribute('height', '20');
	closeImg.setAttribute('width', '20');
	closeImg.setAttribute('src', '/images/design/close.gif');
	closeImg.onclick = closeDialog;
	DialogHead.appendChild(closeImg);
	DialogHead.appendChild(document.createTextNode(name));
	
	Dialog.appendChild(DialogHead);
	DialogBody = document.createElement('div');
	DialogBody.setAttribute('id', 'dialogBody');
	DialogBody.className = 'dialogBody';
	DialogBody.innerHTML = content;
	Dialog.appendChild(DialogBody);

	showOpacity();
	var ourBody = document.getElementsByTagName("body")[0];
	ourBody.insertBefore(Dialog, ourBody.firstChild);
	//alert(1);
	return false;
	
}
function showOpacity(){
if (document.documentElement && document.documentElement.scrollTop)
	var theTop = document.documentElement.scrollTop;
else if (document.body)
	var theTop = document.body.scrollTop;
if (document.documentElement && document.documentElement.scrollTop)
	var theLeft = document.documentElement.scrollLeft;
else if (document.body)
	var theLeft = document.body.scrollLeft;
	
	_y=document.documentElement.clientHeight;
	if (_y < 1) {
		// for IE5, 5.5
		_y=document.body.offsetHeight;
	}
	x = (document.body.clientWidth-400)/2;
	y = theTop+_y/2;
	opDiv = document.createElement('div');
	opDiv.setAttribute('id', 'opacity');
//		opDiv.appendChild(document.createTextNode('hello'));
	opDiv.className = 'opacity80';
	opDiv.style.bottom = parseInt(0- theTop)+'px';
	opDiv.style.right = parseInt(0- theLeft)+'px';
	ourBody = document.getElementsByTagName("body")[0];
	/* for (i=0; i<ourBody.childNodes.length; i++){
		if (ourBody.childNodes[i].nodeName.substr(0,1) != '#'){
			alert(ourBody.childNodes[i].nodeName);
			ourBody.childNodes[i].style.zIndex = 0;
		}
	}*/
	ourBody.insertBefore(opDiv, ourBody.firstChild);
	return false;
	
}
function showOrder(){
	if (document.documentElement && document.documentElement.scrollTop)
	var theTop = document.documentElement.scrollTop;
else if (document.body)
	var theTop = document.body.scrollTop;
if (document.documentElement && document.documentElement.scrollTop)
	var theLeft = document.documentElement.scrollLeft;
else if (document.body)
	var theLeft = document.body.scrollLeft;
	
	var _y=document.documentElement.clientHeight;
	if (_y < 1) {
		// for IE5, 5.5
		_y=document.body.offsetHeight;
	}
	var x = (document.body.clientWidth-400)/2;
	var y = theTop+_y/2;
	var Dialog = document.getElementById('formOrder');
	Dialog.className = 'dialog';
	Dialog.style.left = parseInt(x)+'px';
	baseX = parseInt(x);
	Dialog.style.top = parseInt(y-400 / 2)+'px';
	baseY = parseInt(y-400 / 2);

	showOpacity();
	Dialog.style.display = 'block';
	loaded = '';
	//alert(1);
	return false;
	
}

	

function removeFromOrder(i){
	if (!confirm('Удалить позицию из заказа?')){
		return;
	}
	cell = document.getElementById('del'+i).parentNode;
	cell.innerHTML = '<img src="/images/ajax/load.gif" height="24" width="24" alt="Удаление позиции" />';	
	var req2;
	req2 = new JsHttpRequest();
	req2.onreadystatechange = function() {
		if (req2.readyState == 4){
			document.getElementById('orderWin').innerHTML = req2.responseText;
		}
	}
	req2.open(null, orderScript, true);
	req2.send({
		action1: 'removeFromOrder', 
		row: i});

}
function createOrder(){
	window.location.href="/order-create.php";
}

