$(document).ready(function(){
    var base_url =$("input[name=base_url]").val();

    /*$("select[name=color]").val(
        parseInt($("div#group_select > input[name=temp_cat]").val() )
    );*/

    /*$("select[name=category]").change(function() {
        var category = $(this).val();
        if (category == -1) {
            location.href = base_url;
        } else {
            location.href = base_url+"?category="+category;
        }
    });*/

    var current_month=parseInt($("input[name=display_month]").val());
    var current_year=parseInt($("input[name=display_year]").val());
	
	var current_day=parseInt($("input[name=display_day]").val());
	
	var current_month1=parseInt($("input[name=c_month]").val());
    var current_year1=parseInt($("input[name=c_year]").val());
	
	var current_day1=parseInt($("input[name=c_day]").val());
	
    var today = new Date();

    $("#btnToday").click(function() {
        location.href=base_url+ "/"+current_month1+"/"+current_year1+"/"+current_day1;
    });

    // go button
    $("input#dateChange").click(function() {
        gotoDate(
            $("select[name=dd_month]").val(), 
            $("select[name=dd_year]").val(),
			$("select[name=dd_day]").val()
        );   
    });

    // previous month
    $("input#prevMonth").click(function() {
        if (current_month == 1) {
            gotoDate(12, current_year-1, current_day);
        } else {
            gotoDate(current_month - 1, current_year, current_day);
        }
    });

    // next month
    $("input#nextMonth").click(function() {
        if (current_month == 12) {
            gotoDate(1, current_year+1, current_day);
        } else {
            gotoDate(current_month + 1, current_year, current_day);
        }
    });

    function gotoDate(month, year, day) {
        location.href = base_url + "/"+month+"/"+year+"/"+day;
    }

    // event click
    //console.debug($("td#tdContent").find("a"));

/*
    $("td#tdContent").find("a").click( function() {
        var target = $(this).attr("href").split("/");
        var day = target[1+$.inArray( "(day)", target) ];
        var month = target[1+$.inArray( "(month)", target) ];
        var year = target[1+$.inArray( "(year)", target) ];
        var order = target[1+$.inArray( "(order)", target) ];

        location.href = base_url+"?day="+day+"&month="+month+"&year="+year+"&order="+order;

        return false;
    });
*/

});
