var setVoiceArray = [];
var CityData = [];
var button;
var button_text = '';

function psPopImg2(obj){
	var w = window.open(obj.href, "", "resizable=1,HEIGHT=100,WIDTH=100,scrollbar=1");
	with(w.document){
		open();
		var c = [
			'<html><head>',
				'<title>',title,'</title>',
				'<script language="javascript">',
					'function fitPic(){',
						'iWidth = document.body.clientWidth;iHeight = document.body.clientHeight;iWidth = document.images[0].width - iWidth;',
						'iHeight = document.images[0].height - iHeight;window.resizeBy(iWidth, iHeight-1);',
						'var sw=(document.body.clientWidth-iWidth)/2;var sh=(document.body.clientHeight-iHeight)/2;',
						'if (sh<0) sh=0; if (sw<0) sw=0;window.moveTo(sw,sh);self.focus();}',
				'</script></head>',
				'<body onload="fitPic();" style="margin:0;padding:0;">',
					'<img src="',obj.href,'" border="0" alt="',title,'" title="',title,'" />',
				'</body>',
			'</html>'].join('');
		write(c);
		close();
	}
  return false;	
}

function psPrint(obj){
  popupWin = window.open(obj.href, '', 'width=700,height=600,toolbar=no,menubar=yes,location=no,status=yes,resizable=yes,scrollbars=yes,left=50,top=50');
  popupWin.focus();
  return false;	
}

// - Windows --------------------------------------------

var psWindows = {
	current:false,
	bg:false,
	loader:false,
	panel:false,
	image:null,
	
	popImg:function(url){
		this.loadingOn();
		var i = new Image();
		this.image = i;
		i.obj = this;
		i.canceled = false;
		i.onload = function(){
			if (this.canceled) return;
			
			this.obj.current = psCreateDiv('psWindow');
			this.obj.current.appendChild(this);
			this.obj.current.className = 'psWindow';
			this.obj.position();
			this.obj.loadingOff();
			if(i.offsetHeight > this.obj.bg.offsetHeight){
				this.obj.bg.style.height = i.offsetHeight + 100+ 'px';
			}
		}
		i.onclick = function(){
			this.obj.close();		
		}		
		i.style.cursor = 'pointer';
		i.src = url.href;
		return false;		
	},
	
	popImgPreview:function(href, title, reloadPanel){
		this.loadingOn();
		var i = new Image();
		this.image = i;
		i.obj = this;
		if(title)
			i.title = title;
		else
			i.title = href.title;
		i.canceled = false;
		this.oldUrl = href;

		i.onload = function(){
			if (this.canceled) return;
			
			if((this.obj.oldUrl == this.src) && (reloadPanel == null)){
				this.obj.createPanel(this);
				this.obj.p = 1;
			}
			else if(reloadPanel != null)	{
				this.obj.currentImg = this;
				this.obj.p = 1;
			}
			else	{
				this.obj.p = 0;
			}

			this.obj.oldUrl = null;
			this.obj.current = psCreateDiv('psWindow');
			this.obj.current.style.zIndex = 1100;
				
			this.obj.current.appendChild(this.obj.closeButtonCreate());		
			this.obj.current.appendChild(this);
			this.obj.current.className = 'psWindow';

			this.obj.current.appendChild(this.obj.titleImg(this.title));
			
			this.obj.current.style.display = 'none';

			if(this.obj.p == 1)	{
				this.obj.current.p = 1;
			}
			
			this.obj.position();
			this.obj.loadingOff();
			if(i.offsetHeight > this.obj.bg.offsetHeight){
				this.obj.bg.style.height = i.offsetHeight + 100+ 'px';
			}
		}
		i.onclick = function(){
			this.obj.close();		
		}		
		i.style.cursor = 'pointer';
		i.src = href;
		return false;		
	},

	
	popDiv:function(id){
		this.loadingOn();
		objSrc = $(id);
		if (!objSrc) return false;
		this.current = psCreateDiv('psWindow');	
		this.current.className = 'psWindow';
		this.current.innerHTML = objSrc.innerHTML;
		this.current.onclick = stopEvent;
		this.position();
		this.loadingOff();
		return false;
	},
	
	popUrl:function(url){
		if (!url) return false;
		this.loadingOn();

		this.current = psCreateDiv('psWindow');
		this.current.className = 'psWindow';
		obj = this.current;
		objMain = this;
		
		this.request = new Request.JSON({
			url: url,
			onComplete: function(jsonObj) {
				if(this.response.json)	{
					psCommentsEditor.psPrefix = 'blog_';
					obj.innerHTML = this.response.json.js.PageContent;
					obj.onclick = stopEvent;
					objMain.position();
					objMain.loadingOff();
				}
			}
		}).post();
	},

	close:function(){
		if (this.current){
			psDeleteObj(this.current);
			this.current = false;
		}
		if (this.bg){
			psDeleteObj(this.bg);
			this.bg = false;
		}
		if (this.panel){
			psDeleteObj(this.panel);
			this.panel = false;
		}
		if (this.loader){
			psDeleteObj(this.loader);
			this.loader = false;
		}
		psCommentsEditor.psPrefix = 'forum_cat_';
	},

	position:function(obj){
		var t, l;
		obj = (obj)?obj:this.current;
		obj.style.display = 'block';
		psPage.getSize();

		t = (psPage.windowHeight - obj.offsetHeight)/2 + psGetPageScroll();
		
		if(obj.p == 1)	{
			l = ((psPage.windowWidth - 140 - obj.offsetWidth)/2);
		}
		else	{
			l = ((psPage.windowWidth - obj.offsetWidth)/2);
		}
		obj.style.top = (t <= 0) ? '0px' : t + 'px';
		obj.style.left = (l <= 0) ? '0px' : l + 'px';

		/*
		if(t < psGetPageScroll())	{
			window.scrollTo(0, t);
		}
		else	{
			window.scrollTo(0, psGetPageScroll());
		}
		*/
	},

	loadingOn:function(){
		this.closeBackGround();
		this.loader = psCreateDiv('psLoader');
		this.loader.className = 'psLoader';
		this.loader.innerHTML = 'Загрузка';
		this.position(this.loader);
	},
	
	loadingOff:function(){
		if (this.loader){
			psDeleteObj(this.loader);
			this.loader = false;
		}		
	},
	
	closeBackGround:function(){
		if (this.bg){
			return false;
		}
		psPage.getSize();
		
		this.bg = psCreateDiv('closeFonId');
		this.bg.obj = this;
		this.bg.className='psCloseBackGround';
		this.bg.style.height=psPage.pageHeight+100+'px';
		this.bg.style.width=document.body.scrollWidth+'px';
		this.bg.onclick = function(){
			this.obj.close();		
		}
	},
	createPanel:function(img){
		this.currentImg = img;
		this.panel = psCreateDiv('psPanel');
		this.panel.style.height = parseInt(this.bg.style.height) - 40 +'px';
		this.wrapper = psCreateDiv('psIcoWrapper');
		
		/* таблица с иконками */
		this.divCenter = psCreateDiv('psCenter');			
		this.table = document.createElement('table');
		this.table.id = 'icoTable';
		this.tbody = document.createElement('tbody');
		this.table.appendChild(this.tbody);
		this.divCenter.appendChild(this.table);

		this.wrapper.appendChild(this.divCenter);
		this.panel.appendChild(this.wrapper);
				
		this.list = listImg;
		for(var i=0;i<this.list.length;i++){
			this.tr = document.createElement('tr');
			this.td = document.createElement('td');
			this.td.id = 'ImgShow'+i;
			this.td.onmouseover = function(){
				this.className = (this.className == 'icoTdActive') ? this.className : 'icoTdhover';
			}
			this.td.onmouseout = function(){
				this.className = (this.className == 'icoTdActive') ? this.className : 'icoTd';
			}
			this.td.className = 'icoTd';
			this.div = psCreateDiv('DivImgShow'+i);
			this.div.className = 'psIco';
			this.div.listImg = this.list[i];
			this.div.style.background = 'url('+this.div.listImg.ico + this.div.listImg.file+') no-repeat center center';

			if((this.div.listImg.img + this.div.listImg.file) == img.src)	{
				this.td.className = 'icoTdActive';
			}

			this.div.obj = this;
			this.div.td = this.td;
			this.div.onclick = function(){
				this.obj.td = this.td;
				this.obj.div = this;
				this.obj.reloadImg();
			}
			this.td.appendChild(this.div);
			this.tr.appendChild(this.td);
			this.tbody.appendChild(this.tr);
			this.div = null;
			this.td = null;
			this.tr = null;
		}
		
		psPage.getSize();
		this.wrapper.style.height = psPage.windowHeight + 'px';
		this.divCenter.style.margin = (this.wrapper.offsetHeight - this.divCenter.offsetHeight)/2 + 'px 0px 0px 0px';		
		
		if(LibBWCheck().ie6)	{
			this.wrapper.style.top = document.documentElement.scrollTop + (psPage.windowHeight - this.wrapper.offsetHeight)/2 + 'px';
			this.panel.style.position = 'absolute';
			this.panel.style.zIndex = 2000;
			this.panel.style.top = 0;
			this.panel.style.width = '140px';
			this.panel.style.padding = '0px 5px 0px 5px';
			this.panel.style.height = this.bg.style.height;
		}
	},
	closeButtonCreate:function(){
		this.title = '<img src="'+psIMG+'0.gif" width="15" height="15" alt="Закрыть" />';
		this.button = psCreateDiv('psClose');	
		this.button.className = 'psClose';
		this.button.obj = this;
		this.button.onclick = function(){
			this.obj.close();
		}
		this.button.innerHTML = this.title;
		return this.button;
	},
	titleImg:function(title){
		this.title = title;
		this.text = psCreateDiv('psTitle');	
		this.text.className = 'psTitle';
		this.text.obj = this;
		this.text.innerHTML = this.title;
		return this.text;
	},
	reloadImg:function(){
		for(var i=1;i<this.list.length;i++){
			if(this.currentImg.src == (this.list[i].img + this.list[i].file)){
				this.num = i;
				break;
			}
		}
		
		if(this.div)	{
			if(this.currentImg.src != (this.div.listImg.img + this.div.listImg.file))	{
				$('ImgShow'+this.num).className = 'icoTd';
				
				var tUrl = {};
				tUrl.href = this.div.listImg.img + this.div.listImg.file;
				tUrl.title = this.div.listImg.name;
				this.current.removeChild(this.currentImg);
				psDeleteObj(this.current);
				this.popImgPreview(tUrl.href, tUrl.title, 1);
				
				this.td.className = 'icoTdActive';
				this.div = null;
			}
		}
	}
}


// - Windows --------------------------------------------

function psSendForm(formData,postfix){

	if(formData['send_button']){
		button = formData['send_button'].parentNode;
		button_text = button.innerHTML;
		button.innerHTML = '<span style="line-height: 25px; color: #44A80F; font-weight: bold;">Идет отправка данных...</span>';
	}
	
	postfix = (postfix)?postfix:'';
	currentWindow = formData.action;
	var sdata = {};
	sdata['ajax'] = 1;
	for (var i=0; i<formData.elements.length; i++)	{
		sdata[formData.elements[i].name] = formData.elements[i].value;
	}

	var request = new Request.JSON({
		url: formData.action,
		onComplete: function(jsonObj) {
			if(this.response.json)	{
				if(this.response.json.js._login)	{
					if(this.response.json.js.cmd_errors.length == 0)	{
						document.location.href = psHTTP;
					}
					else	{
						var err = this.response.json.js.cmd_errors;
						var msg  = '';
						for(var i=0; i < err.length; i++){
							msg += err[i] + "!\n";
						}
						alert(msg);
					}
				}
				else	{
					psShowFormResult(this.response.json.js,postfix);
				}
				return false;
			}
		}
	}).post(sdata);
	return false;
}

function psShowFormResult(data,postfix){
	psFormErrorsId = $('psFormErrors'+postfix);
	psFormMessegesId = $('psFormMesseges'+postfix);
	psFormFieldsId = $('psFormFields'+postfix);

	psFormMessegesId.style.display='none';
	psFormErrorsId.style.display='none';
	psFormErrorsId.innerHTML = '';
		
	if (data.Error){
		psFormErrorsId.style.display='';
		psFormErrorsId.innerHTML=data.Error;
		psReloadCaptcha(data,postfix);		

		if(button_text)
			button.innerHTML = button_text;
	}else if (data.Messeges){
		if(data._redirect){
			document.location.href = data._redirect;
		}
		else if(data._closeshow){
			psWindows.close();
			$('post'+data._closeshow).style.display = 'none';
		}
		else	{
			psFormMessegesId.style.display='';
			psFormFieldsId.style.display='none';
			psFormMessegesId.innerHTML=data.Messeges;		
		}
	}else{
		psFormErrorsId.style.display='';
		psFormErrorsId.innerHTML='Ошибка при предаче данных';
	}
}

function psReloadCaptcha(data,postfix){
	psFormCaptchaId = $('psFormCaptcha'+postfix);
	if(psFormCaptchaId)	{

		psFormCaptchaId.src = psHTTP+'?mod=505&cmd=get_captcha&'+Math.round(Math.random()*100000000)+'&'+Math.round(Math.random()*100000000);
	}
}


// - Base Functions --------------------------------------------

function addEvent(el, evname, func) {
	if (el.attachEvent) { // IE
		el.attachEvent("on" + evname, func);
	} else if (el.addEventListener) { // Gecko / W3C
		el.addEventListener(evname, func, true);
	} else {
		el["on" + evname] = func;
	}
};
//--------------------------------------------------------------------------
function removeEvent(el, evname, func) {
	if (el.detachEvent) { // IE
		el.detachEvent("on" + evname, func);
	} else if (el.removeEventListener) { // Gecko / W3C
		el.removeEventListener(evname, func, true);
	} else {
		el["on" + evname] = null;
	}
};

function stopEvent(ev) {
	ev || (ev = window.event);
	if(Calendar.is_ie) {
		ev.cancelBubble = true;
		ev.returnValue = false;
	} else {
		ev.preventDefault();
		ev.stopPropagation();
	}
	return false;
};

function psCreateDiv(idName){
	var obj = document.createElement('div');
	document.getElementsByTagName("body")[0].appendChild(obj);
	obj.id=idName;
	return $(idName);
}

function psDeleteObj(obj){
	if (typeof(obj) == 'string'){
		obj = $(obj);
	}
	if (obj){
		document.body.removeChild(obj);
	}
}

function psPreloadImg(url){
    var image = new Image();
    image.src = url;    
}

var psPage = {
	pageWidth:0,
	pageHeight:0,
	windowWidth:0,
	windowHeight:0,
	
	getSize:function(){
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		if (self.innerHeight) {	// all except Explorer
			this.windowWidth = self.innerWidth;
			this.windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			this.windowWidth = document.documentElement.clientWidth;
			this.windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			this.windowWidth = document.body.clientWidth;
			this.windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < this.windowHeight){
			this.pageHeight = this.windowHeight;
		} else { 
			this.pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < this.windowWidth){	
			this.pageWidth = this.windowWidth;
		} else {
			this.pageWidth = xScroll;
		}
	}
//	
//	return arrayPageSize;
}

// временная функция
function psGetPageSize(){
	return [psPage.pageWidth,psPage.pageHeight,psPage.windowWidth,psPage.windowHeight];
}

function psGetPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}
//--------------------------------------------------------------------------
// Browser Check
//--------------------------------------------------------------------------
function LibBWCheck(){ //Browsercheck (needed)
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.opera5=this.agent.indexOf("Opera 5")>-1
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	this.ieTrueBody = function(){
		return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}
	
	return this
}
//--------------------------------------------------------------------------
// Mouse
//--------------------------------------------------------------------------
function _psMouse(){
	this.move = function(e){
		psMouse.x=(psBW.ns4 || psBW.ns6)?e.pageX:event.clientX + psBW.ieTrueBody().scrollLeft;
		psMouse.y=(psBW.ns4 || psBW.ns6)?e.pageY:event.clientY + psBW.ieTrueBody().scrollTop;
	}
}

//--- Flash --------------------------------------------------
function Flash( ) {

    this.transparent = true;
    this.needFlashVerion = 8;          
    this.flashvars = "xml_source=/ixml/&menuselid=0";
    this.BrowserInfo( );

}


Flash.prototype.BrowserInfo = function( ) { 
 
    var userAgent = navigator.userAgent.toLowerCase( );
       this.browserIE = ( userAgent.indexOf( 'msie' ) != -1 );

}

Flash.prototype.CheckVersionFlash = function( needVersion ) {
 
    if ( navigator.plugins[ 'Shockwave Flash' ] ) {
        matchStr = new RegExp ( '^[A-Za-z ]*(.*) .*$' );
        this.flashVerion = parseInt( navigator.plugins[ 'Shockwave Flash' ].description.replace( matchStr, '$1' ) );
        return ( needVersion <= this.flashVerion );
    }
    else if ( this.browserIE ) {
        for( var i = needVersion; i < needVersion + 10; i++ ) {
            try {
                    flashPlayer = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash.' + i );
                    this.flashVerion = i;
                    return true;
            }
            catch( e ) {
                continue;
            }
        }
        return false;     
    }
    else {
        this.flashVerion = 0;
        return false;
    }
 
}

Flash.prototype.Insert = function( ) {
	if ( this.CheckVersionFlash( this.needFlashVerion ) ) { 
		document.write( this.GenerateHtmlFlash( ) );
	}else{
		document.write( this.GenerateHtmlImage( ) );
	}
}

Flash.prototype.GenerateHtmlFlash = function( ) {
 
    var flashCode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
    flashCode += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version= ' + this.flashVerion + ',0,0,0"' + ' width="' + this.width + '" height="' + this.height + '" align="middle">';
    flashCode += '<param name="allowScriptAccess" value="always"/>';
    flashCode += '<param name="movie" value="' + this.srcFlash + '"/>';
    flashCode += '<param name="quality" value="high"/>';
    if ( this.base ) {
        flashCode += '<param name="base" value="' + this.base + '"/>';
    }
    if ( this.background ) {
        flashCode += '<param name="bgcolor" value="' + this.background + '"/>';
    }
    if ( this.transparent ) {
        flashCode += '<param name="wmode" value="transparent"/>';
    }
    if ( this.flashvars ) {
        flashCode += '<param name="flashvars" value="' + this.flashvars + '"/>';
    }
 
    flashCode += '<embed quality="high" allowScriptAccess="always" type="application/x-shockwave-flash"' + ' pluginspage="http://www.macromedia.com/go/getflashplayer" ';
    flashCode += 'src="' + this.srcFlash+'" ' + '" width="' + this.width + '" height="' + this.height + '" ';
    if ( this.base ){
        flashCode += ' base="' + this.base + '"';
    }
    if ( this.background ){
        flashCode += ' bgcolor="' + this.background + '"';
    }
    if ( this.transparent ){
        flashCode += ' wmode="transparent"'
    }
    if ( this.flashvars ){
        flashCode += ' flashvars="' + this.flashvars + '"';
    }
    flashCode += '></embed>';
 
    flashCode += '</object>';
    return flashCode;
 
}

Flash.prototype.GenerateHtmlImage = function( ) {
 
    var imageCode = '<img src="' + this.srcImage + '"/>';
    return imageCode;
 
}
//--- Flash --------------------------------------------------



//-------------------------------------------------------------------------
//	Результаты голосования
//-------------------------------------------------------------------------
function setVotingResult(div, href, block, form)
{
	var sdata = {};
	vForm = $(form);
	if(!vForm.send_vote.value)	{
		alert('Выберите вариант!');	
		return false;
	}

	sdata['value'] = vForm.send_vote.value;
	sdata['cmd'] = vForm.cmd.value;
	sdata['id'] = vForm.voteid.value;
	sdata['ajax'] = 1;
	
	this.request = new Request.JSON({
		url: href,
		onComplete: function(jsonObj) {
			if(this.response.json)	{				
				if(this.response.json.js.vote == true)
					$('vMsg').className = 'voting-msg';
				else
					$('vMsg').className = 'voting-err';
				$('vMsg').innerHTML = this.response.json.js.msg;
				
				if(this.response.json.js.vote)	{
					href = href + '?cmd=popup&id='+sdata['id'];
					getVotingResult(div, href, block);
				}
			}
		}
	}).get(sdata);
}


function getVotingResult(div, href, block, goBack)
{
	this.request = new Request.JSON({
		url: href,
		onComplete: function(jsonObj) {
			if(this.response.json)	{
				$('vName').innerHTML = 	'<div class="voting-name" style="padding-bottom: 15px; margin-top: -3px;">'+this.response.json.js.vName+'</div>';
//				$('vVotes').innerHTML = 'Всего голосов:&nbsp;' + this.response.json.js.vVotes;
				var msg = '';
				for(i=1;i<this.response.json.js.vItems;i++){
					doc_vote = 0;
					doc_vote_percent = 0;
					msg = msg + '<div class="voting-vote">'+this.response.json.js['value'+i]+'</div><div class="voting-line"><img src="'+psIMG+'0.gif" alt="" title="" width="'+this.response.json.js['width'+i]+'%">&nbsp;'+this.response.json.js['vote'+i]+'/<span>'+this.response.json.js.vVotes+'</span></div>';
				}				
				$('vItems').innerHTML = msg;
				
				$(div).style.display  = "block";//временно
				
				if(block)	{
					$(block).style.display  = "none";//временно
				}
				if(goBack)	{
					$('goBack').style.display  = "block";
				}
			}
		}
	}).get();
}

/* new-edit post */
/*
function validateTags(e){
	var s = form.doc_tags_user.value;
	var list = form.doc_tags_all.value;
	
	key = e.which || e.keyCode;
	s += String.fromCharCode(key);
	
	if(s[s.length-1] != ',') s += ',';
	var curList = s.split(",");
	
	return curList;
}
	
function getTags(){
	
	if(list[list.length-1] != ',') list += ',';
	var allList = list.split(",");
		
	for(var i=0;i<curList.length;i++){
		if(curList[i] != '')	{
			if(array_search(curList[i], allList) == true)	{
				testTag(trim(curList[i]));
			}
		}
	}
}
*/

function addTag(id){
	var s = $('postform').doc_tags_user.value;
	
	if($('tag'+id).className == 'addLink')	{
		s = s.replace($('tag'+id).innerHTML, ''); 
		s = trim(s);
		s = trim(s, ',');
		s = trim(s);
	}
	else	{		
		if(s[s.length-1] != ',' && s.length > 0) s += ',';
		s += $('tag'+id).innerHTML;
	}
	$('postform').doc_tags_user.value = s;

	return false;
}

//-----------------------------------------//
function setComplaint(post, blog)
{
	if(window.confirm('Вы действительно хотите пожаловаться на этот сон?')){
		var myRequest = new Request.JSON({
				url: psHTTP+'?mod=510',
				onSuccess:function(data){
					var buttons = $('post'+post);
					buttons.style.display = 'none';
				}
		}).post({cmd:'add', ajax:1, post:post, blog: blog});
	}
	return false;
}

function setRating(mark, id)
{
	var myRequest = new Request.JSON({
			url: '?mod=400',
			onSuccess:function(data){
				$('psRatingButtons'+id).style.display = 'none';
				$('psRatingResult'+id).style.display = '';
				$('psRatingResult'+id).innerHTML = data.doc_mark;
			}			
	}).post({cmd:'vote',ajax:1, mark:mark, post:id});
	
	return false;
}

function setSortPosts(id, url)
{
	var myRequest = new Request.JSON({
			url: '?mod=511',
			onSuccess:function(data){
				document.location = url;
			}
	}).post({cmd:'sort',ajax:1, sort:id});
	
	return false;
}

function setVoice(form, input, value, button)
{
	if(!setVoiceArray[form]){
	  setVoiceArray[form] = $(form)[input].value;
	}
	
	button = (button) ? button : 'search2';
	  
	$(form)[input].value = value;
	
	$(form+setVoiceArray[form]).src = psIMG + button + '-radio-off.gif';
	setVoiceArray[form] = value;
	$(form+setVoiceArray[form]).src = psIMG + button + '-radio-on.gif';

	return false;
}

function setCheckbox(obj)
{
	var value = $(obj).value;
	var img1 = (value == 0) ? 'on' : 'off';
	var img2 = (value == 0) ? 'off' : 'on';
	$(obj+'_'+img1).style.display = '';
	$(obj+'_'+img2).style.display = 'none';
	$(obj).value = (value == 0) ? 1 : 0;

	return false;
}

function setUserPanel(mod, cmd, new_cmd, user, confirm, pid)	{

	if(confirm == 3){
		var parent = $(cmd+mod+user).parentNode;
		parent.innerHTML = '<img src='+psIMG+'loader_white.gif alt="Отправка данных" />';
	}

	var myRequest = new Request.JSON({
			url: '?mod='+mod,
			onSuccess:function(data){
				
				if(confirm != 3 && !pid){
					$(cmd+mod+user).style.display = 'none';	
				}
					
				if(!confirm && !pid)	{
					$(new_cmd+mod+user).style.display = 'block';
				}
				else if(confirm == 2){
					window.location.href = document.location;
				}
				else if(confirm == 3){
					parent.style.background = 'none';
					parent.innerHTML = 'Действие выполнено успешно';
				}
			}
	}).post({cmd:cmd,ajax:1,user:user, xid:pid});
	
	return false;
}

function addUser()	{

	user_select = $('addfriend').user;
	user = user_select.value;

	var myRequest = new Request.JSON({
			url: '?mod=512',
			onSuccess:function(data){
				for(var i=0; i< user_select.options.length;i++){
					if(user = user_select.options[i].value)	{
						user_select.options[i] = null;
						break;
					}
				}
				if(user_select.options.length == 0)
					$('user_list').style.display = 'none';
					
				alert('Заявка успешно подана!');
			}
	}).post({cmd:'add',ajax:1, user:user});
	
	return false;
}

function checkLogin(form){
	var login = form.doc_login.value;

	if(login)	{
		var myRequest = new Request.JSON({
				url: '/?mod=600',
				onSuccess:function(data){
					$('checklogin').style.display = 'block';
					if(data.js.cmd_errors)
						$('checklogin').style.color = '#FF0000';
					else
						$('checklogin').style.color = '#44A80F';
					$('checklogin').innerHTML = data.js.result;
				}
		}).post({cmd:'check_login',ajax:1, login:login});
	}
	else	{
		alert('Введите логин!');
	}
	
	return false;
}
function loadAvatar(form){
	if(form.doc_img_upload)
		form.tmp_upload.value = form.doc_img_upload.value;
	else
		form.tmp_upload.value = form.doc_file_upload.value;
}
//-------------------------------------------------------------------/
function array_search( needle, haystack, strict ) {
    var strict = !!strict;
    for(var key in haystack){
		if(typeof(haystack[key]) == 'string')	{
			if( (strict && trim(haystack[key]) === trim(needle)) || (!strict && trim(haystack[key]) == trim(needle)) ){
				return key;
			}
		}
    } 
    return false;
}

function trim( str, charlist ) {  
	charlist = !charlist ? ' \s\xA0' : charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '\$1');  
	var re = new RegExp('^[' + charlist + ']+|[' + charlist + ']+$', 'g');  
	return str.replace(re, '');  
} 

function psLoadCountry(obj){
	val = obj.options[obj.selectedIndex].value;
	if (val == 0) return false;
	
	if(CityData[val])
	{
		psSetCity(CityData[val],obj);
		return;
	}
	obj.form.elements['doc_country'].disabled = true;
	obj.form.elements['doc_city'].disabled = true;
	
	var myRequest = new Request.JSON({
			url: '?mod=1000',
			onSuccess:function(data){
				CityData[val] = data.js.list;
				psClearSelect(obj.form.elements['doc_city']);
				psSetCity(CityData[val], obj);
			}
	}).post({cmd:'citylist',ajax:1, id:165, xid:val});
}

function psSetCity(data, obj)
{
	if (data !== null )
	{
		n = 0;
		for (var prop in data){
			obj.form.elements['doc_city'].options[n] = new Option(data[prop], prop);
			n++;
		}
		obj.form.elements['doc_city'].disabled=false;
		obj.form.elements['doc_country'].disabled = false;
		obj.form.elements['doc_city'].style.display = 'block';
	}	
}

function psClearSelect(sel)
{
	while (sel.childNodes.length) {
		if (sel.firstChild.tagName == 'OPTGROUP') {
			while (sel.firstChild.childNodes.length) {
				sel.firstChild.removeChild(sel.firstChild.firstChild);
			}
		}
		sel.removeChild(sel.firstChild);
	}
}

function userExit(){
	var myRequest = new Request.JSON({
			url: '/?cmd=logout',
			onSuccess:function(data){
				document.location.href = psHTTP;
			}
	}).post({ajax:1});
	return false;
}

function explode( delimiter, string ) {    // Split a string by string
    var emptyArray = { 0: '' };
 
    if ( arguments.length != 2
        || typeof arguments[0] == 'undefined'
        || typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === ''
        || delimiter === false
        || delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function'
        || typeof delimiter == 'object'
        || typeof string == 'function'
        || typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
 
    return string.toString().split ( delimiter.toString() );
}

function backToVoting(){
	$('portalVResultIndex').style.display  = "none";
	$('goBack').style.display  = "none";
	$('voteIndex').style.display  = "block";
}

function validateSearch(form){
	if(form.search_text.value.length > 0)
		form.submit();
	return false;
}

// index------------------------------
function tabs(id){
	if(activeTab != id)	{
		$('tab'+activeTab).className = 'moon-border-t';
		$('left'+activeTab).className = 'moon-left-cor';
		$('right'+activeTab).className = 'moon-right-cor';
		$('text'+activeTab).style.display = 'none';
		
		
		$('tab'+id).className = 'act-moon-border-t';
		$('left'+id).className = 'act-moon-left-cor';
		$('right'+id).className = 'act-moon-right-cor';
		$('text'+id).style.display = '';
		activeTab = id;
	}
}

function bookmark(a){
	var b = getBrowserInfo();
	if (b.type == 'IE' && 7 >= b.version && b.version >= 4)
		window.external.AddFavorite(url,title);
	else if (b.type == 'Opera') {
		a.href = url;
		a.rel = "sidebar";
		a.title = url+','+title;
		return true;
	}
	else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
	else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
	return false;
}

function getBrowserInfo() {
	var t,v = undefined;
	if (window.opera) t = 'Opera';
	else if (document.all) {
		t = 'IE';
		var nv = navigator.appVersion;
		var s = nv.indexOf('MSIE')+5;
		v = nv.substring(s,s+1);
	}
	else if (navigator.appName) t = 'Netscape';
	return {type:t,version:v};
}

function showForm(closeForm)	{
	if(closeForm)
		$('formAuth').style.display = 'none';
	else
		$('formAuth').style.display = 'block';
	return false;
}

function deleteMail(obj, id, type)	{
	var html = obj.parentNode.innerHTML;
	obj.parentNode.innerHTML = 'Отправка данных';
	var myRequest = new Request.JSON({
			url: '?mod=516',
			onSuccess:function(data){
				if(data.js.cmd_messages)
					document.location.href = data.js.new_url + '?type=' + data.js.type;
				else
					obj.parentNode.innerHTML = html;
					
			}
	}).post({cmd:'delete',ajax:1, id:id, type:type});	
	return false;
}
function selectAction(obj){
	var select_folder = $('select_folder');
	if(obj.value == 'move'){
		select_folder.style.display = '';
	}
	else{
		select_folder.style.display = 'none';
	}
}
function goAction(form){
	var select_action = $('select_action');
	var select_folder = $('select_folder');
	
	var sdata = {};
	for(var i=0; i<form.elements.length; i++){
		if(form.elements[i].type == 'checkbox' && form.elements[i].checked){
			sdata[form.elements[i].name] = 1;
		}
	}
	alert(sdata);
	
	if((select_action.value == 'move' && select_folder.value.length > 1) || (select_action.length > 1 && select_action.value != 'move')){
		
		/*
		var myRequest = new Request.JSON({
				url: '?mod=516',
				onSuccess:function(data){
					if(data.js.cmd_messages)
						document.location.href = data.js.new_url + '?type=' + data.js.type;
					else
						obj.parentNode.innerHTML = html;
						
				}
		}).post({cmd:'delete',ajax:1, id:id, type:type});	
		*/
	}
	else	{
		if(select_action.value == 0)
			alert('Выберите действие!');
		else
			alert('Выберите папку!');
	}
	return false;
}