function savePetSalute()
{
    var userStatuses = '';
    var filterUserStatus = new Array();
    filterUserStatus[0] = 'friend';
    filterUserStatus[1] = 'sobesed';
    filterUserStatus[2] = 'guest';
    for (i=0; i<filterUserStatus.length; i++) {
        if ($('#salute_' + filterUserStatus[i]).attr('checked') == true) {
            userStatuses += filterUserStatus[i] + ',';
        }
    }
    if (userStatuses == '') {
        alert("Не заполнен фильтр показов.");
        return false;
    }
    if (!$('#saluteTextId').val()) {
        $('#saluteFormFields').hide();
        alert("Не заполнен текст приветсвия.");
        $('#saluteFormFields').show();
        $('#saluteTextId').focus();
        return false;
    }
    var user_sex = $('#salute_user_sex').val();
    var my_city = $('#salute_my_city').val();
    var saluteText = $('#saluteTextId').val();
    var saluteId = $('#salute_id').val();
    $('#saluteButton').attr('disabled', true);
    $.post('/pet/salute/savesalute/?ajax=true', {'ajax':true, 'userStatuses':userStatuses, 'user_sex' : user_sex, 'my_city' : my_city, 'saluteText' : saluteText, 'salute_id':saluteId}, function(data) {
        popup.winContent.html(data);
    });
}
function openSaluteWindow(petId) {
    $.post('/pet/salute/?ajax=true', {'petId' : petId}, function(data) {
        popup.simple(data, {title:'Навык «Приветсвия»', width:600});
    });
}
function editSalute(saluteId) {
    $.post('/pet/salute/?ajax=true', {'editSaluteId':saluteId}, function(data) {
        popup.winContent.html(data);
    });
}
function cancelSaluteEdit() {
    openSaluteWindow(petId);
}
function deleteSalute(saluteId) {
    popup.confirm("Удалить данное приветсвие?", function() {
        $.post('/pet/salute/?ajax=true', {'deleteSaluteId':saluteId}, function(data) {
            openSaluteWindow(petId);
        });
    }, function() {
            openSaluteWindow(petId);
    });
}

function openSecretaryWindow(tab, petId) {
    $.post('/pet/secretary/?ajax=true', {'tabName' : tab, 'petId' : petId},function(data) {
        popup.simple(data, {title:'Навык «Секретарь»', width:600});
    });
}

function setWaiting(userId, petId) {
    $('#answerResultId').html("<img src='"+staticDomain+"/images/ajax-transparent.gif' />");
    $('#answerResultTmpId').load('/pet/secretary/setwaiting/?ajax=true', {'userId' : userId, 'petId': petId},
        function (data) {
            if(data == 'ok') {
                $('#answerResultId').html("Хорошо, я обязательно сообщу!");
            } else {
                $('#answerResultId').html("Ты уже говорил, что ждёшь.");
            }
            setTimeout("$('#petPhraseBlock').fadeOut(100);", 2000);
        }
    );
}
function clearWaiting(petId) {
    $('#secretaryWaiting').hide('slow');
    $.get('/pet/secretary/clearwaiting/?ajax=true', {'petId': petId});
}

function openSkillGuestWindow(petId) {
    $.post('/pet/guestnew/options/?ajax=true', {'petId': petId}, function(data) {
        popup.simple(data, {title:'Навык «Поход в гости»', width:600});
    });
}

function openTellerWindow(tab, petId) {
    $.post('/pet/teller/?ajax=true', {'petId': petId}, function(data) {
        popup.simple(data, {title:'Навык «Предсказатель»', width:600});
    });
}

function openQuestionWindow(tab, petId) {
    $.post('/pet/quiz/question/?ajax=true', {'tabName': tab, 'petId': petId}, function(data) {
        popup.simple(data, {title:'Навык «Опроса»', width:560, tabs:true});
    });
}
function setPetAnswer(val, petId) {
    $('#answerResultId').html("<img src='"+staticDomain+"/images/ajax-transparent.gif' />");
    $('#answerResultTmpId').load('/pet/quiz/setanswer/?ajax=true', {'answerVal' : val, 'petId': petId},
        function (data) {
            if(data == 'ok') {
                $('#answerResultId').html("Твой ответ отправлен.");
            } else {
                $('#answerResultId').html("Ты уже отвечал на вопрос.");
            }
            setTimeout("$('#petPhraseBlock').fadeOut(100);", 2000);
        }
    );
}