<?
	$job_id = $_REQUEST["job_id"];
	
	//$mail_subject = utility::getTableFieldById("mail_format","mail_format_subject","mail_format_name","confermation_mail_send_by_fran");
	//$mail_body = strip_tags(utility::getTableFieldById("mail_format","mail_format_body","mail_format_name","confermation_mail_send_by_fran"));
?>
<!-------- Start Modal ---------->
<form class="form-horizontal1" method="post" name="form2" id="form-horizontal1" action="" enctype="multipart/form-data">
<div class="modal-dialog">
	<div class="modal-content">
	  <div class="modal-header">
		<div class="col-lg-12">
		<div class="row">
			<div class="col-lg-8">
				<h4 class="modal-title" id="myModalLabel">Send Mail</h4>
			</div>
			<div class="col-lg-4">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			</div>
		</div>
		</div>
		
		
	  </div>
	  <div class="modal-body" style="height: 500px;">
		<div class="col-lg-12" style="margin-bottom:10px;">
		  <label for="Select All Surveyor" class="col-lg-12 control-label">Mail format subject</label>
		  <div class="col-lg-12">
			<input type="text" id="mail_format_subject" name="mail_format_subject" value="<?php echo $mail_subject;?>" class="form-control" placeholder="Mail format subject">
		  </div>
		</div>
		<div class="col-lg-12">
		  <label for="Select All Surveyor" class="col-lg-12 control-label">Mail format body</label>
		  <div class="col-lg-12">
			<textarea class="form-control" id="mail_format_body" name="mail_format_body" rows="15" cols="30" placeholder="Mail format body"><?php echo $mail_body;?></textarea>
		  </div>
		</div>
		<div class="col-lg-12" id="upload_multiple_document">
		  <label for="Upload Document" class="col-lg-12 control-label">Upload Document</label>
		  <div class="col-lg-12">
			<div style="width:250px;height:50px;border:0px solid red;display:none;" id="div_to_clone" class="div_to_clone_class">
					<a title="" style="float:right;margin-right: 30px;"><img class="multiform_row_remover" src="../images/del.gif" border="0" style="cursor:pointer;position: relative;top: 12px;"/></a>					
					<input type="file" name="mail_document[]" class="docs">
			</div>
			<span id="add_new_row" style="cursor:pointer">
				<b style="font-size:12px;">Upload More Documents (+)</b>
			</span>	
		  </div>
		</div>
	  </div>
	  <div class="modal-footer">
		<input type="hidden" name="job_id" id="job_id" value="<?php echo $job_id;?>" />
		<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
		<button type="submit" class="btn btn-primary" id="save_change">Send Mail</button>
	  </div>
	</div>
</div>
</form>
<!---------- End Modal ---------->
<script type="text/javascript">		
$(document).ready(function(){
	////////////////////////// Cloning /////////////////////////////////
	$('#add_new_row').click(function() {
	    $(this).parent().find('.docs').attr("class","new_docs");
		$('#div_to_clone').show();
		var cloned_div = $('#div_to_clone').clone();
		$('#div_to_clone').after(cloned_div);
		$(this).parent().children().first().find('.new_docs').attr("class","docs");
		$('#div_to_clone').hide();			
	});
	$("#upload_multiple_document").on("click",".multiform_row_remover",function() {
		$(this).parent().parent().remove();
	});
	
	$("#form-horizontal1").submit(function(event) {
		var mail_format_subject   = $("#mail_format_subject").val();
		var mail_format_body   = $("#mail_format_body").val();
		if(mail_format_subject != "" && mail_format_body !=""){
		  event.preventDefault();
		  //grab all form data  
		  var formData = new FormData($(this)[0]);
		  
			$.ajax({
				async: false,
				contentType: false,
				processData: false,
				type: "POST",
				url: site_url+"/modules/enquiry_management/index.php?page=ajax_actions&action=mail_send",
				data: formData,
				success: function(r){          
					alert(r);
					location.reload();
				}
			});
			return false;
		}else{
			alert("Please enter mail subject and mail body");
		}
	});
});
</script>