﻿var ctlCentral = "ctl00_content1_";
var ctlMenu = "ctl00_menu1_";

function loginUsuario() {
    if (checkLogin()) {
        document.forms[0].action = "inicio_perfil.aspx";
        document.forms[0].submit();
    }
}

function checkLogin() {
    var ok = true;
    var txtLogin = document.getElementById("txtLogin");
    var txtPwd = document.getElementById("txtPwd");

    if (txtLogin.value != "") {
        if (txtPwd.value != "") {

        } else {
            ok = false;
        }
    } else {
        ok = false;
    }
    return ok;
}

function logout() {

}

function confirma(texto) {
    var ok = false;
    var opcion = confirm(texto);
    if (opcion == true) {
        ok = true;
    }

    return ok;
}

function cargaControles(ctls) {
    var ctlYVal = new Array(2);

    try {
        for (var i = 0; i < ctls.length; i++) {
            ctlYVal = ctls[i].split(sepGra);
            ponValsCtlsForm(ctlYVal[0], ctlYVal[1]);
        }
    } catch (e) { }
}

function muestraComu(tipo) {
    var selPais, selComu, selProv, tituloComu, tituloProv;

    switch (tipo) {
        case "ubicacion":
            selPais = document.getElementById("selPaisUbic");
            if (selPais == null) {
                selPais = document.getElementById("selPaisUbicBas");
                tituloComu = document.getElementById("spaComuAutoUbicBas");
                selComu = document.getElementById("selComuAutoUbicBas");
                selProv = document.getElementById("selProvUbicBas");
                tituloProv = document.getElementById("spaProvUbicBas");
            } else {
                tituloComu = document.getElementById("spaComuAutoUbic");
                selComu = document.getElementById("selComuAutoUbic");
                selProv = document.getElementById("selProvUbic");
                tituloProv = document.getElementById("spaProvUbic");
            }
            if (selPais.options[selPais.selectedIndex].value == "73") {
                selComu.selectedIndex = 0;
                selComu.style.visibility = "visible";

                tituloComu.style.display = "inline";
            } else {
                tituloComu.style.display = "none";
                selComu.style.visibility = "hidden";
                selProv = document.getElementById("selProvUbic");
                tituloProv = document.getElementById("spaProvUbic");
                tituloProv.style.display = "none";
                selProv.style.visibility = "hidden";
            }
            break;
        case "viaje":
            break;
    }
}

function muestraProv(tipo) {
    var sel, titulo, hidProv, selProv, opcion;
    var encontrado = false;
    var terminar = false;

    switch (tipo) {
        case "ubicacion":
            sel = document.getElementById("selComuAutoUbic");
            if (sel == null) {
                sel = document.getElementById("selComuAutoUbicBas");
                titulo = document.getElementById("spaProvUbicBas");
                selProv = document.getElementById("selProvUbicBas");
                hidProv = document.getElementById(ctlCentral + "hidSelProvUbicBas");
            } else {
                titulo = document.getElementById("spaProvUbic");
                selProv = document.getElementById("selProvUbic");
                hidProv = document.getElementById("hidSelProv") == null ? document.getElementById(ctlCentral + "hidSelProv") : document.getElementById("hidSelProv");
            }
            if (sel.options[sel.selectedIndex].value != "0") {
                titulo.style.display = "inline";
                selProv.style.visibility = "visible";
                var datos = hidProv.value.split(sepElem);
                var bloc, txtValProv;
                selProv.length = 0;

                /*opción en blanco */
                opcion = document.createElement("option");
                opcion.value = "0";
                nOpcion = document.createTextNode("");
                opcion.appendChild(nOpcion);
                selProv.appendChild(opcion);

                for (var i = 0; i < datos.length && !terminar; i++) {
                    bloc = datos[i].split(sepVal);
                    if (bloc[1] == sel.options[sel.selectedIndex].value) {
                        txtValProv = bloc[0].split(sepGrid);
                        opcion = document.createElement("option");
                        opcion.value = txtValProv[1];
                        nOpcion = document.createTextNode(txtValProv[0]);
                        opcion.appendChild(nOpcion);
                        selProv.appendChild(opcion);
                        encontrado = true;
                    } else if (encontrado) {
                        terminar = true;
                    }
                }
            } else {
                titulo.style.display = "none";
                selProv.style.visibility = "hidden";
            }
            break;
        case "viaje":
            break;
    }
}

function continuaReg() {
    if (checkReg()) {
        document.forms[0].action = "registro.aspx";
        document.forms[0].submit();
    }
}

function checkReg() {
    var ok = true;
    var elem;

    //txtNickReg, txtEmailReg, txtPwdReg, txtPwdRepReg, selDia, selMes, selAnyo, tipoPer
    elem = document.getElementById("txtNickReg");
    if (ok && elem.value == "") {
        alert("Introduce el Nick");
        ok = false;
    }
    elem = document.getElementById("txtEmailReg");
    if (ok && elem.value == "") {
        alert("Introduce el E-mail");
        ok = false;
    } else if (ok && !esMailValido(elem.value)) {
        alert("El formato del E-mail es incorrecto");
        ok = false;
    }
    elem = document.getElementById("txtPwdReg");
    if (ok && elem.value == "") {
        alert("Introduce una contraseña");
        ok = false;
    }
    elem = document.getElementById("txtPwdRepReg");
    if (ok && elem.value == "") {
        alert("Repite la contraseña");
        ok = false;
    }
    if (ok && getCtl("txtPwdReg").value != getCtl("txtPwdRepReg").value) {
        alert("Las contraseñas no coinciden");
        ok = false;
    }
    if (ok && (getCtl("selDia").selectedIndex == 0 || getCtl("selMes").selectedIndex == 0 || getCtl("selAnyo").selectedIndex == 0)) {
        alert("Rellena la fecha de nacimiento");
        ok = false;
    }
    if (ok && !checkOver18("")) {
        alert("Debes ser mayor de 18 años");
        ok = false;
    }

    return ok;
}

function checkOver18(ctl) {
    var selDia = document.getElementById(ctl + "selDia");
    var selMes = document.getElementById(ctl + "selMes");
    var selAnyo = document.getElementById(ctl + "selAnyo");
    var dia = parseInt(selDia.options[selDia.selectedIndex].value);
    var mes = parseInt(selMes.options[selMes.selectedIndex].value - 1);
    var anyo = parseInt(selAnyo.options[selAnyo.selectedIndex].value);
    var fechaNac = document.getElementById("hidFechaNac");

    var fecha = new Date();
    fecha.setFullYear(anyo, mes, dia);
    var hoy = new Date();
    var ok = false;

    if (hoy.getFullYear() - fecha.getFullYear() > 18)
        ok = true;
    else if (hoy.getFullYear() - fecha.getFullYear() == 18) {
        if (hoy.getMonth() >= fecha.getMonth()) {
            if (hoy.getDate() >= fecha.getDate()) {
                ok = true;
            }
        }
    }

    if (ok) {
        fechaNac.value = formatoDate(fecha, "dd/MM/yyyy");
    }

    return ok;
}

function formatoDate(vDate, vFormat) {
    var vDay = addZero(vDate.getDate());
    var vMonth = addZero(vDate.getMonth() + 1);
    var vYearLong = addZero(vDate.getFullYear());
    var vYearShort = addZero(vDate.getFullYear().toString().substring(3, 4));
    var vYear = (vFormat.indexOf("yyyy") > -1 ? vYearLong : vYearShort);
    var vHour = addZero(vDate.getHours());
    var vMinute = addZero(vDate.getMinutes());
    var vSecond = addZero(vDate.getSeconds());
    var vDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear)
    vDateString = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond)
    return vDateString;
}

function addZero(vNumero) {
    return ((vNumero < 10) ? "0" : "") + vNumero;
}

function checkfinalizaReg(cambios) {
    ok = true;
    var hayDato = false;
    var datos = cambios.split(sepCtl);
    var ctlVal;
    var aceptaCond = document.getElementById("radCondi1");


    // divSelPaisUbic(_){_C_}divSelComuAutoUbic(_){_C_}divSelProvUbic(_){_C_}divTxtPobUbic(_){_C_}divRadOrient(_){_C_}divSelEstSer(_){_C_}divRadVerEstSer(_)
    for (var i = 0; i < 3 && !hayDato; i++) {
        ctlVal = datos[i].split("(_)");
        if (ctlVal[1] != "") hayDato = true;
    }

    if (!hayDato) {
        var txtPob = document.getElementById("txtPobUbic")
        if (txtPob.value == "") {
            alert("Debes seleccionar una ubicación");
            ok = false;
        }
    }

    // Orientación sexual
    if (ok) {
        ctlVal = datos[4].split("(_)");
        if (ctlVal[1] == "") {
            alert("Selecciona tu orientación sexual");
            ok = false;
        }
    }
    // Estado serológico
    if (ok) {
        ctlVal = datos[5].split("(_)");
        if (ctlVal[1] == "") {
            alert("Selecciona una opción en el desplegable 'Estado serológico'");
            ok = false;
        }
    }
    /*
    // Visibilidad estado serológico
    if (ok) {
    ctlVal = datos[6].split("(_)");
    if (ctlVal[1] == "") {
    alert("Marca el tipo de visibilidad para la respuesta\n que has dado en el estado serológico");
    ok = false;
    }
    }
    */
    if (ok && !aceptaCond.checked) {
        ok = false;
        alert("Debes aceptar las condiciones");
    }
    return ok;
}

function finalizaReg() {
    var padre, elems, agrup, ctlsAgrup, hidVal;
    var hidCtls = document.getElementById("hidCtlReg");
    var ctls = hidCtls.value.split(",");
    var cambios = "";
    var params, nomSec, data;
    var encontrado = false;

    for (var i = 0; i < ctls.length; i++) {
        padre = document.getElementById(ctls[i]);
        if (padre == null) padre = document.getElementById(ctlCentral + ctls[i]);
        params = "";
        data = "";
        // miramos el tipo de control(es) que contiene
        switch (ctls[i].substring(3, 6).toLowerCase()) {
            case "sel":
                elems = padre.getElementsByTagName("select");
                //alert(padre.id);
                if (padre.lastChild != null && String(padre.lastChild.id) != "undefined") {
                    //alert(padre.lastChild.id);
                    hidVal = padre.getElementsByTagName("input")[0];
                    if (elems[0].options.length > 0 && elems[0].options[elems[0].selectedIndex].value != "0") {
                        nomSec = elems[0].id;
                        if (hidVal.value == "") {  // lo que enviamos es nuevo
                            data += "N" + sepVal + elems[0].options[elems[0].selectedIndex].value;
                        } else if (elems[0].options[elems[0].selectedIndex].value != hidVal.value) {
                            data += "U" + sepVal + elems[0].options[elems[0].selectedIndex].value;
                        }
                    }
                }
                break;
            case "txt":
            case "tar":
                var tipo;
                tipo = ctls[i].substring(3, 6).toLowerCase() == "txt" ? "input" : "textarea";
                elems = padre.getElementsByTagName(tipo);
                hidVal = padre.lastChild;
                if (hidVal.value == "" && elems[0].value != "") {  // lo que enviamos es nuevo
                    data += "N" + sepVal + elems[0].value;
                } else if (elems[0].value != hidVal.value) {
                    data += "U" + sepVal + elems[0].value;
                }
                break;
            case "chk":
            case "rad":
                elems = padre.getElementsByTagName("input");
                agrup = padre.firstChild.id.substring(3, padre.firstChild.id.indexOf("_"));
                nomSec = agrup;
                ctlsAgrup = document.getElementsByName(agrup);
                hidVal = padre.lastChild; // (hidden con los valores iniciales)

                for (var j = 0; j < ctlsAgrup.length; j++) {
                    if (ctlsAgrup[j].checked) {
                        params += ctlsAgrup[j].value;
                        params += sepVal;
                    }
                }

                var datos = new Array();
                var hids = new Array();
                datos = params.split(sepVal);
                if (hidVal.value == "") {  // todo lo que enviamos es nuevo
                    for (var h = 0; h < datos.length; h++) {
                        if (datos[h] != "") {
                            data += "N" + sepVal + datos[h];
                            data += sepElem;
                        }
                    }
                } else {
                    hids = hidVal.value.split(sepVal);
                    for (var h = 0; h < datos.length; h++) {
                        encontrado = false;
                        for (var k = 0; k < hids.length && !encontrado; k++) {
                            if (datos[h] == hids[k]) {
                                datos[h] = hids[k] = "";
                                encontrado = true;
                            }
                        }
                    }
                    for (var h = 0; h < datos.length; h++) {
                        if (datos[h] != "") {
                            data += "N" + sepVal + datos[h];
                            data += sepElem;
                        }
                    }
                    for (var k = 0; k < hids.length; k++) {
                        if (hids[k] != "") {
                            data += "D" + sepVal + hids[k];
                            data += sepElem;
                        }
                    }
                }
                if (data.length > 0) data = data.substring(0, data.length - sepElem.length);
                break;
        }
        //if (data.length > 0) {
        data += sepCtl;
        cambios += ctls[i] + sepGra + data;
        //}
    }

    if (cambios.length > 0) cambios = cambios.substring(0, cambios.length - sepCtl.length);
    //alert(cambios);
    if (checkfinalizaReg(cambios)) {
        //alert(cambios);
        // ocultamos el botón
        var lnkBtnContinuar = document.getElementById("lnkBtnContinuar");
        lnkBtnContinuar.style.display = "none";
        verCtl("imgLoading");
        params = "Registro" + sepGra + "continuaReg" + sepBloc + cambios;
        petiAjaxMain("MiPerfil" + sepGra + params, finalizaRegVuelta);
    }
}

function finalizaRegVuelta(res) {
    //alert(res);
    var resul = res.split(sepSBloc);
    if (resul[0] == "ok") {
        window.location = "finregistro.aspx";
    } else {
        alert(resul[1]);
    }
}

function muestraFoto(numero, tipo) {
    var img;
    var imgSrc, servidor, foto, extension;

    img = document.getElementById("imgFoto" + numero);
    if (img == null) img = document.getElementById(ctlCentral + "imgFoto" + numero);
    imgSrc = img.src;

    if (imgSrc.indexOf("nofoto") != -1) imgSrc = "img/nofoto_xxl.gif";

    if (tipo == "MiPerfil") {
        var hidImgFoto = document.getElementById("hidImgFoto" + numero);
        var hidImgAct = document.getElementById(ctlCentral + "hidImgActual");
        var btnEliminar = document.getElementById("btnElimFoto");
        var orden = "";
        btnEliminar.style.display = "none";

        if (imgSrc.indexOf("nofoto") == -1) { // hay foto
            btnEliminar.style.display = "inline";
            var bloque = hidImgFoto.value.split(sepElem);
            var descrip = document.getElementById("tarDescripFoto");
            descrip.value = bloque[4];
            var esPrincipal = document.getElementById("chkEsFotoPrin");
            esPrincipal.checked = bloque[5] == "true" ? true : false;
        }
        hidImgAct.value = hidImgFoto.value;
    }
    img = document.getElementById("imgFotoMain");
    if (img == null) img = document.getElementById(ctlCentral + "imgFotoMain");
    if (imgSrc.indexOf("_mini") != -1) {
        servidor = imgSrc.substring(0, imgSrc.lastIndexOf("/") + 1);
        foto = imgSrc.substring(imgSrc.lastIndexOf("/") + 1, imgSrc.length);
        extension = imgSrc.substring(imgSrc.lastIndexOf("."), imgSrc.length);
        imgSrc = servidor + foto.substring(0, foto.indexOf("_mini")) + extension;
    }

    img.src = imgSrc;
}

/*******************************
*******     Mensajes    ********
********************************/
function iniEnviaMensaje() {
    //    var idPerfil = document.getElementById("hidIdPerfil");
    //    var params = "Mensajes" + sepGra + "iniEnviaMsj" + sepBloc + idPerfil.value;
    //    petiAjaxMain("MiPerfil" + sepGra + params, iniEnviaMensajeVuelta);

    var params = "";
    var ok = true;
    var idPerfil = document.getElementById("hidIdPerfil");
    var accion = document.getElementById("hidAccion");
    var lnkFav = document.getElementById("hidLnkImgFav").value;
    var hayRecarga = document.getElementById("hidRecarga").value;
    var imagesFav = document.getElementById(ctlCentral + "hidImgAddDelFav").value.split(sepBloc);

    switch (accion.value) {
        case "send_msg":
            params = "Mensajes" + sepGra + "iniEnviaMsj" + sepBloc + idPerfil.value;
            break;
        case "add_fav":
            var hlkFavorito = document.getElementById(lnkFav);
            //if (hlkFavorito
            hlkFavorito.href = "mensaje_ajax.aspx?idperfil=" + idPerfil.value + "&accion=del_fav&lnkImgFav="
                + lnkFav + "&height=100&width=320";
            var imgFav = document.getElementById(lnkFav.substring(0, lnkFav.indexOf("Favorito") - 3) + "img" + lnkFav.substring(lnkFav.indexOf("Favorito")));
            imgFav.src = "img/" + imagesFav[1];
            imgFav.title = "Eliminar de mis favoritos";
            params = "Favoritos" + sepGra + "agregaFavorito" + sepBloc + idPerfil.value + sepArg + hayRecarga;
            break;
        case "del_fav":
            var hlkFavorito = document.getElementById(lnkFav);
            hlkFavorito.href = "mensaje_ajax.aspx?idperfil=" + idPerfil.value + "&accion=add_fav&lnkImgFav="
                + lnkFav + "&height=100&width=320";
            var imgFav = document.getElementById(lnkFav.substring(0, lnkFav.indexOf("Favorito") - 3) + "img" + lnkFav.substring(lnkFav.indexOf("Favorito")));
            imgFav.src = "img/" + imagesFav[0];
            imgFav.title = "Añadir a mis favoritos";
            params = "Favoritos" + sepGra + "eliminaFavorito" + sepBloc + idPerfil.value + sepArg + hayRecarga;
            break;
        default:
            ok = false;
            break
    }
    if (ok)
        petiAjaxMain("MiPerfil" + sepGra + params, iniEnviaMensajeVuelta);
}

function iniEnviaMensajeVuelta(res) {
    var resul = res.split(sepArg);
    var spaRespuesta = document.getElementById("spaRespuesta");
    var tblMensaje = document.getElementById("tblMensaje");
    var divRespuesta = document.getElementById("divRespuesta");
    var divMsjAnterior = document.getElementById("divMsjAnterior");
    var hidIdMensaje = document.getElementById("hidIdMensaje");
    var hidCitaMensaje = document.getElementById("hidCitaMensaje");

    switch (resul[0]) {
        case "Mensajes":
            if (resul[1] == "ok") {
                spaRespuesta.style.display = "none";
                tblMensaje.style.display = "inline";
                if (hidIdMensaje.value != "") { // es una respuesta
                    divRespuesta.style.display = "inline";
                    divMsjAnterior.innerHTML = hidCitaMensaje.value;
                }
            } else if (resul[1] == "bloqueado") {
                tblMensaje.style.display = "none";
                spaRespuesta.innerHTML = "Este usuario le tiene en su lista de bloqueados.";
                spaRespuesta.style.display = "inline";
            }
            break;
        case "Favoritos":
            var bloc = resul[1].split(sepBloc);
            if (bloc[0] == "ok") {
                switch (bloc[1]) {
                    case "agrega":
                        spaRespuesta.innerHTML = "Usuario a&ntilde;adido a tus favoritos.";
                        break;
                    case "elimina":
                        spaRespuesta.innerHTML = "Usuario eliminado de tus favoritos.";
                        if (bloc.length > 2) {
                            if (bloc[2] == "1") {// hay recarga
                                var cerrar = document.getElementById("TB_closeWindowButton");
                                cerrar.onclick = function() { location.href = "favoritos.aspx" };

                            }
                        }
                        break;
                }
                spaRespuesta.style.display = "inline";
                //location.href = "favoritos.aspx";
            }
            break;
    }
}

function enviaMensaje() {
    var idPerfil = document.getElementById("hidIdPerfil");
    var tarMensaje = document.getElementById("tarMensaje");
    var idMsj = document.getElementById("hidIdMensaje");
    var responder = "";
    if (idMsj.value != "") {
        responder = idMsj.value;
    }
    if (tarMensaje.value != "") {
        var params = "Mensajes" + sepGra + "enviaMsj" + sepBloc + idPerfil.value + sepArg + tarMensaje.value + sepArg + responder;
        petiAjaxMain("MiPerfil" + sepGra + params, enviaMensajeVuelta);
    }
}

function enviaMensajeVuelta(res) {
    var resul = res.split(sepArg);

    var spaRespuesta = document.getElementById("spaRespuesta");
    var tblMensaje = document.getElementById("tblMensaje");
    var bloc = resul[1].split(sepSBloc);
    if (bloc[0] == "ok") {
        tblMensaje.style.display = "none";
        spaRespuesta.innerHTML = "Mensaje enviado correctamente.";
        spaRespuesta.style.display = "inline";
        if (bloc.length > 1) {
            if (bloc[1] == "responder") {
                location.href = "mensajes.aspx";
            }
        }
    }
}

function recordarPwd() {
    var ok = true;
    var txtMail = document.getElementById(ctlCentral + "txtMail");
    if (txtMail.value == "" || !esMailValido(txtMail.value)) {
        alert("El E-mail no tiene un formato correcto");
        ok = false;
    }
    if (ok) {
        verCtl("imgLoading");
        var lnkBtnRecordarPwd = document.getElementById(ctlCentral + "lnkBtnRecordarPwd");
        lnkBtnRecordarPwd.style.display = "none";
    }

    return ok;
}

function nuevoRelato() {
    var divNuevo = document.getElementById("divNuevoRel");
    var resRelato = document.getElementById(ctlCentral + "resNuevo");
    var divCont = document.getElementById(ctlCentral + "divCont");
    var lnkBtnNuevo = document.getElementById("lnkBtnNuevo");

    if (divNuevo.style.display == "none") {
        divNuevo.style.display = "inline";
        divCont.style.display = "none";
        resRelato.style.display = "none";
        lnkBtnNuevo.style.display = "none";
    } else {
        divNuevo.style.display = "none";
        divCont.style.display = "inline";
        lnkBtnNuevo.style.display = "inline";
    }
}

function enviaRelato() {
    var ok = true;
    var txtTitulo = document.getElementById(ctlCentral + "txtTitulo");
    var tarTexto = document.getElementById(ctlCentral + "tarTexto");


    if (txtTitulo.value == "") {
        alert("Escribe un título");
        ok = false;
    }
    if (ok && tarTexto.value == "") {
        alert("El texto del relato es obligatorio");
        ok = false;
    }

    return ok;
}

function nuevoComentario() {
    var divNuevo = document.getElementById("divNuevoCom");
    var resRelato = document.getElementById(ctlCentral + "resNuevo");
    var divCont = document.getElementById(ctlCentral + "divCont");
    var lnkBtnNuevo = document.getElementById("lnkBtnNuevo");

    if (divNuevo.style.display == "none") {
        divNuevo.style.display = "inline";
        divCont.style.display = "none";
        resRelato.style.display = "none";
        lnkBtnNuevo.style.display = "none";
    } else {
        divNuevo.style.display = "none";
        divCont.style.display = "inline";
        lnkBtnNuevo.style.display = "inline";
    }
}

function enviaComentario() {
    var ok = true;
    var txtTitulo = document.getElementById(ctlCentral + "txtTitulo");
    var tarTexto = document.getElementById(ctlCentral + "tarTexto");


    if (txtTitulo.value == "") {
        alert("Escribe un título");
        ok = false;
    }
    if (ok && tarTexto.value == "") {
        alert("El texto del comentario es obligatorio");
        ok = false;
    }

    return ok;
}

function checkContacto() {
    var ok = true;

    var txtNombre = document.getElementById(ctlCentral + "txtNombre");
    var txtEmail = document.getElementById(ctlCentral + "txtEmail");


    if (txtNombre.value == "") {
        alert("El nombre es obligatorio");
        ok = false;
    }
    if (ok && txtEmail.value == "") {
        alert("Debes especificar una dirección de e-mail");
        ok = false;
    }
    if (ok && !esMailValido(txtEmail.value)) {
        alert("La dirección de e-mail tiene un formato incorrecto");
        ok = false;
    }

    return ok;
}

function checkVideo(idTxtTit, idFUpload) {
    var ok = true;
    var txtTitVideo = document.getElementById(ctlCentral + idTxtTit);
    var upload = document.getElementById(ctlCentral + idFUpload);

    if (txtTitVideo != null && txtTitVideo.value == "") {
        alert("El título es obligatorio");
        ok = false;
    }
    if (ok && upload.value == "") {
        alert("Indica el vídeo que quieres subir");
        ok = false;
    }

    return ok;
}

function VotarVideo(id, idVideo) {
    //alert(id + " " + idVideo);
    var selVoto = document.getElementById("selVoto_" + id);
    var puntuacion = selVoto.options[selVoto.selectedIndex].value;
    if (puntuacion != "") {
        var divVot = document.getElementById("divVota_" + id);
        divVot.style.display = "none";
        var imgVot = document.getElementById("imgVota_" + id);
        imgVot.style.display = "inline";
        var params = "VideoSex" + sepGra + "votar" + sepBloc + id + sepArg + idVideo + sepArg + puntuacion;
        petiAjaxMain("Videos" + sepGra + params, VotarVideoVuelta);
    } else {
        alert("Selecciona una puntuación");
    }
}

function VotarVideoVuelta(res) {
    var resul = res.split(sepArg);
    var imgVot, spaPunt;

    if (resul[0] == "ok") {
        imgVot = document.getElementById("imgVota_" + resul[1]);
        imgVot.style.display = "none";
        spaPunt = document.getElementById("spaPunt_" + resul[1]);
        spaPunt.innerHTML = resul[2];
    } else {
        alert(resul[1]);
    }
}

function recargaMenu() {
    petiAjaxMain("MiPerfil" + sepGra + "RecargaMenu", recargaMenuVuelta);
}

function recargaMenuVuelta(res) {
    var imgNuevosMsj = document.getElementById(ctlMenu + "imgNuevoMsj");
    if (res == "si")
        imgNuevosMsj.style.display = "inline";
    else
        imgNuevosMsj.style.display = "none";

    setTimeout(function() { recargaMenu() }, 30000);
}

function cambiaVisibilidadPerfil() {
    var selVisibilidad = document.getElementById("selVisibilidad");
    var divPerfilPublico = document.getElementById(ctlCentral + "divPerfilPublico");

    if (selVisibilidad.value == "0")
        divPerfilPublico.style.display = "none";
    else
        divPerfilPublico.style.display = "block";
}
