<?php 
//include("includes/FCKeditor/fckeditor.php");
$file_name		= "index?page=view_ess_template";
$form_action	= "insert";
$button_value 	= "Add";
$table_name 	= "ess_image_template";
$id	 = "";
$query_string = "";
$page_name      = "ESS Image Template";
$from = $_REQUEST['from'];
################################################## START INSERT ##################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'insert'){	
	utility::addslashesOnAllInput(array("query_string"));
	
	$title 			        = $_REQUEST['title'];
	
	$created_on = date("Y-m-d H:i:s");
	$created_by = $_SESSION["user_id"];
    $updated_by = $_SESSION["user_id"];
	$updated_on = date("Y-m-d H:i:s");
	
	$sql= "INSERT INTO $table_name (title,created_on,created_by,updated_by,updated_on) VALUES('$title','$created_on','$created_by','$updated_by','$updated_on')";
	mysqli_query($conn,$sql);
	$ess_id = mysqli_insert_id($conn);
	
	if(isset($_FILES['ess_image_1']['name']) && $_FILES['ess_image_1']['name'] !=""){
		$path = $_FILES['ess_image_1']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
		//if($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "JPG" || $ext == "JPEG" || $ext == "PNG"){
			
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$ess_image_1_name_array = explode(".",$_FILES['ess_image_1']['name']);
			
			$ess_1_ext = array_pop($ess_image_1_name_array);
			$doc_name_1 = implode('.', $ess_image_1_name_array);
			$ess_image_1_name = $ess_id."_"."tem"."_".$doc_name_1."_".$random_number.".".$ess_1_ext;
			$ess_image_1_name = str_replace(" ","",$ess_image_1_name);
			$uploadfile = $uploaddir . $ess_image_1_name;
			move_uploaded_file($_FILES['ess_image_1']['tmp_name'], $uploadfile);
			$sql= "UPDATE $table_name SET ess_image_1 = '$ess_image_1_name' WHERE id = $ess_id ";
			mysqli_query($conn,$sql);
			
			$tmp = ucfirst(str_replace("_"," ", $table_name));
		/* }else{
			$message = "Please upload only png or jpg lift_image";
		} */
    }
	if(isset($_FILES['ess_image_2']['name']) && $_FILES['ess_image_2']['name'] !=""){
		$path = $_FILES['ess_image_2']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
		//if($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "JPG" || $ext == "JPEG" || $ext == "PNG"){
			
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$ess_image_2_name_array = explode(".",$_FILES['ess_image_2']['name']);
			
			$ess_2_ext = array_pop($ess_image_2_name_array);
			$doc_name_2 = implode('.', $ess_image_2_name_array);
			$ess_image_2_name = $ess_id."_"."tem"."_".$doc_name_2."_".$random_number.".".$ess_2_ext;
			$ess_image_2_name = str_replace(" ","",$ess_image_2_name);
			$uploadfile = $uploaddir . $ess_image_2_name;
			move_uploaded_file($_FILES['ess_image_2']['tmp_name'], $uploadfile);
			$sql= "UPDATE $table_name SET ess_image_2 = '$ess_image_2_name' WHERE id = $ess_id ";
			mysqli_query($conn,$sql);
			
			$tmp = ucfirst(str_replace("_"," ", $table_name));
		/* }else{
			$message = "Please upload only png or jpg lift_image";
		} */
    }
	if(isset($_FILES['ess_image_3']['name']) && $_FILES['ess_image_3']['name'] !=""){
		$path = $_FILES['ess_image_3']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
		//if($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "JPG" || $ext == "JPEG" || $ext == "PNG"){
			
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$ess_image_3_name_array = explode(".",$_FILES['ess_image_3']['name']);
			
			$ess_3_ext = array_pop($ess_image_3_name_array);
			$doc_name_3 = implode('.', $ess_image_3_name_array);
			$ess_image_3_name = $ess_id."_"."tem"."_".$doc_name_3."_".$random_number.".".$ess_3_ext;
			$ess_image_3_name = str_replace(" ","",$ess_image_3_name);
			$uploadfile = $uploaddir . $ess_image_3_name;
			move_uploaded_file($_FILES['ess_image_3']['tmp_name'], $uploadfile);
			$sql= "UPDATE $table_name SET ess_image_3 = '$ess_image_3_name' WHERE id = $ess_id ";
			mysqli_query($conn,$sql);
			
			//$tmp = ucfirst(str_replace("_"," ", $table_name));
		/* }else{
			$message = "Please upload only png or jpg lift_image";
		} */
    }
	if(isset($_FILES['ess_image_4']['name']) && $_FILES['ess_image_4']['name'] !=""){
		$path = $_FILES['ess_image_4']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
		//if($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "JPG" || $ext == "JPEG" || $ext == "PNG"){
			
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$ess_image_4_name_array = explode(".",$_FILES['ess_image_4']['name']);
			
			$ess_4_ext = array_pop($ess_image_4_name_array);
			$doc_name_4 = implode('.', $ess_image_4_name_array);
			$ess_image_4_name = $ess_id."_"."tem"."_".$doc_name_4."_".$random_number.".".$ess_4_ext;
			$ess_image_4_name = str_replace(" ","",$ess_image_4_name);
			$uploadfile = $uploaddir . $ess_image_4_name;
			move_uploaded_file($_FILES['ess_image_4']['tmp_name'], $uploadfile);
			$sql= "UPDATE $table_name SET ess_image_4 = '$ess_image_4_name' WHERE id = $ess_id ";
			mysqli_query($conn,$sql);
			
			//$tmp = ucfirst(str_replace("_"," ", $table_name));
		/* }else{
			$message = "Please upload only png or jpg lift_image";
		} */
    }
	$_SESSION['info_message'] = "Record added sucessfully";
	header("Location: $file_name");
    exit();
}
################################################# END INSERT #################################################

################################################## START EDIT ##################################################
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){	
	$id = $_REQUEST['id'];
	$form_action 	= "update";
	$button_value 	= "Update";
	$page_name      = "Edit ESS Template";
	$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
	
    $sql= "SELECT * FROM $table_name WHERE id = $id";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_array($result_edit);
    $row_edit=utility::validate_crypt_data($row_edit);
	$title 			        = $row_edit['title'];
	
	$ess_image_1= $row_edit['ess_image_1'];
	$ess_image_2 = $row_edit['ess_image_2'];
	$ess_image_3 = $row_edit['ess_image_3'];
	$ess_image_4 = $row_edit['ess_image_4'];

}
################################################# END EDIT ################################################# 


################################################## START UPDATE ################################################## 
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'update'){    
	utility::addslashesOnAllInput(array("query_string"));
	$id= $_REQUEST['id'];
	$title 			        = $_REQUEST['title'];
	
    $updated_by = $_SESSION["user_id"];
	
	$hidden_ess_image_1 	= $_REQUEST['hidden_ess_image_1'];
	if(isset($_FILES['ess_image_1']['name']) && $_FILES['ess_image_1']['name'] !=""){
		$path = $_FILES['ess_image_1']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$old_ess_image_1	=	$uploaddir.$hidden_ess_image_1;	
			if(file_exists($old_ess_image_1)){
				unlink($old_ess_image_1);
			}
			$ess_image_1_name_array = explode(".",$_FILES['ess_image_1']['name']);
			$document_ext = array_pop($ess_image_1_name_array);
			$doc_name = implode('.', $ess_image_1_name_array);
			$ess_image_1_name = $id."_"."tem"."_".$doc_name."_".$random_number.".".$document_ext;
			
			$uploadfile = $uploaddir . $ess_image_1_name;
			move_uploaded_file($_FILES['ess_image_1']['tmp_name'], $uploadfile);
		 }else{
			$ess_image_1_name = $hidden_ess_image_1;
		} 
	
	$hidden_ess_image_2 	= $_REQUEST['hidden_ess_image_2'];
	if(isset($_FILES['ess_image_2']['name']) && $_FILES['ess_image_2']['name'] !=""){
		$path = $_FILES['ess_image_2']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$old_ess_image_2	=	$uploaddir.$hidden_ess_image_2;	
			if(file_exists($old_ess_image_2)){
				unlink($old_ess_image_2);
			}
			$ess_image_2_name_array = explode(".",$_FILES['ess_image_2']['name']);
			$document_ext = array_pop($ess_image_2_name_array);
			$doc_name = implode('.', $ess_image_2_name_array);
			$ess_image_2_name = $id."_"."tem"."_".$doc_name."_".$random_number.".".$document_ext;
			
			$uploadfile = $uploaddir . $ess_image_2_name;
			move_uploaded_file($_FILES['ess_image_2']['tmp_name'], $uploadfile);
		 }else{
			$ess_image_2_name = $hidden_ess_image_2;
		} 
	$hidden_ess_image_3 	= $_REQUEST['hidden_ess_image_3'];
	if(isset($_FILES['ess_image_3']['name']) && $_FILES['ess_image_3']['name'] !=""){
		$path = $_FILES['ess_image_3']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$old_ess_image_3  =	$uploaddir.$hidden_ess_image_3;	
			if(file_exists($old_ess_image_3)){
				unlink($old_ess_image_3);
			}
			$ess_image_3_name_array = explode(".",$_FILES['ess_image_3']['name']);
			$document_ext = array_pop($ess_image_3_name_array);
			$doc_name = implode('.', $ess_image_3_name_array);
			$ess_image_3_name = $id."_"."tem"."_".$doc_name."_".$random_number.".".$document_ext;
			
			$uploadfile = $uploaddir . $ess_image_3_name;
			move_uploaded_file($_FILES['ess_image_3']['tmp_name'], $uploadfile);
		 }else{
			$ess_image_3_name = $hidden_ess_image_3;
		} 
	$hidden_ess_image_4 	= $_REQUEST['hidden_ess_image_4'];
	if(isset($_FILES['ess_image_4']['name']) && $_FILES['ess_image_4']['name'] !=""){
		$path = $_FILES['ess_image_4']['name'];
		$ext = pathinfo($path, PATHINFO_EXTENSION);
			$digits = 5;
			$random_number = rand(pow(10, $digits-1), pow(10, $digits)-1);
			$uploaddir = '../ess_images/';
			$old_ess_image_4	=	$uploaddir.$hidden_ess_image_4;	
			if(file_exists($old_ess_image_4)){
				unlink($old_ess_image_4);
			}
			$ess_image_4_name_array = explode(".",$_FILES['ess_image_4']['name']);
			$document_ext = array_pop($ess_image_4_name_array);
			$doc_name = implode('.', $ess_image_4_name_array);
			$ess_image_4_name = $id."_"."tem"."_".$doc_name."_".$random_number.".".$document_ext;
			
			$uploadfile = $uploaddir . $ess_image_4_name;
			move_uploaded_file($_FILES['ess_image_4']['tmp_name'], $uploadfile);
		 }else{
			$ess_image_4_name = $hidden_ess_image_4;
		} 
	
    $sql= "UPDATE $table_name SET title = '$title', ess_image_1 = '$ess_image_1_name', ess_image_2 = '$ess_image_2_name', ess_image_3 = '$ess_image_3_name',ess_image_4 = '$ess_image_4_name',updated_by = '$updated_by' WHERE id = $id";
    mysqli_query($conn,$sql);
	
	$query_string = (isset($_REQUEST['query_string']) && !empty($_REQUEST['query_string'])) ? $_REQUEST['query_string'] : "";
  	$query_string = str_ireplace("page=add_ess_template", "page=view_ess_template", $query_string);
	$query_string = "&".$query_string;
	
	$_SESSION['info_message'] = "Template updated sucessfully";
    header("Location: $file_name$query_string");
    exit();
}
################################################# END UPDATE ################################################# 
?>
<style>
.custom-trash{
	font-size:20px;
	cursor:pointer;
}
</style>

<section class="content-header">
  <h1>
	<?=$page_name;?>
  </h1>
</section>
<section class="content">
	<div class="row">
		<div class="col-xs-12">
			<!----------------------- Message ------------------------------->
			<? if(isset($_SESSION['message'])){ ?>
			  <div class="alert alert-info alert-dismissable">
				<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
				<? echo $_SESSION['message']; unset($_SESSION['info_message']);?>
			  </div>
			  <? } ?>
			<!----------------------- End Message ------------------------------->
			<!-- general form elements -->
              <div class="box box-primary">
                <form class="form-horizontal" method="post" name="form1" id="form1" action="index?page=add_ess_template&action=<? echo $form_action; ?>" onsubmit="return validateForm(this)" enctype="multipart/form-data">
                  <div class="box-body">
				  <div class="col-lg-9 col-md-9 col-sm-12">
					<div class="form-group"> 
						<label class="col-sm-2 control-label" for="title">Title</label> 
						<div class="col-sm-10"> 
							<input type="text" id="title" name="title" class="form-control" value="<?php echo $title;?>" placeholder="Title" required> 
						</div> 
					</div>
					
					<div class="form-group">
						<label class="col-sm-2 control-label" for=""></label> 
						<div class="col-sm-10" style="padding:0;">
							<div class="col-sm-3">
							    <? $dir = "../../ess_images/";
									if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit'){ 
										 if($ess_image_1 !=''){
										   $img1=$ess_image_1;
									   }else{
										   $img1="blank_imag.png";
									   }
									?>
										<img id="frame1" src="<?= $dir.$img1;?>" width="100px" height="100px" style="" />
									<? }else {?>
										<img id="frame1" src="../../ess_images/blank_imag.png" width="100px" height="100px" style="" />
									<? }?>
								    <input type="file" onchange="preview1()" name="ess_image_1" id="ess_image_1" accept="image/*" style="color:transparent;" />
									<input type="button" id="delete1" value="Delete File" />
									<i class="fa fa-refresh fa-spin" style="display:none;" id="delete_load_1"></i>
									<input type="hidden" id="hid1" name="hidden_ess_image_1" value="<? echo $ess_image_1;?>">
							</div>
							<div class="col-sm-3">
							<? $dir = "../../ess_images/";
									if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit'){ 
									   if($ess_image_2 !=''){
										   $img2=$ess_image_2;
									   }else{
										   $img2="blank_imag.png";
									   }
									?>
										<img id="frame2" src="<?= $dir.$img2;?>" width="100px" height="100px" style="" />
									<? }else{?>
										<img id="frame2" src="../../ess_images/blank_imag.png" width="100px" height="100px" style="" />
									<? }?>
									<input type="file" onchange="preview2()" name="ess_image_2" id="ess_image_2" accept="image/*" style="color:transparent;" />
									<input type="button" id="delete2" value="Delete File" />
									<i class="fa fa-refresh fa-spin" style="display:none;" id="delete_load_2"></i>
									<input type="hidden" id="hid2" name="hidden_ess_image_2" value="<? echo $ess_image_2;?>">
							</div>
							<div class="col-sm-3">
							<? $dir = "../../ess_images/";
									if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit'){ 
										 if($ess_image_3 !=''){
										   $img3=$ess_image_3;
									   }else{
										   $img3="blank_imag.png";
									   }
									?>
										<img id="frame3" src="<?= $dir.$img3;?>" width="100px" height="100px" style="" />
									<? }else{?>
							          <img id="frame3" src="../../ess_images/blank_imag.png" width="100px" height="100px" style="" />
									<? }?>  
								     <input type="file" onchange="preview3()" name="ess_image_3" id="ess_image_3" accept="image/*" style="color:transparent;" />
									 <input type="button" id="delete3" value="Delete File" />
									 <i class="fa fa-refresh fa-spin" style="display:none;" id="delete_load_3"></i>
									<input type="hidden" id="hid3" name="hidden_ess_image_3" value="<? echo $ess_image_3;?>">
							</div>
							<div class="col-sm-3">
							<? $dir = "../../ess_images/";
									if(isset($_REQUEST['action']) && $_REQUEST['action']=='edit'){ 
										 if($ess_image_4 !=''){
										   $img4=$ess_image_4;
									   }else{
										   $img4="blank_imag.png";
									   }
									?>
										<img id="frame4" src="<?= $dir.$img4;?>" width="100px" height="100px" style="" />
									<? }else{?>
							          <img id="frame4" src="../../ess_images/blank_imag.png" width="100px" height="100px" style="" />
									<? }?>  
								    <input type="file" onchange="preview4()" name="ess_image_4" id="ess_image_4" accept="image/*" style="color:transparent;"/>
									<input type="button" id="delete4" value="Delete File" />
									<i class="fa fa-refresh fa-spin" style="display:none;" id="delete_load_4"></i>
									<input type="hidden" id="hid4" name="hidden_ess_image_4" value="<? echo $ess_image_4;?>">
							</div>
						</div>
					</div>
				   </div>
                  </div><!-- /.box-body -->
                  <div class="box-footer">
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="from" name="from" value="<?php echo $from;?>">
					<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
                    <button type="submit" id="submit" name="submit" value="<?php echo $button_value;?>" class="btn btn-primary">Submit
						<i class="fa fa-refresh fa-spin" style="display:none;" id="page_load_div"></i>
					</button>
                  </div>
                </form>
              </div><!-- /.box -->
		</div>
	</div>
</section>
<script type="text/javascript">
$('#form1').submit(function(){
		$("#submit").attr("disabled", true);
		$('#page_load_div').show();
	}); 
function preview1() {
    frame1.src=URL.createObjectURL(event.target.files[0]);
}
function preview2() {
    frame2.src=URL.createObjectURL(event.target.files[0]);
}
function preview3() {
    frame3.src=URL.createObjectURL(event.target.files[0]);
}
function preview4() {
    frame4.src=URL.createObjectURL(event.target.files[0]);
}

$(document).ready(function() {
  de(); 
  if(($("#hid1").val() != "")) {
	$("#delete1").attr("style", "display:block");
  }	
  $("#ess_image_1").on("change", function() {
  if (($("#ess_image_1").val() != "") ) {
	$("#delete1").attr("style", "display:block");
  } else {
	de();
  } 
}); 	
 $("#delete1").click(function() {
	var id = $("#id").val();
	var hid1 = $("#hid1").val();
	if(id !=''){ 
      if(hid1 ==''){
		$("#ess_image_1").val('');
		$("#frame1").attr("src", "../../ess_images/blank_imag.png");
		de();  
	  }else{ 	
		var con = confirm("Are you sure you want to delete ?");
		if(con){
			$("#delete_load_1").show();
			var form_data   = {'id':id}; 
			$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/ess/index.php?page=ajax_actions&action=delete_ess_template_image_1",
					data: form_data,
					success: function(result){    
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$("#ess_image_1").val('');
							$("#hid1").val('');
							$("#delete_load_1").hide();
							$("#frame1").attr("src", "../../ess_images/blank_imag.png");
							de();
						}
					}	
				 });
		   }
      }		   
	}else{
		$("#ess_image_1").val('');
		$("#frame1").attr("src", "../../ess_images/blank_imag.png");
		de();
	}
  });
  
  df(); 
  if(($("#hid2").val() != "")) {
	$("#delete2").attr("style", "display:block");
  }	
  $("#ess_image_2").on("change", function() {
  if (($("#ess_image_2").val() != "") ) {
	$("#delete2").attr("style", "display:block");
  } else {
	df();
  } 
}); 	
 $("#delete2").click(function() {
	var id = $("#id").val();
	var hid2 = $("#hid2").val();
	if(id !=''){ 
      if(hid2 ==''){
		$("#ess_image_2").val('');
		$("#frame2").attr("src", "../../ess_images/blank_imag.png");
		df();  
	  }else{ 
		var con = confirm("Are you sure you want to delete ?");
		if(con){
			$("#delete_load_2").show();
			var form_data   = {'id':id}; 
			$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/ess/index.php?page=ajax_actions&action=delete_ess_template_image_2",
					data: form_data,
					success: function(result){    
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$("#ess_image_2").val('');
							$("#hid2").val('');
							$("#frame2").attr("src", "../../ess_images/blank_imag.png");
							$("#delete_load_2").hide();
							df();
						}
					}	
				 });
		    }
	  }			
	}else{
		$("#ess_image_2").val('');
		$("#frame2").attr("src", "../../ess_images/blank_imag.png");
		df();
	}
  });
  
  dg(); 
  if(($("#hid3").val() != "")) {
	$("#delete3").attr("style", "display:block");
  }	
  $("#ess_image_3").on("change", function() {
  if (($("#ess_image_3").val() != "") ) {
	$("#delete3").attr("style", "display:block");
  } else {
	dg();
  } 
}); 	
 $("#delete3").click(function() {
	var id = $("#id").val();
	var hid3 = $("#hid3").val();
	if(id !=''){ 
      if(hid3 ==''){
		$("#ess_image_3").val('');
		$("#frame3").attr("src", "../../ess_images/blank_imag.png");
		dg();  
	  }else{ 
		var con = confirm("Are you sure you want to delete ?");
		if(con){
			$("#delete_load_3").show();
			var form_data   = {'id':id}; 
			$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/ess/index.php?page=ajax_actions&action=delete_ess_template_image_3",
					data: form_data,
					success: function(result){    
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$("#ess_image_3").val('');
							$("#hid3").val('');
							$("#frame3").attr("src", "../../ess_images/blank_imag.png");
							$("#delete_load_3").hide();
							dg();
						}
					}	
				 });
		    }
	  }			
	}else{
		$("#ess_image_3").val('');
		$("#frame3").attr("src", "../../ess_images/blank_imag.png");
		dg();
	}
  });
  
  dh(); 
  if(($("#hid4").val() != "")) {
	$("#delete4").attr("style", "display:block");
  }	
  $("#ess_image_4").on("change", function() {
  if (($("#ess_image_4").val() != "") ) {
	$("#delete4").attr("style", "display:block");
  } else {
	dh();
  } 
}); 	
 $("#delete4").click(function() {
	var id = $("#id").val();
	var hid4 = $("#hid4").val();
	if(id !=''){ 
      if(hid4 ==''){
		$("#ess_image_4").val('');
		$("#frame4").attr("src", "../../ess_images/blank_imag.png");
		dh();  
	  }else{ 
		var con = confirm("Are you sure you want to delete ?");
		if(con){
			$("#delete_load_4").show();
			var form_data   = {'id':id}; 
			$.ajax({
					async: true,
					type: "POST",
					url: site_url+"/modules/ess/index.php?page=ajax_actions&action=delete_ess_template_image_4",
					data: form_data,
					success: function(result){    
						var resultObj = jQuery.parseJSON(result); 
						if(resultObj.status == "success"){
							$("#ess_image_4").val('');
							$("#hid4").val('');
							$("#frame4").attr("src", "../../ess_images/blank_imag.png");
							$("#delete_load_4").hide();
							dh();
						}
					}	
				 });
		   }
	  }		   
	}else{
		$("#ess_image_4").val('');
		$("#frame4").attr("src", "../../ess_images/blank_imag.png");
		dh();
	}
  });
  
});
function de() {
  $("#delete1").attr("style", "display:none");
}
function df() {
  $("#delete2").attr("style", "display:none");
}
function dg() {
  $("#delete3").attr("style", "display:none");
}
function dh() {
  $("#delete4").attr("style", "display:none");
}
</script>