 $(function(){	
			
                $('#enrollee_datepicker').live('focus', function() {
                    $(this).datepicker({
                        dateFormat: 'yy-mm-dd',
                        changeMonth: true,
			changeYear: true,
                        showButtonPanel: true
                    });
                });
				
			
			$('#date_start,#date_end').datepicker({ 
			dateFormat: 'yy-mm-dd',
                        changeMonth: true,
			changeYear: true,
            showButtonPanel: true,
            minDate:0,
						              
    onSelect: customRange, showTrigger: '#calImg'}); 
     
function customRange(dates) { 
    if (this.id == '#date_start') { 
        $('#date_end').datepicker('option', 'minDate', dates[0] || null); 
    } 
    else { 
        $('#date_start').datepicker('option', 'maxDate', dates[0] || null); 
    } 
}	
			
                $('#search-users-name').live('keyup',function(){
                    console.log($(this).attr('rel'));
                    var value = $(this).val(), url = $(this).attr('rel');
                    if( value == ''){
                        $.post(url+'index.php/admin/admin_site/switch_admin_view/1',function(data){
                            $('.container-switch-body').attr('innerHTML',data);
                            $('#search-users-name').focus();
                        });
                    } else {
                       $.post(url+'index.php/admin/admin_site/search_users',{
                            search_username: value
                            },
                            function(data){
                            $('.table-list').attr('innerHTML',data);
                        });
                    }

                });
                $('#enrollee_datepicker, #enrollee_country').live('change', function() {
                     var url = $(this).attr('rel');
                     $.post(url+'index.php/admin/admin_site/search_enrollee/',{
                        enrollee_dateen: $('#enrollee_datepicker').val(),
                        enrollee_country: $('#enrollee_country').val()
                    },
                    function(data){
                        $('.table-list').attr('innerHTML', data);
                    });
                });
			
                $('.action-button').live('click',function(e){
                    e.preventDefault();
                    var id = $(this).attr('id'), url = $(this).attr('rel');
                    id = id.split('-');
                    var action = id[0];
                    id = id[1];
                    if( action == 'edit' ) {
                        // this is for edit
                        $.post(url+'index.php/admin/admin_site/search_users/'+id,{
                                edit: '1'
                            },function(data){
                            $('.content-toggled').attr('innerHTML',data);
                        });
                    } else if( action == 'update' ) {
                        // this is for update
                        var username = $('#edit-username').val(), password = $('#edit-password').val();
                        var firstname = $('#edit-firstname').val(), lastname = $('#edit-lastname').val();
                        var country = $('#edit-country').val(), email_address = $('#edit-email-address').val();
                        var user_type = $('#edit-usertype').val();
                        $.post(url+'index.php/admin/admin_site/search_users/'+id,{
                                update: id,
                                username: username,
                                password: password,
                                firstname: firstname,
                                lastname: lastname,
                                country: country,
                                email_address: email_address,
                                user_type: user_type
                            },function(data){
                            $('.content-toggled').attr('innerHTML',data);
                            $.post(url+'index.php/admin/admin_site/search_me',{
                                id:id
                                },
                                function(data){
                                    $('#lists-division-'+id).attr('innerHTML',data);
                                    $("#success_display").html("*Data was successfully updated.").show().fadeOut(2000);
                            });
                        });
                       // console.log($('#edit-username').val());
                    }
                   // console.log(action);
                    //console.log(id);
                });
            });
            
            $(function(){
                $('#datepicker1').live('focus', function() {
                    $(this).datepicker({
                        dateFormat: 'yy-mm-dd',
                        changeMonth: true,
                        changeYear: true,
                        showButtonPanel: true
                    });
                }); 
            });
$(function(){
    $('#datepicker2').live('focus', function() {
        $(this).datepicker({
            dateFormat: 'yy-mm-dd',
            changeMonth: true,
            changeYear: true,
            showButtonPanel: true
        });
    }); 
});
