﻿var GRFunc = Class.create({

    initialize: function() {
        if (typeof (URLImagenes) != "undefined")
            URLImagenes += "/";
        if (typeof (URLImpresa) != "undefined")
            URLImpresa += "/";
        if (typeof (URLFlashes) != "undefined")
            URLFlashes += "/";
        this.NuestroHost = "http://" + window.location.hostname + "/";
        this.NuestroHost = this.NuestroHost.toLowerCase();
        this.NumeroAleatorio = "P" + Math.round(Math.random() * 1000);
        this.EsStage = false;
        this.UsuarioLoggueado = this.Get_UserLogeado();
        this.stageBase();
        this.oas = 'http://anuncios.gruporeforma.com/RealMedia/ads/';
        this.RN = new String(Math.random());
        this.RNS = this.RN.substring(2, 11);
        this.VersionBrowser = this.browserversion();
        this.IdPlaza = this.Get_Plaza();
        this.verificaSitioMovil();        
    }

    //Parapublicidad
    , browserversion: function() {

        var _version = 11;
        if (navigator.userAgent.indexOf('Mozilla/3') != -1) {
            _version = 10;
        }
        return _version;


    }

    //Saber en que dominio
    , stageBase: function() {
        //stage desarrollo
        this.EsStage = false;
        var host = window.location.hostname;
        var posicion = host.indexOf(".com");
        this.NuestroHost = "http://www.cancha.com/";
        posicion = host.indexOf("operacionesinternet");
        if (posicion > -1) { this.NuestroHost = "http://operacionesinternet/stage/cancha/"; this.EsStage = true; }
        posicion = host.indexOf("edtimd052sw");
        if (posicion > -1) { this.NuestroHost = "http://edtimd052sw/canchastage/"; this.EsStage = true; }
        posicion = host.indexOf("intranetimdcms");
        if (posicion > -1) { this.NuestroHost = "http://edtimd052sw/canchastage/"; this.EsStage = true; }
        posicion = host.indexOf("localhost");
        if (posicion > -1) { this.NuestroHost = "http://edtimd052sw/canchastage/"; this.EsStage = true; }
        if (this.EsStage || typeof (URLImagenes) == "undefined") {
            URLImagenes = this.NuestroHost;
            URLFlashes = this.NuestroHost;
            URLImpresa = this.NuestroHost;
        }
    }, WriteBase: function(urlBase) {
        document.write("<base href='" + this.NuestroHost + "'>");
    },
    ObscurecePagina: function() {
        $('obscurecePagina').style.display = "block";

        var body = document.body,
        html = document.documentElement;
        var height = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.offsetHeight);
        var width = Math.max(body.offsetWidth, html.clientWidth, html.offsetWidth);

        $('obscurecePagina').style.width = width - 20 + "px";
        $('obscurecePagina').style.height = height + "px";
        $("iframeGalerias").style.top = 0 + "px";
        $("iframeGalerias").style.left = 0 + "px";
        $("iframeGalerias").style.marginLeft = (width / 2) - ($("iframeGalerias").getWidth() / 2) - 10 + "px";
        $("iframeGalerias").style.marginTop = document.viewport.getScrollOffsets()[1] + 50 + "px";

    },
    CerrarGaleria: function() {
        if ($("iframeGalerias")) {
            document.body.removeChild($('iframeGalerias'));
            document.body.removeChild($('obscurecePagina'));
        }
    }
    //Abre pagina normal o popup
    , AbrirPagina: function(tipo, urlPagina, ancho, alto) {
    // this.GetUrlPagina(urlPagina);

        if (!(urlPagina.indexOf("http") == 0))
            urlPagina = this.NuestroHost + urlPagina;
        
        var vAncho = 800;
        var vAlto = 400;
        if (ancho != null)
            vAncho = ancho;
        if (alto != null)
            vAlto = alto;
        if (typeof (urlPagina) != 'undefined' || urlPagina != '') {
            if (tipo == 'normal') { window.location.href = urlPagina; }
            else if (tipo == "modal") {
                var construir = "";
                if (urlPagina.toLowerCase().indexOf("fotogaleria", 0) > -1)
                    construir += "<iframe src='" + urlPagina + "' width='770' height='710' scrolling='no' frameborder='0'></iframe>";
                else
                    construir += "<iframe src='" + urlPagina + "' width='732' height='622' scrolling='no' frameborder='0'></iframe>";

                this.CerrarGaleria();
                var divObjIframeGalerias = document.createElement('div');
                divObjIframeGalerias.id = "iframeGalerias";
                document.body.insertBefore(divObjIframeGalerias, document.body.firstChild)

                var divObjObscurecePagina = document.createElement('div');
                divObjObscurecePagina.id = "obscurecePagina";
                divObjObscurecePagina.onclick = this.CerrarGaleria;
                document.body.insertBefore(divObjObscurecePagina, document.body.firstChild)

                $("iframeGalerias").style.position = "absolute";
                $("iframeGalerias").style.zIndex = "11";

                $("iframeGalerias").update(construir);
                this.ObscurecePagina();
            }
            else { this.OpenWindow(urlPagina, tipo == "scroll", ancho, alto); }
        }
    }
    //Abre un popup con o sin scroll
    , OpenWindow: function(urlPagina, scroll, ancho, alto) {
        var vAncho = 800;
        var vAlto = 400;
        if (ancho != null)
            vAncho = ancho;
        if (alto != null)
            vAlto = alto;

        LeftPosition = (screen.width) ? (screen.width - 800) / 2 : 0;
        TopPosition = (screen.height) ? (screen.height - 400) / 2 : 0;
        //if (urlPagina.indexOf("http:") == -1) urlPagina = this.NuestroHost + urlPagina;
        window.open(urlPagina, this.NumeroAleatorio, 'top=' + TopPosition + ',left=' + LeftPosition + ',width=' + vAncho + ',height=' + vAlto + ',directories=no,location=no,menubar=no,scrollbars=' + (scroll ? "yes" : "no") + ',status=no,toolbar=no,resizable=no');
    }

    , trim: function(str) {
        var str = str.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = str.length;
        while (ws.test(str.charAt(--i)));
        return str.slice(0, i + 1);
    }

    //Manejo de hora y fecha en notas de portada
    , HoraOFechaGeneracion: function(ArtHora, ArtFecha) {
        if (ArtHora != '' && ArtFecha != '') {
            var FechaAux = ArtFecha.split(' ');
            if (FechaAux.length > 2) {
                var ArtDia = parseInt(FechaAux[0], 10);
                if (isNaN(ArtDia)) { return; }
                var ArtMes = FechaAux[1];
                ArtMes = this.trim(ArtMes.toLowerCase()).substring(0, 3);
                var meses = { ene: 1, feb: 2, mar: 3, abr: 4, may: 5, jun: 6, jul: 7, ago: 8, sep: 9, oct: 10, nov: 11, dic: 12 };
                var MesAux = parseInt(meses[ArtMes], 10);
                if (isNaN(MesAux)) { return; }
                var ArtAnio = parseInt(FechaAux[2], 10);
                if (isNaN(ArtAnio)) { return; }
                var FechaHoy = new Date();
                var DiaHoy = FechaHoy.getDate();
                var MesHoy = FechaHoy.getMonth() + 1;
                var AnioHoy;
                if (navigator.appName == 'Netscape') { AnioHoy = FechaHoy.getYear() + 1900; } else if (navigator.appVersion.indexOf("MSIE 9.0")) { AnioHoy = FechaHoy.getFullYear(); } else { AnioHoy = FechaHoy.getYear(); }
                if (DiaHoy == ArtDia && MesHoy == MesAux && AnioHoy == ArtAnio)
                    document.write(ArtHora);
                else
                    document.write((ArtDia < 10 ? "0" + ArtDia : ArtDia) + "/" + (MesAux < 10 ? "0" + MesAux : MesAux) + "/" + ArtAnio);
            }
        }
    }

    //Editar una zona en modo debug
    , ZonaDebug: function(IdContenedorAreaZona) {
        //window.parent.window.location.hash = IdContenedorAreaZona;
    }

    //Escribir la BASE sabiendo el dominio
    //, escribirBase: function() {
    // document.write('<base href="'+this.stageBase()+'">');
    //}
    , ValidaComentario: function(strCaracter) {
        //abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890 áéíóúüñÑ .,¿?¡!
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        if (miCode == 46) { return true; }  //.

        if (this.ValidaTeclado(strCaracter) == true) { return true; }

        if (this.ValidaNumero(strCaracter) == true) { return true; }

        if (this.ValidaLetra(strCaracter) == true) { return true; }

        if (this.ValidaSigno(strCaracter) == true) { return true; }

        return false;
    }
    , ValidaTeclado: function(strCaracter) {
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        if (miCode == 8) { return true; }   //Backspace

        if (miCode == 9) { return true; }   //Tab

        if (miCode == 13) { return true; }  //Enter

        return false;
    }
    , ValidaNumero: function(strCaracter) {
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        //Números
        if (miCode >= 48 && miCode <= 57) { return true; }

        return false;
    }
    , ValidaLetra: function(strCaracter) {
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        //Letras minúsculas
        if (miCode >= 65 && miCode <= 90) { return true; }

        //Letras mayúsculas
        if (miCode >= 97 && miCode <= 122) { return true; }

        return false;
    }
    , ValidaSigno: function(strCaracter) {
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        if (miCode == 44) { return true; }  //,

        if (miCode == 191) { return true; } //¿

        if (miCode == 63) { return true; }  //?

        if (miCode == 161) { return true; } //¡

        if (miCode == 33) { return true; }  //!

        if (miCode == 32) { return true; }  //Espacio

        if (miCode == 225) { return true; } //á

        if (miCode == 233) { return true; } //é

        if (miCode == 237) { return true; } //í

        if (miCode == 243) { return true; } //ó

        if (miCode == 250) { return true; } //ú

        if (miCode == 241) { return true; } //ñ

        if (miCode == 209) { return true; } //Ñ

        if (miCode == 252) { return true; } //ü

        //Se agregan los siguientes caracteres "°#$%()=';:-_

        if (miCode == 34) { return true; }  //"

        if (miCode == 176) { return true; } //°

        if (miCode == 35) { return true; }  //#

        if (miCode == 36) { return true; }  //$

        if (miCode == 37) { return true; }  //%

        if (miCode == 40) { return true; }  //(

        if (miCode == 41) { return true; }  //)

        if (miCode == 61) { return true; }  //=

        if (miCode == 39) { return true; }  //'

        if (miCode == 59) { return true; }  //;

        if (miCode == 58) { return true; }  //:

        if (miCode == 45) { return true; }  //-

        if (miCode == 95) { return true; }  //_

        return false;
    }
    , ValidaCorreo: function(strCaracter) {
        var miCode = strCaracter.charCode ? strCaracter.charCode : strCaracter.keyCode;

        if (miCode == 45) { return true; }  //-

        if (miCode == 46) { return true; }  //.

        if (miCode == 64) { return true; }  //@

        if (miCode == 95) { return true; }  //_

        if (this.ValidaTeclado(strCaracter) == true) { return true; }

        if (this.ValidaNumero(strCaracter) == true) { return true; }

        if (this.ValidaLetra(strCaracter) == true) { return true; }

        return false;
    }
    , RegresaComentarios: function(intCantidad, strXmlRuta) {
        try {
            if (intCantidad == null || intCantidad == '') { intCantidad = 0; }

            var grcuser = this.Get_Cookie('cusuarioss');

            if (grcuser == null || grcuser == '') { return intCantidad; }

            var miXml = this.LeeXml(this.NuestroHost + strXmlRuta);

            if (miXml == null) { return intCantidad; }

            var miNodo = miXml.getElementsByTagName("ComentariosCuenta")[0];

            var miNodoHijo = miNodo.childNodes[0];

            intCuenta = miNodoHijo.nodeValue;

            return intCuenta;
        }
        catch (ex) { return intCantidad; }
    }
    , LeeXml: function(strXmlRuta) {
        try {
            if (window.XMLHttpRequest) {
                miXMLHttpRequest = new XMLHttpRequest();
            }
            else {
                miXMLHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }
            miXMLHttpRequest.open("GET", strXmlRuta, false);
            miXMLHttpRequest.send();

            return miXMLHttpRequest.responseXML;
        }
        catch (ex) { return null; }
    }
    , ResizeIframe: function(miIframeName) {
        var miIframe = $(miIframeName);

        miIframe.style.height = miIframe.contentWindow.document.body.scrollHeight;
    }
    , GetForm: function(_form, _action, _params) {
        try {
            if (_action.toString().length > 0)
                document.getElementById(_form).action = _action;
            var params = _params.toString().split('|');
            for (i = 0; i < params.length; i++) {
                var values = params[i].split('.:.');
                document.getElementById(values[0]).value = values[1];
            }

            document.getElementById(_form).submit();
        }
        catch (ex)
            { }

    }
    , Compartir: function(url, tipo, TitORes) {
        var type = parseInt(tipo, 10);

        if ((!(url.indexOf("http") == 0)) && (tipo != 0)) {
            var NuestroHostEscapado = escape(this.NuestroHost);
            while (NuestroHostEscapado.indexOf("/") != -1) {
                NuestroHostEscapado = NuestroHostEscapado.replace("/", "%2F");
            }
            url = NuestroHostEscapado + url;
        }
        
        
        var urlFinal = "";
        var params = "";
        var nameFinal = "";
        var settingFinal = "";
        switch (type) {
            case 0: //twitter
                {

                    LeftPosition = (screen.width) ? (screen.width - 800) / 2 : 0;
                    TopPosition = (screen.height) ? (screen.height - 400) / 2 : 0;
                    urlFinal = "http://twitter.com/intent/tweet?text=" + url;
                    nameFinal = "twitterfinal";
                    settingFinal = "top=" + TopPosition + ",left=" + LeftPosition + ",resizable=yes,scrollbars=yes,toolbar=0,status=0,width=760,height=436";
                    window.open(urlFinal, "_self", settingFinal);
                } break;
            case 1: //twitter
                {
                    LeftPosition = (screen.width) ? (screen.width - 800) / 2 : 0;
                    TopPosition = (screen.height) ? (screen.height - 400) / 2 : 0;
                    urlFinal = this.NuestroHost + "aplicaciones/redessociales/enviaTwitter.aspx?url=" + url + "&resumen=" + TitORes;
                    nameFinal = "twitter";
                    settingFinal = "top=" + TopPosition + ",left=" + LeftPosition + ",resizable=yes,scrollbars=yes,toolbar=0,status=0,width=760,height=436";
                    window.open(urlFinal, nameFinal, settingFinal);
                } break;
            case 2: //facebook
                {
                    LeftPosition = (screen.width) ? (screen.width - 800) / 2 : 0;
                    TopPosition = (screen.height) ? (screen.height - 400) / 2 : 0;
                    urlFinal = "http://www.facebook.com/sharer.php?u=" + url + "&t=" + TitORes;
                    nameFinal = "facebook";
                    settingFinal = "top=" + TopPosition + ",left=" + LeftPosition + ",toolbar=0,status=0,width=626,height=436";
                    window.open(urlFinal, nameFinal, settingFinal);
                } break;
            case 3: //mail a amigo
                {
                    LeftPosition = (screen.width) ? (screen.width - 800) / 2 : 0;
                    TopPosition = (screen.height) ? (screen.height - 400) / 2 : 0;
                    urlFinal = this.NuestroHost + "aplicaciones/correos/CorreoEnvio.aspx?CorreoTipo=3&Url=" + url + "&Titulo=" + TitORes;
                    this.AbrirPagina("noscroll", urlFinal);
                } break;
        }
    }
    , ValidaAccesoModal: function() {
        //var urlembed = this.Get_PlazaQueryString('urlembed');
        var wlUE = window.location.href;
        var urlEP = wlUE.split('urlembed=');
        var urlembed = urlEP[1];
        if (urlembed != null && urlembed.length > 0 && urlembed.indexOf('galeria') > -1) {
            if (urlembed.indexOf('http://') == -1 && urlembed.substring(0, 1) == "/")
                urlembed = this.NuestroHost + urlembed.substring(1); //Se omite el primer slash ya que la variable nuestro host lo concatena.
            this.AbrirPagina('modal', urlembed);
        }

    }
    , AjustarIframe: function(IdObj, Tipo) {
        try {
            IdObj = (Tipo != null ? Tipo.toString() + IdObj.toString() : IdObj.toString());
            if (navigator.userAgent.indexOf('MSIE') != -1) {
                //explorer
                height = window.frames[IdObj].document.body.scrollHeight;
                if (height == 0 && Tipo == 'sondeo') height = 250;
                var objIframe = document.getElementById(IdObj);
                objIframe.height = height;
            }
            else {
                //mozilla
                height = $(IdObj).contentWindow.document.body.offsetHeight;
                var objIframe = document.getElementById(IdObj);
                objIframe.height = height;
            }
        }
        catch (ex) { }
    }
    , SetCookie: function(cookieName, cookieValue, nDays) {
        var today = new Date();
        var expire = new Date();
        if (nDays == null || nDays == 0) nDays = 30;
        expire.setTime(today.getTime() + 3600000 * 24 * nDays);
        if (this.EsStage) {
            expire.setTime(today.getTime() + 24 * 60 * 60 * 1000 * nDays);
            document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expire.toGMTString() + "; path = /";
        }
        else {
            document.cookie = cookieName + "=" + escape(cookieValue) + "; expires=" + expire.toGMTString() + "; path = /;domain=.cancha.com";
        }
        //document.cookie += "domain=.cancha.com";
    }
    , GetCookieVal: function(offset) {
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        var clave = unescape(document.cookie.substring(offset, endstr));
        return clave.toLowerCase();
    }
    , Get_Cookie: function(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg)
                return this.GetCookieVal(j);
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }

    , Delete_Cookie: function(name) {
        if (Get_Cookie(name)) document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
    }

    , Get_UserLogeado: function() {
        return this.Get_Cookie('cusuarioss');
    }
    , Get_CookiePlaza: function() {
        return this.Get_Cookie('grcidfte');
    }
    , DisplayAds: function(tipo, categoriadir, subcategoriadir, elementosubcategoriaid, posisionanuncio) {

        var plazacookie = this.Get_CookiePlaza('grcidfte');
        var sitepage = 'reforma.com/';
        var directoriopub = '';
        baseAddress = document.domain;
        baseAddress = baseAddress.toLowerCase();
        if (baseAddress.search(".com") != -1) {
            switch (plazacookie) {
                case '101':
                    sitepage = 'elnorte.com/'; break;
                case '102':
                    sitepage = 'reforma.com/'; break;
                case '103':
                    sitepage = 'mural.com/'; break;
            }


            switch (tipo) {
                case 'portadah':
                    directoriopub = 'portada';
                    break;
                case 'portadac':
                    directoriopub = 'portada/' + categoriadir;
                    break;
                case 'portadas':
                    directoriopub = 'portada/' + categoriadir + '/' + subcategoriadir;
                    break;
                case 'edicionimpresa': case 'busquedas': case 'radio': case 'concentradora/noticias': case 'concentradora/galeriamm': case 'concentradora/fotogaleria':
                    directoriopub = tipo;
                    break;
                case 'articulo': case 'fotogaleria': case 'galeriamm': case 'foro':
                    directoriopub = tipo + '/' + categoriadir + '/' + subcategoriadir + '/' + elementosubcategoriaid;
                    break;
                case 'articulo/editoriales/cancha':
                    directoriopub = tipo + '/' + elementosubcategoriaid;
                    break;
                case 'carton/editoriales/cancha':
                    directoriopub = tipo + '/' + categoriadir;
                    break;
            }

            var oasdir = 'principal/int/canchacom/' + directoriopub.toLowerCase() + '/default.asp/1';
            var oaspage = sitepage + oasdir + this.RNS + '@' + posisionanuncio;

            switch (this.VersionBrowser) {
                case 11:
                    document.write(String.fromCharCode(60) + 'SCRIPT LANGUAGE="JavaScript1.1" SRC="' + this.oas + 'adstream_jx.cgi/' + oaspage + '"' + String.fromCharCode(62));
                    document.write(String.fromCharCode(60) + '/SCRIPT' + String.fromCharCode(62));
                    break;

                case 10:
                    var width = 0;
                    var height = 0;

                    document.write(String.fromCharCode(60) + 'A HREF="' + this.oas + 'click_nx.cgi/' + oaspage + '" TARGET="_top"' + String.fromCharCode(62) + String.fromCharCode(60) + 'IMG SRC="' + this.oas + 'adstream_nx.cgi/' + oaspage + '" BORDER="0" WIDTH="' + width + '" HEIGHT="' + height + '"' + String.fromCharCode(62) + String.fromCharCode(60) + '/a' + String.fromCharCode(62));
                    break;

            }
        }
        else {
            baseSTG = String.fromCharCode(60) + 'img src="' + URLImagenes + 'libre/imgdiseno/';
            switch (posisionanuncio) {
                case 'TopRight': case 'Right': case 'Right1': case 'Right2': case 'Right3':
                    document.write(baseSTG + 'publi_180_60.jpg" width="180" height="60"' + String.fromCharCode(62)); break;
                case 'x11': case 'x12': case 'x13':
                    document.write(baseSTG + 'publi_300_100.jpg" width="300" height="100"' + String.fromCharCode(62)); break;
                case 'Middle1': case 'Middle2':
                    document.write(baseSTG + 'publi_300_250.jpg" width="300" height="250"' + String.fromCharCode(62)); break;
                case 'Top':
                    document.write(baseSTG + 'publi_728_90.jpg" width="728" height="90"' + String.fromCharCode(62)); break;
                case 'Middle':
                    document.write(baseSTG + 'publi_683_60.jpg" width="683" height="60"' + String.fromCharCode(62)); break;
                case 'x01':
                    document.write(baseSTG + 'banner_headerMxM.gif" width="1" height="1"' + String.fromCharCode(62)); break;
                case 'x02':
                    document.write(baseSTG + 'anuncioheader_derecha.gif" width="77" height="84"' + String.fromCharCode(62)); break;

            }
        }

    }
     , CambiaTamanioTexto: function(objs) {

         for (ind = 0; ind < objs.length; ind++) {
             var obj = objs[ind];
             if ($(obj) != null) {
                 if ($(obj).className.toString().indexOf('zoom') > -1)
                     $(obj).className = $(obj).className.toString().split('zoom').join('');
                 else
                     $(obj).className = $(obj).className.toString() + "zoom";

             }
         }
     }
     , Get_Plaza: function() {
         var plaza = '';
         plaza = this.Get_PlazaQueryString('pc');
         if (plaza == null || typeof (plaza) == "undefined" || !this.Valida_Plaza(plaza)) {
             plaza = this.Get_CookiePlaza();
             //if (plaza == null || plaza == "undefined") {
             if (window.location.href.indexOf("Defaultn.htm") > -1 || window.location.href.indexOf("defaultn.htm") > -1) {
                 this.Set_CookiePlaza("101", 30);
                 plaza = this.Get_CookiePlaza();
             }
             else if (window.location.href.indexOf("Defaultr.htm") > -1 || window.location.href.indexOf("defaultr.htm") > -1) {
                 this.Set_CookiePlaza("102", 30);
                 plaza = this.Get_CookiePlaza();
             }
             else if (window.location.href.indexOf("Defaultm.htm") > -1 || window.location.href.indexOf("defaultm.htm") > -1) {
                 this.Set_CookiePlaza("103", 30);
                 plaza = this.Get_CookiePlaza();
             }
             //}
         }
         else
             this.Set_CookiePlaza(plaza, 30);
         return plaza;
     }
     , Valida_Plaza: function(plaza) {
         var plazas_disp = ["101", "102", "103"];
         if (plazas_disp.indexOf(plaza) != -1)
             return true;
         else
             return false;
     }
     , Set_CookiePlaza: function(cookieValue, nDays) {
         this.SetCookie("grcidfte", cookieValue, nDays);
     }
     , Get_PlazaQueryString: function(qs) {
         var qsParam = new Array();
         if (window.location.search) {
             var querys = window.location.search.substring(1);
             var param = querys.split('&');
             for (var i = 0; i < param.length; i++) {
                 var pos = param[i].indexOf('=');
                 if (pos > 0) {
                     var key = param[i].substring(0, pos);
                     var val = param[i].substring(pos + 1);
                     qsParam[key] = val;
                 }
             }
             querystring = qsParam[qs];
             return querystring;
         }
         return null;
     }

     , Switch_Plaza: function(str_plaza) {
         var id_plaza;
         switch (str_plaza) {
             case "Norte":
                 id_plaza = "101";
                 break;
             case "Reforma":
                 id_plaza = "102";
                 break;
             case "Mural":
                 id_plaza = "103";
                 break;
         }
         return id_plaza;
     }

     , Default_Plaza: function(idPlaza) {
         var nomdefault = "";
         switch (idPlaza) {
             case "101":
                 nomdefault = "Defaultn.htm";
                 break;
             case "102":
                 nomdefault = "Defaultr.htm";
                 break;
             case "103":
                 nomdefault = "Defaultm.htm";
                 break;
         }
         return nomdefault;
     }

     , AbrirFotoZoom: function(autor, tipo, urlfoto) {
         var liga = this.NuestroHost + 'aplicaciones/fotozoom/verfoto.aspx?autor=' + autor + '&tipo=' + tipo + '&urlfoto=' + urlfoto;
         this.AbrirPagina('noscroll', liga);
     }
     , PintaComentarios: function(IdComentario, CantidadComentario, OcultarComentario, RutaComentario, TituloEncoded, URLEncoded, IdCategoria, Tipoburbuja) {

         //var RutaComentario = '\\cntxml\\Comentario\\1\\1\\41.xml';

         //RutaComentario = RutaComentario.replace(/\\/g, '/');

         CantidadComentario = grFunc.RegresaComentarios(CantidadComentario, RutaComentario);

         if (CantidadComentario > 0) {
             var Comentarios = Class.create({
                 initialize: function(IdComentario, CantidadComentario, OcultarComentario, RutaComentario, TituloEncoded, URLEncoded, IdCategoria) {
                     this.Aplicacion = 'aplicaciones/comentarios/ComentarioPublicoCompleto.aspx';
                     this.IdComentario = IdComentario;
                     this.CantidadComentario = CantidadComentario;
                     this.OcultarComentario = OcultarComentario;
                     this.RutaComentario = RutaComentario;
                     this.TituloEncoded = TituloEncoded;
                     this.URLEncoded = URLEncoded;
                     this.IdCategoria = IdCategoria;
                 },
                 AbrirComentarios: function() {
                     var LigaComentario = grFunc.NuestroHost + this.Aplicacion;
                     LigaComentario += '?IdComentario=' + this.IdComentario;
                     LigaComentario += '&OcultarComentarios=' + this.OcultarComentario;
                     LigaComentario += '&Titulo=' + this.TituloEncoded;
                     LigaComentario += '&Url=' + this.URLEncoded;
                     LigaComentario += '&IdCategoria=' + this.IdCategoria;
                     //LigaComentario += 'grFunc.AbrirPagina(' +  String.fromCharCode(39) + 'scroll' +  String.fromCharCode(39) + ',' +  String.fromCharCode(39) + LigaComentario +  String.fromCharCode(39) + ');'
                     return LigaComentario;
                 } /*,
                 EscribeCantidad: function() {
                     var intCantidad = grFunc.RegresaComentarios(this.CantidadComentario, this.RutaComentario);
                     return intCantidad;
                 }
                 */
             });
             var AppComentarios = new Comentarios(IdComentario, CantidadComentario, OcultarComentario, RutaComentario, TituloEncoded, URLEncoded, IdCategoria);

             switch (Tipoburbuja) {
                 case 'App2':
                     document.write('<td width="7" align="right" valign="middle" class="arblanco11">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     document.write('<img src="libre/imgdiseno/coment_left.png" border="0" width="7" height="16" /></a></td>');
                     document.write('<td height="16" align="right" valign="middle" class="arblanco11" background="libre/imgdiseno/comentario_01.gif">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     //document.write('<span class="arblanco10"><span class="comenblanco11">' + AppComentarios.EscribeCantidad() + '</span></span></a></td>');
                     document.write('<span class="arblanco10"><span class="comenblanco11">' + AppComentarios.CantidadComentario + '</span></span></a></td>');
                     document.write('<td width="18">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     document.write('<img src="libre/imgdiseno/coment_right.png" border="0" width="19" height="16" /></a></td>');
                     break;
                 case 'App3':
                     document.write('<td width="7" align="right" valign="middle" class="arblanco11">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     document.write('<img src="libre/imgdiseno/coment_left.png" border="0" width="7" height="16" /></a></td>');
                     document.write('<td height="16" align="right" valign="middle" class="arblanco11" background="libre/imgdiseno/comentario_01.gif">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     //document.write('<span class="arblanco10"><span class="comenblanco11">' + AppComentarios.EscribeCantidad() + '</span></span></a></td>');
                     document.write('<span class="arblanco10"><span class="comenblanco11">' + AppComentarios.CantidadComentario + '</span></span></a></td>');
                     document.write('<td width="18">');
                     document.write('<a onclick=grFunc.AbrirPagina("noscroll","' + AppComentarios.AbrirComentarios() + '",690,600)>');
                     document.write('<img src="libre/imgdiseno/coment_right.png" border="0" width="19" height="16" /></a></td>');
                     break;
             }
         }
     }
     , caractEspec: function(strr) {
         myStrr = new String(strr);
         myStrr = myStrr.replace(/[á]/g, '&aacute;');
         myStrr = myStrr.replace(/[é]/g, '&eacute;');
         myStrr = myStrr.replace(/[í]/g, '&iacute;');
         myStrr = myStrr.replace(/[ó]/g, '&oacute;');
         myStrr = myStrr.replace(/[ú]/g, '&uacute;');
         myStrr = myStrr.replace(/[Á]/g, '&Aacute;');
         myStrr = myStrr.replace(/[É]/g, '&Eacute;');
         myStrr = myStrr.replace(/[Í]/g, '&Iacute;');
         myStrr = myStrr.replace(/[Ó]/g, '&Oacute;');
         myStrr = myStrr.replace(/[Ú]/g, '&Uacute;');
         myStrr = myStrr.replace(/[ñ]/g, '&ntilde;');
         myStrr = myStrr.replace(/[Ñ]/g, '&Ntilde;');
         myStrr = myStrr.replace(/[ë]/g, '&euml;');
         myStrr = myStrr.replace(/[Ë]/g, '&Euml;');
         myStrr = myStrr.replace(/[ü]/g, '&uuml;');
         myStrr = myStrr.replace(/[Ü]/g, '&Uuml;');
         myStrr = myStrr.replace(/[*]/g, '');
         myStrr = myStrr.replace(/[-]/g, '');
         myStrr = myStrr.replace(/[+]/g, '');
         myStrr = myStrr.replace(/[|]/g, '');
         myStrr = myStrr.replace(/[!]/g, '');
         myStrr = myStrr.replace(/[(]/g, '');
         myStrr = myStrr.replace(/[)]/g, '');
         myStrr = myStrr.replace(/[{]/g, '');
         myStrr = myStrr.replace(/[}]/g, '');
         myStrr = myStrr.replace(/[<]/g, '');
         myStrr = myStrr.replace(/[>]/g, '');
         myStrr = myStrr.replace(/[:]/g, '');
         myStrr = myStrr.replace(/[?]/g, '');
         myStrr = myStrr.replace(/[~]/g, '');
         myStrr = myStrr.replace(/[#]/g, '');
         myStrr = myStrr.replace(/[\\]/g, '');
         myStrr = myStrr.replace(/[\^]/g, '');
         myStrr = myStrr.replace(/[\[]/g, '');
         myStrr = myStrr.replace(/[\]]/g, '');
         return myStrr;
     }

     , validaFecha: function(dia, mes, ano) {
         var fecha = new Date(ano, mes - 1, dia);
         return fecha;
     }

    , ligaBuscador: function(zona) {
        sitePcob = 'canchacom';
        if (zona == 1) {
            document.buscador.strbusqueda.value = this.caractEspec(document.buscador.strbusqueda.value);
            document.buscador.q.value = document.buscador.strbusqueda.value;
            document.buscador.method = "POST";
            document.buscador.target = "_top";
            document.buscador.action = 'http://busquedas.gruporeforma.com/' + sitePcob + '/Pages/Buscaimpresa.aspx?pc=' + this.IdPlaza;
        }
        //buscador fotogaleria
        else if (zona == 2) {
            document.buscador2.strbusqueda.value = this.caractEspec(document.buscador2.strbusqueda.value);
            document.buscador2.method = "POST";
            document.buscador2.target = "_top";
            var auxFecha = this.validaFecha(document.buscador2.diaini.value, document.buscador2.mesini.value, document.buscador2.anoini.value);
            document.buscador2.fechaini.value = auxFecha.getDate() + '/' + (auxFecha.getMonth() + 1) + '/' + auxFecha.getFullYear();
            auxFecha = this.validaFecha(document.buscador2.diafin.value, document.buscador2.mesfin.value, document.buscador2.anofin.value);
            document.buscador2.fechafin.value = auxFecha.getDate() + '/' + (auxFecha.getMonth() + 1) + '/' + auxFecha.getFullYear();
            document.buscador2.action = 'http://busquedas.gruporeforma.com/' + sitePcob + '/Pages/BuscaFotoGal.aspx?pc=' + this.IdPlaza;
        }
        //buscador galeria multimedia
        else if (zona == 3) {
            document.buscador3.strbusqueda.value = this.caractEspec(document.buscador3.strbusqueda.value);
            document.buscador3.method = "POST";
            document.buscador3.target = "_top";
            var auxFecha = this.validaFecha(document.buscador3.diaini.value, document.buscador3.mesini.value, document.buscador3.anoini.value);
            document.buscador3.fechaini.value = auxFecha.getDate() + '/' + (auxFecha.getMonth() + 1) + '/' + auxFecha.getFullYear();
            auxFecha = this.validaFecha(document.buscador3.diafin.value, document.buscador3.mesfin.value, document.buscador3.anofin.value);
            document.buscador3.fechafin.value = auxFecha.getDate() + '/' + (auxFecha.getMonth() + 1) + '/' + auxFecha.getFullYear();
            document.buscador3.action = 'http://busquedas.gruporeforma.com/' + sitePcob + '/Pages/BuscaAudioGal.aspx?pc=' + this.IdPlaza;
        }
    }
     , Block_Copy: function(e) {
         if ((grFunc.IdPlaza == '101'))
             msg = "Derechos Reservados ©\nEditora el Sol, S.A. de C.V.";
         else
             msg = "Derechos Reservados ©\nC.I.C.S.A";
         if (navigator.appName == 'Netscape' && e.which == 3) {
             alert(msg);
             return false;
         }
         if (navigator.appName == 'Microsoft Internet Explorer' && event.button == 2) {
             alert(msg);
             return false;
         }
         else return true;
     }
     , AgregaImg_BlockCopy: function() {
         if (document.images) {
             for (i = 0; i < document.images.length; i++) {
                 document.images[i].onmousedown = this.Block_Copy;
                 document.images[i].onmouseup = this.Block_Copy;
             }
         }
     }
     , GetNombre_Plaza: function() {
         var sitepage = ''
         switch (grFunc.IdPlaza) {
             case '101':
                 sitepage = 'elnorte.com/'; break;
             case '102':
                 sitepage = 'reforma.com/'; break;
             case '103':
                 sitepage = 'mural.com/'; break;
         }
         return sitepage;
     }

    /*FUNCIONES MULTIPROMO CANCHA*/

     , GetInternetExplorerVersion: function() {
         // Returns the version of Internet Explorer or a -1
         // (indicating the use of another browser).

         var rv = -1; // Return value assumes failure.
         if (navigator.appName == 'Microsoft Internet Explorer') {
             var ua = navigator.userAgent;
             var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
             if (re.exec(ua) != null)
                 rv = parseFloat(RegExp.$1);
         }
         return rv;
     }


        , SetUpPanes: function(containerId, defaultTabId) {
            // go through the DOM, find each tab-container
            // set up the panes array with named panes
            // find the max height, set tab-panes to that height
            panes[containerId] = new Array();
            var maxHeight = 0; var maxWidth = 0;
            var container = document.getElementById(containerId);
            var paneContainer = container.getElementsByTagName("div")[0];
            var paneList = paneContainer.childNodes;
            for (var i = 0; i < paneList.length; i++) {
                var pane = paneList[i];
                if (pane.nodeType != 1) continue;
                if (pane.offsetHeight > maxHeight) maxHeight = pane.offsetHeight;
                if (pane.offsetWidth > maxWidth) maxWidth = pane.offsetWidth;
                panes[containerId][pane.id] = pane;

                pane.style.display = "none";
            }
            paneContainer.style.height = maxHeight + "px";
            paneContainer.style.width = maxWidth + "px";
            document.getElementById("tab1").onclick();
        }

        , ShowPane: function(paneId, activeTab, urlproducto) {
            // make tab active class
            // hide other panes (siblings)
            // make pane visible
            var container = document.getElementById("containercancha");
            var paneContainer = container.getElementsByTagName("div")[0];
            var paneList = paneContainer.childNodes;
            var lastpane = "pane" + paneList.length
            //alert('lastpane' + lastpane);


            for (var con in panes) {
                activeTab.blur();
                if (paneId == "pane1") {
                    activeTab.className = "tab-active1";
                    var ver = this.GetInternetExplorerVersion();
                    if (ver > -1) {
                        document.getElementById("imgterminacioncurva").align = "top";
                        document.getElementById("imgterminacioncurva").src = urlproducto + "libre/imgdiseno/terminacion_curvaroja.gif";
                    }
                    else {
                        document.getElementById("imgterminacioncurva").align = "absmiddle";
                        document.getElementById("imgterminacioncurva").src = urlproducto + "libre/imgdiseno/terminacion_curvaroja.gif";
                    }
                }
                else {
                    if (paneId == lastpane) {
                        activeTab.className = "tab-activelast";
                    }
                    else {
                        activeTab.className = "tab-active";
                    }

                }

                if (panes[con][paneId] != null) {
                    // tab and pane are members of this container
                    var pane = document.getElementById(paneId);
                    pane.style.display = "block";
                    var container = document.getElementById(con);
                    var tabs = container.getElementsByTagName("ul")[0];
                    var tabList = tabs.getElementsByTagName("a")
                    //alert('tablist ' + tabList.length);
                    for (var i = 1; i <= tabList.length; i++) {
                        var tab = tabList[i - 1];
                        if (tab != activeTab) {
                            var ultimo = "pane" + i
                            if (ultimo == lastpane) {
                                tab.className = "tab-disabledlast";
                            }
                            else {
                                if (i == 1) {
                                    tab.className = "tab-disabled1";
                                    var ver = this.GetInternetExplorerVersion();
                                    if (ver > -1) {
                                        document.getElementById("imgterminacioncurva").align = "top";
                                        document.getElementById("imgterminacioncurva").src = urlproducto + "libre/imgdiseno/terminacion_curva.gif";
                                    }
                                    else {
                                        document.getElementById("imgterminacioncurva").align = "absmiddle";
                                        document.getElementById("imgterminacioncurva").src = urlproducto + "libre/imgdiseno/terminacion_curva.gif";
                                    }
                                }
                                else {
                                    tab.className = "tab-disabled";
                                }
                            }
                        }
                        else {
                            var imagenact = document.getElementById("imagenpane" + i).src;
                            if (imagenact.indexOf("pix.gif") > -1) {
                                //alert(imagenact);
                                var nuevaimagen = imagenes[i];
                                //alert(nuevaimagen);
                                document.getElementById("imagenpane" + i).src = nuevaimagen;
                            }
                        }

                    }


                    for (var i in panes[con]) {
                        var pane = panes[con][i];
                        if ((undefined != pane.id) && (pane.id != null)) {
                            if (pane.id != paneId) {
                                document.getElementById(pane.id).style.display = "none";
                            }
                        }
                        else {
                            continue;
                        }
                    }


                }



            }
            return false;
        }

        /************************************
        * IDENTIFICAR PLATAFORMA Y BROWSER *
        ************************************/
        , verificaSitioMovil: function() {

            var dominio = document.domain.toLowerCase();
            var navUA = navigator.userAgent.toLowerCase();
            var tipoBrowser;
            var tipoPlataforma;
            if (navUA.indexOf('ipod') != -1)
                tipoBrowser = 'iphone';
            else if (navUA.indexOf('iphone') != -1)
                tipoBrowser = 'iphone';
            else if (navUA.indexOf('ipad') != -1)
                tipoBrowser = 'ipad';
            else if (navUA.indexOf('android') != -1)
                tipoBrowser = 'android';
            else if (navUA.indexOf('blackberry') != -1)
                tipoBrowser = 'blackberry';
            else if (navUA.indexOf('msie') != -1)
                tipoBrowser = 'explorer';
            else if (navUA.indexOf('netscape') != -1)
                tipoBrowser = 'netscape';
            else if (navUA.indexOf('firefox') != -1)
                tipoBrowser = 'firefox';
            else if (navUA.indexOf('safari') != -1)
                tipoBrowser = 'safari';
            else
                tipoBrowser = 'otros';

            if (navUA.indexOf('windows') != -1)
                tipoPlataforma = 'windows';
            else
                tipoPlataforma = 'mac';

            if (tipoBrowser == 'iphone') {
                var cookieiphone = this.Get_Cookie('gruporeforma_iphone');
                if (cookieiphone == null) {
                    window.location.href = 'http://' + dominio + '/EntradaIphone.htm';                                        
                }
            }
            else if (tipoBrowser == 'blackberry') {
                var cookieblackberry = this.Get_Cookie('gruporeforma_blackberry');
                if (cookieblackberry == null) {
                    window.location.href = 'http://' + dominio + '/EntradaBlackberry.htm';                    
                }
            }
            else if (tipoBrowser == 'otros' && tipoPlataforma != 'windows' && tipoPlataforma != 'mac') {
                window.location.href = 'http://www.cancha.com/';
            }
        }

});
