function authorization(ret_path) {
	if (document.getElementById("toplayer")) {
		var loadingDiv = document.getElementById("toplayer");
		if (loadingDiv.style.display == "block") {
			loadingDiv.style.display = "none";
            _$('error_msg_dop').style.display = "none";
            _$("qip_user_login_dop").value = '';
            _$("qip_user_password_dop").value = '';
			if (navigator.userAgent.indexOf('MSIE 6') != -1 || navigator.userAgent.indexOf('MSIE 5') != -1) {
				document.body.style.backgroundImage = "";
				document.body.style.backgroundAttachment = "";
			}
		}
		else {
			loadingDiv.style.display = "block";
            _$('qip_user_login_dop').focus();
            if(ret_path){
                _$('toplayer_ret_path').value = ret_path;
            }
			if (navigator.userAgent.indexOf('MSIE 6') != -1 || navigator.userAgent.indexOf('MSIE 5') != -1) {
				document.body.style.backgroundImage = loadingDiv ? "url(/;-)/n.gif)" : "";
				document.body.style.backgroundAttachment = loadingDiv ? 'fixed' : "";
			}
		}
	}
}

function close_toplayer(){
	if (document.getElementById("toplayer")) {
		var loadingDiv = document.getElementById("toplayer");
		if (loadingDiv.style.display == "block") {
			loadingDiv.style.display = "none";
            _$('loading').style.display = 'none';
            $('#toplayer form').resetForm();
            $('#toplayer #submit').removeClass().attr('disabled','disabled').show();
            $('.poll-options input, .poll-options br').removeAttr('disabled').show();
            $('.poll-options .poll-results').hide();
            $('#toplayer #close-window-block').hide();
            $('#toplayer .login').css('top','35%');
            clearTimeout(count_down_timer);
			if (navigator.userAgent.indexOf('MSIE 6') != -1 || navigator.userAgent.indexOf('MSIE 5') != -1) {
				document.body.style.backgroundImage = "";
				document.body.style.backgroundAttachment = "";
			}
		}
	}
}

function show_toplayer(){
	if (document.getElementById("toplayer")) {
		var loadingDiv = document.getElementById("toplayer");
		if (loadingDiv.style.display == "none") {
			loadingDiv.style.display = "block";
            _$('loading').style.display = 'none';
			if (navigator.userAgent.indexOf('MSIE 6') != -1 || navigator.userAgent.indexOf('MSIE 5') != -1) {
				document.body.style.backgroundImage = loadingDiv ? "url(/;-)/n.gif)" : "";
				document.body.style.backgroundAttachment = loadingDiv ? 'fixed' : "";
			}
		}
	}
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function send_vote(f)
{
    var v = getCheckedValue(f.answer1);
    if (v == '') return false;
    $.getJSON(
        '/external/aeterna_poll.php', 
        {
            vote: v,
            action: f.action.value,
            poll_id: f.poll_id.value   
        },        
        function (response) {}
    );   
}

function show_poll_results(){
    $('#toplayer #submit').hide();
    $('.poll-options input, .poll-options br').hide();
    $('.poll-options .poll-results').show();
    _$('loading').style.display = 'none';
    $('#toplayer .login').css('top','30%');
}

function submit_form(f)
{
    _$('loading').style.display = 'block';
    $('#toplayer #submit').hide();
    //$('.poll-options input').attr('disabled','disabled');
    $(document).ready(function() {
        $(f).ajaxSubmit({
            url: '/external/aeterna_poll.php',
            type: 'post',
            resetForm: true,
            success: function(response){
                show_poll_results();
                $('#poll_link').empty().append('Результаты опроса')
                .unbind().click(function(){
                    show_toplayer(); show_poll_results(); return false;
                });
                var seconds = 5;
                $('#toplayer #countdown').empty().html(seconds);
                $('#toplayer #close-window-block').show();
                countDown(seconds);
            }
        });
    });
    
    return false;
}

count_down_timer = false;

function countDown(secs) {
  if (secs < 0) {
    close_toplayer();
    return;
  }
  $('#countdown').empty().html(secs);
  count_down_timer = setTimeout("countDown(" + (secs-1) + ")", 1000);
}

