/*
 * перейти по указанной урле
 */
function urljump(url){
	top.window.location = url;
}

/*
 * вставка текста между тэгами с указанным @id
 */
function setInner(id, txt) {
	document.getElementById(id).innerHTML = txt;
}

function jsconfirm(thetext){
		return confirm(thetext);
}

/*
 * вставка значения в тэг с указанным @tagid
 */
function insertext(str,tagid,display){
	document.getElementById(tagid).value = str;
	if(display){
		document.getElementById(display).style.display='none';
	}
}

function appendtext(str,tagid,display){
	document.getElementById(tagid).value += str;
	document.getElementById(tagid).focus();
	if(display){
		document.getElementById(display).style.display='none';
	}
}

/*
 * открытие нового окна
 */
function open_window(url,wth,hgt) {
	if('full' == wth){
		pwindow = window.open(url);
	} else {
		if (wth) {
			mywidth=wth;
		} else {
			mywidth=600;
		}

		if (hgt) {
			myheight=hgt;
		} else {
			myheight=400;
		}

		pwindow = window.open(url,'Name', 'top=100,left=100,resizable=yes,width='+mywidth+',height='+myheight+',scrollbars=yes,menubar=yes')
	}
	pwindow.focus();
}

var ref=""+escape(top.document.referrer);
var colord = window.screen.colorDepth;
var res = window.screen.width + "x" + window.screen.height;
var eself = document.location;

var clientPC = navigator.userAgent.toLowerCase();
var clientVer = parseInt(navigator.appVersion);
var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1) && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1) && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;
var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
var mod_selectedInputArea;
var mod_selectedRange;
var mod_dupCounter = 1;

/*
 * вывод справки по элементам управления cms - в эдите с индефикатором form_module_cms
 */
function help(help,tagid){
	if(tagid){
		document.getElementById(tagid).value = help;
	}
	else if(document.getElementById('form_module_cms')) {
		document.getElementById('form_module_cms').helpb.value = help;
	}
}

function storeCaret (textAr){
	mod_selectedInputArea = textAr;
	if (textAr.createTextRange){
		mod_selectedRange = document.selection.createRange().duplicate();
	}
}

/*
 * печать соответствующих пользовательских тэгов в мемо
 */
function mozWrap(txtarea, open, close){
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) selEnd = selLength;
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

function addtext(text, emote){
	if (window.mod_selectedInputArea){
		var ta = mod_selectedInputArea;
		if (emote != true){
			val = text.split('][');
			}
		else { val = text; }

		if ((clientVer >= 4) && is_ie && is_win){
			theSelection = document.selection.createRange().text; /* wrap selected text */
			if (theSelection) {
				if (emote != true){
					document.selection.createRange().text = val[0] +']' +  theSelection + '[' + val[1];
				} else {
					document.selection.createRange().text = theSelection + val;
				}
				ta.focus();
				theSelection = '';
				return;
			}

		}else if (ta.selectionEnd && (ta.selectionEnd - ta.selectionStart > 0)){
			if (emote != true){
				mozWrap(ta, val[0] +']', '[' + val[1]); /* wrap selected text */
			} else {
				mozWrap(ta, val, ''); /* wrap selected text */
			}
			return;
		}
		text = ' ' + text + ' ';
		if (ta.createTextRange && mod_selectedRange) {
			var caretPos = mod_selectedRange; /* IE */
			caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		} else if (ta.selectionStart || ta.selectionStart == '0') { /* Moz */
		   	var startPos = ta.selectionStart;
			var endPos = ta.selectionEnd;
			var charb4 = ta.value.charAt(endPos-1);
			ta.value = ta.value.substring(0, endPos)+ text + ta.value.substring(endPos);
		} else {
			ta.value  += text;
		}
		ta.focus();
	}
}


if(document.getElementById&&!document.all){ns6=1;}else{ns6=0;}
var agtbrw=navigator.userAgent.toLowerCase();
var operaaa=(agtbrw.indexOf('opera')!=-1);
var head="display:''";
var folder='';

/*
 * вывод определенных объектов (таблица выбора цвета и др.)
 */
function expandit(curobj, hide) {
	if(document.getElementById(curobj)) {
  		folder=document.getElementById(curobj).style;
	} else {
		if(ns6==1||operaaa==true) {
			folder=curobj.nextSibling.nextSibling.style;
		} else {
			folder=document.all[curobj.sourceIndex+1].style;
		}
   }
	if(folder.display=="none")
	{
		folder.display="";
	} else {
		folder.display="none";
	}
	if(hide) {
		var hide_objects = hide.split(",");	
		for(i=0; i<hide_objects.length; i++) {
			hide_objects[i]=hide_objects[i].replace(/^\s*(.*)/, "$1");
			hide_objects[i]=hide_objects[i].replace(/(.*?)\s*$/, "$1");
			if(document.getElementById(hide_objects[i])) {
				hidden=document.getElementById(hide_objects[i]).style;
				if(hidden.display=="") {
					hidden.display="none";
				}
			}
		}
	}
}



/**
 * Функция установки/снятие цвета на определенный элемент таблицы
 *
 * theRow				строка таблицы
 * theRowNum			количество строк
 * theAction 			действие на строчку (over, out or click)
 * theDefaultColor		цвет строки по умолчанию
 * thePointerColor		цвет при наведении мыши
 * theMarkColor			цвет при клике
 *
 * Функция возвращает логическое значение
 */
var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Вернуть фальш если неправильные настройки
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Определяем ячейки в строке иначе выходим
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Установка цвета
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 Проверка на броузер - Опера
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... другой броузер
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } 

    // 4. Определение новых цветов
    // 4.1 Установка цвета
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Текущий цвет не установлен
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Текущий цвет установлен
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Установить новый цвет
    if (newColor) {
        var c = null;
        // 5.1 ... для Оперы
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... для других броузеров
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
}


