tim1 = new Image(128, 15);
tim1.src = '/img/loading30.gif';
MYSITE = 'begame.net';

function registerName()
{
	$.post('/other/register_new.php', {text:$('#regName').val(), action:'checkname'}, function(data)
	{
		if(data.error == null) $('#name_check').stop().fadeIn(500).html('<strong style="color:green">Доступно</strong>').delay(2000).fadeOut(500);
		else $('#name_check').stop().fadeIn(500, function(){alert(data.error)}).html('<strong style="color:red">Недоступно</strong>').delay(2000).fadeOut(500);
	}, 'json');
}




function registerEmail()
{
	$.post('/other/register_new.php', {text:$('#regEmail').val(), action:'checkemail'}, function(data)
	{
		if(data.error == null) $('#email_check').stop().fadeIn(500).html('<strong style="color:green">Доступно</strong>').delay(2000).fadeOut(500);
		else $('#email_check').stop().fadeIn(500, function(){alert(data.error)}).html('<strong style="color:red">Недоступно</strong>').delay(2000).fadeOut(500);
	}, 'json');
}


function captchaImages()
{
	$('#cptch').stop().animate({opacity:0.2}, 500, function()
	{
		$.post('/other/captcha/captcha_code.php', function()
		{
			$('#cptch').attr({src:'/other/captcha/captcha_code.php?' + Math.random()}); $('#cptch').animate({opacity:1.0}, 500);
		});
	});
	
}

function registerNew()
{
	shadow();
	$.post('/other/register_new.php', $('#regForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#content').fadeOut(500, function()
			{
				$(this).html('<div align="center">Вы успешно зарегистрировались <strong>' + $('#regName').val() + '</strong>. <br>Пароль для входа на сайт отправлен на указанный Вами E-mail.<br>'
				+ 'После первого входа, желательно, сменить пароль на другой, выбранный Вами.</div>').fadeIn(500);
			});
		}
		else
		{
			alert(data.error);
		}
		
	}, 'json');
}


function registerPass()
{
	shadow();
	$.post('/other/register_new.php', $('#PassForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#content').fadeOut(500, function()
			{
				$(this).html('<div align="center">Новый пароль отправлен на указанный Вами E-mail.<br>После входа на сайт, желательно, сменить пароль на другой, выбранный Вами.</div>').fadeIn(500);
			});
		}
		else
		{
			alert(data.error);
		}
		
	}, 'json');
	
}



function shadow()
{
	var w = $(document).width() / 2 - 64;
	var h = $(document).height() / 2 - 7;
	$('<div class="loading_div" id="loader"><img src="/img/loading30.gif"></div>').prependTo('body');
}

function blockChanger(id){
$('.blockChange:visible').fadeOut(300, function()
	{
		$('#blockChange-' + id).fadeIn(300);
	});
}




function settings(action)
{
	shadow();
	$.post('/other/settings_back.php', $('#form' + action).serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#savedSpan-' + action).fadeIn(500).html('Сохранено').delay(1000).fadeOut(500);
			if(action == 'Pass')
			{
				$('#pass-1').val('');
				$('#pass-2').val('');
			}
		}
		else
		{
			alert(data.error);
		}
	}, 'json');
}






function loadedImage(data)
{
	$('#loader').remove();
	if(data.error == '')
	{
		$('#' + data.obj).attr('src', data.path + data.src);
		$('#loadfile').val('');
	}
	else alert(data.error);
}



function saveEvents()
{
	$.post('/other/save_events.php', $('#sv').serialize(), function(data)
	{
		if(data.error == null)
		{
			$('#saved').fadeIn(500).html('Сохранено').delay(2000).fadeOut(500);
			//time = window.setTimeout('$(\'#saved\').fadeOut(500)', 2000);
		
		}
	}, 'json');
}

function deleteEvents()
{
	$.post('/other/save_events.php', {action:'delete'}, function()
	{
		$('#showEv').fadeOut(500, function(){$('#showEv').html('<div align="center">Новых событий нет</div>').fadeIn(500);});
	}, 'json');
}




function messages(action)
{
	shadow();
	$('#message-2').html('');
	$.post('/other/messages_back.php', {'action':action}, function(data)
	{
		$('#loader').remove();
		$('#message-1').html(data);
	}, 'html');
}


function messagesDelete(id, from)
{
	shadow();
	$.post('/other/messages_back.php', {'action':'delete', 'id':id, 'from':from}, function()
	{
		$('#loader').remove();
		$('#mess-' + id).slideUp(500);
		$('#message-2').html('');
	});
}

function messagesRead(id, from)
{
	shadow();
	$.post('/other/messages_back.php', {'action':'read', 'id':id, 'from':from}, function(data)
	{
		$('#loader').remove();
		$('#message-2').html(data);
		$('#mess-' + id).attr('class', 'old_messages');
	}, 'html');
}








function sendMessage(id)
{
	shadow();
	$.post('/other/player_back.php', {'id':id, 'theme':$('#sendTheme').val(), 'text':$('#sendText').val()}, function(data)
	{
		$('#loader').remove();
		
		if(data.error == null)
		{
			$('#sendTheme').val('');
			$('#sendText').val('');
			$('#sendMessage').slideUp(500, function()
			{
				alert('Сообщение удачно отправлено');
			});
			
		}
		else alert(data.error);
		
	}, 'json');
}





function insertTag(start_tag, end_tag, form_id)
{
	form_id = (form_id)?form_id:'sendText';	
	var text = $('#' + form_id).val();
	var url = '';

	
	if(start_tag == '[url]')
	{
		url = prompt('Адрес ссылки', 'http://');
		var link_text = prompt('Описание ссылки', 'ССЫЛКА');
		if(url == null || link_text == null) return;
		
		start_tag = '[url=' + url + ']' + link_text;
	}
	else if(start_tag == '[img]')
	{
		url = prompt('Адрес картинки', 'http://');
		if(url == null) return;
		
		start_tag = '[img]' + url + '[/img]';
	}
	$('#' + form_id).val(text + start_tag + end_tag);
}






function blockShow(id, speed)
{
	if($('#' + id).css('display') == 'none') $('#' + id).slideDown(speed); 
	else $('#' + id).slideUp(speed);
}


function sendWallMessage(id)
{
	shadow();
	$.post('/other/wall_back.php', {'text':$('#sendText2').val(), 'id':id, 'action':'add'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			messageRead(id, 0);
		}
		else alert(data.error);
	}, 'json');	
}


function messageRead(user_id, page)
{
	shadow();
	$.post('/other/wall_back.php', {'id':user_id, 'page':page, 'action':'show'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#user_wall').html(data.text);
			$('#sendText2').val('');
			imgResize(150);
			//setTimeout('imgResize(150)', 200);
		}
		else alert(data.error);
	}, 'json');
}

function deleteWallMessage(user_id, id)
{
	shadow();
	$('#tab' + id).slideUp(500, function()
	{
		$.post('/other/wall_back.php', {'id':id, 'action':'delete'}, function()
		{
			$('#loader').remove();
			messageRead(user_id, 0);
		});		
	});

}





function searchSome()
{
	shadow();
	$.post('/other/search_results.php', $('#searchForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#searchResults').html(data.text);
		}
		else alert(data.error);
	}, 'json');
}


function checkthis(obj)
{
	if(obj.id == 'che-0') $(":checkbox[id^='che-']:gt(0)").attr('checked', '');
	else $('#che-0').attr('checked', '');
}


function loginUser(action)
{
	shadow();
	if(action == 'entrance')
	{
		$.post('/other/entrance_back.php', $('#userLogin').serialize() + '&action=entrance', function(data)
		{
			$('#loader').remove();
			if(data.error == null)
			{
				window.location.reload();
			}
			else alert(data.error);
		}, 'json');
	}
	else if(action == 'exit')
	{
		$.post('/other/entrance_back.php', {'action':'exit'}, function()
		{
			$('#loader').remove();
			window.location.reload();
		}, 'json');
	}
}



function selectInput(id)
{ 
	id.focus(); 
	id.select();
}



function changeBanner(color)
{
	curColor = (typeof(color) != 'undefined')?color:1;
	var check = $(':input[name="banner"]:checked').val();
	var size = ['width="88" height="31"', 'width="88" height="15"', 'width="31" height="31"'];
	var htmlCode = '<a href="http://' + MYSITE + '" title="beGame.net - Мониторинг серверов, ClanWar, кланы и игроки">';
	htmlCode += '<img src="http://' + MYSITE + '/img/banner/' + check + '_' + curColor + '.gif" alt="beGame.net - Мониторинг серверов, ClanWar, кланы и игроки" border="0" ' + size[check - 1] + ' /></a>';
	
	$('.selDiv').css('border', '1px solid #8c8c8c');
	$('#htmlcode').text(htmlCode);
	$('#viewer').hide().html(htmlCode).fadeIn(500);
	$('#fcolor' + curColor).css('border', '3px solid #8c8c8c');
}


function serverShowContent(action, id)
{
	selectBlock('id-' + action, 'server');
	shadow();
	$.post('/other/server_back.php', {'action':action, 'id':id}, function(data)
	{
		$('#loader').remove();
		$('#serverContent').html(data);
		
	}, 'html');	
}



function load(lat1, lon1, lat2, lon2, title1, title2) 
{

	
	if (GBrowserIsCompatible()) 
	{
		var map = new GMap2(document.getElementById("map"));
				
		if(lat1 != '' && lon1 != '')
		{
			map.setCenter(new GLatLng(lat1, lon1), 5);
			
			var servIcon = new GIcon(G_DEFAULT_ICON);
			servIcon.image = "http://" + MYSITE + "/img/google_server.png";
			servIcon.iconSize = new GSize(32, 32);
			servIcon.iconAnchor = new GPoint(16, 34); 		
			
			markerOptions2 = { icon:servIcon, title:title2 };		
			
			var lat_2 = new GLatLng(lat1, lon1);
			map.addOverlay(new GMarker(lat_2, markerOptions2));		
			
			if(lat2 != '' && lat1 != '')
			{
				var homeIcon = new GIcon(G_DEFAULT_ICON);
				homeIcon.image = "http://" + MYSITE + "/img/google_gamer.png";
				homeIcon.iconSize = new GSize(32, 32);
				homeIcon.iconAnchor = new GPoint(16, 34); 
	
				markerOptions = { icon:homeIcon, title:title1 };
				var lat_1= new GLatLng(lat2, lon2);
				map.addOverlay(new GMarker(lat_1, markerOptions));
					
	
					
				var polyline = new GPolyline([lat_1,lat_2], "#ff0000", 5);
				map.addOverlay(polyline);
			}
			
		}
		else
		{
			map.setCenter(new GLatLng(0.0000, 0.0000), 1);
		}
				
	}
	else alert("Ваш браузер не поддерживает GoogleMaps");
}




function addServerComment(id)
{
	$.post('/other/server_comment.php', {'id':id, 'text':$('#sendText2').val()}, function(data)
	{
		if(data.error == null)
		{
			serverShowContent('main', id);
		}
		else alert(data.error);
	}, 'json');
}



function serverVote(id, char)
{
	shadow();
	$.post('/other/server_vote.php', {'id':id, 'char':char}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#sRating').text(data.value);
			$('#voteLeft').html('<img src="/img/vote_left_0.png" class="im2" >');
			$('#voteRight').html('<img src="/img/vote_right_0.png" class="im2" >');
			if(data.gold != '') alert(data.gold);
		}
		else alert(data.error);
	}, 'json');
}




function changeMonImg(id)
{
	var img_id = $('input[name="mon"]:checked').val();
	
	$('#newm').attr({src:'/monitor/img/banners/' + id + '-' + img_id + '.png'});
	$('#newt').val('<a href="http://' + MYSITE + '/server-' + id + '" target="_blank"><img src="http://' + MYSITE + '/monitor/img/banners/' + id + '-' + img_id + '.png" border="0" alt="Игры, мониторинг серверов, ClanWar, форум и новости для игроков."></a>');
	
	
}



function changeMonBlock(id)
{
	var mcolor = $('#mcolor').val();
	var mfont = $('#mfont').val();
	var mborder = $('#mborder').val();
	
	
	var req = /^[a-z0-9A-Z]{3,12}$/;
	if(!req.test(mcolor)) mcolor = '000000';
	if(!req.test(mfont)) mfont = 'FFFFFF';
	if(!req.test(mborder)) mborder = '262a2e';
	
	var ir = '';
	if($('#refresh').attr('checked')) ir = '&refresh';

	var t = '<iframe src="http://'+ MYSITE +'/servers/viewer.php?id=' + id +'&color=' + mcolor + '&font='+ mfont + ir + '" style="border:1px solid #'+ mborder +'" width="170" height="195" scrolling="no" frameborder="0">Мониторинг</iframe>';
	
	$('#mtext').val(t);
	$('#frm').html(t);
	
}



function changeUserbar(id)
{
	var size = $('#MMsize').val();
	var color = $('#MMcolor').val();
	

	$('#mybar').attr('src', 'http://' + MYSITE + '/img/vote/' + id + '-' + size + '-' + color + '.gif'); 
	$('#gethtml').val('<a href="http://' + MYSITE + '/server-' + id + '" target="_blank" title="Голосуй за наш сервер!"><img src="http://' + MYSITE +'/img/vote/' + id + '-' + size + '-' + color + '.gif" border="0"></a>');
	$('#getbb').html('[url=http://' + MYSITE + '/server-' + id +'][img]http://' + MYSITE + '/img/vote/' + id + '-' + size + '-' + color + '.gif[/img][/url]');
}


function imgResize(imgSize)
{
	var imagez = document.getElementsByName("userimage");
	for(var i = 0; i < imagez.length; i++)
	{
		if(imagez[i].width > imgSize) imagez[i].width = imgSize;
	}
}


function serverAdd()
{
	shadow();
	$.post('/other/server_add.php', $('#addServer').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#serverAddContrainer').fadeOut(500, function(){$('#serverAddContrainer').html('<div align="center">Сервер добавлен на рассмотрение администратору. <br>Он появится в списке после модерации.</div>').fadeIn(500);});
			
		}
		else alert(data.error);
	}, 'json');
}


function saveServerSettings()
{
	shadow();
	$.post('/other/server_edit.php', $('#serverSettings').serialize(), function(data)
	{
		if(data.error == null)
		{
			$('#loader').remove();
			$('#savedServ').fadeIn(500).text('Сохранено').delay(1000).fadeOut(500);
		}
		else alert(data.error);
	}, 'json');
}




var tooltip=function(){
	var id = 'tt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 100;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;

			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();





function changer()
{
	var countA = $('.ai').size();
	if(typeof(tempA) == 'undefined') tempA = 2;
	
	$('.ai').fadeOut(1000);
	$('#ai-' + tempA).fadeIn(1000);

	
	for(var i = 1; i <= countA; i++)
	{
		$('#dvl-' + i).removeClass('dvl2').addClass('dvl1');
	}
	$('#dvl-' + tempA).removeClass('dvl1').addClass('dvl2');	
	
	tempA++;
	if(tempA > countA) tempA = 1;
}

function cancelChanger(id)
{
	tempA = id;
	clearInterval(stl);
	changer();
	startChange();
}

function startChange()
{
	stl = setInterval('changer()', 7000);
}


function selectBlock(id, class_id)
{
	$('.' + class_id).css('backgroundColor', '');
	$('#' + id).css('backgroundColor', '#e2e3de');
}


function sendClanMessage(id)
{
	shadow();
	$.post('/other/clan_back.php', {'text':$('#sendText2').val(), 'action':'addclannews', 'id':id}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#sendText2').val('');
			clanNewsShow(id);
		}
		else alert(data.error);
	}, 'json');
}

function clanNewsShow(id)
{
	shadow();
	$.post('/other/clan_back.php', {'id':id, 'action':'show'}, function(data)
	{
		$('#loader').remove();
		$('#newscontent').hide().html(data).fadeIn(500);
		imgResize(150);
	}, 'html');
}

function clanMessDelete(mess_id, id)
{
	shadow();
	$.post('/other/clan_back.php', {'mess_id':mess_id, 'action':'delete'}, function()
	{
		$('#loader').remove();
		clanNewsShow(id);
	});
}


function clanAction(id, action)
{
	shadow();
	$.post('/other/clan_back.php', {'id':id, 'action':action}, function()
	{
		$('#loader').remove();
		$('#cr-' + id).slideUp(500);
	});
	
}


function clanExit()
{
	shadow();
	$.post('/other/clan_back.php', {'action':'exit'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			window.location.reload();
		}
		else alert(data.error);
	}, 'json');
}


function clanTransfer()
{
	id = $('#adminTr').val();
	shadow();
	$.post('/other/clan_back.php', {'id':id, 'action':'admintransfer'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			window.location.reload();
		}
		else alert(data.error);
	}, 'json');
}

function clanStatus()
{
	shadow();
	$.post('/other/clan_back.php', $('#clanstatusall').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#savedSpan').fadeIn(500).html('Сохранено').delay(1000).fadeOut(500);
		}
		else alert(data.error);
	}, 'json');
}

function clanOut(id)
{
	shadow();
	$.post('/other/clan_back.php', {'id':id, 'action':'clanout'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#trstat-' + id).fadeOut(500);
		}
		else alert(data.error);
	}, 'json');
}

function clanDisband()
{
	shadow();
	$.post('/other/clan_back.php', {'action':'disband'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			window.location.href = 'http://' + MYSITE + '/';
		}
		else alert(data.error);
	}, 'json');
}

function clanInfo()
{
	shadow();
	$.post('/other/clan_back.php', $('#clanInfo').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#savedSpan2').fadeIn(500).html('Сохранено').delay(1000).fadeOut(500);
		}
		else alert(data.error);
	}, 'json');
}


function checkClan(action)
{
	shadow();
	if(action == 'name')
	{
		$.post('/other/clan_back.php', {'action':'check', 'text':'name', 'text2':$('#name2').val()}, function(data)
		{
			$('#loader').remove();
			if(data.error == null)
			{
				$('#savedName').fadeIn(500).html('<span style="color:green">Доступно</span>').delay(1000).fadeOut(500);
			}
			else
			{
				$('#savedName').fadeIn(500, function(){alert(data.error);}).html('<span style="color:red">Недоступно</span>').delay(1000).fadeOut(500);
				
			}
		}, 'json');
	}
	else if(action == 'page')
	{
		$.post('/other/clan_back.php', {'action':'check', 'text':'page', 'text2':$('#link2').val()}, function(data)
		{
			$('#loader').remove();
			if(data.error == null)
			{
				$('#savedPage').fadeIn(500).html('<span style="color:green">Доступно</span>').delay(1000).fadeOut(500);
			}
			else
			{
				$('#savedPage').fadeIn(500, function(){alert(data.error);}).html('<span style="color:red">Недоступно</span>').delay(1000).fadeOut(500);
				
			}
		}, 'json');
	}
}

function clanNew()
{
	shadow();
	$.post('/other/clan_back.php', $('#addClan').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#addContent').fadeOut(500, function(){$('#addContent').html('Поздравляем! Вы успешно зарегистрировали клан <strong>' + $('#name2').val() + '</strong><br><a href="http://' + MYSITE + '/clan-' + $('#link2').val() + '">Перейти на страницу клана</a><br><a href="http://' + MYSITE + '/clans/edit.php">Страница редактирования клана</a>').fadeIn(500)})
		}
		else alert(data.error);
	}, 'json');
}

function clanJoin(id)
{
	shadow();
	$.post('/other/clan_back.php', {'id':id, 'text':$('#joinText').val(), 'action':'join'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#joinContent').fadeOut(500, function(){$('#joinContent').html('Заявка на вступление в клан успешно отправлена').fadeIn(500);});
		}
		else alert(data.error);
	}, 'json');
}


function sendContact()
{
	shadow();
	$.post('/other/contact_back.php', $('#contactForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == null)
		{
			$('#contactDiv').fadeOut(500, function(){$('#contactDiv').html('<div align="center" style="height:250px">Ваше сообщение успешно отправлено.</div>').fadeIn(500);});
		}
		else alert(data.error);
	}, 'json');
}


function clanwarBlock(id)
{
	if(id == 'search')
	{
		$('#clanwarAdd').fadeOut(100, function()
		{
			$('#clanwarSearch').fadeIn(500);
		});
	}
	else
	{
		$('#clanwarSearch').fadeOut(100, function()
		{
			$('#clanwarAdd').fadeIn(500);
		});
	}
}



function timer(element)
{
	var d = new Date();
	var timestamp = $(element).attr('start');
	var r = timestamp - d.getTime();

	if(r > 0)
	{
		var result = '';

		var m1 = Math.floor(r / 86400000);//day
		var m2 = Math.floor((r - 86400000 * m1) / 3600000);//hours
		var m3 = Math.floor((r - 86400000 * m1 - m2 * 3600000) / 60000);//minutes
		var m4 = Math.floor((r - 86400000 * m1 - m2 * 3600000 - m3 * 60000) / 1000);
      
		if(m1 >= 1) result += m1+'д. ';

		if(m2 >= 1)
		{
			if(m2 >= 10) result += m2+':';
			else result += '0'+m2+':';
		}
		else result += '00:';
		
		if(m3 >= 1)
		{
			if(m3 >= 10) result += m3+':';
			else result += '0'+m3+':';
		}
		else result += '00:';
		
		if(m4 >= 1)
		{
			if(m4 >= 10) result += m4;
			else result += '0'+m4;
		}
		else result += '00';

		$(element).html(result);
		}
		else $(element).html('Истекло');
}



function clanwarAdd()
{
	shadow();
	$.post('/other/clanwar_back.php', $('#addClanwar').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			window.location.reload();
		}
		else alert(data.error);
	}, 'json');
	
}

function clanwarDelete(id)
{
	shadow();
	$.post('/other/clanwar_back.php', {'action':'delete', 'id':id}, function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			window.location.href = 'http://' + MYSITE + '/clans/clanwar.php';
		}
		else alert(data.error);
	}, 'json');
}




function addNewsComment(id)
{
	shadow();
	$.post('/other/news_comments.php', {text:$('#sendText2').val(), 'id':id}, function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			$('#sendText2').val('');
			$(data.return2).css('display', 'none').appendTo($('#commentsDiv')).fadeIn(500);
		}
		else alert(data.error);
	}, 'json');
}


function changeNewsVote(id, vote)
{
	shadow();
	$.post('/other/news_voting.php', {'id':id, 'vote':vote}, function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			$('#vrating').html(data.return2);
		}
		else alert(data.error);
	}, 'json');
}

function showDownloadComments(id)
{
	shadow();
	$.post('/other/download_comments.php', {'id':id, 'action':'show'}, function(data)
	{
		$('#loader').remove();
		$('#commentDiv').hide().html(data).fadeIn(500);
		imgResize(150);
	}, 'html');
}


function addDownloadComment(id)
{
	shadow();
	$.post('/other/download_comments.php', {'id':id, 'action':'add', 'text':$('#sendText2').val()}, function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			$('#sendText2').val('');
			showDownloadComments(id);
		}
		else alert(data.error);
	}, 'json');
}


function loadBGsound(data)
{
	$('#loader').remove();
	if(data.error == '') $('#mp3loadDiv').fadeOut(500, function()
	{
		$('#mp3loadDiv').html(data.text).fadeIn(500);
	});
	else alert(data.error);
}

function deleteMp3File()
{
	shadow();
	$.post('/other/settings_back.php', {'action':'delete_mp3'}, function(data)
	{
		$('#loader').remove();
		if(data.error == null) $('#mp3loadDiv').fadeOut(500, function()
		{
			$('#mp3loadDiv').html(data.text).fadeIn(500);
		});
		else alert(data.error);
	}, 'json');
}

function showSize(obj, fsize)
{
	var file = $(obj).attr("files")[0];
	var fileName = file.fileName;
	var fileSize = file.fileSize;
	if(fileSize < fsize) return true;
	else return false;
}

function submitBet()
{
	shadow();
	$.post('/other/bet_back.php', $('#betForm').serialize(), function(data)
	{
		$('#loader').remove();
		if(data.error == '')
		{
			dropBet();
			$('#balance').html(data.balance);
			alert('Ставки приняты. Пусть Вам повезет ;)');
		}
		else alert(data.error);
	}, 'json');
}

function dropBet()
{
	$('input[name^="bet"]').attr('checked', false); 
	$('input[name^="points"]').val('').attr('disabled', true);
	calculatePoints();
}


function calculatePoints()
{
	var summ = 0;
	$('input[name^="bet"]:checked').each(function()
	{
		var text = $(this).attr('name');
		var num = text.substr(4, text.length - 5);
		var textNum = $('input[name="points[' + num + ']"]').val();
		if(textNum != '') summ += Math.floor(Number($(this).attr('how')) * textNum);
	});
	$('#calc').html(summ);
}

function activateInput(id)
{
	var obj = $('input[name="points[' + id + ']"]');
	obj.attr('disabled', false);
	if(obj.val() == '') obj.val(10);
	 calculatePoints();
}

function checkNum(id)
{
	var re = new RegExp('^[0-9]+$');
	var text = $(id).val();
	
	if(!re.test(text)) $(id).val('');
	calculatePoints();
}


function changeLoginMail(id)
{
	if(id == 1)
	{
		$('#loginMail').attr('name', 'mylogin').val('Ваш логин');
		$('#loginlink').attr('class', 'log');
		$('#loginemail').attr('class', 'log2');
	}
	else
	{
		$('#loginMail').attr('name', 'myemail').val('Ваш E-mail');
		$('#loginemail').attr('class', 'log');
		$('#loginlink').attr('class', 'log2');
	}
}




