
function displayGuestbook()
{
    clearClick = false;
    if (isIE)
    {
        if ($('#content').css('display') == 'none')
        {
            $('#home-text').stop(true, true).animate({'opacity':'1'}, 600, function(){$('#home-text').css('display', 'none');});
            $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
            {
                $('#news').css('display', 'none');
                $('#content').css('display', 'block');
                initGuestbook();
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width()}, 600, function()
            {
                initGuestbook();
            });
        }
    }
    else
    {
        if ($('#content').css('display') == 'none')
        {
            $('#content').stop(true, true).animate({'opacity':'0'}, 0,  function()
            {
                $('#home-text').stop(true, true).animate({'opacity':'1'}, 600, function(){$('#home-text').css('display', 'none');});
                $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
                {
                    $('#news').css('display', 'none');
                    $('#content').css('display', 'block');
                    initGuestbook();
                });
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width(), 'opacity':'0'}, 600, function()
            {
                initGuestbook();
            });
        }
    }
}

function initGuestbook()
{
    var HTML = '<input type="submit" name="guestbook-submit" id="guestbook-submit" class="submit_style" onclick="displayGuestbookForm()" value="'+GUESTBOOK_WRITE_A_MESSAGE+'" />';
    initPageType1();
    $('#content-scroll-content').html('');

    $('#content-loader').css('display', 'block');
    $.post('includes/php/guestbook.php', {action:'load'}, function(data)
    {
        $('#content-loader').css('display', 'none');
        $('#content-fix').css('display', 'block');
        $('#content-fix').css('height', 'auto');
        $('#content-scroll').css('display', 'block');
        $('#content-fix').html(HTML);
        $('#content-scroll-content').html(data);

        RPContent();

        if (isIE) clearClick = true;
        else $('#content').stop(true, true).animate({'opacity':'1'}, 300, function(){clearClick = true;});
    });
}

function displayGuestbookForm()
{
    currentPage = 'guestbookForm';
    clearClick = false;
    if (isIE)
    {
        if ($('#content').css('display') == 'none')
        {
            $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
            {
                $('#news').css('display', 'none');
                $('#content').css('display', 'block');
                initGuestbookForm();
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width()}, 600, function()
            {
                initGuestbookForm();
            });
        }
    }
    else
    {
        if ($('#content').css('display') == 'none')
        {
            $('#content').stop(true, true).animate({'opacity':'0'}, 0,  function()
            {
                $('#news').stop(true, true).animate({'margin-top':$(window).height()}, 600, function()
                {
                    $('#news').css('display', 'none');
                    $('#content').css('display', 'block');
                    initGuestbookForm();
                });
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width(), 'opacity':'0'}, 600, function()
            {
                initGuestbookForm();
            });
        }
    }
}

function initGuestbookForm()
{
    var HTML = '<form method="post" action="" onsubmit="return sendGuestbookMessage()">';
    HTML += '<div class="input_container" style="margin:0;"><label id="label-guestbook-name" for="guestbook-name">'+GUESTBOOK_NAME+' '+REQUIRED+'</label><input type="text" name="guestbook-name" id="guestbook-name" class="input_style" value="" /></div>';
    HTML += '<div class="input_container"><label id="label-guestbook-email" for="guestbook-email">'+GUESTBOOK_EMAIL+' '+REQUIRED+'</label><input type="text" name="guestbook-email" id="guestbook-email" class="input_style" value="" /></div>';
    HTML += '<div class="input_container"><label id="label-guestbook-message" for="guestbook-message">'+GUESTBOOK_MESSAGE+' '+REQUIRED+'</label><textarea name="guestbook-message" id="guestbook-message" rows="" cols="" class="textarea_style"></textarea></div>';
    HTML += '<div class="input_container">';
    HTML += '<input type="submit" name="guestbook-submit" id="guestbook-submit" class="submit_style" value="'+GUESTBOOK_POST+'" />';
    HTML += '&nbsp;&nbsp;&nbsp;<input type="button" name="reset" id="reset" class="submit_style" onclick="resetGuestbook()" value="'+RESET+'" />';
    HTML += '&nbsp;&nbsp;&nbsp;<input type="button" name="back" id="back" class="submit_style" onclick="displayGuestbook()" value="'+BACK+'" />';
    HTML += '&nbsp;&nbsp;&nbsp;<span class="form-info" id="guestbook-info"></span>';
    HTML += '</div>';
    HTML += '</form>';
    
    initPageType1();

    $('#content-fix').html(HTML);
    $('#content-fix').css('display', 'block');
    $('#content-fix').css('height', 'auto');
    $('#content-scroll').css('display', 'none');

    RPContent();

    if (isIE) clearClick = true;
    else
    {
        setTimeout(function()
        {
            $('#content').stop(true, true).animate({'opacity':'1'}, 300, function(){clearClick = true;});
        }, 1);
    }
}

function sendGuestbookMessage()
{
    var ok = true;

    if ($('#guestbook-name').val() == '')
    {
        ok = false;
        $('#label-guestbook-name').addClass('error');
        $('#label-guestbook-name').html(GUESTBOOK_NAME_BLANK);
    }

    if ($('#guestbook-email').val() == '')
    {
        ok = false;
        $('#label-guestbook-email').addClass('error');
        $('#label-guestbook-email').html(GUESTBOOK_EMAIL_BLANK);
    }

    if ($('#guestbook-email').val() != '' && !validEmail($('#guestbook-email').val()))
    {
        ok = false;
        $('#label-guestbook-email').addClass('error');
        $('#label-guestbook-email').html(GUESTBOOK_EMAIL_INVALID);
    }

    if ($('#guestbook-message').val() == '')
    {
        ok = false;
        $('#label-guestbook-message').addClass('error');
        $('#label-guestbook-message').html(GUESTBOOK_MESSAGE_BLANK);
    }

    if (ok)
    {
        disableGuestbookForm(true);

        $.post('includes/php/guestbook.php', {action:'save', name:$('#guestbook-name').val(), email:$('#guestbook-email').val(), message:$('#guestbook-message').val()}, function(data)
        {
            disableGuestbookForm(false);
            resetGuestbook();
            $('#guestbook-info').html('<span id="guestbook-info-text">'+GUESTBOOK_POST_SUCCESS+'</span>');
            setTimeout(function()
            {
                $('#guestbook-info-text').stop(true, true).animate({'opacity':'0'}, 1000, function()
                {
                    $('#guestbook-info').html('');
                });
            }, 4000);
        });
    }
                

    return false;
}

function disableGuestbookForm(val)
{
    $('#guestbook-name').attr('disabled', val);
    $('#guestbook-email').attr('disabled', val);
    $('#guestbook-message').attr('disabled', val);
    if (val) $('.submit_style').css('cursor', 'default');
    else $('.submit_style').css('cursor', 'pointer');
    $('#submit').attr('disabled', val);
    $('#reset').attr('disabled', val);
    $('#back').attr('disabled', val);
}

function resetGuestbook()
{
    $('#label-guestbook-name').html(GUESTBOOK_NAME+' '+REQUIRED);
    $('#label-guestbook-name').removeClass('error');
    $('#guestbook-name').val('');
    $('#label-guestbook-email').html(GUESTBOOK_EMAIL+' '+REQUIRED);
    $('#label-guestbook-email').removeClass('error');
    $('#guestbook-email').val('');
    $('#label-guestbook-message').html(GUESTBOOK_MESSAGE+' '+REQUIRED);
    $('#label-guestbook-message').removeClass('error');
    $('#guestbook-message').val('');
}
