/*new function () {
  var debug    = true;
  var original = window.console;
  window.console = {};
  ['log', 'dir', 'warn', 'info', 'err'].forEach(function (method) {
    console[method] = function () {
      return (debug && original) ? original[method].apply(original, arguments) : null;
    }
  });
};*/

var timer;
var sendEmail;
$(document).ready(function() {
	var

	slideId,
	slideCurrent = 0,
	slideFeature = [
		{
			img 	: 'slide-feature-img1',
			navi	: 'slide-feature-navi1'
		},
		{
			img 	: 'slide-feature-img2',
			navi	: 'slide-feature-navi2'
		},
		{
			img 	: 'slide-feature-img3',
			navi	: 'slide-feature-navi3'
		}
	];


	jQuery.each( slideFeature, function( i, val) {
		var feature = this;
		$('#' + this.navi ).hover( function() {
			clearInterval( slideId );
			slideCurrent = i;
			$('.slide-navigation div').attr('class', 'slide-navigation-item');
			$('#' + feature.navi ).attr('class', 'slide-navigation-item-active');
			$('.sf-image').css({display: 'none'});
			$('#' + feature.img ).css({display: 'block'});
		}, function() {
			slideId = intervalTrigger();
		});
		$('#' + this.img ).hover( function() {
			clearInterval( slideId );
		}, function() {
			slideId = intervalTrigger();
		});

		slideFeature[i]['href'] = $('#' + this.navi ).attr('data-url');

		$('#' + this.navi ).click( function() {
			window.location = feature.href;
		});

		$('#' + this.img ).click( function() {
			window.location = feature.href;
		});
	});

	function slideTimer() {
		var slideTo = ( (slideCurrent + 1) == slideFeature.length) ? 0 : (slideCurrent + 1);
		$('.slide-navigation div').attr('class', 'slide-navigation-item');
		$('#' + slideFeature[slideTo].navi ).attr('class', 'slide-navigation-item-active');
		$('.sf-image').css({display: 'none'});
		$('#' + slideFeature[slideTo].img ).css({display: 'block'});
		slideCurrent = slideTo;
	}

	function intervalTrigger() {
		return setInterval( slideTimer, 3000 );
	}

	function fixShadowHeight() {
		var
			winHeight,
			bodyHeight,
			height;

		bodyHeight = $('body').innerHeight();
		winHeight = (document.documentElement.clientHeight || document.body.clientHeight);
		height = ( winHeight > bodyHeight ) ? winHeight : bodyHeight;

		$('.shadow').css({height: (height + 25) + 'px'});
	}

	if ($('#categorySelect')) {
		$('#categorySelect').change( function(e) {
			e.preventDefault();
			var path = window.location.href.split('/');

                        //by Atorian;
			if ($(this).val() != '0') {
                                var url = '/' + (path[3] ? (path[3] + '/') : '') + 'category/' + $(this).val();
                                url += $('#currentGroupSelect').val() !== undefined ? '/group/' + $('#currentGroupSelect').val() + '/' : '';
				window.location.href = url;
			} else {
                                var url = '/' + (path[3] ? path[3] + '/' : '/');
                                url += $('#currentGroupSelect').val() !== undefined ? '/group/' + $('#currentGroupSelect').val() + '/' : '';
				window.location.href = url;//by Atorian + 'group/' + $('#currentGroupSelect').val() + '/';
			}
                        // end by Atorian
			return false;
		});
	}
	if ($('.activityGroupsList_a')) {
            $('.activityGroupsList_a').click(function(e){
			e.preventDefault();
			var path = window.location.href.split('/');
			if ($(this).val() != '0') {
				window.location.href = '/' + (path[3] ? (path[3] + '/') : '') + 'group/' + $(this).attr('id') + '/category/' + $('#currentCategorySelect').val() + '/';
			} else {
				window.location.href = '/' + (path[3] ? path[3] + '/' : '/') + 'category/' + $('#currentCategorySelect').val() + '/';
			}
			return false;
            });
        }
	if ($('#groupSelect')) {
		$('#groupSelect').change( function(e) {
			e.preventDefault();
			var path = window.location.href.split('/');
			if ($(this).val() != '0') {
				window.location.href = '/' + (path[3] ? (path[3] + '/') : '') + 'group/' + $(this).val() + '/category/' + $('#currentCategorySelect').val() + '/';
			} else {
				window.location.href = '/' + (path[3] ? path[3] + '/' : '/') + 'category/' + $('#currentCategorySelect').val() + '/';
			}
			return false;
		});
	}


	if ($('#authorSelect')) {
		$('#authorSelect').change( function(e) {
			e.preventDefault();
			var path = window.location.href.split('/');
			if ($(this).val() != '') {
				window.location.href = '/' + (path[3] ? (path[3] + '/') : '') + 'author/' + $(this).val() + '/';
			} else {
				window.location.href = '/' + (path[3] ? path[3] + '/' : '/');
			}
			return false;
		});
	}

	slideId = intervalTrigger();

	var closePopUp = function () {
		$($('.smart-popup-close').attr('data-popup')).css({display: 'none'});
		$('.shadow').css({display: 'none'});
		$('#popup-login-auth').css({display: 'block'});
		$('.popup-login-clink').css({display: 'block'});
		$('#popup-login-register').css({display: 'none'});
		$('#popup-login-auth .popup-activity-login-signup-request').css({display: 'none'});
		$('#popup-login-auth .popup-login-signup-brief.login').css({display: 'none'});
		$('#popup-send-mail').css({display: 'none'});
		$('#popup-login-auth .popup-login-signup-request').css({display: 'block'});
		$('#popup-send-mail').css({display: 'none'});
		$('#popup-print-cert').css({display: 'none'});
		$('#popup-login-add-registration-info').css({display: 'none'});
		$('.popup-login-clink .color-loading').css({display: 'none'});
		$('.popup-login-clink .smart-link-submit').css({display: 'inline'});
		$('.popup-login-clink .color-link').css({display: 'inline'});
		return false;
	}

	$('.smart-field').focus( function() {
		if(!$(this).attr('data-changed')) {
			if($(this).attr("value") == $(this).attr('data-default-value')) {
				$(this).attr({value: ""});
				$(this).removeAttr('style');
			}
		}
	});

	$('.smart-field').blur( function() {
		if($(this).attr("value") == "") {
			$(this).attr({value: $(this).attr('data-default-value')});
			$(this).css({color: "#aaa"});
		}
	});

	$('.smart-field').change( function() {
		$(this).attr({'data-changed': 1});
	});

	$('.smart-form').submit( function() {
		jQuery.each( $('.smart-field', this), function() {
			if(!$(this).attr('data-changed')) {
				if( $(this).attr('value') == $(this).attr('data-default-value') ) {
					$(this).attr({value: ""});
				}
			}
		});
		return true;
	});

	jQuery.each( $('.smart-field'), function() {
		if( $(this).attr('value') == "") {
			$(this).attr({value: $(this).attr('data-default-value')});
			$(this).css({color: "#aaa"});
		}
	});

	$('.popup-login-tw-signin').click(function() {
		$('#popup-login-register').css({display: 'none'});
		$('#popup-login-auth').css({display: 'block'});
		return false;
	});

	$('.popup-login-tw-signup').click(function() {
		$('#popup-login-register').css({display: 'block'});
		$('#popup-login-auth').css({display: 'none'});
		return false;
	});

	//login show\hide
	$('.smart-popup-open').click( function() {
		fixShadowHeight();
		$('#popup-login').css({display: 'block'});
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$('#popup-login-register').css({display: 'none'});
		$('#popup-login-auth').css({display: 'block'});
		$($(this).attr('data-popup')).css({display: 'block'});
		return false;
	});
        
        $('.smart-popup-open-reg').click( function() {
		fixShadowHeight();
		$('#popup-login').css({display: 'none'});
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$('#popup-login-register').css({display: 'block'});
		$('#popup-login-auth').css({display: 'none'});
		$($(this).attr('data-popup')).css({display: 'block'});
		return false;
	});

	$('.smart-popup-close').click( function() {
		closePopUp();
		return false;
	});

	//close popup-login by Esc
	$(document).keydown( function(e){
		if (e == null) { // ie
			keycode = event.keyCode;
		} else { // mozilla
			keycode = e.which;
		}
		if(keycode == 27){
			closePopUp();
		}
	});

	$('.smart-popup-join').click( function(){
		fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$(document).scrollTop(0);
		$('#popup-login').css({display: 'block'});
		$('#popup-login-register').css({display: 'block'});
		$('#popup-login-auth').css({display: 'none'});
		return false;
	});

	$('.smart-popup-signin').click( function() {
		fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$(document).scrollTop(0);
		$('#popup-login').css({display: 'block'});
		$('#popup-login-register').css({display: 'none'});
		$('#popup-login-auth').css({display: 'block'});
		return false;
	});

	$('.popup-login-signin-request .popup-login-clink').click( function() {
		$('.popup-login-signin-request').submit();
	});

	//login ajax
	$('.popup-login-signin-request').submit( function () {
		$('.popup-login-signin-request .popup-login-clink .color-link').css({display: 'none'});
		$('.popup-login-signin-error').css({visibility: 'hidden'});
		$('.popup-login-signin-request .popup-login-clink .color-loading').css({display: 'inline'});
        $.post($(this).attr('data-ajax'), $('.popup-login-signin-request').serializeArray(), function( data ){
			if (data && data.result == 'true') {
				window.location.href = window.location.href;
			    //window.location.reload(true);
			} else {
                $('.popup-login-signin-error').css({visibility: 'visible'});
				$('.popup-login-signin-request .popup-login-clink .color-link').css({display: 'inline'});
				$('.popup-login-signin-request .popup-login-clink .color-loading').css({display: 'none'});
			}
		}, 'json');
		return false;
	});

	$('.smart-link-submit').click( function() {
		$( $(this).attr('data-form')).submit();
		return false;
	});

	$('.inline-comment-block-showhide a').click( function() {
		$(this).parent().next().slideToggle("fast");
		return false;
	});

	$('.custom-bluesolid-signup .signup-input').focus( function() {
		$('.custom-bluesolid-signup .signup-input').attr({value: ''});
	});
	$('.custom-bluesolid-signup  .signup-input').blur( function() {
		if ($('.custom-bluesolid-signup .signup-input').attr('value') == '') {
			$('.custom-bluesolid-signup .signup-input').attr({value: 'E-mail'});
		}
	});

	//signup ajax
	$('.custom-bluesolid-signup').submit( function () {
		$.post($(this).attr('data-ajax'), $(this).serializeArray(), function( data ) {
				if (data && data.message != '') {
					$('.signup-input').attr({value: data.message});
					if (data.success == 'true') {
						$('.custom-bluesolid-signup').css({display: 'none'});
						$('.signup-complete').css({display: 'block'});
					}
				}
		}, 'json');
		return false;
	});

	function shortRegEmail() {
		var email = $(".short-reg-email").val();
		var checkMail = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

		if (checkMail.test(email)) {
			$('.massage-to-user').css({display: 'block'});
			if(typeof timer != 'undefined'){
				clearTimeout(timer);
			}
			if(typeof sendEmail != 'undefined') {
				sendEmail.abort();
			}
			timer = setTimeout(function(){
					sendEmail = $.ajax({
						type: "POST",
						url: $('.short-reg-email').attr("data-ajax"),
						data: {email: email},
						success: function(data){
							var result = $.parseJSON(data);
							if (result.result == false) {
									$('.save_or_reg').text('Create an account');
									$('.save_or_reg_button').removeAttr('disabled');
									$('.save-or-reg-submit').removeAttr('disabled');
									$('.disable-button').css({display: 'none'});
									$('.massage-to-user').css({display: 'none'});
									$('.enable-button').css({display: 'block'});
								} else {
									$('.save_or_reg').text('Save');
									$('.save_or_reg_button').removeAttr('disabled');
									$('.save-or-reg-submit').removeAttr('disabled');
									$('.disable-button').css({display: 'none'});
									$('.massage-to-user').css({display: 'none'});
									$('.enable-button').css({display: 'block'});
							}
						}
					});
				}, 100);
		} else {
			$('.save_or_reg_button').attr('disabled', 'disabled');
			$('.save-or-reg-submit').attr('disabled', 'disabled');
			$('.enable-button').css({display: 'none'});
			$('.disable-button').css({display: 'block'});
		}
	}

	//short reg

	$('.short-reg-email').keyup(shortRegEmail);
	$('.short-reg-email').bind('paste', function (){shortRegEmail});

	//register ajax
	$('.popup-login-register-form').submit( function () {
		$('#popup-login-register .color-link').css({display: 'none'});
        $('#popup-login-register .color-link .smart-link-submit.refresh').parent().css({display: 'inline'});
		$('#popup-login-register .color-loading').css({display: 'inline'});
		$.post($(this).attr('data-ajax'), $(this).serializeArray(), function( data ) {
				$('#popup-login-register .color-link').css({display: 'inline'});
				$('#popup-login-register .color-loading').css({display: 'none'});
				if ( data.response ) {
					$('.popup-login #popup-login-register .popup-login-register-form').html( data.response );
                    $('#refreshCode').click( function() {
                        $('#kaptchaCode').attr({src:'/kaptcha.php?' + Math.random(0, 1000000000)});
                        return false;
                    });
				}
				if ( data.registrationComplete ) {
					$('.popup-login-clink').css({display: 'none'});
					window.location.href = window.location.href;
					//window.location.reload(true);
				}
		}, 'json');
		return false;
	});
	/*!Small register
	 *
	 */
	$('.popup-activity-login-signup-request.smart-link-submit').click( function() {
		$( $(this).attr('data-form')).submit();
		return false;
	});

	$('.popup-login-short-register-form').submit( function () {
		$('.popup-activity-login-signup-request .color-link').css({display: 'none'});
		$('.popup-activity-login-signup-request .color-loading').css({display: 'inline'});
        //var acknowForm = $('#xx-acknowledge-form').serializeArray();
		$.post($('#activity-register-short').attr('data-ajax'), $(this).serializeArray(), function( data ) {
				$('.popup-login-short-register-form.color-link').css({display: 'inline'});
				$('.popup-login-short-register-form.color-loading').css({display: 'none'});
				//cleare errors
				jQuery.each($('#popup-login-auth .popup-login-short-register-form .popup-login-register-error'), function() {
					$(this).html('');
				});
				if (data.errors) {
					for (var i in data.errors) {
						$('#popup-login-auth .popup-login-short-register-form .popup-login-register-error.'+i).html(data.errors[i]);
					}
				}
				if (data.result == 'false') {
					$('#popup-login-auth .popup-activity-login-signup-request .popup-login-signup-brief.continue').css({display: 'block'});
					$('#popup-login-auth .popup-activity-login-signup-request .popup-login-signup-brief').css({display: 'none'});
					$('#popup-login-auth .popup-activity-login-signup-request .popup-login-short-register-form').css({display: 'none'});
					$('#popup-login-auth .popup-activity-login-signup-request .popup-login-clink').css({display: 'none'});
					$('#popup-login-auth .popup-activity-login-signup-request .popup-login-signup-brief.continue').html('Some error happened. Please, try login with Your E-mail');
				}
				if (data.result == 'true') {
					window.location.href = data.reload;
				}

				$('.popup-activity-login-signup-request .color-link').css({display: 'inline'});
				$('.popup-activity-login-signup-request .color-loading').css({display: 'none'});
		}, 'json');
		return false;
	});

	$('.inline-comment-addcomment').submit( function() {
		var parrentForm = this;
		$('.inline-comment-error', parrentForm).css({display: 'none'});
		$('.inline-comment-success', parrentForm).css({display: 'none'});
		$('.color-link', parrentForm).css({display: 'none'});
		$('.color-loading', parrentForm).css({display: 'inline'});
		$.post( $(this).attr('data-ajax'), $(this).serializeArray(), function( data ){
			if( data.error ) {
				$('.inline-comment-error', parrentForm).html(data.error);
				$('.inline-comment-error', parrentForm).css({display: 'block'});
			}
			else {
				$('.inline-comment-success', parrentForm).css({display: 'block'});
				$('textarea', parrentForm).attr({value: ''});
			}
			$('.color-link', parrentForm).css({display: 'inline'});
			$('.color-loading', parrentForm).css({display: 'none'});
		}, 'json');
		return false;
	});

	$('select[name=journals]').change( function() { // journals
			if($(this).attr('value')!=''){
				window.open($(this).attr('value'));
			}
	});
    $('#pupmed-search-select').change( function() {
			if($(this).attr('value')!=''){
				window.open($(this).attr('value'));
			}
	});

    $('#pupmed-search-select-button').attr('disabled','disabled');

    $('#pupmed-search-select-field').keyup(function() {
        if ($(this).val() != "") {
            $('#pupmed-search-select-button').removeAttr('disabled');
        } else {
            $('#pupmed-search-select-button').attr('disabled','disabled');
        }
    });

    $('#pupmed-search-select-field').keydown(function(e) {
        if (e.keyCode==13) {
            $('#pupmed-search-select-button').click();
        }
    });

    $('#pupmed-search-select-button').click( function() {
			if($('#pupmed-search-select-field').val()!=''){
				window.open('http://www.ncbi.nlm.nih.gov/sites/entrez?cmd=Search&amp;db=pubmed&amp;term=' + $('#pupmed-search-select-field').attr('value'));
			}
	});
    

    

	$('#add-activity-question-button').click( function(){
		if ($('#header').find('.username').length == 0) {console.log('gdf');
			fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		var html = '<div style="display: block;" class="remember_email">' +
				'Log-in or leave your email in order to get the answer to your question' +
				'<div class="email-input">' +
					'E-mail:' +
					'<input class="email" type="text" autocomplete="OFF" name="email" value="">' +
				'</div>' +
				'<p class="botton ok">[ <a href="#">continue</a> ]</p>' +
				'<p class="botton cancel">[ <a href="#">close</a> ]</p>' +
			   '</div>';
		$('body').append(html);	
		return false;
		} else {
			$('#add-activity-question-form').submit();
			return false;
		}
	});
	
	$('.remember_email .botton').live('click', function () {
		$('.shadow').css({display: 'none'});
		$('.remember_email').css({display: 'none'});
	});
	
	$('.remember_email .ok').live ('click', function () {
		var email = $('.remember_email .email').val();
		$('#question-iput').attr({'value': $('#question-iput').attr('value') + ' (User email - ' + email + ')'});
		$('#add-activity-question-form').submit();
		return false;
	})

	$('#add-activity-question-form').submit( function() {
		if ($('#question-iput').attr('value') != '') {
			$('#add-activity-sending-button').css({display: 'inline'});
			$('#add-activity-question-button').css({display: 'none'});
			$.post($(this).attr('data-ajax'), $('#add-activity-question-form').serializeArray(), function( response ){
				if (response && response.result == 'true') {
					$('#question-iput').attr({'value': 'Your question has now been submitted and will be reviewed by the presenter.'});
				}
				$('#add-activity-question-button').css({display: 'inline'});
				$('#add-activity-sending-button').css({display: 'none'});
			}, 'json');
		}
		return false;
	});

	$('#add-activity-question').click( function() {
		show_hide('#add-activity-question-form-body');
		return false;
	});

	show_hide = function( element_id ) {
		if ($(element_id).css('display') == 'none') {
			$(element_id).show('slow');
			$('#question-iput').attr({'value': ''});
			$('#add-activity-question-button').css({display: 'block'});
			$('#sending-question').css({display: 'none'});
			return false;
		} else {
			$(element_id).hide('slow');
			return false;
		}
	}

	$('.save_button, .save-popup-link').click(function() {
			fixShadowHeight();
			$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
			$('.save_or_reg_block').css({display: 'block'});
			//$('.save_button').css({display: 'none'});
			return false;
	});

	$('.smart-save-or-reg-close').click(function() {
		$('.shadow').css({display: 'none'});
		$('.save_or_reg_block').css({display: 'none'});
		//$('.save_button').css({display: 'block'});
		$('.short-reg-email').val('');
		$('.enable-button').css({display: 'none'});
		$('.disable-button').css({display: 'block'});
		return false;
	});

	$('a.save-or-reg-submit').click(function() {
		return false;
	});

	$('#activity-register-short').click( function() {
		if($('#begin-eula').is(':checked')){
			fixShadowHeight();
			$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
			$(document).scrollTop(0);
			$('#popup-login').css({display: 'block'});
			$('#popup-login-register').css({display: 'none'});
			$('#popup-login-auth .popup-activity-login-signup-request').css({display: 'block'});
			$('#popup-login-auth .popup-login-signup-request').css({display: 'none'});
			$('#popup-login-auth .popup-login-signup-brief.login').css({display: 'block'});
			$('#popup-send-mail').css({display: 'none'});
			$('#nochecked_alert').css({display: 'none'});
		} else {
			$('#nochecked_alert').css({display: 'block'});
		}
		return false;
	});

	$('#userSaveActivity').click( function(){
		jQuery.post($('#userSaveActivity').attr('data-ajax'), null, function(response) {
				if (response.success == 'true') {
					$('#userSaveActivity').html('Saved');
				}
			},
			'json'
		);
		return false;
	});

	$('#userEmailActivity').click( function(){
		fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$(document).scrollTop(0);
		$('#popup-login').css({display: 'block'});
		if ($('#popup-login-register')) $('#popup-login-register').css({display: 'none'});
		if ($('#popup-login-auth')) $('#popup-login-auth').css({display: 'none'});
		$('#popup-send-mail').css({display: 'block'});
		return false;
	});

	$('#popup-send-mail .smart-link-submit').click(function() {
		$('#popup-send-mail .smart-link-submit').css({display: 'none'});
		$('#popup-send-mail .color-loading').css({display: 'inline'});
		jQuery.post($('#userEmailActivity').attr('data-ajax'), $('#popup-send-mail .popup-send-mail-form').serializeArray(), function( response ) {
			$('#popup-send-mail .smart-link-submit').css({display: 'inline'});
			$('#popup-send-mail .color-loading').css({display: 'none'});
			jQuery.each($('#popup-login .popup-send-mail-form .popup-login-register-error'), function() {
				$(this).html('');
			});
			if (response.success == 'true') {
				$('#popup-login').css({display: 'none'});
				$('.shadow').css({display: 'none'});
				$('#popup-send-mail .popup-send-mail-form')[0].reset();
			} else {
				if (response.success == 'false' && response.errors) {
					for (var i in response.errors) {
						$('#popup-login .popup-send-mail-form .popup-login-register-error.'+i).html(response.errors[i]);
					}
				}
			}
		}, 'json'
		);
		return false;
	});

	if ($('.showCertClick')) {
		jQuery.each($('.showCertClick'), function() {
			$(this).click( function() {
				if ($(this).attr('data-ajax')) {
					window.open($(this).attr('data-ajax'));
				}
				return false;
			});
		});
	}

	$('#deleteSavedActivity').click( function() {
		if ($('#deleteSavedActivity').attr('data-ajax')) {
			jQuery.post($('#deleteSavedActivity').attr('data-ajax'), null, function(response) {
					if (response.success = 'true') {
						$('.xx-mediaapp-list.xx-mediaapp-min .xx-mediaapp-list-item.'+response.id).remove();
					}
				},
				'json'
			);
		}
		return false;
	});

	completeRegistration = function() {
		fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$(document).scrollTop(0);
		$('#popup-login').css({display: 'block'});
		if ($('#popup-login-register')) $('#popup-login-register').css({display: 'none'});
		if ($('#popup-login-auth')) $('#popup-login-auth').css({display: 'none'});
		$('#popup-login-add-registration-info').css({display: 'block'});
	}

	$('#popup-login-add-registration-info .popup-login-add-reg-info-form').submit(function(){
		$('#popup-login-add-registration-info .color-link').css({display: 'none'});
		$('#popup-login-add-registration-info .color-loading').css({display: 'inline'});
        var data = $('#continueRegister').attr('ajax-continue');
        if (!data) {
            data = $('#popup-login-add-registration-info .popup-login-add-reg-info-form').attr('data-ajax');
        }
		$.post(data, $(this).serializeArray(), function( data ) {
				$('#popup-login-add-registration-info .color-link').css({display: 'inline'});
				$('#popup-login-add-registration-info .color-loading').css({display: 'none'});
				if ( data.response ) {
					$('#popup-login-add-registration-info .popup-login-add-reg-info-form').html( data.response );
				}
				if ( data.registrationComplete ) {
					$('.popup-login-clink').css({display: 'none'});
				}
				if ( data.result == 'true') {
					window.location.href = data.reload;
				}
		}, 'json');
		return false;
	});

	$('#continueRegister').click(function() {
		if ($('#continueRegister').attr('data-ajax')) {
			jQuery.post($('#continueRegister').attr('data-ajax'), $('#postQuestionnaireForm').serializeArray(), function( response ) {
				if (response.success == 'true' ) {
					jQuery.each($('#postQuestionnaireForm .xx-fieldset'), function() {
						$(this).removeClass('xx-fieldset-fail');
						$(this).addClass('xx-fieldset');
					});
					completeRegistration();
				} else {
					if (response.errors) {
						jQuery.each($('#postQuestionnaireForm .xx-fieldset'), function() {
							$(this).removeClass('xx-fieldset-fail');
							$(this).addClass('xx-fieldset');
						});
						for(var i in response.errors) {
							$('#postQuestionnaireForm .xx-fieldset.' + i).addClass('xx-fieldset-fail');
						}
					}
				}
			}, 'json');
		} else {
			completeRegistration();
		}
		return false;
	});

	$('#refreshCode').click( function() {
		$('#kaptchaCode').attr({src:'/kaptcha.php?' + Math.random(0, 1000000000)});
		return false;
	});
	$('.no-video-in-this-category .login-click').click( function() {
		fixShadowHeight();
		$('.shadow').css({display: 'block', opacity: 0.6, 'top':0});
		$('#popup-login').css({display: 'block'});
		$('#popup-login-register').css({display: 'none'});
		$('#popup-login-auth').css({display: 'block'});
		$($(this).attr('data-popup')).css({display: 'block'});
		return false;
	});

    // --------------------------------------------------------
    // SF
    // Poll form submit
    $('#pollOnMainForm input[type="radio"]').click(function() {
        $("#content .readerPoll form .submit").removeClass('disabled');
    });

	$('#pollOnMainForm').submit(function() {
        if (!$("#content .readerPoll form .submit").hasClass('disabled')) {
            $("#content .readerPoll form .submit").css('visibility','hidden');
            $("#loadingSpinner").show();
            jQuery.post($('#pollOnMainForm').attr('data-ajax'), $('#pollOnMainForm').serializeArray(), function( response ) {
                if (response.success == 'true') {
                    $('#pollOnMain').html(response.html);

                } else {
                }
            }, 'json'
            );
        }
        return false;
	});
    // --------------------------------------------------------

	$('.xx-beginactivity-form').submit(function() {
		if(!$('#begin-eula').is(':checked')) {
			$('#nochecked_alert').show();
			return false;
		}
		return true;
	});

    //console.log('habr');
});

