
function displayContact()
{
    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');
                initContact();
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width()}, 600, function()
            {
                initContact();
            });
        }
    }
    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');
                    initContact();
                });
            });
        }
        else
        {
            $('#content').animate({'margin-left':$(window).width(), 'opacity':'0'}, 600, function()
            {
                initContact();
            });
        }
    }
}

function initContact()
{
    var HTML = '<div id="contact-address"></div>';
    HTML += '<form method="post" action="" onsubmit="return sendContactMessage()">';
    HTML += '<div class="input_container" style="margin:0;"><label id="label-contact-name" for="contact-name">'+CONTACT_NAME+' '+REQUIRED+'</label><input type="text" name="contact-name" id="contact-name" class="input_style" value="" /></div>';
    HTML += '<div class="input_container"><label id="label-contact-email" for="contact-email">'+CONTACT_EMAIL+' '+REQUIRED+'</label><input type="text" name="contact-email" id="contact-email" class="input_style" value="" /></div>';
    HTML += '<div class="input_container"><label id="label-contact-message" for="contact-message">'+CONTACT_MESSAGE+' '+REQUIRED+'</label><textarea name="contact-message" id="contact-message" rows="" cols="" class="textarea_style" style="width:350px;"></textarea></div>';
    HTML += '<div class="input_container">';
    HTML += '<input type="submit" name="contact-submit" id="contact-submit" class="submit_style" value="'+CONTACT_SEND+'" />';
    HTML += '&nbsp;&nbsp;&nbsp;<input type="button" name="reset" id="reset" class="submit_style" onclick="resetContact()" value="'+RESET+'" />';
    HTML += '&nbsp;&nbsp;&nbsp;<span class="form-info" id="contact-info"></span>';
    HTML += '</div>';
    HTML += '</form>';
    HTML += '<div id="contact-address">';
    HTML += '</div>';

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

        RPContent();

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

function sendContactMessage()
{
    var ok = true;

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

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

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

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

    if (ok)
    {
        disableContactForm(true);

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


    return false;
}

function disableContactForm(val)
{
    $('#contact-name').attr('disabled', val);
    $('#contact-email').attr('disabled', val);
    $('#contact-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);
}

function resetContact()
{
    $('#label-contact-name').html(CONTACT_NAME+' '+REQUIRED);
    $('#label-contact-name').removeClass('error');
    $('#contact-name').val('');
    $('#label-contact-email').html(CONTACT_EMAIL+' '+REQUIRED);
    $('#label-contact-email').removeClass('error');
    $('#contact-email').val('');
    $('#label-contact-message').html(CONTACT_MESSAGE+' '+REQUIRED);
    $('#label-contact-message').removeClass('error');
    $('#contact-message').val('');
}
