function guess_months(selected){
    var year= $('#year').val();
    $(".customStyleSelectBox").remove();
    $.getJSON('ajax/news.php?q=months&d='+year, function(data) {
        $("#month").html("");
        for (i=0;i<data.length;i++){
            $('#month').
            append($("<option></option>").
                attr("value",data[i]).
                text(data[i]));
        }
        $("#month option[value='"+(months.indexOf(selected)>0?selected:data[data.length-1])+"']").attr('selected', 'selected');
        $('.date-search select').customStyle();
    });
};
function go_date(type){
    var data="";
    switch (type){
        case "year":
            data=$('#year').val();
            break
        default:
            data=$('#year').val()+"/"+$('#month').val();

    }
    document.location.href="news/"+data+".htm";
}
$(function(){
    $.getJSON('ajax/news.php?q=years', function(data) {
        for (i=0;i<data.length;i++){
            $('#year').
            append($("<option></option>").
                attr("value",data[i]).
                text(data[i]));
        }
        $("#year option[value='"+(info.year>0?info.year:data[data.length-1])+"']").attr('selected', 'selected');
        $("#year").change (function(){
            go_date("year");
        });
        $("#month").change (function(){
            go_date("both");
        });
        guess_months (info.month);
    });
});
