<? global $vis_language; ?>
<div class="modal-dialog" id="blabDialog">
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title"><? echo $vis_language['TXTADDBLAB']; ?></h4>
    </div>
    <div class="modal-body">
    <form action="index.php" method="post" target="vis_hidden_frame" name="vis_new_blab_form" id="vis_new_blab_form" class="form-horizontal">
		<div class="form-group">
			<label class="col-sm-2 control-label">
   
   <? if(VIS_STAFF_IMAGE!='' && is_file(VIS_PATH_PROFILE.VIS_STAFF_IMAGE) && VIS_STAFF_IMAGE!='default.jpg'){?>
   <div class="l-avatar">
<img src="<?= VIS_PATH_PROFILE.(VIS_STAFF_IMAGE!='' && is_file(VIS_PATH_PROFILE.VIS_STAFF_IMAGE) ? VIS_STAFF_IMAGE : 'default.jpg');?>" class="md bg-white img-responsive">
</div>

<? }else{ ?>
<div class="l-avatar">
<? if($currentstaff[0]['first_name']!=''){
	$firstname=preg_split('//u', $currentstaff[0]['first_name'], -1, PREG_SPLIT_NO_EMPTY);
$lastname=preg_split('//u', $currentstaff[0]['last_name'], -1, PREG_SPLIT_NO_EMPTY);
	?>
   <div class="md"><? echo ucfirst($firstname[0]).ucfirst($lastname[0]);?></div>
    <? }else{ ?>
    <img class="md bg-white img-responsive" src="<?= VIS_PATH_PROFILE.'default.jpg';?>">
    <? }?>

</div>
<? }?>

   <!--<a href="#" class="thumb-md avatar">
			<img src="<? //= VIS_PATH_PROFILE.(VIS_STAFF_IMAGE!='' && is_file(VIS_PATH_PROFILE.VIS_STAFF_IMAGE) ? VIS_STAFF_IMAGE : 'default.jpg');?>" width="48" class="bg-white img-responsive ">
			
			</a>--></label>
			<div class='col-sm-10'>
				<textarea name="vis_blab_post_area" id="vis_blab_post_area" class="form-control"  data-minwords="6" rows="2"></textarea>
			</div>
			<div class="col-sm-12 text-right">
				<a class="btn btn-link link m-l text-muted" data-toggle="class:show" href="#attach">
					<?php echo $vis_language['TXTATTACHMEDIA']; ?>
			</a>
		</div>
		</div>
		<div id="attach" class="hide">
			<div class="form-group">
			<label class="col-sm-2 control-label"></label>	
			  <div class="col-sm-10">
					<input type="text" placeholder="<? echo $vis_language['TXTINSERTURL']; ?>" name="insertUrl" class="form-control" id="vis_insert_url" onChange="imageUrl();">
			  </div>
			</div>
			<div class="form-group">
			<label class="col-sm-2 control-label"></label>	
				<div class="col-sm-10">					
						<input type="file" name="files[]" multiple="multiple" class="filestyle" data-icon="false" data-classButton="btn btn-link link" data-buttonText="<? echo $vis_language['TXTUPLOADFROMLOCAL']; ?>" data-input="false" onchange="$(this).visExecution('upload_file', {'vis_static_area':'#vis_blab_attachments', 'vis_form':'vis_new_blab_form', 'vis_form_attachment_area':'#vis_attachments'});" style="display:none">							
						<input type="hidden" name="vis_location" value="<? echo VIS_DOMAIN; ?>" />
						<input type="hidden" name="vis_attachments" id="vis_attachments" value="" />						
				</div>
			 </div>
        </div>
        <div id="attachedMedia">
		  <div class="line line-dashed b-b line-lg pull-in"></div>
		  <div class="form-group">
			<label class="col-sm-2 control-label" for="HomeAddress"><? echo $vis_language['TXTATTACHEDMEDIA']; ?></label>
			<div class="col-sm-10">					
			  <div id="vis_blab_attachments">
		   
			  </div>
			</div>
		  </div>
        </div> 
        <div class="form-group">
		<label class="col-sm-2 control-label"><?= $vis_language['TXTSHAREDWITH']; ?></label>
		<div class="col-sm-10">
			<div class="radio i-checks pull-left m-r-lg">
			<label>
				<input type="radio" name="vis_share" id="vis_all_staff" value="1" <? if(!isset($operation['vis_home']) && $operation['vis_home']!=1) echo "checked=checked"; else "";?> onclick="$('#shareWith').hide();"><i></i>
				<? echo $vis_language['TXTALL']; ?>
			</label>
			</div>
			<div class="radio i-checks pull-left m-r-lg">
			<label>
				<input type="radio" id="vis_selected_staff" name="vis_share" value="0" <? if(isset($operation['vis_home']) && $operation['vis_home']==1) echo "checked=checked"; else "";?>onclick="$('#shareWith').show();"><i></i>
				<? echo $vis_language['TXTSELECTEDSTAFF']; ?>
			</label>	
			</div>
		</div>	
		</div>
		<div class="form-group" id="shareWith">
			<label class="col-sm-2 control-label"></label>
			<div class="col-sm-10">
					<input class="form-control" type="text" placeholder="<? echo $vis_language['TXTSEARCHSTAFF'];?>" id="share_with" value="<? if(isset($staff)) echo $staff['first_name']; ?>" data-resize="no">
				<script type="text/javascript">
					$(document).ready(function() {
						$("#share_with").tokenInput(
							"index.php?vis_module=staff&vis_operation=staff_listing",
							{
								theme: "facebook",
								searchDelay: 300,
								minChars: 1,
								queryParam: "vis_data",
								preventDuplicates: true,
								propertyToSearch: "full_name",
								tokenValue: "full_name",
								searchingText: "<? echo $vis_language['MSGSEARCHING']."..."; ?>",
								noResultsText: "<? echo $vis_language['TXTNOMATCHFOUND']; ?>",
								resultsFormatter: function(item){ 
								if(item.type=="heading"){
									return "<b>" + "<div style='cursor:pointer;display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.full_name + "</div></div></b>"
								}
								else{ return "<li>" + "<div style='display: inline-block; padding-left: 10px;margin-left:30px;'><div class='full_name'>" + item.full_name + "</div></div></li>"	} },
								tokenFormatter: function(item) { if(item.group_id){$('#vis_blab_grp_share').val($('#vis_blab_grp_share').val()+item.group_id+',');}else{$('#vis_blab_share').val($('#vis_blab_share').val()+item.id+',');$('#vis_staff').val($('#vis_staff').val()+item.id+',');}return "<li><p>" + item.full_name + "</p></li>" },
								onDelete: function(item){
								if(item.group_id)
								{										
									var staffs = $('#vis_blab_grp_share').val();
									var newStaffs = staffs.replace(item.group_id+',', ''); 
									$('#vis_blab_grp_share').val(newStaffs);
								}
								else
								{
									var staffs = $('#vis_blab_share').val();
									var staffIds = $('#vis_staff').val();	
									var newStaffs = staffs.replace(item.id+',', ''); 
									$('#vis_blab_share').val(newStaffs);
									$('#vis_staff').val(newStaffs);								
								}
								},
								onAdd: function(item)
								{
									if(item.type == "heading")
									{	
										$("#share_with").tokenInput("remove", {full_name: item.full_name});
									}
								}
							}
						);	
						<?if(isset($operation['vis_home']) && $operation['vis_home']==1){?>
						$("#share_with").tokenInput("add", {id: "<?= $operation['vis_staff_id']; ?>", full_name: "<?= $operation['vis_first_name']." ".$operation['vis_last_name']; ?>"});<? } ?>
						//$("div.token-input-dropdown-facebook").css('width',$(".token-input-list-facebook").width()+2+'px');
					});
				</script>
				<input type="hidden" id="vis_blab_grp_share" name="vis_blab_grp_share"/>
				<input type="hidden" id="vis_blab_share" name="vis_blab_share"/>
				<input type="hidden" id="vis_staff" name="vis_staff" value=""/>
				<input type="hidden" id="vis_attachment_count" name="vis_attachment_count" value="0">
			</div>
		</div>
		<input type="hidden" name="parent_type" value="3">	
		<textarea name="vis_blab_post_hidden" id="vis_blab_post_hidden" class="form-control"  data-minwords="6" rows="2" style="display:none;"></textarea>
	</form>
    </div>
    <div class="modal-footer">
		<a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>  
		<a class="btn btn-primary" onclick="add_blab();"><? echo $vis_language['TXTADD']; ?></a>    
    </div>
  </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

<script>
	$(document).ready(function(){
		$('#attachedMedia').hide();
		<?if(isset($operation['vis_home']) && $operation['vis_home']==1){ ?>
		$('#shareWith').show();
		<? } else { ?>
		$('#shareWith').hide();<? } ?>
	});
	var imgWidth = 0;
	var isImg = 0;
	function imageUrl()
	{
		var content=$('#vis_insert_url').val();				
		var matches=content.match(/youtube\.com(.*)v=(.*)/g);
        if(matches==null)
        {
		   $("<img>", {
		   src: content,
		   error: function(){
				isImg = 0;
		   },
		   load: function(){	
			isImg = 1;
			$("<img/>").attr("src", content).load(function(data){
				imgWidth = this.width;	
			});
		   }
		 });			 
		}
	}		
	function add_blab()
	{
		var selectedRadio = $('input[name=vis_share]:checked').val();
		var content=$('#vis_insert_url').val().trim();
        if($("#vis_blab_post_area").val())
		{
			var data=$("#vis_blab_post_area").val();          
        }
        var matches=content.match(/youtube\.com(.*)v=(.*)/g);
        if(matches!=null) {
            var vid=content.split("v=")[1].substring(0, 11);
            content='<iframe src="http://www.youtube.com/embed/'+vid+'" frameborder="0" allowfullscreen></iframe>';
            $("#vis_blab_post_hidden").val(data+"<br /><br />"+content+'<br /><br />');  
        }
        else if(content.length!=0)
        {
			if(isImg == 1)
			{
				if(imgWidth >= 600)
				{
					$("#vis_blab_post_hidden").val(data+"<br /><br /><img src='"+content+"' width='600'/><br /><br />");   
				}
				else
				{
					$("#vis_blab_post_hidden").val(data+"<br /><br /><img src='"+content+"'/><br /><br />"); 
				}
			}
			else
			{
				$("#vis_blab_post_hidden").val(data+"<br /><br /><a href='"+content+"' class='link'>"+content+"</a><br /><br />");
			}
		}
		if($('#vis_blab_share').val().length == 0 && selectedRadio == 0)
		{
			$('#vis_blab_share').val(1);
		}
		else if(selectedRadio == 1)
		{
			$('#vis_blab_share').val(0);
		}
		$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'blabber', 'vis_operation':'create_blab', 'vis_form':'vis_new_blab_form'});
	}
	function vis_remove_attachment(attach_id){
	$.ajax({
        url: 'index.php',
        data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
        type: "POST",
        success: function(data) {  }
    });
    var attachments=$("#vis_attachment_count").val();
	$("#vis_attachment_count").val(eval(parseInt(attachments)-1));
	var attachmentsCnt=$("#vis_attachment_count").val();
	if((attachmentsCnt==0)) $("#attachedMedia").css('display','none');
	}
</script>
<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
