var iD = FetchNumber();


var app = {
	black:0,
	newZ:250,
	cbInput:'',multiInput:'',v:'',vv:'',
	clipboard:'',
	submit:'',
	form:'',
	amx:0,amy:0, mx:0,my:0, sw:1024,sh:768,	state: 0, opaq: '',
	up: new Array(0,0,0,0),
	down: new Array(0,0,0,0),

	GetZ:function()	{return this.newZ;}
}



var desc = {noId:'Не найден элемент формы...'};



var win = {dx:0,dy:0, bound:'', last:'', id:'', drag:'', pointed:'', head:''};
var iWin;


var aWin = new Array();			var retireWin = '';

var scroll = {name:'', over:''};


var amorT = new Array();



var aElem = new Array(0,0,0,0);
var aHide = new Array();


var DnD = {from:'',to:'', x:0,y:0, ref:'',id:0, ref2:'',id2:0, on:0};

var time = {con:0}
var timer = {menu:0,amor:0}
var xTime = {};
var oMenu = {mod:'',mi:'',ref:'',area:'',xarea:''};
var oOver = {mod:'',mi:'',ref:'',area:'',op:'',xarea:''};
var oDown = {mod:'',mi:'',ref:'',area:'',op:'',mx:0,my:0};
var oBuffer = {mod:'',mi:'',ref:'',area:'',op:''};


var keyCtrl	= 1;
var keyShift	= 2;



document.onkeyup = KeyUp;
document.onkeydown = KeyDown;

document.onmousemove = MoveWin;

document.onmouseup = MouseUp;
document.onmousedown = MouseDown;



//-F-u-n-d-a-m-e-n-t-a-l- - - - - - - - - - - - - - - - - -


function getElementsByTagAttr(tag,attr,val){	var elem = document.getElementsByTagName(tag),	aOut = new Array();

for(i=0, iArr=0; i<elem.length; i++)	{	att = elem[i].getAttribute(attr);
	if(att==val)	{			aOut[iArr] = elem[i];		iArr++;	}	}

	return aOut;	}



function xmlElements(node,tag,prop,pval){	var elem = node.getElementsByTagName(tag),	aOut = new Array();

	if(prop==undefined)	prop = '';	if(pval==undefined)		pval = '';

for(i=0, iArr=0; i<elem.length; i++)	{
	if(prop)	{			att = elem[i].getAttribute(prop);
		if(att!=pval)			continue;	}

	aOut[iArr] = elem[i];			iArr++;	}			return aOut;	}



function checkAcc($key)	{
	if(uAcc.indexOf('|duncan|'))		return 1;
	if($key=='')		return 1;	return uAcc.indexOf('|'+$key+'|')!=-1;	}



function dTime(id)	{
	if(id==undefined)			id = gen;
	if(xTime[id]==undefined)		xTime[id] = 0;

	var x =	new Date().getTime();		var xx = x - xTime[id];
	xTime[id] = x;				return xx;	}


function uniqid()	{	var s = 'u_'+iD;
	iD++;			return s;	}



function delayHide(id,delay)	{		if(delay==undefined)		delay = 500;
	if(aHide[id]!=undefined)		clearTimeout(aHide[id]);
	var s = "var o = byId('"+ id +"'); if(o) o.style.visibility='hidden'";
	aHide[id] = setTimeout(s,delay);	}

function Show(id)	{
	var o = document.getElementById(id);	if(o)	o.style.visibility = 'visible';	}

function Hide(id)	{
	var o = document.getElementById(id);	if(o)	o.style.visibility = 'hidden';	}

function ToggleVis(id)	{			var o = document.getElementById(id);
if(o)	if(o.style.visibility=='hidden')
	o.style.visibility = 'visible';	else	o.style.visibility = 'hidden';	}

function ToggleDisplay(o)	{		if(typeof(o)=='string')		o = document.getElementById(o);
if(o)	if(o.style.display=='none')	{
	o.style.display = 'block';		return 1;	}
else{	o.style.display = 'none';		return 0;	}		return 0;	}

function Style(o,v,vv)	{	o = byId(o);	if(!o)	return;			o.style[v] = vv;	}

function cancelHide(id)	{
	if(aHide[id]!=undefined)		clearTimeout(aHide[id]);
	var o = document.getElementById(id);	if(o)				o.style.visibility = 'visible';	}

function clearHide(id)	{			if(aHide[id]!=undefined)	clearTimeout(aHide[id]);	}



function setCookie(name,value,expires)	{	document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "");	}


function killCookie(name)	{
	var oDate = new Date();			oDate.setFullYear(oDate.getFullYear() - 1);
	document.cookie = name + "=; expires=" + oDate.toGMTString();	}


function getCookie(name)	{		var cookie = " " + document.cookie;
	var search = " " + name + "=";		var setStr = null;
	var offset = 0;				var end = 0;

if(cookie.length>0)	{			offset = cookie.indexOf(search);
	if(offset!=-1)	{
		offset += search.length;	end = cookie.indexOf(";", offset)
		if(end==-1)			end = cookie.length;

		setStr = unescape(cookie.substring(offset, end));	}

	}	return(setStr);	}



function appCopyText(s)	{	setCookie('clipboard', s);	}



function byId(o)	{        return typeof o == 'string' ? document.getElementById(o) : o;	}

function byName(o)	{        return typeof o == 'string' ? document.getElementsByName(o) : o;	}



function miMultiInput(input,mi)	{			var o = byId(input);	if(o==undefined)		return;
	if(mi==undefined)				mi = 'node_root';
	app.multiInput = input;	o.blur();		winRQ('?route=route;cms_miLevel;input;'+ o.id +';mi;'+ mi, 'multiInput');	}



function getInput(id)	{	id = byId(id);	if(id)	return id.value;	return '';	}

function buffInput(v,vv){	app.v = v;	if(vv==undefined)	vv = '';	app.vv = vv;	}

function passInput()	{	if(app.v=='')		return;
	var o = byId(app.multiInput);		if(o)	o.value = app.v;
	var oo = byId(app.multiInput+'x');	if(oo)	oo.value = app.vv;		winClear('multiInput');	}

function setInput(id,val){	var o = byId(id);	if(o)	o.value = val;	var o = byId(id+'text');	if(o)	o.value = val;	}

function setName(id,val){	var o = byId(id);	if(o)	o.value = val;	var o = byId(id+'text');	if(o)	o.value = val;	}

function setTagVal(tag,name,val)	{		var a = getElementsByTagAttr(tag,'name', name);
	for(var i in a)					a[i].value = val;	}



function selectRow(o,v)	{	var xTD = o.getElementsByTagName('td');
for(var i=0; i<xTD.length; i++)	{
	if(v)			xTD[i].style.backgroundColor = '#dfdfdf';
	else			xTD[i].style.backgroundColor = '';	}	}



function Print()	{	window.print();	}
function Resign(from,to){	var dst = document.getElementById(to);
	if(dst)			dst.innerHTML = from.innerHTML;	}





var Base64 = {
 
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
 
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = Base64._utf8_encode(input);
 
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
 
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
 
		}
 
		return output;
	},
 
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
 
		while (i < input.length) {
 
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
 
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
 
			output = output + String.fromCharCode(chr1);
 
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
 
		}
 
		output = Base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}





function refreshImage(id,src,q)	{	var o = byId(id);
	if(q==undefined)	q = '?';	else	q = '&';
	if(o)			o.src = src+q+miliTime();	}

function xSetImage(id,src){	var o = byId(id);	if(o)		o.src = src;	}

function setImage(id,src){	var o = byId(id);
	if(o)		{	o.src = 'c/img/blank.gif';		setTimeout('xSetImage("'+ id +'","'+ src +'")', 1);	}	}


function setImageWH(id,src,w,h,anim)	{	var o = byId(id);	if(anim==undefined)	anim = 0;
	if(o==undefined)	return false;	o.src = 'c/img/blank.gif';			setTimeout('xSetImage("'+ id +'","'+ src +'")', 1);
if(anim)
	amorQuery(id, 'w,'+w+',h,'+h);
else{	o.width = w;		o.height = h;	}			return true;	}


function setCheck(id,v){	var o = byId(id);
	if(o)			o.checked = v;	}

function xorCheck(id,v){	var o = byId(id);
	if(o)	if(o.checked)	o.checked = 0;
		else		o.checked = 1;	}





function findNode(types,o)	{

	if(typeof(types)=='string')	types = explode(',', types);

	var c = o.childNodes.length;

for(var i=0; i<c; i++)	{

	for(var t in types)
		if(types[t]==o.childNodes[i].tagName)
			gNodes.push(o.childNodes[i]);

	if(o.childNodes[i].hasChildNodes)
		findNode(types, o.childNodes[i]);	}

}


	var gNodes = Array();

function fetchNodes(types,o)	{

	o = byId(o);		gNodes = Array();

	if(o==undefined)	return Array();

	var aType = explode(',', types);

	findNode(aType, o);	return gNodes;	}



function xUnpackArray(s)	{	var a = {};

	var v = explode(';', s),	c = v.length;

for(var i=0; i<c; i+=3)	{		if(v[i]=='')			continue;

if(v[i+1]==1)	{			a[v[i]] = xUnpackArray(Base64.decode(v[i+2]));
	for(var j in a[v[i]])	{	var sName = v[i]+'$'+j;		a[sName] = a[v[i]][j];	}	}

else	a[v[i]] = Base64.decode(v[i+2]);	}			return a;	}



function findMatch(name,x)	{
for(var i in x)
	if(typeof(x[i])=='string')
		if( name==i || name.indexOf('$'+i+'$')!=-1 )		return x[i];

	return false;	}



function toInt(a)	{		if(typeof(a)!='object')		return parseInt(a);
for(var i in a)
	a[i] = parseInt(a[i]);		return a;	}



function selectStep(field,v,val)	{				var a = toInt(explode(';', v)),	s = '<select name="'+ field +'">';
for(var i=a[0]; i<=a[1]; i+=a[2])	{				s += '<option ';
	if(i==val)	s += ' selected ';				s += 'value="'+ i +'">'+ i +'</option>';

}	s += '</select>';						return s;	}



function selectStr(field,str,val)	{				var s = '<select name="'+ field +'">';
	var select = explode(';', str),					c = select.length & 0xfe;

for(var i=0; i<c; i+=2)	{						s += '<option ';
	if(select[i+1]==val)		s += ' selected ';		s += 'value="'+ select[i+1] +'">'+ select[i] +'</option>';

}	s += '</select>';						return s;	}



function gatherTime(from,to)	{

//	alert(from +' : '+ to);

	var a = fetchNodes('SELECT', from);

	var t = {day:1,month:1,year:2000, hour:0,minute:0,second:0};


//	alert(a.length);

for(var i in a)	{				var v = a[i].getAttribute('name');
switch(v)	{
case 'day':	case 'month':	case 'year':	case 'hour':	case 'minute':	case 'second':		t[v] = parseInt(a[i].value);	}	}



	var xOut = byId(to);

	var myDate = new Date(t.year,t.month-1,t.day, t.hour,t.minute,t.second);
	var xTime = myDate.getTime()/1000;

if(t.hour==0 && t.minute==0 && t.second==0)
	xOut.value = date('Y-m-d', xTime);	else		xOut.value = date('Y-m-d G:i:s', xTime);



//	alert(t.year+'.'+t.month+'.'+t.day+' '+t.hour+':'+t.minute+':'+t.second);

//	var xxx = strtotime( t.year+'.'+t.month+'.'+t.day+' '+t.hour+':'+t.minute+':'+t.second );

//	alert(xxx);


	winClear(from);

}




function datetimeInput(to,apply,time)	{				var t = getdate(time),		s = '';

	var s = '<table align="center" style="padding:10px"><tr><td><b>День</b></td><td colspan="2" align="center"><b>Месяц</b></td><td align="right"><b>Год</b></td></tr><tr><td align="center">'+ selectStep('day', '1;31;1', t['mday']) +'</td><td colspan="2" align="center">'+ selectStr('month', 'Январь;1;Февраль;2;Март;3;Апрель;4;Май;5;Июнь;6;Июль;7;Август;8;Сентябрь;9;Октябрь;10;Ноябрь;11;Декабрь;12', t['mon']) +'</td><td align="right">'+ selectStep('year', '1939;'+ (parseInt(date('Y'))+5) +';1', t['year']) +'</td></tr>';
	s += '<tr><td align="center">'+ selectStep('hour', '0;23;1', t['hours']) +'</td><td colspan="2" align="center">'+ selectStep('minute', '0;59;1', t['minutes']) +'</td><td align="right">'+ selectStep('second', '0;59;1', t['seconds']) +'</td></tr><tr><td><b>Час</b></td><td colspan="2" align="center"><b>Минута</b></td><td align="right"><b>Секунда</b></td></tr></table>';

	s += '<div style="border-top:1px solid #bfbfbf; text-align:center"><input type="button" value="Применить" onclick="gatherTime(\''+ to +'\',\''+ apply +'\')" /></div>';

	var o = byId(to);		if(o!=undefined)		o.innerHTML = s;	}


function dateInput(to,apply,time)	{				var t = getdate(time),		s = '';

	var s = '<table align="center" style="padding:10px"><tr><td><b>День</b></td><td colspan="2" align="center"><b>Месяц</b></td><td align="right"><b>Год</b></td></tr><tr><td align="center">'+ selectStep('day', '1;31;1', t['mday']) +'</td><td colspan="2" align="center">'+ selectStr('month', 'Январь;1;Февраль;2;Март;3;Апрель;4;Май;5;Июнь;6;Июль;7;Август;8;Сентябрь;9;Октябрь;10;Ноябрь;11;Декабрь;12', t['mon']) +'</td><td align="right">'+ selectStep('year', '1939;'+ (parseInt(date('Y'))+5) +';1', t['year']) +'</td></tr></table>';

	s += '<div style="border-top:1px solid #bfbfbf; text-align:center"><input type="button" value="Применить" onclick="gatherTime(\''+ to +'\',\''+ apply +'\')" /></div>';

	var o = byId(to);		if(o!=undefined)		o.innerHTML = s;	}



function markNode(o)	{		if(o.id=='')			o.id = uniqid();		return o.id;	}



function patchInput(o,x)	{	var sName = o.getAttribute('name');	if(sName==null)		return;

	var v = findMatch(sName, x);



switch(o.tagName)	{

case 'INPUT':

	switch(o.getAttribute('type'))	{
	case 'xdate':				if(v===false) v = 0;	v = parseInt(v);	v += new Date().getTimezoneOffset()*60;
		markNode(o);			o.value = date('Y-m-d', v);			o.setAttribute('readonly', 'readonly');

		o.onclick = function() {	winCreate('xdatetime', '','','','', 1);		dateInput('xdatetime',o.id, v);	}

		return;

	case 'xdatetime':			if(v===false) v = 0;	v = parseInt(v);	v += new Date().getTimezoneOffset()*60;
		markNode(o);			o.value = date('Y-m-d G:i:s', v);		o.setAttribute('readonly', 'readonly');

		o.onclick = function() {	winCreate('xdatetime', '','','','', 1);		datetimeInput('xdatetime',o.id, v);	}

		return;

	case 'text':
		if(v===false)			v = '';
		if(o.value=='')			o.value = v;		return;	}

	break;

case 'TEXTAREA':
	if(v!==false)	o.value = v;	return;

case 'SELECT':	{	var aOption = fetchNodes('OPTION', o);

for(var i=0; i<aOption.length; i++)
	if(aOption[i].value==v)		o.selectedIndex = i;		return;	}

}


}



function parseForm(form,s)	{

//	alert(1);



	var oForm = byId(form);

	var aNode = fetchNodes('INPUT,SELECT,TEXTAREA', oForm);


	var x = xUnpackArray(s);

for(var i in aNode)
	patchInput(aNode[i], x);

//	alert(oForm.hasChildNodes());

//	alert(oForm.childNodes.length);

//	alert(oForm.childNodes.length);

//	alert(form);
//	alert(byId(form));
//	alert(s);

}





function initTiny(id)	{

tinyMCE.init({
// General options
	mode : "exact",
	elements : id,
	theme : "advanced",
	plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

// Theme options
	theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
	theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,

// Example content CSS (should be your site CSS)
	content_css : "c/tiny.css",

// Drop lists for link/image/media/template dialogs
	template_external_list_url : "lists/template_list.js",
	external_link_list_url : "lists/link_list.js",
	external_image_list_url : "lists/image_list.js",
	media_external_list_url : "lists/media_list.js",

// Style formats
	style_formats : [
		{title : 'Bold text', inline : 'b'},
		{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
		{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
		{title : 'Example 1', inline : 'span', classes : 'example1'},
		{title : 'Example 2', inline : 'span', classes : 'example2'},
		{title : 'Table styles'},
		{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
	],

// Replace values for the template plugin
	template_replace_values : {
		username : "Some User",
		staffid : "991234"
	}	});

}



function simpleTiny(id)	{

tinyMCE.init({
// General options
	mode : "exact",
	elements : id,
	theme : "simple"
});	}




function packArray(o)	{	var s = '';
for(var i in o)
	s += i +';'+ o[i] +';';	return s;	}



function unpackArray(s)	{

	var a = explode(';', s);	var x = Array();

for(var i=0; i<a.length; i+=2)	{

	if(a[i]=='')	continue;	x[a[i]] = a[i+1];	}

	return x;	}





function winExist(id)	{	return aWin[id]!=undefined;	}

function winMax(id)	{
	amorQuery(id+'_top', 'x,0,y,32,w');
	amorQuery(id+'_frame', 'w,'+(app.sw-16)+',h,'+(app.sh-32));	}

function winHide(id,delay){	if(aWin[id].status=='hidden')	return;
				if(delay==undefined)		delay = 500;

if(delay<=0)	{		var o = byId(id+'_top');	o.style.visibility = 'hidden';
}	else			fadeOut(id+'_top', 500);	aWin[id].status = 'hidden';	}

function winRestore(id)	{	if(aWin[id].status=='')		return;	fadeIn(id+'_top', 500);		aWin[id].status = '';	}

function winHideAll()	{
for(var i in aWin)
	if(aWin[i]!=undefined)	winHide(i);	}


function winRecreate(id){	if(aWin[id]==undefined)		return;

	winCreate(id, aWin[id].w,aWin[id].h, aWin[id].x,aWin[id].y);

	blockReroute(id);	aWin[id].status = '';	}



function winAlter(id)	{
switch(aWin[id].status)	{
case 'fetch':
	winRecreate(id);	break;
case 'hidden':
	winRestore(id);		break;
case '':
	winHide(id);		break;	}	}



function winRetire(id)	{	retireWin += id+';';
	killCookie('win_'+id);	setCookie('retireWin', retireWin);	}



function winClear(id)	{	if(id=='')	return;

	if(win.head==id)	win.head = '';

	aWin[id] = undefined;	refreshTaskbar();

	var xWin = document.getElementById(id+'_top');
if(xWin)
	KillId(xWin);		winRetire(id);

	if(win.last==id)	win.last = '';	}



function cookWin(id)	{	var s = packArray(aWin[id]);
	if(!s)	return;		setCookie('win_'+id, s);	}



function winClose()	{			winClear(oOver.area);	}



var oResize = {id:'', x:0,y:0, w:0,h:0};

function setResize()	{

	var o = byId(oOver.area);		if(o==undefined)	return false;

	oResize.id = oOver.area;

	oResize.x = app.mx;			oResize.y = app.my;

	oResize.w = o.clientWidth;		oResize.h = o.clientHeight;

	return false;
}


function unsetResize()	{	oResize.id = '';	}



function aResize()	{	if(oResize.id=='')			return false;

	return false;

//	document.title = miliTime();	return;

	var o = byId(oResize.id);

	o.style.width = (app.mx-oResize.x) + oResize.w + 'px';
	o.style.height = (app.my-oResize.y) + oResize.h + 'px';	}



function winCreate(id, w,h, x,y, bits)	{	if(id=='this')		return oOver.area;

	if(bits==undefined)			bits = 5;

if(id==undefined || id=='?')	{

	id = 'win'+iD;				iD++;	}

else{	var o = document.getElementById(id);	if(o!=undefined){	cookWin(id);	return id;	}	}


	if(w==undefined || w=='')		w = 200;		if(h==undefined || h=='')	h = 15;

	if(x==undefined || x=='')
		if(aWin[id]==undefined)		x = app.amx-28;	else	x = aWin[id].x;
	if(y==undefined || y=='')
		if(aWin[id]==undefined)		y = app.amy-28;	else	y = aWin[id].y;

	var type = 'c/img/custom';


//	var s = '<table cellpadding="0" cellspacing="0" width="'+ w +'" height="'+ h +'">';
	var s = '<table id="'+id+'_frame" cellpadding="0" cellspacing="0" width="'+ w +'" height="'+ h +'">';

	s += '<tr><td width="1" height="1"><img src="c/img/custom_nw.png" /></td><td background="c/img/custom_n.png"><img src="c/img/blank.gif" /></td><td><img src="c/img/custom_ne.png" /></td></tr>';

	s += '<tr><td background="c/img/custom_w.png"><img src="c/img/blank.gif" /></td><td background="'+ type +'_x.png" style="border:1px solid #5f5f5f">';

	s += '<table cellpadding="0" cellspacing="0" width="100%" height="24" onmouseout="win.head=\'\'" onmouseover="win.head=\''+ id +'\'" background="c/img/win_top.png" class="cms_title" style="border-bottom:1px solid #5f5f5f"><tr><td id="'+ id +'_title" style="vertical-align:middle; padding:5px"></td><td align="right" width="128" style="vertical-align:top">';

if(bits&4)
	s += '<img onmousedown="winHide(\''+ id +'\')" src="c/img/win_min.png" />';
if(bits&2)
	s += '<img onmousedown="winMax(\''+ id +'\')" src="c/img/win_max.png" />';
if(bits&1)
	s += '<img onmousedown="winClear(\''+ id +'\')" src="c/img/win_close.png" />';

	s += '</td></tr></table>';

	s += '<div id="'+ id +'"></div></td><td background="c/img/custom_e.png"><img src="c/img/blank.gif" /></td></tr>';

	s += '<tr><td><img src="c/img/custom_sw.png" /></td><td background="c/img/custom_s.png"><img src="c/img/blank.gif" /></td><td width="1" height="1"><img style="cursor:nw-resize" onmousedown="return setResize()" src="c/img/custom_se.png" /></td></tr></table>';


	var xWin = document.createElement("DIV");

	xWin.id = id+'_top';

//	xWin.style.width = w+'px';		xWin.style.height = h+'px';

	xWin.style.position = 'absolute';

//	xWin.style.visibility = 'hidden';

	xWin.style.left = x +'px';		xWin.style.top = y +'px';

	xWin.style.zIndex = app.GetZ();

	xWin.innerHTML = s;

//	alert(s);

if(aWin[id]==undefined)	{

	aWin[id] = Array();			aWin[id].title = 'O_o';
	aWin[id].x = x;				aWin[id].y = y;
	aWin[id].w = w;				aWin[id].h = h;

}	aWin[id].id = id;			aWin[id].status = '';


	byId('core_point').appendChild(xWin);

	cookWin(id);

	return id;

}





function LoadTaskbar()	{	var s = getCookie('sWin');	if(!s)		return;

	var a = explode(';', s);

for(var i=0; i<a.length; i++)	{	var n = a[i];		if(n=='')	continue;

	var win = getCookie('win_'+n);	if(win==null)	{	winRetire(n);	continue;	}

	aWin[n] = unpackArray(win);	aWin[n].status = 'fetch';	}	}



function refreshTaskbar()	{

	var o = byId('cp_panel');	if(!o)	return;

	var s = '<div class="cms_light">';		var names = '';

for(var i in aWin)
	if(aWin[i]!=undefined)	{	names += i+';';
		if(aWin[i].title=='')	aWin[i].title = '...';
		s += '<div onclick="winAlter(\''+ i +'\')" style="float:left">'+ aWin[i].title +'</div>';	}

	setCookie('sWin', names);	s += '</div>';	o.innerHTML = s;	}



function explode(sep,s)	{	var out = Array();	var p = 0, i = 0;
while(p!=-1 && i<s.length)	{
	i = s.indexOf(sep,p);	if(i==-1)		i = s.length;
	out.push( s.substring(p,i) );			p = i+sep.length;	}		return out;	}



function smartExplode(sep,s){	var a = explode(sep,s), c = a.length>>1, out = Array();
for(var i=0; i<c; i++)
	out[a[2*i]] = a[2*i+1];	return out;	}



function getHTML(id)	{	var o = document.getElementById(id);
if(o)	return o.innerHTML;	else	return '';	}


function getCleanHTML(id)	{	var o = document.getElementById(id);
if(o)	{
	var s = o.innerHTML;		KillId(o);
	return s;	}	else	return '';	}



function UnpackArray(s)	{	var xA = new Array();


	var xGroup = explode(String.fromCharCode(1)+String.fromCharCode(1), s);

for(var i=0; i<xGroup.length-1; i++)	{

	var xSub = explode(String.fromCharCode(1), xGroup[i]);


	xA[i] = new Array();

for(var j=0; j<xSub.length; j+=2)	xA[i][xSub[j]] = xSub[j+1];	}


	return xA;	}





function fixBlack(vis)	{		var o = byId('black_top');
	if(vis==undefined)		vis = 1;

	if(!o)		return;		if(vis)	o.style.visibility = 'visible';

	var x = (app.sw-o.clientWidth) / 2;
//	var y = (app.sh-o.clientHeight) / 2;

//	o.style.left = x+'px';

if(o.getAttribute('readonly')==null)
	amorQuery('black_top', 'x,'+x);
//	amorQuery('black_top', 'x,'+x+',y,'+y);

//	o.style.top = y+'px';

}



function fixBlack2(vis)	{		var o = byId('black2_top');
	if(vis==undefined)		vis = 1;

	if(!o)		return;		if(vis)	o.style.visibility = 'visible';

	var x = ((app.sw-o.clientWidth) / 2);
	var y = (app.sh-o.clientHeight) / 2;

//	o.style.left = x+'px';
//	o.style.top = y+'px';

if(o.getAttribute('readonly')==null)
	amorQuery('black2_top', 'x,'+x+',y,'+y);

//	alert(o.id);

}



function blackIt()	{		dTime('black');		runFade('blackout',0.85, 250);	setTimeout('fixBlack()', 250);	app.black = 1;	}
function blackIt2()	{		dTime('black2');	runFade('blackout',0.85, 250);	setTimeout('fixBlack2()', 250);	app.black = 1;	}

function inBlack()	{		return app.black;	}

function inWhite()	{		if(dTime('black')<500)	return;		clearScroll();
if(app.black)	{
	runFade('blackout',0, 250);	Hide('black_top');	Hide('black2_top');
	app.black = 0;			return 1;	}	return 0;	}



function FindBlocks(s,sign,sign2){	var out = Array();	var i = 0, i2 = 0;

while(i<s.length)	{
	i = s.indexOf(sign,i2);		if(i==-1)		return out;
	i2 = s.indexOf(sign2,i);	if(i2==-1)		i2 = s.length;

	out.push( s.substring(i+sign.length,i2) );	}	return out;	}



function ExecScripts(s)	{

	var xScript = FindBlocks(s, '<SCRIPT>', '</SCRIPT>');
	for(var i=0; i<xScript.length; i++)			setTimeout(xScript[i], 0);

	xScript = FindBlocks(s, '<script>', '</script>');
	for(var i=0; i<xScript.length; i++)			setTimeout(xScript[i], 0);

	xScript = FindBlocks(s, '<span style="display: none;">', '</span>');
	for(var i=0; i<xScript.length; i++)			setTimeout(xScript[i], 0);	}



function elemPos(o)	{					o = byId(o);
	if(o==undefined)					return new Array(0,0,0,0);

if(o.style.position=='absolute')
	if(o.offsetLeft!=0 && o.offsetTop!=0)			return new Array(o.offsetLeft, o.offsetTop, o.clientWidth, o.clientHeight);

	var x = 0,		y = 0,				w = o.clientWidth,	h = o.clientHeight;

while(o)	{						x += o.offsetLeft + o.clientLeft;
	y += o.offsetTop + o.clientTop;				o = o.offsetParent;
if(o)
	if(o.style.position=='absolute')	break;	}	return new Array(x,y,w,h);	}



function inAbsolute(o)	{	if(typeof(o)=='string')		o = document.getElementById(o);
	if(o==undefined)	return 0;			o = o.offsetParent;
while(o)	{
	if(o.style.position=='absolute')	return 1;	o = o.offsetParent;	}

	return 0;	}





function parseClip(o)	{		o = byId(o);
	if(o==undefined)		return new Array(0, 0, 0, 0);

	if(o.style.clip=='')		return new Array(0, o.clientWidth, o.clientHeight, 0);

	var a = o.style.clip.indexOf('(')+1,			b = o.style.clip.indexOf(')');
if(o.style.clip.indexOf(' ')==-1)
	var dim = explode(',', o.style.clip.substring(a,b));
else	var dim = explode(' ', o.style.clip.substring(a,b));

for(var i=0; i<4; i++)	{
if(dim[i].indexOf('auto')!=-1)
	dim[i] = 0;	else		dim[i] = parseInt(dim[i]);
	if(isNaN(dim[i]))		dim[i] = 0;	}

	return new Array(dim[0], dim[1], dim[2], dim[3]);	}



function uScreenWH()	{
if(document.documentElement)	{
	app.sw = document.documentElement.clientWidth;		app.sh = document.documentElement.clientHeight;	}
if(document.body)	{
	app.sw = document.body.clientWidth;			app.sh = document.body.clientHeight;	}	}



function fetchWheel()	{		wheelType = (/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";	}



function fetchOpacity()	{		if(app.opaq!='')	return;

if (typeof document.body.style.opacity == 'string')	{					// CSS3 compliant (Moz 1.7+, Safari 1.2+, Opera 9)
	app.opaq = 'opacity';		return;	}
else if (typeof document.body.style.MozOpacity == 'string')	{				// Mozilla 1.6 и младше, Firefox 0.8 
	app.opaq = 'MozOpacity';	return;	}
else if (typeof document.body.style.KhtmlOpacity == 'string')	{				// Konqueror 3.1, Safari 1.1
	app.opaq = 'KhtmlOpacity';	return;	}
else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5)	{	// Internet Exploder 5.5+
	app.opaq = 'filter';		return;	}

	app.opaq = false;		return;	}


//-A-m-o-r- -r-u-n-s- - - - - - - - - - - - - - - - - - - -


function amorThread()	{		var c = amorT.length,	xNow = new Array(0,0,0,0),	t = miliTime(),	cActive = 0;

for(var k=0; k<c; k++)	{		var i = amorT[k];

	if(i.done)			continue;		cActive++;

	var x = (t-i.ta) / i.time;	var o = i.node;
if(x<1)	{				x = Math.sin(x*1.570795);
	for(var j=0; j<i.pc; j++)	xNow[j] = i.va[j] + x * i.vd[j];
}	else	{			x = 1;			xNow = i.vb;			i.done = 1;	}
	for(var j=0; j<i.pc; j++)	o[i.op][j] = xNow[j];


switch(i.op)	{
case '_a':	setOpacity(o, xNow[0]);				break;

case '_c':	{						var q = 'rect(';
		if(i.vb[0]<0)	q += 'auto,';		else	q += parseInt(xNow[0]) +'px,';
		if(i.vb[1]<0)	q += 'auto,';		else	q += parseInt(xNow[1]) +'px,';
		if(i.vb[2]<0)	q += 'auto,';		else	q += parseInt(xNow[2]) +'px,';
		if(i.vb[3]<0)	q += 'auto)';		else	q += parseInt(xNow[3]) +'px)';

		o.style.clip = q;				break;	}

case '_w':	o.style.width = parseInt(xNow[0])+'px';		break;
case '_h':	o.style.height = parseInt(xNow[0])+'px';	break;
case '_x':	o.style.left = parseInt(xNow[0])+'px';		break;
case '_y':	o.style.top = parseInt(xNow[0])+'px';		break;	}	}


if(cActive==0)	{
	clearInterval(timer.amor);	timer.amor = 0;	}	}





function amorGetThread(id,op,time){	var c = amorT.length;

for(var i=0; i<c; i++)
	if(amorT[i].id==id && amorT[i].op==op)		break;			if(i>=c)
for(var i=0; i<c; i++)
	if(amorT[i].done==1)				break;

	var o = byId(id);		if(o==undefined)	return 0;	var a;

if(i>=c)	{			a = new Array();
	a.va = new Array(0,0,0,0);	a.vb = new Array(0,0,0,0);
	a.vd = new Array(0,0,0,0);	}		else			a = amorT[i];

	if(o[op]==undefined)		amorReset(o,op);

for(var j=0; j<4; j++)
	a.va[j] = o[op][j];		a.done = 0;

	a.id = id;			a.op = op;				a.node = byId(id);
	a.ta = miliTime();		a.tb = a.ta + time;			a.time = time;

if(timer.amor==0)
	timer.amor = setInterval('amorThread()', 1);	amorT.push(a);		return a;	}



function amorReset(o,op)	{
switch(op)	{
case '_a':
	o._a = new Array(getOpacity(o), 0,0,0);		return;
case '_c':
	o._c = parseClip(o);				return;
case '_w':
	o._w = new Array(o.clientWidth, 0,0,0);		return;
case '_h':
	o._h = new Array(o.clientHeight, 0,0,0);	return;
case '_x':
	o._x = new Array(o.offsetLeft, 0,0,0);		return;
case '_y':
	o._y = new Array(o.offsetTop, 0,0,0);		return;
case '_z':
	o._z = new Array(o.style.zIndex, 0,0,0);	return;	}	}



function amorAppend(id,op,time, v,v2,v3,v4)	{	var h = amorGetThread(id,op, time);
	if(typeof(h)!="object")				return;
if(op=='_c')
	h.pc = 4;	else	h.pc = 1;		h.vb = new Array(v,v2,v3,v4);

	for(var j=0; j<4; j++)				h.vd[j] = h.vb[j] - h.va[j];	}



function amorQuery(id,query,time)	{		var com = explode(',', query),	c = com.length;

	if(id=='')		return;			if(time==undefined)		time = 500;

for(var i=0; i<c; i++)		switch(com[i])	{

case 'a':	case 'x':	case 'y':
case 'z':	case 'w':	case 'h':	{	if((i+1)>c)	return;

		amorAppend(id, '_'+com[i],time, parseFloat(com[i+1]),0,0,0);
		i++;					break;	}

case 'c':	case 'p':	{			if((i+4)>c)	return;
		amorAppend(id, '_'+com[i],time, parseFloat(com[i+1]),parseFloat(com[i+2]),parseFloat(com[i+3]),parseFloat(com[i+4]));
		i += 4;					break;	}

default:	return;		}	}



function queryXY(id,x,y,time)	{
	if(id=='')		return;			if(time==undefined)		time = 500;
	amorAppend(id, 'x',time, x,0,0,0);		amorAppend(id, 'y',time, y,0,0,0);	}


//-A-m-o-r- -r-u-n-s- - - - - - - - - - - - - - - - - - - -


function IsCtrl()	{	return app.state & keyCtrl;	}
function IsShift()	{	return app.state & keyShift;	}

function FetchTime()	{	return new Date().getTime();	}

function FetchNumber()	{	return (new Date().getTime()) % 86400000;	}



function toURL(url,delay){	if(dTime('url')<5)	return;
	if(delay==undefined)	delay = 0;
if(delay==0)	{
if(url.indexOf('http://')!=-1)
	window.open(url,'_blank');
else	window.location.replace(url);			return;	}

	var s = 'window.location.replace(\''+url+'\')';	setTimeout(s,delay);	}





function blockRefresh(id){	wrapRequest('refresh', id, '?');	}
function blockReroute(id){	wrapRequest('reroute', id, '?');	}



function Drag()	{		if(DnD.on==0)		return;

	var o = document.getElementById('drag');

	if(o.style.visibility!='visible')		o.style.visibility = 'visible';

	var x = (app.mx+8),	y = (app.my-32);

	o.style.left = x+'px';				o.style.top = y+'px';	}



function Undrag()	{	if(DnD.on==0)		return;

	DnD.id = 0;		DnD.ref = '';
	DnD.id2 = 0;		DnD.ref2 = '';

	DnD.from = '';		DnD.to = '';		DnD.on = 0;

	DnD.x = app.mx;		DnD.y = app.my;

	var o = document.getElementById('drag');

	if(o)			o.style.visibility = 'hidden';	}



function DragAction(to,to2, link, ref,id,ref2,id2, xref,xid,xref2,xid2)	{

	if(DnD.ref=='')					return;

	if(ref==ref2 && id==id2)			return;

	var xURL = link + ref+','+id+','+ref2+','+id2 +','+ xref+','+xid+','+xref2+','+xid2;

	wrapRequest('cpx', '?', xURL);	}



function DragSelect(to, ref,id, ref2,id2)	{

	if(ref2==undefined)	ref2 = '';		if(id2==undefined)	id2 = 0;

if(IsShift())	{
	var a = ref;	ref = ref2;	ref2 = a;
	a = id;		id = id2;	id2 = a;	}	DnD.from = to;

if(DnD.select!=undefined)	if(FetchTime()<DnD.select)
	return false;		DnD.select = FetchTime() + 100;

if(ref!=undefined && ref!='')	{
	DnD.id = id;		DnD.ref = ref;	}	else	DnD.ref = '';

	DnD.id2 = id2;		DnD.ref2 = ref2;

	DnD.x = app.mx;		DnD.y = app.my;		DnD.on = 1;

	return false;	}



function DragBind(to,link, ref,id,ref2,id2)	{

	if(ref2==undefined)	ref2 = '';		if(id2==undefined)	id2 = 0;

if(IsShift())	{
	var a = ref;	ref = ref2;	ref2 = a;
	a = id;		id = id2;	id2 = a;	}	DnD.to = to;

if(DnD.bind!=undefined)		if(FetchTime()<DnD.bind)
	return false;		DnD.bind = FetchTime() + 100;

	var Range = Math.abs(DnD.x-app.mx)+Math.abs(DnD.y-app.my);
	if(Range<5)		return true;


	DragAction(DnD.from,DnD.to, link, DnD.ref,DnD.id, ref,id, DnD.ref2,DnD.id2, ref2,id2);


	Undrag();		return false;	}





function miMenuClear()	{	if(timer.menu)		clearTimeout(timer.menu);	}

function miOverClear()	{	oOver.ref = '';		oOver.mod = '';		oOver.mi = '';
	oOver.mx = 0;		oOver.my = 0;		miMenuClear();		return true;	}

function miOver(mi,ref)	{	if(mi==undefined)	return false;
	if(ref==undefined)				ref = '';

	var a = explode('_', mi);			oOver.mod = a[0];

	oOver.mi = mi;		oOver.ref = ref;	return true;	}



function areaOver(id)	{
	if(dTime('areaSelect')>10)			return false;
	oOver.area = id;				return true;	}





	var inAccCheck = 0;

function AccCheck()	{		inAccCheck = 1;

	var x = document.getElementsByName('acc[]');

for(var i=0; i<x.length; i++)	{
	setTimeout(x[i].onchange,1);	}

	setTimeout('inAccCheck = 0',50);	}



function AccCheck2(el,req)	{

	if(req=='')			return;

	var parent = document.getElementById(req);
	var child = document.getElementById(el);

if(parent==undefined)	{
	child.checked = 0;		return;	}

if(child.checked)
	if(parent.checked==0)	{

if(inAccCheck)
	child.checked = 0;	else	parent.checked = 1;

	setTimeout(parent.onchange,1);	}	}





function SetGroup(name,v,vv,vvv){	var x = document.getElementsByName(name);

if(vvv==undefined)
	for(var i=0; i<x.length; i++)	x[i][v] = vv;
else	for(var i=0; i<x.length; i++)	x[i][v][vv] = vvv;	}



function CustomHV(name,v,input,vv)	{

	SetGroup(name,'style','backgroundColor','#ffffff');
	v.style.backgroundColor = '#bfbfbf';

	var x = document.getElementsByName(input);
	x[0].value = vv;	}





function FixPosition(id)	{	o = document.getElementById(id+'_top');		var w = aWin[id];
	if(o==undefined)		return;		o.style.visibility = 'visible';

	if(w==undefined)		return;		var x = w.x,	y = w.y;

if((w.x+o.clientWidth+16) > app.sw)	{
if(o.clientWidth > app.sw)
	x = 0;
else	x = app.sw - o.clientWidth-16;	}	else	if(w.x<0)	x = 0;

if((w.y+o.clientHeight) > app.sh)	{
if(o.clientHeight > app.sh)
	y = 0;
else	y = app.sh - o.clientHeight;	}	else	if(w.y<0)	y = 0;

	o.style.left = x+'px';		o.style.top = y+'px';

	aWin[id].x = x;			aWin[id].y = y;			cookWin(id);	}



function PatchPosition(o)	{
if(app.mx<o.offsetLeft || app.mx>(o.offsetLeft+o.clientWidth))		o.style.left = app.mx-32 + 'px';
if(app.my<o.offsetTop || app.my>(o.offsetTop+o.clientHeight))		o.style.top = app.my-32 + 'px';	}



function InPosition(o)	{
if(app.mx<o.offsetLeft || app.mx>(o.offsetLeft+o.clientWidth) || app.my<o.offsetTop || app.my>(o.offsetTop+o.clientHeight))
	return false;				return true;	}





function UpdateXY(elem,aEvent)	{		var e = aEvent ? aEvent : window.event;

	aElem[0] = e.offsetX;			aElem[1] = e.offsetY;
	aElem[2] = elem.clientWidth;		aElem[3] = elem.clientHeight;		return false;	}





function Bind(aEvent)	{			var e = aEvent ? aEvent : window.event;

if(win.head!='')	{			win.bound = win.head;			var xWin = byId(win.bound+'_top');
	if(!xWin)				return;					iWin = aWin[win.bound];
	win.dx = iWin.x - app.mx;		win.dy = iWin.y - app.my;		return false;	}

	return true;	}



function MoveWin(aEvent){	var e = aEvent ? aEvent : window.event;

	app.amx = e.clientX;	app.amy = e.clientY;

	app.mx = app.amx+document.documentElement.scrollLeft;
	app.my = app.amy+document.documentElement.scrollTop;

	Drag();

	aResize();

	var xWin = byId(win.bound+'_top');		if(!xWin)	return true;

	iWin.x = app.mx + win.dx;			iWin.y = app.my + win.dy;

	xWin.style.left = iWin.x + 'px';		xWin.style.top = iWin.y + 'px';

	return false;	}

	

function BindWin(id,e)	{

	win.bound = id;					win.last = id;

	var xWin = byId(id+'_win');			iWin = aWin[id];

	win.dx = iWin.x - app.mx;			win.dy = iWin.y - app.my;

	return false;	}



function UndragWin()	{	Undrag();

	if(win.bound)	{	cookWin(win.bound);	FixPosition(win.bound);	}

	win.bound = '';		return true;	}



function Console(aEvent){	var e = aEvent ? aEvent : window.event;

	var xConsole = document.getElementById('console_input');		if(e.keyCode==96)	return false;
if(e.keyCode==13)	{
	wrapRequest('console','console_output','?com='+Base64.encode(xConsole.value));			xConsole.value = '';	}	}





function CreateDiv(x,y,w,h, text,parent){	var xDiv = document.createElement("DIV");

	parent = byId(parent);			if(parent==undefined)		parent = byId('core_point');

	xDiv.style.position = 'absolute';	xDiv.style.zIndex = app.GetZ();
	xDiv.style.left = x +'px';		xDiv.style.top = y +'px';
if(w)	xDiv.style.width = w+'px';	if(h)	xDiv.style.height = h+'px';

	xDiv.innerHTML = text;			parent.appendChild(xDiv);	return xDiv;	}



function FixRadialPos(a,r)	{}



function RadialPos(i,from, r)	{

	var xAngle = (i/from)*6.283152 - 3.14159, dx = 0, dy = 0;

	return {0:r*Math.cos(xAngle)+dx, 1:r*Math.sin(xAngle)+dy};	}



function PlanarPos(i,from, r)	{		var dx = from*r/2;		return {0:r*i-18, 1:0};	}



function KillId(id)	{			id = byId(id);

if(id)	{					var xNode = byId('core_point');
	try{	xNode.removeChild(id);	}	catch(e)	{}

	delete id;	}	}

function delayedKill(id,time)	{		if(time==undefined)		time = 1000;	setTimeout('KillId("'+ id +'")', time);	}



function miEdit(mi,lang,win)	{		var a = explode('_', mi);
	if(lang==undefined)	lang = '';	if(win==undefined)		win = '?';
	if(a[0]=='ref')		return;		var q = '?route=route;cp_edit;mi;'+ mi +';mod;'+ a[0] +';item;'+ a[1] +';lang;'+ lang +';edge;'+ oDown.ref;

	winRQ(q,win);	}

function propEdit(mi,win)	{		var q = '?route=route;cp_edit2;mi;'+ mi;	winRQ(q,win);	}

function miCreate(mi)	{	winRQ('?route=route;test_create;mi;'+mi, '?', 480);	}



function miNew(mod,ref,key,prop)	{

	if(ref==undefined)			return;
	if(key==undefined)			key = '';
	if(prop==undefined)			prop = '';

	var q = '?route=route;cp_edit;mi;'+ mod +'_0;mod;'+ mod +';ref;'+ ref +';key;'+ key +';prop;'+ prop;

	winRQ(q);	}



function miMenu(up)	{			if(checkAcc('menu')==0)		return;

	oOver.xarea = oOver.area;		xAction = '?route=route;test_test';

if(oDown.mi)	{

	var list = 'edit,new,prop,copy,kill,conduct';

	var r = Math.abs(app.mx-oDown.mx) + Math.abs(app.my-oDown.my);
	if(up==0)	if(r>50)	{	miMenuClear();			return;	}

if(up==0)	{

	if(oDown.ref)		list += ',cut,unref';

	if(list)		list += ',tag';		else	list = 'order,tag';

	if(oBuffer.op)				if(oBuffer.mi!=oMenu.mi)	list += ',paste';

}	else	{

	list = 'order';

}


}	else	{

	var list = 'cp,root,question,exit';

}

	var xList = explode(',', list),		xR = 64+1*(xList.length-2),	xID = uniqid();

	if(xList.length==0)			return;


if(xList.length==1)	if(xList[0]!='paste')	{
	wrapRequest('cpx','?',xAction+';op;'+xList[0]+';mi;'+oDown.mi+';ref;'+oDown.ref+';mi2;'+oOver.mi+';ref2;'+oOver.ref);	return;	}


	var xMenu = CreateDiv(app.amx-xR, app.amy-xR, 2*xR,2*xR, '', 'core_point');

	xMenu.id = xID;				xMenu.onclick = 'return false';

for(var i=0; i<xList.length; i++)	{	if(xList[i]=='')		continue;

	var x = RadialPos(i,xList.length, xR),	xTitle = '';


	xText = '<img alt="" width="48" height="48" onmouseup="';		var iAction = 1;
switch(xList[i])	{
case 'copy':	case 'cut':
	xText += 'oBuffer.mi=\''+oDown.mi+'\'; oBuffer.ref=\''+oDown.ref+'\'; oBuffer.op=\''+xList[i]+'\'; oBuffer.area=\''+oDown.area+'\';';
if(xList[i]=='copy')
	xTitle = 'Копировать';		else	xTitle = 'Вырезать';		iAction = 0;		break;

case 'kill':
	xTitle = 'Удалить';
	xText += 'if(confirm(\'Удалить?\'))';					break;

case 'conduct':
	xTitle = 'Открыть';			$iAction = 0;
	xText += "winRQ('?route=route;test_conductor;key;;mi;'+oDown.mi,'?',866,572, '','',7);";
	break;

case 'unref':
	xTitle = 'Удалить ссылку';		break;

case 'edit':
	xTitle = 'Редактировать';		iAction = 0;
	xText += 'miEdit(\''+oDown.mi+'\');';	break;

case 'prop':
	xTitle = 'Редактировать';		iAction = 0;
	xText += 'propEdit(\''+oDown.mi+'\');';	break;

case 'tag':
	xTitle = 'В избранное';							iAction = 0;
	xText += 'winRQ(\'?route=route;test_tag;mi;'+oDown.mi+'\');';		break;

case 'new':
	xTitle = 'Создать подчиненный объект';					iAction = 0;
	xText += 'miCreate(\''+oDown.mi+'\')';					break;

case 'paste':
	xTitle = 'Вставить';							iAction = 0;
if(oDown.mi!=oBuffer.mi)
	xText += 'wrapRequest(\'cpx\',\'?\',\''+xAction+';op;'+xList[i]+';area;'+oDown.area+';mi;'+oDown.mi+';ref;'+oDown.ref+';op2;'+oBuffer.op+';area2;'+oBuffer.area+';mi2;'+oBuffer.mi+';ref2;'+oBuffer.ref+'\')';
	break;	}

if(iAction)
	xText += 'wrapRequest(\'cpx\',\'?\',\''+xAction+';op;'+xList[i]+';area;'+oDown.area+';mi;'+oDown.mi+';op2;'+oBuffer.op+';ref;'+oDown.ref+';mi2;'+oOver.mi+';ref;'+oOver.ref+'\')';

	xText += ';KillId(\''+xID+'\')" src="c/img/'+xList[i]+'_48" title="'+ xTitle +'" />';


	var xDiv = CreateDiv(xR-24+x[0],xR-24+x[1], 0,0, xText,xMenu);

}	var xDiv = CreateDiv(xR-12,xR-12, 0,0, '<img src="c/img/nexus_48" width="24" onmouseup="KillId(\''+xID+'\')" />',xMenu);



	miMenuClear();

}





function cpMenu()	{			if(checkAcc('duncan')==0)	return;

	var r = Math.abs(app.mx-oDown.mx) + Math.abs(app.my-oDown.my);
	if(r>50)	{	miMenuClear();	return;	}

	var list = 'conduct,exit';


	var xList = explode(',', list),		xR = 48+2*(xList.length-2),	xID = uniqid();
	if(xList.length==0)			return;


	var xMenu = CreateDiv(app.amx-xR, app.amy-xR, 2*xR,2*xR, '', byId('core_point'));

	xMenu.id = xID;				xMenu.onclick = 'return false';

for(var i=0; i<xList.length; i++)	{	if(xList[i]=='')		continue;

	var x = RadialPos(i,xList.length, xR),	xTitle = '';


	xText = '<img alt="" width="48" height="48" onmouseup="';		var iAction = 1;
switch(xList[i])	{
case 'conduct':
	xText += "winRQ('?route=route;test_conductor;key;','?',866,500);";
	break;

case 'hide':
	xText += "winHideAll();";
	break;

case 'exit':
	xText += "if(confirm('Закончить сессию?')) toURL('?&logout');";
	break;

case 'max':
	break;

case 'min':
	break;	}


	xText += ';KillId(\''+xID+'\')" src="c/img/'+xList[i]+'" title="'+ xTitle +'" />';


	var xDiv = CreateDiv(xR-24+x[0],xR-24+x[1], 0,0, xText,xMenu);

}	var xDiv = CreateDiv(xR-12,xR-12, 0,0, '<img src="c/img/nexus_48" width="24" onmouseup="KillId(\''+xID+'\')" />',xMenu);



	miMenuClear();

}





function Key1(key)	{
	if(app.down[0]==key)	return 1;		return 0;	}

function Key2(key)	{
	if(app.down[0]==(key&0xff))
		if(app.down[1]==((key>>8)&0xff))
			return 1;			return 0;	}

function Key3(key)	{
	if(app.down[0]==(key&0xff))
		if(app.down[1]==((key>>8)&0xff))
			if(app.down[2]==((key>>16)&0xff))
				return 1;		return 0;	}

function KeyClear()	{
	app.down[0] = 0;	app.down[1] = 0;	app.down[2] = 0;	app.down[3] = 0;	}



function KeyDown(aEvent){	var e = aEvent ? aEvent : window.event;
for(var i=3; i>0; i--)
	app.down[i] = app.down[i-1];			app.down[0] = e.keyCode;

	if(e.keyCode==16)	app.state |= keyShift;	if(e.keyCode==17)	app.state |= keyCtrl;

if(e.keyCode==27)	{	var xCP = document.getElementById('cp');	if(xCP)	{
	if(inWhite()==0)	{
if(xCP.style.visibility=='visible')
	xCP.style.visibility = 'hidden';	else	xCP.style.visibility = 'visible';	}	}

}


	var val = true;		if(Key1(0x11))		val = false;

if(Key2(0x1145))
	winRQ('?route=route;test_conductor;key;', 'conduct', 820,560);

if(Key3(0x111111))	{
	winRQ('?route=route;login_who','login', 325,50);	KeyClear();	}

if(e.keyCode==27)	{

	if(win.last=='')	return true;		winClear(win.last);	}

	return val;	}



function KeyUp(aEvent)	{	var e = aEvent ? aEvent : window.event;
for(var i=3; i>0; i--)
	app.up[i] = app.up[i-1];			app.up[0] = e.keyCode;

	if(e.keyCode==16)	app.state &= ~keyShift;	if(e.keyCode==17)		app.state &= ~keyCtrl;

	if(Key1(0xc0))	{	var xConsoleI = document.getElementById('console_input');
	if(xConsoleI)	{	if(ToggleDisplay('console'))	xConsoleI.focus();	setOpacity('console',0.75);	}	}

	return true;	}



function MouseDown(aEvent)	{	var hRes = true;

if(checkAcc('duncan'))	{
if(oOver.mi)	{			oDown.mi = oOver.mi;
	oDown.ref = oOver.ref;		oDown.area = oOver.area;

	oDown.mx = app.mx;		oDown.my = app.my;

	timer.menu = setTimeout('miMenu(0)', 500);	return false;	}

if(IsShift())	{
	oDown.mx = app.mx;		oDown.my = app.my;
	timer.menu = setTimeout('cpMenu()', 250);	return false;	}	}

	return Bind(aEvent ? aEvent : window.event);	}



function MouseUp(aEvent)	{	miMenuClear();

if(oOver.mi!='' && oDown.mi!='')	if(oOver.mi!=oDown.mi)	{
	miMenu(1);			return true;	}

	timer.menu = 0;			oDown.mi = '';

	unsetResize();			return UndragWin();	}





function CustomShow(show,hide,prefix)	{		var a = explode(',', hide),	c = a.length;
	if(prefix==undefined)				prefix = '';

	var o = document.getElementById(prefix+show);	if(o)	o.style.display = 'inline';
for(var i=0; i<c; i++)					if(a[i]!=show)	{
	o = document.getElementById(prefix+a[i]);	if(o)	o.style.display = 'none';	}	}



function procNames(id,op,val)	{	var a = document.getElementsByName(id);		var c = a.length;

for(var i=0; i<c; i++)	{

switch(op)	{
case 'hide':	a[i].style.visibility = 'hidden';	break;
case 'show':	a[i].style.visibility = 'visible';	break;
case 'check':	a[i].checked = 1;			break;
case 'uncheck':	a[i].checked = 0;			break;
case 'docheck':	a[i].checked = val;			break;

case 'smartcheck':
if(val)	{	if(i==from)		a[i].checked = val;	}
else		a[i].checked = val;	break;	}	}	}



function ProcGroup(id,from,to,op,val)	{

for(var i=from; i<=to; i++)	{

	var name = id + '_' + i,	oSrc = document.getElementById(name);

if(oSrc)	switch(op)	{
case 'hide':	oSrc.style.display = 'none';		break;
case 'show':	oSrc.style.display = 'inline';		break;
case 'check':	oSrc.checked = 1;			break;
case 'uncheck':	oSrc.checked = 0;			break;
case 'docheck':	oSrc.checked = val;			break;

case 'smartcheck':
if(val)	{	if(i==from)		oSrc.checked = val;	}
else		oSrc.checked = val;	break;	}	}	}



function xProcGroup(id,from,to,one,op,val)	{

switch(op)	{
case 'show':
//	alert(id+' '+from+' '+to+' '+one+' '+op);
	ProcGroup(id,from,to,'hide');
	ProcGroup(id,one,one,'show');			break;	}	}



function ShowOne(id,one,total)	{

	ProcGroup(id,0,total-1,'hide');	ProcGroup(id,one,one,'show');	}




function CheckParent(id,set)	{	var a = 0, b = 0, s, oSrc;

for(var i=0; i<9; i++)	{
	a = set.indexOf('.', a)+1;	if(a==0)	break;
	b = set.indexOf(',', a);	if(b==-1)	break;

	s = set.substring(a,b);
	var name = id + '_' + s;	oSrc = document.getElementById(name);
	if(oSrc)			oSrc.checked = 1;	}	}



function togglemenu(oUlId)	{
	var oUl=document.getElementById(oUlId);
	oUl.style.display=((oUl.style.display=="none") ? 'block' : 'none');	}

function vismenu(oUlId)	{
	var oUl=document.getElementById(oUlId);
	oUl.style.display='block';	}

function hidmenu(oUlId)	{
	var oUl=document.getElementById(oUlId);
	oUl.style.display='none';	}


function runMenu(id)	{
	s = "vismenu('" + id + "')";
	setTimeout(s,500);	}


function open_window(link,w,h)	{
	var xWin = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
	newWin = window.open(link,'order', xWin);	}



function miscop(src,dst)	{

	iD++;

	var oSrc = document.getElementById(src);
	var oDst = document.getElementById(dst);

	var xAct = 'var oSrc = document.getElementById(\'form_' + iD + '\');	oSrc.innerHTML = \'\';';

	oDst.innerHTML += '<span id="form_' + iD + '">' + oSrc.innerHTML + '<center class="link" align="right"><b style="cursor:pointer" onclick="' + xAct + '">Удалить</b></center></span>';	}



function doop(dst,check)	{
	var o = document.getElementById(dst);
if(check.checked==true)
	o.style.display = 'block';
else	o.style.display = 'none';	}





function asyncPage(s)	{			var xs = '', xPos=0, lPos = 0;

while(xPos=s.indexOf('href="?',xPos+6))	{	if(xPos==-1)	break;

	xs += s.substring(lPos,xPos+6);		lPos = s.indexOf('"', xPos+6);
	var link = 'javascript:LoadPage(\'' + s.substring(xPos+6,lPos) + '\')';

	xs += link;	}			xs += s.substring(lPos,s.length);	return xs;	}



function uPage()	{
	var oTodo = document.getElementById('todos');
	oTodo.innerHTML = asyncPage(oTodo.innerHTML);	}



function FetchReq()	{			var req;

if (window.XMLHttpRequest) {			req = new XMLHttpRequest();
	if (req.overrideMimeType)		req.overrideMimeType('text/xml');
} else if (window.ActiveXObject){
	try {   req = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {	req = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {}	}	}

if (!req) {	alert('Giving up :( Cannot create an XMLHTTP instance');	return req;	}

	return req;	}





function patchString(s,a,b)	{		var xs = '', xPos=0, lPos = 0;

while(xPos=s.indexOf('href="?',xPos+6))	{	if(xPos==-1)	break;

	xs += s.substring(lPos,xPos+6);		lPos = s.indexOf('"', xPos+6);
if(s[xPos+7]=='&')
	xs += s.substring(xPos+6,lPos);
else	xs += a + s.substring(xPos+6,lPos) + b;	}

	xs += s.substring(lPos,s.length);	return xs;	}



function getCaps()	{
//	var s = '?java=1;sw=' + screen.width + ';sh=' + screen.height;
//	return s;
	return '';
}



function callURL(url)	{			var req = false;
	req = new FetchReq();			if (!req)	return;
	req.open('GET', url, true);		req.send(null);	}



function execURL(url)	{			var req = false;	//	alert(url);
	req = new FetchReq();			if (!req)	return;
	req.open('GET', url+'&async=31', true);	req.send(null);	}








function routeRQ(route,p,to)	{		var s = '?route=route;'+ route;
	if(p)	s += ';'+ p;			wrapRequest('route',to, s);	}



function winRQ(url,win, w,h,x,y, bits)	{	var O = document.getElementById(win);
if(!O)	{
	win = winCreate(win, w,h,x,y,bits);	wrapRequest('win',win, url);	}

else	wrapRequest('cpx',win, url);	}






function wrapFunc(id,id2,time)	{//		alert(id + ' x ' + id2);

	var elemA = document.getElementById(id);
	var elemB = document.getElementById(id2);

//	elemA.innerHTML = elemB.innerHTML;
	KillId(elemB);

}



function animateX(o,x)	{

	var oElem = document.getElementById(o),			xElem = document.getElementById(x);

//	oElem.innerHTML = xElem.innerHTML;

//	oElem.innerHTML = '123';

//	alert(xElem.innerHTML);

if(xElem!=undefined)
	KillId(xElem);

//	document.title = xElem.style.visibility +' x '+ xElem.style.opacity;

//	setOpacity(o, 1);

//	oElem.style.height = '';

//	oElem.style.height = '';

}



function addEvent(o, eve, handler)	{	o = byId(o);
if(o.attachEvent)
	o.attachEvent('on'+eve, handler);
else	o.addEventListener(eve, handler, false);	}


function remEvent(o, eve, handler)	{
	if(typeof(o)=='string')			o = document.getElementById(o);
if(o.detachEvent)
	o.detachEvent('on'+eve, handler);
else	o.removeEventListener(eve, handler, false);	}






function stopBubble(event)	{		event = event || window.event;
	event.stopPropagation ? event.stopPropagation() : (event.cancelBubble=true);	}



function SetArea(o)	{	o = byId(o);	if(!o)			return;
if(!o.xmouseover)	{
	addEvent(o, 'mouseover', function () {if(dTime('area')>5)	oOver.area = o.id;	});
	o.xmouseover = 1;	}	}



function winTitle(id,s)	{	var oTitle = byId(id+'_title');
if(oTitle)	{
	aWin[id].title = s;	cookWin(id);
	refreshTaskbar();	oTitle.innerHTML = s;	}	}



function hexdec (hex_string) {
	hex_string = (hex_string + '').replace(/[^a-f0-9]/gi, '');	return parseInt(hex_string, 16);	}

function getText(node)	{	if(node.textContent==undefined)		return node.text;	else	return node.textContent;	}

function wrapJoint(req, inter)	{

if (req.readyState==4)	{
	if (req.status!=200)
		alert('There was a problem with the request.');	}	else	return;


	s = req.responseText;	//	alert(s);

if(window.DOMParser)	{
	parser = new DOMParser();	xmlDoc = parser.parseFromString(s, "text/xml");
}	else	{			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async = "false";		xmlDoc.loadXML(s);	}


	var aWrap = xmlElements(xmlDoc, 'wrap'),		o, oTop, oTitle, sTitle;

for(i in aWrap)	{	var id = aWrap[i].getAttribute('id');	o = byId(id);

	var sText = aWrap[i].textContent;			if(sText==undefined)		sText = aWrap[i].text;

if(o==undefined)	{					var xElem = document.createElement("DIV");
	xElem.innerHTML = getText(aWrap[i]);			byId('core_point').appendChild(xElem);
	xElem.id = uniqid();					delayedKill(xElem.id);	}

	ExecScripts(getText(aWrap[i]));				if(o==undefined)	continue;

	o.innerHTML = getText(aWrap[i]);			sTitle = xmlElements(xmlDoc, 'title','id',id);
	if(sTitle)						winTitle(id, getText(sTitle[0]));

	FixPosition(id);					SetArea(o);	}


	xData = xmlElements(xmlDoc, 'xdata');			if(xData.length)
for(i in xData)	{
	var xRoute = xData[i].getAttribute('route');		window[xRoute](xData[i]);	}

}





function wrapRequest(id,to,url,inter,a,b){	if(to=='')	to = id;	//	alert(to+' : '+url);

if(oOver.area)	{
	url = url.replace('route=', 'route=parent;'+oOver.area+';');	}	//	alert(to+' : '+url);

	var xList = explode(',', to);
for(var i=0; i<xList.length; i++)	{	var xID = document.getElementById(xList[i]);
	if(xID)					if(xID.innerHTML=='')		xID.innerHTML = '<div style="position:absolute"><img alt="" src="c/img/wait.gif" /></div>';	}

if(inter==undefined)
	inter = 0;
if(a==undefined || a=='')
	a = 'javascript:wrapRequest(\''+ id +'\',\''+ to +'\',\'';
if(b==undefined || b=='')
	b = '\','+ inter +')';					var req = false;


	req = new FetchReq();			if (!req)	return;
	req.onreadystatechange = function() {			wrapJoint(req,inter);	}
	req.open('GET', url+'&async=31&wrap='+id+'&wrapto='+to, true);		req.send(null);	}





function wrapiRequest(id,to,url,inter,a,b, time)	{
	var s = 'wrapRequest(\''+id+'\', \''+id+'\', \''+url+'\', '+inter+', \''+a+'\', \''+b+'\')';
	setInterval(s, time);	}





function eBehave(o)	{
if(app.down[0]==9)	{
	insertAtCursor(o,String.fromCharCode(9)); return false;	}

	return true;	}



function insertAtCursor(myField, myValue) {	if(typeof(myField)=='string')	myField = document.getElementById(myField);

//  Для MSIE   
if (document.selection)	{
	myField.focus();
	sel = document.selection.createRange();
	sel.text = myValue;	}

// Для нормальных браузеров   
else if (myField.selectionStart || myField.selectionStart == '0')	{
	var startPos = myField.selectionStart;
	var endPos = myField.selectionEnd;
	myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);

	myField.selectionStart = startPos + 1;
	myField.selectionEnd = endPos + 1;

}

// Для остальных
else	myField.value += myValue;	}  



function curStyle(el, cssprop){
if (el.currentStyle) //IE
	return el.currentStyle[cssprop]
else if (document.defaultView && document.defaultView.getComputedStyle) //Firefox
	return document.defaultView.getComputedStyle(el, "")[cssprop];
else	//try and get inline style
	return el.style[cssprop];	}





function getOpacity(o)	{		if(typeof(o)=='string')			o = document.getElementById(o);

	if(app.opaq=='')		fetchOpacity();

	if(curStyle(o,'visibility')=='hidden')					return 0;

if(app.opaq=="filter")	{		var oAlpha = o.filters['DXImageTransform.Microsoft.alpha'] || o.filters.alpha;
	if (oAlpha)			return oAlpha.opacity / 100;		return 1;	}

if(o.style[app.opaq]=='' && o.style[app.opaq]!='0')
	return 1;			return parseFloat(o.style[app.opaq]);	}



function setOpacity(o,alpha)	{	if(app.opaq=='')			fetchOpacity();

	if(typeof(o)=='string')		o = document.getElementById(o);		if(!o || !app.opaq)	return;

	if(alpha==0)		{	o.style.visibility = 'hidden';		return;	}

	if(curStyle(o,'visibility')=='hidden' && alpha!=0)			o.style.visibility = 'visible';

if (app.opaq=="filter")	{		alpha *= 100;
	var oAlpha = o.filters['DXImageTransform.Microsoft.alpha'] || o.filters.alpha;
	if (oAlpha)			oAlpha.opacity = alpha;
	else o.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+alpha+")";  }

else	o.style[app.opaq] = alpha;	}





function miliTime()	{		var xTime = FetchTime();	return xTime;	}



function runFade(id,to, time)	{	if(!byId(id))			return;
	if(time==undefined)		time = 1000;			amorQuery(id, 'a,'+to, time);	}

function fadeIn(id, time)	{	runFade(id,1, time);	}
function fadeOut(id, time)	{	runFade(id,0, time);	}




function SlideRoutine(list,delay,period,index)	{			var xList = explode(',', list);

	var xIndex = index+1;		if(xIndex>=xList.length)	xIndex = 0;

	if(delay<=period)		delay = period;

	fadeOut(xList[index], period);					fadeIn(xList[xIndex], period);

	var s = 'SlideRoutine(\''+list+'\','+delay+','+period+','+xIndex+')';

	setTimeout(s, delay);	}


function SlideShow(list,delay,period)	{

	var s = 'SlideRoutine(\''+list+'\','+delay+','+period+',0)';

	setTimeout(s, delay);	}





function openView(mi,view)	{			var name = 'cat_'+mi;

	var o = document.getElementById(name),		oo = document.getElementById(name+'_x');

if(o.innerHTML!='')	{
	execURL('?op=cf='+ mi +','+view);		o.innerHTML = '';	o.style.height='';	}
else{	wrapRequest('mod',name, '?mod=of='+ mi +';vf='+ mi +','+ view);	}	}



function closeView(mi,view)	{			var name = 'cat_'+mi;	var o = document.getElementById(name);
if(o.innerHTML!='')	{
	execURL('?op=cf='+ mi +','+view);		o.innerHTML = '';	o.style.height='';	}	}





function FrameContent(id)	{			var x = document.getElementById(id);

if (x.contentDocument)
	var d = x.contentDocument;	else
if (x.contentWindow)
	var d = x.contentWindow.document;
else	var d = window.frames[id].document;		return d.body.innerHTML;	}




	var cpPanel = 'cp_x';

function asyncPatchString(s)	{	var a = 'javascript:wrapRequest(\'cpx\',\''+ cpPanel + '\',\'';
	ExecScripts(s);
	var b = '\')';			return patchString(s, a,b);	}



function submitClose(form)	{	app.submit = oOver.area;	app.form = form;
	var o = byId(form);	if(o){	if(o.onsubmit) if(o.onsubmit()==false) return;	winHide(oOver.area,0);	o.submit();	}	}

function submitApply(form)	{	app.submit = 'apply';		app.form = form;
	var o = byId(form);		if(o)				o.submit();	}

function submitUpdate(form)	{	app.submit = '';		app.form = form;	var o = byId(form);
if(o)	{
	if(o.onsubmit)	{
		if(o.onsubmit())	o.submit();	}	else	o.submit();	}	}


function LinkFrame(frame,out)	{
					var x = document.getElementById(out);
if(x)	{				var z = asyncPatchString(FrameContent(frame));

	if(app.submit=='apply')	{	app.submit = '';	return;	}
	if(app.submit)		{	winClear(app.submit);	app.submit = '';	return;	}

	if(z!='')			x.innerHTML = z;	}			app.submit = '';	}



function CloseFrame(id,win)	{	var s = FrameContent(id);
if(s!='')	{
	winClear(win);			ExecScripts(s);	}	}



function validateUser()	{		xForm = window.document.form;			var oPW = document.getElementById('opw');
	if(oPW)
	if(oPW.value=="")	{	window.alert("Вы не указали пароль");		oPW.focus();		return false; }

	return true;	}





function capsRequest(redraw)	{

	fetchWheel();		fetchOpacity();

	var caps = "?caps&body="+app.sw+'x'+app.sh+"&screen="+screen.width+'x'+screen.height+"&depth="+(((navigator.appName.substring(0,3)=="Mic"))?screen.colorDepth:screen.pixelDepth);

	caps += '&alpha='+app.opaq+'&wheel='+wheelType;

	req = new FetchReq();				if(req)	{
	req.open('GET', caps, true);			req.send(null);
if(redraw)
	setTimeout('window.location.replace(document.URL)', 500);	}	}





function Scroll(dx,dy, name,dt)	{	if(name==undefined)	name = scroll.name;	if(name==undefined)	return false;

	var xX = byId(name+'_bar');	var xH = byId(name+'_hbar');			var xV = byId(name+'_vbar');
	if(dt==undefined)								dt = 250;

	var xClip = name+'_clip';	var xAbs = inAbsolute(name);			var xBeacon = elemPos(name+'_beacon');


	var view = elemPos(name),	clip = elemPos(xClip);
//document.title = clip;
	var x = clip[0],		y = clip[1];		if(dy==undefined)	dy = 0;

	var vS = view[3],		hS = view[2];
	if(xV)				hS -= 16;
	if(xH)				vS -= 16;

	if(clip[3]<=view[3])	{	clip[3] = vS;		if(dy!=0 && dx==0){	dx = dy;	dy = 0;	}	}
	if(clip[2]<=view[2])	{	clip[2] = hS;	}

	x += dx/2;			y += dy/2;

	var minX = xBeacon[0] + hS - clip[2],			maxX = xBeacon[0];
	var minY = xBeacon[1] + vS - clip[3],			maxY = xBeacon[1];
//document.title = minX+' : '+maxX;
	if(x<minX)	x = minX;	if(x>maxX)		x = maxX;
	if(y<minY)	y = minY;	if(y>maxY)		y = maxY;


if(xH){	var partX = parseInt((hS-34)*hS / clip[2]);		part = parseInt(hS - partX - 34);
	var k;	if(clip[2]==hS)		k = 1;		else	var k = (clip[2] - hS - x + minX) / (clip[2] - hS);
	var p = parseInt(k*part);				amorQuery(xH.id, 'w,'+partX+',x,'+p, dt);	}

if(xV){	var partX = parseInt((vS-34)*vS / clip[3]);		var part = parseInt(vS - partX- 34);
	var k;	if(clip[3]==vS)		k = 1;		else	k = (clip[3] - vS - y + minY) / (clip[3] - vS);
	var p = parseInt(k*part);

	amorQuery(xV.id, 'h,'+partX+',y,'+p, dt);	}


	var q = 'x,'+ x +',y,'+ y +',c,'+ (xBeacon[1]-y) +','+ (xBeacon[0]+hS-x) +','+ (xBeacon[1]+vS-y) +','+ (xBeacon[0]-x);

	amorQuery(xClip, q, dt);

//	document.title = x+':'+minX+':'+maxX+' '+y+':'+minY+':'+maxY;
//	document.title = (x=minX || x==maxX)+' '+(y=minY || y==maxY);

	if((x==minX || x==maxX) && (y==minY || y==maxY))	return false;		return true;

}



function ScrollHome(name,dt)	{

	var oView = byId(name),		oClip = byId(name+'_clip');

if(oView)	if(oClip)	{
	if((oClip.clientWidth-16)<oView.clientWidth)
		oClip.style.width = (oView.clientWidth-16)+'px';	}

	Scroll(9999,9999, name,dt);	}



function SystemWheel(e)	{	var evt = window.event || e;

	var delta = evt.detail ? evt.detail*(-120) : evt.wheelDelta;

	if(Math.abs(delta)<360)	delta *= 3;

	if(scroll.over)		scroll.over(delta);

else{	if(scroll.name=='')	return true;

	Scroll(0,delta);	}

if(evt.preventDefault)
	evt.preventDefault();	else	return false;	}



function overrideScroll(func)	{			scroll.over = func;	}

function selectScroll(name)	{			scroll.name = name;	Scroll(0,0,name,250);	}

function clearScroll()	{	scroll.name = '';	scroll.over = '';	}





function wrapRoutine(from,to,bits,x)	{	//	if(to=='?')	return;

	if(bits==undefined)				bits = 0;
	var a = document.getElementById(from);		var b = document.getElementById(to);

	if(a==undefined || b==undefined)		return;

if(bits&1)	{

	sa = 'javascript:wrapRequest(\''+ x +'\',\''+ to +'\',\'';	sb = '\',0)';

	b.innerHTML = patchString(a.innerHTML, sa,sb);	}

else	b.innerHTML = a.innerHTML;			KillId(a);	}



function placeRoutine(from,to,bits,x)	{

	setTimeout('wrapRoutine(\''+from+'\',\''+to+'\','+bits+',\''+x+'\')',0);	}



function placeInWin(from,to){	to = winCreate(to);

	var xWin = document.getElementById(to+'_top');
	xWin.style.visibility = 'visible';

	wrapRoutine(from,to);	FixPosition(to);	}




function runAlpha0(id)	{	amorQuery(id,'a,0',500);	}
function runAlpha1(id)	{	amorQuery(id,'a,1',500);	}



function thinGroup(names,prefix)	{		if(prefix==undefined)	prefix = '';

	var xList = explode(',', names);		var c = xList.length;

	for(var i=0; i<c; i++)				amorQuery(prefix+xList[i], 'h,0',500);	}



function thinRoll(o)	{
	var o = byId(o);				amorQuery(o.id, 'h,0', 500);	}


function unRoll(o)	{				var o = byId(o), aXY = elemPos(o), hTo = 0;
	if(aXY[3]!=0)					return;

	o.style.height = '';				hTo = o.clientHeight;
	o.style.height = '0px';				amorQuery(o.id, 'h,'+hTo, 500);

	setTimeout('var o = byId(\''+ o.id +'\'); o.style.height="";', 600);	}


function xRoll(o)	{
	var o = byId(o);				amorQuery(o.id, 'h,0',500);	}



function rollnroll(o)	{				var o = byId(o), aXY = elemPos(o), hTo = 0, hRes = 0;
	o.style.overflow = 'hidden';			if(dTime(o.id)<500)		return 0;

if(aXY[3]==0)	{					o.style.height = '';
	hTo = o.clientHeight;				o.style.height = '0px';
	setTimeout('var o = byId(\''+ o.id +'\'); o.style.height="";', 600);		hRes = 1;

}	else	{

}	amorQuery(o.id, 'h,'+hTo, 500);			return hRes;	}



function CountDown(id,time)	{			var s = 'var x = document.getElementById(\''+ id +'\'); if(x) x.innerHTML = x.innerHTML - 1;';
if(time)	{
	var xKill = setInterval(s,1000);		setTimeout('clearInterval(\''+ xKill +'\')', time*1000+500);	}	}





function xAlert(text,x,y)	{

	if(x==undefined)	x = (app.sw>>1);
	if(y==undefined)	y = (app.sh>>1);

	var xDiv = CreateDiv(x,y,192,32, text);

	xDiv.id = uniqid();
	xDiv.className = "xalert";
	xDiv.style.border = '1px solid #000000';
	xDiv.style.backgroundColor = '#ffffff';
	xDiv.style.padding = '5px';
	xDiv.style.width = '';
	xDiv.style.height = '';
	xDiv.style.whiteSpace = 'nowrap';

	amorQuery(xDiv.id, 'a,0,x,0,y,0', 7500);

	setTimeout('KillId("'+ xDiv.id +'")', 8000);

}




/*
function checkInput(ex,warn)	{	if(warn==undefined)	warn = 0;

	var op = smartExplode(';', ex), hRes = true;

if(op.id!=undefined)	{
	var a = Array();	a[0] = byId(op.id);	}	else
if(op.name!=undefined)
	var a = document.getElementsByName(op.name);

if(a.length==0)	{
	xAlert(desc['noId']);		return false;	}


switch(op.op)	{
case '':									break;


case 'equ':				var o = byName(op.to);
if(o)
	hRes = a[0].value==o[0].value;	else	hRes = false;			break;


case 'email':
	break;

case '#':
	break;
	

case 'checked':			hRes = false;
	for(var i in a)		if(a[i].checked)	hRes = true;		break;

case 'val':
	if(a[0].value=='')	hRes = false;		break;

default:
	xAlert('Unknown op: '+ op.op);			return false;	}


if(warn)	if(!hRes)
	xAlert(op.alert);	return hRes;	}



function checkForm()	{	var a = explode(',', app.form),			c = a.length;

for(var i=0; i<c; i++)	{
if(a[i])
	if(checkInput(a[i], 1)==false)
		return false;	}			return true;	}
*/



function procForm()	{

	var aSelect = fetchNodes('SELECT', app.form);

	var c = aSelect.length;

for(var i=0; i<c; i++)	{

	var iSelect = aSelect[i];

	var to = iSelect.getAttribute('name2');

	var aOption = fetchNodes('OPTION', iSelect);

if(to!=null)	{
	var o = byId(to);
	if(o)	o.value = aOption[iSelect.selectedIndex].innerHTML;	}

}

	return true;

}







function tuner(view,render,type)	{		var x = explode('_', view);

	var query = '?route=route;view_tune;mi;'+view+';item;'+x[1]+';type;'+type;

	winRQ(query);	}





fetchWheel();

if (document.attachEvent)
	document.attachEvent("on"+wheelType, SystemWheel)
if (document.addEventListener)
	document.addEventListener(wheelType, SystemWheel, false);

//	alert(wheelType);


LoadTaskbar();

setTimeout('refreshTaskbar()', 1000);

uScreenWH();

//document.title = getCookie('');

//	alert(FetchNumber());
