﻿var ruta = "http://cps-dom.com/"; //"http://localhost:54480/cpsnet/"; 
$(document).ready(function () {
    MessageBox = function (Mensaje, url) {
        var contenido;
        if (url != '')
            contenido = '<img width = 25 height =25 src="./Styles/img/iconos/mediumQuestion.png" /> <span style = "color:blue;"> ' + Mensaje + '</span>' + '<br> <br> <button id ="yes" style = "width:70px;"> Si </button> <button id ="no" style = "width:70px;"> No </button>';
        else
            contenido = '<img width = 25 height =25 src="./Styles/img/iconos/okMedium.png" /> <span style = "color:blue;"> ' + Mensaje + '</span>' + '<br> <br> <button id ="no" style = "width:70px;"> Ok </button>'
        $.msg({
            bgPath: './Scripts/plugins/dreamerslab-jquery.msg-5b5978a/',
            fadeIn: 500,
            fadeOut: 200,
            timeOut: 5000,
            autoUnblock: false,
            clickUnblock: false,
            content: contenido,
            afterBlock: function () {
                // store 'this' for other scope to use
                var self = this;
                // when click #yes btn
                $('#yes').bind('click', function () {
                    if (url != '') {
                        window.location = url;
                        // self.method is not chainable
                        self.replace('Registro eliminado con exito..!');
                        self.unblock(2000);
                    }
                });

                $('#no').bind('click', function () {
                    self.unblock();
                });
            },
            beforeUnblock: function () {
                //alert('This is a callback from beforeUnblock event handler :)');
            }

        });
    }
    CanalCPS = function () {

        window.open('http://www.youtube.com/user/CANALCPS', 'Canal CPS', 'status=yes,width=800,height=800,scrollbars=yes');
    }
    cambiaIdioma = function (idioma) {
        //alert(window.location.pathname + window.location.search);

        //averigua el idioma que tiene actualmente si no existe ahi, es que está vacio y tiene el por defecto
        busqueda = window.location.search;
        if (busqueda.length == 0) { //Si no hay ninguna busqueda o se está en la pagina por defecto
            url = window.location.pathname + "?idioma=" + idioma;
        } else
            if (busqueda.search("idioma") == -1 && busqueda.length > 0) {//No encontrado pero si hay busqueda
                url = window.location.pathname + busqueda + "&idioma=" + idioma;
            } else
                if (busqueda.search("idioma") > 0) {//Si existe idioma 
                    url = window.location.pathname + busqueda.substr(0, busqueda.search("idioma")) + busqueda.substr(busqueda.search("idioma") + 9, busqueda.length) + "&idioma=" + idioma;

                }
        url = url.replace("?&", "?"); //Esto no funciona muy bien, hay que revisarlo mejor
        url = url.replace("aspx&", "aspx?");
        url = url.replace("&&", "&")
        window.location = url;
    }
});
function cargarMembresia(idioma) {
    $.ajax({
        url: ruta + "./contenidos.aspx?ide=membresiaFlexGratis&idioma=" + idioma,
        success: function (datos) {
            $('.cuerpo').append(datos);
            $('.cuerpo').append('<div class="super"></div>');
        }
    });
}

function cargarTiendas(idioma) {
    $.ajax({
        url: ruta + "./contenidos.aspx?ide=tiendasPrincipales&idioma=" + idioma,
        success: function (datos) {
            $('.cuerpo').append(datos);
            $('.cuerpo').append('<div class="super"></div>');
        },
        error: function (xhr, msg, excepcion) {
            alert(msg);
        }
    });
}
function profundidad() {
    cantidadProfundidad = window.location.hostname.split("/").length;
    if (window.location.hostname.search("localhost")) {
        cantidadProfundidad -= 1;
    }
    pro = "";
    for (i = 0; i <= cantidadProfundidad; i++) {
        pro += "../";
    }
    return pro;
}
