﻿function ajustaIframe(iframeId) {
    if (!el('divSize'))
        return;
    iframeElement = getel(window.parent.document, iframeId);
    if (nie)
        iframeElement.style.height = '';
    h = el('divSize').offsetHeight;
    lastHeight = h;
    iframeElement.style.height = (h) + 'px';
}

activeToolTip = 0;
function showToolTip(tid, evento) {
    if (evento)
        evento.cancelBubble = 1;
    if (activeToolTip)
        activeToolTip.style.display = 'none';
    activeToolTip = el(tid);
    if (activeToolTip)
        activeToolTip.style.display = 'inline';
    setTimeout('document.onclick = hidetooltip', 100);
}
function hidetooltip() {
    showToolTip('');
}

function assina(idproduto, idtipo) {
    el('hdProduto').value = idproduto;
    el('hdTipo').value = idtipo;
    el('fCompra').submit();
}

function carregaMaisPosts() {
    url = htmlBase + 'mypoint/mp.controles/postsAjax.aspx?pg=' + (postsPg + 1) + '&idCliente=' + (postsIdCliente) + '&idMaior=' + (postsIdMaior);
    carregarEm(el('lnkMais'), el('divEnviando'), el('imgLoading'), el('postsPg' + (postsPg + 1)), url, '', 'carregarMaisPostsOk()');
}

function carregarMaisPostsOk() {
    postsPg++;
    if (el('divUltima'))
        el('divMais').style.display = 'none'
    ajustaIframe('posts');
    showTwittersIn(el('postsPg' + (postsPg)));
    showXIframes();
}

function carregaMaisAtividades() {
    url = htmlBase + 'mypoint/mp.controles/atividadesAjax.aspx?pg=' + (atividadesPg + 1) + '&tamanhoPagina=' + (atividadesTamanhoPagina) + '&idCliente=' + (atividadesIdCliente) + '&home=' + (atividadesHome) + '&geral=' + (atividadesGeral) + '&tipo=' + (atividadesTipo) + '&idMaior=' + (atividadesIdMaior);
    carregarEm(el('lnkMais'), el('divEnviando'), el('imgLoading'), el('atividadesPg' + (atividadesPg + 1)), url, '', 'carregarMaisAtividadesOk()');
}

function carregarMaisAtividadesOk() {
    atividadesPg++;
    if (el('divUltima'))
        el('divMais').style.display = 'none'
    ajustaIframe('atividades');
}

function avaliaPost(idpost, nota) {

    url = htmlBase + 'mypoint/mp.controles/postRegistraAvaliacao.aspx?idpost=' + (idpost) + '&nota=' + (nota) + '&rnd=' + (Math.random());
    req = getAjax();

    el('imgEnvAval').style.display = 'block';

    req.onreadystatechange = function() {
        if (this.readyState == 4) {
            el('imgEnvAval').style.display = 'none';
            if ((this.status == 200) && (this.responseText.length >= 2)) {
                if (this.responseText.substr(0, 2) == 'OK')
                    alert('Sua avaliação foi registrada! Obrigado!');
                else if (this.responseText.substr(0, 2) == 'JA')
                    alert('Sua avaliação já está registrada, e só é permitido um voto por conteúdo. Obrigado!');
                else if (this.responseText.substr(0, 5) == 'LOGAR')
                    window.location = htmlBase + 'mypoint/cadastro.aspx';
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    req.open('GET', url, true);
    req.setRequestHeader("Connection", "close");
    req.send(null);
}

function gravaComentarioPost(idPost) {

    txt = el('txtComentario').value;

    if (txt.length < 2) {
        alert('Por favor preencha seu comentário!');
        el('txtComentario').focus();
        return;
    }

    btn = el('enviarComentBT');

    btn.style.display = 'none';
    el('divEnviandoComent').style.display = 'block';
    setTimeout('showProgressImage(\'imgLoadingComent\')', 100);

    url = htmlBase + 'mypoint/mp.controles/postRegistraComentario.aspx';
    poststr = "txt=" + encodeURIComponent(txt) + "&idPost=" + idPost;

    if (el('chkReceberFuturos') && (el('chkReceberFuturos').checked))
        poststr += "&receberFuturos=1";

    req = getAjax();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            el('enviarComentBT').style.display = 'block';
            el('divEnviandoComent').style.display = 'none';
            if (req.status == 200) {
                if (req.responseText.substr(0, 5) == 'LOGAR')
                    window.location = htmlBase + 'mypoint/cadastro.aspx';
                else if (req.responseText.substr(0, 2) != "ok")
                    alert(req.responseText)
                else {
                    alert('Seu comentário foi registrado. Obrigado!');
                    idc = req.responseText.substr(3, req.responseText.length - 3);
                    location.href = 'post.aspx?idPost=' + (idPost) + '&ultimaPagina=1&idc=' + (idc) + '#comentario' + (idc);
                }
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    http_request.setRequestHeader("Connection", "close");
    http_request.send(poststr);
}

function avaliaFoto(idfoto, nota) {

    url = htmlBase + 'mypoint/mp.controles/fotoRegistraAvaliacao.aspx?idfoto=' + (idfoto) + '&nota=' + (nota) + '&rnd=' + (Math.random());
    req = getAjax();

    el('imgEnvAval').style.display = 'block';

    req.onreadystatechange = function() {
        if (this.readyState == 4) {
            el('imgEnvAval').style.display = 'none';
            if ((this.status == 200) && (this.responseText.length >= 2)) {
                if (this.responseText.substr(0, 2) == 'OK')
                    alert('Sua avaliação foi registrada! Obrigado!');
                else if (this.responseText.substr(0, 2) == 'JA')
                    alert('Sua avaliação já está registrada, e só é permitido um voto por foto. Obrigado!');
                else if (this.responseText.substr(0, 5) == 'LOGAR')
                    window.location = htmlBase + 'mypoint/cadastro.aspx';
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    req.open('GET', url, true);
    req.setRequestHeader("Connection", "close");
    req.send(null);
}

function gravaComentarioFoto(idFoto) {

    txt = el('txtComentario').value;

    if (txt.length < 2) {
        alert('Por favor preencha seu comentário!');
        el('txtComentario').focus();
        return;
    }

    btn = el('enviarComentBT');

    btn.style.display = 'none';
    el('divEnviandoComent').style.display = 'block';
    setTimeout('showProgressImage(\'imgLoadingComent\')', 100);

    url = htmlBase + 'mypoint/mp.controles/fotoRegistraComentario.aspx';
    fotostr = "txt=" + encodeURIComponent(txt) + "&idFoto=" + idFoto;

    if (el('chkReceberFuturos') && (el('chkReceberFuturos').checked))
        fotostr += "&receberFuturos=1";

    req = getAjax();
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            el('enviarComentBT').style.display = 'block';
            el('divEnviandoComent').style.display = 'none';
            if (req.status == 200) {
                if (req.responseText.substr(0, 5) == 'LOGAR')
                    window.location = htmlBase + 'mypoint/cadastro.aspx';
                else if (req.responseText.substr(0, 2) != "ok")
                    alert(req.responseText)
                else {
                    alert('Seu comentário foi registrado. Obrigado!');
                    idc = req.responseText.substr(3, req.responseText.length - 3);
                    location.href = 'fotoPg.aspx?idFoto=' + (idFoto) + '&ultimaPagina=1&idc=' + (idc) + '#comentario' + (idc);
                }
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    http_request.open('POST', url, true);
    http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    http_request.setRequestHeader("Connection", "close");
    http_request.send(fotostr);
}

blocoAtivo = 0;
blocoDescrAtivo = 0;
function painelOver(idBloco, descricao) {
    bl = el(idBloco);
    if (bl) {
        bl.className = 'painel-content-active';
        blocoAtivo = bl;
    }
    bld = el(idBloco + 'Descr');
    if (bld) {
        bld.className = 'painel-txt-active';
        bld.innerHTML = '<p><a class="txt-painel">' + descricao + '</a></p>';
        blocoDescrAtivo = bld;
    }
}

function painelOut() {
    if (blocoAtivo)
        blocoAtivo.className = 'painel-content';
    if (blocoDescrAtivo) {
        blocoDescrAtivo.innerHTML = '<p><a class="txt-painel">' + blocoDescrAtivo.getAttribute('descricao', 0) + '</a></p>';
        blocoDescrAtivo.className = 'painel-txt';
    }
}

idPost = 0;
function excluiPost(id, titulo) {
    idPost = id;
    el('nomePost').innerHTML = titulo;
    mostraDialogo(el('dialogoExcluir').innerHTML, el('alterar-fotos').clientWidth, el('alterar-fotos').clientHeight);
}

function excluiPost2() {
    el('hdIdPost').value = idPost;
    __doPostBack(idBtnExcluir, '')
}

idFoto = 0;
function excluiFoto(id) {
    idFoto = id;
    el('imgFotoExcluir').src = htmlBase + 'mypoint/foto.aspx?idFoto=' + (id) + '&tamanho=9';
    mostraDialogo(el('dialogoExcluir').innerHTML, el('alterar-fotos').clientWidth, el('alterar-fotos').clientHeight);
}

function excluiFoto2() {
    el('hdIdFoto').value = idFoto;
    __doPostBack(idBtnExcluir, '')
}

function mostraDialogo(html, width, height, noclose, noshow, dofade) {
    ov = el('overlay');
    amp = el('ampliacao');
    ampi = el('ampliInner');
    ct = el('ampliContent');

    ct.innerHTML = '';

    ct.style.height = (height) + 'px';
    ct.style.width = (width) + 'px';
    ampi.style.width = (width) + 'px';

    oh = document.documentElement.scrollHeight > document.body.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
    ov.style.height = (oh) + 'px';
    ov.style.top = (document.body.scrollTop) + 'px';
    ov.style.left = (document.body.scrollLeft) + 'px';

    dofade = ((typeof (dofade) != 'undefined') && (dofade));

    noshow = ((typeof (noshow) != 'undefined') && (noshow));

    noclose = ((typeof (noclose) != 'undefined') && (noclose));
    el('divBtnFechar').style.display = noclose ? 'none' : 'block';

    th = document.documentElement.clientHeight;
    th = ((th - height - 12 - (!noclose ? 18 : 0) - 3) / 2) - 20;
    if (th < 0)
        th = 0;
    th = th + (document.body.scrollTop > 0 ? document.body.scrollTop : document.documentElement.scrollTop);
    ampi.style.marginTop = (th) + 'px';

    if (!noshow)
        mostraDialogoShow(dofade);

    ct.innerHTML = html;
}

function mostraDialogoShow(dofade) {
    ov = el('overlay');
    amp = el('ampliacao');

    try {
        amp.style.filter = "blendTrans(duration=0.5)";
        amp.filters.blendTrans.apply();
        amp.filters.blendTrans.play();
    }
    catch (e) {
    }

    ov.style.display = 'block';
    amp.style.display = 'block';

    h = document.body.scrollTop;
    document.body.style.overflow = 'hidden';
    document.body.scrollTop = h;
}

function fechaDialogo() {
    ov = el('overlay');
    amp = el('ampliacao');
    ct = el('ampliContent');

    ov.style.display = 'none';
    amp.style.display = 'none';
    ct.innerHTML = '';

    document.body.style.overflow = '';
}

function mostraDialogoFrame(src, width, height) {
    mostraDialogo('<iframe width=' + (width) + ' height=' + (height) + ' frameborder=0 src="' + src + '" scrolling=auto></iframe>', width, height);
}

function postComentarioMudaStatus(btn, idPostComentario, status, validador, bloquear, publicar) {

    btnPub = el('btnPubCm' + (idPostComentario));
    btnBlq = el('btnBlqCm' + (idPostComentario));
    divE = el('divEnviandoCm' + (idPostComentario));
    msg = el('msg' + (idPostComentario));

    btnBlq.style.display = 'none';
    btnPub.style.display = 'none';

    divE.style.display = 'block';
    setTimeout('showProgressImage(\'imgLoadingCm' + (idPostComentario) + '\')', 100);

    url = htmlBase + 'mypoint/mp.controles/postComentarioMudaStatus.aspx?idPostComentario=' + (idPostComentario) + '&status=' + (status) + '&valid=' + validador + '&rnd=' + (Math.random());

    req = getAjax();

    saveReqObjs(req, [btnPub, btnBlq, divE, idPostComentario, bloquear, publicar, msg]);

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            objs = loadReqObjs(req);
            btnPub = objs[0];
            btnBlq = objs[1];
            divE = objs[2];
            idFotoComentario = objs[3];
            bloquear = objs[4];
            publicar = objs[5];
            msg = objs[6];
            divE.style.display = 'none';
            if (req.status == 200) {
                if (req.responseText != "ok")
                    alert(req.responseText)
                else {
                    btnPub.style.display = publicar ? 'none' : 'block';
                    btnBlq.style.display = bloquear ? 'none' : 'block';
                    msg.className = publicar ? "counter counter-green" : "counter counter-red";
                    msg.innerHTML = publicar ? "<p>Este comentário foi aprovado por você</p><span></span>" : 
                        "<p>Este comentário foi bloqueado por você</p><span></span>";
                }
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    req.open('GET', url, true);
    req.send(null);
}

function fotoComentarioMudaStatus(btn, idFotoComentario, status, validador, bloquear, publicar) {

    btnPub = el('btnPubCm' + (idFotoComentario));
    btnBlq = el('btnBlqCm' + (idFotoComentario));
    divE = el('divEnviandoCm' + (idFotoComentario));
    msg = el('msg' + (idFotoComentario));

    btnBlq.style.display = 'none';
    btnPub.style.display = 'none';

    divE.style.display = 'block';
    setTimeout('showProgressImage(\'imgLoadingCm' + (idFotoComentario) + '\')', 100);

    url = htmlBase + 'mypoint/mp.controles/fotoComentarioMudaStatus.aspx?idFotoComentario=' + (idFotoComentario) + '&status=' + (status) + '&valid=' + validador + '&rnd=' + (Math.random());

    req = getAjax();

    saveReqObjs(req, [btnPub, btnBlq, divE, idFotoComentario, bloquear, publicar, msg]);

    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            objs = loadReqObjs(req);
            btnPub = objs[0];
            btnBlq = objs[1];
            divE = objs[2];
            idFotoComentario = objs[3];
            bloquear = objs[4];
            publicar = objs[5];
            msg = objs[6];
            divE.style.display = 'none';
            if (req.status == 200) {
                if (req.responseText != "ok")
                    alert(req.responseText)
                else {
                    btnPub.style.display = publicar ? 'none' : 'block';
                    btnBlq.style.display = bloquear ? 'none' : 'block';
                    msg.className = publicar ? "counter counter-green" : "counter counter-red";
                    msg.innerHTML = publicar ? "<p>Este comentário foi aprovado por você</p><span></span>" :
                        "<p>Este comentário foi bloqueado por você</p><span></span>";
                }
            }
            else {
                alert(msgrepetir);
            }
        }
    }

    req.open('GET', url, true);
    req.send(null);
}


function mostraAcaoCad(idnsas) {
    width = 908;
    height = 546;
    mostraDialogo('<iframe width=' + (width) + ' height=' + (height) + ' frameborder=0 src="' + htmlBase + 'mypoint/acaoCadastro.aspx?idnsas=' + (idnsas) + '" scrolling=no></iframe>', width, height, 1, 1, 1);
}

