var isLentaLoadInProcess = false;
var isVideoNewsInProgress = false;
integrio.js.includeUseTag = true;

function selectLastLenta(td) {
    loadLenta(td, "publicationDate");
}
function selectPopularLenta(td) {
    loadLenta(td, "hits");
}

function selectLastVideo(td) {
    loadVideo(td, "publicationDate");
}
function selectPopularVideo(td) {
    loadVideo(td, "hits");
}

function loadLenta(td, order) {
    if (td.className == "aTab") {
        return;
    }
    if (isLentaLoadInProcess) {
        return;
    }
    var container = document.getElementById("left_column_lenta").getElementsByTagName("DIV")[0];
    document.getElementById("left_column_lenta").scrollTop = 0;
    isLentaLoadInProcess = true;
    var tr = td.parentNode;
    for (var i = 0; i < tr.cells.length; i++) {
        if (tr.cells.item(i).className == "aTab") {
            tr.cells.item(i).className = "tab";
        }
    }
    td.className = "aTab";
    container.innerHTML = "Загрузка ... ";
    integrio.js.include("integrio.majax");
    integrio.MAJAX.processAjax("getLentaArticles", "/modules/sport/ajax/index.jsp", "lentaArticles", {order:order}, loadLentaComplete);
}

function loadLentaComplete() {
    var container = document.getElementById("left_column_lenta").getElementsByTagName("DIV")[0];
    isLentaLoadInProcess = false;
    container.innerHTML = this.getParameter("articles");
}

function loadVideo(td, order) {
    if (td.className == "aTab") {
        return;
    }
    if (isVideoNewsInProgress) {
        return;
    }
    var container = document.getElementById("videonews").getElementsByTagName("DIV")[0];
    document.getElementById("videonews").scrollTop = 0;
    isVideoNewsInProgress = true;
    var tr = td.parentNode;
    for (var i = 0; i < tr.cells.length; i++) {
        if (tr.cells.item(i).className == "aTab") {
            tr.cells.item(i).className = "tab";
        }
    }
    td.className = "aTab";
    container.innerHTML = "Загрузка ... ";
    integrio.js.include("integrio.majax");
    integrio.MAJAX.processAjax("getVideoArticles", "/modules/sport/ajax/index.jsp", "videoArticles", {order:order}, loadVideoComplete);
}
function loadVideoComplete() {
    var container = document.getElementById("videonews").getElementsByTagName("DIV")[0];
    isVideoNewsInProgress = false;
    container.innerHTML = this.getParameter("articles");
}
