﻿$(function() {

    function navigated(hash) {
        if (hash == 'send') {
            $('#content .text').hide();
            $('#create-form').hide();
            $('#support-send-form').show();
        } else {
            $('#content .text').show();
            $('#create-form').show();
            $('#support-send-form').hide();
        }
    }
    $.historyInit(navigated, document.location.toString());

    $('#create-form').validate({
        submitHandler: function(form) {
            $(form).ajaxSubmit({
                success: function(message) {
                    $.historyLoad('send');
                    $('#support-send-form textarea').val(message);
                    $('#support-send-form input[name=emailAddress]').val($('#create-form input[name=emailAddress]').val());
                    $('#support-send-form input[name=inform]').val($('#create-form input[name=inform]').is(':checked') ? 'True' : 'False');
                }
            });
        }
    });

    $('#support-send-form').ajaxForm({
        success: function() {
            $('#support-send-form').hide();
            $('#support-sent').show();
        }
    });

    $('#support-go-back').click(function() {
        window.history.go(-1);
        return false;
    });


});