function showMessage(time)
{  
    if(typeof(time)=='undefined') time=1000;
    if(time==-1)
        $.unblockUI({
            fadeOut: 500,
            showOverlay: false,
            centerY: true,          
            css: {
                border: "none",
                padding: "5px",
                backgroundColor: "#000",
                "-webkit-border-radius": "10px",
                "-moz-border-radius": "10px",
                opacity: ".6",
                color: "#fff"
            }
        });	          
    else
    {        
        $.blockUI({
            message: $("#notification"),
            fadeIn: 400,
            fadeOut: 700,
            timeout: time,
            showOverlay: false,
            centerY: true,                
            css: {
                border: "none",
                padding: "5px",
                backgroundColor: "#000",
                "-webkit-border-radius": "10px",
                "-moz-border-radius": "10px",
                opacity: ".6",
                color: "#fff"
            }
        });                    
    }	   
}

function getCalendarFromYear(year)
{
    $.ajax({
        url: location.pathname+"?year="+year,
        datatype: "html",
        timeout: 300000,
        beforeSend: function(){
        	$("#notification").html( "讀取中，請稍待片刻");
        	showMessage(0);	
        },
        error: function(){
        	$("#notification").html( "很抱歉，讀取資料發生錯誤。<br />請重新操作或與客服人員聯絡，謝謝!");
        	showMessage(2000);	        	
        },
        success: function (response) {
			$('#main').html($(response).find('#main').html());
			yearClickScript();  
			showMessage(-1);
        }
    }); 	
}

function yearClickScript()
{
	$('#main table.class-level th div').css('white-space','nowrap');
    $('ol.class-year a').click(function(){
    	getCalendarFromYear($(this).html());   
		return false; 	
    });	
}

$(document).ready(function () {
    yearClickScript();       
}); 
