<!--

$(document).ready(function () {
    
    // setup nav
    mainmenu();

});

function mainmenu() {

    // setup main nav
    $(" #nav ul ").css({ display: "none" }); // Opera Fix
    $(" #nav li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show();
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });

    // setup my.instantasp menu
    $(" #myinstantasp ul ").css({ display: "none" }); // Opera Fix
    $(" #myinstantasp li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show();
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}

/* ------------------------ */
// sign up form
/* ------------------------ */

function signUp(domain) {

    // validation
    var txtName = $("#txtName");
    var txtEmail = $("#txtEmail");

    if (txtEmail.length) {
        if (txtEmail.val() == '' ||txtEmail.val().indexOf("@") == -1 ||txtEmail.val().indexOf(".") == -1 ) {
            alert("You must provide a valid email address!");
            return false;
        }
    }

    // dim background
    $("#bgDimmer").css('opacity', 0.6)
    $("#bgDimmer").css("height", $(document).height());
    $("#bgDimmer").show();

    // do callback
    var url = domain + 'callbacks.aspx?a=guide&n=' + txtName.val().replace(' ', '') + '&e=' + txtEmail.val().replace(' ', '')
    $.get(url, null, function (data) {
        var items = data.getElementsByTagName("result");
        if (items.length > 0) {
            for (var i = 0; i < items.length; i++) {
                var nd = items[i];
                // get result
                var identity = nd.getAttribute("identity") == null ? 0 : nd.getAttribute("identity");
                // was everything ok
                if (identity == -1) {
                    alert("The email address you provided is not valid!");
                    $("#bgDimmer").hide();
                 } else {
                    $("#bgDimmer").hide();
                    $("#thankyou").slideDown("fast");
                }

            }
        }

    });






}

/* ------------------------ */
// modal popups
/* ------------------------ */

popup = new Object();

function PopUp(divid) {

    this.divid = divid;

    if (popup[divid] != null) {
        return popup[divid];
    } else {
    popup[divid] = this;
    }
    return this;

}

PopUp.prototype.initialize = function() {

    var divid = "#" + this.divid;
    var popupStatus = 0;

    jQuery(document).ready(function() {

        // center popup
        centerPopup(divid)
        
        // show popup
        showPopup(divid)

        // add event handler to close popup
        $('#CloseWindow').click(function() {
            hidePopup(divid);
        });

        // close menus on escape key
        $(document).keydown(function (e) {
            var keyCode = getKeyCode(e);
            var esc = (window.event) ? 27 : e.DOM_VK_ESCAPE // MSIE : Firefox
            if (e.keyCode == esc) {
                hidePopup(divid);
                return false;
            }
        });


        // close menus on escape key
        $("#bgDimmer").click(function (e) {
             hidePopup(divid);       
        });
         
    });

    //Adjust height of overlay to fill screen when browser gets resized

    $(window).bind("resize", function() {

        centerPopup(divid);        
        $("#fuzz").css("height", $(window).height());

    });

    $(window).scroll(function() {

        centerPopup(divid);
        $("#bgDimmer").css("height", $(window).height());
        $("#bgDimmer").css("top", document.documentElement.scrollTop);

    });

    function showPopup(divid) {

        if (popupStatus == 0) {

            // dim background
            $("#bgDimmer").css('opacity', 0.6)
            $("#bgDimmer").css("height", $(document).height());
            $("#bgDimmer").show();

            // show popup
            $(divid).show();
            popupStatus = 1;
        }
    }

    function hidePopup(divid) {

        if (popupStatus == 1) {
            
            if (ply != null) {
                ply.stop()
            }

            $("#bgDimmer").hide();
            $(divid).hide();
            popupStatus = 0;

        }

    }

    function getKeyCode(e) {

        if (document.all) {

            if (e != null) {
                return e.keyCode;
            } else {
                if (window.event) {
                    return event.keyCode;
                }
            }

        }
        else if (e.which) {
            return e.which;
        }
    }

    function centerPopup(divid) {

        var popupHeight = $(divid).height();
        var popupWidth = $(divid).width();
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;

        if (document.body.scrollTop > 0) {
            windowHeight = document.body.scrollTop;
        } else {
            windowHeight += document.documentElement.scrollTop * 2;
        }

        $(divid).css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2,
            "left": windowWidth / 2 - popupWidth / 2
        });


    }


}


/* forum helpers */

function iasp_logOut() {

    // disable body
    iasp_disableBody();

    if (confirm("Are you sure you wish to logout?\n\nWhen you logout if you have chosen\nautomated login your cookie will be deleted.\n\nClick OK to confirm this action...")) {
        return true;
    }
    else {
        // enable body if cancel
        iasp_enableBody();
        return false;
    }

}


