$(function() {
		$('#gallery-container a').lightBox();
		$('.calendar-event-link')
		.datePicker({createButton:false})
		.bind(
			'click',
			function()
			{
				$(this).dpDisplay();
				this.blur();
				return false;
			}
		)
		.bind(
			'dateSelected',
			function(e, selectedDate, $td)
			{
				location.href = '/calendar/' + selectedDate.asString( 'yyyy/mm/dd' );
				
			}
		);



		
		});
		
		function login()
		{
			
			if( document.getElementById("login-mail").value === '' )
			{
				$( '#login-error' ).show();
				$( '#login-error' ).text( 'Введите e-mail' );
			}
			else if( document.getElementById("login-password").value === '' )
			{
				$( '#login-error' ).show();
				$( '#login-error' ).text( 'Введите пароль' );
			}
			else
			{
				$.post(
					'/ajaxhandler/',
					{
						method: 'login',
						email: document.getElementById("login-mail").value,
						password: document.getElementById("login-password").value
					},
					function( data )
					{
						if( data.error === "" )
						{
							location.reload( true );
						}
						else
						{
							$( '#login-error' ).show();
							$( '#login-error' ).text( data.error );
						}
					},
					'json'
				);
			}
		}
function showSting() {
    new Boxy('\
<div style="width: 550px; padding: 22px;">\
<span style="color: red;">Уважаемые клиенты! Ознакомьтесь с важной информацией о покупке билетов!</span>\
<br/><br/>\
Для бронирования билетов на концерта Стинга в Казани Вы переходите на сайт <span style="color: red;">КАССИР.РУ Казань</span>.\
Отделение КАССИР.РУ Казань работает в режиме открытия и заполнения сайта.  \
<br/><br/>\
На сайте представлена <span style="color: red;">только часть</span> имеющихся в налиии билетов. Остальные доступные места можно \
забронировать по телефону (843) 512-25-35 либо выкупить в городских зрелищных кассах без предварительного бронирования. \
Билеты, забронированные на сайте, в кассах <span style="color: red;">НЕДОСТУПНЫ!</span>\
<br/><br/>\
Пока билеты, забронированные на этом сайте, можно выкупить <span style="color: red;">только в офисе "Билетти"</span> \
по адресу ул.Лесгафта, 6/57 (перекресток ул.Волкова и Лесгафта, вход с правого торца дома, цокольный этаж),\
можно также заказать доставку (по г.Казани) либо оплатить заказ банковским переводом (для иногородних покупателей).\
<center>\
Для покупки билетов в городских кассах бронируйте билеты по телефону (843) 512-25-35.\
<br/><br/>\
<input type="button" onclick="window.location = \'http://kzn.kassir.ru/kzn/db/text/850222684.html\'" value="Я Согласен" style="color: #0000ff; font-weight: bold;\
 width: 200px; padding: 3px; font-family: Arial,Verdana;"/>\
</center>\
</div>\
',
             {
                 title: "Предупреждение",
                 draggable: false,
                 modal: true,
                 unloadOnHide: true,
                 closeText:'<img src="/js/boxy/images/boxy-close.png"/>'
             }
	    );
}
		
		function showLoginDialog()
		{
				new Boxy(
			'\
	<div style="width: 290px; padding: 22px;">\
		<div style="width: 70px; height: 30px; font-size: 14px; vertical-align: middle;float: left;">E-mail</div>\
		<div><input type="text" style="width: 200px;float: left;" id="login-mail"/></div>\
		<div style="clear: both;"></div>\
		<div style="width: 70px; height: 30px; font-size: 14px; vertical-align: middle;float: left;">Пароль</div>\
		<div><input type="password" style="width: 200px;float: left;" id="login-password"></div>\
		<div style="clear: both;"></div>\
		<button onclick="login();">Войти</button> <span style="font-size: 12px;margin-left: 4px; margin-right: 4px;">или</span> <a href="#" onclick="Boxy.get(this).hide();return false;" class="boxy-close-link">отменить</a>\
		<div id="login-error" style="display: none;margin-top: 5px; width: 275px; height: 25px; padding-top: 5px; color: #000; background-color: #F05454; border: 1px dotted black; vertical-align: baseline; text-align: center; font-size: 12px;"></div>\
	</div>\
				',
			{
				title: "Авторизация",
				draggable: false,
				modal: true,
				unloadOnHide: true,
				closeText:'<img src="/js/boxy/images/boxy-close.png"/>'
			}
			);
			$( '#login-error' ).hide();
		}
		
		function showRegistrationDialog()
		{
			new Boxy(
		'\
<div id="registration-dialog" style="display: none; width: 460px; padding: 20px;">\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;font-weight: bold;">E-mail</div>\
		<div><input type="text" style="width: 200px;float: left;" id="reg-mail"/></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;font-weight: bold;">Пароль</div>\
		<div><input type="password" style="width: 200px;float: left;" id="reg-password"></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;font-weight: bold;">Повторите пароль</div>\
		<div><input type="password" style="width: 200px;float: left;" id="reg-password-repeat"></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;font-weight: bold;">Ник</div>\
		<div><input type="text" style="width: 200px;float: left;" id="reg-nickname"></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;">Имя</div>\
		<div><input type="text" style="width: 200px;float: left;" id="reg-firstname"></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<div style="width: 150px; height: 30px; font-size: 13px; vertical-align: middle;float: left;">Фамилия</div>\
		<div><input type="text" style="width: 200px;float: left;" id="reg-lastname"></div>\
		<div style="clear: both; height: 10px;"></div>\
		<img src="/captcha/index.php" />\
		<div style="clear: both; height: 5px;"></div>\
		<div style="width: 150px;  font-size: 13px; vertical-align: middle;float: left;">\
		Введите текст с картинки\
		</div>\
		<div><input type="text" style="width: 200px;float: left;" id="reg-keystring"></div>\
		<div style="clear: both; height: 10px;"></div>\
		\
		<button onclick="reg();">Зарегистрироваться</button> <span style="font-size: 12px;margin-left: 4px; margin-right: 4px;">или</span> <a href="#" onclick="Boxy.get(this).hide();return false;" class="boxy-close-link">отменить</a>\
		<div id="reg-error" style="display: none;margin-top: 5px; width: 275px; height: 25px; padding-top: 5px; color: #000; background-color: #F05454; border: 1px dotted black; vertical-align: baseline; text-align: center; font-size: 12px;"></div>\
</div>\
			',
		{
			title: "Регистрация",
			draggable: false,
			modal: true,
			unloadOnHide: true,
			closeText:'<img src="/js/boxy/images/boxy-close.png"/>'
		}
		);
		$( '#reg-error' ).hide();
		
		}
		
		function logout()
		{
			$.post(
					'/ajaxhandler/',
					{
						method: 'logout'
					},
					function( data )
					{
						if( data.error === "" )
						{
							location.reload( true );
						}
					},
					'json'
				);
		}
		
		function reg()
		{
			$( '#reg-error' ).hide();
			if( document.getElementById( 'reg-mail' ).value === '' )
			{
				$( '#reg-error' ).show();
				$( '#reg-error' ).text( 'Введите e-mail' );
			}
			else if( document.getElementById( 'reg-password' ).value === '' )
			{
				$( '#reg-error' ).show();
				$( '#reg-error' ).text( 'Введите пароль' );
			}
			else if( document.getElementById( 'reg-password' ).value != document.getElementById( 'reg-password-repeat' ).value )
			{
				$( '#reg-error' ).show();
				$( '#reg-error' ).text( 'Пароли не совпадают' );
			}
			else if( document.getElementById( 'reg-nickname' ).value === '' )
			{
				$( '#reg-error' ).show();
				$( '#reg-error' ).text( 'Вы не ввели никнейм' );
			}
			else if( document.getElementById( 'reg-keystring' ).value === '' )
			{
				$( '#reg-error' ).show();
				$( '#reg-error' ).text( 'Введите текст с картинки' );
			}
			else
			{
				$.post(
					'/ajaxhandler/',
					{
						method: "registration",
						email: document.getElementById("reg-mail").value,
						password: document.getElementById("reg-password").value,
						passwordrepeat: document.getElementById("reg-password-repeat").value,
						keystring: document.getElementById("reg-keystring").value,
						nickname: document.getElementById( 'reg-nickname' ).value,
						firstname: document.getElementById("reg-firstname").value,
						lastname: document.getElementById("reg-lastname").value
					},
					function( data )
					{
						if( data.error === "" )
						{
							alert( 'Вы успешно зарегистрировались' );
							location.reload( true );
						}
						else
						{
							$( '#reg-error' ).show();
							$( '#reg-error' ).text( data.error );
						}
					},
					'json'
				);
			}
		}
		
		
function saveProfile()
{
	$.post(
			'/ajaxhandler/',
			{
				firstname: document.getElementById("profile-firstname").value,
				lastname: document.getElementById("profile-lastname").value,
				method: 'save-profile'
			},
			function( data )
			{
				if( data.error === "" )
				{
					alert( 'Ваши данные успешно сохранены' );
				}
				else
				{
					$( '#reg-error' ).show();
					$( '#reg-error' ).text( data.error );
				}
			},
			'json'
		);
}
