//IE5+, Mozilla 1.0+, Opera 7+
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}


function addUser(href)
{
	openUserWin = window.open(href, "oUW", "scrollbars=yes,width=600,height=550");
	openUserWin.focus();
}

function editUser(href)
{
	openUserEWin = window.open(href, "oUEW", "scrollbars=yes,width=600,height=550");
	openUserEWin.focus();
}

function addFile(href)
{
	openFileWin = window.open(href, "oFW", "scrollbars=yes,width=550,height=440");
	openFileWin.focus();
}

function openWin(href, obj, w, h)
{
	obj = window.open(href, obj+"Up", "scrollbars=yes,width="+w+",height="+h);
	obj.focus();
}

function closeWindow()
{
	opener.location.reload();
	window.close();
	opener.focus();
}

function trLight(idElement)
{	
	trElement = 'tr' + idElement;
	trColor[trElement] = document.getElementById(trElement).style.backgroundColor;		
	document.getElementById(trElement).style.backgroundColor = trOverColor;		
}

function trUnLight(idElement)
{	
	trElement = 'tr' + idElement;
	document.getElementById(trElement).style.backgroundColor = trColor[trElement]; 	
}

function trClick(idElement)
{	
	trElement = 'tr' + idElement;
	boxElement = 'id' + idElement;	
	if (document.getElementById(boxElement).checked == true)
	{
		// Выделяем цветом.
		trColor[trElement] = trSelectColor;		
		document.getElementById(trElement).style.backgroundColor = trColor[trElement];
	}
	else
	{
		// Устанавливаем прежний цвет.
		trColor[trElement] = trDefaultColor[trElement];
		document.getElementById(trElement).style.backgroundColor = trDefaultColor[trElement];
	}	
}

// Перенос выбранных элементов из одного списка в другой.
function addSelectedToList( frmName, srcListName, tgtListName ) 
{	
	var form = eval( 'document.' + frmName );	
	var srcList = eval( 'form.' + srcListName );	
	var tgtList = eval( 'form.' + tgtListName );
	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";
	for (var i=tgtLen-1; i > -1; i--)
    {
		tgt += "," + tgtList.options[i].value + ","	
	}
	for (var i=0; i < srcLen; i++) 
    {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1)
        {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;		
		}
//olll
	}
//44
//44
//44
}

// Удалить выбранные элементы из списка.
function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var srcLen = srcList.length;
	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

// Передвинуть элемент в списке.
function moveInList( frmName, srcListName, index, to) {	
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var total = srcList.options.length-1;
	if (index == -1) {
		return false;	
	}	
	if (to == +1 && index == total) {
		return false;	
	}	
	if (to == -1 && index == 0) {
		return false;
	}
	var items = new Array;
	var values = new Array;
	for (i=total; i >= 0; i--) {
		items[i] = srcList.options[i].text;
		values[i] = srcList.options[i].value;	
	}	
	for (i = total; i >= 0; i--) {
		if (index == i) {
			srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
			srcList.options[i] = new Option(items[i+to], values[i+to]);
			i--;		
		} 
		else {
			srcList.options[i] = new Option(items[i], values[i]);
		}	
	}	
	srcList.focus();
}


// Отправка данных формы - форма категорий.
function formcat(pressbutton) {
	var form = document.adminForm;
	var temp = new Array;
	for (var i=0, n=form.listmod.options.length; i < n; i++) {
		temp[i] = form.listmod.options[i].value;
	}
	form.moderators.value = temp.join( '\n' );
	document.adminForm.submit();			
}

// Объединить дисциплины / направления / авторов для отправки на форме.
function formMaterial() {
	var form = document.adminForm;
	var temp = new Array;
	var temp2 = new Array;
	for (var i=0, n=form.discListAdd.options.length; i < n; i++) {
		temp[i] = form.discListAdd.options[i].value;
	}
	for (var i=0, n=form.authorListAdd.options.length; i < n; i++) {
		temp2[i] = form.authorListAdd.options[i].value;
	}
	form.discs.value = temp.join( '\n' );
	form.authors.value = temp2.join( '\n' );	
	document.adminForm.submit();			
}

function clearImg()
{
	document.adminForm.pathImage.value = '';
}

// Записать параметры.
function listToHide(frmName, srcListName, hideParam)
{
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var hideStr = eval( 'form.' + hideParam );	
	var temp = new Array;
	for (var i=0, n=srcList.options.length; i < n; i++) 
	{
		temp[i] = srcList.options[i].value;
	}	
	hideStr.value = temp.join( '\n' );	
		
}

// Отправить форму.
function sendForm(frmName)
{
	var form = eval( 'document.' + frmName );
	form.submit();
}

// ФУНКЦИИ РЕДАКТОРА ГОСТЕВОЙ.
// Жирный текст.
function textBold(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[b][/b]';
    text.focus();
}

// Курсив.
function textItalic(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[i][/i]';
    text.focus();
}

// Подчеркнутый.
function textUnderline(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[u][/u]';
    text.focus();
}

// Зачеркнутый.
function textS(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[s][/s]';
    text.focus();
}

// Надстрочный.
function textSup(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[sup][/sup]';
    text.focus();
}

// Подстрочный.
function textSub(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[sub][/sub]';
    text.focus();
}

// Горизонтальная линия.
function textHr(frmName, elText)
{
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    text.value = text.value + '[hr]';
    text.focus();
}

// Цитировать.
function addQuote(frmName, elText)
{
    var quote = prompt('Цитата', '');
	var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
	if (quote != null) text.value = text.value + '[quote]' + quote + '[/quote]';
	text.focus();
}

// Добавить ссылку.
function addHref(frmName, elText)
{
    var urlHref = prompt('Введите адрес', 'http://');
	var urlName = prompt('Введите название ссылки', '');
    var form = eval( 'document.' + frmName);
    var text = eval( 'form.' + elText );
    if ((urlHref != null) && (urlName != null)) text.value = text.value + '[url="' + urlHref + '"]' + urlName + '[/url]';
    text.focus();
}

function show(obj) {
    var objImg = 'img' + obj;
    if (document.getElementById(obj).style.display == 'none') {
        document.getElementById(obj).style.display = 'block';
        document.getElementById(objImg).src = imgMinus.src;
    } else {
        document.getElementById(obj).style.display = 'none';  
        document.getElementById(objImg).src = imgPlus.src;        
    }
}
