﻿function OnTimeout(value) {
    jAlert("OOPS - Timeout","Hata!");
}

function OnError(value) {
    jAlert("Oops - ERROR", "Hata!");
}
$(document).ready(function () {

    $("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav

    $("ul.topnav li").mouseover(function () { //When trigger is clicked...
        var cthis = $(this).children("span");
        if (!cthis.hasClass("subhover")) {
            $(this).children("ul.subnav").slideDown(500); //Drop down the subnav on click
            cthis.addClass("subhover");
        }




    }).mouseleave(function () {
        //$(this).children("span").removeClass("subhover"); 
        var cthis = $(this).children("span");
        if (cthis.hasClass("subhover")) {
            $(this).children("ul.subnav").slideUp(500, function fn() { cthis.removeClass("subhover"); }); //When the mouse hovers out of the subnav, move it back up
        }


    });


});

$(function () {
    
    $("#txtSearch").keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $("#btnSearch").click();
            return false;
        } else {
            return true;
        }
    });
});  
function OnSendCommentMessage(value) {
    
    if (value[0].toLocaleString() == "busy") {
        jAlert("Sunucu şu an meşgul lütfen daha sonra tekrar deneyiniz.", "Hata!");
    }
    else if (value[0].toLocaleString() == "ok") {
        jAlert("Mesajınız kaydedildi");
        xComment.css("display", "none");
        $("#comment" + value[1].toLocaleString() + " .commentwrapper .sendreply").after(value[2].toLocaleString());
    }
    else if (value[0].toLocaleString() == "limit") {
        jAlert("Yeni bir gönderim için bir dakika beklemeniz gerekmekte.", "Hata!");
     }
     else if (value[0].toLocaleString() == "member") {
         jAlert("Giriş yapmanız gerekiyor.", "Hata!");
     }

}

function OnCompleteFollow(value) {

    if (value[0].toLocaleString() == "1") {
        $(".follow strong").text("Takipten Çık");
        $(".follow").removeClass().addClass("unfollow");
        folGlobal = false;
    }
    else if (value[0].toLocaleString() == "0") {
        jAlert("Lütfen giriş yapınız!", "Hata!");
    }
    else if (value[0].toLocaleString() == "-1") {
        jAlert("Bir hata oluştu", "Hata!");
    }
}
function OnCompleteUnFollow(value) {
    if (value[0].toLocaleString() == "1") {
        $(".unfollow strong").text("Takip ET");
        $(".unfollow").removeClass().addClass("follow");
        folGlobal = true;
    }
    else if (value[0].toLocaleString() == "0") {
        jAlert("Lütfen giriş yapınız!", "Hata!");
    }
    else if (value[0].toLocaleString() == "-1") {
        jAlert("Bir hata oluştu", "Hata!");
    }

}
function OnSendPostMessage(value) {

    if (value[0].toLocaleString() == "busy") {
        jAlert("Sunucu şu an meşgul lütfen daha sonra tekrar deneyiniz.", "Uyarı!");
    }
    else if (value[0].toLocaleString() == "ok") 
    {
        jAlert("Mesajınız Kaydedildi", "Uyarı!");

        if ($("#postcomments div").is(".commentx") || $("#postcomments div").is(".commenty")) 
        {
            $("#postcomments div[id^=comment]:last").after(value[2].toLocaleString());
            alert(value[2].toLocaleString());
        }
        else 
        {
            $("#postcomments span").after(value[2].toLocaleString());
        }

        xComment.hide();

   }
    else if (value[0].toLocaleString() == "limit") {
        jAlert("Yeni bir gönderim için bir dakika beklemeniz gerekmekte.", "Uyarı!");
    }
    else if (value[0].toLocaleString() == "member") {
        jAlert("Giriş yapmanız gerekmekte.", "Hata!");
    }

}
function OnReply(value) {
    $("#comment" + value[0].toLocaleString() + " .commentwrapper .reply").hide();
    $("#comment" + value[0].toLocaleString() + " .commentwrapper .sendreply").after(value[1].toLocaleString());
}
function OnVote(value) {

    if (value[1] > 0) {
        $("#post" + value[0].toLocaleString() + " .postinfo h4").fadeIn(1000).text(value[1].toLocaleString());
        $("#post" + value[0].toLocaleString() + " .votebutton").text('Oylandı');
        $("#post" + value[0].toLocaleString() + " .votebutton").attr("onclick", "");
        $("#post" + value[0].toLocaleString() + " .votebutton").removeClass().addClass("votedbutton");
    }
    else if (value[1] == -2) {
        jAlert("Giriş yapmanız gerekmekte!", "Hata!");
    }
    else if (value[1] == -3) {
        jAlert("Bu içeriğe daha önce oy vermişsiniz!", "Hata!");
    }
    else if (value[1] == -4) {
        jAlert("Kendi gönderdiğiniz içeriğe oy veremezsiniz!", "Hata!");
    }
}
function OnComment(value) {

    if (value[1] != -100000) {

        $("#comment" + value[0].toLocaleString() + " .point .commentpoint").text(value[1].toLocaleString());
        $("#comment" + value[0].toLocaleString() + " .point .commentpoint").css("font-weight", "bold");
        if (value[2].toLocaleString() == "-1") {
            $("#comment" + value[0].toLocaleString() + " .point .minus").addClass("passiveminus");
            //click temizle
        }
        else {
            $("#comment" + value[0].toLocaleString() + " .point .plus").addClass("passiveplus");
            //click temizle
        }
        if (value[3].toLocaleString() != "0") {
            if (value[3].toLocaleString() == "1") {
                var xPlus = $("#comment" + value[0].toLocaleString() + " .plus");

                $("#comment" + value[0].toLocaleString() + " .passiveplus").removeClass("passiveplus").addClass("plus"); // .after("<div class=\"commentvote minus xxx\" onclick='CommentVote(" + value[0].toLocaleString() + ",-1)'>[-1]</div>");
                $("#comment" + value[0].toLocaleString() + " .passiveminus").removeClass("passiveminus").addClass("minus"); // .after("<div class=\"commentvote plus xxx\" onclick='CommentVote(" + value[0].toLocaleString() + ",1)'>[+1]</div>");
               
            }
            else {
                var xMinus = $("#comment" + value[0].toLocaleString() + " .minus");

                $("#comment" + value[0].toLocaleString() + " .passiveminus").removeClass("passiveminus").addClass("minus"); // .after("<div class=\"commentvote plus xxx\" onclick='CommentVote(" + value[0].toLocaleString() + ",1)'>[+1]</div>");
                $("#comment" + value[0].toLocaleString() + " .passiveplus").removeClass("passiveplus").addClass("plus"); // .after("<div class=\"commentvote minus xxx\" onclick='CommentVote(" + value[0].toLocaleString() + ",-1)'>[-1]</div>");


               
            }
        }


    }
}

function OnComplete(value) {
    $("#typeposts").remove();
    $(value).appendTo("#leftside");
}
function OnCompleteRoot(value) {
    $("#typeposts").remove();
    $(value).appendTo("#leftside");
}
function OnCompleteRoot(value) {
    $("#typeposts").remove();
    $(value).appendTo("#leftside");
}
function OnCompleteComment(value) {
    $("#postcomments").remove();
    $(value).appendTo("#leftside");
}
function GetPage(prmPageNumber, prmPageTypeID,prmClassID) {

    //    $("#typeposts").fadeOut(100, function fn() { $("#typeposts").remove(); });
    $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
    //jAlert($("#typeposts").height());
    $("#pager").remove();
    $("#popmenu li a.current").removeClass();
    $("#popmenu li:nth-child("+(4-prmPageTypeID)+") a").addClass("current");
    reVal = MyAtlas.GetTypePage(prmPageNumber, prmPageTypeID, prmClassID, OnComplete, OnTimeout, OnError);
}
function GetCategoryPage(prmPageNumber, prmPageTypeID,prmCategoryID,prmClassID) {
    $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
    $("#pager").remove();
    $("#popmenu li a.current").removeClass();
    $("#popmenu li:nth-child(" + (4 - prmPageTypeID) + ") a").addClass("current");
    reVal = MyAtlas.GetCategoryTypePage(prmPageNumber, prmPageTypeID,prmCategoryID,prmClassID, OnComplete, OnTimeout, OnError);
}
function GetTagPage(prmPageNumber, prmTagID) {
    $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
    $("#pager").remove();
    reVal = MyAtlas.GetTagPage(prmPageNumber, prmTagID,OnCompleteRoot, OnTimeout, OnError);
}
function GetCommentPage(prmPageNumber, prmCommentID) {
    $("#postcomments").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
    $(".sss").remove();
    reVal = MyAtlas.GetCommentPage(prmPageNumber, prmCommentID, OnCompleteComment, OnTimeout, OnError);
}
function PostVote(prmPostID) {
    $("#post" + prmPostID + " .postinfo h4").fadeOut(500);
    reVal = MyAtlas.PostVote(prmPostID,OnVote, OnTimeout, OnError);

}
function CommentVote(prmCommentID, prmVoteType) {
    reVal = MyAtlas.CommentVote(prmCommentID,prmVoteType, OnComment, OnTimeout, OnError);

}

$(function() {
$(".txtbox").focus(function() { $(this).next("span").css("display", "inline"); $(this).addClass("txtfocus"); });
$(".txtbox").blur(function() { $(this).next("span").css("display", "none"); $(this).removeClass("txtfocus") });
});
function shower() {
    //$("#myhidx").css("visibility", "hidden");
    $(".myhidx").hide();
    $(".myfx").hide();
    $(".myhidx").fadeIn(500, function() { $(".myfx").fadeIn(500) });
    
        $(".txtbox").focus(function() { $(this).next("span").css("display", "inline"); $(this).addClass("txtfocus"); });
        $(".txtbox").blur(function() { $(this).next("span").css("display", "none"); $(this).removeClass("txtfocus") });
    }
    function close() {
        $(".myhidx").hide();
        $(".myfx").hide();
    }
    
    function ShowComment(prmCommentID) {
        if ($("#comment" + prmCommentID + " .commentwrapper .message").hasClass("hide")) {
           $("#comment" + prmCommentID + " .commentwrapper .message").removeClass("hide");
            $("#comment" + prmCommentID + " .commentwrapper .reply").removeClass("hide");
            $("#comment" + prmCommentID + " .commentwrapper .show").text("Mesajı Gizle");  
        }
        else {
         $("#comment" + prmCommentID + " .commentwrapper .message").addClass("hide");
            $("#comment" + prmCommentID + " .commentwrapper .reply").addClass("hide");
            $("#comment" + prmCommentID + " .commentwrapper .show").text("Mesajı Göster");  
                         
        }
    }

    function ShowReplies(prmCommentID) {
        reVal = MyAtlas.ShowReplies(prmCommentID, OnReply, OnTimeout, OnError);
    }
    var xComment;
    $(function() {
    
            xComment = $("#pnlComment");
        
    });

    function ShowCommentForm(prmCommentID) {
        //jAlert($("#comment" + prmCommentID + " .commentwrapper .sendreply").html());
        xComment.show();
        xComment.appendTo($("#formarea"+prmCommentID));
        //xComment.css("display", "inline");
        $("#hdnCommentID").val(prmCommentID);
        $("#txtComment").val('')
        
    }
    function SendComment() {
        var CommentID = $("#hdnCommentID").val();
        if (CommentID != "") {
            var CommentID = $("#hdnCommentID").val();
            var Message = $("#txtComment").val();
            reVal = MyAtlas.SendCommentMessage(CommentID, Message, OnSendCommentMessage, OnTimeout, OnError);
        }
        else {
            var PostID = $("#hdnPostID").val();
            var Message = $("#txtComment").val();
            reVal = MyAtlas.SendPostMessage(PostID, Message, OnSendPostMessage, OnTimeout, OnError);
        
        }
        
        
    }
    function GetMemberPosts(prmPageNumber, prmMemberID, prmCategoryID) {
        $("div .item").removeClass("current");
        $("#posts .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");

//        $("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberPosts(prmPageNumber, prmMemberID, prmCategoryID, OnCompleteRoot, OnTimeout, OnError);
    }

    function GetMemberVotes(prmPageNumber, prmMemberID, prmCategoryID) {
        $("div .item").removeClass("current");
        $("#votes .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");                    
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberVotes(prmPageNumber, prmMemberID, prmCategoryID, OnCompleteRoot, OnTimeout, OnError);
    }

    function GetMemberComments(prmPageNumber, prmMemberID) {
        $("div .item").removeClass("current");
        $("#comments .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberComments(prmPageNumber, prmMemberID, OnCompleteRoot, OnTimeout, OnError);
    }
    function GetMemberTags(prmPageNumber, prmMemberID,prmCategoryID,prmTagID) {
        $("div .item").removeClass("current");
        $("#comments .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberTags(prmPageNumber, prmMemberID, prmCategoryID, prmTagID, OnCompleteRoot, OnTimeout, OnError);
    }
    function PostCommentShow(prmPostID) {
        xComment.css("display", "inline");
        $("#hdnPostID").val(prmPostID);
        $("#txtComment").val('')

    }
    var folGlobal = -1;
    function Follow(prmTo,prmBool) {
        if (folGlobal == -1) {
            if (prmBool) {
                reVal = MyAtlas.Subscribe(prmTo, OnCompleteFollow, OnTimeout, OnError);
            }
            else {
                reVal = MyAtlas.UnSubscribe(prmTo, OnCompleteUnFollow, OnTimeout, OnError);
            }
        }
        else {
            if (folGlobal) {
                reVal = MyAtlas.Subscribe(prmTo, OnCompleteFollow, OnTimeout, OnError);
            }
            else {
                reVal = MyAtlas.UnSubscribe(prmTo, OnCompleteUnFollow, OnTimeout, OnError);
            }
        }


    }  
    
    function GetMemberSubscribers(prmPageNumber, prmMemberID) {
        $("div .item").removeClass("current");
        $("#subscribers .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberSubscribers(prmPageNumber, prmMemberID, OnCompleteRoot, OnTimeout, OnError);
    }
    function GetMemberSubscriptions(prmPageNumber, prmMemberID) {
        $("div .item").removeClass("current");
        $("#subscriptions .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.MemberSubscriptions(prmPageNumber, prmMemberID, OnCompleteRoot, OnTimeout, OnError);
    }
    function GetSocialStream(prmMemberID,prmPageNumber, prmCategoryID) {
        $("div .item").removeClass("current");
        $("#social .item").addClass("current");
        $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
        //$("#membervotes").remove();
        $("#pager").remove();
        reVal = MyAtlas.SocialStream(prmMemberID,prmPageNumber, prmCategoryID, OnCompleteRoot, OnTimeout, OnError);
    }
    function GetMemberSearch(prmPageNumber,prmMemberID) {
        var query=$("#txtSearch").val();
        //        OnCompleteRoot($("#txtSearch").val());
        if (query.length > 2) {
            $("#typeposts").html("<div style=\"clear:both;min-height:500px;text-align:center\"><img style=\"margin-top:50px\" src=\"/themes/theme3/images/layout/19-1.gif\"></div>");
            //$("#membervotes").remove();
            $("#pager").remove();
            if ($('#cbMember:checked').val() != null) {
                reVal = MyAtlas.Search(prmPageNumber, prmMemberID, query, OnCompleteRoot, OnTimeout, OnError);
            }
            else {
                reVal = MyAtlas.Search(prmPageNumber, 0, query, OnCompleteRoot, OnTimeout, OnError);
            }
        }
        else {
            jAlert("Arama terimi en az 3 harften oluşmalı", "Dikkat!");
        }
        
    }

    
