function mainVote()
{
	$.get('/getdata.php?operation=vote&result='+$('#voteAnswer').val(), function(data) {
		$('#pollBlock').fadeOut('normal',function(){	
			$('#pollBlock').html(data);
			$('#pollBlock').fadeIn('normal');
		});
	});
}

function mayVote(num)
{
	$('#voteAnswer').val(num);
}

function getFilmTimeTable(film,delta,photosCount,responsesCount,trailersCount)
{
	$('#ajaxmenu').html('<span class="ajaxmarks"><strong>Расписание</strong></span><a class="ajaxmarks" onclick="getFilmTrailers('+film+','+photosCount+','+responsesCount+','+trailersCount+')"><strong>Трейлеры</strong> ('+trailersCount+')</a><a class="ajaxmarks" onclick="getFilmPhotos('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Фото</strong> ('+photosCount+')</a><a class="ajaxmarks" onclick="getFilmComments('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a>);');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getFilmTimeTable&film='+film+'&date_delta='+delta+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&trailersCount='+trailersCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getFilmPhotos(film,page,photosCount,responsesCount,trailersCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getFilmTimeTable('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Расписание</strong></a><a class="ajaxmarks" onclick="getFilmTrailers('+film+','+photosCount+','+responsesCount+','+trailersCount+')"><strong>Трейлеры</strong> ('+trailersCount+')</a><span class="ajaxmarks"><strong>Фото</strong> ('+photosCount+')</span><a class="ajaxmarks" onclick="getFilmComments('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a>);');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getFilmPhotos&film='+film+'&page='+page+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&trailersCount='+trailersCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getFilmComments(film,page,photosCount,responsesCount,trailersCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getFilmTimeTable('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Расписание</strong></a><a class="ajaxmarks" onclick="getFilmTrailers('+film+','+photosCount+','+responsesCount+','+trailersCount+')"><strong>Трейлеры</strong> ('+trailersCount+')</a><a class="ajaxmarks" onclick="getFilmPhotos('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Фото</strong> ('+photosCount+')</a><span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getFilmComments&film='+film+'&page='+page+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&trailersCount='+trailersCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function addFilmComment(film,page,photosCount,responsesCount,trailersCount)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addFilmComment', film: film, name: $('#name').val(), text: $('#text').val(), page:page, reply: $('#reply').val(), photosCount:photosCount,responsesCount:responsesCount,trailersCount:trailersCount}, function(data){
							if (data == 'done') getFilmComments(film,page,photosCount,responsesCount,trailersCount);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код')
			});
		});
	}
}

function getTheatreTimeTable(film,photosCount,responsesCount)
{
	$('#ajaxmenu').html('<span class="ajaxmarks"><strong>Расписание</strong></span><a class="ajaxmarks" onclick="getTheatrePhotos('+film+',0,'+photosCount+','+responsesCount+',1)"><strong>Фото</strong> ('+photosCount+')</a><a class="ajaxmarks" onclick="getTheatreComments('+film+',0,'+photosCount+','+responsesCount+',1)"><strong>Отзывы</strong> ('+responsesCount+')</a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatreTimeTable&film='+film+'&photosCount='+photosCount+'&responsesCount='+responsesCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getTheatrePhotos(film,page,photosCount,responsesCount,withTimeTable)
{
	if (withTimeTable == 1) var timeTable = '<a class="ajaxmarks" onclick="getTheatreTimeTable('+film+','+photosCount+','+responsesCount+')"><strong>Расписание</strong></a>';
	else var timeTable = '';
	$('#ajaxmenu').html(timeTable+'<span class="ajaxmarks"><strong>Фото</strong> ('+photosCount+')</span><a class="ajaxmarks" onclick="getTheatreComments('+film+',0,'+photosCount+','+responsesCount+','+withTimeTable+')"><strong>Отзывы</strong> ('+responsesCount+')</a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatrePhotos&film='+film+'&page='+page+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&withTimeTable='+withTimeTable, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getTheatreComments(film,page,photosCount,responsesCount,withTimeTable)
{
	if (withTimeTable == 1) var timeTable = '<a class="ajaxmarks" onclick="getTheatreTimeTable('+film+','+photosCount+','+responsesCount+')"><strong>Расписание</strong></a>';
	else timeTable = '';
	$('#ajaxmenu').html(timeTable+'<a class="ajaxmarks" onclick="getTheatrePhotos('+film+',0,'+photosCount+','+responsesCount+','+withTimeTable+')"><strong>Фото</strong> ('+photosCount+')</a><span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatreComments&film='+film+'&page='+page+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&withTimeTable='+withTimeTable, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function addTheatreComment(film,page,photosCount,responsesCount,withTimeTable)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addTheatreComment', film: film, name: $('#name').val(), text: $('#text').val(), page:page, reply: $('#reply').val(), photosCount:photosCount,responsesCount:responsesCount}, function(data){
							if (data == 'done') getTheatreComments(film,page,photosCount,responsesCount,withTimeTable);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код')
			});
		});
	}
}

function addFilmReply(parent)
{
	$('#reply').val(parent);
	location.href = ruri+'#sendMessage';		
}

function addEmptyFilmReply()
{
	$('#reply').val(0);
	location.href = ruri+'#sendMessage';		
}

function getFilmTrailers(film,photosCount,responsesCount,trailersCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getFilmTimeTable('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Расписание</strong></a><span class="ajaxmarks"><strong>Трейлеры</strong> ('+trailersCount+')</span><a class="ajaxmarks" onclick="getFilmPhotos('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Фото</strong> ('+photosCount+')</a><a class="ajaxmarks" onclick="getFilmComments('+film+',0,'+photosCount+','+responsesCount+','+trailersCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a>);');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getFilmTrailers&film='+film+'&photosCount='+photosCount+'&responsesCount='+responsesCount+'&trailersCount='+trailersCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function setSize(h){    
    document.getElementById("playerDiv").style.height=h+"px";
}

function rateFilm(film,mark)
{
	$('#filmRating').fadeOut('slow',function(){
		$.get('/getdata.php?operation=rateFilm&film='+film+'&mark='+mark,function(data){
			if (data != 'error') {
				var text = '';
				var text1 = '';
				for (var i = 0; i<data; i++) text += '<img src="img/star2.gif" width="14" height="13" alt="" />';
				for (var i = 0; i<mark; i++) text1 += '<img style="padding-top:4px" src="img/atioArt.gif">';
				$('#filmRating').html(text);
				$('#filmRating').fadeIn('slow');
				$('#ratediv').fadeOut('normal',function(){
					$('#ratediv').html('<div><strong>Оценка:</strong>'+text1+'</div>');
					$('#ratediv').fadeIn('normal');
				});
				alert('Голос принят');
			} else	alert('Ошибка. Голос не принят.');
		});
	});
}

function getCinemaTimeTable(cinema,delta,responsesCount)
{
	$('#ajaxmenu').html('<span class="ajaxmarks"><strong>Расписание</strong></span><a class="ajaxmarks" onclick="getCinemaDescription('+cinema+','+responsesCount+')"><strong>Описание</strong></a><a class="ajaxmarks" onclick="getCinemaComments('+cinema+',0,'+responsesCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a><a class="ajaxmarks" onclick="getCinemaMap('+cinema+','+responsesCount+')"><strong>Карта</strong></a>);');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getCinemaTimeTable&cinema='+cinema+'&date='+delta+'&responsesCount='+responsesCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getCinemaDescription(cinema,responsesCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getCinemaTimeTable('+cinema+',0,'+responsesCount+')"><strong>Расписание</strong></a><span class="ajaxmarks"><strong>Описание</strong></span><a class="ajaxmarks" onclick="getCinemaComments('+cinema+',0,'+responsesCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a><a class="ajaxmarks" onclick="getCinemaMap('+cinema+','+responsesCount+')"><strong>Карта</strong></a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getCinemaDescription&cinema='+cinema, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});		
	});
}

function getCinemaComments(cinema,page,responsesCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getCinemaTimeTable('+cinema+',0,'+responsesCount+')"><strong>Расписание</strong></a><a class="ajaxmarks" onclick="getCinemaDescription('+cinema+','+responsesCount+')"><strong>Описание</strong></a><span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span><a class="ajaxmarks" onclick="getCinemaMap('+cinema+','+responsesCount+')"><strong>Карта</strong></a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getCinemaComments&cinema='+cinema+'&responsesCount='+responsesCount+'&page='+page, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getCinemaMap(cinema,responsesCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getCinemaTimeTable('+cinema+',0,'+responsesCount+')"><strong>Расписание</strong></a><a class="ajaxmarks" onclick="getCinemaDescription('+cinema+','+responsesCount+')"><strong>Описание</strong></a><a class="ajaxmarks" onclick="getCinemaComments('+cinema+',0,'+responsesCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a><span class="ajaxmarks"><strong>Карта</strong></span>');
	$('#mediaSection').fadeOut('slow',function(){
		/*
		$.get('/getdata.php?operation=getCinemaTimeTable&cinema='+cinema+'&date='+delta+'&responsesCount='+responsesCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
		*/
	});
}

function addCinemaComment(cinema,responsesCount)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {			
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addCinemaComment', cinema: cinema, name: $('#name').val(), text: $('#text').val(),reply: $('#reply').val(), responsesCount:responsesCount}, function(data){
							if (data == 'done') getCinemaComments(cinema,0,responsesCount);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код')
			});
		});
	}
}

function rateCompany(company,mark)
{
	$('#CompanyRating').fadeOut('slow',function(){
		$.get('/getdata.php?operation=rateCompany&company='+company+'&mark='+mark,function(data){
			if (data != 'error') {
				var text = '';
				var text1 = '';
				for (var i = 0; i<data; i++) {
					text += '<img src="img/star2.gif" width="14" height="13" alt="" />';					
				}
				for (var i = 0; i<mark; i++) {
					text1 += '<img style="padding-top:4px" src="img/atioArt.gif" alt="" />';
				}
				$('#CompanyRating').html(text);
				$('#CompanyRating').fadeIn('slow');
				$('#ratediv').fadeOut('normal',function(){
					$('#ratediv').html('<div><strong>Оценка:</strong>'+text1+'</div>');
					$('#ratediv').fadeIn('normal');
				});
				alert('Голос принят');			
			} else	alert('Ошибка. Голос не принят.');
		});
	});
}

function getCompanyComments(company,page,responsesCount,photosCount,showPhotos)
{
	if (showPhotos == 1) $('#ajaxmenu').html('<a class="ajaxmarks" onclick="getCompanyPhotos('+company+',0,'+responsesCount+','+photosCount+')"><strong>Фото</strong> ('+photosCount+')</a><span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span>');
	else $('#ajaxmenu').html('<span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getCompanyComments&company='+company+'&responsesCount='+responsesCount+'&photosCount='+photosCount+'&page='+page, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getCompanyPhotos(company,page,responsesCount,photosCount)
{
	$('#ajaxmenu').html('<span class="ajaxmarks"><strong>Фото</strong> ('+photosCount+')</span><a class="ajaxmarks" onclick="getCompanyComments('+company+',0,'+responsesCount+','+photosCount+',1)"><strong>Отзывы</strong> ('+responsesCount+')</a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getCompanyPhotos&company='+company+'&page='+page+'&photosCount='+photosCount+'&responsesCount='+responsesCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function addCompanyComment(company,responsesCount,photosCount)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addCompanyComment', company: company, name: $('#name').val(), text: $('#text').val(),reply: $('#reply').val(), responsesCount:responsesCount, photosCount:photosCount}, function(data){
							if (data == 'done') getCompanyComments(company,0,responsesCount,photosCount);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код')
			});
		});
	}
}

function confirmForm()
{
	$('#regblock').fadeOut('slow',function(){
		$('#regblock').html('<div class="warningNote">Для завершения регистрации введите код, который был выслан на указанный email.</div><div style="text-align:center;padding-top:10px;padding-bottom:10px;"><input type="text" id="key" size="50"></div><div style="text-align:center"><input type="button" onclick="confirmRegistration()" value="Завершить регистрацию"></div>');
		$('#regblock').fadeIn('slow');
	});
}

function registerUser(fromPopup)
{
	if ($('#nickname').val() == '') $('#error').html('Введите никнейм');
	else if ($('#login').val() == '') $('#error').html('Введите логин');
	else if ($('#password').val() == '') $('#error').html('Введите пароль');
	else if ($('#email').val() == '') $('#error').html('Введите e-mail');
	else if ($('#password').val() != $('#password_conf').val()) $('#error').html('Поля пароль и Проверка пароля должны совпадать');
	else {
		if (fromPopup == 'popup') code = $('#pcaptchaCode').val();
		else code = $('#captchaCode').val();
		$.get('/getdata.php',{operation:'testCaptchaCode',code:code},function(data){
			if (data == 'ok') {
				$.get('/getdata.php?operation=testUser&login='+$('#login').val(), function(data){
					if (data == 'busy') $('#error').html('Логин занят');
					else {
						$.post('/getdata.php',{operation: 'preRegisterUser', nickname: $('#nickname').val(), login: $('#login').val(), password: $('#password').val(),email: $('#email').val()}, function(data){
							if (fromPopup == 'popup') {
								$('.popGray').hide(1,function(){
									$('.popForm').hide(1,function(){
										$('#regblock').css('padding-top','50px');
										$('#regblock').css('padding-bottom','50px');
									});
								});								
							}
							if (data = 'ok') {
								$('#regblock').fadeOut('slow',function(){
									$('#regblock').html('<div class="warningNote">Для завершения регистрации перейдите по ссылке, которая была выслана на указанный email.</div>');
									$('#regblock').fadeIn('slow');
								});
							} else {
								$('#regblock').fadeOut('slow',function(){
									$('#regblock').html('<div class="warningNote">Ошибка при регистрации</div>');					
									$('#regblock').fadeIn('slow');
								});
							}
						});
					}				
				});
			} else $('#error').html('Неправильный код');
		});
	}
}

function confirmRegistration(key)
{	
	$.post('/getdata.php',{operation: 'registerUser', key: key}, function(data) {
		if (data != 'error') {
			data = data.split('|+|');
			$('#regblock').fadeOut('slow',function(){
				$('#regblock').html('<div class="warningNote">Регистрация прошла успешно</div><div style="text-align:center;padding-top:5px"><a href="/users/myprofile">Перейти в мой профиль</a></div><div style="text-align:center;padding-top:5px"><a href="/">Перейти на главную</a></div>');
				log_in(data[0],data[1]);
				$('#regblock').fadeIn('slow');
			});
		} else {
			$('#regblock').fadeOut('slow',function(){
				$('#regblock').html('<div class="warningNote">Неправильный код</div><div style="text-align:center;padding-top:10px;"><a style="cursor:pointer;//cursor:hand" onclick="confirmForm()">назад</a></div>');
				$('#regblock').fadeIn('slow');
			});
		}
	});
	
}

function log_in(login,password)
{	
	$.post('/getdata.php',{operation: 'login', login: login, password: password}, function(data){			
		if (data == 'error') {
			$('#loginLine').html('<a href="/users/register" title="Регистрация">Регистрация</a><form onsubmit="userLogin()"><input type="text" value="'+login+'" id="tlogin" name="login" value="Логин" onclick="if(this.value==\'Логин\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'Логин\';" /><input value="'+password+'" type="password" id="tpassword" name="password" value="******" onclick="if(this.value==\'******\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'******\';" /><img id="loginbut" style="cursor:pointer;//cursor:hand" onclick="userLogin()" src="img/enter.gif" onMouseOver="this.src=\'img/enter_over.gif\'" onMouseOut="this.src=\'img/enter.gif\'" class="enter" title="Вход" /><label for="rememberme"><input type="checkbox" id="rememberme" class="checks" /> Запомнить</label><a href="/users/forgot" title="Забыл пароль?">Забыл пароль?</a><span style="color:red;padding-left:10px">Ошибка при авторизации. Неправильный логин или пароль.</span>');			
			$("#tpassword").keypress(function (e) {
				if (e.which == 13) userLogin();
			});
			$("#popupPassword").keypress(function (e) {
				if (e.which == 13) popupUserLogin();
			});	
		} else {
			$('#loginLine').slideUp('normal',function(){
				data = data.split('+|+');
				
				if ($('#rememberme').is(':checked')) $.cookie('UserSessionId',data[0],{path:'/', expires: 365});
				else $.cookie('UserSessionId',data[0],{path:'/'});
				
				$('#loginLine').html('<a style="cursor:pointer;//cursor:hand" onclick="logout()" title="Выход" style="font-weight:bold;">Выход</a><div><a href="/users/myprofile" title="Профиль" class="userpixSmall"><img src="'+data[2]+'" width="23" height="23" alt="" /></a><a href="/users/myprofile" title="'+data[1]+'" class="user">'+data[1]+'</a></div>');
			}).animate({opacity: 1.0}, 200);
			$('#loginLine').slideDown('normal');
		}
	});
	
}

function logout()
{
	$('#loginLine').slideUp('slow',function(){		
		$.cookie('UserSessionId',null,{path:'/'});
		$('#loginLine').html('<a onclick="needToRegister();" style="cursor:pointer;//cursor:hand" title="Регистрация">Регистрация</a><form onsubmit="userLogin()"><input type="text" id="tlogin" name="login" value="Логин" onclick="if(this.value==\'Логин\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'Логин\';" /><input type="password" id="tpassword" name="password" value="******" onclick="if(this.value==\'******\') this.value=\'\';" onblur="if(this.value==\'\') this.value=\'******\';" /><img id="loginbut" style="cursor:pointer;//cursor:hand" onclick="userLogin()" src="img/enter.gif" onMouseOver="this.src=\'img/enter_over.gif\'" onMouseOut="this.src=\'img/enter.gif\'" class="enter" title="Вход" /><label for="rememberme"><input type="checkbox" id="rememberme" class="checks" /> Запомнить</label><a href="#" title="Забыл пароль?">Забыл пароль?</a></form>');		
		startMsIeHover();
		$("#tpassword").keypress(function (e) {
			if (e.which == 13) userLogin();
		});		
		$('#loginLine').slideDown('slow');		
	}).animate({opacity: 1.0}, 200);
}

function userLogin()
{
	log_in($('#tlogin').val(),$('#tpassword').val());
	document.getElementById('loginbut').src='img/enter_over.gif';
}

$(document).ready(function(){	
	$("#tpassword").keypress(function (e) {
		if (e.which == 13) userLogin();
	});	
	
	$("#popupPassword").keypress(function (e) {
		if (e.which == 13) popupUserLogin();
	});	
});


function getArticleComments(article,page)
{	
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getArticleComments&article='+article+'&page='+page, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function addArticleComment(article,page)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addArticleComment', article: article, name: $('#name').val(), text: $('#text').val(), page:page, reply: $('#reply').val()}, function(data){
							if (data == 'done') getArticleComments(article,page);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код');
			});
		});
	}
}

function reloadCaptcha()
{
	$('#captcha').fadeOut('normal',function(){
		$('#captcha').load('/getdata.php?operation=getcaptcha',function(){
			$('#captcha').fadeIn('normal');
		});
	});
}

function hideRegions()
{
	$('#areaBox').slideUp('normal', function(){
		$('#regionsCap').html('<a style="cursor:pointer;//cursor:hand" onclick="showRegions()">Раскрыть</a><h4>Фильтр:</h4>');		
		$.cookie('hideRegions',1,{path:'/'});
	});
}

function showRegions()
{	
	$('#areaBox').slideDown('normal',function(){
		$('#regionsCap').html('<a style="cursor:pointer;//cursor:hand" onclick="hideRegions()">Скрыть</a><h4>Фильтр:</h4>');
	});
	$.cookie('hideRegions',0,{path:'/'});
}

function addFirm()
{
	if ($('#subcategory').val() == '-') $('#regerror').text('Не выбран подтип компании');
	else if($('#name').val() == '') $('#regerror').text('Введите название компании');
	else if($('#street').val() == '') $('#regerror').text('Введите название улицы');
	else if($('#house').val() == '') $('#regerror').text('Введите номер дома');	
	else if($('#phone1').val() == '') $('#regerror').text('Введите телефон');
	else if($('#fregemail').val() == '') $('#regerror').text('Введите e-mail');
	else document.getElementById('addFirmForm').submit();
}

function addFilmToFav(id)
{
	$.get('/getdata.php?operation=isLogined',function(data) {
		if (data == 1) {
			$.get('/getdata.php?operation=addFilmToFav&film='+id,function(data){
				if (data != 'error') alert('Фильм добавлен в избранное');
				else alert('Ошибка при добавлении');
			});
		} else {
			needToRegister();
		}
	});
}

function addPlayToFav(id)
{
	$.get('/getdata.php?operation=isLogined',function(data) {
		if (data == 1) {
			$.get('/getdata.php?operation=addPlayToFav&play='+id,function(data){
				if (data != 'error') alert(data);
				else alert('Ошибка при добавлении');
			});
		} else {
			needToRegister();
		}
	});
}

function addFirmToFav(id)
{
	$.get('/getdata.php?operation=isLogined',function(data) {
		if (data == 1) {
			$.get('/getdata.php?operation=addFirmToFav&firm='+id,function(data){
				if (data != 'error') alert('Компания добавлена в избранное');
				else alert('Ошибка при добавлении');
			});
		} else {
			needToRegister();
		}
	});
}

function addArticleToFav(id)
{
	$.get('/getdata.php?operation=isLogined',function(data) {
		if (data == 1) {
			$.get('/getdata.php?operation=addArticleToFav&article='+id,function(data){
				if (data != 'error') alert('Статья добавлена в избранное');
				else alert('Ошибка при добавлении');
			});
		} else {
			needToRegister();
		}
	});
}

function genresFilter()
{
	var link = '';
	$(".genreBox:checked").map(function() {
		if (link == '') link = $(this).val();
		else link += 'OR'+$(this).val();
	});
	location.href='/afisha/kino/&genre='+link;
}

function selectGenre()
{
	if ($(".genreBox:checked").length == 0) {
		document.getElementById('allGenres').checked = true;
	} else document.getElementById('allGenres').checked = false;	
}

function unSelectGenres()
{
	$(".genreBox:checked").map(function() {
		$(this).attr('checked', false);
	});
}

function CheckMaxLength(Object, MaxLen)
{
  if(Object.value.length > MaxLen)
  {      
    Object.value = Object.value.substring(0, MaxLen);
  }
}

function popupUserLogin()
{
	$('#tlogin').val($('#popupLogin').val());
	$('#tpassword').val($('#popupPassword').val());
	closePopup();
	userLogin();
}

function closePopup()
{
	$('.popTopBody').fadeOut('slow');
}

function showPopup()
{
	$('.popTopBody').fadeIn('slow');
	$('.popTopBody').css('margin-top',(window.innerHeight-document.getElementById('regP').clientHeight)/2-75);	
	$('.popTopBody').css('margin-left','-'+(window.innerWidth/2 + 150)+'px');
}

function needToRegister() 
{	
	scroll(0,0);
	showPopup();
}

function getTheatreLocationTimeTable(id,responsesCount)
{
	$('#ajaxmenu').html('<span class="ajaxmarks"><strong>Расписание</strong></span><a class="ajaxmarks" onclick="getTheatreLocationDescription('+id+','+responsesCount+')"><strong>Описание</strong></a><a class="ajaxmarks" onclick="getTheatreLocationComments('+id+',0,'+responsesCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatreLocationTimetable&id='+id, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getTheatreLocationDescription(id,responsesCount)
{
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getTheatreLocationTimeTable('+id+','+responsesCount+')"><strong>Расписание</strong></a><span class="ajaxmarks"><strong>Описание</strong></span><a class="ajaxmarks" onclick="getTheatreLocationComments('+id+',0,'+responsesCount+')"><strong>Отзывы</strong> ('+responsesCount+')</a>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatreLocationDescription&id='+id, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function getTheatreLocationComments(film,page,responsesCount)
{
	var id = film;
	$('#ajaxmenu').html('<a class="ajaxmarks" onclick="getTheatreLocationTimeTable('+id+','+responsesCount+')"><strong>Расписание</strong></a><a class="ajaxmarks" onclick="getTheatreLocationDescription('+id+','+responsesCount+')"><strong>Описание</strong></a><span class="ajaxmarks"><strong>Отзывы</strong> ('+responsesCount+')</span>');
	$('#mediaSection').fadeOut('slow',function(){
		$.get('/getdata.php?operation=getTheatreLocationComments&film='+film+'&page='+page+'&responsesCount='+responsesCount, function(data) {
			$('#mediaSection').html(data);
			$('#mediaSection').fadeIn('slow');
		});
	});
}

function addTheatreLocationComment(film,page,responsesCount)
{
	if ($('#name').val() == '') alert('Введите имя');
	else if ($('#text').val() == '') alert('Введите текст комментария');
	else {
		$.get('/getdata.php',{operation:'testCaptchaCode',code:$('#captchaCode').val()},function(data){
			$.get('/getdata.php?operation=isLogined',function(data1) {		
				if (data == 'ok' || data1 == '1') {
					$('#mediaSection').fadeOut('slow',function(){
						$.post('/getdata.php',{operation: 'addTheatreLocationComment', film: film, name: $('#name').val(), text: $('#text').val(), page:page, reply: $('#reply').val(), responsesCount:responsesCount}, function(data){
							if (data == 'done') getTheatreLocationComments(film,page,responsesCount);
							else {
								$('#mediaSection').html(data);
								$('#mediaSection').fadeIn('slow');
							}				
						});
					});
				} else alert('Неправильный код')
			});
		});
	}
}
