<?php echo $this->Html->script('site_js/common');?>
<?php  echo $this->Html->script(array('ckeditor/ckeditor')); //echo $this->Html->script(array('site_js/nicEdit')); ?>
<script type="text/javascript">
	bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
	$(document).ready(function(){
		//initial hide
		$("#cancel").hide();
		$("#changeimage").click(function(){
			$("#fileIntro").show();
			$("#cancel").show();
			$("#curImage").hide();
			$("#changeimage").hide();
			$("#deleteimage").hide();
		});
		$("#cancel").click(function(){
			$("#fileIntro").hide();
			$("#cancel").hide();
			$("#changeimage").show();
			$("#deleteimage").show();
			$("#curImage").show();
		});
		$("#cancel2").hide();
		$("#changeimage2").click(function(){
			$("#fileAtch").show();
			$("#cancel2").show();
			$("#curImage2").hide();
			$("#changeimage2").hide();
			$("#deletefile").hide();
		});

		$("#cancel2").click(function(){
			$("#fileAtch").hide();
			$("#cancel2").hide();
			$("#changeimage2").show();
			$("#curImage2").show();
			$("#deletefile").show();
			
		});
	});
</script>
        <?php 
			echo $this->Html->css(array('jquery.awesome-cropper','/components/imgareaselect/css/imgareaselect-default'));
		?>
<script>
	var path='<?php echo $this->webroot;?>';
</script>

<script>

function validateclsfile(file) {
    var ext = file.split(".");
    ext = ext[ext.length-1].toLowerCase();      
    var arrayExtensions = ["docx" , "docm", "dotx", "dotm", "xlsx","xlsm" , "xltx", "xltm", "xlsb", "xlam","pptx" , "pptm", "potx", "potm", "ppam","ppsx" , "ppsm", "doc", "ppt", "pdf","odt" , "gif", "jpeg", "avi", "txt","tiff" , "jpg", "bmp", "rtf", "png","csv" , "xls", "html", "mp3", "zip","pps"];

    if (arrayExtensions.lastIndexOf(ext) == -1) {
        alert("Wrong extension type. Only below file types that can be uploaded: docx , docm, dotx, dotm, xlsx,xlsm , xltx, xltm, xlsb, xlam,pptx , pptm, potx, potm, ppam,ppsx , ppsm, doc, ppt, pdf,odt , gif, jpeg, avi, txt,tiff , jpg, bmp, rtf, png,csv , xls, html, mp3, zip,pps");
        $("#ContentAttachF").val("");
    }
}

</script>


<style>
#ContentAddForm {
	margin-bottom: 0px;
}
.nicEdit-selectTxt{
	height: 18px !important;
}

.modal {
  background-clip: padding-box;
  background-color: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.3);
  left: 30%;
  margin-left: -280px;
  outline: medium none;
  position: fixed;
  top: 10%;
  width: 82%;
	height:92%;
  z-index: 1050;
}

.modal-body {
  max-height: 100%;
  overflow-y: auto;
  padding: 15px;
  position: relative;
}
.modal-content {
  box-shadow: none;
}
.col-md-4 img {
  max-height: 100% !important;
  width: 390px !important;
}
.cropper-img img{
	max-height: 80px;
	margin-bottom: 10px;
}

.row-fluid .span10 {
    width: 83.606%;
}
.modal-content {
  background-clip: padding-box;
  background-color: #fff;
  border: none;
  border-radius: 0px;
  position: relative;
}
.modal-footer {
  background-color: #fff;
  border-radius:0px;
  border-top: none;
  box-shadow: none;
  margin-bottom: 0;
  padding: 0;
  text-align: right;
}
.awesome-cropper .modal-dialog {
  width: 1080px;
}

.margin-bt{
	margin-bottom: 20px;
}
@media screen and (-webkit-min-device-pixel-ratio:0) { 
	  .margin-bt{
	    	margin-bottom: 0px;
	  }
}
.profile-image{
	height: 80px;
}
</style>
<style>

	.dis_b{display: block;}
	.dis_n{display: none;}
	.dis_b2{display: block;}
	.dis_n2{display: none;}

 </style>
<?php  $params = $this->params; ?>
<?php 
if(empty($owneruserId)):
?>
<?php 
if($this->data['Content']['status'] != SAVE):
	?>
	<div class="blocktitle">Blog - Edit</div>
	<?php
else:
	?>
	<div class="blocktitle">Blog - Draft - Edit</div>
	<?php
endif;
?>

<div class="tar borb">
	<?php echo $this->Html->link('Published',array('controller'=>'contents','action'=>'blog'),array('class'=>'btn btn-mini'))?>
	<?php echo $this->Html->link('Write',array('controller'=>'contents','action'=>'add','Blog'),array('class'=>'btn btn-mini'))?>
	<?php // echo $this->Html->link('Category',array('controller'=>'categories','action'=>'add'),array('class'=>'btn btn-mini'))?>
	<?php echo $this->Html->link('Draft',array('controller'=>'contents','action'=>'draft'),array('class'=>'btn btn-mini'))?>
</div>
<br/>

<div class="w97p pdl10">
<div class="contents form userForm">
	<?php echo $this->Form->create('Content',array('type'=>'file')); ?>
		<?php
			echo $this->Form->input('id');
			echo $this->Form->hidden('type');
			?>
			<div class="row-fluid">
				<div class="span2">Title:</div>
				<div class="span10"><?php echo $this->Form->input('title',array('label'=>false,'style'=>'padding: 2px 0px;'));?></div>
			</div>
			<div class="row-fluid margin-bt" id="intro">
				<div class="span2">Intro Image:</div>
				<div class="span10">
					<?php 
		                 if (!empty($this->data['Content']['link1'])){?>
		                       <img src="<?php echo $this->data['Content']['link1'];?>"   class="profile-image"   id="profileImg" style=""/>
		                    <label id="deliMG" onclick="deletethumb(<?php echo $this->data['Content']['id'];?>);" style="font-weight:normal;margin-top:7px; " class="">Remove Image</label>            
		                   <?php }else {?>
						      <input id="sample_input" type="hidden" name="Content[introImg]">
						<?php }?> 
	           </div>
			</div>
			
			<div class="row-fluid" style="margin-top: 15px;">
				<div class="span2">Category:</div>
				<div class="span10"><?php echo $this->Form->input('category_id',array('label'=>false,'style'=>'padding: 2px 0px;'));?></div>
			</div>
           <div class="row-fluid" style="margin-top: 15px;">
				<div class="span2">Content:</div>
				<div class="span10"><?php echo $this->Form->input('content',array('class'=>'ckeditor','label'=>false,'style'=>'padding: 2px 0px;'));?></div>
			</div>
		<div class="row-fluid mrt10" id="atttach" >
			<div class="span2" style="margin-top: 10px;">Attach:</div>
			<div class="span10" style="margin-top: 10px;">
				<?php if ($this->data['Content']['linkfile']){?>
					<a href="<?= $this->data['Content']['linkfile']?>" style="text-decoration: underline;" target="_blank"><?= $this->data['Content']['linkfile']?></a> 
					<label id="deliMG" onclick="delete_file(<?php echo $this->data['Content']['id'];?>);" style="font-weight:normal;margin-top:7px; " class="">Remove File</label>
				<?php }else {
					echo $this->Form->input('attachF',array('type'=>'file','label'=>false,'onchange'=>"validateclsfile(this.value)",'div'=>array('id'=>'fileAtch','class'=>'')));
				}?>
				
			</div>
		</div>
		<div class="bort pdt15 mrt15 tar">
			<?php //echo $this->Form->input("Publish",array('label'=>false,'type'=>'submit','name'=>'btnPublish','div'=>false));?>	
			<input name="btnPost" class="btn btn-mini" type="submit" value="Publish" style="width: 10%">
			<input name="btnSave" class="btn btn-mini" type="submit" value="Save" style="width: 10%">
			<div class="btn btn-mini">
				<?php echo $this->Html->link('Cancel',array('controller'=>'contents','action'=>'blog'));?>
			</div>
		</div>
	<?php echo $this->Form->end(); ?>
</div>
</div>
<?php endif;?>
<script type="text/javascript">
     var path='<?php echo $this->webroot;?>';
		function deletethumb(id){
			 $.ajax({
			     	type: 'POST',
			     	url: path +'contents/deletethumb',
			     	data: {id:id},
			     	success: function(data){
				     	location.href="<?php echo $this->here?>";
			     	}
		     	});
		}

		function delete_file(id){
			 $.ajax({
			     	type: 'POST',
			     	url: path +'contents/delete_file',
			     	data: {id:id},
			     	success: function(data){
				     	location.href="<?php echo $this->here?>";
			     	}
		     	});
		}
	</script>
<?php 
	echo $this->Html->script(array('jquery-ui-1.10.3.custom','timepicker-addon','jquery.form.min','site_js/jquery.awesome-cropper','jquery.awesome-cropper','/components/imgareaselect/scripts/jquery.imgareaselect'));
?>

   <script>
    $(document).ready(function () {
        $('#sample_input').awesomeCropper(
        { width: 600, height: 400, debug: true }
        );
        $(":file").change(function() {
            var canvas = $('canvas')[0]; // or document.getElementById('canvas');
           canvas.width = canvas.width;
          $('.awesome-cropper img').css('visibility', 'visible'); 
        });
    });
    </script> 
      

