﻿
$.fn.serializeNoViewState = function () {
    return this.find("input,textarea,select,hidden")
                        .not("[type=hidden][name^=__]")
                        .serialize();
}
//หากต้องการส่ง Form ทั้งหมด

function callAjax(targetURL, params, respFunc) {
    jQuery.ajax({
        type: "POST",
        datatype: "script",
        scriptCharset: "UTF-8",
        url: targetURL,
        //data: jQuery("#form1").serialize(),
        //data: $("#form1").serializeNoViewState(),
        data: params,
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Accept-Charset", "UTF-8");
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        },
        /*
        success: function (data) {
        //jQuery("#dialog").html(data); 
        }
        */
        success: respFunc
    });
}

$(document).ready(function () {
    $("#tabLastItemsUpdate").attr("style", "cursor:hand");
    $("#tabLastItemsUpdateStar").attr("style", "cursor:hand");
    $("#tabLastItemAdd").attr("style", "cursor:hand");

    var SelectTab;

    $("#imgLastItemsUpdate").click(function () {
        ShowTab1();

    });
    $("#imgLastItemsUpdateStar").click(function () {
        ShowTab2();

    });
    $("#imgLastItemAdd").click(function () {
        ShowTab3();

    });

    if (SelectTab == "tab3") {
        $("#imgLastItemAdd").attr("src", "images/tabLastItemAddOver.jpg");
        ShowTab3();
    }
    else if (SelectTab == "tab2") {
        ShowTab2();
    }
    else {
        ShowTab1();
    }
    /* ทำให้ปุ่มเป็นขอบมน ยกเว้น IE (มันทำไม่ได้) */
    var IE_error = 0;
    var mybrowser = navigator.userAgent;
    if (mybrowser.indexOf('MSIE') <= 0) {
        $('#TopView').corner('top 10px');
        $('#NewShop').corner('top 10px');
        $('#LastBid').corner('top 10px');
        $('#ShopStar').corner('top 10px');
    }

     $('#TopView').click(function () {
        $('#TopView').addClass("current_active_active");
        $('#NewShop').removeClass("current_active_active");
        $('#LastBid').removeClass("current_active_active");
        $('#ShopStar').removeClass("current_active_active");
        ShowTopTab("TopView");
    });
    $('#NewShop').click(function () {
        $('#TopView').removeClass("current_active_active");
        $('#NewShop').addClass("current_active_active");
        $('#LastBid').removeClass("current_active_active");
        $('#ShopStar').removeClass("current_active_active");
        ShowTopTab("NewShop");
    });
    $('#LastBid').click(function () {
        $('#TopView').removeClass("current_active_active");
        $('#NewShop').removeClass("current_active_active");
        $('#LastBid').addClass("current_active_active");
        $('#ShopStar').removeClass("current_active_active");
        ShowTopTab("LastBid");
    });
    $('#ShopStar').click(function () {
        $('#TopView').removeClass("current_active_active");
        $('#NewShop').removeClass("current_active_active");
        $('#LastBid').removeClass("current_active_active");
        $('#ShopStar').addClass("current_active_active");
        ShowTopTab("ShopStar");
    });

    $('#TopView').click();

});

function ShowTopTab(WhatTop) {
    jQuery.ajax({
        type: "GET",
        datatype: "script",
        scriptCharset: "UTF-8",
        url: "LoadTop10AllTab.aspx",
        data: { tabs: WhatTop },
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Accept-Charset", "UTF-8");
            xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        },
        success: function (data) {
            var a = new Array();
            a = data.split("<!--SPLIT-->");
           $("#LoadTop10Tab").html(a[1]);
        }
    });
}
function ShowTab1() {
    $("#tabLastItemsUpdate").fadeIn();
    $("#tabLastItemsUpdateStar").attr("style", "display:none");
    $("#tabLastItemAdd").attr("style", "display:none");

    $("#imgLastItemsUpdate").attr("src", "images/tabLastItemsUpdate.jpg");

    $("#imgLastItemsUpdateStar").attr("src", "images/tabLastItemsUpdateStarOver.jpg");

    $("#imgLastItemAdd").attr("src", "images/tabLastItemAddOver.jpg");

    SelectTab = "tab1";
    //------------------------------------
    //loading("กรุณารอสักครู่...");
    //	$("#tab1").load("projectListData.aspx?param=1", function () {
    //		//$(document).unblock();  
    //	});
    //$(document).unblock();

    callAjax("LoadLastItems.aspx", "filter=1", function (data, status, result) {

        var a = new Array();
        a = data.split("<!--SPLIT-->");
        $("#tabLastItemsUpdate").html(a[1]);
    });

    //------------------------------------

    //$("#tabLastItemsUpdate").html("This is tab1");
}
function ShowTab2() {

    $("#tabLastItemsUpdate").attr("style", "display:none");
    $("#tabLastItemsUpdateStar").fadeIn();
    $("#tabLastItemAdd").attr("style", "display:none");

    $("#imgLastItemsUpdate").attr("src", "images/tabLastItemsUpdateOver.jpg");

    $("#imgLastItemsUpdateStar").attr("src", "images/tabLastItemsUpdateStar.jpg");

    $("#imgLastItemAdd").attr("src", "images/tabLastItemAddOver.jpg");

    SelectTab = "tab2";
    //------------------------------------
    //	loading("กรุณารอสักครู่...");
    //	$("#tab2").load("projectListData.aspx?param=2");
    //	$(document).unblock();


    callAjax("LoadLastItems.aspx", "filter=2", function (data, status, result) {

        var a = new Array();
        a = data.split("<!--SPLIT-->");
        $("#tabLastItemsUpdateStar").html(a[1]);
    });

    //------------------------------------

    //$("#tabLastItemsUpdateStar").html("This is tab2");
}
function ShowTab3() {
    $("#tabLastItemsUpdate").attr("style", "display:none");
    $("#tabLastItemsUpdateStar").attr("style", "display:none");
    $("#tabLastItemAdd").fadeIn();

    $("#imgLastItemsUpdate").attr("src", "images/tabLastItemsUpdateOver.jpg");

    $("#imgLastItemsUpdateStar").attr("src", "images/tabLastItemsUpdateStarOver.jpg");

    $("#imgLastItemAdd").attr("src", "images/tabLastItemAdd.jpg");
    SelectTab = "tab3";

    //------------------------------------
    //	loading("กรุณารอสักครู่...");
    //	$("#tab3").load("projectListData.aspx?param=3");
    //	$(document).unblock();


    callAjax("LoadLastItems.aspx", "filter=3", function (data, status, result) {

        var a = new Array();
        a = data.split("<!--SPLIT-->");
        $("#tabLastItemAdd").html(a[1]);
    });

    //------------------------------------

    // $("#tabLastItemAdd").html("This is tab3");
}
