﻿var $j = jQuery.noConflict();
var pageSum = 1;
var isPostBack = false;
$j(document).ready(function() {
    pageSum = $j('#hidden_pageSum').val();
    initSelect(pageSum);
    isPostBack = true;
    $j('#ddlPageIndex1').val('0');
    $j('#ddlPageIndex2').val('0');
    $j('h5').click(function() {
        $j(this).next().slideToggle('fast',
        function() {
            $j(this).next().next().toggle(200);
        });
    });
});

function loadNews(pageIndex) {
    $j('#div_newsWait').show();
    $j('#div_newsWait2').show();
    $j.ajax({
        url: '/NewsDataDispose.aspx?rd=' + Math.random(),
        type: 'get',
        data: 'operate=OutNews&pageIndex=' + pageIndex,
        dataType: 'html',
        success: function(json) {
            $j('#div_newsWait').hide();
            $j('#div_newsWait2').hide();
            if (json == '') {
                return;
            }
            var arrNews = json.split('┣');
            var newsContent = '';
            pageSum = parseInt(arrNews[0].split('├')[3]);
            if (!isPostBack) {
                initSelect(pageSum);
                isPostBack = true;
            }
            document.getElementById('ddlPageIndex1').value = pageIndex;
            document.getElementById('ddlPageIndex2').value = pageIndex;
            for (var i = 0; i < arrNews.length; i++) {
                var news = arrNews[i].split('├');
                newsContent += '<h5 style="cursor: pointer;"><img src="images/li.gif" /><a href="/News/' + news[5] + '" target="_blank">' + news[0] + '</a></h5>';
                newsContent += '<div><p>' + news[1] + '</p></div><br />';
                newsContent += '<div style="margin-left: 75%;">' + news[2] + '</div>';
            }
            $j('#div_news').html(newsContent);
            $j('h5').click(function() {
                $j(this).next().slideToggle('fast',
                function() {
                    $j(this).next().next().toggle(200);
                });
            });
        }
    });
}

function initSelect(count) {
    var select1 = document.getElementById('ddlPageIndex1');
    var select2 = document.getElementById('ddlPageIndex2');
    select1.length = 0;
    select2.length = 0;
    for (var i = 0; i < count; i++) {
        select1.options.add(new Option(i + 1, i));
        select2.options.add(new Option(i + 1, i));
    }
}

function pageChange(step) {
    var currentPageIndex = parseInt(document.getElementById('ddlPageIndex1').value);
    // if the current pageIndex is the last pageIndex
    if (currentPageIndex == (pageSum - 1) && step == 1) {
        return;
    }
    // if the current pageIndex is the first pageIndex
    if (currentPageIndex == 0 && step == -1) {
        return
    }
    loadNews(parseInt(currentPageIndex + step));
}

function totrack(id) {
    var trackcontrol = document.getElementById("GoldLeft1_ " + id);
    if (id != null) {
        var trackvalue = trackcontrol.value;
        top.window.location = '/TrackOrder.aspx?search=' + trackvalue;
    }
}