$(document).ready(function (){
  var currMsgID   =   $('#AjaxMsgID').val()
  var currOriginID=   $('#AjaxOrgnID').val();
  var AjaxMsgType=  $('#AjaxMsgType').val();
  if(currMsgID>0 && AjaxMsgType=='customer')	{
      showCustomerMessageDetails(currMsgID,currOriginID,'Ajax_0');
  }else{
      showMessageDetails(currMsgID,currOriginID,'Ajax_0');

  }
   $(document).on('click','#bulkSubmit',function(){
       var checked=$(".chkbx:checked").size();
       if(checked==0){
           jAlert(msgSelectItem);
           return false;
       }
   });
  $(document).on('click','#submitReply',function(){
      if($('#replyText').val()==''){
          $('#div_err_formReplySubmit_replyText').removeClass("hide");
          return false;
      }
	  else{
			var messageID	=	$('#messageID').val();
			var replyText	=	$('#replyText').val();
			var originID	=	$('#originID').val();
			var msgtype		=	$('#msgtype').val();
			var subject		=	$('#subject').val();
			var sentBy		=	$('#sentBy').val();
			var	businessID	=	$('#businessID').val();
			$.ajax({
				   	type: "POST",
					url: GLOBAL_BASE_PATH+"/messages/ajaxReply/",		      		
		           	data: "messageID="+messageID+"&replyText="+replyText+"&originID="+originID+"&msgtype="+msgtype+"&subject="+subject+"&sentBy="+sentBy+"&businessID="+businessID,
				   	success: function(msg){ 
							$('#div_err_formReplySubmit_replyText').addClass("hide");
							location.reload();
					}
			});
		
	  }
  });
  
});
function verifyAjax(id){
  if(id>0 &&  $('#submitVerify').val()!=lblVerified){
      dataArray			= new Array();
      dataArray[0] 			= id;	     
      dataArray[1] 			= 'Verified';	
       $.ajax({
				   	type: "POST",
					url: GLOBAL_BASE_PATH+"/messages/ajaxVerifyUserMessage/",		      		
                                        data: { ajax_request: dataArray},
				   	success: function(msg){ 
					if(msg!='0')
					{
						$('#submitVerify').val(lblVerified);
                                                $('#Ajax_message_'+msg).remove();
                                        }		
				}
	   });
      
  }
}
function showMessageDetails(currMsgID,currOriginID,divid){	
	dataArray			= new Array();
	$('.list-main').removeClass('selected');
        $('#'+divid).addClass('selected');
        if(currMsgID!=''){          
	   $('#Ajax_loader').removeClass("hide");
	   dataArray[0] 			= currMsgID;	 
	   dataArray[1] 			= currOriginID;
           
	   $.ajax({
				   	type: "POST",
					url: GLOBAL_BASE_PATH+"/messages/showAjax/",		      		
		           	data: { ajax_request: dataArray},
				   	success: function(msg){ 
					if(msg!='1')
					{
						$('#Ajax_loader').addClass("hide");
				   	 	$("#AjaxMessageDetails").html(msg);
						$(".msg-scrol-ajax").perfectScrollbar('destroy');
						$(".msg-scrol-ajax").perfectScrollbar();                                              
                    }		
				}
	   });
	 }
}
function showCustomerMessageDetails(currMsgID,currOriginID,divid){	
	dataArray			= new Array();
      $('.list-main').removeClass('selected');
        $('#'+divid).addClass('selected');  
        if(currMsgID!=''){          
	   $('#Ajax_loader').removeClass("hide");
	   dataArray[0] 			= currMsgID;	 
	   dataArray[1] 			= currOriginID;
           
	   $.ajax({
				   	type: "POST",
					url: GLOBAL_BASE_PATH+"/messages/verifyAjax/",		      		
		           	data: { ajax_request: dataArray},
				   	success: function(msg){ 
					if(msg!='1')
					{
						$('#Ajax_loader').addClass("hide");
				   	 	$("#AjaxMessageDetails").html(msg);                                              
                                        }		
				}
	   });
	 }
}
