
<style type="text/css">
	.datepicker thead tr .dow{color:#4c0870 !important}
	.datepicker thead tr .datepicker-switch {color:#4c0870 !important}
	.datepicker thead tr .next:before, .datepicker thead tr .prev:before {color:#4c0870 !important}
	.datepicker table tr td.active.active{background:#4c0870 !important}
	.datepicker table tr td.day:hover {background:#4c0870 !important ;color:#fff}
	.table thead tr >th{
		background-color:#4c0870;
		color:#fff;
	}
	.table thead tr th[class*='sorting_'] {
		color: #fff;
	}
	.txtarea{
		width:100%;
		height:150px;
		border: 2px solid #40d9ca;
	}
	hr{
		border-color:#000
	}
</style>
<div class="container-fluid container-fixed-lg bg-white">
	<div class="panel panel-transparent">
		<div class="panel-heading">
			<div class="panel-title"><?php print CommonLanguage::getMessage('ev_performance_emp');?></div>
			<div id="EvaluationSuccess" class="hidden"></div>
		</div>
		<div class="panel-body" style="height:1000px ">
			<input type="hidden" value="<?php echo count($Question) ?>" id="CountOfQuestion">
			<div class="col-md-12">
				<div class="col-xs-4">
					<div class="form-group">
						<div class="input-group m-b"><span class="input-group-btn">
							<button type="button" class="btn btn-success" style="width:0 " ><i class="fa fa-user"style="color:#fff;margin-left:-7px"></i> </button> </span> 
							<input type="text" placeholder="<?php print CommonLanguage::getMessage('employee_name');?>" id="Employee_Name" class="form-control Autocomplete" required />
						</div>
					</div>
				</div>
				<div class="col-xs-4">
					<div class="form-group">
						<div class="input-group m-b"><span class="input-group-btn">
							<button type="button" class="btn btn-success" style="width:0 " ><i class="fa fa-font"style="color:#fff;margin-left:-7px"></i> </button> </span> 
							<input type="text" placeholder="<?php print CommonLanguage::getMessage('ev_title');?>" id="Evaluation_Title" class="form-control" required />
						</div>
					</div>
				</div>
				<div class="col-xs-4">
					<div class="form-group">
						<div class="input-group m-b"><span class="input-group-btn">
							<button type="button" class="btn btn-success" style="width:0 " ><i class="fa fa-calendar"style="color:#fff;margin-left:-7px"></i> </button> </span> 
							<input type="text" id="Evaluation_Date" name="Evaluation_Date" value="<?php echo $today?>" class="form-control" />
						</div>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<table class="table table-bordered table-hover demo-table-search " id="EvaluationTable"> 
					<thead>
						<tr>
							<th class="text-center"><?php print CommonLanguage::getMessage('ev_questions');?></th>
							<?php for($x=0;$x<count($evaluationName);$x++){
	$CurItem = $evaluationName[$x];
							?>
							<th class="text-center" style="width:15%"><?php echo CommonLanguage::getMessage($CurItem['Evaluation_Name']).'<br>'.$CurItem['EvaluationDegree_ID']?></th>
							<?php }
							?>
						</tr>
					</thead>
					<tbody>
						<?php 
						for($x=0;$x<count($Question);$x++){
							$CurItemQuestion = $Question[$x];
						?>
						<tr>
							<td class="text-center Question_ID"  data-id="<?php echo $CurItemQuestion['Question_ID']?>"><?php echo $CurItemQuestion['Question_Name']?></td>
							<td class="text-center"><input type="radio" name="Evaluation_Name<?php echo $x?>" value="1"   class="Evaluation_Name"/></td>
							<td class="text-center"><input type="radio"  name="Evaluation_Name<?php echo $x?>" value="2"   class="Evaluation_Name"/></td>
							<td class="text-center"><input type="radio" name="Evaluation_Name<?php echo $x?>" value="3" class="Evaluation_Name"/></td>
							<td class="text-center"><input type="radio" name="Evaluation_Name<?php echo $x?>" value="4" class="Evaluation_Name"/></td>
							<td class="text-center"><input type="radio" name="Evaluation_Name<?php echo $x?>" value="5" class="Evaluation_Name"/></td>
						</tr>
						<?php }  ?>
					</tbody>
				</table>
			</div>
			<div class="col-md-12">
				<div class="col-md-3" style="margin-left:-18px">
					<label class="bold"><?php print CommonLanguage::getMessage('average_percent');?></label>
				</div>
				<div class="col-md-3" style="margin-left: -43px;">
					<input type="text" class="form-control" id="Average_Performance" placeholder="Performance" disabled style="color: #000;"/>
				</div>
			</div>
			<div class="col-md-12">
				<div class="col-md-3" style="margin-top:8px;margin-left: -18px;">
					<label class="bold"><?php print CommonLanguage::getMessage('require_training');?></label>
				</div>
				<div class="col-md-3 " style="margin-left: -43px;">
					<div class="radio radio-success" id="Extra_Training">
						<input type="radio" value="1" name="optionyes" id="yes">
						<label for="yes"><?php print CommonLanguage::getMessage('agree');?></label>
						<input type="radio" checked="checked" value="0" name="optionyes" id="no">
						<label for="no"><?php print CommonLanguage::getMessage('disagree');?></label>
					</div>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<label><?php print CommonLanguage::getMessage('remarks');?>:</label>
					<textarea class="txtarea" id="Evaluation_Remarks"></textarea>
				</div>
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<label><?php print CommonLanguage::getMessage('proposed_action');?>:</label>
					<div class="radio radio-success" id="Checkboxlist" >
						<?php for($x=0;$x<count($Action);$x++){
	$CurItemCheck = $Action[$x];
						?>
						<input type="radio" value="<?php echo $CurItemCheck['Action_ID']?>" name="ProposedAction" id="<?php echo $CurItemCheck['Action_Name']?>">
						<label for="<?php echo $CurItemCheck['Action_Name']?>"><?php echo $CurItemCheck['Action_Name']?></label>
						<?php } ?>
					</div>
				</div>
				<hr style="border-color:#B4B4B4;border:2px solid">
			</div>
			<div class="col-md-12">
				<div class="form-group">
					<label><?php print CommonLanguage::getMessage('manager_signature');?>  :<hr> </label>
					<label  class="pull-right"><?php print CommonLanguage::getMessage('employee_signature');?> <?php print CommonLanguage::getMessage('ev_performance_emp');?> :<hr> </label>  
				</div>
			</div>
			<div class="col-md-12 no-print">
				<button class="btn btn-success pull-right" style="margin:5px" id="SubmitEvaluation"><i class="fa fa-check"></i> <?php print CommonLanguage::getMessage('Save');?></button>
				<button class="btn btn-danger pull-right" style="margin:5px"  onclick="javascript:window.print();"><i class="fa fa-print"></i> <?php print CommonLanguage::getMessage('print');?></button>
			</div>
		</div>
	</div>
</div>
<script>
    var Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully'));?>,
        Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit'));?>;
	var current_Employee;
	$(function(){
		EnableAutoComplete($("#Employee_Name"));
                    $("#Evaluation_Date").datepicker({autoclose:true}).on("changeDate",function(){$(this).val()})
		var CheckValue = [] ,CheckValueName=[] ,ProposedAction=[]
		$("#SubmitEvaluation").on("click",function(){
			if( $("#Evaluation_Title").val() == '' || $("#Employee_Name").val() == ''  ){
				$("#EvaluationSuccess").attr("class","alert alert-danger").html('<?php echo json_encode(CommonLanguage::getMessage('Required_Fields'));?>')
				return ;
			}
			$("#EvaluationSuccess").attr("class","hidden");
			var Data = {
				Employee_ID : current_Employee,
				Evaluation_Title : $("#Evaluation_Title").val(),
				Evaluation_Date :$("#Evaluation_Date").val(),
				Evaluation_Remarks :$("#Evaluation_Remarks").val(),
				Extra_Training : $("#Extra_Training :checked").val(),
				Average_Performance : $("#Average_Performance").val(),
				CheckValueName:CheckValueName,
				CheckValue:CheckValue,
				ProposedAction :ProposedAction
			}
			$("#EvaluationTable tbody tr").each(function(){
				var me = $(this);
				CheckValue.push(
					me.find("td > input.Evaluation_Name:checked").val()
				)
				CheckValueName.push(
					me.find(".Question_ID").attr('data-id')    
				)
			})
			$('input[name="ProposedAction"]:checked').each(function() {
				ProposedAction.push(this.value);
			});
			$.ajax({
				url:'HRMAjax/EvaluationPerformanceRequest',
				data:Data,
				method:"POST",
				complete:function(v1,v2){
					if(v2 == 'success'){
						$("#EvaluationSuccess").attr("class","alert alert-success").html(Submitted_Successfully)
					}
					else{
						$("#EvaluationSuccess").attr("class","alert alert-danger").html(Failed_Submit)
					}
					$(document.body).animate({scrollTop:0},800)
				}
			})
		})
		$("#EvaluationTable tbody tr").on("click","td >input",function(){
			UpdateAverage()
		})
	})
	function EnableAutoComplete(who){
		if(!who.hasClass("AutoAdded")){
			who.autocomplete({
				source: 'xhr/ajaxEmployee' ,
				minLength: 2,
				select: function(event, ui){
					var TR = $(this).val(ui.item.Employee_Name)
					current_Employee = ui.item.Employee_ID;
					return false;
				}
			}).autocomplete("instance")._resizeMenu = function( ul, items ) {
				this.menu.element.outerWidth((who.width()) + parseFloat(who.css("padding-left")) + parseFloat(who.css("padding-right")) + 2);
			}
			who.autocomplete("instance")._renderItem = function(ul,item){
				var MyType =  item.Employee_Name;
				return $("<li>").html("<table cellspacing='0' cellpadding='0'><tr><td class='OnlyText'>"+MyType+"</td></tr></table>").appendTo(ul)
			}
			who.addClass("AutoAdded")
		}
		$(document).keydown(function(e){
			if(e.which == 8 && e.target.tagName.toLowerCase() != "input" && e.target.tagName.toLowerCase() != "textarea"){
				e.preventDefault()
			}
		})
	}
	function UpdateAverage(){
		var TotalNumber = $("#CountOfQuestion").val(),A1=0,A2=0,Average=0,Total = TotalNumber * 5 ;
		$("#EvaluationTable tbody tr").each(function(){
			var me = $(this),
				A1 = parseFloat(me.find("td >input.Evaluation_Name:checked").val()) || 0;
			A2 +=A1;
			Average = parseFloat(A2/Total).toFixed(2) ;
			$("#Average_Performance").val(Average*100)
		})
	}
</script>