﻿var d;
var s;

var contentdivsactive = true;

var nCategoriesPerPage = 5;

var var_respon_idcat = -1;
var var_respon_idforo = -1;


function closeLightbox() {
    tb_remove();
    //sendtoiframe();
}

function openLightbox() {
    fireEvent(document.getElementById("thickboxfireevent"), 'click');
    //sendtoiframe();
}

function openLightboxCrearTema() {
    fireEvent(document.getElementById("thickboxfireevent2"), 'click');
    //sendtoiframe();
}

function fireEvent(obj, evt) {
    var fireOnThis = obj;
    if (document.createEvent) {
        var evObj = document.createEvent('MouseEvents');
        evObj.initEvent(evt, true, false);
        fireOnThis.dispatchEvent(evObj);
    } else if (document.createEventObject) {
        fireOnThis.fireEvent('on' + evt);
    }
}

function getCategoryPostsHome(divID, idForo, idForoCategory) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getCategoryPostsHome&idForo=' + idForo + '&idForoCategory=' + idForoCategory + '&date=' + s, divID);
}

function getForumHome(divID, idForo, actualPage) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getForumHome&idForo=' + idForo + '&actualPage=' + actualPage + '&ordCamp=Data&ordOrdre=desc&date=' + s, divID);
}

function getForumHomeOrdre(divID, idForo, actualPage, ordCamp, ordOrdre) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getForumHome&idForo=' + idForo + '&actualPage=' + actualPage + '&ordCamp=' + ordCamp + '&ordOrdre=' + ordOrdre + '&date=' + s, divID);
}

//document.getElementsById = function() {
//    var a = String(arguments[0]).split(" "), b = [], i; for (i = 0; i < a.length; i++) b[b.length] = a[i]; return b
//}

function setStateInoportunoPost(idPost) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    //document.getElementById('post' + idPost).innerHTML = '<img height="15" border="0" width="15" src="/images/foro/inapropiado_actv.gif" title="Contenido notificado como inadecuado" alt="Contenido notificado como inadecuado"/>';
    makeRequestAction('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=setStateInoportunoPost&idCategoryPost=' + idPost + '&date=' + s, 'post' + idPost, 'duplicateInapropiado');

    //var toggle = document.getElementsById('post' + idPost);

    //index = 0;

//    try {
//        document.getElementById('Tpost' + idPost).innerHTML = document.getElementById('post' + idPost).innerHTML
//        div = 'postT' + idPost;
//        alert(div.substring(0, 4) + 'T' + idPost);
//        setTimeout("", 1000);
//    }
//    catch(err) {}
}

function PublicaTemaOriginal(divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    var idtema = document.getElementById("seltema").value;

    var titol;
    titol = escape(htmlEncode(document.getElementById("area_tema").value.toString(), true, 4));
    var areaText;
    areaText = escape(htmlEncode(document.getElementById("area_tema_mensaje").value.toString(), true, 4));

    if (titol.length > 0) {
        document.getElementById("falta_tema").style.display = "none";
        if (areaText.length > 0) {
            makePostRequestAction('/module/ggforos/Webservice/GGForo.ashx', 'Param=' + IDGG + '&action=PublicaTema&idtema=' + idtema + '&titol=' + titol + '&areaText=' + areaText, divID, 'newForo');
            //var varTema = idtema - 1;   //calculem pestanya foro
            //document.cookie = "contentdivtabs" + "=" + varTema + ";path=/" //cookie value is domain wide (path=/)
            //setTimeout("window.location = 'GGForo_home.aspx'", 1000);
            

        }
        else {
            
            document.getElementById("falta_content").setAttribute("Style", "color:Red");
        }
    }
    else {

        document.getElementById("falta_tema").setAttribute("Style", "color:Red; ");
        //document.getElementById("falta_tema").style.visibility = "visible";
        document.getElementById("falta_tema").style.display = "block";
    }

}

function PublicaTema(divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    var idtema = document.getElementById("seltema").value;

    var titol;
    titol = escape(htmlEncode(document.getElementById("area_tema").value.toString(), true, 4));    
    var areaText;
    areaText = escape(htmlEncode(document.getElementById("area_tema_mensaje").value.toString(), true, 4));
    var emoticono = document.getElementById("H_emoticono").value;    
    var avisemail="0";
    if(document.getElementById("avisomail").checked) {
        avisemail = "1";        
    }


    if (titol.length > 0) {
        document.getElementById("falta_tema").style.display = "none";
        if (areaText.length > 0) {
            makePostRequestAction('/module/ggforos/Webservice/GGForo.ashx', 'Param=' + IDGG + '&action=PublicaTema&idtema=' + idtema + '&titol=' + titol + '&areaText=' + areaText + '&avis=' + avisemail + '&emoticono=' + emoticono, divID, 'newForo');
            //var varTema = idtema - 1;   //calculem pestanya foro
            //document.cookie = "contentdivtabs" + "=" + varTema + ";path=/" //cookie value is domain wide (path=/)
            //setTimeout("window.location = 'GGForo_home.aspx'", 1000);


        }
        else {
            document.getElementById("falta_content").setAttribute("Style", "color:Red");
        }
    }
    else {

        document.getElementById("falta_tema").setAttribute("Style", "color:Red; ");
        //document.getElementById("falta_tema").style.visibility = "visible";
        document.getElementById("falta_tema").style.display = "block";
    }

}

function AddPost(idForo, idCategory, divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    var areaText;
    areaText = escape(htmlEncode(document.getElementById("area_post_mensaje").value.toString(), true, 4));

    if (areaText.length > 0) {
        makePostRequest('/module/ggforos/Webservice/GGForo.ashx', 'Param=' + IDGG + '&action=AddPost&idForo=' + idForo + '&idCategory=' + idCategory + '&areaText=' + areaText, divID);

        var varTema = idForo - 1;   //calculem pestanya foro
        //document.cookie = "contentdivtabs" + "=" + varTema + ";path=/" //cookie value is domain wide (path=/)
        //setTimeout("window.location = 'GGForo_home.aspx'", 1000);

        closeLightbox();
        document.getElementById("area_post_mensaje").value = '';
        setTimeout("getCategoryAllPost(idForo, idCategory, 'contentdiv6');", 1000);
        getCategoryAllPost(idForo, idCategory, 'contentdiv6');
        //setTimeout("getCategoryAllPost(idForo, idCategory, 'contentdiv6');", 800);

    }
    else {
        document.getElementById("falta_responder").setAttribute("Style", "color:Red;");
        document.getElementById("falta_responder").style.display = "block";
    }

}

function getCategoryAllPost(idForo, idCategory, divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getCategoryAllPost&idCategory=' + idCategory + '&idForo=' + idForo + '&actualPage=1&ordCamp=Data&ordOrdre=desc&date=' + s, divID);

    startTabcontent();
}


//25/11/2009 Àlex
function getCategoryAllPost1Page(idForo, idCategory, divID) {
    getPagingHeadDetallTema1Page(idForo, idCategory, '1', 'HeadTema');

    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForoPageHandler.ashx', '?Param=' + IDGG + '&action=getCategoryAllPost1Page&idCategory=' + idCategory + '&idForo=' + idForo + '&actualPage=1&ordCamp=Data&ordOrdre=desc&date=' + s, divID);
   
}

//27/11/2009 Àlex
function getCategoryAllPostOrdre1Page(idCategory, divID, actualPage, ordCamp, ordOrdre) {
    getPagingHeadDetallTemaOrdre1Page(idForo, idCategory, actualPage, ordCamp, ordOrdre, 'HeadTema');

    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForoPageHandler.ashx', '?Param=' + IDGG + '&action=getCategoryAllPost1Page&idCategory=' + idCategory + '&idForo=-1&actualPage=' + actualPage + '&ordCamp=' + ordCamp + '&ordOrdre=' + ordOrdre + '&date=' + s, divID);
}

//16/12/2009 Àlex
function getPagingHeadDetallTema1Page(idForo, idCategory, actualPage, divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForoPageHandler.ashx', '?Param=' + IDGG + '&action=getPagingHeadDetallTema&idCategory=' + idCategory + '&idForo=' + idForo + '&actualPage=' + actualPage + '&ordCamp=Data&ordOrdre=desc&date=' + s, divID);
}


function getPagingHeadDetallTemaOrdre1Page(idForo, idCategory, actualPage, ordCamp, ordOrdre, divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForoPageHandler.ashx', '?Param=' + IDGG + '&action=getPagingHeadDetallTema&idCategory=' + idCategory + '&idForo=' + idForo + '&actualPage=' + actualPage + '&ordCamp=' + ordCamp + '&ordOrdre=' + ordOrdre + '&date=' + s, divID);
}


function getCategoryAllPostOrdre(idCategory, divID, actualPage, ordCamp, ordOrdre) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getCategoryAllPost&idCategory=' + idCategory + '&idForo=-1&actualPage=' + actualPage + '&ordCamp=' + ordCamp + '&ordOrdre=' + ordOrdre + '&date=' + s, divID);

    startTabcontent();
}

function getSearchResults(divID) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    var txtSearch = "";
    txtSearch = document.getElementById("elquesigui").value;
    if (txtSearch.length > 0) {
        makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getSearchResults&idForo=-1&actualPage=1&txtSearch=' + txtSearch + '&ordCamp=Data&ordOrdre=desc&date=' + s, divID);

        startTabcontent();
    }
}

function getSearchResultsOrder(idForo, divID, nPag, ordCamp, ordOrdre, txtSearch) {
    d = new Date();
    s = d.getSeconds() + '.' + d.getMilliseconds();

    makeRequest('/module/ggforos/Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=getSearchResults&idForo=-1&actualPage=' + nPag + '&txtSearch=' + txtSearch + '&ordCamp=' + ordCamp + '&ordOrdre=' + ordOrdre + '&date=' + s, divID);
}

function startTabcontent() {
    var contentdivs = new ddtabcontent("contentdivtabs");
    contentdivs.setpersist(true);
    contentdivs.setselectedClassTarget("link"); //"link" or "linkparent"
    contentdivs.init();
    for (var i = 1; i <= 5; i++) {
        var contentdivname1 = "contentdiv" + parseInt(i);
        var contentdivtohide = document.getElementById(contentdivname1);
        contentdivtohide.style.display = "none";
    }

    var contentdivname2 = "contentdiv6";
    var contentdivtoshow = document.getElementById(contentdivname2);
    contentdivtoshow.style.display = "block";

    var contentdivbkg = document.getElementById("contentdivtabs");
    contentdivbkg.style.background = "transparent url(/images/foro/f_tab.gif) no-repeat";


}

//        //Torna el paginador del foro especificat amb el num de registres per plana especificats
//        function getForumPagerHome(divID, idForo, intNumCategoriesPerPage) {
//            d = new Date();
//            s = d.getSeconds() + '.' + d.getMilliseconds();
//            makeRequest('./Webservice/GGForo.ashx', '?Param=' + IDGG + '&action=allPagingForum&idForo=' + idForo + '&intNumCategoriesPerPage=' + intNumCategoriesPerPage + '&date=' + s, divID);
//        }

function showInapropiadoDialog(idPost) {
    document.getElementById(HiddenClientID).value = idPost;

    tb_show("Message", "#TB_inline?height=185&width=424&inlineId=inapropiado&modal=true", null);
}

function showLoginNewForo() {
    //6 = newforo
    idLogin = 6;
    
    tb_show("Message", "#TB_inline?height=313&amp;width=627&amp;inlineId=login_ggforo&amp;modal=true", null);
}

function InapropiadoFunction() {
    //if (document.getElementById(HiddenClientID).value != 0) {
        //alert(document.getElementById(HiddenClientID).value);
    //}

    if (document.getElementById('radioSi').checked) {
        setStateInoportunoPost(document.getElementById(HiddenClientID).value);
        closeLightbox();
    }
    else if (document.getElementById('radioNo').checked) {
        closeLightbox();
    }
}

