﻿var Nethaber = Nethaber || {};
Nethaber.changeMansetCategory = function(catId) {
    $(".selectedCategory").removeClass("selectedCategory").addClass("menu");
    if (catId == -1) {
        $("#dvCategory-0").removeClass("menu").addClass("selectedCategory");
    }
    $("#dvCategory-" + catId).removeClass("menu").addClass("selectedCategory");
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/GalleryHandler.aspx?op=Cat&catId=' + catId,
        success: function(result) {
            $('#dvMansetPhotos').html(result);
            $('#dvMansetPhotos').galleryView({
                panel_width: 454,
                panel_height: 250,
                frame_width: 101,
                frame_height: 60,
                filmstrip_size: 6,
                background_color: 'transparent',
                show_captions: true,
                caption_text_color: 'black'
            });


        },
        error: function() {
            $('#dvMansetPhotos').html("Manşet haberler alırken hata oluştu");
        }
    });
}


Nethaber.changeMansetPage = function() {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/GalleryHandler.aspx?op=Page&catId=' + Nethaber.Category + '&pageNo=' + Nethaber.MansetPageNo,
        success: function(result) {
            $('#dvMansetPhotos').html(result);
            $('#dvMansetPhotos').galleryView({
                panel_width: 454,
                panel_height: 250,
                frame_width: 101,
                frame_height: 60,
                filmstrip_size: 6,
                background_color: 'transparent',
                show_captions: true,
                caption_text_color: 'black'
            });
        },
        error: function() {
            $('#dvMansetPhotos').html("Manşet haberler alırken hata oluştu");
        }
    });
}


Nethaber.changeTopicDetailPage = function(catId, topicDetailPageNo) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/TopicHandler.aspx?Id=' + catId + '&pageNo=' + topicDetailPageNo,
        success: function(result) {
            $('#TopicDetailResult').html(result);
            $('html,body').animate({ scrollTop: $('#TopicDetailResult').offset().top }, 1000);
        },
        error: function() {
            $('#TopicDetailResult').html("Konu detayları alınırken hata oluştu");
        }
    });
}

Nethaber.changeVitrinNewsPage = function(catId, VitrinNewsPageNo) {
    $('#VitrinNewsResult').animate({ "opacity": "toggle" }, "fast");
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/VitrinNewsHandler.aspx?catId=' + catId + '&pageNo=' + VitrinNewsPageNo,
        success: function(result) {
            $("#VitrinNewsResult").animate({ "opacity": "show" }, "fast");
            $('#VitrinNewsResult').html(result);
            $('html,body').animate({ scrollTop: $('#VitrinNewsResult').offset().top }, 1000);
        },
        error: function() {
            $('#VitrinNewsResult').html("Vitrin Haberleri alınırken hata oluştu");
        }
    });
}
Nethaber.changeNewsDetailCommentPage = function(newsId, PageNo) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/NewsDetailCommentHandler.aspx?newsId=' + newsId + '&pageNo=' + PageNo,
        success: function(result) {
            //  $("#NewsDetailCommentResult").animate({ "opacity": "show" }, "fast");
            $('#NewsDetailCommentResult').html(result);
            $('html,body').animate({ scrollTop: $('#NewsDetailCommentResult').offset().top }, 1000);
        },
        error: function() {
            $('#NewsDetailCommentResult').html("Yorumlar alınırken hata oluştu");
        }
    });
}
Nethaber.changeCommentPage = function(PageNo) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/CommentHandler.aspx?pageNo=' + PageNo,
        success: function(result) {
            //  $("#NewsDetailCommentResult").animate({ "opacity": "show" }, "fast");
            $('#CommentsResult').html(result);
            $('html,body').animate({ scrollTop: $('#CommentsResult').offset().top }, 1000);
        },
        error: function() {
            $('#CommentsResult').html("Yorumlar alınırken hata oluştu");
        }
    });
}

Nethaber.changeSearchPage = function(searchStr, PageNo) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/SearchHandler.aspx?searchStr=' + searchStr + '&pageNo=' + PageNo,
        success: function(result) {
            //  $("#NewsDetailCommentResult").animate({ "opacity": "show" }, "fast");
            $('#SearchResult').html(result);
            $('html,body').animate({ scrollTop: $('#SearchResult').offset().top }, 1000);
        },
        error: function() {
            $('#SearchResult').html("Arama Sonuçları alınırken hata oluştu");
        }
    });
}

Nethaber.changeMostReadNews = function(catId, day) {
    $("#load-data").show();
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/MostReadNewsHandler.aspx?catId=' + catId + '&day=' + day,
        success: function(result) {
            $("#MostReadNewsResult").animate({ "opacity": "show" }, "fast");
            $('#MostReadNewsResult').html(result);
            $(".mostread-selected").removeClass("mostread-selected").addClass("mostread-nostyle");
            $("#mostread-" + day).removeClass("mostread-nostyle").addClass("mostread-selected");
            $("#load-data").hide();
        },
        error: function() {
            $('#MostReadNewsResult').html("Haberler alınırken hata oluştu");
            $("#load-data").hide();
        }
    });
}

Nethaber.changeMostCommentedNews = function(catId, day) {
    $("#loadComment-data").show();
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/MostCommentedNewsHandler.aspx?catId=' + catId + '&day=' + day,
        success: function(result) {
            $("#MostCommentedNewsResult").animate({ "opacity": "show" }, "fast");
            $('#MostCommentedNewsResult').html(result);
            $(".mostcommented-selected").removeClass("mostcommented-selected").addClass("mostcommented-nostyle");
            $("#mostcommented-" + day).removeClass("mostcommented-nostyle").addClass("mostcommented-selected");
            $("#loadComment-data").hide();
        },
        error: function() {
            $('#MostCommentedNewsResult').html("Haberler alınırken hata oluştu");
            $("#loadComment-data").hide();
        }
    });
}


Nethaber.changeTopicListPage = function(pageNo, s) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/TopicListHandler.aspx?op=get&pageNo=' + pageNo + '&s=' + s,
        success: function(result) {
            $('#TopicListResult').html(result);
        },
        error: function() {
            $('#TopicListResult').html("Haberler alınırken hata oluştu");
        }
    });
}

Nethaber.searchTopicListPage = function(searchStr, pageNo, s) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/TopicListHandler.aspx?op=search&search=' + searchStr + '&pageNo=' + pageNo + '&s=' + s,
        success: function(result) {
            $('#TopicListResult').html(result);
            $('#txtSearch').html() = searchStr;
        },
        error: function() {
            $('#TopicListResult').html("Haberler alınırken hata oluştu");
        }
    });
}
Nethaber.changeNewsIndexDate = function(startDate) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/NewsIndexHandler.aspx?date=' + startDate,
        success: function(result) {
            $('#AllNewsIndexResult').html(result);
        },
        error: function() {
            $('#AllNewsIndexResult').html("Haberler alınırken hata oluştu");
        }
    });
}

Nethaber.changeNewsCommentPage = function(newsId, pageNo) {
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/NewsCommentHandler.aspx?newsId=' + newsId + '&pageNo=' + pageNo,
        success: function(result) {
            $('#NewsCommentResult').html(result);
            $('html,body').animate({ scrollTop: $('#NewsCommentResult').offset().top }, 1000);
        },
        error: function() {
            $('#NewsCommentResult').html("Yorumlar alınırken hata oluştu");
        }
    });
}

Nethaber.showVitrinCommentPage = function(newsId, pageNo) {
    //$('.WrittenComments').hide();
    var InnerHtml = $("#comments-" + newsId).html();
    if (jQuery.trim(InnerHtml) != "") {
        $("#comments-" + newsId).slideToggle(800);
        return;
    }
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/VitrinNewsCommentHandler.aspx?newsId=' + newsId + '&pageNo=' + pageNo,
        success: function(result) {
            $("#comments-" + newsId).css("display", "none");
            $("#comments-" + newsId).html(result);
            $("#comments-" + newsId).slideToggle(800);

        },
        error: function() {
            $('.WrittenComments').html("Yorumlar alınırken hata oluştu");
        }
    });
}

Nethaber.changeVitrinCommentPage = function(newsId, pageNo) {
    //$('.WrittenComments').hide();
    //    if ($("#comments-" + newsId).html() != "") {
    //        $("#comments-" + newsId).slideToggle(800);
    //        return;
    //    }
    $.ajax({
        type: 'GET',
        url: Nethaber.AppRoot + 'AjaxHandlers/VitrinNewsCommentHandler.aspx?newsId=' + newsId + '&pageNo=' + pageNo,
        success: function(result) {
            $("#comments-" + newsId).html(result);
        },
        error: function() {
            $('.WrittenComments').html("Yorumlar alınırken hata oluştu");
        }
    });
}

Nethaber.MansetPageNo = 0
Nethaber.RssManager = {
    getRss: function(guid) {
        $('#RssAccessResult').html("Rss okunuyor...");
        $.ajax({
            type: 'GET',
            url: Nethaber.AppRoot + 'AjaxHandlers/RssHandler.aspx',
            data: 'op=get&g=' + guid,
            success: function(result) {
                $('#RssFeedResult').html(result);
                $('#RssAccessResult').html("RSS'ler okundu");
            },
            error: function() {
                $('#RssFeedResult').html("Rss okunurken hata oluştu");
                $('#RssAccessResult').html("Rss okunurken hata oluştu");
            }
        });
    },
    addRss: function(guid, url) {
        $.ajax({
            type: 'GET',
            url: Nethaber.AppRoot + 'AjaxHandlers/RssHandler.aspx',
            data: 'op=add&g=' + guid + '&url=' + url,
            success: function(result) {
                if (result != "") {
                    eval(result);
                    return;
                }
                Nethaber.RssManager.getRss(guid);
                Nethaber.RssManager.getRssList(guid);
                //  HideElm('index-rss-bg');
            },
            error: function() {
                $('#RssFeedResult').html("Rss okunurken hata oluştu");
                $('#RssAccessResult').html("Rss okunurken hata oluştu");
            }
        });
    },
    getRssList: function(guid) {
        $('#RssAccessResult').html("Rss okunuyor...");
        $.ajax({
            type: 'GET',
            url: Nethaber.AppRoot + 'AjaxHandlers/RssHandler.aspx',
            data: 'op=getList&g=' + guid,
            success: function(result) {
                $('#StoredRssList').html(result);
                $('#RssAccessResult').html("Rss okundu");
            },
            error: function() {
                $('#RssFeedResult').html("Rss okunurken hata oluştu");
            }
        });
    }
}
Nethaber.SetPageIsPopup = function() {

    var cookieIsPopup = new Nethaber.CookieManager("nethaber_IsPopup", 365, '/', '', '~');
    var cookieIsPopup = cookieIsPopup.get_Cookie();
    if (cookieIsPopup == 0) {
        $("a[name='IsPopup']").attr('target', '_parent');
    }
    if (cookieIsPopup == 1) {
        $("a[name='IsPopup']").attr('target', '_blank');
    }
}

function ShowElm(elmId) {
    $("#" + elmId).fadeIn("slow");
}
function HideElm(elmId) {
    $("#" + elmId).hide();
}

function changeSize(elm, size) {
    document.getElementById(elm).style.fontSize = size + 'px';
}
function changeSizeByClass(elm, size) {
    $("." + elm).css("fontSize", size + "px");
}

/* Realtime Clock */
var tick;
function stop() {
    clearTimeout(tick);
}
function usnotime() {
    var ut = new Date();
    var h, m, s;
    var time = "      ";
    h = ut.getHours();
    m = ut.getMinutes();
    s = ut.getSeconds();
    if (s <= 9) s = "0" + s;
    if (m <= 9) m = "0" + m;
    if (h <= 9) h = "0" + h;
    time += h + ":" + m + ":" + s + " ";

    document.getElementById('lblHour').innerHTML = time;
    tick = setTimeout("usnotime()", 1000);
}
/* Realtime Clock */
function submitenter(myfield, e) {
    var keycode; if (window.event) keycode = window.event.keyCode; else if (e) keycode = e.which; else return true;
    if (keycode == 13) {
        //myfield.form.submit();
        SearchNews();
        return false;
    } else
        return true;
}
