﻿$(document).ready(function(){
  
 //   window.setTimeout('JS_LoadThiSinhCaoDiemNhat(1)',500);
   

});
function switchHelpTab(index) {
    switch(index){
        case 1:
            LoadUrlContent('supportbox','help/register.htm',null);
            changeClass(['h_register'], ['h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            break;
        case 2:
            changeClass(['h_login'], ['h_register', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/login.htm',null);
            break;
        case 3:
            changeClass(['h_thi'], ['h_register', 'h_login', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/thi.htm',null);
            break;
        case 4:
            changeClass(['h_member'], ['h_register', 'h_login', 'h_thi', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/member.htm',null);
            break;
        case 5:
            changeClass(['h_result'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/result.htm',null);
            break;
        case 6:
            changeClass(['h_statistic'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/statistic.htm',null);
            break;
        case 7:
            changeClass(['h_new'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/news.htm',null);
            break;
        case 8:
            changeClass(['h_fun'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/fun.htm',null);
            break;
        case 9:
            changeClass(['h_flash'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/flash.htm',null);
            break;
        case 10:
            changeClass(['h_firefox'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum'], 'title', 'style2')
            LoadUrlContent('supportbox','help/mozilla.htm',null);
            break;
        case 11:
            changeClass(['h_forum'], ['h_register', 'h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/forum.htm',null);
            break;
        default:
        {
            changeClass(['h_register'], ['h_login', 'h_thi', 'h_member', 'h_result', 'h_statistic', 'h_new', 'h_fun', 'h_flash', 'h_forum', 'h_firefox'], 'title', 'style2')
            LoadUrlContent('supportbox','help/register.htm',null);
        }
    }
}

function changeClass(array1, array2, class1, class2)
{
    for (var i = 0; i < array1.length; i++)
    {
        $('#' + array1[i]).removeClass(class1)
        $('#' + array1[i]).addClass(class2)        
    }
    
    for (var i = 0; i < array2.length; i++)
    {
        $('#' + array2[i]).removeClass(class2)
        $('#' + array2[i]).addClass(class1)
    }
 }
 
 function changeClass1(len, style1, style2, idx, pre){
    
    for(var i=1; i<=len; i++)
    {
        $('#' + pre + i).removeClass(style2);
        $('#' + pre + i).addClass(style1);       
    }
    $('#' + pre + idx).removeClass(style1);
    $('#' + pre + idx).addClass(style2);
}

function switchTabTB(index) {
    if(index == 0) {
        $('#div_DV').css('display','block');
        $('#div_SV').css('display','none');
        
        $('#div_DVContent').css('display','none');
        $('#div_SVContent').css('display','block');
    }
    else {
        $('#div_DV').css('display','none');
        $('#div_SV').css('display','block');
        
        $('#div_DVContent').css('display','block');
        $('#div_SVContent').css('display','none');
    }
}

function openQD() {
    openDialog("Page_QuyetDinh.aspx","Quyết định của Bộ Giáo Dục và Đào Tạo", 800);
    //window.open(url,'Download'); 
    /*
    var browser=navigator.appName;
    if (browser=="Microsoft Internet Explorer")
    {
        window.open(url,'Download'); 
    }
    else
    {
    openDialog("Page_QuyetDinh.aspx","Quyết định của Bộ Giáo Dục và Đào Tạo", 800);
    }
    */
}

function openCongVan(url) {
    window.open(url,'Download'); 
    /*
    var browser=navigator.appName;
    if (browser=="Microsoft Internet Explorer")
    {
        window.open(url,'Download'); 
    }
    else
    {
        openDialog("Page_CongVan.aspx?url=" + url,"Công văn của địa phương", 820);
    }
    */
}

function openDoiTuyenQG(url) {    
    window.open(url,'Download'); 
    /*
    var browser=navigator.appName;
    if (browser=="Microsoft Internet Explorer")
    {
        window.open(url,'Download'); 
    }
    else
    {
        openDialog("Page_CongVan.aspx?url=" + url,"Đội tuyển thi cấp quốc gia", 820);
    }
    */
}

function JS_LoadThiSinhCaoDiemNhatQuocGia(obj)
{
    if(obj == 0)
    {
        var tmp = (Math.random()*10).toFixed(0);        
        obj = (tmp < 1 || tmp > 9) ? 1 : tmp;
    }
    $.ajax({
                beforeSend: function() {
                        $('#container_caodiemnhatquocgia').html('<img src="images/loading_bar.gif" />');
                },
                type: "GET",
                dataType: "text",
                url: "Default.aspx" ,
                data: "loadthisinhcaodiemnhatquocgia=" + obj,
              
                success: function(text) {
                    changeClass1(9, 'style2', 'title', obj, 'nt_');
                    $('#container_caodiemnhatquocgia').html(text);
                }
            });
}

function changeButton(len,idx){
    
    for(var i=1; i<=len; i++)
    {
        $('#bt_0' + i).attr('src', 'images/nut_00' + i + '.png');
    }
    $('#bt_0' + idx).attr('src', 'images/nut_0' + idx + '.png');
}

function JS_LoadThiSinhCaoDiemNhat(obj)
{    
    if(obj == 0)
    {        
        var tmp = (Math.random()*10).toFixed(0);              
        obj = (tmp <1  || tmp > 9) ? 1 : tmp;
    }
    $.ajax({
                beforeSend: function() {
                        $('#container_caodiemnhat').html('<center><img src="images/ajax_loader.gif" /></center>');
                        
                },
                type: "GET",
                dataType: "text",
                url: "Page_Default.aspx" ,
                data: "type=highScore&loadthisinhcaodiemnhat=" + obj,
              
                success: function(text) {
                //  alert(text + '-' + obj);
                   changeButton(9, obj);
                    $('#container_caodiemnhat').html(text); 
                }
            });
}

function JS_LoadThiSinhCaoDiemNhatDiaPhuong(obj)
{
    var province_id = $(obj).val();
    $.ajax({
            beforeSend: function() {
                    $('#container_caodiemnhatdiaphuong').html('<img src="images/loading_bar.gif" />');
            },
            type: "GET",
            dataType: "text",
            url: "Default.aspx" ,
            data: "loadthisinhcaodiemnhatdiaphuong=" + province_id,
          
            success: function(text) {
                $('#container_caodiemnhatdiaphuong').html(text);
            }
        });
}

function JS_User_Answer_FunQuestion(questID)
{
 var user_id = 0;
    if($('#login').length >0)
    {
    user_id = $('#login').attr("name").split(',')[0];

   }
   if(user_id == "0")
   {
     AlertNoRedirect("Bạn phải đăng nhập để có thể trả lời câu hỏi");
 
    return;
   }
    var txt_funquest = $('#txt_funquest').val();
   
    if(txt_funquest.length ==0) {
        AlertNoRedirect("Bạn chưa nhập số người sự đoán.");
        return false;
    }
        
    if(isNaN(txt_funquest)) {
        AlertNoRedirect("Số người trả lời đúng phải là số.");
        return false;
    }
        
    var selected = $("input[@name='radChoise']:checked").val();
    if(isNaN(selected)) {
        AlertNoRedirect("Bạn chưa chọn đáp án nào.");
        return false;
    }
    
    $.ajax({
            beforeSend: function() {
                    $('#container_traloicauhoidovuihangtuan').html('<img src="images/loading_bar.gif" />');
            },
            type: "GET",
            dataType: "text",
            url: "Default.aspx" ,
            data: "type=submit_answer&quesId=" + questID + "&selectedId=" + selected + "&numberOf=" + txt_funquest,
            success: function(text) {
               switch(text)
               {
               case -1 :
                  AlertNoRedirect("Bạn chưa đăng nhập");
               break;
               case 0:
                AlertNoRedirect("Có lỗi xảy ra trong quá trình xử lý dữ liệu, bạn vui lòng thử lại");
               break
               default :
               {
                 AlertNoRedirect("Bạn đã gửi trả lời thành công");
                /* $('#questionrep').hide();  */
               }
               break;
               }
            }
        });
}

function JS_Load_DanhSachThiSinhMoiNhat(index)
{
    $.ajax({
            beforeSend: function() {
                    $('#container_thisinhmoinhat').html('<img src="images/loading_bar.gif" />');
            },
            type: "GET",
            dataType: "text",
            url: "Page_members.aspx" ,
            data: "load_thisinhmoinhat=" + index,
          
            success: function(text) {
                $('#container_thisinhmoinhat').html(text);
            }
        });
}