/// <reference path="jQuery/1.3.2/jquery-vsdoc.js" />
/// <reference path="jQuery/plugins/jqModal.js" />
/// <reference path="jQuery/plugins/blockui.2.18.js" />

/*
* Auction Anything common javascript library
* @requires jQuery v1.3.2 or later
* Copyright (c) 2011 Auction Anything, LLC
*/

/*********************************************/
/* Namespace for all code in here            */
/*********************************************/
var AA = {};

AA.Base = {};
AA.Base.Root = function () {
    if (document.getElementById("U_Home")) {
        return jQuery("#U_Home").val();
    }
    else {
        return "/";
    }
};

/*********************************************/
/*  User Details                             */
/*********************************************/
AA.User = {
    "Mask" : 0, 
    "Name" : "", 
    "AN" : 0, 
    "TimeAdjust" : 0, 
    "Mode" : "DEV" 
};
jQuery(document).ready(function () {
    AA.User.Mask = (document.getElementById("U_Mask")) ? Number(jQuery("#U_Mask").val()) : 0;
    AA.User.Name = jQuery("#U_Name").val();
    AA.User.AN = jQuery("#U_AN").val();
    AA.User.TimeAdjust = jQuery("#U_TimeAdjust").val();
    AA.User.Mode = jQuery("#U_Mode").val();
});
AA.User.Is = function (msk) {
    msk = msk || 0;
    if (msk == 0) {
        return false;
    }
    else {
        return (AA.User.Mask & msk) > 0;
    }
};

/*********************************************/
/*  Enumerations                             */
/*********************************************/
AA.TriState = {
    "False": 0,
    "True": -1,
    "Default": -2
};
AA.Status = {
    "None": 0,
    "Active": 1,
    "InActive": 2,
    "Pending": 4,
    "Deleted": 64,
    "Error": 128,
    "Sent": 256,
    "UserDefined": 512,
    "Created": 1024,
    "Posted": 2048,
    "Complete": 4096,
    "GeneratedXML": 8192,
    "Blocked": 16384
};

/*********************************************/
/*  Formatting                               */
/*********************************************/
AA.Format = {};
AA.Format.Currency = function(amount) {
    ///<summary>Formats a currency value</summary>
    var i = parseFloat(amount);
    if (isNaN(i)) { i = 0.00; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    i = parseInt((i + 0.005) * 100, 10);
    i = i / 100;
    var s = '' + i;
    if (s.indexOf('.') < 0) { s += '.00'; }
    if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
    s = minus + s;
    return s;
};
AA.Format.Comma = function(amount) {
    ///<summary>Comma formatted value</summary>
    var delimiter = ",";
    var a, d, i;
    amount = '' + amount;
    a = amount.split('.', 2);
    d = a[1];
    i = parseInt(a[0], 10);
    if (isNaN(i)) { return ''; }
    var minus = '';
    if (i < 0) { minus = '-'; }
    i = Math.abs(i);
    var n = '' + i;
    a = [];
    while (n.length > 3) {
        var nn = n.substr(n.length - 3);
        a.unshift(nn);
        n = n.substr(0, n.length - 3);
    }
    if (n.length > 0) { a.unshift(n); }
    n = a.join(delimiter);
    if (d.length < 1) { amount = n; }
    else { amount = n + '.' + d; }
    amount = minus + amount;
    return amount;
};

//#Region " AA.Date: Date Utilities "
AA.Date = {};
AA.Date.AddDays = function(thisDate, days) {
    ///<summary>Add Days to a Date</summary>
    return new Date(thisDate.getTime() + days * 24 * 60 * 60 * 1000);
};
AA.Date.Add = function(thisDate, type, amount) {
    ///<summary>Add time to a Date</summary>
    var multiplier = 0;
    switch (type.toLowerCase()) {
        case "day": case "d":
            multiplier = 24 * 60 * 60 * 1000;
            break;
        case "hour": case "hr": case "h":
            multiplier = 60 * 60 * 1000;
            break;
        case "minute": case "min": case "m":
            multiplier = 60 * 1000;
            break;
        case "second": case "sec": case "s":
            multiplier = 1000;
            break;
        default:
            break;
    }
    return new Date(thisDate.getTime() + (amount * multiplier));
};
AA.Date.Diff = function(date1, date2, type) {
    var dt1 = new Date(date1);
    var dt2 = new Date(date2);
    if (isNaN(dt1) || isNaN(dt2)) {
        return 0;
    }
    else {
        var milliseconds = Math.abs(dt1.getTime() - dt2.getTime());
        switch (type.toLowerCase()) {
            case "day": case "d":
                return (milliseconds / (24 * 60 * 60 * 1000));
                break;
            case "hour": case "hr": case "h":
                return (milliseconds / (60 * 60 * 1000));
                break;
            case "minute": case "min": case "m":
                return (milliseconds / (60 * 1000));
                break;
            case "second": case "sec": case "s":
                return (milliseconds / 1000);
                break;
            default:
                return milliseconds;
                break;
        }
    }
};
AA.Date.DaysInMonth = function(month, year) {
    ///<summary>Gets the # of days in a month</summary>
    ///<param name="month" type="Object" optional="false">Month of Date</param>
    ///<param name="year" type="Object" optional="false">Year of Date</param>
    var x = new Array(31, ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
    return x[month];
};
AA.Date.IsValid = function(input) {
    ///<summary>Checks a Date for Validity</summary>
    ///<param name="input" type="String" optional="false">Value to Check</param>
    var validformat = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
    if (!validformat.test(input)) {
        return false;
    }
    else {
        var monthfield = input.split("/")[0]; var dayfield = input.split("/")[1]; var yearfield = input.split("/")[2];
        var dayobj = new Date(yearfield, monthfield - 1, dayfield);
        return (((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield)) == false);
    }
};
AA.Date.SetPreset = function (drp, StartBox, EndBox) {
    ///<summary>Set a date range</summary>
    ///<param name="drp" type="Object" optional="false">jQuery object that is the dropdown</param>
    ///<param name="StartBox" type="Object" optional="false">jQuery object that is the start date</param>
    ///<param name="EndBox" type="Object" optional="false">jQuery object that is the end date</param>
    var start = '', end = '';
    var opt = jQuery(drp).val();
    switch (opt) {
        case "TDY":                     // Today
            start = new Date();
            end = start;
            break;
        case "YSD":                     // Yesterday
            start = new Date();
            start = AA.Date.AddDays(start, -1);
            end = start;
            break;
        case "TMR":                     // Tomorrow
            start = new Date();
            AA.Console.Log("Tomorrow for: " + start);
            start = AA.Date.AddDays(start, 1);
            end = start;
            break;
        case "WTD":                     // Week to Date
            end = new Date();
            start = (end.getDay() == 1) ? start = end : AA.Date.AddDays(end, (-1 * (end.getDay() - 1)));
            break;
        case "TW":                      // This Week
            end = new Date();
            start = (end.getDay() == 1) ? start = end : AA.Date.AddDays(end, (-1 * (end.getDay() - 1)));
            start = AA.Date.AddDays(start, -1);
            end = AA.Date.AddDays(start, 6);
            break;
        case "NW":                      // Next week
            end = new Date();
            start = (end.getDay() == 1) ? start = end : AA.Date.AddDays(end, (-1 * (end.getDay() - 1)));
            start = AA.Date.AddDays(start, 6);
            end = AA.Date.AddDays(start, 6);
            break;
        case "LW":                      // Last week
            end = new Date();
            start = (end.getDay() == 1) ? start = end : AA.Date.AddDays(end, (-1 * (end.getDay() - 1)));
            start = AA.Date.AddDays(start, -8);
            end = AA.Date.AddDays(start, 6);
            break;
        case "TM":                      // This Month
            start = new Date();
            start = new Date(start.getFullYear(), start.getMonth(), 1);
            end = AA.Date.DaysInMonth(start.getMonth(), start.getFullYear());
            end = new Date(start.getFullYear(), start.getMonth(), end);
            break;
        case "LM":                      // Last Month
            start = new Date();
            start = new Date(start.getFullYear(), (start.getMonth() - 1), 1);
            end = AA.Date.DaysInMonth(start.getMonth(), start.getFullYear());
            end = new Date(start.getFullYear(), start.getMonth(), end);
            break;
        case "LTD":
            end = new Date();
            start = AA.Date.AddDays(end, -30);
            break;
        case "LSD":
            end = new Date();
            start = AA.Date.AddDays(end, -60);
            break;
        case "LND":
            end = new Date();
            start = AA.Date.AddDays(end, -90);
            break;
        default:
            start = new Date();
            end = start;
    }
    jQuery(StartBox).val(AA.Date.Format(start));
    jQuery(EndBox).val(AA.Date.Format(end));
    AA.Console.Log("Date Presents for '" + opt + "': '" + jQuery(StartBox).val() + "' and '" + jQuery(EndBox).val() + "'");
};
AA.Date.Format = function(dt) {
    ///<summary>Formats as MM/DD/YYYY</summary>
    dt = dt || new Date();
    return AA.Text.Pad(dt.getMonth() + 1, "00") + "/" + AA.Text.Pad(dt.getDate(), "00") + "/" + dt.getFullYear();
};
AA.Date.ToNumber = function(thisDate) {
    ///<summaryConverts a date to YYYYMMDDHHMMSS</summary>
    var dt = new Date(thisDate);
    if (isNaN(dt)) { return "00000000000000"; }
    var arr = [];
    arr.push("" + dt.getFullYear());
    arr.push(AA.Text.Pad(dt.getMonth() + 1, "00"));
    arr.push(AA.Text.Pad(dt.getDate(), "00"));
    arr.push(AA.Text.Pad(dt.getHours(), "00"));
    arr.push(AA.Text.Pad(dt.getMinutes(), "00"));
    arr.push(AA.Text.Pad(dt.getSeconds(), "00"));
    return arr.join("");
};
AA.Date.FromJSON = function (thisDate) {
    if (thisDate.length < 7) { return ""; }
    var dt = new Date(parseInt(thisDate.substr(6)));
    var arr = [];
    arr.push(AA.Text.Pad(dt.getMonth() + 1, "00"));
    arr.push("/" + AA.Text.Pad(dt.getDate(), "00"));
    arr.push("/" + dt.getFullYear());
    arr.push(" ");
    var AP;
    if (dt.getHours() > 12) {
        AP = "PM";
        arr.push(AA.Text.Pad((dt.getHours() - 12), "00"));
    }
    else {
        AP = (dt.getHours() == 12) ? "PM" : "AM";
        arr.push(AA.Text.Pad(dt.getHours(), "00"));
    }
    arr.push(":" + AA.Text.Pad(dt.getMinutes(), "00"));
    arr.push(":" + AA.Text.Pad(dt.getSeconds(), "00"));
    arr.push(" " + AP);
    return arr.join("");
};
//#End Region


//#Region "AA.Text : Text Utilities "
AA.Text = {};
AA.Text.Inner = function(cntrl) {
    ///<summary>Gets the inner text of a DOM node</summary>
    if (typeof cntrl.textContent != 'undefined') { return cntrl.textContent; } else { return cntrl.innerText; };
};
AA.Text.Left = function(str, n){
    ///<summary>Left characters of a string</summary>
    if (n <= 0) { return ''; } else if (n > String(str).length) { return str; } else { return String(str).substring(0, n); };
};
AA.Text.Right = function(str, n) {
    ///<summary>Right characters of a string</summary>
    if (n <= 0) { return ''; } else if (n > String(str).length) { return str; } else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); };
};
AA.Text.EscapeHtml = function(txt) {
    ///<summary>Escapes the HTML of a given string</summary>
    var div = document.createElement("div");
    var text = document.createTextNode(txt);
    div.appendChild(text);
    return div.innerHTML;
};
AA.Text.Pad = function(str, pad) {
    ///<summary>Pads a given string</summary>
    if (pad == undefined) { pad = "00"; }
    str = "" + pad + str;
    return AA.Text.Right(str, pad.length);
};
//#End Region


//#Region "AA.Utils : General Utilities "
AA.Utils = {};
AA.Utils.Message = function (obj, txt, icon) {
    ///<summary>Decorates a div tag for user output</summary>
    ///<param name="obj" type="Object" optional="false">Element to generate</param>
    ///<param name="txt" type="String" optional="true">Message Text</param>
    ///<param name="icon" type="String" optional="true">Icon to use</param>
    jQuery(obj).each(function () {
        txt = txt || '';
        icon = icon || '';
        if (txt == '') {
            jQuery(this).empty().hide();
            return;
        }
        if (icon == '') {
            jQuery(this).css("background-image", "").css("padding-left", "4px");
        }
        else {
            var ext = ".png";
            if (icon.endsWith(".gif")) { ext = "" } else if (icon.beginsWith("indicator")) { ext = ".gif" };
            if (icon.beginsWith("http")) {
                jQuery(this).css("background-image", "url(" + icon + ")").css("background-repeat", "no-repeat").css("background-position", "left center").css("padding-left", "20px");
            }
            else {
                jQuery(this).css("background-image", "url(/images_srv/icons/" + icon + ext + ")").css("background-repeat", "no-repeat").css("background-position", "left center").css("padding-left", "20px");
            }
        }
        jQuery(this).html(txt).show();
    });
};
AA.Utils.Confirm = function(div, text, btnCancel, btnApprove) {
    jQuery(div).dialog({
        bgiframe: true,
        resizable: false,
        height: 140,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            'btnApprove': function() {
                alert("You clicked Approve");
                jQuery(this).dialog('close');
            },
            Cancel: function() {
                jQuery(this).dialog('close');
            }
        }
    });
};
AA.Utils.GetQueryVariable = function(key, val) {
    ///<summary>Retrieves a value from the Query String</summary>
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split('=');
        if (pair[0].toLowerCase() == key.toLowerCase()) {
            return pair[1];
        }
    }
    return (val) ? val : "";
};
AA.Utils.ButtonHover = function() {
    ///<summary>Wires up all buttons for UI theming</summary>
    jQuery(".ui-state-default").hover(
        function() {
            jQuery(this).addClass("ui-state-hover");
        }, 
        function() {
            jQuery(this).removeClass("ui-state-hover");
        }
    );
};
AA.Utils.SizeSelects = function(parent) {
    var MaxWidth = 0;
    var $selects = jQuery(parent).find("select");
    $selects.each(function() {
        if (jQuery(this).width() > MaxWidth) { MaxWidth = jQuery(this).width(); }
    });
    if (MaxWidth > 0) {
        MaxWidth = MaxWidth + 12;
        $selects.each(function() {
            jQuery(this).width(MaxWidth);
        });
    }
};
AA.Utils.Growl = function(message, options) {
    ///<summary>Show a Growl Message</summary>
    ///<param name="message" type="String" optional="false">Message to show</param>
    ///<param name="options" type="Object" optional="true">Options Params: title, icon, timeout, onBlock, onUnblock, centerX, centerY</param>
    var defaults = {
        title: null,
        icon: "process", 
        timeout: 3000,
        showOverlay: true,
        onUnblock: null,
        centerX: false,
        centerY: false
    };
    //Extend our default options with those provided.
    var opts = jQuery.extend(defaults, options);

    //Start the process of showing the message
    var $m = jQuery('<div class="growlUI" style="background-image: url(/images_srv/icons/64/' + opts.icon + '.png);"></div>');
    if (opts.title) { $m.append('<h1>' + opts.title + '</h1>'); }
    if (message) { $m.append('<h2>' + message + '</h2>'); }
    jQuery.unblockUI();  //Clear existing
    jQuery.blockUI({
        message: $m,
        fadeIn: 0,
        fadeOut: 1000,
        centerX: opts.centerX,
        centerY: opts.centerY,
        timeout: opts.timeout,
        showOverlay: opts.showOverlay,
        icon: opts.icon,
        onUnblock: opts.onUnblock,
        css: jQuery.blockUI.defaults.growlCSS
    });
};
AA.Utils.Error = {};
AA.Utils.Error.Set = function(desc, text) {
    desc = (desc == null || desc == undefined) ? "Undefined Error" : desc;
    text = (text == null || text == undefined) ? "Unspecified Error Details" : text;
    jQuery("#Error_Title").html("" + desc);
    jQuery("#Error_Content").html("" + text);
};
AA.Utils.Error.Open = function() {
    //jQuery("#Error_Window").jqmShow();
};
AA.Utils.DomainID = function() {
    var txt = "0";
    var $x = jQuery("#PN_Info:visible");
    if ($x.length == 1) {
        txt = $x.text().trim();
    }
    else {
        $x = jQuery("#DomainName_Search input");
        if ($x.length == 1) {
            txt = $x.val().trim();
        }
    }
    if (txt != "0") {
        var hit = txt.match(/^.+\((\d+)\)$/);
        if (hit && hit.length == 2) {
            txt = hit[1];
        }
        else {
            txt = "0";
        }
    }
    return txt;
}
AA.Utils.Window = {};
AA.Utils.Window.Width = function () {
    var viewportwidth = 0;
    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth;
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth;
    }
    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
    }
    return viewportwidth;
};
AA.Utils.Window.Height = function () {
    var viewportheight = 0;
    if (typeof window.innerWidth != 'undefined') {
        viewportheight = window.innerHeight;
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
        viewportheight = document.documentElement.clientHeight;
    }
    else {
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
    return viewportheight;
};
AA.Utils.Replace = function (orig, mtch, replac) {
    if (mtch == "" || mtch == replac) { return; }
    while (orig.indexOf(mtch) > -1) {
        orig = orig.replace(mtch, replac);
    };
    return orig;
};
AA.Utils.Stop = function (e) {
    ///<summary>Stops default event across all browswers</summary>
    ///<param name="e" type="Object" optional="true">Event Object</param>
    if (!e) {
        if (window.event) {
            e = window.event;
        }
        else {
            return;
        }
    }
    if (e.cancelBubble != null) { e.cancelBubble = true; }
    if (e.stopPropagation) { e.stopPropagation(); }
    if (e.preventDefault) { e.preventDefault(); }
    if (window.event) { e.returnValue = false; }
    if (e.cancel != null) { e.cancel = true; }
}         // StopEvent

jQuery(document).ready(function() {
    AA.Utils.ButtonHover();
});

//jQuery("#thing").delegate("click", {
//  ".quit": function() { /* do quit stuff */ },
//  ".edit": function() { /* do edit stuff */ }
//})
//http://www.danwebb.net/2008/2/8/event-delegation-made-easy-in-jquery
jQuery.fn.delegate = function(eventType, rules) {
    return this.bind(eventType, function(e) {
        var target = jQuery(e.target);
        for (var selector in rules) {
            if (target.is(selector)) { return rules[selector].apply(this, arguments); }
        };
    });
};
//#End Region


/*********************************************/
/*  Table Striping                           */
/*********************************************/
AA.Table = {};
AA.Table.StripeMouseOver = function(tbl, remove) {
    ///<summary>Stripes and applies mouseover class</summary>
    AA.Table.MouseOver(tbl, remove);
    AA.Table.Stripe(tbl, remove);
};
AA.Table.MouseOver = function(tbl, remove) {
    tbl = jQuery(tbl);
    if (remove) {
        tbl.find("tbody tr").unbind("mouseover");
    }
    else {
        tbl.find("tbody tr").mouseover(
            function() {
                jQuery(this).addClass("Over");
            }
        )
        .mouseout(
            function() {
                jQuery(this).removeClass("Over");
            }
        );
    }
};
AA.Table.Stripe = function(tbl, remove) {
    jQuery(tbl).find("tbody tr").removeClass("odd").filter(":even").addClass("odd");
};


/*********************************************/
/*  Ajax Calls and Utilities                 */
/*********************************************/
AA.Ajax = {};
AA.Ajax.Get = function (url, params, success, error, complete) {
    ///<summary>Make a JSON call</summary>
    ///<param name="url" type="String" optional="false">Url of handler to call</param>
    ///<param name="params" type="Object" optional="false">params to pass to handler, this event looks for ".Method" (GET/POST) as well</param>
    ///<param name="success" type="Object" optional="false">Event to call when complete</param>
    ///<param name="error" type="Object" optional="true">Event to call when an error is encountered</param>
    var CallParams = {};
    CallParams.dataType = params.dataType || "json";
    CallParams.processData = true;
    if (CallParams.dataType === "jsonp" || url.substr(0, 4) === "http") {
        AA.Console.Log("AA.Ajax.Get: forced to JSONp");
        CallParams.dataType = "json";
        CallParams.type = "POST";
        jQuery.each(params, function (k, v) {
            url = url + "&" + k + "=" + encodeURIComponent(v);
        });
        url = url + ((url.indexOf("?") < 0) ? "?" : "&") + "callback=?";
        AA.Console.Log("-- url: " + url);
        jQuery.extend(params, { "url" : url });
        AA.Ajax.Get(
            "/common_srv/Service/jsonp.ashx",
            params, 
            function (json) {
                if (success) { success(json); }
            },
            function (x, y, z) {
                if (error) { error(x, y, z); }
            },
            function (a, b) {
                if (complete) { complete(a, b); }
            }
        );
    }
    else {
        CallParams.type = params.Method || "POST";
        CallParams.url = url;
        CallParams.data = params;
        CallParams.success = success;
        if (error) { CallParams.error = error; }
        if (complete) { CallParams.complete = complete; }
        jQuery.ajax(CallParams);
    }
}
AA.Ajax.Error = function(x) {
    ///<summary>Shows .NET error message</summary>
    var msg = 'Unknown Error Encountered';
    var txt = (x && x.responseText) ? x.responseText : "Unknown error details";
    try {
        AA.Console.Log("Checking Permissions: " + AA.User.Mask + "/32");
        if ((AA.User.Mask & 32) > 0) {
            var s = x.responseText.indexOf("<title>") + 7;
            var t = x.responseText.indexOf("</title>");
            msg = x.responseText.substr(s, t - s);
            AA.Console.Log("Show actual error (" + s + " to " + t + "): " + msg);
            //AA.Utils.Error.Set(msg, txt);
        }
        else {
            AA.Console.Log("Show generic");
        }
    }
    catch (e) {
        //Leave it alone
    }
    return (msg == "") ? "Unknown error details" : msg;
}

/*********************************************/
/*  Prototypes that work against primitives  */
/*********************************************/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };
String.prototype.contains = function(t) { return this.indexOf(t) >= 0 ? true : false; };
String.prototype.beginsWith = function(t, i) { if (i == false) { return (t == this.substring(0, t.length)); } else { return (t.toLowerCase() == this.substring(0, t.length).toLowerCase()); } };
String.prototype.endsWith = function(t, i) { if (i == false) { return (t == this.substring(this.length - t.length)); } else { return (t.toLowerCase() == this.substring(this.length - t.length).toLowerCase()); } }

/*********************************************/
/*  Console based stuff                      */
/*********************************************/
AA.Console = {};
AA.Console.Enabled = false;
jQuery(document).ready(function() {
    AA.Console.Enabled = (document.getElementById("U_ConsoleEnabled") || AA.Utils.GetQueryVariable("EnableConsole") == "1") ? true : false;
    try {
        if (window['loadFirebugConsole']) {
            window.loadFirebugConsole();
        } else if (!window['console']) {
            window.console = {}; window.console.info = {}; window.console.log = {}; window.console.warn = {}; window.console.error = {}; window.console.debug = {};
        }
        if (AA.Console.Enabled) { AA.Console.Log("Console enabled by enviroment"); }
    }
    catch (e) {
        //ignore
    }
});
AA.Console.Log = function(txt) {
    ///<summary>Logs a string to console</summary>
    if (AA.Console.Enabled == false) { return; }
    try {
        if (txt == "") { txt = ' '; }
        console.log(txt);
    }
    catch (e) {
    }
};
AA.Console.Debug = function(txt) {
    ///<summary>Logs a debug message to console</summary>
    if (AA.Console.Enabled == false) { return; }
    try {
        if (txt == "") { txt = ' '; }
        console.debug(txt);
    }
    catch (e) {
    }
};
AA.Console.Info = function(txt) { 
    ///<summary>Logs an informative message to console</summary>
    if (AA.Console.Enabled == false) { return; }
    try {
        if (txt == "") { txt = ' '; }
        console.info(txt);
    }
    catch (e) {
    }
};
AA.Console.Warn = function(txt) { 
    ///<summary>Logs a warning to console</summary>
    if (AA.Console.Enabled == false) { return; }
    try {
        if (txt == "") { txt = ' '; }
        console.warn(txt);
    }
    catch (e) {
    }
};
AA.Console.Error = function(txt) { 
    ///<summary>Logs an Error to console</summary>
    if (AA.Console.Enabled == false) { return; }
    try {
        if (txt == "") { txt = ' '; }
        console.error(txt);
    }
    catch (e) {
    }
};


/**************************************************/
/*  Keep alive stuff to keep Tango cookie going   */
/**************************************************/
AA.Ping = {};
AA.Ping.Seconds = 240;
AA.Ping.Heartbeat = function (s) {
    AA.Ping.Seconds = s || AA.Ping.Seconds;
    AA.Ajax.Get(
        "" + AA.Base.Root() + "common/service/common.ashx",
        { "Mode": "Heartbeat" },
        function (json) {
            setTimeout(function () { AA.Ping.Heartbeat(); }, AA.Ping.Seconds * 1000);
        }
    );
};

