function displayBlog (intBlogId, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.view", intBlogId: intBlogId, strJsConfig: strJsConfig }, function (data) {
            $("#blog_container").html(data);
        }
    );

    loadHeadline (strJsConfig, "view");

}

function deleteBlog (intBlogId, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.delete", intBlogId: intBlogId, strJsConfig: strJsConfig }, function (data) {

            if (data != "1") {
                alert (data);
            } else {
                displayBlogList (strJsConfig);
            }

        }
    );

}

function displayBlogList (strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", strJsConfig: strJsConfig }, function (data) {
            $("#blog_container").html(data);
        }
    );

    loadHeadline (strJsConfig, "list");

}

function displayBlogListArea (strJsConfig, intAreaId) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", strJsConfig: strJsConfig, intSetAreaId: intAreaId }, function (data) {
            $("#blog_container").html(data);
        }
    );

    loadHeadline (strJsConfig, "list");

}

function editExistingBlog (intBlogId, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.markEdit", intBlogId: intBlogId, strJsConfig: strJsConfig }, function (data) {

            $("#blog_container").html(data);

        }
    );

}

function blogViewCommentInput (intReferenceId, strJsConfig) {

    var strHtml = $("#comment_add_container").html();

    if (strHtml.length < 2) {

        $.get ("index.php", { ajax: "applic|modules|comment|comment.base.php", ac: "comment.add", intReferenceId: intReferenceId, strJsConfig: strJsConfig }, function (data) {
                $("#comment_add_container").html (data);
                $("#comment_add_container").slideDown();
            }
        );

    } else {

        $("#comment_add_container").slideUp();
        $("#comment_add_container").html("");

    }

}

function blogAddComment (intReferenceId, intReferenceType, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|comment|comment.base.php", ac: "comment.save", strComment: $("#strComment").val(), intReferenceId: intReferenceId, intReferenceType: intReferenceType, strJsConfig: strJsConfig }, function (data) {
            $("#comment_container").slideUp("slow");
            window.setTimeout ("blogCommentLoadCommentList ("+intReferenceId+","+ intReferenceType+", true)", 500);
            window.setTimeout ("refreshNumberOfComment ("+intReferenceId+","+intReferenceType+")", 500);
            $("#comment_add_container").slideUp();
            $("#comment_add_container").html();
        }
    );

}

function blogAddCommentAndUser (intReferenceId, intReferenceType, strJsConfig) {

    $("#strErrorMessage").hide();

    var boolTerms = $("#boolTermsComment").attr("checked");
    if (!boolTerms) boolTerms = 0;
    else boolTerms = 1;

    $.get ("index.php", { ajax: "applic|modules|comment|comment.base.php", ac: "comment.save", strComment: $("#strComment").val(), strUsernameComment: $("#strUsernameComment").val(), strEmailAddressComment: $("#strEmailAddressComment").val(), boolTermsComment: boolTerms, intReferenceId: intReferenceId, intReferenceType: intReferenceType, strJsConfig: strJsConfig }, function (data) {
            if (data != "1") {
                $("#strErrorMessage").html (data);
                $("#strErrorMessage").show();
            } else {
                //$("#comment_container").slideUp("slow");
                $("#strErrorMessage").html ('You will shortly receive a mail with your activation link.');
                $("#strErrorMessage").show();
                //window.setTimeout ("blogCommentLoadCommentList ("+intReferenceId+","+ intReferenceType+", true)", 500);
                //window.setTimeout ("refreshNumberOfComment ("+intReferenceId+","+intReferenceType+")", 500);
            }
        }
    );

}

function blogCommentLoadCommentList (intReferenceId, intReferenceType, boolEffect) {

    $.get ("index.php", { ajax: "applic|modules|comment|comment.base.php", ac: "comment.list", intReferenceId: intReferenceId, intReferenceType: intReferenceType }, function (data) {
            if (boolEffect == true) {
                $("#comment_container").html (data);
                $("#comment_container").slideDown ("normal");
            } else {
                $("#comment_container").html (data);
            }
        }
    );

}

function refreshNumberOfComment (intReferenceId, intReferenceType) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.shownumberofcomments", intReferenceId: intReferenceId, intReferenceType: intReferenceType }, function (data) {

            $("#numComment_container").html (data);

        }

    );

}

function showParagraphAdd (strType, strJsConfig, intParagraphId) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.loadparagraphinput", strType: strType, strJsConfig: strJsConfig, intParagraphId: intParagraphId }, function (data) {

            /*
            if (strType == "text") {
                alert ("1:"+strType);
                if ($("#paddtext")) { $("#paddtext").css ("background-color", "#B3BABC"); }
                if ($("#paddimage")) { $("#paddimage").css ("background-color", "#4C575A"); }
                if ($("#paddvideo")) { $("#paddvideo").css ("background-color", "#4C575A"); }
            } else if (strType == "video") {
                alert ("2:"+strType);
                if ($("#paddtext")) { $("#paddtext").css ("background-color", "#4C575A"); }
                if ($("#paddimage")) { $("#paddimage").css ("background-color", "#4C575A"); }
                if ($("#paddvideo")) { $("#paddvideo").css ("background-color", "#B3BABC"); }
            } else if (strType == "image") {
                alert ("3:"+strType);
                if ($("#paddtext")) { $("#paddtext").css ("background-color", "#4C575A"); }
                if ($("#paddimage")) { $("#paddimage").css ("background-color", "#B3BABC"); }
                if ($("#paddvideo")) { $("#paddvideo").css ("background-color", "#4C575A"); }
            }

            */

            $("#inputField").html (data);

        }

    );

}

function submitImage (strJsConfig, boolFinish) {

    if ($("#blog_headline").val() != "") {

        if ($("#intBlogId").val() == "") {

            if ($("#boolNoticeToFriends").attr("checked") == true) {
                var boolSendToMyFriends = 1;
            } else {
                var boolSendToMyFriends = 0;
            }

            // blog not saved yet - doing
            $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.save", strHeadline: $("#blog_headline").val(), strTags: $("#blog_tags").val(), strJsConfig: strJsConfig, intStatus: 2, intOptBlogId: $("#intBlogId").val(), boolSendToMyFriends: boolSendToMyFriends, intCategory: intGetCategory(), intArea: intGetArea() }, function (data) {
                    $("#intBlogId").val(data);
                    handleFileSubmit (strJsConfig, boolFinish);
                }
            );

        } else {

            handleFileSubmit (strJsConfig, boolFinish);

        }

    } else {

        alert ("Please fill out the headline!");

    }

}

function handleFileSubmit (strJsConfig, boolFinish) {

    if (iFrameUpload.document.getElementById("resultTmp")) {
        iFrameUpload.document.getElementById("resultTmp").value = "";
    }

    document.getElementById("btSaveParagraph").disabled = true;

    $("#intBlogIdImage").val ($("#intBlogId").val());

    $("#uploadPicture").submit();
    handleFileUpload (strJsConfig, boolFinish);

}


function handleFileUpload (strJsConfig, boolFinish) {

    objTimeout = window.setTimeout ("handleFileUpload(\'"+strJsConfig+"\', "+boolFinish+")", 1000);
    if (iFrameUpload.document) {

        if (iFrameUpload.document.getElementById("uploadFileResult")) {
            if (iFrameUpload.document.getElementById("uploadFileResult").value == "OK") {
                iFrameUpload.document.getElementById("uploadFileResult").value = "";
                iFrameUpload.document.getElementById("resultTmp").value = "GO";
                if (boolFinish == true) {
                    window.clearTimeout (objTimeout);
                    blogAdd (strJsConfig, true, 1)
                } else {
                    loadParagraphPreviewList (strJsConfig);
                    window.clearTimeout (objTimeout);
                    hideBlogInput (strJsConfig);
                    document.uploadPicture.reset();
                    document.getElementById("btSaveParagraph").disabled = false;
                    showParagraphAdd('text', '', '');
                    return true;
                }
            }
        }

    } else {
        window.clearTimeout (objTimeout);
        return true;
    }

}

function blogAddPrepare (strJsConfig, boolRedirect) {

    if ($("#blog_headline").val() != "") {

        if ($("#mediaType").val() == 1 || $("#mediaType").val() == 2) {

            if ($("#blogMedia").val() != "") {
                prepareSaveParagraph (strJsConfig, true, true);
            } else {
                blogWaitForFinalSave (strJsConfig, boolRedirect);
            }

        } else if ($("#mediaType").val() == 3) {

            if ($("#inputContainer").attr ("style") == "display: none;") {
                blogWaitForFinalSave (strJsConfig, boolRedirect);
            } else {
                submitImage (strJsConfig, true);
            }

        }

    } else {

        alert ("Please fill out the headline!");

    }

}

function blogWaitForFinalSave (strJsConfig, boolRedirect) {

    objFinalTimeout = window.setTimeout ("blogAdd (\'"+strJsConfig+"\', "+boolRedirect+", 1, '')", 1000);

    if ($("#mediaType").val() == 1 || $("#mediaType").val() == 2) {
        if ($("#strBlogSubText").val() == "" || $("#blogMedia").val() == "") {
            blogAdd (strJsConfig, boolRedirect, 1);
            window.clearTimeout (objFinalTimeout);
            return true;
        }
    } else if ($("#mediaType").val() == 3) {
        if (iFrameUpload.document) {
            if (iFrameUpload.document.getElementById("resultTmp")) {
                if (iFrameUpload.document.getElementById("resultTmp").value == "GO") {
                    blogAdd (strJsConfig, true, 1, "");
                    window.clearTimeout (objFinalTimeout);
                    return true;
                }
            }
        } else {
            window.clearTimeout (objFinalTimeout);
        }
    }

}


function blogAdd (strJsConfig, boolRedirect, intStatus) {

    if ($("#blog_headline").val() != "") {

        var intYear = 0;
        if (document.getElementById ('event_year')) {
           intYear = document.getElementById ('event_year').options[document.getElementById ('event_year').selectedIndex].value;
        }

        var intMonth = 0;
        if (document.getElementById ('event_month')) {
           intMonth = document.getElementById ('event_month').options[document.getElementById ('event_month').selectedIndex].value;
        }

        var intDay = 0;
        if (document.getElementById ('event_day')) {
           intDay = document.getElementById ('event_day').options[document.getElementById ('event_day').selectedIndex].value;
        }

        var intYearTo = 0;
        if (document.getElementById ('event_year_to')) {
           intYearTo = document.getElementById ('event_year_to').options[document.getElementById ('event_year_to').selectedIndex].value;
        }

        var intMonthTo = 0;
        if (document.getElementById ('event_month_to')) {
           intMonthTo = document.getElementById ('event_month_to').options[document.getElementById ('event_month_to').selectedIndex].value;
        }

        var intDayTo = 0;
        if (document.getElementById ('event_day_to')) {
           intDayTo = document.getElementById ('event_day_to').options[document.getElementById ('event_day_to').selectedIndex].value;
        }

        if ($("#boolNoticeToFriends").attr("checked") == true) {
            var boolSendToMyFriends = 1;
        } else {
            var boolSendToMyFriends = 0;
        }

        $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.save", strHeadline: $("#blog_headline").val(), strTags: $("#blog_tags").val(), strYear: intYear, strMonth: intMonth, strDay: intDay, strYearTo: intYearTo, strMonthTo: intMonthTo, strDayTo: intDayTo, strJsConfig: strJsConfig, intStatus: intStatus, intOptBlogId: $("#intBlogId").val(), boolSendToMyFriends: boolSendToMyFriends, intCategory: intGetCategory(), intArea: intGetArea() }, function (data) {
                $("#intBlogId").val(data);

                if (boolRedirect == true) {

                    displayBlogList (strJsConfig);

                } else {

                    return true;

                }
            }
        );

    } else {

        alert ("Please fill out the headline!");

    }

}


function intGetCategory () {

    if (document.getElementById ('intCategory')) {
        var intCategory = document.getElementById ('intCategory').options[document.getElementById ('intCategory').selectedIndex].value;
    } else {
        var intCategory = 0;
    }

    return intCategory;

}

function intGetArea () {

    if (document.getElementById('intArea_static')) {

        var intArea = document.getElementById('intArea_static').value;

    } else {

        if (document.getElementById ('intArea')) {

            var intArea = document.getElementById ('intArea').options[document.getElementById ('intArea').selectedIndex].value;

        } else {

            var intArea = 0;

        }

    }

    return intArea;

}

function prepareSaveParagraph (strJsConfig, skipContentCheck, boolFinish) {

    if ($("#blog_headline").val() != "") {

        if ($("#blogMedia").val() != "" || skipContentCheck == true) {

            if ($("#intBlogId").val() == "") {

                if ($("#boolNoticeToFriends").attr("checked") == true) {
                    var boolSendToMyFriends = 1;
                } else {
                    var boolSendToMyFriends = 0;
                }

                $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.save", strHeadline: $("#blog_headline").val(), strTags: $("#blog_tags").val(), strJsConfig: strJsConfig, intStatus: 2, intOptBlogId: $("#intBlogId").val(), boolSendToMyFriends: boolSendToMyFriends, intCategory: intGetCategory(), intArea: intGetArea() }, function (data) {
                        $("#intBlogId").val(data);
                        saveParagraph (strJsConfig, boolFinish);
                    }
                );
            } else {
                saveParagraph (strJsConfig, boolFinish);
            }

        } else {
            alert ("Please fill out the paragraph media!");
        }
    } else {
        alert ("Please fill out the headline");
    }

}

function saveParagraph (strJsConfig, boolFinish) {

    if ($("#intBlogId").val() != "") {
        document.getElementById("btSaveParagraph").disabled = true;

        var intOptionalParagraphId = $("#intOptParagraphId").val();

        $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.saveparagraph", intBlogId: $("#intBlogId").val(), strBlogSubText: $("#strBlogSubText").val(), strBlogMedia: $("#blogMedia").val(), intMediaType: $("#mediaType").val(), strJsConfig: strJsConfig, intOptionalParagraphId: intOptionalParagraphId }, function (data) {

                var arrData = data.split(';');

                if (arrData[0] == "ERR") {
                    //alert ("An error occours. Please contact the development team: code:blog.js:saveParagraph()");
                    alert (arrData[1]);
                    document.getElementById("btSaveParagraph").disabled = false;
                    hideBlogInput ($("#mediaType").val());
                } else {

                    if (boolFinish == true) {

                        blogAdd (strJsConfig, true, 1);

                    } else {

                        document.getElementById("btSaveParagraph").disabled = false;
                        document.addParagraphInputForm.reset();
                        $("#strBlogSubText").val("");
                        $("#blogMedia").val("");
                        hideBlogInput ($("#mediaType").val());
                        loadParagraphPreviewList (strJsConfig);
                        showParagraphAdd ('text', strJsConfig, 0);
                        window.clearTimeout (handleTimeout);

                        return 0;

                    }

                }

            }
        );

    } else {

        handleTimeout = window.setTimeout ("saveParagraph(\'"+strJsConfig+"\'," +boolFinish+")", 500);

    }
}

function loadParagraphPreviewList (strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.paragraphlist", intBlogId: $("#intBlogId").val(), strJsConfig: strJsConfig }, function (data) {

            $("#preview_container").html (data);

        }

    );

}

function deleteParagraph (intParagraphId, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.deleteparagraph", intParagraphId: intParagraphId, strJsConfig: strJsConfig }, function (data) {

            if (data == 1) {

                loadParagraphPreviewList (strJsConfig);
                showBlogInput ();

            } else {

                alert ("An error occours. Please contact the development team: code:blog.js:deleteParagraph()");

            }

        }

    );

}

function showBlogInput () {
    $("#blog_topnav").show();
    $("#inputContainer").show();
}

function hideBlogInput (strJsConfig) {

    var arrSplitConfig = splitConfig(strJsConfig);

    if (arrSplitConfig[1] == 2 || arrSplitConfig[1] == 3) {
        $("#blog_topnav").hide();
        $("#inputContainer").hide();
    }
}

function blogAboAction (intBlogId, strJsConfig) {

    $.get ("index.php", { ajax: "applic|modules|blog|blog.base.php", ac: "blog.abo", $strJsConfig: strJsConfig, intBlogId: intBlogId }, function (data) {

            var arrData = data.split(';');

            $("#aboBlog").html(arrData[1]);
            //$("#aboBlog").attr("onClick", "blogAboAction("+intBlogId+",\""+strJsConfig+ "\");");
            //$("#aboBlog").attr("style", "");

        }

    );

}

function changeEventSort () {

    if (document.getElementById ('strCategorySelect')) {
        var strSearchCategory = document.getElementById ('strCategorySelect').options[document.getElementById ('strCategorySelect').selectedIndex].value;
    } else {
        var strSearchCategory = 0;
    }

    displayBlogList(strSearchCategory);

}

function showLoginInfoDyn () {

    $("#showlogininfo").show();

}

function jumpToLoginDyn () {

    boolShowSubnav ("register", "login", "lostpass");
    boolShowSubnav ("lostpass", "login", "register");
    location.href="#top";

}