﻿//hook up events

$(document).ready(function() {


    $("#anchAddDisplayName").click(function() {

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divCreateDisplayName' });
    });


    $("#anchAddDisplayNameNewTopic").click(function() {

        $.facebox.settings.opacity = 0.35;
        $.facebox({ elementName: 'divCreateDisplayName' });
    });



    $("#frmCreateDisplayName").submit(function() {
        var isValid = true;


        if (GetIfBlankAndAttachErrorMessage('txtDisplayname', 'Please enter a display name.'))
            isValid = false;



        if (isValid) {
            //            location.reload(true);
            $.post($(this).attr("action"), $(this).serialize(), function(response) { //post using ajax
                if (response == "used") {
                    $("#spanUsed").show();
                    $("#spanUsed").attr("style", "color:Red");
                    $("#spanSwear").hide();
                }
                else if (response == "swearword") {
                    $("#spanSwear").show();
                    $("#spanSwear").attr("style", "color:Red");
                    $("#spanUsed").hide();
                }
                else {
                    //alert("aaa");
                    if (response == "addcomment") {
                        location.reload(true);
                    }
                    if (response == "addtopic") {
                        location.href = "/Family-Add-New-Message/";
                    }
                }
                //location.href = "";//response;
            });
        };

        return false;


    });


});



