/*
	JS Extending Library
	Must be loaded before any other JS script
	v 1.5.2
*/

function addOption(oList, text, value, isDfltSel, isSel) {
//	Replacement for BOM add option with DOM
	var oOpt = document.createElement("option");
	oOpt.appendChild(document.createTextNode(text));
	oOpt.setAttribute("value", value);

	if (isDfltSel) oOpt.defaultSelected = true;
	else if (isSel) oOpt.selected = true;

	oList.appendChild(oOpt);
}

function getQuery(URL) {
	var q = {}, qy;
	if (URL.indexOf('?') == -1) return false;
	
	var RE = /(\?|\&)([^\=]+)\=([^&]*)/ig;
	while (qy = RE.exec(URL)) q[qy[2]] = qy[3];
	
	return q;
}

function buildQuery(arr, escape) {
	if (! isset(escape)) var escape = false;
	var el, res = [];
	if (escape) {
		for (el in arr) res[res.length] = encodeURIComponent(el) +'='+ encodeURIComponent(arr[el]);
	} else {
		for (el in arr) res[res.length] = el +'='+ arr[el];
	}
	return res.join('&');
}

function getPath(URL) {
	var p = {};
	if (URL.indexOf('?') != -1) URL = URL.substr(0, URL.indexOf('?'));
	URL = URL.replace('\\', '/');
	if (URL.search(/^(http|ftp|https):\/\//i) != -1) URL = URL.replace(/^(http|ftp|https):\/\/[^\/]+\//i, '');
	if (URL[URL.length - 1] == '/') URL = URL.substr(0, URL.length - 1);
	return URL.split('/');
}

function getElementsByClass(searchClass, node, tag) {
	var classEl = [];
	if (! isset(node)) node = document;
	if (! isset(tag)) tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	
	for (var i = 0; i < elsLen; i++) {
		if (els[i].className == searchClass) classEl.push(els[i]);
	}

	return classEl;
}

function base_convert(n, to, inUpperCase, zeroes) {
	if (! isset(n)) return false;
	else n = parseInt(n);
	if (! isset(to)) to = 16;
	else to = parseInt(to);
	if (! isset(inUpperCase)) inUpperCase = true;
	if (! isset(zeroes)) zeroes = 0;
	else zeroes = parseInt(zeroes);

	var rel, res = '';
	var let4dig = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];

	while (n > to) {
		rel = n % to;
		n = parseInt(n / to);
		if (rel > 9) rel = let4dig[rel - 10]
		res = rel.toString() + res;
	}
	res = (n > 9 ? let4dig[n - 10] : n) + res;
	if (inUpperCase) res = res.toUpperCase();
	if (zeroes > 0) res = leadingZeroes(res, zeroes);

	return res;
}

function current(arr) {
	var el;
	for (el in arr) return arr[el];
}

function key(arr) {
	var el;
	for (el in arr) return el;
}

function checkPassStrength(password) {
	var hasDigits = false;
	var hasLowerLetters = false;
	var hasUpperLetters = false;
	var hasOtherSigns = false;

	var digits = "01234567";
	var lowerLetters = "abcdefghijklmopqrstuvwxyz";
	var upperLetters = "ABCDEFGHIJKLMOPQRSTUVWXYZ";
	var otherSigns = "~`!@#$%^&*+-=_|\\/()[]{}<>,.;:?\"\'";

	var SO = password.length;
	for (var i = 0; i < SO; i++) {
		hasDigits |= digits.indexOf(password.charAt(i)) >= 0;
		hasLowerLetters |= lowerLetters.indexOf(password.charAt(i)) >= 0;
		hasUpperLetters |= upperLetters.indexOf(password.charAt(i)) >= 0;
		hasOtherSigns |= otherSigns.indexOf(password.charAt(i)) >= 0;
	}
	
	return Math.round(Math.log(Math.pow((hasDigits? 10: 0) + (hasLowerLetters? 26: 0) + (hasUpperLetters? 26: 0) + (hasOtherSigns? 32: 0), SO)));
}

function genID() {
	return 'id'+ parseInt(time() / 1000) + rand(10000, 99999);
}

function leadingZeroes(n, zeroes) {
	if (! isset(n)) return false;
	n = n.toString();
	if (! isset(zeroes)) zeroes = n.length;
	
	var res = '';
	for (var i = n.length; i < zeroes; i++) res += '0';
	res += n;
	
	return res;
}

function rand(min, max) {
	return Math.floor(Math.random() * ((max + 1) - min)) + min;
}

function time() {
	return new Date().getTime();
}

function IDgen() {
	return time().toString() + rand(10000, 99999).toString();
}

function isset(v) {
	return (typeof(v) == 'undefined' ? false : true);
}

function empty(v) {
	return (isset(v) ? (v == '0'   ||   v == 0   ||   v == null   ||   v == '' ? true : false) : true);
	//return (isset(v) ? (in_array(v, ['0', 0, null, '']) ? true : false) : true);
}

function $(id) {
	if (document.getElementById) return document.getElementById(id);
	else if (document.all) return document.all[id];
	else if (document.layers) return document.layers[id];
	else return false;
}

function trim(s) {
	return s.replace('/ /g', '');
}

function array_sum(arr) {
	var k, res = 0;
	for (k in arr) res += parseInt(arr[k]);
	return res;
}

function key_in_array(key, arr) {
	var k;
	for (k in arr) {
		if (k == key) return true;
	}
	return false;
}

function implode(glue, arr) {
	var el, res = [];
	for (el in arr) res[res.length] = arr[el];
	return res.join(glue);
}

function build_query(arr) {
	var el, res = [];
	for (el in arr) res[res.length] = el +'='+ arr[el];
	return res.join('&');
}

function in_array(value, arr) {
	var k;
	for (k in arr) {
		if (arr[k] == value) return true;
	}
	return false;
}

function array_kick(array, key) {
	delete array[key];
	
	return array; // Return required only for compability with older versions.
}

function array_kick_by_value(array, value) {
	var el, res = [];
	
	for (el in array) {
		if (value != array[el]) res.push(array[el]);
	}

	return res;
}

function array_search(v, array) {
	var el;
	for (el in array) {
		if (array[el] == v) return el;
	}
	return false;
}

function count(array) {
	var el, i = 0;
	for (el in array) i++;
	return i;
}

function addEvent(ev, o, func, useCapture) {
	// useCapture and this code required only for compability with older versions.
	if (typeof(ev) == 'object'   &&   typeof(o) != 'string') {
		var tmp = ev;
		var ev = o;
		var o = tmp;
	}
	// ---
	
	if (isIE()) o.attachEvent("on"+ ev, function(){eval(func)});
	else o.addEventListener(ev, function(){eval(func)}, false);
}

function removeEvent(ev, o, func) {
	if (! isIE()) o.removeEventListener(ev, function(){}, false);
	else o.detachEvent("on" + ev, function(){});
}

function isIE() {
	return (window.navigator.appName == 'Microsoft Internet Explorer');
}

function isSAFARI() {
	return (navigator.platform == 'MacPPC'   &&   window.navigator.appName == 'Netscape');
}

function isIE7() {
	return (window.navigator.userAgent.indexOf('MSIE 7') != -1 ? true : false);
}

function isFF() {
	return (/Firefox/i.test(navigator.userAgent));
}

function addslashes(s) {
	return s.split('\\').join('\\\\').split('"').join('\\"');
}

function dump(data) {
	if (! isset(data)) {
		alert(data);
		return;
	}
	var cont = [];

	var k, v;
	for (k in data) {
		if (cont.length) cont[cont.length - 1] += ",";
		v = data[k];
		var vs = '';
		if (v.constructor == String) vs = '"'+ addslashes(v) +'"';
		else vs = v.toString();
		if (v.constructor == Array) cont[cont.length]
		else cont[cont.length] = k +": "+ vs;
	}
	cont = "  "+ cont.join("\n").split("\n").join("\n  ");
	var s = cont;
	if (data.constructor == Object) s = "{\n"+ cont +"\n}";
	else if (data.constructor == Array) s = "[\n"+ cont +"\n]";
	alert(s);
}

function makeObjDump(obj) {
	var el;
	for (el in v) {
		if (typeof(v[el]) == 'object')
		res += el +' => '+ v[el] +'\n';
	}
}

function popup(url, name, width, height, x, y, attr, content, insertHTML) {
	/*
		Usage
		All of the paramaters are not obligatory. It means that you can pass none of them and the popup is going to open anyway.
		
		@url [STRING] - URI of the document to open.
		@name [STRING] - Name of the new window, which can be used in target for A and FORM tags.
		@width [STRING] - Width of the window.
		@height [STRING] - Height of the window.
		@x [STRING] - Location of the window for x axis.
		@y [STRING] - Location of the window for y axis.
		@attr [STRING] - attributes of the window:
			copyhistory   Копировать историю просмотра текущего окна.
			dependent     Создать окно, зависимое от родительского окна. Зависимые окна закрываются при закрытии родительского окна и не показываются в панели задач Windows.
			directories   Показывать панель каталогов обозревателя.
			height        Высота окна в пикселях.
			location      Показывать адресную строку обозревателя.
			menubar       Показывать меню обозревателя.
			resizable     Пользователь может изменять размеры окна.
			screenX       Расстояние в пикселях от левого края экрана по горизонтали.
			screenY       Расстояние в пикселях от верхнего края экрана по вертикали.
			left          Расстояние в пикселях от левого края экрана по горизонтали.
			top           Расстояние в пикселях от верхнего края экрана по вертикали.
			scrollbars    Показывать полосы прокрутки окна.
			status        Показывать строку состояния обозревателя.
			toolbar       Показывать панель кнопок обозревателя.
			width         Ширина окна в пикселях.
		@content [STRING] - Some HTML content that will be written to the window. Pass some HTML or an empty string or "auto" for auto filling with HTML. Additionaly view @insertHTML
		@insertHTML [STRING] - if you pass auto for @content, than this will be placed between BODY tags.
	*/
	

	if (empty(url)) var url = '';
	
	if (! isset(name)) var name = '';

	if (empty(width)) var width = '100';
	else {
		if (width == 'fullscreen') var width = screen.availWidth;
		else {
			width = width.toString();
			if (width.indexOf('%') != -1) var width = (Math.round(parseInt(width) * screen.availWidth / 100)).toString();
		}
	}
	
	if (empty(height)) var height = '100';
	else {
		if (height == 'fullscreen') var height = screen.availHeight;
		else {
			height = height.toString();
			if (height.indexOf('%') != -1) var height = (Math.round(parseInt(height) * screen.availHeight / 100)).toString();
		}
	}

	if (empty(x)   &&   width != 'fullscreen') var x = (Math.round(screen.availWidth / 2 - parseInt(width) / 2)).toString();
	else if (width == 'fullscreen') var x = '0';
	
	if (empty(y)   &&   height != 'fullscreen') var y = (Math.round(screen.availHeight / 2 - parseInt(height) / 2)).toString();
	else if (height == 'fullscreen') var y = '0';
	
	if (! isset(insertHTML)) var insertHTML = '';
	
	if (empty(attr)) {
		var attr = 'dependent=1,width='+ width +',height='+ height;
		if (x != '') attr += ',screenX='+ x +',left='+ x;
		if (y != '') attr += ',screenY='+ y +',top='+ y;
	} else {
		if (! isset(attr)) var attr = '';
		if (x != ''   &&   attr.indexOf('left=') == -1) attr += (attr != '' ? ',' : '') +'left='+ x;
		if (x != ''   &&   attr.indexOf('screenX=') == -1) attr += (attr != '' ? ',' : '') +'screenX='+ x;
		if (y != ''   &&   attr.indexOf('top=') == -1) attr += (attr != '' ? ',' : '') +'top='+ y;
		if (y != ''   &&   attr.indexOf('screenY=') == -1) attr += (attr != '' ? ',' : '') +'screenY='+ y;
		if (attr.indexOf('width=') == -1) attr += (attr != '' ? ',' : '') +'width='+ width;
		if (attr.indexOf('height=') == -1) attr += (attr != '' ? ',' : '') +'height='+ height;
	}

	if (empty(content)) var content = '';
	else {
		if (content == 'auto') var content = '<html><head><style>BODY{overflow:hidden;padding:0;margin:0;}</style><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="imagetoolbar" content="no" /></head><body onLoad="window.moveTo('+ x +', '+ y +');self.focus()" bgcolor="#000000">%content%</body></html>';
	}

	var win = window.open(url, name, attr);
	if (content != '') {
		if (! isIE()) win.document.open();
		win.document.write(content.replace('%content%', insertHTML));
		win.document.close();
	}
	return win;
}

function dynPopup(id, width, height, x, y, content, attr, onResizePos, closeWithClick) {
	/*
		Description: Opens DHTML popup in DIV tag.
		Usage: All of the paramaters are not obligatory. It means that you can pass none of them and the popup is going to open anyway.
		
		@id [STRING] - ID of the DIV.
		@width [STRING] - Width of the window.
		@height [STRING] - Height of the window.
		@x [STRING] - Location of the window for x axis. Leave blank for auto.
		@y [STRING] - Location of the window for y axis. Leave blank for auto.
		@content [STRING] - Some HTML content that will be written to the window. Pass some HTML.
		@attr [OBJECT] - Object which contains configuration for the window. Example:
			{
				'borderWidth' : '3px',
				'borderColor' : '#f00',
				'closeImg' : '/img/...gif',
				'closePos' : 'top-right'
			}
		@onResizePos [BOOLEAN] - Should the window be repositioned on main window resize.
		@closeWithClick [BOOLEAN] - Should the window be closabled by click at any place over it or not.
	*/
	
	if (empty(id)) var id = 'dWin'+ IDgen();
	if (empty(width)) var width = 10;
	if (empty(height)) var height = 10;
	if ($(id)) return false;
	if (! document.body) return false;
	
	if (empty(x)) var x = (Math.round((isIE() ? document.body.clientWidth : innerWidth) / 2 - parseInt(width) / 2) + parseInt(document.body.scrollLeft)).toString();
	if (empty(y)) var y = (Math.round((isIE() ? document.body.clientHeight : innerHeight) / 2 - parseInt(height) / 2) + parseInt(document.body.scrollTop)).toString();
	
	if (! isset(attr)) var attr = {};
	if (isset(onResizePos)) {
		if (onResizePos) {
			addEvent('resize', window, 'setTimeout("dynPopupMove(\''+ id +'\')", 50)');
			addEvent('scroll', window, 'setTimeout("dynPopupMove(\''+ id +'\')", 50)');
		}
	}
	
	var o = document.createElement("DIV");
	o.setAttribute('id', id);
	o = document.body.appendChild(o);
	o.style.display = 'none';
	o.style.position = 'absolute';
	o.style.backgroundColor = '#000';
	o.style.zIndex = 9999;
	o.style.left = x;
	o.style.top = y;
	o.style.width = width +'px';
	o.style.height = height +'px';
	
	if (isset(closeWithClick)) {
		if (closeWithClick) {
			addEvent('click', o, 'setTimeout("dynPopupClose(\''+ id +'\')", 50)');
			o.style.cursor = 'pointer';
		}
	}
	
	if (isset(attr['borderWidth'])   &&   isset(attr['borderColor'])) {
		o.style.borderWidth = attr['borderWidth'];
		o.style.borderColor = attr['borderColor'];
		o.style.borderStyle = 'solid';
	}
	
	if (! empty(content)) {
		var content = '<div style="position:relative;width:100%;height:100%;">'+ content;
		if (isset(attr['closeImg'])) {
			if (! isset(attr['closePos'])) attr['closePos'] = 'top-right';
			content += '<div style="position: absolute; ';
			switch (attr['closePos']) {
				default:
					content += 'top: 0; right: 0;';
				break;
				case 'top-left':
					content += 'top: 0; left: 0;';
				break;
				case 'bottom-left':
					content += 'bottom: 0; left: 0;';
				break;
				case 'bottom-right':
					content += 'bottom: 0; right: 0;';
				break;
			}
			content += '"><img src="'+ attr['closeImg'] +'" alt="Close" style="cursor:pointer" onClick="dynPopupClose(\''+ id +'\')" /></div>';
		}
		o.innerHTML = content +'</div>';
	}
	
	dynPopupMove(id);
	o.style.display = 'block';
	
	return o;
}

function dynPopupClose(id) {
	if ($(id)) document.body.removeChild($(id));
}

function dynPopupMove(id) {
	var o = $(id);
	if (o) {
		o.style.left = (Math.round((isIE() ? document.body.clientWidth : innerWidth) / 2 - parseInt(o.style.width) / 2) + parseInt(document.body.scrollLeft)).toString() +'px';
		o.style.top = (Math.round((isIE() ? document.body.clientHeight : innerHeight) / 2 - parseInt(o.style.height) / 2) + parseInt(document.body.scrollTop)).toString() +'px';
	}
}

function moveObj2Event(e, id, offsetX, offsetY) {
	var x, y, o = $(id);
	if (o) {
		if (! e) var e = window.event;
		
		if (! isset(offsetX)) var offsetX = 0;
		if (! isset(offsetY)) var offsetY = 0;
		
		x = parseInt(e.clientX) + parseInt(document.body.scrollLeft) + offsetX;
		y = parseInt(e.clientY) + parseInt(document.body.scrollTop) + offsetY;
		
		if (document.body.clientHeight < o.offsetHeight + y) y = y - o.offsetHeight;
		if (document.body.clientWidth < o.offsetWidth + x) x = x - o.offsetWidth;
		
		o.style.left = x +'px';
		o.style.top = y +'px';
	}
}

function setCookie(name, value, expires, path) {
	if (! empty(name)) {
		var today = new Date();
		today.setTime(today.getTime());
		if (typeof(expires) != 'undefined') {
			if (expires > 0   &&   expires < 1000) expires *= 86400000;
		}
		var expires_date = new Date(today.getTime() + expires);
		document.cookie = name +'='+ escape(value) +';expires='+ expires_date.toGMTString() +';path='+ path;
	}
}

function winStatus(e, text) {
	if (isIE()) {
		var e = window.event;
		if (! isset(text)) var text = '';
		
		if (isset(window.statusbar)) {
			if (! window.statusbar) {
				e.returnValue = false;
				return false;
			}
		}
		
		window.status = (text != '' ? text : e.srcElement['innerText']);
		
		e.returnValue = true;
		return true;
	}
}

function copyright(o, from) {
	var y = new Date();
	y = parseInt(y.getFullYear());
	if (empty(from)) {
		o.innerHTML = y;
		return;
	}
	var from = parseInt(from);
	
	o.innerHTML = (y - from > 0 ? from +'-'+ y : y);
}

function checkData(s, type) {
	// Data validation
	
	switch (type) {
		
		case 'date':
			if (/^(0|1|2|3)?[0-9]{1}\.(0|1|2)?[0-9]{1}\.(1|2)[0-9]{3}$/gmi.test(s)) return true;
		break;
		
		case 'mail':
		case 'email':
			if (/^[a-z0-9_\-\.\^]+@[a-z0-9_\-\.]+\.[a-z]+$/i.test(s)) return true;
		break;
		
		case 'int':
		case 'integer':
		case 'number':
			if (s == parseInt(s)) return true;
		break;
		
		case 'float':
		case 'double':
			if (/^[0-9]+((.|,)[0-9]{0,2})?$/gmi.test(s)) return true;
		break;
		
		case 'httpLink':
			if (/^http(s)?:\/\/[a-z0-9_\.-]+\.[a-z]{2,5}/gmi.test(s)) return true;
		break;
		
		case 'ftpLink':
			if (/^ftp:\/\/[a-z0-9_\.-]+\.[a-z]{2,5}/gmi.test(s)) return true;
		break;
		
		case 'digitsletters':
		case 'digits-letters':
		case 'dl':
		case 'ld':
			if (/^[0-9a-z]+$/gmi.test(s)) return true;
		break;
		
	}
	
	return false;
}

function validateForm(vData, buttonID, debug) {
	// Automatic form validation
	
	var ok, v, id, el, checkSum = 0, realSum = 0, tmp, alerts = [];
	var fEls = eval(vData);
	if (! isset(debug)) debug = false;
	
	/*
		EXAMPLE of vData to pass
		
		var fEls = {
			'login' : {
				'max' : 16,
				'min' : 1,
				'func' : 'checkData("%value%", "dl")',
				'alert' : 'Invalid data in field Login.'
			},
			'pass' : {
				'max' : 50,
				'min' : 6
			},
			'sex' : {
				'min' : 1
			}
		};

	*/
	
	if (debug) {
		var console = $('console');
		console.innerHTML = '<table>';
	}
	
	for (id in fEls) {
		v = trim($(id).value.toLowerCase());
		for (el in fEls[id]) {
			if (el == 'alert') continue;
			checkSum++;
			ok = false;
			switch (el) {
				case 'max':
					if (v.length <= fEls[id][el]) {
						ok = true;
						realSum++;
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : </td><td>MAX</td><td> : </td><td><b>true</b></td></tr>';
					} else {
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : MAX : false<br />';
					}
				break;

				case 'min':
					if (v.length >= fEls[id][el]) {
						ok = true;
						realSum++;
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : </td><td>MIN</td><td> : </td><td><b>true</b></td></tr>';
					} else {
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : </td><td>MIN</td><td> : </td><td>false</td></tr>';
					}
				break;

				case 'func':
					tmp = fEls[id][el].replace(/%value%/gm, v);
					if (eval(tmp)) {
						ok = true;
						realSum++;
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : </td><td>FUNC ('+ tmp +')</td><td> : </td><td><b>true</b></td></tr>';
					} else {
						if (debug) console.innerHTML += '<tr onMouseOver="this.style.backgroundColor=\'#efe\'" onMouseOut="this.style.backgroundColor=\'\'"><td>'+ id +'</td><td> : </td><td>FUNC ('+ tmp +')</td><td> : </td><td>false</td></tr>';
					}
				break;
			}
			if (! ok) {
				if (isset(fEls[id]['alert'])) {
					if (fEls[id]['alert'] != '') alerts.push(fEls[id]['alert']);
				}
			}
			if (alerts.length > 0) alert(alerts.join('\n'));
		}
	}
	
	if (debug) {
		console.innerHTML += '</table>';
		console.innerHTML += realSum +' == '+ checkSum;
	}
	
	if (isset(buttonID)) {
		if (buttonID != '') {
			if (realSum == checkSum) $(buttonID).disabled = false;
			else $(buttonID).disabled = true;
		}
	}
	return (realSum == checkSum ? true : false);
}

function formCounter(id, max, name) {
	var o, c; // Object and Counter
	if (! isset(name)) name = 'counter';
	
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	if (typeof(name) == 'string') var c = $(name);
	else var c = name;
	
	if (o) {
		var allow = max - o.value.length;
		if (allow < 0) {
	       	allow = 0;
			o.value = o.value.substr(0, max);
		}
	   	if (c) c.innerHTML = allow;
	}
}

function overlay(id, content) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) {
		o.innerHTML = content;
		toggleOn(o);
	}
}

function elrkjt(x, y, z) {
	// mailto: protection from bots
	document.write('<'+'a hr'+'ef="mai'+'lto:'+ x +'@'+ y +'.'+ z +'">'+ x +'@'+ y +'.'+ z +'</a>');
}

function imgSwap(id, state1, state2) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) {
		if (o.src.indexOf(state1) > -1) o.src = state2;
		else o.src = state1;
	}
	return true;
}

function classSwap(id, state1, state2) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) {
		if (o.className == state1) o.className = state2;
		else o.className = state1;
	}
	return true;
}

function changeOpacity(id, v) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (isIE()) o.filters.alpha.opacity = (v * 100).toString();
	else o.style.opacity = v;
}

function toggleAll(id_prefix, id_postfix, start_from) {
	if (! isset(id_prefix)) return;
	if (! isset(id_postfix)) var id_postfix = '';
	if (! isset(start_from)) var start_from = 0;
	else start_from = parseInt(start_from);
	
	var o;
	
	for (var i = start_from;true;i++) {
		o = $(id_prefix + i + id_postfix);
		if (o) {
			if (o.style.display == 'none') o.style.display = 'block';
			else o.style.display = 'none';
		} else break;
	}
}

function toggle(id, focus) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) {
		if (o.style.display == 'none') {
			o.style.display = 'block';
			if (isset(focus)) {
				var focusO = $(focus);
				if (focusO) focusO.focus();
			}
		} else o.style.display = 'none';
	}
	return id;
}

function toggleOn(id) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) o.style.display = 'block';
	return id;
}

function toggleOff(id) {
	if (typeof(id) == 'string') var o = $(id);
	else var o = id;
	
	if (o) o.style.display = 'none';
	return id;
}

function checkAll(id, check, i, useList) {
	// Checks all checkboxes: id0, id1, id2,...
	if (isset(useList)) {
		for (var i = 0; i < useList.length; i++) $(useList[i]).checked = check;
		return;
	}
	
	var o;
	if (! isset(i)) var i = 0;
	if (! isset(check)) var check = true;
	while (o = $(id + i.toString())) {
		o.checked = check;
		i++;
	}
}