//if ( location.href.indexOf('http://cataloxy.ru')==-1 && top.location != this.location ) top.location = this.location;

function rand( min, max ) {
    if( max ) return Math.floor(Math.random() * (max - min + 1)) + min;
    return Math.floor(Math.random() * (min + 1));
}


function topMenu( iNumber, bReset, isCurrent ){
	if ( isNaN(parseInt(iNumber)) ) return;
	var current =current_Module;
	if ( parseInt(current) == parseInt(iNumber) && !isCurrent ) return;
	if ( !bReset ){	
		_( 'topMenuI' + iNumber ).className = 'topMenuHover topMenuHover' + iNumber;
		_( 'topMHLine'+ iNumber ).className = 'topMenuHover' + iNumber;;
		if ( !isCurrent && _( 'topMenuI' + current ) ){
			topMenu( current, 1, 1 );
		}
	} else {
		_( 'topMenuI' + iNumber ).className = '';
		_( 'topMHLine'+ iNumber ).className = '';
		if ( !isCurrent && _( 'topMenuI' + current ) ){
			topMenu( current, null, 1 );
		}
		
	}
}

function mailTo( host, zone, name ) {
	var sAddr=name+'@'+host+'.'+zone;
	document.write( '<a href="mailto:'+sAddr+'">'+sAddr+'</a>');
}document.write( '<script src="http://cataloxy.ru/js/label.js"></script>' );

function _( elementID ) {
	return document.getElementById(elementID);
}

/**
* Counter of HTML text field value.
* @author Popko Vitaliy
* @since 11.11.2008
* @cataloxy.ru
*/
function counterText( oTextarea, iMaxLength ) {
	if ( !iMaxLength ) iMaxLength = 2500;
	var aSplit 	= oTextarea.id.split( '_' );
	var sLang	= aSplit[0];
	var iLength = oTextarea.value.length;
	_( sLang + '_counter').value = (iMaxLength-iLength);
	if ( iLength >= iMaxLength ) {
		oTextarea.value = oTextarea.value.substr(0, iMaxLength );
		var val=iMaxLength-iLength;
		_( sLang + '_counter').value = val<0?0:val;
	}	
}


timeoutClose=0;
function openAuth() {	
	if ( navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ) $('.chrome_debug').addClass('true').click(function(){$('.auth .txt[name='+this.className.split(' ')[1]+']').focus();});
	$('.auth .forme').fadeIn('fast');//.mouseleave(closeAuth);
}
function closeAuth() {		
	setTimeout( function(){ $('.auth .forme').fadeOut('fast') ;}, 400 );
}


if ( typeof $ != 'undefined' ) {
	$(
		function() {
			$('.help.above').css('margin-top',function(){return -($(this).height()+45)+'px';});
			$('.listItem,.listwrap td.border').mouseover(function(){$(this).addClass('overed')}).mouseleave(function(){$(this).removeClass('overed')});
			///$('.listItem .to_favorite').css({position:'absolute',marginTop:function(){return ($(this).parent().height()+5)+'px'}});
			$('.to_favorite').click(setFavorite);
		}
	)
}

function setFavorite() {
	if ( !document.cookie ) {
		alert('Для работы с разделом "Избранное" необходимо включить поддержку Cookies в браузере.');
		return;
	}
	var isOnPage = this.className.indexOf('on_page')!=-1;
	var thisName = $(this).attr('name');
	var newItem = thisName.split(':')[1]+';'
	var cookie = getCookie('fav_'+thisName.split(':')[0]);
	if ( !cookie ) cookie = ';';
	if ( this.className.indexOf('exists')!=-1) {
		cookie = cookie.replace(';'+newItem,';');
		$(this).removeClass('exists').html(isOnPage?'В избранное':'в избранное').attr('title','Добавить в избранное');		
	} else {
		cookie += newItem;
		$(this).addClass('exists').html(isOnPage?'Удалить из избранного':'убрать').attr('title','Удалить из избранного');
		var general = $('#header #favorite_btn a');
		if ( general[0].className.indexOf('full')==-1 ) {
			general.addClass('full');
		}
	}
	
	if ( cookie.length > 1 ) {
		if ( typeof IS_FAVORITE_PAGE != 'undefined') $('#'+parseInt(newItem)+'_li_'+thisName.split(':')[0] ).fadeOut();		
		setCookie('fav_'+thisName.split(':')[0],cookie,getTime4C(3600*24*365*10/* :) */),'/');
		//show
	} else {		
		setCookie('fav_'+thisName.split(':')[0],'',0,'/');
		//hide
	}
	this.blur();
}

function initOpenSearch(sUrl, sTitle ) {
	if (window.external && ("AddSearchProvider" in window.external) ) {		
		$('#search_plugin').html('<a href="#" onclick="window.external.AddSearchProvider(\''+sUrl+'\');">Добавьте плагин "<b>'+sTitle+'</b>"</a>');
	}
}
