﻿var alertBoxChangeTimeout;

function alertBoxDisplayNextMessage() {
    /// <summary>Rotates current Alert Box message to the next message in the cycle and displays it.</summary>
    alertBoxCurrentMessage++;
    if (alertBoxCurrentMessage >= alertBoxMessages.length) {
        alertBoxCurrentMessage = 0;
    }

    if (alertBoxMessages.length == 1) {
        alertBoxShowMessage();
    }
    else if (alertBoxMessages.length > 1) {
        if ($("#AlertBoxContent").html() != "") {
            alertBoxHideMessage(alertBoxShowMessage);
        }
        else {
            alertBoxShowMessage();
        }
    }

    if (alertBoxMessages.length > 1 && alertBoxChangeTimeout == null) {
        alertBoxChangeTimeout = setInterval("alertBoxDisplayNextMessage();", 8 * 1000);
    }
}

function alertBoxHideMessage(callbackFunction) {
    /// <summary>Hides message currently in Alert Box and optionally calls another function when complete.</summary>
    /// <param name='callbackFunction' type='Function'>Optional.  Function to call when hiding is complete.</param>
    if (callbackFunction == null) {
        $("#AlertBoxContent").hide("slow");
    }
    else {
        $("#AlertBoxContent").hide("slow", callbackFunction);
    }
}

function alertBoxShowMessage() {
    /// <summary>Shows the current message in the Alert Box.</summary>
    $("#AlertBoxContent").html(alertBoxMessages[alertBoxCurrentMessage]);
    if (alertBoxMessages.length > 1) {
        $("#AlertBoxCount").html("(" + (alertBoxCurrentMessage + 1) + " of " + alertBoxMessages.length + ")");
    }
    $("#AlertBoxContent").show("slow");
}

function alertBoxShow() {
    /// <summary>Sets display=block to all DOM components of the AlertBox.</summary>
    var alertBoxComponents = new Array("Div", "TitleBar", "Title", "Count", "ContentHolder", "Content");
    for (var i = 0; i < alertBoxComponents.length; i++) {
        $("#AlertBox" + alertBoxComponents[i]).show();
    }
    $("#AlertBoxDiv").corner();
    $("#AlertBoxContentHolder").corner();
}

function confirmExternlaURL() {
    var confirmed = confirm("Please note, you are being directed to BorderTraffic.com, which is not part of the SANDAG 511 system. Proceed?");
    return confirmed;
}
