$( ".check_all_pb" ).click(function() {
	if($( this ).is(':checked')){
		$('.check_all_pb_grp').prop('checked',true);
	}else{
		$('.check_all_pb_grp').prop('checked',false);
	}
});


$( "#btn_send_pb_sms" ).click(function() {
	var pb_group;
	var pb_group_str;
	var module_id = $("#module_id" ).val();
	var message_default = encodeURIComponent($(".message_default" ).val()); 
	var per_msg_length = document.getElementById("per_message").innerHTML;
	var sms_type = "";
	var eng_max_part_no = $("#eng_part_info_holder" ).val();
	var ban_max_part_no = $("#ban_part_info_holder" ).val();
	var max_part_no = 0;

	if(per_msg_length<=160 && per_msg_length>70){
		sms_type="english";
		max_part_no = eng_max_part_no;
	}
	if(per_msg_length<=70){
		sms_type="bangla";
		max_part_no = ban_max_part_no;
	}
	
	//$('.check_all_pb').prop('checked',true);
	
   	var i = 0;
	
	$( ".check_all_pb_grp" ).each(function() {
		if($( this ).is(':checked')){
			pb_group =  $( this ).attr("id");
			if(pb_group){
				if(i == 0){
					pb_group_str = "'"+pb_group.toString()+"'";
				}else{
					pb_group_str = pb_group_str+ ", '"+pb_group.toString()+"'";
				}
			}
			i++;	
		}
	});
   
    var datastr = "sms_type="+sms_type+"&message="+message_default+"&module_id="+module_id+
				"&max_part_no="+max_part_no;
	
	if(!message_default){
		alert("Please write the SMS first"); 
		$(".message_default" ).focus();
	}
	else if(pb_group_str){ 
		pb_group_str = JSON.stringify(pb_group_str); 
	   	datastr = datastr+"&pb_group="+pb_group_str;
		alert(datastr);	
	//	$('#btn_send_pb_sms').hide(200);
		document.getElementById("btn_send_pb_sms").disabled = true;
		document.getElementById("btn_send_pb_sms").innerHTML ='<i class="icon-spinner icon-spin orange bigger-125 icon-loading" ></i> Request processing... ';
		//$('#btn_next').hide(200);
		//$('.processing_msg').html('<span style="color:Blue;"><b><i>Request processing</i></b></span>');
		$.ajax({
				type:"post",
				url:"module/general_notice/insert_general_notice_pb.php",
				data:datastr ,
				success:function(st){
					alert(st);
					$("#phnbk").trigger('reset'); 
					document.getElementById("length").innerHTML = '0';
					document.getElementById("messages").innerHTML = '0';
					document.getElementById("per_message").innerHTML = '160';
					document.getElementById("remaining").innerHTML = '160';
					document.getElementById("rem_lbl").style.color = "grey";
					document.getElementById("remaining").style.color = "grey";
					document.getElementById("btn_send_pb_sms").disabled = false;
					document.getElementById("btn_send_pb_sms").innerHTML = '<i class="icon-ok bigger-100"></i>Send';
					//$('.processing_msg').hide(200);
				}
			});
	}else{
		 alert("Select a group first."); 
	  
	}  
});	
