jQuery(document).ready(function() {
    botchat(true);
    var flashmovie = jQuery('#gaddie_swf');
    if (flashmovie.length != 0) {
        jQuery('#gaddie_swf').flash({
            swf: '/swf/Ms Gadie10.swf',
            height: 65,
            width: 57,
            wmode: 'transparent'
        });
    }
});
function botchat(firstLoad) {
    jQuery.post("/botchat/ajax/ajax.botchat.php", jQuery("#chatform").serialize(),
                function(data) {
                    var botResponse = "";
                    var botChatbox = data.formchat;
                    if (data.response != "") {
                        if (data.usersaid != null) {
                            botResponse = botResponse + "<div class=\"demouser\">You: " + data.usersaid + "</div>";
                            botResponse = botResponse + "<div class=\"demobot\">Ms. Gaddie: " + data.biganswer + "</div>"
                        }
                        jQuery('div#main_gaddie_chat').append(botResponse);
                        jQuery("div#main_gaddie_chat").animate({ scrollTop: jQuery("div#main_gaddie_chat").attr("scrollHeight") }, 3000);
                    }
                    if (typeof (botChatbox) != "undefined" && botChatbox != "") {
                        jQuery('div#main_gaddie_chatbox').html(botChatbox);
                        var lblASK = jQuery('span#lblASK').html();
                        var elSubmit = jQuery('div#main_gaddie_chatbox #chatform input[name=submit]').val(lblASK);
                        jQuery(elSubmit).click(function() {
                            botchat(false);
                            return false;
                        });
                    }
                    if (!firstLoad) jQuery('div#main_gaddie_chatbox #chatform input[name=chat]').val('').focus();
                }, "json");
}
