﻿function $(id){
	return document.getElementById(id);
}
function g(url)
{
try{
    //pageTracker._trackPageview(window.location.href.replace("http://"+window.location.host,"")+"/"+streliminarpuntuacion(url));
    urchinTracker(window.location.href.replace("http://"+window.location.host,"")+"/"+streliminarpuntuacion(url));
    }
    catch(e)
    {}
}
function Request(name, url) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null)
        return "";
    else
        return results[1];
}

function streliminarpuntuacion(cadena)
        {
            cadena=cadena.toLowerCase();
            cadena=cadena.replace(/á/g, "a");
            cadena=cadena.replace(/é/g, "e");
            cadena=cadena.replace(/í/g, "i");
            cadena=cadena.replace(/ó/g, "o");
            cadena=cadena.replace(/ú/g, "u");
            cadena=cadena.replace(/ñ/g, "n");
            cadena=cadena.replace(/¿/g, "");
            cadena=cadena.replace("?", "");
            cadena=cadena.replace(/!/g, "");
            cadena=cadena.replace(/¡/g, "");
            return cadena.replace(/ /g, "-");
        }


function validateimgs(value) {
    var b = value.split('.');
    var valid = /^(gif|jpg|png|jpeg|swf)$/.test(b[b.length - 1].toLowerCase());
    return valid;
}

stuHover = function() {
    try{
    var cssRule;
    var newSelector;
    for (var i = 0; i < document.styleSheets.length; i++)
        for (var x = 0; x < document.styleSheets[i].rules.length; x++) {
        cssRule = document.styleSheets[i].rules[x];
        if (cssRule.selectorText.indexOf("LI:hover") != -1) {
            newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
            document.styleSheets[i].addRule(newSelector, cssRule.style.cssText);
        }
    }/*
    var getElm = $("nav").getElementsByTagName("LI");
    for (var i = 0; i < getElm.length; i++) {
        getElm[i].onmouseover = function() {
            this.className += " iehover";
        }
        getElm[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp(" iehover\\b"), "");
        }
    }*/
    }
   catch(e)
   {}
}
function cambiarTab(mostrarcont, mostrartab)
{
    $("nuevos").style.display="none";
    $("Vistos").style.display="none";
    $("Recomendados").style.display="none";
    
    $("recomendadotab").className="simple_tab";
    $("vistotab").className="simple_tab";
    $("nuevotab").className="simple_tab";
    
    $(mostrarcont).style.display="block";
    $(mostrartab).className="simple_tab selected";
}

function cambiarTabEquipos(mostrarcont, mostrartab)
{
    $("Equiposnuevos").style.display="none";
    $("EquiposVistos").style.display="none";
    $("EquiposRecomendados").style.display="none";
    
    $("Equiposrecomendadotab").className="simple_tab";
    $("Equiposvistotab").className="simple_tab";
    $("Equiposnuevotab").className="simple_tab";
    
    $(mostrarcont).style.display="block";
    $(mostrartab).className="simple_tab selected";
}

if (window.attachEvent) window.attachEvent("onload", stuHover);

function WriteSwfID(img,wsize,hsize,id)
{
	document.write("<object id=\""+id+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\""+wsize+"\" height=\""+hsize+"\">");
	document.write("<param name=\"movie\" value=\""+img+"\">");
	document.write("<param name=\"quality\"  value=\"high\">");
	document.write("<param name=\"wmode\"  value=\"transparent\">");
	document.write("<embed src=\""+img+"\" name=\""+id+"\" wmode=\"transparent\" swliveconnect=\"true\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\""+wsize+"\" height=\""+hsize+"\"></embed>");
	document.write("</object>");
}

function WriteSwfIDVar(img,wsize,hsize,id,Var)
{
 document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0\" WIDTH=\""+wsize+"\" HEIGHT=\""+hsize+"\" ID=\""+id+"\">");
 document.write("<PARAM NAME=\"MOVIE\" VALUE=\""+img+"\">");
 document.write("<PARAM NAME=\"PLAY\" VALUE=\"TRUE\">");
 document.write("<PARAM NAME=\"LOOP\" VALUE=\"TRUE\">");
 document.write("<PARAM NAME=\"WMODE\" VALUE=\"TRANSPARENT\">");
 document.write("<PARAM NAME=\"QUALITY\" VALUE=\"HIGH\">");
 document.write("<PARAM NAME=\"SCALE\" VALUE=\"showall\">");
 document.write("<PARAM name=\"FlashVars\" value=\"" + Var + "\" />"); 
 document.write("<embed src=\""+img+"\" width=\""+wsize+"\" height=\""+hsize+"\" quality=\"high\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" flashvars=\"" + Var + "\"></embed>")
 document.write("</OBJECT>");
}

function divlayer() {
    document.write('<div id="divlayer"></div><div id="divframe">');
    document.write('<table style="height: 100%; width: 100%; _height:700px;" cellpadding="0" cellspacing="0">');
    document.write('<tr><td valign="middle" align="center"><div>');
    document.write('<div id="div_cont_alert">');
    document.write('<div id="div_cont_alert_cab"></div>');
    document.write('<img style="margin:15px;" width="64" height="60" src="/resources/images/ico_alert.jpg" align="left"  />');
    document.write('<div id="div_alert" align="left"></div>');
    document.write('<div align="right" style="height:30px; width:100%; background-color:#D4D4D4;">');
    document.write('<a style="margin-right:10px; margin-top:3px;" id="lnk_accept" href="javascript:closediv();"><img border="0" width="68" height="23" src="/resources/images/alert_acept.gif" /></a>');
    document.write('</div></div><div style="height: 24px;" id="div_cls" align="right"></div>');
    document.write('<div id="div_cont_frame" style="position:relative;"><div align="left" style="position:absolute;top:0px;left:0px;background-color:white;" id="cargando"><img width="20" height="20" style="padding-top:10px;padding-left:10px;" src="/resources/images/ajax_load_small.gif" />Cargando..</div><iframe style="background-color: Black;" scrolling="no" frameborder="0" id="ifrmlayer"></iframe></div>');
    document.write('</div></td></tr></table></div>');
}


function divlayerpromo() {
    document.write('<div id="divlayer_promo"></div><div id="divframe_promo">');
    document.write('<table style="height: 100%; width: 100%; _height:700px;" cellpadding="0" cellspacing="0">');
    document.write('<tr><td valign="middle" align="center"><div>');
    document.write('<div id="div_cont_alert_promo">');
    document.write('<div id="div_cont_alert_cab_promo"></div>');
    document.write('<img style="margin:15px;" width="64" height="60" src="/resources/images/ico_alert.jpg" align="left"  />');
    document.write('<div id="div_alert_promo" align="left"></div>');
    document.write('<div align="right" style="height:30px; width:100%; background-color:#D4D4D4;">');
    document.write('<a style="margin-right:10px; margin-top:3px;" id="lnk_accept" href="javascript:closediv();"><img border="0" width="68" height="23" src="/resources/images/alert_acept.gif" /></a>');
    document.write('</div></div><div style="height: 24px;" id="div_cls" align="right"></div>');
    document.write('<div id="div_cont_frame_promo" style="position:relative;"><div align="left" style="position:absolute;top:0px;left:0px;background-color:white;" id="cargando"><img width="20" height="20" style="padding-top:10px;padding-left:10px;" src="/resources/images/ajax_load_small.gif" />Cargando..</div><iframe style="background-color: Black;" scrolling="no" frameborder="0" id="ifrmlayer_promo"></iframe></div>');
    document.write('</div></td></tr></table></div>');
}


//--------Rotator Home comcel-----------------//
//var widthdiv = document.getElementById("div_slider");
//var widthcon = document.getElementById("div_cont_slider");
var stops = false;
function moveup() {
 widthdiv = document.getElementById("div_slider");
 widthcon = document.getElementById("div_cont_slider");
    if (parseInt(widthdiv.style.left) > (parseInt(widthcon.style.width) - parseInt(widthdiv.style.width)) && !stops) {
        widthdiv.style.left = (parseInt(widthdiv.style.left) - 2) + 'px';
        setTimeout('moveup()', 20);
    }
}

function movedown() {
 widthdiv = document.getElementById("div_slider");
 widthcon = document.getElementById("div_cont_slider");
    if (parseInt(widthdiv.style.left) < 0 && !stops) {
        widthdiv.style.left = (parseInt(widthdiv.style.left) + 2) + 'px';
        setTimeout('movedown()', 20);
    }
}
//--------Rotator Home comcel-----------------//
function changeimg(path, type, content) {
    if (type == '0') {
        if (content == '0')
            $('div_gal').innerHTML = '<img width="315px" height="228px" src="/resources/imagesgalery/' + path + '" border="0" />';
        else
            $('div_gal').innerHTML = '<img width="315px" height="228px" src="/resources/imagesnews/' + path + '" border="0" />';
    }
    else {
        $("player").href = path;
        flowplayer("player", "/resources/images/flowplayer-3.1.5.swf");
    }
}
//gallery//
//participacion//
var status = 0;
var last = 0;
var working = false;
function messageinfo() {
    switch ($('ifoption').value) {
        case "Seccion":
            return " esta sección";
        case "Contenido":
        default:
            return " este contenido";        
    }
}

function displayinfo(voption, h) {
    if (!working) {
        if ($('hf_isauthent').value == "1") {
            next = voption;
            if (last == voption) {
                next = 0;
            }
            if (last == 0) {
                last = voption;
            }
            changevis(voption);
            var divcontent = $('content_action' + last);
            working = true;
            if (voption != $('statemove').value) {
                $('statemove').value = voption;

                if (status == 2 && parseInt(divcontent.style.height) == 0) {
                    status = 0;
                }
                else if (status == 2 && parseInt(divcontent.style.height) > 0) {
                    status = 1;
                }
                if (status != 0) {
                    resize(h, last, voption);
                }
                else {
                    resize(h, last, 0);
                }
            }
            else {
                resizeup(h, voption);
                $('statemove').value = '-1';
            }
            last = next;
        }
        else {
            alerts('Para poder realizar esta acción debes estar logueado.');
        } 
    }
}

function changevis(voption) {
    $('content_action' + voption).style.visibility = 'hidden';
}

function changeinv(voption) {
    $('content_action' + voption).style.visibility = 'visible';
}

function resizeup(height, voption) {
    var divcontent = $('content_action' + voption);
    dh = parseInt(divcontent.style.height);
    if (dh > 0) {
        dh -= 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resizeup(' + height + ', ' + voption + ')', 10);
    }
    else {
        working = false;
    }
}

function resize(height, voption, next) {
    var divcontent = $('content_action' + voption);
    dh = parseInt(divcontent.style.height);
    if (dh == 0) {
        bindcontent(voption);
    }    
    if (dh < height && status == 0) {
        dh += 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resize(' + height + ', ' + voption + ', ' + next + ')', 10);
    }
    else if (dh > 0 && status == 1) {
        dh -= 10;
        divcontent.style.height = dh + 'px';
        setTimeout('resize(' + height + ', ' + voption + ', ' + next + ')', 10);
    }
    else {
        status = 2;
        changeinv(voption);
        if (next != 0) {
            divcontent.innerHTML = "";
            status = 0;
            setTimeout('resize(' + height + ', ' + next + ', 0)', 10);
        }
        else {
            working = false;
        }
    }
}

function loadajax(id) {
    $('content_action' + id).innerHTML = '<div style="margin-top:55px;" align="center"><img src="/resources/images/ajax_load_small.gif" /></div>';
}

function loadmessage(message, id) {
    $('content_action' + id).innerHTML = '<div style="font-size:10px;" align="left"><strong>' + message + '</strong></div>';
}

function bindcontent(voption) {
    var divcontent = $('content_action' + voption);    
    switch (voption) {
        case 1:
            strcaptcha = "";
            if (esIE6() || esIE7()) {
                strcaptcha = "/general/decode.aspx?name=strcaprec";
            } else {
                strcaptcha = "data:image/jpg;base64," + ucaction.SetCaptcha().value;
            }
            divcontent.innerHTML = '<div id="divrecomendar" style="font-size:10px"><div>De:</div><div><strong>' + $('ifusername').value + '</strong></div><div>Para:</div><div><input class="remitentecamp" type="text" name="textfield" id="txt_para" maxlength="50" /></div><div>Correo:</div><div><input class="remitentecamp" type="text" name="textfield2" id="txt_correo" maxlength="50" /></div><div>Comentario</div><div style="background-image:url(resources/images/bg_campo_men.jpg); width:136px; height:66px;"><textarea onKeyPress="CountTextArea(this, 200);return AceptaVarchar(event);" onchange="CountTextArea(this, 200);" id="txtcom_a" style="width:185px; height:58px; border:1px solid #d3d3d3; margin-top:2px;"></textarea></div><div><img id="imgCaptchaRecom" src="' + strcaptcha + '" style="border: 1px solid black;vertical-align:middle;margin-left:3px;margin-top:4px;" /><input type="text" maxlength="6" id="txtCaptchaRec" class="caracteres" style="margin-left: 5px; vertical-align: middle;"></div><div style="margin-top:3px;"><a href="javascript:enviaamigo();"><img border="0" src="/resources/images/bt_men.gif" /></a></div></div>';
            break;
        case 2:            
            divcontent.innerHTML = '<div class="stars" style="margin-top:4px;"><div id="star1" title="Muy malo" class="off" onclick="pool(1)" onmouseover="change(0)" onmouseout="limpia()" ></div><div id="star2" title="Malo" class="off" onclick="pool(2)" onmouseover="change(1)" onmouseout="limpia()" ></div><div id="star3" title="Regular" class="off" onclick="pool(3)" onmouseover="change(2)" onmouseout="limpia()" ></div><div id="star4" title="Bueno" class="off" onclick="pool(4)" onmouseover="change(3)" onmouseout="limpia()" ></div><div id="star5" title="Excelente" class="off" onclick="pool(5)" onmouseover="change(4)" onmouseout="limpia()" ></div><div id="div_res" style="float:left;font-size:11px;"></div></div>';
            break;
        case 3:
            var url = window.location;
            ucaction.redes(url, bindcontent_CallBack);
            break;
        case 4:
            divcontent.innerHTML = '<div style="font-size:10px">Para agregar este contenido a tus favoritos haz click <a href="javascript:favoritos();">aqui</a></div>';
            break;
    }
}


function AceptaVarchar(evt) {

        if(AceptaNumero(evt)||AceptaVarchar1(evt))
        {
            return true;
        }
        else
            return false;
    }

        function AceptaNumero(evt) {
        var nom = navigator.appName;
        var key = 0;
        if (nom.indexOf("Microsoft Internet Explorer") < 0) {
            key = evt.which;
        }
        else {
            key = evt.keyCode;
        }
        return (key <= 13 || (key >= 48 && key <= 57));

    }
    function AceptaVarchar1(evt) {
        var nom = navigator.appName;
        var key = 0;
        if (nom.indexOf("Microsoft Internet Explorer") < 0)
            key = evt.which;
        else
            key = evt.keyCode;
        return (key <= 13 || key == 46 || key == 180 || key == 32 ||
           (key >= 97 && key <= 122) || (key >= 65 && key <= 90) ||
           (key >= 193 && key <= 250));
           }
           
function bindcontent_CallBack(response) {
    imgs = response.value;
    var divcontent = $('content_action3');
    divcontent.innerHTML = '<div style="padding-top:10px;" class="compartir">' + imgs + '</div>';
}

function pool(quality) {
    var idctn = $('ifid').value;
    var option = $('ifoption').value;
    loadajax(2);
    ucaction.pool(quality, option, idctn, pool_CallBack);
}

function pool_CallBack(response) {
    var result = response.value;
    if (result == -1)
        loadmessage('No se pudo ingresar tú calificación.', 2);
    else if (result == 0)
        loadmessage('Ya calificaste' + messageinfo(), 2);
    else
        loadmessage('Gracias por calificar' + messageinfo(), 2);
    setTimeout("displayinfo(2, 0);", 3000);
}

function change(va1) {
    var asd = new Array('star1', 'star2', 'star3', 'star4', 'star5');
    ruta1 = "on";
    ruta2 = "off";
    var cadena = '';
    for (i = va1 + 1; i < 5; i++) {
        $(asd[i]).className = ruta2;
    }
    for (j = va1; j >= 0; j--) {
        $(asd[j]).className = ruta1;
    }
    $('div_res').innerHTML = "&nbsp;"+$(asd[va1]).title;
}

function limpia() {
    var asd = new Array('star1', 'star2', 'star3', 'star4', 'star5');
    ruta2 = "off";
    for (j = 0; j < 5; j++) {
        $(asd[j]).className = ruta2;
    }
    $('div_res').innerHTML = '';
}

function replic(idreplica) {
    if ($('hf_isauthent').value == "1") {
        $('ifreplica').value = idreplica;
        $('divres_' + idreplica).innerHTML = '<iframe id="frm_wy" scrolling="no" frameborder="0" width="620px" height="130px" src="general/wysiwyg.htm"></iframe><a href="javascript:replicar();"><img style="margin-left:5px;" border="0" src="/resources/images/bt_com.gif" /></a>';
        $('divres_' + idreplica).style.display = 'block';
    }
    else
        alerts('Para poder realizar esta acción debes estar logueado.');
}

function replicar() {
    var idctn = $('ifid').value;
    var option = $('ifoption').value;
    var coment = $('frm_wy').contentWindow.getvalue();
    var iduser = $('idusercontent').value != '' ? $('idusercontent').value : '0';
    var idreplica = $('ifreplica').value;
    if (coment != '') {
        ucaction.comentar(coment, option, idctn, idreplica, iduser, replicar_CallBack);
    }
    else
        alerts('Debes ingresar un comentario.');
}

function replicar_CallBack(response) {
    var result = response.value;
    $('div_com').innerHTML = result;
    $('ifreplica').value = '0';
}

function votef(idcom, votos, tipo) {
    if ($('hf_isauthent').value == "1") {
        total = parseInt(votos) + 1;
        ucaction.voteup(idcom, total, tipo);
        $('lnk_f_' + idcom).innerHTML = '(' + total + ') Votos a favor';
        $('lnk_f_' + idcom).href = 'javascript:;';
        $('lnk_c_' + idcom).href = 'javascript:;';
    }
    else {
        alerts('Debes estar logueado para poder votar.')
    }
}

function votec(idcom, votos, tipo) {
    if ($('hf_isauthent').value == "1") {
        total = parseInt(votos) + 1;
        ucaction.votedown(idcom, total, tipo);
        $('lnk_c_' + idcom).innerHTML = '(' + total + ') Votos en contra';
        $('lnk_c_' + idcom).href = 'javascript:;';
        $('lnk_f_' + idcom).href = 'javascript:;';
    }
    else {
        alerts('Debes estar logueado para poder votar.');
    }
}

function favoritos() {
    var idctn = $('ifid').value;
    loadajax(4);
    ucaction.favorito(idctn, favoritos_CallBack);
}

function favoritos_CallBack(response) {
    var result = response.value;
    if (result == -1)
        loadmessage('No se pudo agregar a tus favoritos.', 4);
    else if (result == 0)
        loadmessage('Este ya se encuentra dentro de tus favoritos.', 4);
    else
        loadmessage('Se ha agregado a tus favoritos', 4);
    setTimeout("displayinfo(4, 0);", 3000);
}
var coment = "";
function enviaamigo() {
    if ($('txt_para').value == '') {
        alerts('Debes ingresar el nombre de tu amigo');
        return;
    }
    else if ($('txt_correo').value == '') {
        alerts('Debes ingresar el correo de tu amigo');
        return;
    }
    else if (!ValidMail($('txt_correo').value)) {
        alerts('Debes ingresar un correo v&aacute;lido');
        return;
    }
    else if ($('txtcom_a').value == '') {
        alerts('Debes ingresar un comentario');
        return;
    }
    else if ($('txtCaptchaRec').value == '') {
        alerts('Debes ingresar el c&oacute;digo de confirmaci&oacute;n');
        return;
    }
    else {
        var para = $('txt_para').value;
        var correo = $('txt_correo').value;
        coment = $('txtcom_a').value;
        var captcha = $('txtCaptchaRec').value;
        titulo = window.document.title;
        $("ifdivclone").appendChild($('divrecomendar').cloneNode(true));
        loadajax(1);
        idcontent = 0;
        if($('ifoption').value == "Contenido")
            idcontent = parseInt($('ifid').value);
        else
            idcontent = parseInt($('idpln').value);
        ucaction.enviomsg($('ifoption').value, idcontent, para, correo, window.location, coment, titulo, captcha, sendemail_CallBack);
    }
}

function sendemail_CallBack(response) {    
    var result = response.value;
    if (result == -1) {
        loadmessage('No se pudo enviar el mensaje. Intentalo más tarde.', 1);
        setTimeout("displayinfo(1, 0);", 3000);
    }
    else if (result == -2) {
        if (esIE6() || esIE7()) {
            strcaptcha = "/general/decode.aspx?name=strcaprec";
        } else {
            strcaptcha = "data:image/jpg;base64," + ucaction.SetCaptcha().value;
        }
        alerts('C&oacute;digo de confirmaci&oacute;n incorrecto');
        $('content_action1').innerHTML = "";
        $('content_action1').appendChild($('divrecomendar').cloneNode(true));
        $('txtcom_a').value = coment;
        $('imgCaptchaRecom').src = strcaptcha;
        $('ifdivclone').innerHTML = "";
    }
    else {
        loadmessage('Tu mensaje fue enviado satisfactoriamente.', 1);
        setTimeout("displayinfo(1, 0);", 3000);
        setTimeout("document.location.href=document.location.href;",2500);
    }    
}

function reportcom(idcom) {
    if ($('hf_isauthent').value == "1") {
        var url = window.location.toString();
        var strurl = '/divlayer/dlreportar.aspx?idc=' + idcom + '&op=' + $('ifoption').value + '&url=' + url.replace(/&/gi, '%26');
        opendiv('400px', '180px', strurl, 0);
    }
    else {
        alerts('Para poder realizar esta acción debes estar logueado.');
    }
}

function recoverypassword() {
    opendiv('400px', '180px', '/divlayer/dlpassword.aspx', 0)
}

function deletecom(idcom) {
    if (confirm('¿Estas seguro que deseas eliminar el comentario?')) {
        var tipo = $('ifoption').value;
        var id = $('ifid').value;
        var iduser = $('idusercontent').value != '' ? $('idusercontent').value : '0';
        ucaction.delcomentario(idcom, tipo, id, iduser, deletecom_CallBack);
    }
}

function deletecom_CallBack(response) {
    var result = response.value;
    $('div_com').innerHTML = result;
}
//participacion//
function hideobj(idobj) {
    if ($(idobj).style.display == 'none')
        $(idobj).style.display = 'block';
    else
        $(idobj).style.display = 'none';
}


function opendiv(width, heigh, url, postback) {
    var alto;
    if (window.screen.height > document.body.scrollHeight)
        alto = window.screen.height;
    else
        {
        alto = document.body.scrollHeight;
        }
    /*var navegador = navigator.appName
    if (navegador != "Microsoft Internet Explorer") 
    {
        alert(document.body.clientHeight);
        alto= document.body.clientHeight;
    }*/
   
    yWithScroll = 0;
    xWithScroll = 0;
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    
    
	$("div_cls").style.display = 'block';
    $("div_cont_alert").style.display = 'none';
    $("div_cont_frame").style.display = 'block';
    $("div_cont_frame").style.visibility ="visible";
	$("ifrmlayer").style.display = 'block';
	$('divlayer').style.display = 'block';
    $('divframe').style.display = 'block';
    $('divlayer').style.height = yWithScroll + 'px';
    $('divlayer').style.width = '100%';
    $("ifrmlayer").src = url;
    $("ifrmlayer").height = heigh;
    $("ifrmlayer").width = width;
    $("div_cont_frame").style.height = heigh;
    $("div_cont_frame").style.width = width;
    $("cargando").style.height = heigh;
    $("cargando").style.width = width;
    $("cargando").style.display = 'none';
	$("div_cls").style.width = width;
    window.scrollTo(0, 0);
}


function closediv() {
    $('divlayer').style.display = 'none';
    $('divframe').style.display = 'none';
    if($("ifrmlayer").src.indexOf("dldistribuidores.aspx")==-1)
    {
    $("ifrmlayer").src = '/resources/images/ajax_load_small.gif';
    }
    else
    {
    history.back(1);
    }
    
    $("div_cont_frame").style.display = 'none';
}

function alerts(message)
{
    
    yWithScroll = 0;
    xWithScroll = 0;
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    
    $("divlayer").style.height = yWithScroll + "px";
    $("divlayer").style.width = xWithScroll + "px";
    $("divlayer").style.display = 'block';
	$("divframe").style.display = 'block';
	$("div_cls").style.display = 'none';
	$("div_cont_frame").style.display = 'none';
	$("div_cont_frame").style.visibility ="hidden";
	$("ifrmlayer").style.display = 'none';
	$("div_cont_alert").style.display = 'block';
	$("div_alert").innerHTML = message;
	$("lnk_accept").focus();
	window.scrollTo(0, 0);
	
}
///click sobre el boton buscar
function findportal(url) {
    
    if ($('inp_find').value != '' && $('inp_find').value != 'Busqueda Comcel' && /^[\w* áéíóúÁÉÝÓÚ]+$/.test($('inp_find').value)) {
        //window.location = "/Default.aspx?scc=" + Request('scc', url) + "&opt=ucbusqueda&key=" + $('inp_find').value+"&title=busqueda";
        scc="13";
        if(url.indexOf("scc")>-1) 
            {
            scc=Request('scc', url);
            }
        window.location = "/scc/" + scc + "/opt/ucbusqueda/key/" + $('inp_find').value+"/title/busqueda-"+$('inp_find').value;
    }
    else {
        alerts('Debes ingresar un criterio de b&uacute;squeda v&aacute;lido.');
    }
}
///enter sobre la caja de texto de busqueda
function findsubm(e,url) {

    
    var k = null;
    (e.keyCode) ? k = e.keyCode : k = e.which;
    if (k == 13) {
        g('BuscadorEnter');
        findportal(url);
        e.cancelBubble = true;
        e.returnValue = false;
        return false;
    }

  
}

function validateimgs(value) {
    var b = value.split('.');
    var valid = /^(gif|jpg|png|swf)$/.test(b[b.length - 1].toLowerCase());
    return valid;
}

function validatefiles(value) {
    var b = value.split('.');
    var valid = /^(exe|dll)$/.test(b[b.length - 1].toLowerCase());
    return !valid;    
}



function logInsub(e) {
try{
    var k = null;
    (e.keyCode) ? k = e.keyCode : k = e.which;
    if (k == 13) {
        logIn();
        e.cancelBubble = true;
        e.returnValue = false;
    }
   }
   catch(execScri)
   {}
}

function logIn() {
    if ($('user').value != '' && $('pass').value != '') {
        loguin.authentic($('user').value, $('pass').value, logIn_CallBack);
    }
    else {
        alerts('Debes ingresar tu correo y contraseña.');
    }
}

function logIn_CallBack(response) {
    var result = response.value;
    if (result == 1)
    {
       document.location.href = document.location.href.replace("#anclaBoton","");
    }
    else if (result == 2)
    {
        alerts('Verifica que tu correo y contraseña est&eacute;n bien digitados.');
    }
    else
    {
        
    }
}

function closesession() {
    loguin.closesesion();
    document.location.href = document.location.href.replace("#anclaBoton","");
}

function nameadmin(value) {
try{
    if ($('spn_admin') != null) {
        $('spn_admin').innerHTML = value;
    }
 }
   catch(execScri)
   {}
}

contenido_textarea = ""
function valida_longitud(num_caracteres_permitidos, NameControl) {
    var objtxtArea = $(NameControl);
    num_caracteres = objtxtArea.value.length

    if (num_caracteres <= num_caracteres_permitidos) {
        contenido_textarea = objtxtArea.value
    } else {
        objtxtArea.value = contenido_textarea
    }
}

//Examinar
addEvent = function(obj, type, fn) {
    if (obj.addEventListener)
        obj.addEventListener(type, fn, false);
    else if (obj.attachEvent) {
        obj["e" + type + fn] = fn;
        obj[type + fn] = function() { obj["e" + type + fn](window.event); };
        obj.attachEvent("on" + type, obj[type + fn]);
    }
}
bc_newElement = function(tag) {
    return document.createElement(tag);
}
bc_getElement = function(id) {
    return document.getElementById(id);
}

var field_count = 1;
var optionvald = 1;
bc_init = function(fileId, displayId) {
    try {
        field = bc_getElement(fileId);
        field.display = bc_getElement(displayId);

        if (!field || !field.type || field.type != 'file' || !field.display) return;

        addEvent(field, 'change', bc_addField);
    } catch (ex) { bc_handleError(ex); }
}

bc_load = function(fileId, displayId, optio) {
    optionvald = optio;
    addEvent(window, 'load', new Function("bc_init('" + fileId + "', '" + displayId + "');"));
}
bc_addField = function() {
    var obj = $(this.id);
    if (optionvald == 1) {
        var namefile = obj.value.toString();
        if (!validateimgs(namefile)) {
            alerts("Solo se permiten archivos tipo imagen (jpg, gif o png).");
            return;
        }
    }
    else {
        if (!validatefiles(obj.value)) {
            alerts("No se permiten archivos ejecutables.");
            return;
        }
    }

    if (this.id.indexOf('ifEx') == -1) {
        try {
            new_field = bc_newElement('INPUT');
            new_field.type = 'file';
            new_field.id = new_field.name = this.id.replace(/-@bc-.*$/g, "") + '-@bc-' + field_count++;
            new_field.className = 'file';
            new_field.display = this.display;
            addEvent(new_field, 'change', bc_addField);

            this.parentNode.insertBefore(new_field, this);

            li = bc_newElement('LI');

            a = bc_newElement('A');
            a.href = "#";
            a.appendChild(document.createTextNode('Quitar'));
            a.field_id = this.id;
            addEvent(a, 'click', bc_removeField);

            li.appendChild(a);
            li.appendChild(document.createTextNode('  ' + this.value.substring(this.value.search(/[^\/\\]+$/))));
            this.display.appendChild(li);

            this.style.position = 'absolute';
            this.style.left = '-1000px';
        } catch (ex) { bc_handleError(ex); }
    }
    else {
        document.getElementById('txtExaminar').value = this.value;
    }
}
bc_removeField = function(event) {
    try {
        (del = bc_getElement(this.field_id)).parentNode.removeChild(del);

        this.parentNode.parentNode.removeChild(this.parentNode);
        if (event && event.preventDefault)
            event.preventDefault();
        return false;
    } catch (ex) { bc_handleError(ex); }
}
bc_handleError = function(ex) { alert(ex); }

function dur() {
    var ids = document.getElementsByTagName('LI');
    alert(ids.length)
}
//Fin Examin
function agregaramigo(idrel) {
    if ($('hf_isauthent').value == '1')
        ucgrupos.agregaramigo(idrel, agregaramigo_CallBack);
    else
        alerts('Debes estar logueado para ejecutar esta acción.');
}

function agregaramigo_CallBack(response) {
    var result = response.value;
    if (result == 1)
        alerts('Has agregado satisfactoriamente como amigo.');
    else if (result == 2)
        alerts('Ya has agregado como amigo.');
    else if (result == 3)
        alerts('No puedes agregarte como amigo.');        
    else
        alerts('No se pudo agregar como amigo.');
}

function blurfind(obj) {
    if (obj.value == '')
        obj.value = 'Busqueda Comcel';
}

function ofertinsert(idctn) {
    ucoferta.aplicaoferta(idctn, ofertinsert_CallBack);
}

function ofertinsert_CallBack(response) {
    var result = response.value;
    if (result == 1)
        alerts('Has aplicado a la oferta satisfactoriamente.');
    else if (result == 2)
        alerts('Ya has aplicado a esta oferta.');
    else
        alerts('El sistema esta ocupado, intenta aplicar mas tarde.');
}

function changefilter(result, idoption, idbtn) {
    $(idoption).value = result;
    $(idbtn).click();
    $('al1').className = '';
    $('al2').className = '';
    $('al3').className = '';

    if (result == 0) {
        $('al1').className = 'selected';
    }
    else if (result == 1) {
        $('al2').className = 'selected';
    }
    else if (result == 2) {
        $('al3').className = 'selected';
    }
}

function CheckComcelMIN(min) {
    if (min.length > 0) {
        switch (min.substring(0, 3)) {
            case "310":
            case "311":
            case "312":
            case "313":
            case "314":
            case "320":
            case "321":
                return true;
            default:
                return false;
        }
    } else {
        return true;
    }
}

function CountTextArea(obj, count) {
    obj.value = obj.value.substring(0, count);
}

function CountSMS() {
    max = 159;
    txtaMensaje = document.getElementById("txtaMensaje");
    txtRemitente = document.getElementById("txtRemitente");
    txtCaracteres = document.getElementById("incaracteres");

    now = txtaMensaje.value.length + txtRemitente.value.length;
    if (max >= now) {
        txtCaracteres.value = max - now;
        return true;
    }
    txtaMensaje.value = txtaMensaje.value.substring(0, max - txtRemitente.value.length);
}

function getRadioButtonSelectedValue(ctrl) {
    for (i = 0; i < ctrl.length; i++)
        if (ctrl[i].checked) return ctrl[i].value;
}


function getCheckBoxSelectedValue(ctrl) {
    var checks = "";
    for (i = 0; i < ctrl.length; i++) {

        if (ctrl[i].checked) {
        
            if (checks != "")
                checks += ",";

            checks += ctrl[i].value;
        }
    }

    return checks;
}

function countCheckBoxSelected(ctrl) {
    var checks = 0;
    for (i = 0; i < ctrl.length; i++) {

        if (ctrl[i].checked) {
            checks++;
        }
    }
    return checks;
}


function esInternetExplorer() {

    var explo = navigator.appName == "Microsoft Internet Explorer";
    return explo;
}

function esIE8() {

    if (esInternetExplorer()) {
        var useragent = navigator.appVersion;
        var version = useragent.split(';')[1];
        return version.indexOf("MSIE 8.0") == 1;
    }
    return false;
}

function esIE6() {

    if (esInternetExplorer()) {
        var useragent = navigator.appVersion;
        var version = useragent.split(';')[1];
        return version.indexOf("MSIE 6") == 1;
    }
    return false;
}

function esIE7() {

    if (esInternetExplorer()) {
        var useragent = navigator.appVersion;
        var version = useragent.split(';')[1];
        return version.indexOf("MSIE 7.0") == 1;
    }
    return false;
}

function NumericValidation(e, obj) {
    findPositions(obj);
    value = obj.value;
    tecla = (document.all) ? e.keyCode : e.which;
    if (tecla == 8 || tecla == 0) return true;

    start = getSelectionStart(obj);
    end = getSelectionEnd(obj);

    if (start == end) {
        str = value.substring(0, start) + String.fromCharCode(tecla) + value.substring(start);
    }
    else {
        str = value.substring(0, start) + String.fromCharCode(tecla) + value.substring(end);
    }

    if (str.match(/[0-9]*/) == str) {
        return true;
    }
    else {
        return false;
    }

    return true;
}

function TextValidator(e, obj) {    
    findPositions(obj);
    value = obj.value;
    tecla = (document.all) ? e.keyCode : e.which;
    strpermitido =",8,0,241,209,225,193,233,201,237,205,243,211,250,218,";
    if (strpermitido.indexOf(","+tecla+",")>-1) return true;

    start = getSelectionStart(obj);
    end = getSelectionEnd(obj);

    if (start == end) {
        str = value.substring(0, start) + String.fromCharCode(tecla) + value.substring(start);
    }
    else {
        str = value.substring(0, start) + String.fromCharCode(tecla) + value.substring(end);
    }
    if (str.match(/[A-Za-z0-9 -!"#$%&'()*+,./:;=?@[\\\]^_`{|}~]*/) == str) {
        return true;
    }
    else {
        return false;
    }

    return true;
}

function getSelectionStart(o) {
    if (o.createTextRange) {
        r = document.selection.createRange().duplicate()
        r.moveEnd('character', o.value.length)
        if (r.text == '') {
            return o.value.length
        }
        return o.value.lastIndexOf(r.text)
    }
    else {
        return o.selectionStart
    }
}

function getSelectionEnd(o) {
    if (o.createTextRange) {
        r = document.selection.createRange().duplicate()
        r.moveStart('character', -o.value.length)
        return r.text.length
    }
    else {
        return o.selectionEnd
    }
}


function findPositions(obj) {
    var text = obj.value;

    if (document.selection) {
        // Internet Explorer
        var range = document.selection.createRange();
        var dpl = range.duplicate();
        if (range.text.length > 0) {
            dpl.moveToElementText(obj);
            dpl.setEndPoint("EndToEnd", range);
            startPosition = dpl.text.length - range.text.length;
            endPosition = startPosition + range.text.length;
        }
    }
    else {
        // Mozilla Firefox
        startPosition = obj.selectionStart;
        endPosition = obj.selectionEnd;
    }
}
function pagerblocks(show, hide) {
    $("pgb_" + hide).style.display = "none";
    $("pgb_" + show).style.display = "";
}

function content_print(id) {
    obj = $(id);
    strHTML = ""
    
    arrlink = document.getElementsByTagName("link");
    for (i = 0; i < arrlink.length; i++) {
        strHTML += getOuterHTML(arrlink[i]);
    }
    strHTML += getOuterHTML(obj);

    printer.document.body.innerHTML = strHTML;
    printer.focus();
    printer.print();
    g('imprimir-'+id);
}

function getOuterHTML(object) {    
    var element;
    if (!object) return null;
    element = document.createElement("div");
    element.appendChild(object.cloneNode(true));
    return element.innerHTML;
}

function ValidMail(str) {
    if (str.match(/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/)) {
        return true;
    } else {
        return false;
    }
}

///funcion que ejecuta el loguin de un usuario al oprimir la tecla enter
function AccionEnter(evt) 
    {
        var nom = navigator.appName;
        var key = 0;
        if(nom.indexOf("Microsoft Internet Explorer")<0)
                key = evt.which
        else
                key = evt.keyCode
        
        if(key == 13)
            {
            g('AutenticacionEnter');
            document.getElementById("ingresar").click();       
            return false;
            }
        else
            return true;
    }


//Detectar el cierre de pestañas y de la ventana (no funciona cuando se refresca la pagina)
//window.onbeforeunload  = catchCloseEvent
//document.onmousemove = catchMouseMoveEvent;
var posx = 0;
var posy = 0;
function catchCloseEvent()
{
if(posy<3)
    {
    //implentar cerrar session 
    }
}
function catchMouseMoveEvent(e) {
	
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
}

// Codigo DivLayer Promociones

function opendivpromo(width, heigh, url, postback) {
    var alto;
    if (window.screen.height > document.body.scrollHeight)
        alto = window.screen.height;
    else
        {
        alto = document.body.scrollHeight;
        }
    /*var navegador = navigator.appName
    if (navegador != "Microsoft Internet Explorer") 
    {
        alert(document.body.clientHeight);
        alto= document.body.clientHeight;
    }*/
   
    yWithScroll = 0;
    xWithScroll = 0;
    if (window.innerHeight && window.scrollMaxY) {// Firefox
        yWithScroll = window.innerHeight + window.scrollMaxY;
        xWithScroll = window.innerWidth + window.scrollMaxX;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        yWithScroll = document.body.scrollHeight;
        xWithScroll = document.body.scrollWidth;
    } else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
        yWithScroll = document.body.offsetHeight;
        xWithScroll = document.body.offsetWidth;
    }
    
    
	$("div_cls_promo").style.display = 'block';
    $("div_cont_frame_promo").style.display = 'block';
    $("div_cont_frame_promo").style.visibility ="visible";
	$("ifrmlayer_promo").style.display = 'block';
	$('divlayer_promo').style.display = 'block';
    $('divframe_promo').style.display = 'block';
    $('divlayer_promo').style.height = yWithScroll + 'px';
    $('divlayer_promo').style.width = '100%';
    $("ifrmlayer_promo").src = url;
    $("ifrmlayer_promo").height = heigh;
    $("ifrmlayer_promo").width = width;
    $("div_cont_frame_promo").style.height = heigh;
    $("div_cont_frame_promo").style.width = width;
    $("cargando_promo").style.height = heigh;
    $("cargando_promo").style.width = width;
    $("cargando_promo").style.display = 'none';
	$("div_cls_promo").style.width = width;
    window.scrollTo(0, 0);
}


function closedivpromo(){
	
    $('divlayer_promo').style.display = 'none';
    $('divframe_promo').style.display = 'none';
    if($("ifrmlayer_promo").src.indexOf("/divlayer/Promocion.aspx")==-1)
    {
    $("ifrmlayer_promo").src = '/resources/images/ajax_load_small.gif';
    }
    else
    {
    history.back(1);
    }
    
    $("div_cont_frame_promo").style.display = 'none';
}


function closelayer(){
	
    $('divlayer_promo').style.display = 'none';
    $('divframe_promo').style.display = 'none';
    if($("ifrmlayer_promo").src.indexOf("/divlayer/Promocion.aspx")==-1)
    {
    $("ifrmlayer_promo").src = '/resources/images/ajax_load_small.gif';
    }
    
    $("div_cont_frame_promo").style.display = 'none';
}





