﻿if (!common) {
    var common = new function() {
        this.UrlBase;

        this.CallbackProcess = function(responseText, textStatus, XMLHttpRequest) {
            switch (XMLHttpRequest.status) {
                case 418:
                    alert("Necesitas estar identificado para utilizar esta opción<br/><ul style='margin-top:3px;margin-bottom:3px;'><li style='text-align:left'><a href='/Registro/registro.aspx?source=" + escape(window.location) + "'>Ya estoy registrado</a></li><li style='text-align:left'><a href='/Registro/NuevoUsuario.aspx?source='" + escape(window.location) + ">Soy nuevo en dietasan.com</a></li></ul>");
                    break;
                case 500:
                case 404:
                    alert("Se ha producido un error inseperado. Por favor, intentelo pasado unos minutos.");
                    break;
                default: break;
            }
        }

        this.padLeft = function(str, len, pad) {
            str = "" + str;
            return Array(len + 1 - str.length).join(pad) + str;
        }

        this.DateToString = function(date) {
            return this.padLeft(date.getDate(), 2, "0") + "/" + this.padLeft(date.getMonth(), 2, "0") + "/" + this.padLeft(date.getFullYear(), 4, "0");
        }

        this.SelectedValue = function(ddl, value) {
            ddl.selectedIndex = -1;
            for (var i = 0; i < ddl.options.length; i++) {
                if (ddl.options[i].value == value) {
                    ddl.selectedIndex = i;
                    break;
                }
            }
        }
    }
}
window.alert = function(msg) {
    var panel;
    panel = document.getElementById('p_alert');
    if (panel)
        document.body.removeChild(panel);
    panel = document.createElement("div");
    panel.id = "p_alert";
    if (navigator.userAgent.match(/MSIE [123456]/i)) {
        panel.className = "panelAlert";
        panel.style.top = ShowPosyScroll() + 300 + "px";
    }
    else {
        panel.className = "panelAlertFix";
    }
    panel.innerHTML = "<table class=\"tableshadow\" align=\"right\"><tr><td class=\"tl\"></td><td class=\"tc\"></td><td class=\"tr\"></td></tr><tr><td class=\"ml\"></td><td class=\"mc\" style=\"padding-right:12px\">" + msg.replace(/\r\n/, "<br />") + "<button style=\"display:block;margin-top:5px\" onclick=\"document.body.removeChild(document.getElementById('p_alert'))\">Aceptar</button></td><td class=\"mr\"></td></tr><tr><td class=\"bl\"></td><td class=\"bc\"></td><td class=\"br\"></td></tr></table>";
    document.body.insertBefore(panel, document.body.childNodes[0]);
}
