﻿function alterCustomTab(objLi, tabId, sectionId, containerId) {
    var objUl = $(objLi).parent();
    var l = objUl.find("li").length;
    if (!objUl.find("li").eq(sectionId - 1).hasClass("focus")) {
        $.get("/Ashx/Ajax/Index/Block3.ashx?Action=AlterTab", { SectionId: sectionId }, function(data) {
            $("#CustomSection" + containerId).html(data);
        });
        if (tabId > l) {
            switch (l) {
                case 2: tabId = tabId % 2 == 0 ? 2 : 1; break;
                case 3:
                    var yu = tabId % 3;
                    if (yu == 2) tabId = 2;
                    if (yu == 0) tabId = 3;
                    if (yu == 1) tabId = 1;
                    break;
            }
        }
        objUl.find("li").each(function(i) {
            if ((i + 1) != tabId)
                $(this).removeClass("focus");
            else
                $(this).addClass("focus");
        });
    }
}

function alterTab(objLi, sectionId, sectionType) {
    var objUl = $(objLi).parent();
    var l = objUl.find("li").length;

    //如果具有focus 则忽略操作
    if (!objUl.find("li").eq(sectionId - 1).hasClass("focus")) {
        $("#NewsSection").css({ lineHeight: "500%", textAlign: "center" }).text("数据载入中...");
        alterSlideShow(objUl, sectionId, sectionType);

        if (sectionId != 0) {
            $.get("/Ashx/Ajax/Index/Block1.ashx?Action=AlterTab", { SectionName: "PicFocus", SectionId: sectionId }, function(data) {
                $("#NewsSection").html(data);
            });
        }
        else {
            alterMedia(sectionType);
        }
        objUl.find("li").each(function(i) {
            var alterId = sectionId != 0 ? sectionId : sectionType + 4;
            if ((i + 1) != alterId)
                $(this).removeClass("focus");
            else
                $(this).addClass("focus");
        });
    }

}

function alterSlideShow(objUl, curSectionId, sectionType) {
    if (sectionType == 2) curSectionId = 5;
    var allLi = objUl.find("li");
    var focusToFind = objUl.find("li.focus");
    var pos = allLi.index(focusToFind);

    if (pos < 5 && curSectionId == 5) {

        $("#IndexShower_L").html('<img src="/Images/index_ready_play.jpg" alt="请选择您要播放的视频" />');
    }
    else if (pos == 5 && curSectionId < 5) {
        $.get("/Ashx/Ajax/Index/Block1.ashx?Action=AlterTab", { SectionName: "NewsSection" }, function(res) {
            $("#NewsSection").html(res);
        })
    }
    else { return; }
}

function alterMedia(type) {
    var sectionName = type == 1 ? "PicFocus" : "MediaList";
    $.get("/Ashx/Ajax/Index/Block1.ashx?Action=AlterTab", { SectionName: sectionName, SectionId: -1 }, function(data) {
        $("#NewsSection").html(data);
    });
}

function playVideo(videoSource, isAutoPlay) {
    $.get("/Ashx/Ajax/Index/Block1.ashx?Action=PlayMedia", { VideoIsAutoPlay: isAutoPlay, Source: videoSource }, function(data) {
        $("#IndexShower_L").html(data);
    });
}

function alterTel(tabid) {
    var obj = $("#Block3_L .title li");
    obj.removeClass("focus");
    obj.eq(tabid).attr("class", "focus");
    $("input[name='SearchType']").val(tabid);
}

function alterShopList(showType) {
    var tabId = showType == "Category" ? 0 : 1;
    var obj = $("#Block6_R_Title li");
    obj.removeClass("focus");
    obj.eq(tabId).attr("class", "focus");
    $.get("/Ashx/Ajax/Index/Block6.ashx?Action=AlterTab", { ShowType: showType }, function(data) {
        $("#RoamSection").html(data);
    });
}

function reloadProduct() {
    $.get("/Ashx/Ajax/Index/Block6.ashx?Action=ReloadProduct", function(html) {
        $("#ProductSection > div:last").html(html);
    });
}


function alterBill(tabId, blockId, cateId) {
    var obj = $(".blockBill .container").eq(blockId - 1).find(".title ul li");
    obj.removeClass("focus").eq(tabId - 1).addClass("focus");
    $.get("/Ashx/Ajax/Index/Block7.ashx?Action=AlterBill", { CateId: cateId }, function(html) {
        $("#BillListSection" + blockId).html(html);
    });

}

function g(formname) {
    var url = "http://www.baidu.com/baidu";
    if (!formname.s[0].checked) {
        for (var i = 1; i < 4; i++) {
            if (formname.s[i].checked == true)
                formname.si.value = formname.s[i].value;
        }
        formname.ct.value = "2097152";
    }
    else {
        formname.ct.value = "0";
    }
    formname.action = url;
    return true;
}