var basicPATH =localStorage['basicPATH'];
var serviceURLHR =localStorage['serviceURLHR'];
jQuery('.updateBasicProfile').live('click',updateBasicProfile);

var emp_id = getUrlVars()["employ_id"];

jQuery(document).ready(function(){ eventListner(); });

$('#workFrom').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});

$('#workTo').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});



/*loadDesignation();

function loadDesignation(){
	
	$.getJSON(serviceURLHR + 'designations.php?action=load',function(data){
		designation = data.designation;
		
		$.each(designation, function(index, designation) {
									 
							$('#designation').append('<option value="'+designation.desig_id+'">'+designation.desig_name+'</option>');
							
		});	
	});
}*/

loadDepartment();

function loadDepartment(){
	$.getJSON(serviceURLHR + 'department.php?action=load',function(data){
		department = data.department;
		
		$.each(department, function(index, department) {
									 
							$('#department').append('<option value="'+department.depart_id+'">'+department.depart_name	+'</option>');
							
		});	
		setTimeout(function(){ $('#department').val(deptid); },100);
	});
}






function loadBranch(){
	$.getJSON(serviceURLHR + 'branch.php?action=load',function(data){
		branch = data.branch;
		
		$.each(branch, function(index, branch) {
									 
							$('#branch1').append('<option value="'+branch.branch_id+'">'+branch.branch_name	+'</option>');
							
		});	
		setTimeout(function(){ $('#branch1').val(branchid); },100);
	});
}


loadimediatesupervisor();

function loadimediatesupervisor(){
	$.getJSON(serviceURLHR + 'immediatesupervisor.php?action=load',function(data){
		imdsupervisor = data.imdsupervisor;
		$('#imdatesupervisor').append('<option value="">Select Imm Supervisor</option>');
		$.each(imdsupervisor, function(index, imdsupervisor) {
									 
							$('#imdatesupervisor').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');
							
		});	
		
		  	setTimeout(function(){ $('#imdatesupervisor').val(immsuperid); },2500);

	});
}

function editBankDetails(){
	
	var accountName =$('#accountname').html();
	var accountno =$('#accountno').html();
	var bname =$('#bname').html();
	var baddress =$('#baddress').html();
	var bankcode =$('#bankcode').html();
	
	$('#accountname').html('<input type="text" value="'+accountName+'" name="accountName" class="accountName">');
	$('#accountno').html('<input type="text" value="'+accountno+'" name="accountno" class="accountno">');
	$('#bname').html('<input type="text" value="'+bname+'" name="bname" class="bname">');
	$('#baddress').html('<input type="text" value="'+baddress+'" name="baddress" class="baddress">');
	$('#bankcode').html('<input type="text" value="'+bankcode+'" name="bankcode" class="bankcode">');
	$('.edit-bankDetails').attr({'src':'images/icon-tick.png','class':'save-bankdetails'})
}
function updateBankDetails(){
	
	var accountName =$('.accountName').val();
	var accountno=$('.accountno').val();
	var bname =$('.bname').val();
	var baddress =$('.baddress').val();
	var bankcode =$('.bankcode').val();
	
	$('#accountname').html(accountName);
	$('#accountno').html(accountno);
	$('#bname').html(bname);
	$('#baddress').html(baddress);
	$('#bankcode').html(bankcode);
	$('.save-bankdetails').attr({'src':'images/edit.png','class':'edit-bankDetails'})
	
	var dataString = 'accountname='+accountName+'&bankname='+bname+'&accountno='+accountno+'&bankaddress='+baddress+'&ifsccode='+bankcode+'&employee_id='+emp_id;
	
	$.post(serviceURLHR+"manageEmployees.php?action=updatebankdetails",dataString,function(){
																							   
	});
	
}




function editWorkExperiance(){
	
	var emp_name 	= $('#emp').html();
	var address		= $('#address2').html();
	var phone 		= $('#phno').html();
	var email1		= $('#email1').html();
	var position	= $('#posi').html();
	var salary		= $('#sal').html();
	var workfrom	= $('#from').html();
	var workto		= $('#to').html();
	var reasontoleave= $('#rfl').html();
	
	$('#emp').html('<input type="text" value="'+emp_name+'" class="emp" name="emp[]"/>');
	$('#address2').html('<input type="text" value="'+address+'" class="address2" name="address[]"/>');
	$('#phno').html('<input type="text" value="'+phone+'" class="phno" name="phno[]"/>');
	$('#email1').html('<input type="text" value="'+email1+'" class="email1" name="email[]"/>');
	$('#posi').html('<input type="text" value="'+position+'" class="posi" name="posi[]"/>');
	$('#sal').html('<input type="text" value="'+salary+'" class="sal" name="sal[]"/>');
	$('#from').html('<input type="text" value="'+workfrom+'" class="from" name="from[]"/>');
	$('#to').html('<input type="text" value="'+workto+'" class="to" name="to[]"/>');
	$('#rfl').html('<input type="text" value="'+reasontoleave+'" class="rfl" name="rfl[]"/>');
	
	$('.edit-workexperiance').before('<img src="images/icon-add.png" class="addmore-workexperiance"/>');
	
	$('.edit-workexperiance').attr({'src':'images/icon-tick.png','class':'save-workexperiance'});
	
	
}

function addmoreWorkExperiance(){

	//var newExperiance = $('.profile-view-tab02').clone();
	//newExperiance.find('h3').remove();
	//$('#work-experiance').append(newExperiance);
}


function editProfileImage(){
	$('.profile-photo').html('<form class="changeprofileimage"><input accept="image/*" type="file" name="profileimage" class="profileimage"/></form>');
};

function displayNewImage($this){
	
	//var imageURL = $this.val();
	//var dataString = $('#updateproduct').serialize();

	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'manageEmployees.php?action=updateimage',  //Server script to process data
        type: 'POST',
        data: formData,
		processData: false,  // tell jQuery not to process the data
  		contentType: false ,  // tell jQuery not to set contentType
		success: function(data){
			//	if(data=='success'){
		/*		$('.profile-photo')	.html('<div class="pane clearfix" style="z-index">'+
							  '<img src="'+data+'" class="profile-image" alt="Loulou form Sos Chats Geneva" width="150" />'+
							  '</div>'+
							  '<input type="text" class="cropx" value="0">'+
							  '<input type="text" class="cropy" value="0">'+
							  '<input type="text" class="imgwidth" value="0">'+
							  '<input type="text" class="imgheight" value="0">'+
							   '<input type="text" class="zoomwidth" value="0">'+
							  '<input type="text" class="zoomheight" value="0">'+
							  '<input type="button" class="saveImage" value="Done">');*/
		
		$("body").append('<div class="newProfileImage" style="display:none">'+
					 '<table width="510" height="520" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="500"><div style="width:500px;height:400px;">'+
						'<div id="cropbox" style="width:500px;height:400px;"><img src="'+data+'" class="profile-image" /></div></div>'+
						
						'<form class="cropdetails" method="post">'+
							'<input type="hidden" id="fileurl" name="fileurl" value="'+data+'" />'+
							'<input type="hidden" id="x" name="x" />'+
							'<input type="hidden" id="y" name="y" />'+
							'<input type="hidden" id="w" name="w" />'+
							'<input type="hidden" id="h" name="h" />'+
							'<input type="button" value="Crop Image" class="btn btn-large btn-inverse color-button crop-image" />'+
						'</form>'+
						
						'</td>'+
					  '</tr>'+

					  '<tr>'+
						'<td><input type="button" name="button" id="applyLeave" class="color-button2" value="Submit" />'+
						'<input type="button" name="button" id="cencelApplication" class="color-button2" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></div>');
		
		$('.newProfileImage').show('fade',300);
	$('.newProfileImage').center();
		
	 $('#cropbox').Jcrop({
      aspectRatio: 1,
      onSelect: updateCoords
    });
	
	//cropImage();
		//	}
		}
	});	
	
	
}
$('.crop-image').live('click',function(){ 
									   
		var dataString = $('.cropdetails').serialize();
		$.post(serviceURLHR + 'manageEmployees.php?action=cropimage',dataString,function(data){
																						 
		});
									   
 });
/*function cropImage(){
 $('.pane img').jrac({
          'crop_width': 170,
          'crop_height': 172,
          'crop_x': 100,
          'crop_y': 100,
          'image_width': 400,
          'viewport_onload': function() {
            var $viewport = this;
            var inputs = $('#profimage').find('input:text');
            var events = ['jrac_crop_x','jrac_crop_y','jrac_crop_width','jrac_crop_height','jrac_image_width','jrac_image_height'];
            for (var i = 0; i < events.length; i++) {
              var event_name = events[i];
              // Register an event with an element.
              $viewport.observator.register(event_name, inputs.eq(i));
              // Attach a handler to that event for the element.
              inputs.eq(i).bind(event_name, function(event, $viewport, value) {
                $(this).val(value);
              })
              // Attach a handler for the built-in jQuery change event, handler
              // which read user input and apply it to relevent viewport object.
              .change(event_name, function(event) {
                var event_name = event.data;
                $viewport.$image.scale_proportion_locked = $viewport.$container.parent('.pane').find('.coords input:checkbox').is(':checked');
                $viewport.observator.set_property(event_name,$(this).val());
              });
            }

          }
        })
        // React on all viewport events.
        .bind('jrac_events', function(event, $viewport) {
          var inputs = $(this).parents('.pane').find('.coords input');
          inputs.css('background-color',($viewport.observator.crop_consistent())?'chartreuse':'salmon');
        });	
}*/

function saveProfilePicture(){
	cropx = $('.cropx').val();
	cropy = $('.cropy').val();
	imgwidth = $('.imgwidth').val();
	imgheight = $('.imgheight').val();
	
	zoomwidth = $('.zoomwidth').val();
	zoomheight = $('.zoomheight').val();
	
	
	
	fileurl =$('.profile-image').attr('src');
	var dataString = "cropx="+cropx+"&cropy="+cropy+"&fileurl="+fileurl+"&imgwidth="+imgwidth+"&imgheight="+imgheight+"&zoomwidth="+zoomwidth+"&zoomheight="+zoomheight;
	$.post(serviceURLHR + 'manageEmployees.php?action=cropimage',dataString,function(data){
		
	});
};


function eventListner(){
	
	jQuery('.edit-bankDetails').live('click',editBankDetails);
	jQuery('.save-bankdetails').live('click',updateBankDetails);
	
	
	jQuery('.editBasicProfile').live('click',editBasicProfile);
	jQuery('.edit-workexperiance').live('click',editWorkExperiance);
	//jQuery('.save-workexperiance').live('click',updateWorkExperiance);
	jQuery('.addmore-workexperiance').live('click',function(){ addmoreWorkExperiance() });
	//jQuery('.delete-workexperiance').live('click',deleteWorkExperiance);
	jQuery('.profile-photo').live('mouseenter',function(){ $('.edit-profileimage').show(); }).live('mouseleave',function(){ $('.edit-profileimage').hide(); });
	jQuery('.edit-profileimage').live('click',editProfileImage);
	jQuery('.profileimage').live('change',function(){ var $this =$(this); displayNewImage($this); });
	jQuery('.saveImage').live('click',saveProfilePicture);
	jQuery('#cencelApplication').live('click',function(){$('.newLeaveApplication').hide('clip',300,function(){ $(this).remove()});});
	jQuery('#applyLeave').live('click',applyLeave);
	jQuery('.removeDeduction').live('click',removeDeductionFromEmployee);
	jQuery('.adddeductions').live('click',addDeductionToEmployee);
	jQuery('.removeLeave').live('click',removeLeavesFromEmployee);
	jQuery('.addleaves').live('click',addLeavesToEmployee);
	jQuery('.leaveApplication').live('click',newLeaveApplication);
	jQuery('.editBasicPay').live('click',editBasicPayment);
	jQuery('.saveBasicPay').live('click',updateBasicPayment);
	jQuery('.editovertime').live('click',editovertime);
	jQuery('.saveovertime').live('click',updateovertime);
	jQuery('.newSalary').live('keypress',function(e) { if(e.which == 13) { updateBasicPayment(); } });
	
	
	jQuery('.addEmployeeDetails').live('click',addEmployeeDetails);
	jQuery('.saveEmployeeDetails').live('click',saveEmployeeDetails);
	jQuery('.cancelEmployeeDetails').live('click',function(){  $('.newEmployeeDetails').hide('clip',300,function(){ $(this).remove(); })  });
	
	jQuery('.editReferance').live('click',editReferance);	
	jQuery('.saveReferance').live('click',saveReferance);
	jQuery('.addNewWorkExperiance').live('click',addWorkExperiance);
	
	
	
	
	jQuery('.cancelWorkExperiance').live('click',function(){  $('.newWorkExperiance').hide('clip',300,function(){ $(this).remove(); })  });
	jQuery('.saveWorkExperiance').live('click',saveWorkExperiance);
	jQuery('.savebasicdetails').live('click',savebasicdetails);
	jQuery('.changebasicdetails').live('click',changebasicdetails);
	
	//jQuery('.cancelWorkExperiance').live('click',function(){  $('.newWorkExperiance').hide('clip',300,function(){ $(this).remove(); })  });
//	jQuery('.saveWorkExperiance').live('click',saveWorkExperiance);
	jQuery('.cancelBasicProfile').live('click',function(){  $('.newbasicdetails').hide('clip',300,function(){ $(this).remove(); })  });
	jQuery('.cancelView').live('click',function(){  $('.viewbasicdetails').hide('clip',300,function(){ $(this).remove(); })  });
	/*jQuery('.vieweducation').live('click',vieweducation);*/
	/*jQuery('.viewworkexperience').live('click',viewworkexperience);*/
	
	jQuery('.changepassword').live('click',changepassword);
	jQuery('.savechangepassword').live('click',savechangepassword);
	jQuery('.cancelchangepassword').live('click',function(){  $('.newChangePassword').hide('clip',300,function(){ $(this).remove(); })  });
	
}

function editBasicPayment(){
	var basicPay = $('.basicpay').html();
	$('.basicpay').html('<input type="text" value="'+basicPay+'" style="width:60px" class="newSalary">')
	$(this).attr({'src':'images/1388406658_ok-green.png','class':'saveBasicPay'});
}

function updateBasicPayment(){


	var newBasicPay = $('.newSalary').val();
	var employeeId =emp_id ;
 

	$.get(serviceURLHR + "manageSalary.php?act=updateBasicPay&newSalary="+newBasicPay+"&eid="+employeeId,function(){
		$('.basicpay').html(newBasicPay);	
		$('.saveBasicPay').attr({'src':'images/edit.png','class':'editBasicPay'});
	});	
}

function editovertime(){
	var overtime = $('.overtime').html();
	$('.overtime').html('<input type="text" value="'+overtime+'" style="width:60px" class="newovertime">')
	$(this).attr({'src':'images/1388406658_ok-green.png','class':'saveovertime'});
}

function updateovertime(){


	var newovertime = $('.newovertime').val();
	var employeeId =emp_id ;
 

	$.get(serviceURLHR + "manageSalary.php?act=updateovertime&newSalary="+newovertime+"&eid="+employeeId,function(){
		$('.overtime').html(newovertime);	
		$('.saveovertime').attr({'src':'images/edit.png','class':'editovertime'});
	});	
}
setTimeout(loadDeductios,150);
function loadDeductios(){
var basicpay_val=$('.basicpay').html();

 var depart_id=$('.depart_id').val();
  var employ_id=$('#employ_id').val();
  
					if(depart_id != 3)
					{
					var dedovertime= "editedovertime";
					var dedclassname = "adddeductiond";
					}
					else
					{
						var dedovertime= "editovertime";
						var dedclassname = "adddeductionsd";
					}
	$.getJSON(serviceURLHR +"manageDeduction.php?act=list&employ_id="+employ_id,function(data){
																						 
			var deduction = data.deductions
			
			
			
			
				$.each(deduction, function(index,deductions){
										   
				if($('.overtime_check').length == 0) {
					if(deductions.overtime_status == "1")	{
						$('.benefits').append( '<tr height="25" class="overtime_check">'+
									'<td>OverTime</td>'+
									'<td width="40%" align="left" valign="top">:<span class="overtime">'+deductions.over_time+'</span>%</td>'+
									'<td><img class="'+dedovertime+'" data-id="'+deductions.e_id+'" src="images/edit.png" width="16" height="16"/></td>'+
									'</tr>');	
						
					}
				}						   
										   
				
				
					switch(deductions.unit){
						case "1":ded_unit="Rs";break;
						case "2":ded_unit = "%";break;
					}
					
				if(deductions.deduction_benefit == "2")	{
					$('.benefits').append( '<tr height="25">'+
								'<td>'+deductions.name+" ("+ded_unit+')</td>'+
								'<td>:'+deductions.amount+'</td>'+
								'<td><img class="'+dedclassname+'" data-id="'+deductions.id+'" src="images/tick.png"/></td>'+
								'</tr>');	
					
				}
				
				
				else if(deductions.deduction_benefit == "1"){
				
					//alert('aa');
					var dedclassname1='';
					//alert(deductions.name);
					//if(basicpay_val<6500 && deductions.name == 'PF')
//					{
//						
//						
//					}
//					else
//					{
									
					$('.deductions').append( '<tr height="25">'+
								'<td>'+deductions.name+" ("+ded_unit+')</td>'+
								'<td>:'+deductions.amount+'</td>'+
								'<td><img class="'+dedclassname+'" data-id="'+deductions.id+'"  src="images/tick.png"/></td>'+
								'</tr>');
					//}
					
					
					
				}
				
				else{
					
					$('.contribution').append( '<tr height="25">'+
								'<td width="60%">'+deductions.name+" ("+ded_unit+')</td>'+
								'<td width="40%">:'+deductions.amount+'</td>'+
								'<td><img class="'+dedclassname+'" data-id="'+deductions.id+'" src="images/bt-close.jpg"/></td>'+
								'</tr>');	
				}
				
				
				
				
		});
				alert(deductions.overtime_status);
		setTimeout(deductionsCurrentEmployee,50);	
		},'json');										  
}

function deductionsCurrentEmployee(){
	
	 var depart_id=$('.depart_id').val();
					
					if(depart_id != 3)
					{
					var dedclassname = "adddeduction";
					}
					else
					{
						var dedclassname = "adddeductions";
					}
	
	var employeeid = emp_id;
	$.getJSON(serviceURLHR + "manageDeduction.php?act=emp&emp_id="+employeeid,function(data){
		var deductions = data.deductions;
		$.each(deductions,function(index,deductions){
			$('.'+dedclassname).each(function(){
				var deductionid = $(this).attr('data-id');
				if(deductions.deduction_id  == deductionid)		{
					$(this).attr({'src':'images/tick.png','class':'removeDeduction'});	
					
					if(depart_id != 3){
						$(this).attr({'class':'removedDeduction'});	
						}
						else{
						$(this).attr({'class':'removeDeduction'});	
						}	
				}
			});
		});
	});
}

function removeDeductionFromEmployee(){
	$this = $(this);	
	var deductionid = $this.attr('data-id');
	var employeeid  = emp_id;
	$.get(serviceURLHR +"manageDeduction.php?act=removeded&emp_id="+employeeid+"&deduction_id="+deductionid,function(){
		$this.attr({'class':'adddeductions','src':'images/bt-close.jpg'});
	});
	
}
function addDeductionToEmployee(){
	$this =$(this);
	var deductionid = $this.attr('data-id');
	var employeeid  = emp_id;
	
	$.get(serviceURLHR +"manageDeduction.php?act=addtoemp&emp_id="+employeeid+"&deduction_id="+deductionid,function(){
		$this.attr({'class':'removeDeduction','src':'images/tick.png'});
	});
}


loadLeaves();
function loadLeaves(){
	
 var depart_id=$('.depart_id').val();
 
					if(depart_id != 3)
					{
					var classname = "addleave";
					}
					else
					{
						var classname = "addleaves";
					}
				
 $.getJSON(serviceURLHR +"manageLeaves.php?act=list",function(data){
			var leaves = data.leaves
			
			
				$.each(leaves, function(index,leaves){
				switch(leaves.based_on){
					case "1":based_on="Month";break;
					case "2":based_on = "Year";break;
				}
				
					$('.leaves').append( '<tr height="25">'+
								'<td width="40%">'+leaves.title+'</td>'+
								'<td width="40%">:'+leaves.number_of_days+' Days / '+based_on+'</td>'+								
								'<td width="40%"><img class="'+classname+'" data-id="'+leaves.lid+'" src="images/inactive-icon.png" style="max-width:75px!important; width:75px;"/></td>'+	
								
								'</tr>');	
					
				
		});
		leavesCurrentEmployee();	
		},'json');										  
}

function leavesCurrentEmployee(){
	 var depart_id=$('.depart_id').val();
					
					if(depart_id != 3)
					{
					var classname = "addleave";
					}
					else
					{
						var classname = "addleaves";
					}
	var employeeid = emp_id;
	$.getJSON(serviceURLHR + "manageLeaves.php?act=emp&emp_id="+employeeid,function(data){
		var leaves = data.leaves;
		$.each(leaves,function(index,leaves){
							   
			$('.'+classname).each(function(){
				var leaveid = $(this).attr('data-id');
				if(leaves.leave_id  == leaveid)	
				{
					$(this).attr({'src':'images/active-icon.png','class':'removeLeave'});	
				
						if(depart_id != 3){
						$(this).attr({'class':'removedLeave'});	
						}
						else{
						$(this).attr({'class':'removeLeave'});	
						}		
				
				}
				
				
			});
		});
	});
}

function removeLeavesFromEmployee(){
	
	$this = $(this);	
	var leaveid = $this.attr('data-id');
	var employeeid  = emp_id;
	$.get(serviceURLHR +"manageLeaves.php?act=removeded&emp_id="+employeeid+"&leave_id="+leaveid,function(){
		$this.attr({'class':'addleaves','src':'images/inactive-icon.png'});
	});
	
}


function addLeavesToEmployee(){
	
	$this =$(this);
	var leaveid = $this.attr('data-id');
	var employeeid  = emp_id;
	
	$.get(serviceURLHR +"manageLeaves.php?act=addtoemp&emp_id="+employeeid+"&leave_id="+leaveid,function(){
		$this.attr({'class':'removeLeave','src':'images/active-icon.png'});
	});
}

function newLeaveApplication(){
	var employeeid = emp_id;
	$("body").append('<div class="newLeaveApplication" style="display:none">'+
					 '<form class="newLeaveApplicationForm"><table width="500" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="217">&nbsp;</td>'+
						'<td width="304">&nbsp;</td>'+
					  '</tr>'+
					  '<tr>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave From</translate></td>'+
						'<td><input type="text" name="day_from" id="day_from" class="my_date" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave To</translate></td>'+
						'<td><input type="text" name="day_to" id="day_to" class="my_date" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Leave Type</translate></td>'+
						'<td><select name="leave_id" id="leaveList">'+
						'</select>    </td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories"><translate>Reason</translate></td>'+
						'<td><textarea name="reason" id="reason" cols="45" rows="5"></textarea></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td class="categories">&nbsp;</td>'+
						'<td><input type="button" name="button" id="applyLeave" class="color-button2" value="Submit" />'+
						'<input type="button" name="button" id="cencelApplication" class="color-button2" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');
	$('#leaveList').loadLeaves();
	$('.newLeaveApplication').show('fade',300);
	$('.newLeaveApplication').center();
}


function applyLeave(){
	var $this = $(this);
	var employeeid = emp_id;
	var dataString = $('.newLeaveApplicationForm').serialize();
	
	$.post(serviceURLHR + "manageLeaves.php?act=newRequest&emp_id="+employeeid,dataString,function(){
		$('.newLeaveApplication').hide('clip',300,function(){ $(this).remove()});
	});

}


function editReferance(){
	
	$(this).attr({'src':'images/icon-tick.png','class':'saveReferance'});
	$('#rname').html('<input type="text" value="'+$('#rname').text()+'" class="referanceName">');
	$('#contact').html('<input type="text" value="'+$('#contact').text()+'" class="referanceContact">');
	$('#relation').html('<input type="text" value="'+$('#relation').text()+'" class="referanceRelation">');
	$('#loc').html('<input type="text" value="'+$('#loc').text()+'" class="referanceloc">');
	
}

function saveReferance(){
	
	var referanceName = $('.referanceName').val();
	var referanceContactno = $('.referanceContact').val();
	var referanceRelation = $('.referanceRelation').val();
	var referanceloc = $('.referanceloc').val();
	var empid = emp_id;
	
	var dataString = "referanceName="+referanceName+"&referanceContact="+referanceContactno+"&referanceRelation="+referanceRelation+"&referanceloc="+referanceloc
	$.post(serviceURLHR + "manageEmployees.php?action=updateReferance&empid="+empid,dataString,function(){
		$('#rname').html(referanceName);
		$('#contact').html(referanceContactno);
		$('#relation').html(referanceRelation);
		$('#loc').html(referanceloc);	
		$('.saveReferance').attr({'src':'images/edit.png','class':'editReferance'});	
	});
}

function editBasicProfile(){
	
	var fname 	= $('.fname').val();
	var mname 	= $('.mname').val();
	var lname 	= $('.lname').val();
	var e_id 	= $('#e_id').val();
	var dob		= $('#dob').html();
	var phone 		= $('#phone').html();
	var email		= $('#email').html();
	var mobile	= $('#mobile').html();
	var password	= $('#password').html();
	var username	= $('#username').html();
	
	$("body").append('<div class="newBasicProfile" style="display:none;padding:25px;">'+
					 '<form class="newBasicProfileForm"><table width="800" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="200"><translate>First Name</translate></td>'+
						'<td width="200"><input type="text" name="f_name" id="f_name" class="f_name" value="'+fname+'" /><input type="hidden" name="e_id" id="e_id" class="e_id" value="'+e_id+'" /></td>'+
						'<td width="200"><translate>Middle Name</translate></td>'+
						'<td width="200"><input type="text" name="m_name" id="m_name" class="m_name" value="'+mname+'" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Last Name</translate></td>'+
						'<td><input type="text" name="l_name" id="l_name" class="l_name" value="'+lname+'" /></td>'+
						'<td><translate>Email</translate></td>'+
						'<td><input type="text" name="e_mail" id="e_mail" class="e_mail" value="'+email+'" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Phone</translate></td>'+
						'<td><input type="text" name="phone_no" id="phone_no" class="phone_no" value="'+phone+'" /></td>'+
						'<td><translate>Mobile</translate></td>'+
						'<td><input type="text" name="mobile_no" id="mobile_no" class="mobile_no" value="'+mobile+'" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Username</translate></td>'+
						'<td><input type="text" name="empuser_name" id="empuser_name" class="empuser_name" value="'+username+'" /></td>'+
						'<td><translate>Password</translate></td>'+
						'<td><input type="text" name="emppassword" id="emppassword" class="emppassword" value="'+password+'" /></td>'+
					  '</tr>'+

					  '<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveBasicProfile"  class="color-button updateBasicProfile" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelBasicProfile" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');
	 $('#gender1').val(gender);
	$('.newBasicProfile').show('fade',300);
	$('.newBasicProfile').center();
}

function updateBasicProfile(){
	
	var e_id 	= $('#e_id').val();

	var dataString = $('.newBasicProfileForm').serialize();
	
	$.post(serviceURLHR + "manageEmployees.php?action=updateprofile&empid="+e_id,dataString,function(data){
		$('.newBasicProfile').hide('clip',300,function(){ $(this).remove(); });																							   
	},'json');
	
	
	var fname =$('.f_name').val();
	var mname=$('.m_name').val();
	var lname =$('.l_name').val();
	var email =$('.e_mail').val();
	var phone =$('.phone_no').val();
	var mobile =$('.mobile_no').val();
	var username =$('.empuser_name').val();
	var password =$('.emppassword').val();
	$('#name').html(fname+" "+lname);
	$('.fname').val(fname);
	$('.mname').val(mname);
	$('.lname').val(lname);
	$('#phone').html(phone);
	$('#mobile').html(mobile);
	$('#email').html(email);
	$('#username').html(username);
	$('#password').html(password);
	
}



function changebasicdetails(){ 

	var emp_name 	= $('#emp').html();
	var address		= $('#address2').html();
	var phone 		= $('#phno').html();
	var email1		= $('#email1').html();
	var position	= $('#posi').html();
	var salary		= $('#sal').html();
	var workfrom	= $('#from').html();
	var workto		= $('#to').html();
	var reasontoleave= $('#rfl').html();
	var branchid= $('#branchhidden').val();
	var deptid= $('#depthidden').val();
	var desigid= $('#desighidden').val();
	var immsuperid= $('#immsuperhidden').val();
	var branch_admin = $('#branch_admin').val();
	if(branch_admin=='Y')
	{
		var branch_admin_column = '<tr>'+
                      	'<td><label for="branch_admin">Branch admin</label></td>'+
                        '<td><input type="checkbox" name="branch_admin" id="branch_admin" checked></td>'+
                       '</tr>';
	}
	else
	{
		var branch_admin_column = '<tr>'+
                      	'<td><label for="branch_admin">Branch admin</label></td>'+
                        '<td><input type="checkbox" name="branch_admin" id="branch_admin"></td>'+
                       '</tr>';
	}
	loadBranch();
	loadDepartment();
	loadDesignation();
	loadimediatesupervisor();
	$("body").append('<div class="newbasicdetails" style="display:none;padding:25px;">'+
					 '<form class="newbasicdetailsForm"><table width="740"  border="0" cellpadding="0" cellspacing="0">'+
					 '<tr>'+
						'<td colspan="4" style="font-size:15px;font-weight:bold;background:#d80b5d;padding:5px 10px;color:#fff;margin-bottom:10px;" ><translate>Organization Details</translate></td>'+
					  '</tr>'+
					   '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>branch Name</translate></td>'+
						'<td><select name="branch" id="branch1" selected="selected" class="tabfield-1"></select></td>'+
						'<td width="200"><translate>Department Name</translate></td>'+
						'<td><select name="department" id="department" class="tabfield-1 masters"></select></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Designation Name</translate></td>'+
						'<td><select name="designation" id="designation" class="tabfield-1"></select></td>'+
						'<td width="200"><translate>Imm.Supervisor Name</translate></td>'+
						'<td><select name="imdatesupervisor" id="imdatesupervisor" class="tabfield-1"></select></td>'+
					  '</tr>'+branch_admin_column+'<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="savebasicdetails"  class="color-button savebasicdetails tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelBasicProfile tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newbasicdetails').show('fade',500);
	
	//alert(branchid);
	//alert(deptid);
	//alert(desigid);
	//alert(immsuperid);
	



	
	
	
	

	$('.newbasicdetails').center();
	
	load_desigs(deptid);
}

function savebasicdetails(){
	var desig_r_id=$('#desighidden').val();
	var desig_chng_id=$('#chng_val').val();	
	
		var emp_id=$('#employ_id').val();
		var sal_id=$('#salstruct').val(); 
	var dataString = $('.newbasicdetailsForm').serialize();
if(sal_id!='')
{

	if((Number(desig_r_id)!= Number(desig_chng_id)) && Number(desig_chng_id!=''))
	{
	
	    var x = confirm("Do You Want To Keep Old Pay Structure");
        if(x==true)
       {
		   $.post(serviceURLHR + "manageEmployees.php?action=newbasicdetails&empid="+emp_id,dataString,function(data){
		   $('.newbasicdetails').hide('clip',300);																							   
	       },'json');
      }
      else
     {
	     $.post(serviceURLHR + "manageEmployees.php?action=newbasicdetails&empid="+emp_id+"&old_del=1",dataString,function(data){
		 $('.newbasicdetails').hide('clip',300);																							   
	     },'json');
     }

	

  }
  else
  {
		$.post(serviceURLHR + "manageEmployees.php?action=newbasicdetails&empid="+emp_id,dataString,function(data){
		$('.newbasicdetails').hide('clip',300);																							   
	    },'json');
  }
  
  
}///sal struct employee id checking
else
{
	 $.post(serviceURLHR + "manageEmployees.php?action=newbasicdetails&empid="+emp_id,dataString,function(data){
		$('.newbasicdetails').hide('clip',300);																							   
	    },'json');
}
	
	window.location="profile-view.php?employ_id="+emp_id;
	
	
}

function addEmployeeDetails(){ 
	
	var dob		= $('#dob1').html();
	var gender 	= $('#gen').html();
	var email 	= $('#eml').html();
	var phone		= $('#phn').html();
	var dt_join 	= $('#history_dt_join').html();
	var dtjoin 	= $('#dt_join').html();
	var dt_rel 		= $('#dt_rel').html();
	var emp_name		= $('#emp_id').html();
	var bloodgrp 	= $('#blood_grp').html();
	var last_desig 	= $('#last_desig').html();
	var esidetails 	= $('#esi_details').html();
	var emp_num		= $('#emp_num').html();
	
	
	$('#histdt_join').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});		
	$('#dat_join').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});
	$('#emp_dob').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});
	$('#emp_date_rel').live('click',function(){
		 $(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
	});
	
	$("body").append('<div class="newEmployeeDetails" style="display:none; padding:25px;">'+
					 '<form class="newEmployeeDetailsForm"><table width="740" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td colspan="4" style="font-size:15px;font-weight:bold;background:#d80b5d;padding:5px 10px;color:#fff"><translate>Persoanal Details</translate></td>'+
						
					  '</tr>'+
					  '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>DOB</translate></td>'+
						'<td width="150"><input type="text" name="emp_dob" value="'+dob+'" id="emp_dob" class="emp_dob tabfield-1" /></td>'+
						'<td width="150"><translate>Gender</translate></td>'+
						'<td width="150"><input type="text" name="emp_gender" value="'+gender+'" id="emp_gender" class="emp_gender tabfield-1" /></td>'+
					  '</tr>'+
					   '<tr>'+
						'<td width="100"><translate>Email</translate></td>'+
						'<td width="150"><input type="text" name="emp_email" value="'+email+'" id="emp_email" class="emp_email tabfield-1" /></td>'+
						'<td width="150"><translate>Phone</translate></td>'+
						'<td width="150"><input type="text" name="emp_phn" value="'+phone+'" id="emp_phn" class="emp_phn tabfield-1" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Employee ID</translate></td>'+
						'<td width="150"><input type="text" name="emp_ids" value="'+emp_name+'" id="emp_ids" class="emp_ids tabfield-1" /></td>'+
						'<td width="100"><translate>Date of Join</translate></td>'+
						'<td><input type="text" name="dat_join" value="'+dtjoin+'" id="dat_join" class="dat_join tabfield-1" /></td>'+
					  '</tr>'+
					
					  '<tr>'+
						'<td width="100"><translate>Blood Group</translate></td>'+
						'<td><input type="text" name="blood_grp" value="'+bloodgrp+'" id="blood_grp" class="blood_grp tabfield-1" /></td>'+
						'<td width="100"><translate>ESI details</translate></td>'+
						'<td><input type="text" name="esi_details" value="'+esidetails+'" id="esi_details" class="esi_details tabfield-1" /></td>'+
					  '</tr>'+
				
					 
					  '<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveEmployeeDetails"  class="color-button saveEmployeeDetails tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelEmployeeDetails tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');
	

	$('.newEmployeeDetails').show('fade',100);
	$('.newEmployeeDetails').center();
}


function saveEmployeeDetails(){
	//alert("hh");
	var dataString = $('.newEmployeeDetailsForm').serialize();
	
	$.post(serviceURLHR + "manageEmployees.php?action=updateDetails&empid="+emp_id,dataString,function(data){
		$('.newEmployeeDetails').hide('clip',300);																							   
	},'json');
	

	
	var emp_dob =$('.emp_dob').val();
	var emp_gender=$('.emp_gender').val();
	var emp_email =$('.emp_email').val();
	var emp_phn =$('.emp_phn').val();
	var emp_ids =$('.emp_ids').val();
	var histdt_join =$('.histdt_join').val();
	var dat_join =$('.dat_join').val();
	var emp_date_rel =$('.emp_date_rel').val();
	var blood_grp =$('.blood_grp').val();
	var last_desg =$('.last_desg').val();
	var esi_details =$('.esi_details').val();
	var emp_num =$('.emp_num').val();
	
	
	$('#dob1').html(emp_dob);
	$('#gen').html(emp_gender);
	$('#eml').html(emp_email);
	$('#phn').html(emp_phn);
	$('#history_dt_join').html(histdt_join);
	$('#dt_join').html(dat_join);
	$('#dt_rel').html(emp_date_rel);
	$('#emp_id').html(emp_ids);
	$('#blood_grp').html(blood_grp);
	$('#last_desig').html(last_desg);
	$('#esi_details').html(esi_details);
	$('#emp_num').html(emp_num);
	

		
}


function addWorkExperiance(){
	
	var emp_name 	= $('#emp').html();
	var address		= $('#address2').html();
	var phone 		= $('#phno').html();
	var email1		= $('#email1').html();
	var position	= $('#posi').html();
	var salary		= $('#sal').html();
	var workfrom	= $('#from').html();
	var workto		= $('#to').html();
	var reasontoleave= $('#rfl').html();
	$("body").append('<div class="newWorkExperiance" style="display:none;padding:25px;" >'+
					 '<form class="newWorkExperianceForm"><table width="800" height="200" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td width="200"><translate>Company Name</translate></td>'+
						'<td width="200"><input type="text" name="companyName" value="'+emp_name+'" id="companyName" class="companyName" /></td>'+
						'<td width="200"><translate>Address</translate></td>'+
						'<td width="200"><input type="text" name="companyAddress" value="'+address+'" id="companyAddress" class="companyAddress" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Phone</translate></td>'+
						'<td><input type="text" name="companyPhone" value="'+phone+'" id="companyAddress" class="companyPhone" /></td>'+
						'<td><translate>E-mail</translate></td>'+
						'<td><input type="text" name="companyEmail" value="'+email1+'" id="companyEmail" class="companyEmail" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Position</translate></td>'+
						'<td><input type="text" name="companyPosition" value="'+position+'" id="companyPosition" class="companyPosition" /></td>'+
						'<td><translate>Salary</translate></td>'+
						'<td><input type="text" name="companySalary" value="'+salary+'" id="companySalary" class="companySalary" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Work From</translate></td>'+
						'<td><input type="text" name="workFrom" value="'+workfrom+'" id="workFrom" class="my_date" /></td>'+
						'<td><translate>Work To</translate></td>'+
						'<td><input type="text" name="workTo" value="'+workto+'" id="workTo" class="my_date" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Reason To Leave</translate></td>'+
						'<td><input type="text" name="reasontoLeave" value="'+reasontoleave+'" id="reasontoLeave" class="reasontoLeave" /></td>'+
						'<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
					  '</tr>'+

					  '<tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveWorkExperiance"  class="color-button saveWorkExperiance" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelWorkExperiance" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newWorkExperiance').show('fade',300);
	$('.newWorkExperiance').center();
}


function saveWorkExperiance(){
	
	var dataString = $('.newWorkExperianceForm').serialize();
	
	$.post(serviceURLHR + "manageEmployees.php?action=newexperiance&empid="+emp_id,dataString,function(data){
		$('.newWorkExperiance').hide('clip',300);																							   
	},'json');
	
	var companyName =$('.companyName').val();
	var companyAddress=$('.companyAddress').val();
	var companyPhone =$('.companyPhone').val();
	var companyEmail =$('.companyEmail').val();
	var companyPosition =$('.companyPosition').val();
	var companySalary =$('.companySalary').val();
	var workFrom =$('#workFrom').val();
	var workTo =$('#workTo').val();
	var reasontoLeave =$('.reasontoLeave').val();
	
	
	
	$('#emp').html(companyName);
	$('#address2').html(companyAddress);
	$('#phno').html(companyPhone);
	$('#email1').html(companyEmail);
	$('#posi').html(companyPosition);
	$('#sal').html(companySalary);
	$('#from').html(workFrom);
	$('#to').html(workTo);
	$('#rfl').html(reasontoLeave);
	
	
}







/////////////////////// Load Leave types list to select box //////////////////////////////////////
jQuery.fn.loadLeaves = function getLeaveList(){
	$this =this;
	var employeeid = emp_id;
	$.getJSON(	serviceURLHR +"manageLeaves.php?act=getLeaves&emp_id="+employeeid,function(data){
		var leaves = data.leaves;
		$.each(leaves,function(index,leaves){
			$this.append('<option value='+leaves.lid+'>'+leaves.title+'</option>');
		});
	});
}


///////////////////////////////////////// Common functions /////////////////////////////////////////////////////
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
jQuery.fn.center = function(parent) {
    if (parent) {
        parent = this.parent();
    } else {
        parent = window;
    }
    this.css({
        "position": "absolute",
        "top": ((($(parent).height() - this.outerHeight()) / 2) + $(parent).scrollTop() + "px"),
        "left": ((($(parent).width() - this.outerWidth()) / 2) + $(parent).scrollLeft() + "px")
    });
return 
}


/*function vieweducation(){ 
	var ed	= '<div class="viewbasicdetails" style="display:none;padding:25px;"><table id="view_edu" width="100%">'+
			  '<tr><td><h3>Education</h3></td></tr>'+
			  '</table></div>'; 
	$("body").append(ed);
	$.getJSON(serviceURLHR+'branch.php?employ_id='+emp_id+'&action=edu',function(data){
				$('#view_edu').append('<tr>'+
							'<td width="100" class="td-bg-style-1">Qualification:</td>'+
							'<td width="100" class="td-bg-style-1">Specialization:</td>'+
							'<td width="100" class="td-bg-style-1">University:</td>'+
							'<td width="100" class="td-bg-style-1">Year: </td>'+
							'<td width="100" class="td-bg-style-1">Percentage: </td>'+
							'</tr>');						
			   edulist = data.educ; 
			   $.each(edulist, function(index, edulist) 
				{
					
					$('#view_edu').append(
						    '<tr>'+
							'<td width="200">'+edulist.course+'</td>'+
							'<td>'+edulist.spl+'</td>'+
							'<td>'+edulist.unv+'</td>'+
							'<td>'+edulist.yr+'</td>'+
							'<td>'+edulist.pcntg+'</td>'+
						    '</tr>');
					
				});
			   $('#view_edu').append('<tr>'+
					'<td colspan="5"><input type="button" name="button" class="color-button2 cancelView" style="float:left;" value="Close"  align="right" /></td>'+
				  '</tr>');
		});	

		$('.viewbasicdetails').show('fade',300);
		$('.viewbasicdetails').center();
		return false;
}*/
vieweducation();
function vieweducation(){ 
	
	$.getJSON(serviceURLHR+'branch.php?employ_id='+emp_id+'&action=edu',function(data){
										
			   edulist = data.educ; 
			   $.each(edulist, function(index, edulist) 
				{
					
					$('#view_edu').append(
						    '<tr>'+
							'<td width="200">'+edulist.course+'</td>'+
							'<td>'+edulist.spl+'</td>'+
							'<td>'+edulist.unv+'</td>'+
							'<td>'+edulist.yr+'</td>'+
							'<td>'+edulist.pcntg+'</td>'+
						    '</tr>');
					
				});
			   
		});	

		
		return false;
}
viewworkexperience()
function viewworkexperience(){ 
	
	$.getJSON(serviceURLHR+'branch.php?employ_id='+emp_id+'&action=exp',function(data){
			 						
			   explist = data.wk_exp; 
			   $.each(explist, function(index, explist) 
				{
					
					$('#view_wke').append(
						  	'<tr>'+
							'<td width="200">'+explist.refer+'</td>'+
							'<td>'+explist.emp+'</td>'+
							'<td>'+explist.phno+'</td>'+
							'<td style="text-transform: lowercase;">'+explist.email+'</td>'+
							'<td>'+explist.posi+'</td>'+
							'<td>'+explist.sal+'</td>'+
							'<td>'+explist.from+'</td>'+
							'<td>'+explist.to+'</td>'+
							'<td>'+explist.rfl+'</td>'+
						  '</tr>');
					
					
				});
			  
		});	
		
		return false;
}
/*function viewworkexperience(){ 
	var ed	= '<div class="viewbasicdetails" style="display:none;padding:25px;"><table id="view_wke">'+
			  '</table></div>'; 
	$("body").append(ed);
	$.getJSON(serviceURLHR+'branch.php?employ_id='+emp_id+'&action=exp',function(data){
			   $('#view_wke').append('<tr>'+
							'<td width="100" class="td-bg-style-1">Company Name:</td>'+
							'<td width="100" class="td-bg-style-1">Address:</td>'+
							'<td width="100" class="td-bg-style-1">Contact No:</td>'+
							'<td width="100" class="td-bg-style-1">Email: </td>'+
							'<td width="100"class="td-bg-style-1">Position: </td>'+
							'<td width="100" class="td-bg-style-1">Salary: </td>'+
							'<td width="100" class="td-bg-style-1">From: </td>'+
							'<td width="100" class="td-bg-style-1">To: </td>'+
							'<td width="100" class="td-bg-style-1">Reason To Leave : </td>'+
							'</tr>');						
			   explist = data.wk_exp; 
			   $.each(explist, function(index, explist) 
				{
					
					$('#view_wke').append(
						  	'<tr>'+
							'<td width="200">'+explist.refer+'</td>'+
							'<td>'+explist.emp+'</td>'+
							'<td>'+explist.phno+'</td>'+
							'<td>'+explist.email+'</td>'+
							'<td>'+explist.posi+'</td>'+
							'<td>'+explist.sal+'</td>'+
							'<td>'+explist.from+'</td>'+
							'<td>'+explist.to+'</td>'+
							'<td>'+explist.rfl+'</td>'+
						  '</tr>');
					
					
				});
			   $('#view_wke').append('<tr>'+
					'<td colspan="9"><input type="button" name="button" class="color-button2 cancelView" style="float:left;" value="Close" /></td>'+
				  '</tr>');
		});	
		
		$('.viewbasicdetails').show('fade',300);
		$('.viewbasicdetails').center();
		return false;
}*/

function changepassword(){

	
	$("body").append('<div class="newChangePassword" style="display:none;padding:25px;" >'+
					 '<form class="newchangepasswordForm"><table width="740" border="0" cellpadding="0" cellspacing="0">'+
					  '<tr>'+
						'<td colspan="4" style="font-size:15px;font-weight:bold;background:#d80b5d;padding:5px 10px;color:#fff"><translate>Change Password</translate></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>New password</translate></td>'+
						'<td><input type="password" name="new_pass" id="new_pass" class="phone_no tabfield-1" value="" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td>&nbsp;</td>'+
						'<td id="new_err" class="profile-font-10"></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td><translate>Confirm password</translate></td>'+
						'<td><input type="password" name="confirm_pass" id="confirm_pass" class="empuser_name tabfield-1" value="" /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td>&nbsp;</td>'+
						'<td id="conf_err" class="profile-font-10"></td>'+
					  '</tr>'+
					  '<tr>'+
					    '<td>&nbsp;</td>'+
						'<td><input type="button" name="button" id="savechangepassword"  class="color-button savechangepassword tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelchangepassword tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newChangePassword').show('fade',300);
	$('.newChangePassword').center();
}

function savechangepassword(){
	
		if ($.trim($("#new_pass").val()).length != 0) {
			$('#new_err').html('');
			if ($.trim($("#confirm_pass").val()).length != 0) {
				$('#conf_err').html('');
				if ($.trim($("#new_pass").val()) == $.trim($("#confirm_pass").val())){
					$('#conf_err').html('');
					var dataString = $('.newchangepasswordForm').serialize();
					$.post(serviceURLHR + "manageEmployees.php?action=change_password&empid="+emp_id,dataString,function(data){
						$('.newChangePassword').hide('clip',300);	
						alert('Password Successfully changed.');
					});
				}else
					$('#conf_err').html("Password do not match with confirm password.");
			}else
	 			 $('#conf_err').html("Please enter confirm password.");
		}else
	 		 $('#new_err').html("Please enter new password.");
	
}
	
	
	
	jQuery('#department').live('change',loadDesignation);
	
	



loadDesignation();

function loadDesignation(){
	var dept=$('#department').val(); 
	var mast=$('#depthidden').val(); 
    $('#chng_val').val(dept);

//alert(mast);alert(dept);


	if(dept)
	{
		var dept=dept;
	}
	else
	{
		var dept=0;
		
	} 
	$.getJSON(serviceURLHR + 'designations.php?action=load&dept='+dept,function(data){
		designation = data.designation;
		$("#designation").empty(); 
		if(!dept)
		{
			$('#designation').append('<option value="">Select Designation</option>');
		}
		$.each(designation, function(index, designation) {
									 
				$('#designation').append('<option value="'+designation.desig_id+'">'+designation.desig_name+'</option>');
							
		});	
		setTimeout(function(){ $('#designation').val(desigid); },100);
	});
}

function load_desigs(dept){
	//var dept=$('#department').val(); alert(depart);

var mast=$('#depthidden').val(); 
$('#chng_val').val(dept);

//alert(mast);alert(dept);


	if(dept)
	{
		var dept=dept;
	}
	else
	{
		var dept=0;
		
	} 
	$.getJSON(serviceURLHR + 'designations.php?action=load&dept='+dept,function(data){
		designation = data.designation;
		$("#designation").empty(); 
		if(!dept)
		{
			$('#designation').append('<option value="">Select Designation</option>');
		}
		$.each(designation, function(index, designation) {
									 
							$('#designation').append('<option value="'+designation.desig_id+'">'+designation.desig_name+'</option>');
							
		});	
	});
}
