﻿function joinBloggersBaseNow() {
    $.ajax({
        type: "POST",
        processData: false,
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
            xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        },
        contentType: "application/x-www-form-urlencoded; charset=utf-8",
        url: "http://local.bloggersbase.com/global/join_now.ashx",
        data: "email=" + escape($("#joinEmailTxt").val()),
        dataType: "html",
        success: function(html) {
            showResponseMessage(html);
        }
    });
}

function showResponseMessage(html) {
    var div = htmlToDocumentFragment(html);
    $("#" + div.id).remove();
    $("body").append(div);
    div = $("#" + div.id);

    div.css("left", (document.documentElement.clientWidth - div.width()) / 2);
    div.css("top", ((document.documentElement.clientHeight - div.height()) / 2 + document.documentElement.scrollTop));
    div.css({ 'display': '', 'position': 'absolute' });
    div.animate({ opacity: 0.0 }, 5000, "swing");
}

function htmlToDocumentFragment(htmlString) {
    var tempDiv = document.createElement('div');
    tempDiv.innerHTML = htmlString;
    if (tempDiv.childNodes.length == 1) {
        return tempDiv.firstChild;
    } else {
        var fragment = document.createDocumentFragment();
        while (tempDiv.firstChild) {
            fragment.appendChild(tempDiv.firstChild);
        }
        return fragment;
    }
}

function switchNavBarTab(tabsContainerId, currentTabCssId, originalTab, menuContainerId) {
    var currTab = null;
    var children = $("#" + tabsContainerId).children();
    children.each(function() {
        var obj = $(this);
        obj.attr("id", "");
        var tabString = obj.attr("name");
        if (tabString == originalTab) {
            currTab = obj;
        }
    });
    currTab.attr("id", currentTabCssId);

    var menuContainer = $("#" + menuContainerId);
    for (var i = 0; i < children.length/*not menuContainer.childNodes.length !!!*/; ++i) {
        var child = menuContainer.children()[i];
        child = $(child);
        if (child.attr("name") == originalTab) {
            child.attr("class", "navClass " + child.attr("class"));
            child.css("display", "");
        } else {
            child.attr("class", child.attr("class").replace("navClass ", ""));
            child.css("display", "none");
        }
    }
}