var blocker = {
    blockUser:function(){
        var memberId = $('#memberId').val();
         $.ajax({
                url:'modules/blockuser/formBlockUser.php',
                cache: false,
                data:{'refId':memberId},
                type:'POST',
                success:function(data){
                   if(data == -50){
                     sessionTimeout();
                   }else{
                        blockUI(data);
                    }//end if
                }

         });       
    },
    
    blockData:function(){
        
        var option = $('#methodBlock').val();
        if(option == 1){
            $('#blockBtn').attr('disabled','disabled');
            var refId = $('#memberId').val();
            var arrayBlock = [];
            var suggest = 0;
            var comment = 0;
            var sms = 0;
            var profile = 0;
            var method = 'block';
            
            if($('#suggestMethod'+refId).val()!=''){
                if($('#blockSuggest'+refId).attr('checked')==true){
                      suggest = 1;
                }else{
                      suggest = 2;
                }
            }
            
            if($('#commentMethod'+refId).val()!=''){
                if($('#blockComment'+refId).attr('checked')==true){
                      comment = 1;
                }else{
                      comment = 2;
                }
            }
            
            if($('#messageMethod'+refId).val()!=''){
                if($('#blockMessage'+refId).attr('checked')==true){
                      sms = 1;
                }else{
                      sms = 2;
                }
            }
            
            if($('#profileMethod'+refId).val()!=''){
                if($('#blockHome'+refId).attr('checked')==true){
                      profile = 1;
                }else{
                      profile = 2;
                }
            }
            $.ajax({
                    url:'modules/blockuser/formBlockUserSub.php',
                    cache: false,
                    data:{'refId':refId,'blockSuggest':suggest,'blockComment':comment,'blockSMS':sms,'blockProfile':profile},
                    type:'POST',
                    success:function(data){
                       if(data == 1){
                           msgSuccess('บันทึกข้อมูลเรียบร้อยแล้วคะ'); 
                       }
                    }

             });
        }else{
            //msgSuccess('บันทึกข้อมูลเรียบร้อยแล้วคะ'); 
            var total = $('#totalList').val();
            var allSuggest = '';
            var allComment = '';
            var allMessage = '';
            var allProfile = '';
            for(i=0;i<total;i++){
                
                var suggest = 'blockSuggest'+i;
                var suggestList = $('#'+suggest).val();
                if($('#'+suggest).attr('checked')==true){
                     
                     allSuggest = allSuggest + suggestList + ':' + '1'+ ',';
                }else{

                     allSuggest = allSuggest + suggestList + ':' + '2' + ',';
                }
                
                var comment = 'blockComment'+i;
                var commentList = $('#'+comment).val();
                if($('#'+comment).attr('checked')==true){
                     
                     allComment = allComment + commentList + ':' + '1'+ ',';
                }else{
                     //var commentList = $('#'+comment+'not(:checked)').val();
                     allComment = allComment + commentList + ':' + '2' + ',';
                }
                
                var message = 'blockMessage'+i;
                var messageList = $('#'+message).val();
                if($('#'+message).attr('checked')==true){
                     
                     allMessage = allMessage + messageList + ':' + '1'+ ',';
                }else{
                     //var messageList = $('#'+message+'not(:checked)').val();
                     allMessage = allMessage + messageList + ':' + '2' + ',';
                }
                
                var profile = 'blockHome'+i;
                var profileList = $('#'+profile).val();
                if($('#'+profile).attr('checked')==true){
                     
                     allProfile = allProfile + profileList + ':' + '1'+ ',';
                }else{
                     //var profileList = $('#'+profile+'not(:checked)').val();
                     allProfile = allProfile + profileList + ':' + '2' + ',';
                }
            }
            $('#suggestBlock').val(allSuggest);
            $('#commentBlock').val(allComment);
            $('#messageBlock').val(allMessage);
            $('#profileBlock').val(allProfile);
            
            blocker.editListBlocked();
        }
    },
    
    method:function(id,input,refId){
        var boxId = id+refId;
        var total = $('#total').val();
        /*if($("input:checkbox").attr('checked')==true){
            $('#blockBtn').removeAttr("disabled");
        }else{
            $('#blockBtn').attr('disabled','disabled');
        }*/
        if($('#method').val()==1){
            if($('#'+id+refId).attr('checked')==true){
                 var countCheck = $("input[@name="+boxId+"]:checked").val();
                 if(total != ''){
                    var data = total + ',' + countCheck;
                 }else{
                    var data = total + countCheck;
                 }                             
                 $('#'+input+refId).val('block');
            }else{                              
                 $('#'+input+refId).val('unblock');
            }
        }else{
            if($('#'+id+refId).attr('checked')==true){
                 var countCheck = $("input[@name="+boxId+"]:checked").val();
                     if(total != ''){
                        var data = total + ',' + countCheck;
                     }else{
                        var data = total + countCheck;
                     }                             
                 $('#'+input+refId).val('block');
            }else{
                     if(total != ''){
                        var data = total + ',' + refId;
                     }else{
                        var data = total + refId;
                     }            
                 $('#'+input+refId).val('unblock');
            }
        }
        $('#total').val(data);     
    },
    
    goTab:function(id){
        $('#total').val('');
        if(id == 2){
           $('#ListBlocked').empty().append(IMG_LOADING);
           var refId = $('#memberId').val();
           var method = 2;
           $("#BlockedMember").empty()
           $('#methodBlock').val(2);
           $.ajax({
                url:'modules/blockuser/formListBlockUser.php',
                cache: false,
                data:{'refId':refId,'option':method},
                type:'POST',
                success:function(data){
                       $("#ListBlocked").empty().append(data);
                       
                }

         }); 
        }else{
           $('#BlockedMember').empty().append(IMG_LOADING);
           var refId = $('#memberId').val();
           var method = 1;
           $("#ListBlocked").empty();
           $('#methodBlock').val(1); 
           $.ajax({
                url:'modules/blockuser/formListBlockUser.php',
                cache: false,
                data:{'refId':refId,'option':method},
                type:'POST',
                success:function(data){
                       $("#BlockedMember").empty().append(data);
                }

         });  
        }
    },
    
    /*editListBlocked:function(id,input,refId){
        var method = 0;
        var suggest = 0;
        var comment = 0;
        var sms = 0;
        var profile = 0;
        switch(id){
            case 'blockSuggest':
                if($('#'+id+refId).attr('checked')==true){
                      suggest = 1;
                }else{
                      suggest = 2;
                } 
            break;
            
            case 'blockComment':
                if($('#'+id+refId).attr('checked')==true){
                      comment = 1;
                }else{
                      comment = 2;
                }
            break;
            
            case 'blockMessage':
               if($('#'+id+refId).attr('checked')==true){
                      sms = 1;
                }else{
                      sms = 2;
                } 
            break;
            
            case 'blockHome':
               if($('#'+id+refId).attr('checked')==true){
                      profile = 1;
               }else{
                      profile = 2;
               } 
            break;
        }
        $.ajax({
                    url:'modules/blockuser/formBlockUserSub.php',
                    cache: false,
                    data:{'refId':refId,'blockSuggest':suggest,'blockComment':comment,'blockSMS':sms,'blockProfile':profile},
                    type:'POST',
                    success:function(data){
                       if(data == 1){
                           //msgSuccess('บันทึกข้อมูลเรียบร้อยแล้วคะ'); 
                       }
                    }

        });
        
    }*/
    
    editListBlocked:function(){
        var suggest = $('#suggestBlock').val();
        var comment = $('#commentBlock').val();
        var message = $('#messageBlock').val();
        var profile = $('#profileBlock').val();

        //alert(suggest+"\n"+comment+"\n"+message+"\n"+profile);
        $.ajax({
                    url:'modules/blockuser/editListBlockedSub.php',
                    cache: false,
                    data:{'blockSuggest':suggest,'blockComment':comment,'blockSMS':message,'blockProfile':profile},
                    type:'POST',
                    success:function(data){
                       if(data == 1){
                           msgSuccess('บันทึกข้อมูลเรียบร้อยแล้วคะ'); 
                       }
                    }

        });
    },
    
    showBlock:function (){
        var data = $("#chagePage").val();
        var datas = data.split("|");
        var id = datas[0];
        var total = datas[1];
        //alert(id+"\n"+total);
        //document.getElementById('block'+id).style.display = 'block';
        //document.getElementById('a'+id).style.color = 'red';
        for(i=1;i<=total;i++){
            //if(i!=id){
              document.getElementById('block'+i).style.display = 'none';
             // document.getElementById('a'+i).style.color = 'blue';
            //}
        }
        document.getElementById('block'+id).style.display = 'block';
        //document.getElementById('a'+id).style.color = 'red';
    }
    
}