/* 
remove image flickering in IE
http://www.hedgerwow.com/360/bugs/dom-fix-ie6-background-image-flicker.html
rating img script Copyright (c) Art. Lebedev Studio | http://www.artlebedev.ru/
*/
(function(){
	/*Use Object Detection to detect IE6*/
	var  m = document.uniqueID /*IE*/
	&& document.compatMode  /*>=IE6*/
	&& !window.XMLHttpRequest /*<=IE6*/
	&& document.execCommand ;
	
	try{
		if(!!m){
			m("BackgroundImageCache", false, true) /* = IE6 only */ 
		}
		
	}catch(oh){};
})();

var mk = {};

var sectionURL='';

/**
 * Switches visibility of element (add or remove 'hidden' class)
 * @param {String, Element} elem Target element ID or pointer
 */
/*for event & etc */
function whoisClass( objectNode, whoisNclass ) {
	return ( objectNode && objectNode.className.length && objectNode.className.match( new RegExp('(^|\\s+)(' + whoisNclass + ')($|\\s+)') ) );
}
function deleteClass( objectNode, whoisNclass ) {
	replaceClass( objectNode, '', whoisNclass );
}
function replaceClass( objNode, strNewClass, strCurrClass ) {
	var strOldClass = strNewClass;
	if ( strCurrClass && strCurrClass.length ){
		strCurrClass = strCurrClass.replace( /\s+(\S)/g, '|$1' );
		if ( strOldClass.length ) strOldClass += '|';
		strOldClass += strCurrClass;
	}
	objNode.className = objNode.className.replace( new RegExp('(^|\\s+)(' + strOldClass + ')($|\\s+)', 'g'), '$1' );
	objNode.className += ( (objNode.className.length)? ' ' : '' ) + strNewClass;
}

function newClass( objectNode, newnClass, nowClass ) {
	var oldClass = newnClass;
	if ( nowClass && nowClass.length ){
		nowClass = nowClass.replace( /\s+(\S)/g, '|$1' );
		if ( oldClass.length ) oldClass += '|';
		oldClass += nowClass;
	}
	objectNode.className = objectNode.className.replace( new RegExp('(^|\\s+)(' + oldClass + ')($|\\s+)', 'g'), '$1' );
	objectNode.className += ( (objectNode.className.length)? ' ' : '' ) + newnClass;
}
function setClass( objectNode, newnClass ) {
	newClass( objectNode, newnClass, '' );
}
function checkEvent(oEvt){
	oEvt=(oEvt) ? oEvt : ( (window.event) ? window.event : null );
	if(oEvt && oEvt.srcElement && !window.opera)
		oEvt.target=oEvt.srcElement;
	
	//Handle mouse wheel event
	if(oEvt){
		if(oEvt.wheelDelta){
			oEvt.mouse_wheel_delta=oEvt.wheelDelta/120;
			if(window.opera)
	        	oEvt.mouse_wheel_delta*=-1;
		}
		else if(oEvt.detail){
	    	oEvt.mouse_wheel_delta = -oEvt.detail/3;
		}
	}
	
	return oEvt;
}

function removeEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.removeEventListener) objElement.removeEventListener(strEventType, ptrEventFunc, false);
		else if (objElement.detachEvent) objElement.detachEvent('on' + strEventType, ptrEventFunc);
}
function switchVisibility(elem){
	if(typeof(elem) == 'string')
		elem=document.getElementById(elem);
	if(whoisClass(elem, 'hidden'))
		deleteClass(elem, 'hidden');
	else
		setClass(elem, 'hidden');
	return false;
}

var elemLastRating, idRatingTimeout;

function ratingVote(elem){
	var inp=elem.getElementsByTagName('input')[0];
	var post_id=inp.name.substr(6);
	var r=inp.value;//alert(elem.className);
	setClass(elem, 'disabled');
	SendVote(post_id, r);
	
}
function ratingFindParent(evt){
	var elem=null;
	if((evt=checkEvent(evt))){
		elem=evt.target;
		do{
			if(elem.nodeType == 1 && elem.nodeName == 'SPAN')
				break;
		}while(elem=elem.parentNode);
		if(elem && whoisClass(elem, 'disabled'))
			elem=null;
	}
	return elem;
}

function ratingCalc(evt){
	if((evt=checkEvent(evt))){
		var elemParent=ratingFindParent(evt);
		if(elemParent){
			elem=evt.target;
			var img=elemParent.getElementsByTagName('img');
			var rating=0;
			for(var i=0; i<img.length; i++){
				if(img[i] == elem){
					rating=i+1;
					break;
				}
			}
			return rating;
		}
	}
	return 0;
}

function ratingHover(evt){
	if((evt=checkEvent(evt)) && evt.target.nodeName == 'IMG'){
		var elem=ratingFindParent(evt);
		if(elem){
			ratingSet(elem, ratingCalc(evt));
			clearTimeout(idRatingTimeout);
		}
	}
}

/**
 * Sets article rating
 * @param {Element} parent Rating controls container
 * @param {Number} rating Rating value 
 */
function ratingSet(parent, rating){
	if(parent){
		var img=parent.getElementsByTagName('img');
		for(var i=0; i<img.length; i++) {
			img[i].className = (i < rating) ? 'hover' : '';}
	}
}

function ratingClick(evt){
	if((evt=checkEvent(evt))){
		var elem=ratingFindParent(evt);
		if(elem){
			var inp=elem.getElementsByTagName('input')[0];
			var rating=ratingCalc(evt);
			ratingSet(elem, rating);
			inp.value=rating;
			ratingVote(elem);
		}
	}
}

function ratingOut(evt){
	if((evt=checkEvent(evt))){
		var elem=ratingFindParent(evt);
		if(elem){
			if(elemLastRating && elemLastRating != elem){
				ratingRestore();
				clearTimeout(idRatingTimeout);
			}
			
			elemLastRating=elem;
			idRatingTimeout=setTimeout('ratingRestore()', 100);
		}
	}
}

function ratingRestore(){
	if(elemLastRating){
		var inp=elemLastRating.getElementsByTagName('input')[0];
		ratingSet(elemLastRating, Number(inp.value));
		elemLastRating=null;
	}
}
function addEvent(objElement, strEventType, ptrEventFunc) {
	if (objElement.addEventListener)
		objElement.addEventListener(strEventType, ptrEventFunc, false);
	else if (objElement.attachEvent)
		objElement.attachEvent('on' + strEventType, ptrEventFunc);
}
function ratingAttachEvent(parent){
	var elem=parent||document.getElementById('rate');
	var span=elem.getElementsByTagName('span');
	for(var i=0; i<span.length; i++){
		if(whoisClass(span[i], 'rate_result_1')){
			addEvent(span[i], 'mouseover', ratingHover);
			addEvent(span[i], 'mouseout', ratingOut);
			addEvent(span[i], 'click', ratingClick);
		}
	}
}
function commentAttachEvent(parent){
	var elem=parent||document.getElementById('comments_parent');
	var dv=elem.getElementsByTagName('div');
	for(var i=0; i<dv.length; i++){
		if(whoisClass(dv[i], 'answ')){
			
			addEvent(dv[i].firstChild, 'click', commentClick);
		}
	}
}
function linkAttachEvent(parent){
	var elem=parent||document.getElementById('sort2');
	var dv=elem.getElementsByTagName('div');
	for(var i=0; i<dv.length; i++){
		if(whoisClass(dv[i], 'ln')){
			//alert(dv[i].firstChild.tagName);
			addEvent(dv[i], 'click', DelLink);
		}
	}
}
function commentClick(evt){
	if((evt=checkEvent(evt))){
		var elem=evt.target;
		if(elem){
			var ParentComments=document.getElementById('comments_parent');
			arrDiv=ParentComments.getElementsByTagName('div');
			for(i=0;i<arrDiv.length;i++){
				if(whoisClass(arrDiv[i], 'answ_send')){
					if(arrDiv[i].style.display=='block'){
						arrDiv[i].style.display='none';
					}
					else if(arrDiv[i].parentNode==elem.parentNode){arrDiv[i].style.display='block';}
				}
				if((arrDiv[i] != elem.parentNode.parentNode)&&(arrDiv[i].className.indexOf('comment')!= -1)&& ( document.all && !window.opera )){
					op=elem.parentNode.parentNode;op.style.zIndex="200";arrDiv[i].style.zIndex='-100';
				}
			}
		}
	}
}
function messageAttachEvent(parent){
	var elem=parent||document.getElementById('message_parent');
	var dv=elem.getElementsByTagName('a');
	for(var i=0; i<dv.length; i++){
		if(whoisClass(dv[i], 'answ')){
			addEvent(dv[i], 'click', messageClick);
		}
	}
}
function messageClick(evt){
	if((evt=checkEvent(evt))){
		var elem=evt.target;
		if(elem){ document.getElementById('meta').style.position='relative';
			var ParentComments=document.getElementById('message_parent');
			arrDiv=ParentComments.getElementsByTagName('div');
			for(i=0;i<arrDiv.length;i++){
				if(whoisClass(arrDiv[i], 'hid_mess')){
					if((arrDiv[i].style.display=='block')&&(arrDiv[i].parentNode!=elem.parentNode.parentNode)){
						arrDiv[i].style.display='none';
						Pn=arrDiv[i].parentNode;
						arrLink=Pn.getElementsByTagName('A');
						for(k=0;k<arrLink.length;k++){
							if(whoisClass(arrLink[k], 'answ')){
								arrLink[k].style.cursor="hand";arrLink[k].style.cursor="pointer";
							}
						}
			
					}
					else if(arrDiv[i].parentNode==elem.parentNode.parentNode){
						arrDiv[i].style.display='block';elem.style.cursor="default";
						// added 05.01.08 Andrey (mark msg as read)
						var msgId=elem.parentNode.parentNode.id.toString().substr(7);
						MarkMsgAsRead(msgId);
						elem.style.color="#336699";
						if(whoisClass(elem.parentNode, 'new')){
						//document.getElementById('new_mess_ind').value=new_newMess;
						}	
						
					}
				}
				//if((arrDiv[i] != elem.parentNode.parentNode)&&(arrDiv[i].className.indexOf('comment')!= -1)&& ( document.all && !window.opera )){
				//	op=elem.parentNode.parentNode;op.style.zIndex="200";arrDiv[i].style.zIndex='-100';
				//}
			}
		}
	}return false;
}
function messageOff(Elm){
	if(Elm){
	Elm.style.display='none';	
	Pn=Elm.parentNode;
	arrLink=Pn.getElementsByTagName('A');
	for(k=0;k<arrLink.length;k++){
		if(whoisClass(arrLink[k], 'answ')){
			arrLink[k].style.cursor="hand";arrLink[k].style.cursor="pointer";
		}
	}
	document.getElementById('meta').style.position='absolute';
	arrDiv=Elm.getElementsByTagName('div');
			for(i=0;i<arrDiv.length;i++){
				if(whoisClass(arrDiv[i], 'message_hidden')){
					arrDiv[i].innerHTML='';
					arrDiv[i].style.display='none';
				}
			}
	}
return false;
}
function isNotEmpty(elem){
		var str= elem.value;
		var re = /.{4,}/;  blockHid=document.getElementById("empty");
		if(!str.match(re)){
		if(blockHid){blockHid.style.display="block";blockHid.innerHTML="Слова для поиска не должны быть короче 4 символов.";}
		return false;
		}else{if(blockHid){blockHid.style.display="none";}return true;}
	}
function get_checked_count() { 
    var d = document 
    var f = d.forms['load_article'].elements // form1 - имя формы 
    var chkd = 0 
    var chx 
    for (i = 0; i < f.length; i ++) { 
        chx = f[i] 
        if (chx.type == 'checkbox' && chx.checked == true) { 
            chkd ++ 
        }     
    }     
    return chkd 
} 
function checkThem(from, to) {   var indErr=0;
        Name=document.forms['load_article'].hdrtitle;
	Announce=document.forms['load_article'].hdrtext;
	if(Name){
	        str=Name.value;
                var re = /.{1,}/;  
		if(!str.match(re)){
			document.getElementById('error_nickname').style.visibility='visible';
			document.getElementById('search').scrollIntoView(); 
			document.forms['load_article'].hdrtitle.focus();
			indErr=1;
			//return false;
		}else{document.getElementById('error_nickname').style.visibility='hidden';}

	}
	if(Announce){
	        str=Announce.value;
               dlina=str.length; 
		var re = /^.+\S/;
  		if(dlina > 255 || dlina < 1 || !str.match(re)) 
		{
			document.getElementById('error_announce').style.visibility='visible';
			document.getElementById('search').scrollIntoView(); 
			document.forms['load_article'].hdrtext.focus();
			indErr=1;
			//return false;
		}else{document.getElementById('error_announce').style.visibility='hidden';}

	}
	var num = get_checked_count() 
    if (num > to || num < from) { 
        err=document.getElementById('cat_error');
	if(err) err.style.color='#ff3300';
	document.getElementById('search').scrollIntoView(); 
        indErr=1;
	//return false; 
    } else { 
        err=document.getElementById('cat_error');
	if(err) err.style.color='#666666';
		//var d = document 
        //var f = d.forms['load_article'].submit() 
        //return true; 
    } 
	if(indErr==0){var d = document 
        	var f = d.forms['load_article'].submit() 
        	return true; 
	}
	else{return false;}	
} 
function checkEditUser() { var indErr=0;
        Name=document.forms['load_article'].nickname;
	Announce=document.forms['load_article'].descr;
	Pass=document.forms['load_article'].passwd;
	if(Name){
	        str=Name.value;
                var re = /.{1,}/;  
		if(!str.match(re)){
			document.getElementById('error_nickname').style.visibility='visible';
			document.getElementById('search').scrollIntoView(); 
			document.forms['load_article'].nickname.focus();
			indErr=1;
			//return false;
		}else{document.getElementById('error_nickname').style.visibility='hidden';}

	}
	if(Announce){
	        str=Announce.value;
                var re = /^.?.{0,256}$/;  
		if(!str.match(re)){
			document.getElementById('error_announce').style.visibility='visible';
			document.getElementById('search').scrollIntoView(); 
			document.forms['load_article'].descr.focus();
			indErr=1;
			//return false;
		}else{document.getElementById('error_announce').style.visibility='hidden';}

	}
	if(Pass){
	        str=Pass.value;
                var re = /^[a-zA-Z0-9_]+$/;  
		if(!str.match(re)){
			document.getElementById('error_passwd').style.visibility='visible';
			document.getElementById('search').scrollIntoView(); 
			document.forms['load_article'].passwd.focus();
			indErr=1;
			//return false;
		}else{document.getElementById('error_passwd').style.visibility='hidden';}

	}

	if(indErr==0){var d = document 
        	var f = d.forms['load_article'].submit() 
        	return true; 
	}
	else{return false;}	
} 

function searchLink(strPage){
	if(document.forms[2].page){
		if(strPage) document.forms[2].page.value=strPage;
		else document.forms[2].page.value=0;
			document.forms[2].submit();
	}return false;
}
function getComplaint(){
	blockComplaint=document.getElementById('complaint');
	blockA4complaint=document.getElementById('acompl');
	if(blockComplaint&&blockA4complaint){
		blockComplaint.style.display='block';
		removeEvent(blockA4complaint, 'click', getComplaint);
		addEvent(blockA4complaint, 'click', offComplaint);
	}
	return false;
}
function offComplaint(){
		blockComplaint=document.getElementById('complaint');
		blockA4complaint=document.getElementById('acompl');
		if(blockComplaint&&blockA4complaint){
			blockComplaint.style.display='none';
			removeEvent(blockA4complaint, 'click', offComplaint);
			addEvent(blockA4complaint, 'click', getComplaint);
		}
		return false;
}
function getMailAuthor(){
	blockMail=document.getElementById('mailauthor');
	blockLinkMail=document.getElementById('link4MailAuthor');
	if(blockMail&&blockLinkMail){
		blockMail.style.display='block';
		removeEvent(blockLinkMail, 'click', getMailAuthor);
		addEvent(blockLinkMail, 'click', offMailAuthor);
	}
	return false;
}
function offMailAuthor(){
	blockMail=document.getElementById('mailauthor');
	blockLinkMail=document.getElementById('link4MailAuthor');
	if(blockMail&&blockLinkMail){
		blockMail.style.display='none';
		removeEvent(blockLinkMail, 'click', offMailAuthor);
		addEvent(blockLinkMail, 'click', getMailAuthor);
	}
	return false;
}
function InputPlaceholder (input, value, cssFilled, cssEmpty)
{
	var thisCopy = this
	
	this.Input = input
	this.Value = value
	this.SaveOriginal = (input.value == value)
	this.CssFilled = cssFilled
	this.CssEmpty = cssEmpty

	this.setupEvent (this.Input, 'focus', function() {return thisCopy.onFocus()})
	this.setupEvent (this.Input, 'blur',  function() {return thisCopy.onBlur()})
	this.setupEvent (this.Input, 'keydown', function() {return thisCopy.onKeyDown()})

	if (input.value == '') this.onBlur();

	return this
}

InputPlaceholder.prototype.setupEvent = function (elem, eventType, handler)
{
	if (elem.attachEvent)
	{
		elem.attachEvent ('on' + eventType, handler)
	}

	if (elem.addEventListener)
	{
		elem.addEventListener (eventType, handler, false)
	}
}

InputPlaceholder.prototype.onFocus = function()
{
	if (!this.SaveOriginal &&  this.Input.value == this.Value)
	{
		this.Input.value = ''
	}
	else
	{
			this.Input.className = 'inplogin'
	}
}

InputPlaceholder.prototype.onKeyDown = function()
{
	this.Input.className = ''
	//this.Input.style.color = '#333333';
}

InputPlaceholder.prototype.onBlur = function()
{
	if (this.Input.value == '' || this.Input.value == this.Value)
	{
		this.Input.value = this.Value
		this.Input.className = this.CssEmpty
	}
	else
	{
		this.Input.className = this.CssFilled
	}
}
function recFormAttachEvent(parent){
	var elem=parent;
	if(elem){
		
		
		blockElForm=document.getElementById(elem);
		addEvent(blockElForm, 'click', LoadImg);

	}
}
function recDelAttachEvent(parent){
	var elem=parent;
	if(elem){
		
		
		blockElDelBan=document.getElementById(elem);
		addEvent(blockElDelBan, 'click', DelBan);

	}
}

function vewBan(evt){
	if((evt=checkEvent(evt))){
		var elem=evt.target;
		if(elem){strNew=new String(elem.id);
			numb=strNew.substring(4, strNew.length);
			if(numb==""){numb="0";}
			fName=parseInt(numb); 
			nLink='/banners/'+fName+'/';popupWin = window.open(nLink, 'images', 'location,width=940,height=800,top=0,scrollbars=yes'); popupWin.focus(); return false;
		}
	}
}

function recLinkAttachEvent(parent, fn){
	var elem=parent;
	if(elem){
		
strNew=new String(elem);
	numb=strNew.substring(4, strNew.length);if(numb==""){numb="0";}formName=parseInt(numb);
		
		blockLink=document.getElementById(elem);
		
			addEvent(blockLink, 'click', vewBan);
			if(fn){
			strBd="bandel_"+fn;
			blockLinkDl=document.getElementById(strBd);
			if(blockLinkDl){addEvent(blockLinkDl, 'click', DelBan);}
			}
		
	}

}