function LoadXML(uri,method,post_str)
{
	var request = null;

	// пытаемся создать объект для MSXML 2 и старше
	if (!request)
	{
		try
		{
			request = new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e){}
	}

	// не вышло... попробуем для MSXML 1
	if (!request)
	{
		try
		{
			request = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e){}
	}

	// не	вышло... попробуем для Mozilla и Opera 7.60
	if (!request)
	{
		try
		{
			request = new XMLHttpRequest();
		}
		catch (e){}
	}

	if (!request)
	{
		// ничего не получилось...
		return null;
	}

	// делаем запрос
	request.open(method, uri, false);
	if (method=='GET') {
		request.send(null);
	} else {
		request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		request.send(post_str);
	}
//	if (request.responseXML.childNodes.length==0)
//		return null;//alert('xml не загрузился');

	//возвращаем XML

	return request.responseText;

}
function block_click() {
	return false;
}
function check_key(e) {
	e = (e)?e:window.event;
	if(e.keyCode == '27')
	{
		p2 = window.top.document.getElementById("popup_div_id2")
		if(p2 != undefined) window.top.closePopup2();
			else window.top.closePopup();
	}
	return true;
}
function popup_form_submit(e) {
	e = (e)?e:window.event;
	form_obj = (e.target)?e.target:e.srcElement;
	page_popup = document.getElementById("admin_popup");

//	page_popup.innerHTML = LoadXML(url,'POST');
	var post_str = "";
	var url;
	form_children = new Array;
	form_children = form_obj.getElementsByTagName('input');
//	alert(form_obj.getElementsByTagName('input'));
	for (i=0;i<form_children.length;i++) {
		if (form_children[i].name == 'req_url') {
				url = form_children[i].value;
			} else	post_str += ((post_str == "")?"":"&")+form_children[i].name+"="+form_children[i].value;
	}
//	page_popup.innerHTML = url+"------"+post_str;
	page_popup.innerHTML = LoadXML(url,'POST',post_str);
	return false;
}

function closePopup(reload)
{
	var popup_div=document.getElementById("popup_div_id");
	if (popup_div)
	{
		popup_div.parentNode.removeChild(popup_div);

		var page_content = document.getElementById("whole_page_content");

		if (page_content)
		{
			page_content.style.overflow='';
			page_content.style.height = '';
			page_content.style.width = '';
			page_content.oncontextmenu = '';
		}

		var sels = document.getElementsByTagName('select');
		for (i=0; i<sels.length; i++)
		{
			sels[i].disabled = false;
		}

		window.onresize = '';
		window.document.onkeypressed = '';

		if (reload=='yes')
		{
			window.top.location.reload();
		}
	}

}

function openPopup(in_html, width, height, scroll)
{
	if (scroll==true)
		scroll='yes';
	else
		scroll='no';

	sels = document.getElementsByTagName('select');
	for (i=0; i<sels.length; i++)
	{
		sels[i].disabled = true;
	}

	if (document.getElementById("dhtmltooltip2")) hideddrivetip();

	var popup_div = document.createElement("div");
	popup_div.setAttribute("id","popup_div_id");
//	popup_div.innerHTML = '<div id="admin_mask">&nbsp;</div><div id="admin_popup" style="width:'+width+'px;height:'+height+'px;"><iframe id="iframe_popup" name="iframe_popup" frameborder=0 width="100%" height="100%" src="'+url+'" scrolling="'+scroll+'"/></div>';

	var page_mask = document.createElement("div");
	page_mask.setAttribute("id","admin_mask");

	var page_popup = document.createElement("div");
	page_popup.setAttribute("id","admin_popup");
	page_popup.style.width = width+'px';
	page_popup.style.height = height+'px';

//	var page_frame = document.createElement("iframe");
//	page_frame.setAttribute("id","iframe_popup");
//	page_frame.setAttribute("name","iframe_popup");
//	page_frame.setAttribute("width","100%");
//	page_frame.setAttribute("height","100%");
//	page_frame.setAttribute("frameBorder", "0");
//	page_frame.setAttribute("src",url);
//	page_frame.setAttribute("scrolling",scroll);

//	var page_popup_header = document.createElement("div");
//	page_popup_header.setAttribute("id","admin_popup_header");
//	page_popup_header.style.width = width+'px';
//	page_popup_header.style.height = '27px';

//	page_popup.appendChild(page_popup_header);
//	page_popup.appendChild(page_frame);
page_popup.innerHTML = in_html;
	popup_div.appendChild(page_mask);
	popup_div.appendChild(page_popup);
	document.body.appendChild(popup_div);

//	new Draggable('admin_popup',{handle:'admin_popup_header', scroll: false});

	// parent = document.body.appendChild(popup_div);
//	var page_mask = document.getElementById("admin_mask");
	var page_content = document.getElementById("whole_page_content");

//	var page_popup = document.getElementById("admin_popup");
	if (page_popup)
	{
		var top = parseInt((pageHeight()-height)/2);
		var left = parseInt((pageWidth()-width)/2);
		if (top<5) top = 5;
		if (left<5) left = 5;
		page_popup.style.top = top+"px";
		page_popup.style.left = left+"px";
	}

	setSizes();

	if (page_content)
	{
		var s_top = window.scrollY;
		page_content.style.overflow="hidden";
		page_content.scrollTop = s_top;
		page_content.oncontextmenu = block_click;
	}

	page_mask.oncontextmenu = block_click;
	window.document.onkeypress = check_key;
	window.onresize = setSizes;
}

function setSizes()
{
	var page_mask = document.getElementById("admin_mask");
	var page_mask2 = document.getElementById("admin_mask2");
	var page_content = document.getElementById("whole_page_content");

	if (page_content)
	{
		page_content.style.height = pageHeight()+'px';
		page_content.style.width = pageWidth()+'px';
	}

	if (page_mask)
	{
		page_mask.style.height = pageHeight()+"px";
		page_mask.style.width = pageWidth()+"px";
	}

	if (page_mask2)
	{
		page_mask2.style.height = pageHeight()+"px";
		page_mask2.style.width = pageWidth()+"px";
	}


	var page_popup = document.getElementById("admin_popup");


	if (page_popup)
	{
		var top = parseInt((pageHeight()-parseInt(page_popup.style.height))/2);
		var left = parseInt((pageWidth()-parseInt(page_popup.style.width))/2);
		if (top<5) top = 5;
		if (left<5) left = 5;
		page_popup.style.top = top+"px";
		page_popup.style.left = left+"px";
	}
}

function set_sizes_by_content()
{
	var page_content = document.getElementById("whole_page_content");
	var page_popup = window.top.document.getElementById("admin_popup");
	if (page_popup)
	{
		page_popup.style.height = (parseInt(page_content.offsetHeight)+20)+'px';
	}

	var popup_frame = window.top.document.getElementById("iframe_popup");

	if (parseInt(page_popup.offsetHeight) > parseInt((parseInt(page_popup.offsetWidth)*64/38)))
	{
		popup_frame.setAttribute("scrolling",'yes');
		page_popup.style.height = parseInt((parseInt(page_popup.offsetWidth)*64/38));
	}
	if (parseInt(page_popup.offsetHeight) > window.top.pageHeight()*0.8)
	{
		popup_frame.setAttribute("scrolling",'yes');
		page_popup.style.height = (window.top.pageHeight()*0.8) + 'px';
	}

	window.top.setSizes();
}

function pageWidth()
{
	return window.innerWidth != null? window.innerWidth: document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth:document.body != null? document.body.clientWidth:null;
}
function pageHeight()
{
	return window.innerHeight != null? window.innerHeight: document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight:document.body != null? document.body.clientHeight:null;
}
if (window != window.top)
{
	window.document.onkeypress = check_key;
}

function show_popup_error(text, close_text)
{
	openPopup('<table width="100%" height="100%"><tr><td valign="middle" align="center" style="color:#d10d0d; font-weight:bold;">'+text+'<br/><br/><input type="button" value="'+close_text+'" onclick="closePopup()"/></td></tr></table>', 350, 120);
}

function show_popup_accepted(text, close_text)
{

	openPopup('<table width="100%" height="100%"><tr><td valign="middle" align="center" style="color:#fff; font-weight:bold;">'+text+'<br/><br/><input type="button" value="'+close_text+'" onclick="closePopup()"/></td></tr></table>', 350, 120);
}

