$(window).load(function() {
	// Текущая страница
	$cur_page = $( '#page-value' ).val();
	$stcal = $( '#STCAL' ).val();
	if ( $stcal == '1' ){
		if ( $( '#cal .thiss' ).children().html() ){
			$( '#cal .thiss' ).children().css( {'background':'#f2b7b2'} );
		} else {
			$( '#cal .thiss' ).css( {'background':'#f2b7b2'} );
		}
		$( '#cal .thispo' ).css( {'background':'#f2b7b2'} );
		if ( $( '#daypo' ).val() != $( '#days' ).val() )
			setBgChild()
	}
	$( '#call .yeahh' ).click( function(){
		$( '#call' ).fadeOut( 'slow' );
		$( '#thday' ).val( getDateTwo( $( this ) ) );
		document.event_form.submit(); 
	});
	$( '#calll .yeahh' ).click( function(){
		//$( '#call' ).fadeOut( 'slow' );
		$( '#thday' ).val( getDateTwo( $( this ) ) );
		document.event_form.submit(); 
	});
	$( '.time-line .time' ).click( function() {
		var $id = $( this ).parent().find( 'input:first').val();
		$.ajax({
			url: "/includes/ajax/ajax-addshow.php",
			global: false,
			type: "POST",
			data: ( {id:$id} ),
			dataType: "html",
			async:false,
			success: function(msg){
				if ( msg == 'error:1' ){
					alert( 'Для добавления события в органайзер необходимо зарегистрироваться.' );
				} else {
					alert( msg );
				}
			}
		} ).responseText;
	} );
	$( '.time-line .time' ).mousemove( function(e){
			var $x = e.pageX-40, $y = e.pageY-50;
			$( '.add-to-org' ).fadeIn();
			$( '.add-to-org' ).css( { top:$y+'px', left:$x+'px' } );
	} );
	$( '.time-line .time' ).mouseout( function() {
		$( '.add-to-org' ).fadeOut();
	} );
	$( '.org-sob .red-close-but' ).click( function() {
		var $id = $( this ).parent().find( 'input:first' ).val();
		var type = $( this ).parent().find( '#event_type' ).val();
		$.ajax({
			url: "/includes/ajax/ajax-deleteshow.php",
			global: false,
			type: "POST",
			data: ( {id:$id, type:type} ),
			dataType: "html",
			async:false,
			success: function(msg){
				if ( msg == 'ok' ){
					alert( 'Событие успешно удалено из вашего органайзера.' );
					document.location.href='/organiser/';
				} else {
					alert( msg );
				}
			}
		} ).responseText;
	} );
	$( '#cal .sub-title-txt' ).click( function() {
		$days = $( '#days' ); $daypo = $( '#daypo' );
		if ( $( this ).hasClass( 'yeahh' ) ){
			if ( $days.val() == '0' ){
				setDates( getDate( $( this ) )*1 );
				$( this ).addClass( 'thiss' );
			} else {
				if( $days.val()*1 > getDate( $( this ) )*1 ){
					clearBg();
					setDates( 0 ); setDatepo( 0 );
					setDates( getDate( $( this ) )*1 );
					$( this ).addClass( 'thiss' );
				} else if ( $days.val()*1 == getDate( $( this ) )*1 ){
					clearBg();
					setDates( 0 ); setDatepo( 0 );
				} else if ( $days.val()*1 < getDate( $( this ) )*1 ){
					if ( $daypo.val()*1 == 0 ){
						setDatepo( getDate( $( this ) )*1 );
						$( this ).addClass( 'thispo' );
						setBgChild();
					} else {
						clearBg();
						setDates( 0 ); setDatepo( 0 );
						setDates( getDate( $( this ) )*1 );
						$( this ).addClass( 'thiss' );
					}
				}
			}
		}
	} );

	// Оверлей
	$( '#hidden-overlay' ).width( $( window ).width() ).height( $( window ).height() ); 
	$overlay = $( '#overlay' ); $ebox = $( '#enter-box' );

	// Установки для index
	if ( $cur_page == 'index' ) { 
		$overlay.width( $( 'body' ).width() ).height( $( 'body' ).height() ); 
		$left = ((($( window ).width()/2)-123).toFixed(0))*1;
		$top = ((($( window ).height()/2)-73 ).toFixed(0))*1;
		$ebox.css( 'left', $left ).css( 'top', $top );
	}

	// Открытие блока для входа
	$( '#enter-but, #enter-but-two' ).click( function() {
		$( '#step-1' ).show(); $( '#step-2' ).hide();
		$( '#overlay' ).css( "display", "block" ).stop().animate( {opacity:0.6}, 300 );
		$( '#enter-box' ).css( "display", "block" ).stop().animate( {opacity:1}, 400 );
	} );

	// Закрытие блока входа и оверлея
	$( '#overlay, #ebox-close' ).click( function() {
		$( '#overlay' ).stop().fadeOut().animate( {opacity:0}, 0 );
		$( '#enter-box' ).stop().fadeOut().animate( {opacity:0}, 0 );
	} );

	// Чекбоксы
	$( '.chbox' ).click( function() {
		var $isall = $( this ).attr( 'rel' ),
			$val = $( this ).parent().find( 'input:first' ),
			$sel = $( this ).parent().find( '.chsel:first' );
		if ( !$isall )
			$isall = 'normal';
		if ( $isall == 'all-types' ){
			if( $val.val() == '1' ){
				$( this ).parent().parent().parent().find( 'input' ).val( '0' );
				$( this ).parent().parent().parent().find( '.chsel' ).fadeOut();
			} else {
				$( this ).parent().parent().parent().find( 'input' ).val( '1' );
				$( this ).parent().parent().parent().find( '.chsel' ).fadeIn();
			}
		} else if ( $isall == 'one-is' ){
			$( this ).parent().parent().parent().find( 'input' ).val( '0' );
			$( this ).parent().parent().parent().find( '#inputptype' ).val( '' );
			$( this ).parent().parent().parent().find( '.chsel' ).fadeOut();
			if ( $( this ).attr( 'id' ) != 'inputptype' ){
				$val.val( '1' );
				$sel.fadeIn();
			}
		} else {
			if( $val.val() == '1' ){
				$val.val( '0' );
				$sel.fadeOut();
			} else {
				$val.val( '1' );
				$sel.fadeIn();
			}
		}
	} );

	// Запомнить
	$( '#rem-but' ).click( function() {
		$( '#step-1' ).stop().fadeOut();
		setTimeout( function() { $( '#step-2' ).fadeIn(); }, 300 );
	} );

	// Оценки
	$( '.star-ch' ).mouseover( function() {
		$num = $( this ).attr( 'title' );
		if ( $num != 1 ){
			$parent = $( this ).parent();
			$( this ).addClass( 'hov-star' );
			$( this ).css( 'background', 'url(/images/star-full.png) no-repeat' );
			$parent.find( 'div:first' ).css( 'background', 'url(/images/star-full.png) no-repeat' );
			$parent.find( 'div:first' ).nextUntil( '.hov-star' ).css( 'background', 'url(/images/star-full.png) no-repeat' );
		} else {
			$( this ).css( 'background', 'url(/images/star-full.png) no-repeat' );
		}
	} );

	$( '.star-ch' ).mouseout( function() {
		$( '.hov-star' ).removeClass( 'hov-star' );
		$( this ).parent().find( 'div' ).css( 'background', 'url(/images/star-of.png) no-repeat' );
	} );

	$( '.star-ch' ).click( function() {
		$( '.hov-star' ).removeClass( 'hov-star' );
		$( '#star-oc-block' ).hide();
		var $oc = $( this ).attr( 'title' ),
			$id = $( '#type_id_oc' ).val(),
			$type = $( '#oc_type' ).val();
		$.ajax( {
			url: "/includes/ajax/ajax-oc.php",
			global: false,
			type: "POST",
			data: ( { id:$id, oc:$oc, type:$type } ),
			dataType: "html",
			async:false,
			success: function(msg){
				msg = msg.split( '--++--' );
				var $ocen = msg[0],
					$count = msg[1];
				$( '#ocenochki' ).html( WriteStars ( 'event_rate', $ocen ) );
				$( '#ocenili' ).html ( 'Оценили: '+$count );
			}
		} ).responseText;
	} );

	// Идущие люди	
	$( '#walk-peoples' ).mouseover( function() {
		$( this ).find( '#walk-hover').show();
	} );
	$( '#walk-peoples' ).mouseout( function() {
		$( this ).find( '#walk-hover').hide();
	} );
	$( '#igoobutton' ).click( function() {
		$( this ).hide( function() {
			var $id = $( '#type_id_oc' ).val(),
				$type = $( '#oc_type' ).val();
			$.ajax( {
				url: "/includes/ajax/ajax-visitors.php",
				global: false,
				type: "POST",
				data: ( { id:$id, type:$type } ),
				dataType: "html",
				async:false,
				success: function(msg){
					$( '#visitors' ).html( msg );
				}
			} ).responseText;
		} );
	} );

	// Показ комментариев
	$( '.comm-rall' ).click( function() {
		if( $( this ).parent().find( '.comm-text:first' ).find( 'span:first' ).css( 'display' ) == 'none' ){
			$( this ).parent().find( '.comm-text:first' ).find( 'point' ).hide();
			$( this ).parent().find( '.comm-text:first' ).find( 'span:first' ).fadeIn(1000);
		} else {
			$( this ).parent().find( '.comm-text:first' ).find( 'point' ).show();
			$( this ).parent().find( '.comm-text:first' ).find( 'span:first' ).fadeOut();
		}
		$( this ).html( ( ($( this ).html() == 'Читать полностью' ) ? 'Скрыть' : 'Читать полностью' ) );
	} );

	// Регистрация
	$( '#goreg' ).click( function() {
		$( this ).removeAttr( 'id' );
		$( this ).html( '<center><img src="/images/ajax-loader.gif" title="Пожалуйста, подождите" alt="Пожалуйста, подождите"/></center>' );

		var $form = $( '#regform' ).children(),
			$name = $form.find( 'input:[name = "name"]' ),
			$lastname = $form.find( 'input:[name = "lastname"]' ),
			$email = $form.find( 'input:[name = "email"]' ),
			$password = $form.find( 'input:[name = "password"]' ),
			$repassword = $form.find( 'input:[name = "repassword"]' ),
			$cap = $form.find( 'input:[name = "cap"]' ),
			$agree = $form.find( 'input:[name = "agree"]' ),
			$nameRor = 0, $lastnameRor = 0, $emailRor = 0, $passRor = 0, $repassRor = 0, $captRor = 0, $agreeRor = 0, $error = 0;
		if ( $name.val() == '' ) {
			$nameRor = 1; $error = 1;
		} 
		if ( $lastname.val() == '' ) {
			$lastnameRor = 1; $error = 1;
		} 
		if ( $email.val() == '' || substr_count( $email.val(), '@' ) != '1' || substr_count( $email.val(), '.' )*1 < 1 ){
			$emailRor = 1; $error = 1;
		} 
		if ( $password.val().length < '6' || $password.val() == '' ){
			$passRor = 1; $error = 1;
		}
		if ( $password.val() != $repassword.val() ){
			$repassRor = 1; $error = 1;
		}
		if ( $agree.val() == '0' ){
			$agreeRor = 1; $error = 1;
		}
		if ( $cap.val() != '' ){
			$.ajax({
				url: "/includes/captcha/ajax-check-captcha.php",
				global: false,
				type: "POST",
				data: ( { cap: $cap.val() } ),
				dataType: "html",
				async:false,
				success: function(msg){
					$captRor = msg;
					if ( $error == '0' )
						$error = ( $captRor == 0 ) ? 0 : 1;
				}
			} ).responseText;
		}

		showRor( $form, 'input:[name = "name"]', 'span:[rel = "nameRor"]', 'null', $nameRor );
		showRor( $form, 'input:[name = "lastname"]', 'span:[rel = "lastnameRor"]', 'null', $lastnameRor );
		
		showRor( $form, 'input:[name = "email"]', 'span:[rel = "emailRor"]', 'null', $emailRor );
		
		$ret = showRor( $form, 'input:[name = "password"]', 'span:[rel = "passwordRor"]', 'null', $passRor );
		
		if ( $ret == '0' ){
			$ret = showRor( $form, 'input:[name = "repassword"]', 'span:[rel = "repasswordRor"]', 'null', $repassRor );
			if( $ret == '1' )
				$form.find( 'input:[name = "password"]' ).addClass( 'bcred' );
			else
				$form.find( 'input:[name = "password"]' ).removeClass( 'bcred' );
		}
		showRor( $form, 'div:[rel = "agree"]', 'span:[rel = "agreeRor"]', 'null', $agreeRor );
		showRor( $form, 'input:[name = "cap"]', '.capinp', 'span:[rel = "captRor"]', $captRor );
		$( this ).attr( 'id', 'goerr' );
		
		if ( $error == 0 ){
			$.ajax({
				url: "/includes/ajax/ajax-reg.php",
				global: false,
				type: "POST",
				data: ( { name:$name.val(), lname:$lastname.val(), email:$email.val(), pass:$password.val(), cap:$cap.val() } ),
				dataType: "html",
				async:false,
				success: function(msg){
					$error = msg;
					if ( $error == '1' ){
						showRor( $form, 'input:[name = "email"]', 'span:[rel = "emailRorAlredy"]', 'null', $error );
						$( '#goerr' ).html( '<div class="comm-send-but">Ошибка</div>' );
						setTimeout( function() { $( '#goerr' ).find( '.comm-send-but' ).fadeOut( function(){
							$( this ).html( 'Готово' ).fadeIn();
							$( this ).parent().attr( 'id', 'goreg' )
						} ); }, 1000 );
					} else if( $error == '0' ) {
						showRor( $form, 'input:[name = "email"]', 'span:[rel = "emailRorAlredy"]', 'null', $error );
						$( '#regform' ).fadeOut( function() {
							$( '#regend' ).fadeIn();
							$( '#goerr' ).html( '<div class="comm-send-but">Готово</div>' ).attr( 'id', 'goreg' );
						} );
					} else {
						alert( $error );
					}
				}
			} ).responseText;
		} else {
			$( this ).html( '<div class="comm-send-but">Ошибка</div>' );
			setTimeout( function() { $( '#goerr' ).find( '.comm-send-but' ).fadeOut( function(){
				$( this ).html( 'Готово' ).fadeIn();
				$( this ).parent().attr( 'id', 'goreg' )
			} ); }, 1000 );
		}
	} );

	// Выслать новое письмо для подтверждения
	$( '#remail' ).click( function() {
		var $form = $( '#regform' ).children(),
			$email = $form.find( 'input:[name = "email"]' );
		$.ajax({
			url: "/includes/ajax/ajax-remail.php",
			global: false,
			type: "POST",
			data: ( { email: $email.val() } ),
			dataType: "html",
			async:false
		}).responseText
	} );

	// Опции
	$( '.select-but, #hidden-overlay' ).click( function() {
		$click = $( this ).parent().attr( 'id' );	
		$open = $( '#open-select' );
		if ( $click != "" && $click != $open.val() ){
			$open.val( $click );
			$( '.select-child' ).parent().find( '.select-but:first' ).css( 'background', 'url(/images/s-but-down.png) no-repeat' );
			$( this ).css( 'background', 'url(/images/s-but-up.png) no-repeat' );
			$( '.select-child' ).css( 'display', 'none' );
			$( '#hidden-overlay' ).fadeIn();
			$( this ).parent().find( '.select-child:first' ).css( 'display', 'block' );
		} else {
			$( "#"+$open.val() ).find( '.select-but:first' ).css( 'background', 'url(/images/s-but-down.png) no-repeat' );
			$open.val( '' );
			$( '.select-child' ).css( 'display', 'none' );
			$( '#hidden-overlay' ).fadeOut();
		}
	} );

	$( '.select-option, .select-option-sel' ).click( function() {
		var $url = $( this ).attr( 'url' );
		if( !$url ){
			$open = $( '#open-select' );
			$( "#"+$open.val() ).find( '.select-but:first' ).css( 'background', 'url(/images/s-but-down.png) no-repeat' );

			$( this ).parent().find( '.select-option-sel:first' ).removeClass( 'select-option-sel' ).addClass( 'select-option' );
			$( this ).parent().parent().find( 'span:first' ).html( $( this ).html() );
			$( this ).removeClass( 'select-option' ).addClass( 'select-option-sel' );
			$( this ).parent().parent().find( 'input:first' ).val( $( this ).html() );

			$open.val( '' );
			$( '.select-child' ).css( 'display', 'none' );
			$( '#hidden-overlay' ).fadeOut();
		} else {
			document.location.href=$url;
		}
	} );

	// Войти
	$( '#enter-button' ).click( function() {
		var $form = $( '#step-1' ),
			$email = $form.find( 'input:[name = "login"]' ),
			$password = $form.find( 'input:[name = "password"]' ),
			$rem = $form.find( 'input:[name = "rem"]' );
			$.ajax({
				url: "/includes/ajax/ajax-login.php",
				global: false,
				type: "POST",
				data: ( { email: $email.val(), password: $password.val(), rem: $rem.val() } ),
				dataType: "html",
				async:false,
				success: function(msg){
					if ( msg == 'ok' ){
						document.location.reload();
					} else {
						alert( msg );
					}
				}
			} ).responseText;
	} );

	// Выйти
	$( '#exit-button' ).click( function() {
		$.ajax({
			url: "/includes/ajax/ajax-exit.php",
			global: false,
			type: "POST",
			data: ( {} ),
			dataType: "html",
			async:false,
			success: function(msg){
				if ( msg == 'ok' ){
					document.location.reload();
				} else {
					alert( msg );
				}
			}
		} ).responseText;
	} );

	// Выслать новый пароль
	$( '#rem-button' ).click( function() {
		var $form = $( '#step-2' ),
			$email = $form.find( 'input:[name = "email"]' );
		$.ajax({
			url: "/includes/ajax/ajax-rem.php",
			global: false,
			type: "POST",
			data: ( {email:$email.val()} ),
			dataType: "html",
			async:false,
			success: function(msg){
				if ( msg == 'ok' ){
					document.location.href = '/';
				} else {
					alert( msg );
				}
			}
		} ).responseText;
	});

	// Новый пароль в опциях
	$( '#repass-butt' ).click( function() {
		if ( $( this ).html() == 'Изменить' ){
			$( this ).css( 'background', 'none' ).html( '<img src="/images/ajax-loader.gif" title="Пожалуйста подождите" alt="Пожалуйста подождите"/>' );
			var $form = $( this ).parent().parent().parent(),
				$pass = $form.find( 'input:[name = "pass"]' );
				$newpass = $form.find( 'input:[name = "newpass"]' );
				$renewpass = $form.find( 'input:[name = "renewpass"]' );
			if ( $newpass.val().length*1 >= 6 ){
				if ( $newpass.val() == $renewpass.val() && $newpass.val() != '' ){
					$.ajax({
						url: "/includes/ajax/ajax-newpass.php",
						global: false,
						type: "POST",
						data: ( {oldpass:$pass.val(), pass:$newpass.val() } ),
						dataType: "html",
						async:false,
						success: function(msg){
							alert( msg );
							$( '#repass-butt' ).css( 'background', '#a1a1a1' ).html( 'Изменить' );
						}
					} ).responseText;
				} else {
					$( this ).css( 'background', '#a1a1a1' ).html( 'Изменить' );
					alert( 'Пароль и подтверждение пароля не совпадают.' );
				}
			} else {
				alert( 'Пароль должен быть не менее 6 символов.' );
				$( this ).css( 'background', '#a1a1a1' ).html( 'Изменить' );
			}
		}
	} );
	$( '#newemail-butt' ).click( function() {
		if ( $( this ).html() == 'Изменить' ){
			$( this ).css( 'background', 'none' ).html( '<img src="/images/ajax-loader.gif" title="Пожалуйста, подождите." alt="Пожалуйста, подождите."/>' );
			var $form = $( this ).parent().parent().parent(),
				$email = $form.find( 'input:[name = "new-email"]' );
			if( $email.val() == '' || substr_count( $email.val(), '@' ) != '1' || substr_count( $email.val(), '.' ) != '1' ){
				alert( 'Email введен некорректно.' );
				$( this ).css( 'background', '#a1a1a1' ).html( 'Изменить' );
			} else {
				$.ajax({
					url: "/includes/ajax/ajax-newmail.php",
					global: false,
					type: "POST",
					data: ( {email:$email.val()} ),
					dataType: "html",
					async:false,
					success: function(msg){
						alert( msg );
						$( '#newemail-butt' ).css( 'background', '#a1a1a1' ).html( 'Изменить' );
					}
				} ).responseText;
			}
		}
	} );
	$( '.imgrel' ).click( function() { 
		gallery( $( this ) ); 
	} );
	$( '#prevmonth, #nextmonth' ).click( function() {
		var $flag = $( '#monthflag' );
		if ( $flag.val() == '0' ){
			$flag.val( '1' );
			var	$func = $( this ).attr( 'id' ),
				$cur = $( '#cur_month_num' );
			$( this ).parent().find( '.sub-title-txt:first' ).html( '<img src="/images/ajax-loader1.gif" title="Пожалуйста подождите" alt="Пожалуйста подождите"/>' );
			$.ajax({
				url: "/includes/ajax/ajax-get-days.php",
				global: true,
				type: "POST",
				data: ( {func:$func, to:$cur.val(), yflag:$( '#yflag' ).val() } ),
				dataType: "html",
				async:false,
				success: function(msg){
					var html = msg.split( '---+++---' );
					$flag.val( '0' );
					$( '#cur_month_num' ).val( html[0] ).parent().find( '.sub-title-txt:first' ).html( html[1] );
					$( '#yflag' ).val( html[2] );
					$( '#cal' ).html( html[3] );

					$( '#cal .sub-title-txt' ).click( function() {
						$days = $( '#days' ); $daypo = $( '#daypo' );
						if ( $( this ).hasClass( 'yeahh' ) ){
							if ( $days.val() == '0' ){
								setDates( getDate( $( this ) )*1 );

								$( this ).addClass( 'thiss' );
							} else {
								if( $days.val()*1 > getDate( $( this ) )*1 ){
									clearBg();
									setDates( 0 ); setDatepo( 0 );
									setDates( getDate( $( this ) )*1 );
									$( this ).addClass( 'thiss' );
								} else if ( $days.val()*1 == getDate( $( this ) )*1 ){
									clearBg();
									setDates( 0 ); setDatepo( 0 );
								} else if ( $days.val()*1 < getDate( $( this ) )*1 ){
									if ( $daypo.val()*1 == 0 ){
										setDatepo( getDate( $( this ) )*1 );
										$( this ).addClass( 'thispo' );
										setBgChild();
									} else {
										clearBg();
										setDates( 0 ); setDatepo( 0 );
										setDates( getDate( $( this ) )*1 );
										$( this ).addClass( 'thiss' );
									}
								}
							}
						}
					} );

				}
			} ).responseText;
		}
	} );
	$( '#Add-event-but' ).click( function() {
		//error-border
		var $form = $( '#add-event-box' ),
			$name = $form.find( 'input:[name = "name"]' ),
			$ko = $form.find( 'textarea:[name = "crop"]' ),
			$mo = $form.find( 'input:[name = "place"]' ),
			$adr = $form.find( 'input:[name = "addr"]' ),
			$pho = $form.find( 'input:[name = "phone"]' ),
			$error = 0;
		if( $name.val().length == 0 ){
			$error++;
			$name.addClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeIn();
		} else {
			$name.removeClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeOut();
		}
		if ( $ko.val().length == 0 || $ko.val() == 'Краткое описание' ){
			$error++;
			$ko.addClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeIn();
		} else {
			$ko.removeClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeOut();
		}
		if ( $mo.val().length == 0 ){
			$error++;
			$mo.addClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeIn();
		} else {
			$mo.removeClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeOut();
		}
		if ( $adr.val().length == 0 ){
			$error++;
			$adr.addClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeIn();
		} else {
			$adr.removeClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeOut();
		}
		if ( $pho.val().length == 0 ){
			$error++;
			$pho.addClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeIn();
		} else {
			$pho.removeClass( 'error-border' ).parent().find( '.error-txt-two' ).fadeOut();
		}
		if ( $error == 0 ){
			document.add_event_form.submit();
		}
	} );
	$( '#CaptImg, #ClickOther' ).click( function() {
		$.ajax({
			url: "/includes/captcha/ajax-get-new.php",
			global: true,
			type: "POST",
			data: ( {} ),
			dataType: "html",
			async:false,
			success: function(msg){
				$( '#CaptImg' ).fadeOut( function() {
					$( this ).attr( 'src', '/tmp/'+msg ).load( function() { $( this ).fadeIn(); } );
				} );
			}
		});
	});
	$( '#aadd-sob-but' ).click( function() {
			var $form = $( '#add-event-box' ),
			$name = $form.find( 'input:[name = "name"]' ),
			$ko = $form.find( 'textarea:[name = "crop"]' ),
			$error = 0;
			if( $name.val().length == 0 ){
				$error++;
				$name.addClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeIn();
			} else {
				$name.removeClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeOut();
			}
			if ( $ko.val().length == 0 || $ko.val() == 'Краткое описание' ){
				$error++;
				$ko.addClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeIn();
			} else {
				$ko.removeClass( 'error-border' ).parent().find( '.error-txt-one' ).fadeOut();
			}
			if ( $error == 0 ){
				document.add_event_form.submit();
			}
	} );
});

// Показать ошибки при регистрации
function showRor( $form, $one, $two, $three, $val ){
	if ( $three == 'null' ){
		if ( $val == '1' ){
			$form.find( $one ).addClass( 'bcred' );
			$form.find( $two ).fadeIn();
			return 1;
		} else {
			$form.find( $one ).removeClass( 'bcred' );
			$form.find( $two ).fadeOut();
			return 0;
		}
	} else {
		if ( $val == '1' ){
			$form.find( $one ).addClass( 'bcred' );
			$form.find( $two ).children().find( $three ).fadeIn();
			return 1;
		} else {
			$form.find( $one ).removeClass( 'bcred' );
			$form.find( $two ).children().find( $three ).fadeOut();
			return 0;
		}
	}
}

// Написание звезд
function WriteStars ( div, count ) {
	var st = '';
	for ( var i = 1; i < 6; i++ ) {
		if ( count > i-1 && count < ((i-1)*2+1)/2 )
			st	+= '<img src="/images/star-have.png" title="Рейтинг" alt="'+i+'"/>';
		else if ( count >= ((i-1)*2+1)/2 )
			st	+= '<img src="/images/star-full.png" title="Рейтинг" alt="'+i+'"/>';
		else

			st	+= '<img src="/images/star-of.png" title="Рейтинг" alt="'+i+'"/>';
	}
	document.getElementById ( div ).innerHTML = st;
}
// После загрузки аватарки
function AvaUploaded( data ) {
	$( '#user-ava-block' ).find( 'img:first' ).fadeOut( function() {
		$( this ).attr( 'src', data ).fadeIn();
	} );
	$( '#del-ava-block' ).fadeIn();
}
// Удаление аватарки
function DeleteAva( $type, $id ) {
	$.ajax({
		url: "/includes/ajax/ajax-ava-delete.php",
		global: false,
		type: "POST",
		data: ({type:$type,id:$id}),
		dataType: "html",
		async:false,
		success: function(msg){
			if( $type == 'ava' ){
				$( '#user-ava-block' ).find( 'img:first' ).fadeOut( function() {
					$( this ).attr( 'src', '/images/noava.jpg' ).fadeIn();
				} );
				$( '#del-ava-block' ).fadeOut();
			} else {
				var $id = msg;
				$( '#childdelimg'+$id ).fadeOut();
				$( '#chava' + $id ).find( 'img:first' ).fadeOut( function() {
					$( this ).attr( 'src', '/images/noava.jpg' ).fadeIn();
				} );
			}
		}
	} ).responseText;
}
// Загрузка фотографии ребёнка
function ChAvaUploaded( data ) {
	data = data.split( '{--++--}' );
	var $image = data[0],
		$id = data[1];
	$( '#chava'+$id ).find( 'img:first' ).fadeOut( function(){
		$( this ).attr( 'src', $image ).fadeIn();
	});
	$( '#childdelimg'+$id ).fadeIn();
}
function chimage( data ) {
	var $data = data.split( '--++--' ), $images = $( '#imagesname' ), $tmp = $images.val();
	if ( $data[0] != '' ){
		alert( $data[0] );
	}
	$( '#imageimage'+$data[2] ).fadeIn();
	$( '#image'+$data[2]+'image' ).attr( 'src', $data[1] );
	if ( $tmp == '' )
		$tmp = $data[3];
	else
		$tmp += '--++--'+$data[3];
	$images.val( $tmp );
}
function delimageev( $num ){
	var $images = $( '#imagesname' ), $tmp = $images.val().split( '--++--' ), $tmp2 = '', $src = $( '#image'+$num+'image' ).attr( 'src' ).split('/tmp/small_');
	$src = $src[1];
	for ( $i = 0; $i<$tmp.length; $i++ ){
		if ( $tmp[$i] != $src ){
			$tmp2 += ( $tmp2 == '' ) ? $tmp[$i] : '--++--'+$tmp[$i] ;
		} else {
			var $del = $tmp[$i];
		}
	}
	$images.val( $tmp2 );
	$( '#imageimage'+$num ).fadeOut();
	$( '#image'+$num+'image' ).attr( 'src', '/images/noimage.jpg' );
	$.ajax({
		url: "/includes/ajax/ajax-sobimg-delete.php",
		global: false,
		type: "POST",
		data: ({name:$del}),
		dataType: "html",
		async:false,
		success: function(msg) {}
	} ).responseText;
}
// Попадание в строку
function substr_count(haystack, needle, offset, length) {
	var pos = 0,
		cnt = 0;

	haystack += '';
	needle += '';
	if (isNaN(offset)) {
		offset = 0;
	}
	if (isNaN(length)) {
		length = 0;
	}
	offset--;

	while ((offset = haystack.indexOf(needle, offset + 1)) != -1) {
		if (length > 0 && (offset + needle.length) > length) {
			return false;
		} else {
			cnt++;
		}
	}

	return cnt;
}

// Установка фонов
function setBgChild(){
	$rows = $( '#cal .thiss' ).parent().attr( 'rel' ).split( '-' ); $rows = $rows[1];
	$rowpo = $( '#cal .thispo' ).parent().attr( 'rel' ).split( '-' ); $rowpo = $rowpo[1];
	$table = $( '#cal' );
	for( $i = $rows; $i<=$rowpo; $i++ ){
		if( $i == $rows ){
			$table.children().find( '[rel = "row-'+$i+'"]' ).find( '.thiss' ).nextUntil('.thispo').css( {'background':'#f2b7b2'} );
		} else if( $i < $rowpo ){
			$table.children().find( '[rel = "row-'+$i+'"]' ).find( 'td' ).css( {'background':'#f2b7b2'} );
		} else if( $i == $rowpo ){
			if( $table.children().find( '[rel = "row-'+$i+'"]' ).find( 'td:first' ).hasClass( 'thispo' ) ){
				$table.children().find( '[rel = "row-'+$i+'"]' ).find( '.thispo' ).css( {'background':'#f2b7b2'} );
			} else {
				$table.children().find( '[rel = "row-'+$i+'"]' ).find( 'td:first' ).css( {'background':'#f2b7b2'} );
				$table.children().find( '[rel = "row-'+$i+'"]' ).find( 'td:first' ).nextUntil( '.thispo' ).css( {'background':'#f2b7b2'} );
			}
		}
	}
	//alert( $table.children().find( '[rel = "row-1"]' ).html() );
	//$table.children().attr( 'reel' );
	//$( '#cal .thiss' ).nextUntil( '.thispo' ).css( {'background':'#f2b7b2'} );
	//$( '#cal .thispo' ).prevUntil( '.thiss' ).css( {'background':'#f2b7b2'} );
}
// Удаление фонов и классов
function clearBg(){
	$( '#cal .yeahh' ).css( {'background':'none'} );
	$( '#cal .curday-cal' ).css( {'background':'#ffffff'} );
	if( $( '#cal .thiss' ).children().html() )
		$( '#cal .thiss' ).children().css( {'background':'#ffffff'} );
	$( '#cal .yeahh' ).removeClass( 'thiss thispo' );
}
// Установка даты с
function setDates( $date ){
	$( '#days' ).val( $date );
}
// Установка даты по
function setDatepo( $date ){
	$( '#daypo' ).val( $date );
}
// Вычисление даты
function getDate( $obj ){
	if ( $obj.children().html() ){
		if( $obj.children().children().html() ){
			$obj.children().css( {'background':'#f2b7b2'} );
			return $obj.children().children().html();
		} else {
			$obj.children().css( {'background':'#f2b7b2'} );
			$obj.css( {'background':'#f2b7b2'} );
			return $obj.children().html()*1;
		}
	} else {
		$obj.css( {'background':'#f2b7b2'} );
		return $obj.html();
	}
}
function getDateTwo( $obj ){
	if ( $obj.children().html() ){
		if( $obj.children().children().html() ){
			//$obj.children().css( {'background':'#f2b7b2'} );
			return $obj.children().children().html();
		} else {
			//$obj.children().css( {'background':'#f2b7b2'} );
			//$obj.css( {'background':'#f2b7b2'} );
			return $obj.children().html()*1;
		}
	} else {
		//$obj.css( {'background':'#f2b7b2'} );
		return $obj.html().trim();
	}
}


