$(document).ready(function(){
    $('.message').delay(4000).slideUp('fast');
    
    $('#enroll_btn').live('click',function() {

        if($('#enroll_state').val()){
            $('#enroll_form').submit();
        } else {
            $('#enroll_sel').css('color','red');
        }
    });
    $('div.cust_desc').click(function() {
        var id = $(this).attr('id');
        var arr = id.split('_');
        $('#cust_desc_ta_' + arr[2] + '_' + arr[3]).toggle();
        if($('#' + id).html() == '+ Custom Description'){
            $('#' + id).html('- Custom Description');
        } else {
            $('#' + id).html('+ Custom Description');
        }
     });
 
    $('div#attributeList').sortable({
        stop: function(event, ui){
            var order = [], // array for latest order
            passdata = '',
            that = $(this),
            inputs = that.find('input[name^="attributes"]');
            
            $.each(inputs, function(index){
                order.push($(this).val());
                passdata += '&' + index + '=' + $(this).val();
            });
            $.ajax({
                url: '/admin/attribute_groups/ajax',
                data: passdata,
                type: 'post'    
            });
        }
     }).disableSelection();
     
     $('div#planList').sortable({
        stop: function(event, ui){
            var order = [], // array for latest order
            passdata = '',
            that = $(this),
            inputs = that.find('input[name^="coverage_plans"]');
            
            $.each(inputs, function(index){
                order.push($(this).val());
                passdata += '&' + index + '=' + $(this).val();
            });
            $.ajax({
                url: '/admin/coverage_groups/ajax',
                data: passdata,
                type: 'post'    
            });
        }
     }).disableSelection();
     
     $('span.show_copyform').live('click',function(){

         var el = $(this);
         var id = el.attr('data-cfg');
         $('#cfg-' + id).show();
     });    
});
