var fnCheckGender = function() {

    var fn = Functional;
    var generateGender = function(g) {
        var fn = "a -> jQuery(this).attr('type')=='" + g + "' ? this : null";
        return fn.lambda();
    }


    var isM = generateGender("M");
    var isF = generateGender("F");
    var isChecked = "a -> (this.checked==true) ? this : null".lambda();
    var getValue = "this.value".lambda()

    jQuery("div.check_gender").each(function() {
        var iCnt = 0;
        var chk = jQuery("input[type='checkbox']", this);
        chk.each(function() {
            jQuery(this).bind("click",
            function() {
               
                if(jQuery(chk).map(isChecked).size()==0) {
                   this.checked=true;
                   return;
                }
               
                var fnMap = [];
                jQuery(chk).map(isChecked).each(function() {
                    if (this.value == "isM") fnMap.push(isM);
                    if (this.value == "isF") fnMap.push(isF);
                });
                
                
                jQuery("tr#expand_content").remove();
                jQuery('td span.open_button').removeClass('close_button');
                jQuery(".expandible_content tr[type]").hide().map(fn.or.apply(null, fnMap)).show();
            });
            iCnt++;
        });
    });

};





 (function() {
    jQuery(document).ready(function() {
        fnCheckGender();
        prepareOnLoad();

        var rq = document.location.toString().split("?");
        if (rq[1]) {
            jQuery("#calendar_list li a").removeClass('active').map(function() {
                return jQuery(this).attr("rel") == rq[1] ? this: null;
            }).addClass("active");
        }
        //jQuery("td.expand_button span").hide();

    });
})()
