/* onload */
/* type browser */
/* ajax */
/* newsreader */
/* form registration */
/* projector */
/* sessions and cookies */
/* show hide comments */
/* report moderator */
/* subscribe new comment */
/* fixpng */
/* new comments */



/* onload */
// Onload functions init in this place
function addLoadEvent(func) { // Functions loader
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		};
	}
}

if (window.selectFirst) {
	addLoadEvent(selectFirst);
}
/* /onload */



/* type browser */
var client = {};

client.whoBrouser = function() {
	var ua = window.navigator.userAgent;
	var msie = ua.indexOf ( "MSIE " );
	var ieVer = parseInt (ua.substring (msie+5, ua.indexOf (".", msie )), 10);
	
	if (document.documentMode) {
		if (document.documentMode == 8) {
			ieVer = 8;
		} else if (document.documentMode == 7) {
			ieVer = 7;
		}
	}
	
	if (document.all && navigator.userAgent.indexOf("Opera")<0 && ieVer != 8) {
		return "ie";
	} else {
		return "normal";
	}
};

client.brouser = client.whoBrouser();
/* /type browser */




/* ajax */
var net = {};

net.Loader = function (url,onload,onerror,method,params,contentType) {
	this.req=null;
	this.onload=(onload)?onload:this.defaultOnload;
	this.onerror=(onerror)?onerror:this.defaultError;
	this.loadXMLDoc(url,method,params,contentType);
};

net.Loader.prototype = {
	loadXMLDoc:function(url,method,params,contentType){
		if (!method) {
			method="GET";
		}
		if (!contentType && method=="POST") {
			contentType='application/x-www-form-urlencoded'; 
		}
		if (window.XMLHttpRequest) {
			this.req=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.req) {
			try {
				var loader=this;
				this.req.onreadystatechange = function() {
					loader.onReadyState.call(loader);
				};
				this.req.open(method,url,true);
				if (contentType) {
					this.req.setRequestHeader("Content-Type", contentType);
					this.req.setRequestHeader("Content-length", params.length);  
					this.req.setRequestHeader("Connection", "close"); 
				}
				this.req.send(params);
			} catch (err) {
				this.onerror.call(this);
			}
		}
	},
	
	onReadyState:function(){
		var req=this.req;
		var ready=req.readyState;
		if (ready==4 && this.onload) {
			var httpStatus=req.status;
			if (httpStatus===200 || httpStatus===0) {
				this.onload.call(this);
			} else {
				this.onerror.call(this);
			}
		}
	},

	defaultOnload:function(){
	},
	
	defaultError:function(){
	}
};
/* /ajax */




/* menu */
jQuery(function(){
	var page_pathname = window.location.pathname;
	var link_pathname = '';
	jQuery('a',jQuery('div > ul.menu')).each(function(){
		if(this.href == '') return;
		link_pathname = this.pathname;
		if(link_pathname[0] !== '/') {link_pathname = '/'+link_pathname}
		if(jQuery(this).attr('href')!=='' && page_pathname === link_pathname){
			jQuery(this).next().css('display','block');
			jQuery(this).parents('ul').not(':last').css('display','block');
			jQuery(this).parents('li').addClass('expanded').addClass('active-trail');
			return;
		}
	});
	
	// for russia_24
	if(jQuery('#page_r24')[0]) {
		jQuery('ul.r24_rubrikator li').removeClass('r24_current_rub');

		var r24_page_pathname = page_pathname;
		var cur_item;
		
		if(r24_page_pathname.substr(r24_page_pathname.length-1) !== '/') {
			r24_page_pathname += '/';
		}

		jQuery('a',jQuery('ul.r24_rubrikator')).each(function(){
			link_pathname = this.pathname;

			if(link_pathname.substr(0, 1) !== '/') {
				link_pathname = '/' + link_pathname;
			}

			if(link_pathname.substr(link_pathname.length-1) !== '/') {
				link_pathname += '/';
			}

			if(r24_page_pathname === link_pathname || r24_page_pathname.indexOf(this.pathname) !== -1){
				cur_item = jQuery(this).parents('li');
			}
		});
		cur_item.addClass('r24_current_rub')
	}
});
/* /menu */




/* newsreader */
function buttonsSwitch(_this,id,tagType){
	var liButtons = document.getElementById(id).getElementsByTagName("li");
	var switchTags = document.getElementById(id).getElementsByTagName(tagType);
	for(var i=0;i<liButtons.length;i++){
		if(liButtons[i] != _this){
			liButtons[i].className = "";
		}
	}
	_this.className = "active-bookmark";
	for(var i=0;i<switchTags.length;i++){
		if(switchTags[i].className != "news-txt"){
			/* Keep the heading table with All stats link always open */
			if(switchTags[i].id != _this.id+"-"+tagType && switchTags[i].id != 'heading-results-table'){
				switchTags[i].style.display = "none";
			}else{
				if(client["brouser"] == "ie" || switchTags[i].tagName == "DIV") switchTags[i].style.display = "block";
				else switchTags[i].style.display = "table";
			}
		}
	}
}
/* /newsreader */



/* form registration */
function registrationeFocus() {
	if (document.getElementById("reg-mail")) {
		document.getElementById("reg-mail").focus();
	}
}

addLoadEvent(registrationeFocus);

function setCookie(name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function sb_c_auth_def_registr_elem(input_name, error_text, type) {
	var input, span_node, text_node, text_error, input_parent;
	
	span_node = document.createElement('SPAN');
	text_node = document.createTextNode(error_text);
	text_error = document.getElementById(input_name + '-error');
	input = document.getElementById(input_name);
	input_parent = input.parentNode;
	
	if(input_parent.nodeName == 'SPAN' && type) {
		input.parentNode.className = 'sb_c_auth_def_error';
	} else if (input_parent.nodeName == 'SPAN') {
		input.parentNode.className = 'sb_c_auth_def_brd';
	}
	
	if (text_error.getElementsByTagName('SPAN')[0] !== undefined) {
		text_error.removeChild(text_error.getElementsByTagName('SPAN')[0]);
	}
	
	span_node.appendChild(text_node);
	text_error.appendChild(span_node);
	
	if (type) {
		text_error.className = 'sb_c_auth_def_error_t';
	} else {
		text_error.className = '';
	}
}

function sb_c_auth_def_registr(form) {
	var submit_type = true;
	var inputs = ['reg-mail', 'reg-password', 'reg-repeat-password', 'reg-nick', 'reg-capcha', 'reg-licence', 'auth-mail', 'auth-password'];
	var error_text = ['', 'Пароль должен быть длиннее 5-и символов', '', 'Псевдоним может состоять только из английских букв, цифр, тире и подчеркивания. Псевдоним не может быть изменен после регистрации.', '', 'При успешной регистрации на Ваш адрес будет прислано письмо со ссылкой на активацию. Это нужно для того, чтобы исключить регистрацию по чужим адресам электронной почты.', '', 'Пароль должен быть длиннее 5-и символов'];
	var input, input2, re;
	
	for (var i=0; i<inputs.length; i++) {
		input = document.getElementById(inputs[i]);
		
		if (input !== null) {
			if (input.type == 'text' || input.type == 'password') {
				if (input.value == '') {
					sb_c_auth_def_registr_elem(inputs[i], 'Не заполнено. ' + error_text[i], true);
					submit_type = false;
				} else {
					if (inputs[i] == 'auth-password') {
						sb_c_auth_def_registr_elem(inputs[i], '', false);
					} else {
						sb_c_auth_def_registr_elem(inputs[i], error_text[i], false);
					}
				}
			} else if (input.type == 'checkbox') {
				if (!input.checked) {
					sb_c_auth_def_registr_elem(inputs[i], 'Ограничение не соблюдено. ' + error_text[i], true);
					submit_type = false;
				} else {
					sb_c_auth_def_registr_elem(inputs[i], error_text[i], false);
				}
			}
		}
	}
	
	
	input = document.getElementById('reg-mail');
	re = /^[\._a-zA-Z0-9-\+]+@[\.a-zA-Z0-9-]+\.[a-z]{2,6}$/;
	
	if (input !== null) {
		if (input.value != '') {
			if (re.exec(input.value) === null) {
				sb_c_auth_def_registr_elem('reg-mail', 'Неправильно заполнено', true);
				submit_type = false;
			}
		}
	}
	
	
	input = document.getElementById('reg-password');
	
	if (input !== null) {
		if (input.value != '') {
			if (input.value.length < 6) {
				sb_c_auth_def_registr_elem('reg-password', error_text[1], true);
				submit_type = false;
			}
		}
	}
	
	
	input = document.getElementById('reg-repeat-password');
	
	if (input !== null) {
		if (input.value != '') {
			if (input.value.length < 6) {
				sb_c_auth_def_registr_elem('reg-repeat-password', error_text[1], true);
				submit_type = false;
			}
		}
	}
	
	
	input = document.getElementById('reg-password');
	input2 = document.getElementById('reg-repeat-password');
	
	if (input !== null && input2 !== null) {
		if (input.value != '' && input2.value != '') {
			if (input.value.length > 5 && input2.value.length > 5) {
				if (input.value != input2.value) {
					sb_c_auth_def_registr_elem('reg-repeat-password', 'Пароли не совпадают', true);
					submit_type = false;
				}
			}
		}
	}
	
	
	input = document.getElementById('reg-nick');
	re = /^[A-Za-z0-9\-_\s]+$/;
	
	if (input !== null) {
		if (input.value != '') {
			if (re.exec(input.value) === null) {
				sb_c_auth_def_registr_elem('reg-nick', 'Неправильно заполнено' + error_text[3], true);
				submit_type = false;
			}
		}
	}
	
	
	input = document.getElementById('auth-mail');
	re = /^[\._a-zA-Z0-9-\+]+@[\.a-zA-Z0-9-]+\.[a-z]{2,6}$/;
	
	if (input !== null) {
		if (input.value != '') {
			if (re.exec(input.value) === null) {
				sb_c_auth_def_registr_elem('auth-mail', 'Неправильно заполнено', true);
				submit_type = false;
			}
		}
	}
	
	
	input = document.getElementById('auth-password');
	
	if (input !== null) {
		if (input.value != '') {
			if (input.value.length < 6) {
				sb_c_auth_def_registr_elem('auth-password', error_text[7], true);
				submit_type = false;
			}
		}
	}
	
	
	return submit_type;
}
/* /form registration */


/* projector */
/*
jQuery(function(){

	if(!window.projector_ready_cookie_name) { return }

	if( readCookie('projector_ready2') ) { return }

	var limit_projector_cookie_time =  (    new Date(  (new Date).getTime()+(1000*86400)  )    ).toGMTString();

	setCookie('projector_ready2', window.projector_ready_cookie_name, limit_projector_cookie_time);

	function set_projector(){
			if(jQuery.browser.msie && jQuery.browser.version < 7) { return }
			
			var body = jQuery('body');
			var offset_left = 115;
			var offset_top  = jQuery(flash_rolik).offset().top  - 50;
			
			var projector = jQuery('<div style="zoom:1;z-index:3000;overflow:hidden;position:absolute;left:0;top:0;width:100%;height:'+ body.height() +'px"><div style="position:absolute;background:url(http://s-ports.ru/i/ads_files/banners/projector.png) no-repeat;width:490px;height:490px;left:50%;top:0;margin-left:'+ offset_left +'px;top:'+ offset_top +'px;">\
										<div style="position:absolute;background:url(http://s-ports.ru/i/ads_files/banners/fill.png);width:2000px;height:10000px;left:-2000px;top:-'+ offset_top +'px"></div>\
										<div style="position:absolute;background:url(http://s-ports.ru/i/ads_files/banners/fill.png);width:2000px;height:2000px;left:0;top:-2000px"></div>\
										<div style="position:absolute;background:url(http://s-ports.ru/i/ads_files/banners/fill.png);width:2000px;height:10000px;right:-2000px;top:0"></div>\
										<div style="position:absolute;background:url(http://s-ports.ru/i/ads_files/banners/fill.png);width:100%;height:10000px;left:0;top:100%"></div>\
									</div></div>');
			
			if(jQuery.browser.msie && jQuery.browser.version > 6) {
				var img_png = jQuery('<img src="http://s-ports.ru/i/ads_files/banners/projector.png" style="width:100%;height:100%; display:block" />');
				jQuery('>div', projector).css('background','none').prepend(img_png);
			}
			
			projector.css({opacity:0}).appendTo(body);
			projector.animate({opacity:1},3000, function(){
				projector.fadeOut(3000, function(){ 	jQuery(this).remove()  });
			});
	}
	
	
	var flash_rolik = jQuery('div.spb_right_column_banner embed')[0] ? jQuery('div.spb_right_column_banner embed')[0] : jQuery('div.spb_right_column_banner object')[0];
	if(!flash_rolik && jQuery('div.spb_right_column_banner iframe')[0]) {
		setTimeout(function(){
			flash_rolik = jQuery('div.spb_right_column_banner iframe')[0];
			set_projector();
		}, 1000)
	}
	else {
		var flash_loaded_interval = setInterval(function(){
			if(flash_rolik.PercentLoaded() == 100) {
				clearInterval(flash_loaded_interval);
				set_projector();
			}
		},10);
	}
		
	
});
*/
/* /projector */


/* sessions and cookies */
function checkCookies() {
	//empty function for IE
	if (this.req.responseText) {
		var data=this.req.responseText.split(';');
		document.getElementById('auth_form').style.display='none';
		document.getElementById('auth_profile').style.display='block';
		document.getElementById('auth_name').innerHTML=data[1];
	}
}

function checkSession() {
	var nl = new net.Loader('/session?ssid='+authCookie+'&random='+Math.random(),checkCookies,null,"get",null,null);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)===' ') {
			c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) === 0) {
			return c.substring(nameEQ.length,c.length);
		}
	}
	return null;
}

function setCookie2(name) {
	var now = new Date();
	var expire = new Date(now.getTime() + 3600000);
	document.cookie = name + '; path=/; domain=.sportbox.ru; expires='+expire.toGMTString();
}
/* /sessions and cookies */



/* show hide comments */
function sp_c_comm_def_show(show_id, comms_id, class_top, class_bottom) {
	var show_obj = document.getElementById(show_id);
	var comms_obj = document.getElementById(comms_id);
	
	if (comms_obj.style.display === 'block' || comms_obj.style.display === '') {
		comms_obj.style.display = 'none';
		show_obj.className = class_bottom;
		setCookie2('sp_c_comm_def_show=0');
	} else {
		comms_obj.style.display = 'block';
		show_obj.className = class_top;
		setCookie2('sp_c_comm_def_show=1');
	}
}
/* /show hide comments */



/* report moderator */
function closeComplainBox() {
	$('#complainBox').remove();
}

function finishComplainBox() {
	$('#complainBox').html("<div style=\"padding: 10px\">"+ window.complainLoader.req.responseText+"</div><div style=\"padding: 10px\">Ваше сообщение отправлено и в ближайшее время будет рассмотрено модератором</div>");
	setTimeout(closeComplainBox, 3000);
}

function sendComplain( topicId, postId ) {
	var text = $('#complainTextBox').val();
	var url = "/ipbmakecomments?do=complain&act=report&send=1&t="+topicId+"&p="+postId+"&text="+text;
	window.complainLoader = new net.Loader(url,finishComplainBox,null,"get",null,null);
}

function showComplainBox( callerObj, topicId, postId ) {
	closeComplainBox();
	
	var bounds = $(callerObj).offset();
	var dom_bdiv = $('<div id="complainBox" class="complain-box"></div>').css({left :  bounds.left +"px" , top: bounds.top + 15 + "px"});
	
	$('<span class="spb_user_iface_pointer-box" style="float: right; cursor: pointer"> x </span>').click(function(){closeComplainBox();}).appendTo(dom_bdiv);
	
	dom_bdiv.append(" Введите причину жалобы: ");
	
	$('<textarea id="complainTextBox" class="complain-box-textarea"></textarea>').appendTo(dom_bdiv);
	$('<input type="button" value="Пожаловаться" />').click(function(){sendComplain(topicId, postId);}).appendTo(dom_bdiv);
	
	$('body').append(dom_bdiv);
	
	$('#complainTextBox').focus();
	
	return false;
}

function commentsQuickReplyClick( text ) {
	var bounds = $('#commenttext_field').val(text).focus().offset();
	window.scrollTo(0,bounds.top);
	return false;
}
/* /report moderator */



/* subscribe new comment */
var commentsSubscribeLinkObj;
var commentsSubscribeSubscribeTxt;
var commentsSubscribeUnSubscribeTxt;

function closeCommentsSubscribeBox() {
	if ( document.getElementById('subscribeBox') ) {
		$('#subscribeBox').remove();
	}
}

function finishCommentsSubscribe() {
	closeCommentsSubscribeBox();
	
	var linkVal = commentsSubscribeLinkObj.innerHTML;
	
	if ( linkVal == commentsSubscribeSubscribeTxt ) {
		commentsSubscribeLinkObj.innerHTML = commentsSubscribeUnSubscribeTxt;
	} else if ( linkVal == commentsSubscribeUnSubscribeTxt ) {
		commentsSubscribeLinkObj.innerHTML = commentsSubscribeSubscribeTxt;
	}
	
	
	var bounds = $(commentsSubscribeLinkObj).offset();
	
	$('<div id="subscribeBox" class="complain-box"></div>')
		.css({left: bounds.left + "px", top: bounds.top + $(commentsSubscribeLinkObj).height() + "px"})
		.html('<div style="padding: 10px">'+window.subLoader.req.responseText+'</div>')
		.appendTo('body');
	
	
	setTimeout(closeCommentsSubscribeBox, 3000);
}

function doCommentsSubscribe( callerObj, topicId, subscribeTxt, unsubscribeTxt ) {
	if( !topicId ){
		return "";
	}
	
	commentsSubscribeLinkObj = callerObj;
	commentsSubscribeSubscribeTxt = subscribeTxt;
	commentsSubscribeUnSubscribeTxt = unsubscribeTxt;
	window.subLoader=new net.Loader("/ipbmakecomments?do=subscribe&t="+topicId+"&random="+Math.random(),finishCommentsSubscribe,null,"get",null,null);
}
/* /subscribe new comment */



/* fixpng */
function sb_js_cmn_fixPng(element) {
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		
		if (element.tagName=='IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "/d/0/img/s/sb/g/other/pix.gif";
			}
		} else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src) {
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		
		if (src) {
			element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='crop')";
		}
	}
}
/* /fixpng */



/* new comments */
function ctrl_enter(e, form) {
	if (((e.keyCode === 13) || (e.keyCode === 10)) && (e.ctrlKey === true)) {
		form.submit();
	}
}

function showhideCommentBody(s,h) {
	var ss = document.getElementById(s).style;
	var hh = document.getElementById(h).style;

	if (ss.display === 'block' ) {
		ss.display = 'none';
		hh.display = 'block';
	} else if ( ss.display === 'none' ) {
		ss.display = 'block';
		hh.display = 'none';
	}

	return false;
}

function deleteConfirm(){
    if (confirm("Вы уверены, что хотите удалить этот комментарий?")) {
        return true;
    } else {
        return false;
    }
}

if ( typeof(readCookie) === 'function' ) {
    status = readCookie('sp_c_comm_def_show');
    if ( status !== null ) {
        if ( status !== '' ) {
            if ( status === 0 ) {
                sp_c_comm_def_show('sp_c_comm_def_show', 'sp_c_comm_def_comms', 'sp_c_comm_def_show', 'sp_c_comm_def_show_r');
            }
        }
    }
}

function sp_c_comm_def_imgs_resize() {
	var dom_images = document.images;
	var dom_comments = document.getElementById('sp_c_comm_def');
	dom_comments.style.overflow = 'hidden';
	dom_comments.style.width = '100%';
	var comments_width = dom_comments.offsetWidth;
	var dom_image, image_width;

	for (i=0; i<dom_images.length; i++) {
		dom_image = dom_images[i];

		if (dom_image.className === 'bbc_img') {
			image_width = dom_image.offsetWidth;

			if (image_width > comments_width) {
				dom_image.width = comments_width - 40;
			}
		}
	}

	dom_comments.style.overflow = 'visible';
	dom_comments.style.width = 'auto';
}
/* /new comments */
 

/* dynamic menu into .sb_t_cols_210 */
/*
jQuery(function(){
	
	// definite current item
	{	
		var page_address = location.href;
		var link_path = '';
		var founded_flag = false;
		jQuery('ul.stats a').each(function(){
			if(this.pathname.indexOf('/stats') !== -1) {
				link_path = this.pathname.substring( this.pathname.indexOf('/stats') );
				if(page_address.indexOf(link_path) !== -1) {
						if(jQuery(this).next('ul')[0]) {
							jQuery(this).parent().attr('class','active-trail');
							jQuery(this).next('ul').show()
						}
						else {
							jQuery(this).css('color','#2E3844').parent().attr('class','active-trail');
						}
						
						if(jQuery(this).parents('ul').size()>1) {
							jQuery(this).parent().parent().show()
							jQuery(this).parent().parent().parent().attr('class','active-trail')
						}
				}
			}
		});
	};
	// end definite current item
	
	
	var currentOpenedMenu = jQuery('li.active-trail ul');
	
	jQuery('ul.stats a').mousedown(function(event){
		event.preventDefault();
		if(   jQuery('ul', this.parentNode)[0]   ) {
			jQuery(this).click(function(event){event.preventDefault();})
			if( jQuery('ul', this.parentNode).is(':hidden') ) {
				jQuery('ul', this.parentNode).show();
				jQuery(this.parentNode).addClass('active-trail');
			}
			else {
				jQuery('ul', this.parentNode).hide();
				jQuery(this.parentNode).attr('class','collapsed');
			}
				
			if(currentOpenedMenu[0] !== jQuery('ul', this.parentNode)[0]) {
				currentOpenedMenu.hide().parent().attr('class','collapsed');
			}
			currentOpenedMenu = jQuery('ul', this.parentNode);
		}
	});
});
*/
/* /dynamic menu into .sb_t_cols_210 */
