<form onSubmit="return edit_validation(this);" action="<?php echo base_url($this->router->fetch_class()."/update")?>" method="POST" style="padding-left: 5px; padding-right: 5px;">
	<!--  -->
	<?php if(isset($data)):?>
		<input type="hidden" id="edit_ID" name="ID" value="<?php echo $data->ID;?>">
	<?php endif;?>
	<!--  -->
	
	<div class="form-group">
		<label>Date</label>
		<?php if(isset($data)):?>
			<p class="form-control-static"><?php if($data->DATE_CREATED != "") echo date("d M Y h:i a", strtotime($data->DATE_CREATED));?></p>
		<?php endif;?>
	</div>
	
	<?php if(isset($data) && $data->TO != ""):?>
		<div class="form-group">
			<label>To</label>
			<p class="form-control-static"><?php echo $data->TO;?></p>
		</div>
	<?php endif;?>
	
	<?php if(isset($data) && $data->CC != ""):?>
		<div class="form-group">
			<label>CC</label>
			<p class="form-control-static"><?php echo $data->CC;?></p>
		</div>
	<?php endif;?>
	
	<?php if(isset($data) && $data->BCC != ""):?>
		<div class="form-group">
			<label>BCC</label>
			<p class="form-control-static"><?php echo $data->BCC;?></p>
		</div>
	<?php endif;?>
	
	<div class="form-group">
		<label>Subject</label>
		<p class="form-control-static"><?php if(isset($data)) echo $data->SUBJECT;?></p>
	</div>
	
	<div class="form-group">
		<label>Status</label>
		<p class="form-control-static">
			<?php if(isset($data)):?>
				<span class="label label-<?php echo $data->SUCCESS? "success":"danger";?>">
					<?php echo $data->SUCCESS? "SUCCESS":"FAILED";?>
				</span>
			<?php endif;?>
		</p>
	</div>
	
	<?php if(isset($data) && $data->CREATE_USER_NAME != ""):?>
		<div class="form-group">
			<label>User Info</label>
			<p class="form-control-static">
				<?php 
					$user_info = "Sent";
					if($data->CREATE_USER_NAME != "") $user_info .= " by ".$data->CREATE_USER_NAME;
					if($data->DATE_CREATED != "") $user_info .= " on ".date("d M Y h:i a", strtotime($data->DATE_CREATED));
					$user_info .= ".";
					
					echo $user_info;
				?>
			</p>
		</div>
	<?php endif;?>
	
	<?php if(isset($data) && in_array($this->session->userdata('user_id'), $this->domain_id)):?>
		<div class="form-group">
			<label>Result</label>
			<p class="form-control-static">
				<?php echo $data->RESULT;?>
			</p>
		</div>
	<?php endif;?>
</form>

<script>
	$(document).ready(function(){
		$("#edit_ajax_container .select2").select2();
	});

	function edit_validation(form){
		var error = "";
		
		$(form).find("[required]").each(function(){
			if($(this).val() == ""){
				if(error != "") error += "<br>";
				switch($(this).attr("name")){
					case "NAME":
						error += "Please fill in the Name!";
						break;
					default:
						error += "Please complete the Form!";
						break;
				}
				
				return false;
			}
		});

		if(error == ""){
			disable_btn(".btn_submit");
		}
		else{
			prompt_error(error);
			return false;
		}
	}
</script>