function WinClose(id) {
	var el = document.getElementById('w' + id);
	el.style.display = "none";
	SaveWidgets();
}

function WinCom(id) {
	var el = document.getElementById('w' + id);
	var tds = el.getElementsByTagName('TD');
	for (var i = 0; i < tds.length; i++) {
		if (tds[i].className == 'cont') {
			for (var j = 0; j < tds[i].childNodes.length; j++) {
				var ch = tds[i].childNodes[j];
				if (ch.style) {
					ch.style.display = ch.style.display == 'none' ? '' : 'none';
				}
			}
			break;
		}
	}
	//SaveWidgets();
}

function SaveWidgets() {
	var ts = document.getElementsByTagName('table');
	var tdl = null;
	var tdc = null;
	var tdr = null;
	for (var i = 0; i < ts.length; i++) {
		if ((((ts[i].className == 'window') && (ts[i].id != 'w0')) || (ts[i].className == 'log')) && (ts[i].style.display != 'none')) {
			if (ts[i].parentNode.className.indexOf('col_left') > -1) {
				if (tdl == null) {
					tdl = ts[i].parentNode;
					tdl.Widgets = new Array();
				}
				tdl.Widgets[tdl.Widgets.length] = ts[i].id.substring(1);
			}
			else if (ts[i].parentNode.className.indexOf('content') > -1) {
				if (tdc == null) {
					tdc = ts[i].parentNode;
					tdc.Widgets = new Array();
				}
				tdc.Widgets[tdc.Widgets.length] = ts[i].id.substring(1);
			}
			else if (ts[i].parentNode.className.indexOf('col_right') > -1) {
				if (tdr == null) {
					tdr = ts[i].parentNode;
					tdr.Widgets = new Array();
				}
				tdr.Widgets[tdr.Widgets.length] = ts[i].id.substring(1);
			}
		}
	}
	var s = 'l:';
	if (tdl)
		s += tdl.Widgets;
	s += '.c:';
	if (tdc)
		s += tdc.Widgets;
	s += '.r:';
	if (tdr)
		s += tdr.Widgets;
	s += '.';


	var ifrID = 'ifr_savewidgets';
	var ifr = document.getElementById(ifrID);
	if (ifr) {
		ifr.src = '/savewidgets.aspx?w=' + s + '&t=' + Math.round(Math.random() * 100000);
	}
	else {
		ifr = document.createElement('iframe');
		ifr.id = ifrID;
		ifr.style.display = 'none';
		ifr.src = '/savewidgets.aspx?w=' + s + '&t=' + Math.round(Math.random() * 100000);
		document.body.appendChild(ifr);
	}
}

function SubmitForm(f) {
	document.getElementById(f).submit();
}

function OpenPopup(a, w, h) {
	var wi = 'width=500';
	if (w) {
		wi = 'width=' + w;
	}
	var he = 'height=500';
	if (h) {
		he = 'height=' + h;
	}
	window.open(a.href, null, wi + ',' + he, false);
	return false;
}

function BigWin(a, obj, str, sm_top, sm_left) {
	el = document.getElementById("con_win");
	el1 = document.getElementById("showimage");
	el2 = document.getElementById("str");
	el2.style.margin = "0px 0px 0px " + str + "px";
	el1.style.display = "block";
	el1.style.left = "0px";
	el1.style.top = "0px";
	var curtop = 0;
	var curleft = 0;
	while (obj.offsetParent) {
		curtop += obj.offsetTop;
		curleft += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	if (sm_left == null)
	{ el1.style.margin = curtop + parseInt(sm_top) + "px 0px 0px " + curleft + "px"; }
	else
	{ el1.style.margin = curtop + parseInt(sm_top) + "px 0px 0px " + (curleft + parseInt(sm_left)) + "px"; }
	el.innerHTML = a;
}

function OpenFrame(src, w, h, obj, str, sm_top, sm_left) {
	BigWin('<iframe src=\'' + src + '\' scrolling=\'no\' frameborder=\'0\' width=\'' + w + '\' height=\'' + h + '\'></iframe>',
	obj,
	str,
	sm_top, 
	sm_left);
}

function CloseFrame() {
	if (window.parent) {
		window.parent.document.getElementById('showimage').style.display = 'none';
		return false;
	}
	return true;
}

function OpenPopup(a, w, h) {
	var wi = 'width=500';
	if (w) {
		wi = 'width=' + w;
	}
	var he = 'height=500';
	if (h) {
		he = 'height=' + h;
	}
	window.open(a.href, null, wi + ',' + he +',top=100,left=100', false);
	return false;
}

function UserWin(p, user, avatar, fio, country, obj, str, sm_top, sm_left)
{
	var a = '<div class="user">';
	a += '<h2>Пользователь</h2>';
	if (avatar) {
		a += '<p><a href="/user/' + user + '.html"><img src="/image/profile/avatar/' + p + '.ashx?profile=a" width="100" height="100" alt="" /></a></p>';
	}
	a += '<p><b>Логин:</b> ' + user + '</p>';
	a += '<p><b>ФИО:</b> ' + fio + '</p>';
	a += '<p><b>Страна:</b> ' + country + '</p>';
	a += '<p><a href="/user/' + p + '.html">Полная информация</a></p>';
    a += '</div>';
	BigWin(a, obj, str, sm_top, sm_left);
}
