var basicPATH =localStorage['basicPATH'];
var serviceURLHR =localStorage['serviceURLHR'];
var baseURL	= localStorage['serviceURL'];
var hrURL =localStorage['serviceURLHR'];

var itemCount =0;
var k=1;
var pageLimit = 15;
var state_selected;
var country_selected;
var language_selected;
var lang_index;
var uploadedDocuments;
var emplyee_id = getUrlVars()["employ_id"];

$(window).load(function(){
    $('#light-pagination').pagination({
        itemsOnPage: pageLimit,
        cssStyle: 'light-theme',
        onPageClick : recruitment_list
    });
});
 
$(function(){
	setTimeout(function(){ $('input').iCheck('destroy'); },500);
	viewEmployee();	
	eventHandler();
	getAllDocuments();
	$('#formintsch').attr('action',serviceURLHR + 'interview_schedule_insert.php');
});
setTimeout(loadDepartment,100);


function removeCurrentPage(){
	$('.paymentMethod').remove();
	$('#tablelist table').hide('blind',500,function(){ $(this).remove(); }) 
}
function eventHandler(){
jQuery('.searchPdt').live('click',function(){ productivity_list('1','') });
//jQuery('.searchRecuit').live('click',function(){ recruitment_list('1','') }); /// commented by subha

jQuery('.showdetaildoclist').live('click',productivity_detailshw);
jQuery('.showperformdoclist').live('click',performance_detailshw);
jQuery('.showperformremarkdoclist').live('click',performance_Remarkdetailshw);
//jQuery('.interview_schd').live('click',function(){ interview_schedule_list('1','') });
jQuery('.resume_List').live('click',resume_List);
jQuery('.interview_schd').live('click',interview_schd);
jQuery('.shortlist_form').live('click',shortlist_form);
jQuery('.selected_List_form').live('click',selected_List_form);
jQuery('.shrt_list').live('click',short_List);
jQuery('.sel_list').live('click',sel_List);
jQuery('#emp_contract').live('change',setContractPeriod);
//jQuery('.searchRecuitselect').live('click',function(){ selected_candiate_list('1','') });
//jQuery('.searchRecuitshortlist').live('click',function(){ shortlisted_list('1','') });
//jQuery('.searchRecuitinterview').live('click',function(){ interview_schedule_list('1','') });
}

function getAllDocuments(){
	$.getJSON(serviceURLHR + "getDocuments.php?action=getDocs&eid="+emplyee_id,function(data){
		var files = data.allfiles;
		uploadedDocuments= files;
		resume = files.resume[0].resume;
		fileid = files.resume[0].fid;
		console.log(uploadedDocuments);
		// Resume
		if(resume.length > 0){
			$('.file-resume').find('input').css('display','none').parent().append('<div><a href="upload/resume/'+resume+'">'+
																				  'Download File.</a> || '+
										'<a style="cursor:pointer" class="removeResume" data-file="'+resume+'" data-id="'+fileid+'">Remove File</a></div>');	
		}
		
		//ID Proof.
		
		var filetype =  files.idproof[0].proof_type;
		var file     = files.idproof[0].file;
		var rowid	 = files.idproof[0].idid; 
		
		
		if(filetype.length > 0){
			
			setTimeout(function(){
								
			switch(filetype){
				case "Drive": $('#drive').trigger('click');
							  $('#drfile').css('visibility','visible').prop('disabled', false);
						
				
								break;
				case "Passport":$('#passp').trigger('click');
								 $('#passfile').css('visibility','visible').prop('disabled', false);
								
				
								break;
				case "Govt":$('#govtrs').trigger('click');
							  $('#gvtfile').css('visibility','visible').prop('disabled', false);
							  
								break;
				case "Othr":$('#othr').trigger('click');
							  $('#othtxt').css('visibility','visible').prop('disabled', false);
							   
				
				
								break;
			}
			
			},300);
			
			
			//$('.file-resume').find('input').css('display','none').parent().append('<div><a href="upload/resume/'+resume+'">'+
													//							  'Download File.</a> || '+
								//		'<a style="cursor:pointer" class="removeResume" data-file="'+resume+'" data-id="'+fileid+'">Remove File</a></div>');	
		}
		
		
		
		
		
		

	});
}

$('.removeResume').live('click',removeResume);
$('.removeIdproof').live('click',removeIdproof);

function removeResume(){
	var $this = $(this);
	var fileid = $this.attr('data-id');
	var file  = $this.attr('data-file');
	var dataString = 'id='+fileid+'&filename='+file;
	$.post(serviceURLHR + "remove-files.php?action=resume",dataString,function(){
		$this.parent().remove();
		$('.file-resume').find('input').css('display','block');
	});
	
}
function removeIdproof(){
	var $this = $(this);
	var fileid = $this.attr('data-id');
	var file  = $this.attr('data-file');
	var dataString = 'id='+fileid+'&filename='+file;
	$.post(serviceURLHR + "remove-files.php?action=idproof",dataString,function(){
		$this.parent().parent().prev('input').css('visibility','visible');
		$this.parent().remove();
	});
}





function setContractPeriod(){
	$this = $(this);
	if($this.val() == "L"){
		$('.contractPeriod').css('display','block');	
	}else{
		$('.contractPeriod').css('display','none')
							.find('input').val('');	
	}
}

function resume_List(){
	window.location="recruitment-list.php";
}

function interview_schd(){
	window.location="interview-schedule-list.php";
}

//////////////////////////////////////////////////////////////Fill Answer//////////////////////////////////////////////////////////////////////////
function fnFillAnswer(emp_id){
	var datastring = $("#fill_qst1form").serialize();	
	$.post(serviceURLHR + "fill_qstns.php?action=fill_qstns&emp_id="+emp_id,datastring,function(data){   
		alert("Item successfully updated.");
		location.reload(true);
 	},'json');
}
//////////////////////////////////////////////////////////////Fill Answer//////////////////////////////////////////////////////////////////////////


function fnShortlisted(){
	var datastring = $("#frm_short").serialize();	
	var shtlist_id = $('#shtlist_id').val();
	$.post(serviceURLHR + "shortlist_insert.php?action=update&shtlist_id="+shtlist_id,datastring,function(data){   
		alert("Shortlisted candidate details successfully updated.");
		$('.performance-grid').hide('blind',300); 
		window.location="shortlisted-page-list.php";
		
 },'json');
}

function fninterviewSchdule(){ 
	var intv_name = $('#intv_name').val();
	var interv_gender = $('#interv_gender').val();
	var department = $('#department').val();
	var recdesg = $('#recdesg').val();
	var intv_qual = $('#intv_qual').val();
	var intv_email = $('#intv_email').val();
	var intv_phone = $('#intv_phone').val();
	var intv_locn = $('#intv_locn').val();
	var intv_schedule = $('#intv_schedule').val();
	var intv_resume = $('#intv_resume').val();
	
	if(intv_name == ''){
		alert('Name of the Candidate is required')	;$('#intv_name').focus();
	}else if(interv_gender == ''){
		alert('Gender is required')	;$('#interv_gender').focus();
	}else if(department == ''){
		alert('Department is required')	;$('#department').focus();
	}else if(recdesg == ''){
		alert('Designation is required')	;$('#recdesg').focus();
	}else if(intv_qual == ''){
		alert('Qualification is required')	;$('#intv_qual').focus();
	}else if(intv_email == ''){
		alert('Email is required')	;$('#intv_email').focus();
	}else if(intv_email != '' && !ValidateEmail(intv_email)){
		alert('Email is Invalid. Please try another')	;$('#intv_email').focus();
	}else if(intv_phone == ''){
		alert('Phone is required')	;$('#intv_phone').focus();
	}else if(intv_locn == ''){
		alert('Interview Location is required')	;$('#intv_locn').focus();
	}else if(intv_schedule == ''){
		alert('Interview Schedule is required')	;$('#intv_schedule').focus();
	}else if(intv_resume == ''){
		alert('Resume is required')	;$('#intv_resume').focus();
	}
	else{
		var file =  $('#intv_resume')[0].files[0];
		fileName = file.name;
		var fileExt = '.' + fileName.split('.').pop().toLowerCase();
		if($.inArray(fileExt, [".doc", ".docx", ".pdf" ,".zip","rar",".jpg",".jpeg",".png",".gif",".txt"]) == -1) {
		alert('This is not an allowed file type');
		}
		else {
		 $('#formintsch').submit();
		 		setTimeout(function(){  $('#formintsch').submit(); },100);
		}
	}
}
var Submiting = 0;

$('#formintsch').live('submit',function(){

		var progressbox     = $('.progressbox');
		var progressbar     = $('.progressbar');
		var statustxt       = $('.statustxt');
		var completed       = '0%';
		if(Submiting == 0){
			Submiting =1;
		$(this).ajaxForm({
			beforeSend: function() {
			//	console.log("beforeSend");
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			//	console.log(percentComplete);
			},
			success: function() {
				$("#formintsch")[0].reset()
				alert("Details successfully inserted.");
				window.location="interview-schedule-list.php";
				progressbox.hide(); 
			},
			complete: function() {
				console.log('done.');
			}
	
			});
		}
		return false; 
		//	return false;
	
});
function shortlist_form(){
	window.location="shortlisted-page-list.php";
}
editShortList();
function editShortList()
{ 

    
	
	var shtlist_id = getUrlVars()["shtlist_id"];
	$.getJSON(serviceURLHR+"shortlist_insert.php?action=get&shtlist_id="+shtlist_id,function(data){
		short_list = data.short_list;
		
		$.each(short_list, function(index, short_list) { 	
									
			  $('#sht_name').val(short_list.sht_name_cand);
			  $('#sht_intv_date').val(short_list.sht_intv_dt);
			  loadDepartmentSelected(short_list.sht_dept);
			  loadDesignationSelected(short_list.sht_desg);
			  $('#sht_loc').val(short_list.sht_loc);
			  $('#sht_qual').val(short_list.sht_qual);
			  $('#sht_exp').val(short_list.sht_exp);
			  $('#sht_exp_month').val(short_list.sht_exp_month);
			  $('#sht_cont_dt').val(short_list.sht_contdt);
			  $('#sht_curnt_sal').val(short_list.sht_curnt_sal);
			  $('#sht_exp_sal').val(short_list.sht_exp_sal);
			  $('#sht_notice_prd').val(short_list.sht_notice_prd);
			 // $('#sht_status').val(short_list.sht_status);
			  $('#sht_gender').val(short_list.sht_gender);
			  $('#sht_remark').val(short_list.sht_remarks);
			  $('#sht_email').val(short_list.sht_email);
			  $('#sht_phone').val(short_list.sht_phone);
			  $('#shtlist_id').val(short_list.shtlist_id);
		});	
	});
	
}

function fnShortlisted(){
	var sht_name = $('#sht_name').val();
	var sht_intv_date = $('#sht_intv_date').val();
	var sht_pos = $('#sht_pos').val();
	var sht_qual = $('#sht_qual').val();
	var sht_exp = $('#sht_exp').val();
	var sht_email = $('#sht_email').val();
	var sht_phone = $('#sht_phone').val();
	var sht_exp_sal = $('#sht_exp_sal').val();
	var sht_status = $('#sht_status').val();
	
	if(sht_name == ""){
		alert('Name of the Candidate is required');	$('#sht_name').focus();
	}else if(sht_intv_date == ""){
		alert(' Interviewed date is required');	$('#sht_intv_date').focus();
	}else if(sht_pos == ""){
		alert(' Position is required');	$('#sht_pos').focus();
	}else if(sht_qual == ""){
		alert('Qualification is required');	$('#sht_qual').focus();
	}else if(sht_exp == ""){
		alert(' Experience is required');	$('#sht_exp').focus();
	}else if(sht_email == ""){
		alert('Email is required');	$('#sht_email').focus();
	}else if(sht_email != '' && !ValidateEmail(sht_email)){
		alert('Email is Invalid. Please try another');$('#sht_email').focus();
	}else if(sht_phone == ""){
		alert('Phone is required');	$('#sht_phone').focus();
	}else if(sht_exp_sal == ""){
		alert('Expected salary is required');$('#sht_exp_sal').focus();
	}else if(sht_status == ""){
		alert('Status is required');$('#sht_status').focus();
	}else{
		
		var datastring = $("#frm_short").serialize();	
		var shtlist_id = $('#shtlist_id').val();
		$.post(serviceURLHR + "shortlist_insert.php?action=update&shtlist_id="+shtlist_id,datastring,function(data){   
			alert("Details successfully updated.");
			$('.performance-grid').hide('blind',300); 
			window.location="shortlisted-page-list.php";			
		},'json');
		
	}
	
}

function selected_List_form(){
	window.location="selected-page-list.php";
}
editSelectedList();
function editSelectedList(){ 
	var sel_id = getUrlVars()["sel_id"];
	$.getJSON(serviceURLHR+"selectedlist_insert.php?action=get&sel_id="+sel_id,function(data){
		select_list = data.select_list;
		$.each(select_list, function(index, select_list) { 			 
			  $('#sel_name').val(select_list.sel_name_cand);
			  $('#sel_gender').val(select_list.sel_gender);
			  loadDepartmentSelected(select_list.sel_dept);
			  loadDesignationSelected(select_list.sel_desg);
			  $('#sel_loc').val(select_list.sel_loc);
			  /*$('#sel_salary').val(select_list.sel_sal);
			  $('#sel_doj').val(select_list.sel_doj);
			  $('#sel_prb_prd').val(select_list.sel_prb_prd);*/
			  $('#sel_email').val(select_list.sel_email);
			  $('#sel_phone').val(select_list.sel_phone);
			  $('#sel_id').val(select_list.sel_id);
		});	
	});
}

function fnSelectedlisted(){

	var sel_name = $('#sel_name').val();
	var sel_desg = $('#sel_desg').val();
	var sel_email = $('#sel_email').val();
	var sel_phone = $('#sel_phone').val();
	
	if(sel_name == ""){
		alert('Name of the Candidate is required');	$('#sel_name').focus();
	}else if(sel_desg == ""){
		alert('Designation is required'); $('#sel_desg').focus();	
	}else if(sel_email == ""){
		alert('Email is required');	 $('#sel_email').focus();
	}else if(sel_email != '' && !ValidateEmail(sel_email)){
		alert('Email is Invalid. Please try another');$('#sel_email').focus();
	}else if(sel_phone == ""){
		alert('Phone is required');	 $('#sel_phone').focus();
	}else{
		var datastring = $("#frm_select").serialize();	
		var sel_id 	   = $('#sel_id').val();
		$.post(serviceURLHR + "selectedlist_insert.php?action=update&sel_id="+sel_id,datastring,function(data){   
			alert("Selected candidate details successfully updated.");
			$('.performance-grid').hide('blind',300);
			window.location="selected-page-list.php";
		},'json');
	}
}

$('.edit_form_date').live('click',function(){
		 $(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();	
});

function productivity_detailshw(){
	$this = $(this);
	$('.productivity-grid').hide("blind",300,function(){ $(this).remove() });
	//alert($this);
	$currentRow = $this.parent();
	//alert($currentRow);
	console.log($currentRow);
	var did = $(this).attr('data-id');
	
	if($('.Grid_'+did).length){
		
	}else{
	
	$currentRow.after('<div class="testdiv" style="display:none"><table width="100%" border="0" cellspacing="0" class="productivity-grid Grid_'+did+'" cellpadding="0">'+
					  '<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Document No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Wt Carried</translate></td>'+
					  '</tr>'+
					  '</table></div>');
	
	$.getJSON(serviceURLHR+"getproductivity_details.php?prd_id="+did,function(data){
		imdsupervisor = data.getproductivitydts;
		var k = 1;
		$.each(imdsupervisor, function(index, imdsupervisor) {
									 
				    	$('.Grid_'+did).append('<tr>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+ k + '</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">'+imdsupervisor.prd_docno+'</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">'+imdsupervisor.prd_wt_carry+'</td>'+
					  '</tr>');
			k++;				
		});		
		$('.testdiv').show('blind',300);
	});
	}
	
}

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

loadattributevalues();
function loadattributevalues(){
	$.getJSON(serviceURLHR + 'immediateperformancesupervisor.php?action=load_attribute',function(data){
		imdsupervisor = data.attribute;
		$.each(imdsupervisor, function(index, imdsupervisor) {
			$('#attributetype').append('<option value="'+imdsupervisor.perfom_attr_id+'">'+imdsupervisor.attributes	+'</option>');
		});	
	});
}

loadperformanceimediatesupervisor();
function loadperformanceimediatesupervisor(){
	//alert('rrrr');
	$.getJSON(serviceURLHR + 'immediateperformancesupervisor.php?action=load',function(data){
		imdsupervisor = data.imdsupervisor;
		$.each(imdsupervisor, function(index, imdsupervisor) {
									 
							$('#imdateperformancesupervisor').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');
							
		});	
	});
}

//////////////////////////////////////////////////////////////Profile//////////////////////////////////////////////////////////////////////////

function interview_schedule_list(pageno,e,p){
	//alert(p);	
		if(p=='Y' || p=='A')
{
		 var searchString = $('.interviewSearchForm').serialize(); 
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		
		$.getJSON(serviceURLHR+"getinterview_schedule.php?page="+pageno+"&"+searchString,function(data){
																						   
						
				
						
						
					$('.recruitmentGrid').html('');						
				   profile = data.getinterview;

				   
					
					$('.recruitmentGrid').append('<table width="120%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><input type="checkbox" name"sel_al_sht"></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Interview Schedule</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Candidate</translate></td>'+
					/*  '<td align="center" valign="middle" class="employee-row-01"><translate>Status</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Designation</translate></td>'+
					  /*'<td align="center" valign="middle" class="employee-row-01"><translate>Location</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Qualification</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Experience</translate></td>'+
					  /*'<td align="center" valign="middle" class="employee-row-01"><translate>Contact Details</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Emai</translate></td>'+ */
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Phone</translate></td>'+ 
					  /*'<td align="center" valign="middle" class="employee-row-01"><translate>Interview Location</translate></td>'+ */
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Remarks</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01" colspan="2">Resume</translate></td>'+
					  '</tr></table>');
			
					$.each(profile, function(index, profile) 
					{
						 
						 if(profile.totalrows==0){
								 $('.Grid').append('<tr class="catmenuitems">'+
								'<td align="center" scope="col" colspan="10" >No records found</td>'+
								 '</tr>');
						} else {
						 
						 
							 if(profile.interv_exp !="")
							   var exp_yr =  profile.interv_exp +"Y";
							 else 
								 var exp_yr ="";
							 if(profile.interv_exp_month!=0)
							   var exp_mn =  profile.interv_exp_month +"M";
							 else
							   var exp_mn ="";
							
							if(profile.intv_resume!=""){
								var resume_view = '<a  href="upload/resume/'+profile.intv_resume +'" title="'+profile.intv_resume +'" style="height:5px,width:5px" class="pro-icon-02"  target="_blank">View</a>';
								
								var resume_download = '<a  href="'+serviceURLHR+'download_resume.php?filename='+profile.intv_resume +'" title="'+profile.intv_resume +'" style="height:5px,width:5px" class="pro-icon-02"><img src="'+baseURL+'images/download.png"  target="_blank"></a>';
							}
							else {
								var resume_view = '';
								var resume_download = '';
							}
							
							$('.Grid').append('<tr class="catmenuitems">'+
								  '<td align="center" valign="middle"><input type="checkbox" name="sel_sht[]" value="'+profile.interv_id+'"></td>'+		  
								  '<td align="center" scope="col" >'+ k + '</td>'+
								  '<td align="center" scope="col" >'+ profile.int_date + '</td>'+
								  '<td align="center" scope="col" >'+ profile.name_cand+ '</td>'+
								  /*'<td align="center" scope="col" >'+ profile.interv_status + '</td>'+*/
								  '<td align="center" scope="col" >'+profile.desig_name+ '</td>'+
								 /* '<td align="center" scope="col" >'+profile.interv_loc+ '</td>'+*/
								  '<td align="center" scope="col" >'+profile.interv_qual+ '</td>'+
								  '<td align="center" scope="col" >'+ exp_yr+ " "+exp_mn + '</td>'+
								  /*'<td align="center" scope="col" >'+ profile.interv_contdt + '</td>'+*/
								 /* '<td align="center" scope="col" >'+ profile.intv_email + '</td>'+*/
								  '<td align="center" scope="col" >'+ profile.intv_phone + '</td>'+
							/*	  '<td align="center" scope="col" >'+ profile.interv_location + '</td>'+*/
								  '<td align="center" scope="col" >'+ profile.interv_remark + '</td>'+
								  '<td align="center" scope="col" >'+resume_view+'</td>'+
								  '<td align="center" scope="col" >'+resume_download+'</td>'+
								  '</tr>');	
							
						itemCount = profile.totalrows;
											
						k++;
						}
					});	//'</tbody></table>';
					  $('#light-pagination').pagination( 'updateItems',itemCount );
					  
					 // $('#light-pagination').pagination( 'selectPage', 3 );


	       });
		
}/////if end for permission chechk////////////
else
{
	$('.recruitmentGrid').html('<font color="Red" size="4">Sorry, You Do Not Have Enough Permission To View This Form...</font>')
} ///
	  
	
}

function shortlisted_list(pageno,e,p){
	
	if(p=='Y' || p=='A')
    {
	
		 var searchString = $('.shortlistSearchForm').serialize(); 
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		
		$.getJSON(serviceURLHR+"getshortlisted.php?page="+pageno+"&"+searchString,function(data){
																						   
																		    
					$('.recruitmentGrid').html('');						
				   profile = data.getshortlist;
				   
			 permissions_user = profile[profile.length -1 ].permissions[0].user_id; 
			if(permissions_user!=1)
			{
	  
			permissions_edit = profile[profile.length -1 ].permissions[0].edit_right; 
			permissions_del = profile[profile.length -1 ].permissions[0].delete_right;
			permissions_add = profile[profile.length -1 ].permissions[0].add_right;
			  
			}
				   
					
					$('.recruitmentGrid').append('<table width="120%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><input type="checkbox" name"sel_al"></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Interviewed date</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Candidate</translate></td>'+
					 /* '<td align="center" valign="middle" class="employee-row-01"><translate>Status</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Designation</translate></td>'+
					 /* '<td align="center" valign="middle" class="employee-row-01"><translate>Location</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Qualification</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Exp</translate></td>'+
					 /* '<td align="center" valign="middle" class="employee-row-01"><translate>Contact Details</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Email</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Phone</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>CTC</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>ETC</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Notice period</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Remarks</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01" colspan="2"><translate>Resume</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Edit</td>'+
					  '</tr></table>');
			
					$.each(profile, function(index, profile) 
					{
						 if(profile.totalrows==0){
								 $('.Grid').append('<tr class="catmenuitems">'+
								'<td align="center" scope="col" colspan="15" >No records found</td>'+
								 '</tr>');
						} else {
						 
							 if(profile.sht_exp !="")
							   var exp_yr =  profile.sht_exp +"Y";
							 else 
								 var exp_yr ="";
							 if(profile.sht_exp_month!=0)
							   var exp_mn =  profile.sht_exp_month +"M";
							 else
							   var exp_mn ="";
							
							if(profile.sht_resume!=""){
								var resume_view = '<a  href="upload/resume/'+profile.sht_resume +'" title="'+profile.sht_resume +'" style="height:5px,width:5px" class="pro-icon-02" target="_blank">View</a>';
								
								var resume_download = '<a  href="'+serviceURLHR+'download_resume.php?filename='+profile.sht_resume +'" title="'+profile.sht_resume +'" style="height:5px,width:5px" class="pro-icon-02" target="_blank"><img src="'+baseURL+'images/download.png"></a>';
							}
							else {
								var resume_view = '';
								var resume_download = '';
							}
							
								
							$('.Grid').append('<tr class="catmenuitems">'+
								  '<td align="center" valign="middle"><input type="checkbox" name="selected_list[]" value="'+profile.shtlist_id+'"></td>'+				  
								  '<td align="center" scope="col" >'+ k + '</td>'+
								  '<td align="center" scope="col" style=" width:150px;">'+ profile.sht_date+ '</td>'+
								  '<td align="center" scope="col" >'+profile.sht_name_cand+ '</td>'+
								 /* '<td align="center" scope="col" >'+ profile.sht_status + '</td>'+*/
								  '<td align="center" scope="col" >'+profile.desig_name+ '</td>'+
								 /* '<td align="center" scope="col" >'+profile.sht_loc+ '</td>'+*/
								  '<td align="center" scope="col" >'+ profile.sht_qual + '</td>'+
								  '<td align="center" scope="col" >'+ exp_yr+ " "+exp_mn +  '</td>'+
								  /*'<td align="center" scope="col" >'+ profile.sht_contdt + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sht_email + '</td>'+*/
								  '<td align="center" scope="col" >'+ profile.sht_phone + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sht_curnt_sal+ '</td>'+
								  '<td align="center" scope="col" >'+ profile.sht_exp_sal + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sht_notice_prd + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sht_remarks + '</td>'+
								  '<td align="center" scope="col" >'+resume_view+'</td>'+
								  '<td align="center" scope="col" >'+resume_download+'</td>'+
								  '<td align="center" scope="col" class="edit_remv"><a href="shortlisted-page.php?shtlist_id='+ profile.shtlist_id+ '" ><img class="eimgs" src="'+baseURL+'images/pen.png"></a></td>'+
								  '</tr>');	
							      /*  if(permissions_edit==0)
			         {
			         $('.edit_remv a').removeAttr("href");
					 $('.eimgs').remove();
					 }*/
						itemCount = profile.totalrows;
											
						k++;
						}
					});	//'</tbody></table>';
					  $('#light-pagination').pagination( 'updateItems',itemCount );
					  
					 // $('#light-pagination').pagination( 'selectPage', 3 );


	       });
		
	}/////if end for permission chechk////////////
else
{
	$('.recruitmentGrid').html('<font color="Red" size="4">Sorry, You Do Not Have Enough Permission To View This Form...</font>')
} /////else end for permission chechk////////////
	  
	
}

function selected_candiate_list(pageno,e,p){

		 //var searchString = $('.recuitselectSearchForm').serialize(); 
		 if(p=='Y' || p=='A')
         {
		 
		 var searchString ="";
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 
		$.getJSON(serviceURLHR+"getselectedlisted.php?page="+pageno+"&"+searchString,function(data){
					$('.recruitmentGrid').html('');						
				   profile    = data.getselectedlist;

			permissions_user = profile[profile.length -1].permissions[0].user_id; 

			if(permissions_user!=1)
			{
			permissions_edit = profile[profile.length -1].permissions[0].edit_right; 
			permissions_del = profile[profile.length -1].permissions[0].delete_right;
			permissions_add = profile[profile.length -1].permissions[0].add_right;
			}			   

					$('.recruitmentGrid').append('<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Candidate</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Designation</translate></td>'+
					 /* '<td align="center" valign="middle" class="employee-row-01"><translate>Location</translate></td>'+
					   '<td align="center" valign="middle" class="employee-row-01"><translate>Email</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Phone</translate></td>'+
				/*	  '<td align="center" valign="middle" class="employee-row-01"><translate>Salary</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Date of Join</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Probation Period</translate></td>'+*/
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Edit</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"></td>'+
					  '</tr></table>');
			
					$.each(profile, function(index, profile) 
					{
				
						
						if(profile.totalrows==0){
								 $('.Grid').append('<tr class="catmenuitems">'+
								'<td align="center" scope="col" colspan="6" >No records found</td>'+
								 '</tr>');
						} else {
						
							/*if(profile.sel_status=="Employee joined"){
								var status = "Employee joined";
							} else {
								var status = '<a href="#" onclick="selected_candidate_status_change('+profile.sel_id+');">Add Employee</a>';
							}*/
							
							var status = '<a href="create-person.php?sel_id='+profile.sel_id+'" >Add Employee</a>';
							$('.Grid').append('<tr class="catmenuitems">'+
								  '<td align="center" scope="col" >'+ k + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sel_name_cand+ '</td>'+
								  '<td align="center" scope="col" >'+profile.desig_name+ '</td>'+
								/*  '<td align="center" scope="col" >'+profile.sel_loc+ '</td>'+
								  '<td align="center" scope="col" >'+profile.sel_email+ '</td>'+*/
								  '<td align="center" scope="col" >'+profile.sel_phone+ '</td>'+
								/*  '<td align="center" scope="col" >'+profile.sel_sal+ '</td>'+
								  '<td align="center" scope="col" >'+ profile.sel_date + '</td>'+
								  '<td align="center" scope="col" >'+ profile.sel_prb_prd + '</td>'+*/
	'<td align="center" scope="col"  class="edit_remv"><a href="selected-page.php?sel_id='+ profile.sel_id+ '"><img src="'+baseURL+'images/pen.png" class="eimgs"></a></td>'+
								  '<td align="center" scope="col" id="sel_emp">'+status+'</td>'+
								  '</tr>');	
							
							itemCount = profile.totalrows;
							
				/*	 if(permissions_edit==0)
			         {
			         $('.edit_remv a').removeAttr("href");
					 $('.eimgs').remove();
					 }
							*/
							k++;
						}
					});	//'</tbody></table>';
					  $('#light-pagination').pagination( 'updateItems',itemCount );
					  
					 // $('#light-pagination').pagination( 'selectPage', 3 );


	       });
}///////////////////if end for privillege/////////////////////
else
{
	$('.recruitmentGrid').html('<font color="Red" size="4">Sorry, You Do Not Have Enough Permission To View This Form...</font>');
} 
	  
	
}
function selected_candidate_status_change(sel_id){
	window.location="create-person.php";
	 $.ajax({
        url: serviceURLHR + 'recruitment.php?action=update_sel_list&sel_id='+sel_id,  //Server script to process data
        type: 'POST',
		success: function(data){
			
			window.location="create-person.php";
		
		}
	});	
}

function recruitment_list(pageno,e,p){
	

if(p=='Y' || p=='A')
{


		 var searchString = $('.recuitSearchForm').serialize(); 
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 
		$.getJSON(serviceURLHR+"getrecruitment.php?page="+pageno+"&"+searchString,function(data){
					$('.recruitmentGrid').html('');						
				   profile = data.getrecruitment;
					
					$('.recruitmentGrid').append('<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td width="3%" align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td width="10%" align="center" valign="middle" class="employee-row-01"><translate>Date</translate></td>'+
					  '<td width="20%" align="center" valign="middle" class="employee-row-01"><translate>Source</translate></td>'+
					  '<td width="10%" align="center" valign="middle" class="employee-row-01"><translate>No of Resumes</translate></td>'+
					  /*  '<td width="12%" align="center" valign="middle" class="employee-row-01" style="width:5%;">No of Candidate Attend the interview</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Selected Candidate</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Cost</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Cost Ratio</td>'+*/
					  '<td width="28%" align="center" valign="middle" class="employee-row-01"><translate>Department</translate></td>'+
					  '<td width="25%" align="center" valign="middle" class="employee-row-01"><translate>Designation</translate></td>'+
					  '<td width="15%" align="center" valign="middle" class="employee-row-01"><translate>Download </translate></td>'+
					  '</tr></table>');
			
					$.each(profile, function(index, profile) 
					{ 
						if(profile.resume!=null)
						{
						$('.Grid').append('<tr class="catmenuitems">'+
							  '<td align="center" scope="col" >'+ k + '</td>'+
							  '<td align="center" scope="col" >'+ moment(profile.rect_date).format("DD-MM-YYYY")/* new Date(profile.rect_date).format("dd-mm-yyyy")*/+ '</td>'+
							  '<td align="center" scope="col" >'+ profile.rect_source+ '</td>'+
							  '<td align="center" scope="col" >'+profile.rect_resume+ '</td>'+
							  /*'<td align="center" scope="col" >'+profile.rect_num_cand+ '</td>'+
							  '<td align="center" scope="col" >'+profile.rec_sel_cand+ '</td>'+
							  '<td align="center" scope="col" >'+ profile.rect_cost + '</td>'+
							  '<td align="center" scope="col" >'+ profile.rect_costratio + '</td>'+*/
							  '<td align="center" scope="col" >'+ profile.depart_name + '</td>'+
							  '<td align="center" scope="col" >'+ profile.desig_name + '</td>'+
							  '<td align="center" scope="col" ><a  href="'+serviceURLHR+'download_resume_zip.php?rect_id='+profile.rect_id+'" class="pro-icon-02"><img src="'+baseURL+'images/download.png"></a></td>'+
					  '</tr>');	
						}
						else{ 
							if(profile.totalrows==0){
								 $('.Grid').append('<tr class="catmenuitems">'+
								'<td align="center" scope="col" colspan="7" >No records found</td>'+
								 '</tr>');
							} else {
								 $('.Grid').append('<tr class="catmenuitems">'+
								  '<td align="center" scope="col" >'+ k + '</td>'+
								  '<td align="center" scope="col" >'+ new Date(profile.rect_date).format("dd-mm-yyyy")+ '</td>'+
								  '<td align="center" scope="col" >'+ profile.rect_source+ '</td>'+
								  '<td align="center" scope="col" >'+profile.rect_resume+ '</td>'+
								  /*'<td align="center" scope="col" >'+profile.rect_num_cand+ '</td>'+
								  '<td align="center" scope="col" >'+profile.rec_sel_cand+ '</td>'+
								  '<td align="center" scope="col" >'+ profile.rect_cost + '</td>'+
								  '<td align="center" scope="col" >'+ profile.rect_costratio + '</td>'+*/
								  '<td align="center" scope="col" >'+ profile.depart_name + '</td>'+
								  '<td align="center" scope="col" >'+ profile.desig_name + '</td>'+
								  '<td align="center" scope="col" ></td>'+
								  '</tr>');	
							}
						}
						itemCount = profile.totalrows;
								
						k++;
					});	//'</tbody></table>';
					  $('#light-pagination').pagination( 'updateItems',itemCount );
					  
					 // $('#light-pagination').pagination( 'selectPage', 3 );


	       });
	 
	 
}/////if end for permission chechk////////////
else
{
	$('.recruitmentGrid').html('<font color="Red" size="4">Sorry, You Do Not Have Enough Permission To View This Form...</font>')
} /////else end for permission chechk////////////
	 
	
}

function employee_list_delete(pageno,e){
		 var searchString = $('.recuitSearchForm').serialize(); 
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 
		$.getJSON(serviceURLHR+"getempoyeelist_delete.php?page="+pageno+"&"+searchString,function(data){
					$('.recruitmentGrid').html('');						
				   profile = data.getemp_delete;
					
					$('.recruitmentGrid').append('<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Employee name</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Branch</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Department</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Designation</translate></td>'+
					  '</tr></table>');
			
					$.each(profile, function(index, profile) 
					{
						$('.Grid').append('<tr class="catmenuitems">'+
							  '<td align="center" scope="col" >'+ k + '</td>'+
							  '<td align="center" scope="col" >'+ profile.e_fname+ '</td>'+
							  '<td align="center" scope="col" >'+ profile.branch_name+ '</td>'+
							  '<td align="center" scope="col" >'+ profile.depart_name+ '</td>'+
							  '<td align="center" scope="col" >'+ profile.desig_name+ '</td>'+
							 '</tr>');	
						
					itemCount = profile.totalrows;
										
					k++;
					});
				$('#light-pagination').pagination( 'updateItems',itemCount );
	       });
	  
	
}

	function productivity_list(pageno,e)
	  {
		  var searchString = $('.pdtSearchForm').serialize(); 
		 if(pageno == 1 ){
			k=1; 
		 }else{
			k= ((pageno-1) * pageLimit)+1;
		 }
		 var tot = 0;
		
																				
		 $.getJSON(serviceURLHR+"getproductivity.php?page="+pageno+"&"+searchString,function(data){
				   $('.productivityGrid').html('');						
				   profile = data.getproductivity;
					$('.productivityGrid').append('<div class="productivity_list">'+
												 '<ul class="productivity_ul">'+
												<!-- '<li class="employee-row-01" style="width=10px;">No</li>'+-->
												 '<li class="employee-row-01"><translate>Prd No</translate></li>'+
												 '<li class="employee-row-01"><translate>Date</translate></li>'+
												 '<li class="employee-row-01"><translate>Employee Name</translate></li>'+
												 '<li class="employee-row-01"><translate>Branch</translate></li>'+
												 '<li class="employee-row-01"><translate>View</translate></li>'+
												 '</ul>'+
												 '</div>');
					/*'<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01">No</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Date</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Employee Name</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Branch</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Wt Carried</td>'+
					  '</tr></table>');*/
				  
					$.each(profile, function(index, profile){ 
							tot = parseInt(tot)+parseInt(profile.prd_wt_carried);
						$('.productivity_list').append('<ul class="productivity_ul">'+
								<!--'<li class="employee-row-01" style="width=10px;">'+ k + '</li>'+-->
								'<li class="employee-row-01">'+ profile.prd_unique+ '</li>'+
								'<li class="employee-row-01">'+ new Date(profile.prd_date).format("dd-mm-yyyy")+ '</li>'+
								'<li class="employee-row-01">'+ profile.e_fname+ '</li>'+
								'<li class="employee-row-01">'+profile.branch_name+ '</li>'+
							    '<li class="employee-row-01 showdetaildoclist" data-id="'+profile.prd_id+'" >'+profile.prd_wt_totcarried+ '</li>'+
							'</ul>');	
					itemCount = profile.totalrows;
					//tot = tot+profile.prd_wt_carried;
					k++;
					});	//'</tbody></table>';
				/*	
					$('.productivity_list').append('<ul class="productivity_list">'+
							  '<td align="center" scope="col" style="width:15%;"></td>'+
							  '<td align="center" scope="col" style="width:15%;"></td>'+
							  '<td align="center" scope="col" style="width:15%;"></td>'+
							  '<td align="center" scope="col" style="width:15%;">Total</td>'+
							  '<td align="center" scope="col" style="width:20%;">'+tot+'</td>/tr>');	*/
					  $('#light-pagination').pagination( 'updateItems',itemCount );

	       });
	  
}




$('#prdaddate').live('click',function(){
		 //$(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
		  $(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();	
	});

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

$('#toaddate').live('click',function(){
		 //$(this).datepicker({dateFormat:"dd-mm-yy"}).focus();	
		  $(this).datepicker({
							dateFormat:"dd-mm-yy",
							yearRange: "1950:2020",
							changeMonth: true, 
							changeYear: true
							})
		 		.focus();	
	});

setTimeout(profile,200);

	function profile()
	  {
	
		$.getJSON(serviceURLHR+"profile.php",function(data){
											
				   profile = data.employee;
					
					$('.clear-float').append('<li class="catmenuitems">'+
					'<h1><center> Employee Report</center></h1>'+
					'<table class="Grid" cellspacing="0" cellpadding="6" id="dgOrder" style="border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;">'+
					'<tbody><tr class="GridHeader">'+
					'<th align="center" scope="col" style="width:15%;"><translate>Emp No.</translate></th>'+
					'<th align="center" scope="col" style="width:10%;"><translate>Name</translate></th>'+
					'<th align="center" scope="col" style="width:10%;"><translate>Address</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Mobileno</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Post</translate></th>'+
					
					'<th align="center" scope="col" style="width:10%;"><translate>Qualification</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Edit</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Delete</translate></th>'+
					'</tr>');
			
					$.each(profile, function(index, profile) {		   
										$('.Grid').append('<tr class="catmenuitems">'+
											  '<td align="center" scope="col" style="width:15%;">'+ profile.e_id + 
											  '</td><td align="center" scope="col" style="width:15%;">'+ profile.e_fname+'   ' + profile.e_lname +
											  '</td><td align="center" scope="col" style="width:15%;">'+profile.e_add+
											  '</td><td align="center" scope="col" style="width:20%;">'+profile.e_mob+
											  '</td><td align="center" scope="col" style="width:15%;">'+ profile.e_post + 
											 
											  '</td><td align="center" scope="col" style="width:15%;">'+ profile.e_course + 
											  '</td> </tr>');	
					});	'</tbody></table>';
				
				

	
	       });
}




//////////////////////////////////////////////////////////////End Of Profile///////////////////////////////////////////////////////////////////


 //////////////////////////////////////////////////////Employee insertion///////////////////////////////////////////////////////////////



$('#register').live('click',insert);
function insert(){
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'insert.php',  //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){
				alert("Item successfully inserted.");
		}
	});	
}

 //////////////////////////////////////////////////////Employee Listing///////////////////////////////////////////////////////////////
 setTimeout(listEmployees,250);

	function listEmployees()
	  {
	
		$.getJSON(serviceURLHR+"list.php",function(data){
											
				   employeeslist = data.employee;
					
					$('.profile').append('<li class="catmenuitems">'+
					'<h1><center> Employee Report</center></h1>'+
					'<table class="Grid" cellspacing="0" cellpadding="6" id="dgOrder" style="border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;">'+
					'<tbody><tr class="GridHeader">'+
					'<th align="center" scope="col" style="width:15%;"><translate>Emp No.</translate></th>'+
					'<th align="center" scope="col" style="width:10%;"><translate>Name</translate></th>'+
					'<th align="center" scope="col" style="width:10%;"><translate>Address</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Mobileno</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Post</translate></th>'+
					'<th align="center" scope="col" style="width:10%;"><translate>Qualification</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Edit</translate></th>'+
					'<th align="center" scope="col" style="width:15%;"><translate>Delete</translate></th>'+
					'</tr>');
			
					$.each(employeeslist, function(index, employeeslist) {
						$('.Grid').append('<tr class="catmenuitems">'+
								'<td align="center" scope="col" style="width:15%;">'+ employeeslist.e_id + 
								'</td><td align="center" scope="col" style="width:15%;">'+ employeeslist.e_fname+'   ' + employeeslist.e_lname +
								'</td><td align="center" scope="col" style="width:15%;">'+employeeslist.e_add+
								'</td><td align="center" scope="col" style="width:20%;">'+employeeslist.e_mob+
								'</td><td align="center" scope="col" style="width:15%;">'+ employeeslist.e_post + 
								'</td><td align="center" scope="col" style="width:15%;">'+ employeeslist.e_course + 
								'</td><td align="center" scope="col" style="width:10%;"><a class="findurl" href="edit.html?employ_id='+employeeslist.e_id+
								'" data-link="'+ employeeslist.e_id + '"><img src="images/edit.png" alt="Edit" title="Edit"  border="0" />'+
								'</a></td><td align="left" scope="col" style="width:10%;"><a class="findurl" href="#" id="delete" data-link="'+ employeeslist.e_id +
								'"><img src="images/imagees.jpg" alt="Delete" title="Delete"  border="0" /></a></td> </tr>');	
					});	'</tbody></table>';
				
				

	
	       });
}// '</td><td align="left" scope="col" style="width:15%;"><img src="'+serviceURL+'upload/thumb/'+ employeeslist.photo+'"/>'+
$(document).ready(function()
{ 
	$('#delete').live('click',function(){
		var employ=confirm("Do you want to delete the Employee.....!!!")
		  $data=$(this).attr('data-link');
if (employ==true)
  {
	$(this).parent().parent().remove();	
 	$.post(serviceURLHR+'list.php?employee_id='+$data,function(o){

															});
  }
		
	});
});

//////////////////////////////////////////////////////Addmore Language(insert page)/////////////////////////////////////////////////////////////// 

//////////////////////////////////////////////////////Addmore Language(Edit page)/////////////////////////////////////////////////////////////// 

$(function() {
	//var k=0;
var addDiv = $('#radiodiv1');
var i = $('#radiodiv1 p').size() + 1;
$('#radio1').live('click', function() {
	
	
$('<p><td align="left" valign="middle"><span id="lblLName"><td align="left" valign="middle"><span id="lblFName">Level</span></td><td align="left" valign="middle">:</td><td align="left" valign="middle">'+
'<span id="lblLName"><select name="level1[]" id="level1"><option selected="selected">---select---</option><option>Poor</option><option>Average</option>'+
'<option>Good</option></select></span></td></tr><a href="#" id="radio1"><img src="images/icon-add.png" width="20" height="15" title="Add More" /></a></br><a href="#" id="nouse">Remove</a></span></td></p>').appendTo(addDiv);i++;// k++;
return false;
}

);
$('#nouse').live('click', function() 
{
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);

//////////////////////////////////////////////////////Addmore Language(Edit page)Upa/////////////////////////////////////////////////////////////// 

$('#language').live('click',function(msg){
	getlanguage();
});

function getlanguage(){
		$.getJSON(serviceURLHR+'get.php?em_id='+id,function(data){
				   employeeslist = data.employee2;
					$.each(employeeslist, function(index, employeeslist) {
						$('#spot').append('<table id="reference'+employeeslist.lan_id+'" class="catmenuitems">'+
	         				 '<p><td align="left" valign="middle"><span id="lblLName"><input type="text" name="other" id="other" value="'+employeeslist.e_lang+'"><td align="left" valign="middle"><span id="lblFName">Level</span></td><td align="left" valign="middle">:</td><td align="left" valign="middle">'+
'<span id="lblLName"><select name="level1" id="level1"><option selected="selected">'+employeeslist.e_level+'</option><option>Poor</option><option>Average</option>'+
'<option>Good</option></select><input type="button" name="up" id="insert1" data-id="'+employeeslist.lan_id+'" class="pushup" value="Save" align="middle" /></a></br> <input type="button" name="dels" id="noneed" data-id="'+employeeslist.lan_id+'" class="pushdel" value="Delete" align="middle" /></span></td></p></table>');	
				});	
				
				

	
	       });
}
$('#noneed').live('click',function(msg){
	$(this).parent().parent().parent().remove();
	var eidd= $(this).attr('data-id');
	Delete2(eidd);
});
function Delete2(eidd){
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'edit.php?delll_id='+eidd,  //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){

		}
	});	
}

$('#insert1').live('click',function(msg){
	var eid= $(this).attr('data-id');
	
	updatelanguage(eid);
});
function updatelanguage(eid){
	
	
	var currentRef = $('#reference'+eid);
	
	var other = currentRef.find('#other').val();
	var level1 = currentRef.find('#level1').val();

   $.ajax({
  type: "POST",
  url: 'edit.php?upd_id='+eid,
  data: { other: other,level1:level1 }
	})
  .done(function( msg ) {
    alert( "Data Saved: " );
  });


}

//////////////////////////////////////////////////////Validation(insert page)/////////////////////////////////////////////////////////////// 




function ValidateEmail(email) {
        var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return expr.test(email);
    };


 function fnCheckPage() {
	 
	 /*
	
            if ($("#fname").val().length == 0) {
                alert("Please enter first name");
                return false;
            }
            if ($("#mname").val().length == 0) {
                alert("Please enter your middle name");
                return false;
            }

            if ($("#lname").val().length == 0) {
                alert("Please enter your last name");
                return false;
            }

            if ($("#address").val().length == 0) {
                alert("Please enter your address ");
                return false;
            }
			
            if ($('#country option:selected').val() == '---select---') {
                alert('Please select country');
                return false;
            }

            if ($('#state option:selected').val() == '---select---') {
                alert('Please select state');
                return false;
            }
			 if ($("#zip").val().length == 0) {
                alert("Please enter your zipCode ");
                return false;
            }
			if ($("#zip").val().length != 6) {
                alert("Please enter 6 digit zipCode.");
                return false;
            }
			
			
            
                if ($('#dob').val().length == 0) {
                    alert('Please enter your dob');
                    return false;
                }
           
			if ($("#phone").val().length == 0) {
                alert("Please enter your phone number");
                return false;
            }
			
				var H=$('#phone').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}

            if ($("#mobile").val().length == 0) {
                alert("Please enter your mobile");
                return false;
            }
			
				var H=$('#mobile').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Mobile Number should contain Numeric Values...!");
				
				return false; 
				}
				

            if ($("#mobile").val().length != 10) {
                alert("Please enter 10 digit mobile no.");
                return false;
            }
			 if ($('#gender option:selected').val() == '---select---') {
                alert('Please select gender');
                return false;
            }
				
			if (!ValidateEmail($("#email").val())) {
				alert("Invalid email address.");
				return false;
			}
				/*if($("#photo").val() !=undefined)
			{
			if ($("#photo").val().length == 0) {
                alert("Please upload your photo");
                return false;
            }
			}
			if($("#resume").val() !=undefined)
			{
		if ($("#resume").val().length == 0) {
                alert("Please upload your resume");
                return false;
            }
			}*/
			
			/*if ($("#proof").val().length == 0) {
                alert("Please enter your Idproof type");
                return false;
            }
	
			if ($("#p_new").val().length == 0) {
                alert("Please upload your Idproof");
                return false;
            }
			if ($("#rname").val().length == 0) {
                alert("Please enter  Reference name");
                return false;
            }
			if ($("#relation").val().length == 0) {
                alert("Please enter  relation");
                return false;
            }
			if ($("#contact").val().length == 0) {
                alert("Please enter your contact no");
                return false;
            }
			if ($("#loc").val().length == 0) {
                alert("Please enter your location");
                return false;
            }*/
			/*if($('input[name=pa]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#jloc").val().length == 0) {
                alert("Please Select Workplace");
                return false;
            }
			  if ($('#date').val().length == 0) {
                    alert('Please enter Date');
                    return false;
                }
			if ($("#day").val().length == 0) {
                alert("Please enter your Working Days");
                return false;
            }
			if($('input[name=level]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#course").val().length == 0) {
                alert("Please Select your course");
                return false;
            }
			if($('input[name=se]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#refer").val().length == 0) {
                alert("Please enter  Company name");
                return false;
            }
			if ($("#phno").val().length == 0) {
                alert("Please enter  Phone Number");
                return false;
            }
			var H=$('#phno').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}
				if (!ValidateEmail($("#email1").val())) {
				alert("Invalid email address.");
				return false;
			}
			
			
			if ($("#posi").val().length == 0) {
                alert("Please enter  position");
                return false;
            }
			if ($("#sal").val().length == 0) {
                alert("Please enter  Salary");
                return false;
            }
			if ($("#rfl").val().length == 0) {
                alert("Please enter  Reason for leaving");
                return false;
            }
			alert('rty');*/
            insert();
		}


$(function(){
	var id = getUrlVars()["employ_id"];
	$('#frm1').attr('action',serviceURLHR + 'update.php?action=basic&hid='+id);
	$('#frm2').attr('action',serviceURLHR + 'update.php?action=ref&hid='+id);
	$('#frm3').attr('action',serviceURLHR + 'update.php?action=exp&hid='+id);
	$('#frm4').attr('action',serviceURLHR + 'update.php?action=details&hid='+id);
	$('#frm5').attr('action',serviceURLHR + 'update.php?action=bank&hid='+id);
	$('#frm6').attr('action',serviceURLHR + 'update.php?action=passport&hid='+id);
	 $('#frm5').submit();
	  $('#frm4').submit();
});
function updateBasicProfile(){
	$('#frm1').submit();
	setTimeout(function(){  $('#frm1').submit(); },100);
}
function updateReference(){
	$('#frm2').submit();
	setTimeout(function(){  $('#frm2').submit(); },300);
}
function updateExperience(){
	$('#frm3').submit();
	setTimeout(function(){  $('#frm3').submit(); },100);
}
function updateDetails(){
	
	if($('#vpf_percentage').val() != ''){
		var emp_id = getUrlVars()["employ_id"];
		var vpf = $('#vpf_percentage').val();
		var desig = $('#sel_desigs').val();
		$.getJSON(serviceURLHR + "update-salary-structure-pfdetails.php?action=update&empid="+emp_id+"&vpf="+vpf+"&designationid="+desig,function(data){
			//var newStatus = data.status;
		
		});
	
	}
	
	//$('#frm4').submit();
	setTimeout(function(){  $('#frm4').submit(); },100);
}
function updateBank(){
	//$('#frm5').submit();
	
	setTimeout(function(){  $('#frm5').submit(); },100);
}
function updatePassport(){
	$('#frm6').submit();
	setTimeout(function(){  $('#frm6').submit(); },100);
}
$('#push').live('click',function(msg){ 
	//updateMenuItems();
	updatePassport();
});


$('#frm1').live('submit',function(e){
								  

		var progressbox     = $('.progressbox');
		var progressbar     = $('.progressbar');
		var statustxt       = $('.statustxt');
		var completed       = '0%';
		
		$(this).ajaxForm({
						 
			beforeSend: function() {
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			},
			success: function() {
				progressbox.hide();
				alert("Basic Details successfully updated.");
				//window.location="profile-view.php?employ_id="+id;
			},
			complete: function() {
				console.log('done.');
			}
	
			});
		//}
		return false; 
	e.preventDefault();
});

$('#frm2').live('submit',function(e){ 
											
		var progressbox     = $('.progressbox');
		var progressbar     = $('.progressbar');
		var statustxt       = $('.statustxt');
		var completed       = '0%';
	
			$(this).ajaxForm({
							 
				beforeSend: function() {
					progressbox.show(); //show progressbar
					progressbar.width(completed); //initial value 0% of progressbar
					statustxt.html(completed); //set status text
					statustxt.css('color','#000'); //initial color of status text
					
				},
				uploadProgress: function(event, position, total, percentComplete) {
					progressbar.width(percentComplete + '%') //update progressbar percent complete
					statustxt.html(percentComplete + '%'); //update status text
					console.log(percentComplete);
					if(percentComplete>50)
						{
							statustxt.css('color','#fff'); //change status text to white after 50%
						}
				},
				success: function() {
					progressbox.hide();
					alert("Reference Details successfully updated.");
					//window.location="profile-view.php?employ_id="+id;
				},
				complete: function() {
					console.log('done.');
				}
		
			});

		return false; 
	e.preventDefault();
});

$('#frm3').live('submit',function(e){
								  

		var progressbox     = $('.progressbox');
		var progressbar     = $('.progressbar');
		var statustxt       = $('.statustxt');
		var completed       = '0%';
		
		$(this).ajaxForm({
						 
			beforeSend: function() {
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			},
			success: function() {
				progressbox.hide();
				alert("Education & Work experience successfully updated.");
				//window.location="profile-view.php?employ_id="+id;
			},
			complete: function() {
				console.log('done.');
			}
	
			});

		return false; 
	e.preventDefault();
});

$('#frm4').live('submit',function(e){
								  
		var progressbox     = $('#frm4 #progressbox');
		var progressbar     = $('#frm4 #progressbar');
		var statustxt       = $('#frm4 #statustxt');
		var completed       = '0%';
		$(this).ajaxForm({
						 
			beforeSend: function() {
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			},
			success: function() {
				progressbox.hide();
				alert("Employee details successfully updated.");
				//window.location="profile-view.php?employ_id="+id;
			},
			complete: function() {
				console.log('done.');
			}
	
			});

		return false; 
	e.preventDefault();
});

$('#frm5').live('submit',function(e){
		//alert("test");						  
		var progressbox     = $('#frm5 #progressbox');
		var progressbar     = $('#frm5 #progressbar');
		var statustxt       = $('#frm5 #statustxt');
		var completed       = '0%';
		$(this).ajaxForm({
						 
			beforeSend: function() {
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			},
			success: function() {
				
				progressbox.hide();
				alert("Bank details successfully updated.");
				//window.location="profile-view.php?employ_id="+id;
			},
			complete: function() {
				console.log('done.');
			}
	
			});
		return false; 
	e.preventDefault();
});

$('#frm6').live('submit',function(e){
								  
		var progressbox     = $('#frm6 #progressbox');
		var progressbar     = $('#frm6 #progressbar');
		var statustxt       = $('#frm6 #statustxt');
		var completed       = '0%';
		
		$(this).ajaxForm({
						 
			beforeSend: function() {
				progressbox.show(); //show progressbar
				progressbar.width(completed); //initial value 0% of progressbar
				statustxt.html(completed); //set status text
				statustxt.css('color','#000'); //initial color of status text
				
			},
			uploadProgress: function(event, position, total, percentComplete) {
				progressbar.width(percentComplete + '%') //update progressbar percent complete
				statustxt.html(percentComplete + '%'); //update status text
				console.log(percentComplete);
				if(percentComplete>50)
					{
						statustxt.css('color','#fff'); //change status text to white after 50%
					}
			},
			success: function() {
				progressbox.hide();
				alert("Passport details successfully updated.");
				window.location="profile-view.php?employ_id="+id;
			},
			complete: function() {
				console.log('done.');
			}
	
			});
		return false; 
	e.preventDefault();
});


//////////////////////////////////////////////////////country selection///////////////////////////////////////////////////////////////
 selectcountry();
function selectcountry(){

$.ajax({
   url: serviceURLHR+"get.php",
   success: function(data){ 
     $("#country").html(data);
	
   }
 });
}


function selectcountry1(){
$.ajax({
   url: serviceURLHR+"get.php",
   success: function(data){ 
     $("#country1").html(data);
	setTimeout(function(){ $("#country1").val(country_selected); },100);
	
   }
 });
}

function check_pf_service(val){
	
	pf_servicedetails();
	/*if(val == '3')
	{
		Resigned_details();	
	}
	else if(val == '2')
	{
		Terminated_details();	
	}*/
}

function pf_servicedetails(){ 
	
	var emp_id = getUrlVars()["employ_id"];
	$.getJSON(serviceURLHR + 'managePFserviceDetails.php?action=loadstst&empids='+emp_id,function(data){
		pfleft_service = data.pfleftservice;
		
		//alert(JSON.stringify(pfleft_service));
		var pf_leavedate = pfleft_service[0].pf_leaving_date;
		$('#pf_date_leaving').val(pf_leavedate);
		
		var reason_leavingpf = pfleft_service[0].reason_leaving_pf;
		$('#reason_pf_leaving').val(reason_leavingpf);
		
		var pfremarks = pfleft_service[0].pfremarks;
		$('#pf_remarks').val(pfremarks);
					
	});
	
	
	$("body").append('<div class="newbasicdetails pfservice" style="display:none;padding:25px;">'+
					 '<form class="newpfserviceForm"><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>Whether Employee Have Left PF Service Details</translate></td>'+
					  '</tr>'+
					   '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Date of leaving service</translate></td>'+
						'<td><input type="text" name="pf_date_leaving" id="pf_date_leaving" class="edit_form_date" /></td>'+
						'<td width="200"><translate>Reason for Leaving Service</translate></td>'+
						'<td><textarea name="reason_pf_leaving" id="reason_pf_leaving" /></textarea></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Remarks</translate></td>'+
						'<td><input type="text" name="pf_remarks" id="pf_remarks"  /></td>'+
						'<td width="200"><translate></translate></td>'+
						'<td></td>'+
					  '</tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="savepfdetails"  class="color-button savepfdetails tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelPFList tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newbasicdetails').show('fade',500);
	

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

jQuery('.cancelPFList').live('click',function(){  $('.newbasicdetails').hide('clip',300,function(){ $(this).remove(); })  });
jQuery('.savepfdetails').live('click',savePFDetails);

function savePFDetails(){
	
	var emp_id = getUrlVars()["employ_id"];
	var dataString = $('.newpfserviceForm').serialize();
	
	$.post(serviceURLHR + "managePFserviceDetails.php?action=insertDetails&type=1&empid="+emp_id,dataString,function(data){
																							   
	},'json');
	$('.newbasicdetails').hide('clip',300);		
}

loadBranch();

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

jQuery('.view_emp_left_pf_service').live('click',check_Emp_Left_PF_service);

function check_Emp_Left_PF_service(){
	pf_servicedetails();
}

function check_terminate(val){
	if(val == '3')
	{
		Resigned_details();	
	}
	else if(val == '2')
	{
		Terminated_details();	
	}
}

function Resigned_details(){ 
	
	var emp_id = getUrlVars()["employ_id"];
	$.getJSON(serviceURLHR + 'manageTerminateResign.php?action=loadstst&empids='+emp_id,function(data){
		resignlist = data.terminateresignlist;
		//alert(JSON.stringify(newdate));
		var resigndate = resignlist[0].resign_submit_dt;
		var resigndatenewdate = resigndate.split("-").reverse().join("-");		
		$('#resigned_submit_dt').val(resigndatenewdate);
		
		var tentativedate = resignlist[0].tentaive_leave_dt;
		var tentativenewdate = tentativedate.split("-").reverse().join("-");
		$('#tentative_leave_dt').val(tentativenewdate);
		
		$('#reason_leaving').val(resignlist[0].reason_leaving);
		$('#notice_day').val(resignlist[0].notice_days);
		$('#resigned_remark').val(resignlist[0].resign_remark);
		
	});
	
	
	$("body").append('<div class="newbasicdetails" style="display:none;padding:25px;">'+
					 '<form class="newresigndetailsForm"><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>Resigned Details</translate></td>'+
					  '</tr>'+
					   '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Resignation Submitted On</translate></td>'+
						'<td><input type="text" name="resigned_submit_dt" id="resigned_submit_dt" class="edit_form_date" /></td>'+
						'<td width="200"><translate>Reason for Leaving</translate></td>'+
						'<td><textarea name="reason_leaving" id="reason_leaving" /></textarea></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Notice Period</translate></td>'+
						'<td><input type="text" name="notice_period" id="notice_period"  /></td>'+
						'<td width="200"><translate>Notice Days</translate></td>'+
						'<td><input type="text" name="notice_day" id="notice_day"  /></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Tentative Leaving Date</translate></td>'+
						'<td><input type="text" name="tentative_leave_dt" id="tentative_leave_dt" class="edit_form_date" /></td>'+
						'<td width="200"><translate>Remarks</translate></td>'+
						'<td><textarea name="resigned_remark" id="resigned_remark" /></textarea></td>'+
					  '</tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveresigndetails"  class="color-button saveresigndetails tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelResignedList tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newbasicdetails').show('fade',500);
	

	$('.newbasicdetails').center();
	
	load_desigs(deptid);
}
jQuery('.cancelResignedList').live('click',function(){  $('.newbasicdetails').hide('clip',300,function(){ $(this).remove(); })  });
jQuery('.saveresigndetails').live('click',saveResignDetails);

jQuery('.view_resign_terminated').live('click',check_Resig_Terminate_details);


function saveResignDetails(){
	
	var emp_id = getUrlVars()["employ_id"];
	var dataString = $('.newresigndetailsForm').serialize();
	
	$.post(serviceURLHR + "manageTerminateResign.php?action=insertDetails&type=1&empid="+emp_id,dataString,function(data){
		$('.newbasicdetails').hide('clip',300);																							   
	},'json');
	
}

function check_Resig_Terminate_details(){
	var emp_id = getUrlVars()["employ_id"];
	$.getJSON(serviceURLHR + 'manageTerminateResign.php?action=checkdetails&empids='+emp_id,function(data){
		chk_resgin_ter_type =  data.terminateresigndts
		if(chk_resgin_ter_type[0].term_regin_type==0)
		{
			Resigned_details();
		}
		else
		{
			Terminated_details();
		}
	});	
}

function Terminated_details(){ 

	var emp_id = getUrlVars()["employ_id"];
	
	$.getJSON(serviceURLHR + 'manageTerminateResign.php?action=loadstst&empids='+emp_id,function(data){
		resignlist = data.terminateresignlist;
		//console.log(resignlist);
		
		var terminateleave_dt = resignlist[0].terminate_leave_dt;
		var resigndatenewdate = terminateleave_dt.split("-").reverse().join("-");		
		$('#date_leaving').val(resigndatenewdate);
		
		var pfleave_dt = resignlist[0].pf_leave_dt;
		var tentativenewdate = pfleave_dt.split("-").reverse().join("-");
		$('#date_leaving_pf').val(tentativenewdate);
		
		$('#reason_leaving_service').val(resignlist[0].terminate_reason_leave);
		
		
	});
	
	$("body").append('<div class="newbasicdetails" style="display:none;padding:25px;">'+
					 '<form class="newterminatedetailsForm"><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>Terminated, Expired & Retired Details</translate></td>'+
					  '</tr>'+
					   '<tr>'+
						'<td colspan="4" height="10" ></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Date of Leaving</translate></td>'+
						'<td><input type="text" name="date_leaving" id="date_leaving" class="edit_form_date" /></td>'+
						'<td width="200"><translate>Reason for leaving the service</translate></td>'+
						'<td><textarea name="reason_leaving_service" id="reason_leaving_service" /></textarea></td>'+
					  '</tr>'+
					  '<tr>'+
						'<td width="100"><translate>Date of Leaving the PF Service</translate></td>'+
						'<td><input type="text" name="date_leaving_pf" id="date_leaving_pf" class="edit_form_date"  /></td>'+
						'<td width="200"></td>'+
						'<td></td>'+
					  '</tr>'+
					    '<td>&nbsp;</td>'+
						'<td>&nbsp;</td>'+
						'<td></td>'+
						'<td><input type="button" name="button" id="saveterminated_details"  class="color-button saveterminated_details tabfield-bt-1" value="Submit" style="float:left; margine-left:5px" />'+
						'<input type="button" name="button" class="color-button2 cancelTerminatedList tabfield-bt-1" style="float:left;" value="Cancel" /></td>'+
					  '</tr>'+
					'</table></form></div>');

	$('.newbasicdetails').show('fade',500);
	
	$('.newbasicdetails').center();
	
	load_desigs(deptid);
}
jQuery('.cancelTerminatedList').live('click',function(){  $('.newbasicdetails').hide('clip',300,function(){ $(this).remove(); })  });

jQuery('.saveterminated_details').live('click',saveTerminatedDetails);

function saveTerminatedDetails(){
	var emp_id = getUrlVars()["employ_id"];
	var dataString = $('.newterminatedetailsForm').serialize();
	
	$.post(serviceURLHR + "manageTerminateResign.php?action=insertDetails&type=0&empid="+emp_id,dataString,function(data){
		$('.newbasicdetails').hide('clip',300);																							   
	},'json');
}

statusLoadin = 0;
function selectstatus()
{
	
	if(statusLoadin == 0){
		statusLoadin =1;
	$('#empstat2').html('');//alert();
	
		$.getJSON(serviceURLHR + 'branch.php?action=loadstst',function(data){
		branch = data.branch;
	//	console.log(branch);
		$('#empstat2').append('<option value="0">Not Applicable</option>');
		$.each(branch, function(index, branch) {
			$('#empstat2').append('<option value="'+branch.id+'">'+branch.emply_stat	+'</option>');
		});	
		statusLoadin = 0;
	});
	}
}
function loadXMLDoc(str)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("state").innerHTML=xmlhttp.responseText;
	$('#state').val(state_selected);
    }
	}
xmlhttp.open("GET",serviceURLHR +"list.php?id="+str,true);
xmlhttp.send();
}

//////////////////////////////////////////////////////////////////////////////////

selectdesig();

function selectdesig()
{ 
$.ajax({
   url: serviceURLHR+"edit.php",
   success: function(data){ 
     $("#pos").html(data);
	
   }
 });
}




//////////////////////////////////////////////////////////////////////////////////




$(function() 
{
	
var addDiv = $('#fetch');
var i = $('#fetch p').size() + 1;
$('#level2').live('click', function() 
{
	
	//alert("hai");
$('<p><label for="course">course</label><input type="text" name="course" id="course" AUTOCOMPLETE=OFF /><a href="#" id="notneed">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#notneed').live('click', function() 
{
	
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);
////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////
$(function() 
{
	
var addDiv = $('#fetch');
var i = $('#fetch p').size() + 1;
$('#c').live('click', function() 
{
	
	//alert("hai");
$('<p><label for="course">course</label><input type="text" name="course" id="course" AUTOCOMPLETE=OFF /><a href="#" id="notneed1">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#notneed1').live('click', function() 
{
	
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);


///////////////////////////////////////////////////


$(function() 
{
	//var k=0;
var addDiv = $('#insert');
var i = $('#insert p').size() + 1;
$('#cert').live('click', function() 
{
	
	
$('<p><label for="course">course</label><input type="text" name="cert[]" id="cert" AUTOCOMPLETE=OFF /><a href="#" id="cert"><img src="images/icon-add.png" width="20" height="15" title="Add More" /></a></br><a href="#" id="drop">Remove</a></span></p>').appendTo(addDiv);i++;// k++;
return false;
}

);
$('#drop').live('click', function() 
{
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);

//////////////////////////////////////////////////////LiSt Item(Edit page)/////////////////////////////////////////////////////////////// 

var id = getUrlVars()["employ_id"];
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;
}

setTimeout(function(){
//	viewEmployee();				
},1500);


UpdateEmployee();

var employeeslist;
var empListLoading =0;

function viewEmployee(){
	
		selectstatus();
		
		if(empListLoading == 0){
			empListLoading =1;
			$('#spinner').show();
		//$('#busy').show();
		$.getJSON(serviceURLHR+'edit.php?employ_id='+emplyee_id,function(data){
		   emplist = data.employ;
		   empListLoading = 0;
		   $.each(emplist, function(index, employeeslist){ 
									//console.log(employeeslist);
				if(index ==0){
				$('#name').html(employeeslist.e_fname+" "+employeeslist.e_lname);
				$('.fname').val(employeeslist.e_fname);
				$('.mname').val(employeeslist.e_mname);
				$('.lname').val(employeeslist.e_lname);
				$('#e_id').val(id);
				$('#deviceid').html(employeeslist.device_id);
				
				$('#dob1').html(employeeslist.e_dob);
				$('#phn').html(employeeslist.e_mob);
				$('#eml').html(employeeslist.e_mail); 
				$('#gen').html(employeeslist.e_gender);
				
				$('#address').html(employeeslist.e_add);
				$('#country2').html(employeeslist.country_name);
				$('#state1').html(employeeslist.state);
				$('#zip').html(employeeslist.e_zip);
				$('#dob').html(employeeslist.e_dob);
				
				if(employeeslist.e_phone !="")
				$('#phone').html(", "+employeeslist.e_phone);//$('#phone').append(','+employeeslist.e_phone);    // Changed by Jithin.(May by commented code is needed)
				
				$('#mobile').html(employeeslist.e_mob); 
				$('#gender').html(employeeslist.e_gender);
				$('#email').html(employeeslist.e_mail);
				$('#branchhidden').val(employeeslist.branchid);
				$('#depthidden').val(employeeslist.departid);
				$('#desighidden').val(employeeslist.e_post);
				$('#immsuperhidden').val(employeeslist.imd_supervisor_id);
				$('#branch').html(employeeslist.branch_name); 
				$('#dept').html(employeeslist.depart_name);
				$('#desig').html(employeeslist.desig_name);
				$('#resign_join').val(employeeslist.resigned_date);
				$('#immsuper').html(employeeslist.immediatesupervisr);
				$('.basicpay').html(employeeslist.emp_basic_pay);
				$('#empstat2').val(employeeslist.emp_status);
				
				$('.overtime').html(employeeslist.over_time);
				selectcountry1();
				country_selected = employeeslist.e_country;
				state_selected =employeeslist.e_state;
				
				//setTimeout(function(){ $('#country1').val(employeeslist.e_country) },800);;
				loadXMLDoc(employeeslist.e_country);
				
			//	setTimeout(function(){ $('#state').val(); },800);
				
				if(employeeslist.photo=='')
				{
				photo='noimg.jpg';
				}else{ 
				if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
				{
				photo='noimg.jpg'; 
				
				}
				else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
				{ 
				photo='Female.PNG'; 
				}
				else
				{
				photo=employeeslist.photo;	}
				}	
				
				$('#images').html('<span id="doc"><a href="'+serviceURLHR+'download_image.php?filename='+employeeslist.photo+'"  target="_blank" class="pro-icon-01">Photo</a></span>');
				$('.profile-photo').html('<img src="'+baseURL+'upload/image/'+photo+'" height="250" width="220">');
				$('#profimage').html('<img src="'+baseURL+'upload/image/'+employeeslist.photo+'" height="250" width="220">'+
									   '<img src="images/edit.png" style="z-index:20; position:absolute; top:10px;left:200px; display:none;" class="edit-profileimage">');
				if(employeeslist.resume){
				$('#resumelists').html('<span><a  href="'+serviceURLHR+'download_resume.php?filename='+employeeslist.resume+'"  target="_blank" title="'+employeeslist.resume+'" style="height:5px,width:5px" class="pro-icon-02">Resume</a></span>');
				}
				$('#filetype').html(employeeslist.filetype);
				//$('#proof').val(employeeslist.filetype);
				//fileToSend =baseURL+'/upload/idproof/'+employeeslist.file;
				
				if(employeeslist.idfiles)
				{
					 $('#id_proofs').html('<span><a  href="'+serviceURLHR+'download_addressproof.php?idf=1&employ_id='+emplyee_id+'"   title="'+employeeslist.file+'" style="height:5px,width:5px" class="pro-icon-03">Address Proof</a></span>');
				}
				else
				{
						 $('#id_proofs').html('<span><a  href="#" title="No files Attached" style="height:5px,width:5px" class="pro-icon-03">Address Proof(No File Uploaded)</a></span>');
				}
				
			
				 $('#rname').html(employeeslist.e_rname);
				 
				 $('#relation').html(employeeslist.e_relation);
				 $('#contact').html(employeeslist.e_contact);
				 $('#loc').html(employeeslist.e_rlocation);
				 $('#e_post').html(employeeslist.desig_name);
					
				 $('#loc1').html(employeeslist.e_plocation);
				 $('#date').html(employeeslist.e_dstart);
				 $('#day').html(employeeslist.e_dweek);
				// $('#e_qualification').html(employeeslist.e_qualification);
																			
				 //$('#course').html(employeeslist.e_course);
				 $('#username').html(employeeslist.username);
				 $('#password').html(employeeslist.password);
				  
				
				//$('#refer').html(employeeslist.refer);
				//alert(employeeslist.email);
				/*$('#emp').html(employeeslist.emp);
				 $('#address2').html(employeeslist.address2);
				 $('#phno').html(employeeslist.phno);
				 $('#email1').html(employeeslist.email);
				 $('#posi').html(employeeslist.posi);				
				 $('#sal').html(employeeslist.sal);				 
				 $('#rfl').html(employeeslist.rfl);
				 $('#from').html(employeeslist.from);
				 $('#to').html(employeeslist.to);*/
				 
				 $('#emp_id').html(employeeslist.employee_id);
				 $('#dt_join').html(employeeslist.date_join);
				 $('#blood_grp').html(employeeslist.blood_group);
				/* $('#pf_ac_no').html(employeeslist.pf_accnum);
				 $('#pf_nominee').html(employeeslist.pf_nominee);*/
				 $('#pay_salary_type').val(employeeslist.pay_sal_type);
				 //alert(employeeslist.pay_sal_type);
				 // $('#pay_salary_type').val(employeeslist.pay_sal_type);
				 $('#esi_details').html(employeeslist.esi_details);
				 $('#emp_contract').val(employeeslist.emp_contract);
				 $('#emp_prob_period').val(employeeslist.emp_prob_period);
				 //$('#pay_salary_type').val(employeeslist.pay_salary_type);
				 $('#passport_exp_date').val(employeeslist.passport_exp_date);
				 $('#pf_acc_no').val(employeeslist.pf_accnum);
				 $('#date_join_fund').val(employeeslist.pf_date_join_fund);
				 $('#pf_year').val(employeeslist.pf_service_year);
				 $('#pf_month').val(employeeslist.pf_service_month);
				 $('#pf_days').val(employeeslist.pf_service_day);
				 $('#current_pf_acc_balance').val(employeeslist.emp_pfamt);
				 $('#vpf_percentage').val(employeeslist.vpf_percent);
				 
				 if(employeeslist.pf_service_status == 1){
					$('#pf_servicecheck').attr('disabled',true);  
				 }
				
				 
				 $('#insur_alloted_corp').val(employeeslist.insurance_alloted_corp);
				
				 //alert(employeeslist.pay_salary_type);
				 if(employeeslist.emp_contract=='U')
				 {
					$('.contractPeriod').css('display','none'); 
				 }
				 else
				 {
				 	$('.contractPeriod').val(employeeslist.contract_end_date);
				 }
				 $('#visa_exp_date').val(employeeslist.visa_exp_date);
				 
				 $('#emirates_id_number').val(employeeslist.emirates_id_number);
				 $('#emirates_card_number').val(employeeslist.emirates_card_number);
				 $('#emirates_expiry_date').val(employeeslist.emirates_expiry_date);
				 
				 $('#labour_card_number').val(employeeslist.labour_card_number);
				 $('#labour_card_authority').val(employeeslist.labour_card_issuing_authority);
				 $('#labour_card_zone').val(employeeslist.labour_card_zone);
				 $('#labour_expiry_date').val(employeeslist.labour_card_expiry_date);
				 
				  if(employeeslist.passport_doc!=""){
					 $('#pass_doc_list').html(employeeslist.passport_doc+" "+'<a href="#" id="passport_rm"><img src="'+baseURL+'images/cross-button.png"></a>');
				 }
				 if(employeeslist.visa_doc!=""){
					 $('#visa_doc_list').html(employeeslist.visa_doc+" "+'<a href="#" id="visa_rm"><img src="'+baseURL+'images/cross-button.png"></a>');
				 }
				
				 $('#history_dt_join').html(employeeslist.hist_dt_join);
				 $('#emptype2').html(employeeslist.hist_emptype);
				 $('#dt_rel').html(employeeslist.date_releve);
				 $('#last_desig').html(employeeslist.hist_pre_desig);
				 $('#emp_num').html(employeeslist.hist_emp_num);
				/* $('#dt_prev_pay_revision').html(employeeslist.hist_dt_prev_pay);
				 $('#dt_pay_revised').html(employeeslist.hist_dt_pay);
				 $('#comp_probation').html(employeeslist.hist_comp_prob);
				 */
				 
				 
				 
				 $('#accountname').html(employeeslist.e_account);
				 
				 $('#bname').html(employeeslist.e_bank);
				 $('#accountno').html(employeeslist.e_accountno);
				  
				 $('#baddress').html(employeeslist.e_bankadd);
				 
				 $('#bankcode').html(employeeslist.e_code);
				 $('#editbtn').html(' <a  href="employee_editform.php?employ_id='+emplyee_id+'"><button id="registerButton" type="button" class="color-button3">Add Details</button></a>');
				}
				
				//$('#hid').html(id);
							
		   });	
		   
		setTimeout(viewLanguage,200);
		setTimeout(viewExperience,250);
		setTimeout(viewEducation,300);
		setTimeout(viewDocuments,150);
		 //  $('#busy').hide();
		 $('#spinner').hide();
		});
	}
}
	function viewDocuments()
	{
			$.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=documents',function(data){ 
				documents = data.documents;																	
				$.each(documents, function(index, documents) 
				{	
					
					$('#addmoredoc').show();
					if(documents.doc!=""){
						var remlink	= ' <a href="#" title="'+documents.emp_doc_id+'" class="doc_rm"><img src="'+baseURL+'images/cross-button.png"></a>';
					} else 
					    var remlink	= "" ;
						
					$('#addmoredoc').append('<table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164" valign="top" class="form-padd-01"><label for="label">Document name</label></td><td><input name="doc_name[]" type="text" value="'+documents.doc_name+'"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" valign="top" class="form-padd-01"><label for="label">Document</label></td><td><input name="doc[]" type="file"   /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td></td><td align="left">'+documents.doc+remlink+'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td></td><td><a href="#" class="rmmoredoc">x Remove</a></td><td><input type="hidden" name="emp_doc_id[]" value="'+documents.emp_doc_id+'"></td></tr><tr><td colspan="2" height="8"></td></tr></table><div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr" "></div>');
					
				});
			});
	}
	function viewLanguage()
	{ var k=1;
			$.getJSON(serviceURLHR+'view.php?employ_id='+id+'&action=lang',function(data){ 
				language = data.lang;
				
				$('.ttrr').remove();
				$.each(language, function(index, language) 
				{	
				
				
					if(language.lang_rd==1)
								 var rd_chk	= "checked";
							 else
								 var rd_chk	= " ";
								 
							if(language.lang_wt==1)
								 var wt_chk	= "checked";
							 else
								 var wt_chk	= " ";	 
							
							if(language.lang_sk==1)
								 var sk_chk	= "checked";
							 else
								 var sk_chk	= " ";	
								 
							$('#lang_view').append('<tr class="ttrr"><td align="left" valign="top">'+language.language+'</td><td align="left" valign="top"><input type="checkbox" name="radio_eng1" id="radio_eng1" value="1" disabled="disabled" '+rd_chk+' /></td><td align="left" valign="top"><input type="checkbox" name="radio_eng2" id="radio_eng2" value="1" disabled="disabled" '+wt_chk+' /></td><td align="left" valign="top"><input type="checkbox" name="radio_eng3" id="radio_eng3" value="1" disabled="disabled" '+sk_chk+' /></td></tr>');
			k++;	});
			});
	}
	
	function viewExperience()
	{
			$.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=exp',function(data){
			   explist = data.wk_exp;
			  
			   $.each(explist, function(index, explist) 
			   {
				   	// $('#emp').html(explist.refer);
					 $('#address2').html(explist.emp);
					 $('#phno').html(explist.phno);
					 $('#email1').html(explist.email);
					 $('#posi').html(explist.posi);
					 $('#sal').html(explist.sal);
					 $('#rfl').html(explist.rfl);
					 $('#from').html(explist.from);
					 $('#to').html(explist.to);
					 if(index>0)
						 $('.viewworkexperience').show();
					 
			   });
			});
					
	}
	
	function viewEducation()
	{
			$.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=edu',function(data){
										
			   edulist = data.educ;
			   $.each(edulist, function(index, edulist) 
				{
						 $('#e_qualification').html(edulist.course);
						 $('#spl').html(edulist.spl);
						 $('#unv').html(edulist.unv);
						 $('#yer').html(edulist.yr);
						 $('#prc').html(edulist.pcntg);
						 if(index>0)
					 		$('.vieweducation').show();
				});
			});
	}
	
	function loadExperience(){
		$.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=exp',function(data){
										
			   explist = data.wk_exp;
			   if(data.wk_exp!=null){
			   $('#addinput2').html('');
			   }
			   $.each(explist, function(index, explist) 
				{
					
					$('#addinput2').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="exp_bdr" ">'+
										   '</div><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'+
										   '<td width="164"  align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Company Name</label></td><td>'+
								'<input type="text" name="refer[]" id="refer"  AUTOCOMPLETE=OFF  value="'+explist.refer+'"/><br />'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Address</label></td><td>'+
								'<textarea name="emp[]" id="emp">'+explist.emp+'</textarea></td></tr>'+
								'<tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Contact No</label></td><td><input type="text" name="phno[]" id="phno"  AUTOCOMPLETE=OFF value="'+explist.phno+'"  />'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td align="left" width="164" valign="top" class="form-padd-01">'+
								'<label for="label">Email</label></td><td><input type="text" name="email1[]" id="email1" AUTOCOMPLETE=OFF value="'+explist.email+'"/>'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Position</label></td><td><input type="text" name="posi[]" id="posi" AUTOCOMPLETE=OFF value="'+explist.posi+'" />'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Salary</label></td><td><input type="text" name="sal[]" id="sal" AUTOCOMPLETE=OFF value="'+explist.sal+'" />'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01">'+
								'<label for="label">Reason for leaving</label></td><td><input type="text" name="rfl[]" id="rfl" AUTOCOMPLETE=OFF value="'+explist.rfl+'"/>'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01">'+
								'<label for="label">From</label></td><td>'+
								'<input type="text" id="from'+index+'" name="from[]"  class="edit_form_date" readonly AUTOCOMPLETE=OFF  value="'+explist.from+'"/>'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top"  class="form-padd-01">'+
								'<label for="label">To</label></td><td>'+
								'<input type="text"  id="to'+index+'"name="to[]"  readonly class="edit_form_date" AUTOCOMPLETE=OFF value="'+explist.to+'"/>'+
								'</td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remNew2">Remove</a></td></tr></table>');
					
					
				});
		});	   
	}
    function loadLanguage()
    {
		var vars = [];
	   
		var k=1;
		Rows = ($('table#myTable tr:last').index() + 1);
	    $.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=lang',function(data){
									
		   langlist = data.lang;
		   if(data.lang==null){
			  $('.list_lang').append('<tr class="add-lang"><td width="20%" align="left" valign="top">&nbsp;</td><td align="left" valign="top"><input type="text" name="lang[]" id="lang" ></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_rd'+Rows+'" id="radio_eng_rd'+Rows+'" value="1" class="reads"/></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_wt'+Rows+'" id="radio_eng_wt'+Rows+'" value="1" class="writs"/></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_sk'+Rows+'" id="radio_eng_sk'+Rows+'" value="1" class="spks"/></td><td><a  href="#" class="remLang"  data-id="1">Remove</a></td><td><input type="hidden" id="emp_lang_id'+Rows+'" name="emp_lang_id'+Rows+'" value="" class="emplngs"></td></tr>');
			  //selectlanguage();
		   }
		   $.each(langlist, function(index, langlist) 
			{
				
				if(langlist.lang_rd==1)
					 var rd_chk	= "checked";
				 else
					 var rd_chk	= " ";
					 
				if(langlist.lang_wt==1)
					 var wt_chk	= "checked";
				 else
					 var wt_chk	= " ";	 
				
				if(langlist.lang_sk==1)
					 var sk_chk	= "checked";
				 else
					 var sk_chk	= " ";
					 
		//	alert(langlist.language_name);
				$('.list_lang').append('<tr><td width="20%" align="left" valign="top">&nbsp;</td><td align="left" valign="top"><input type="text" name="lang[]" id="lang'+k+'"  value="'+langlist.language_name+'" ></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_rd'+k+'" id="radio_eng_rd'+k+'" value="1"'+rd_chk+' class="reads"/></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_wt'+k+'" id="radio_eng_wt'+k+'" value="1"'+wt_chk+' class="writs"/></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_sk'+k+'" id="radio_eng_sk'+k+'" value="1"'+sk_chk+' class="spks" /></td><td><a href="#" class="remLang"  data-id="'+k+'">Remove</a></td><td><input type="hidden" id="emp_lang_id'+k+'" name="emp_lang_id'+k+'" value="'+langlist.id+'" class="emplngs"></td></tr>');
				
				
	
			k++;	
				
			});
		  
		}); 
	   
	   
   }
	function loadEducation(){
		$.getJSON(serviceURLHR+'branch.php?employ_id='+id+'&action=edu',function(data){
										
			   edulist = data.educ;
			   if(data.educ!=null){
			  	 $('#edu').html('');
			   }
			   $.each(edulist, function(index, edulist) 
				{
					
					
					$('#edu').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr" "></div><table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164" align="left" valign="top" class="form-padd-01" align="left"><label for="label">Course</label></td><td><input name="course[]" type="text" value="'+edulist.course+'" /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" valign="top" align="left" class="form-padd-01" align="left"><label for="label">Specialization</label></td><td><input name="spl[]" type="text"  value="'+edulist.spl+'" /></td></tr><tr><td colspan="2" height="8"></td> </tr><tr><td width="164"  align="left"  valign="top" class="form-padd-01"><label for="label" align="left">University/Institute</label></td><td><input name="unv[]" type="text"  value="'+edulist.unv+'" /></td> </tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01"><label for="label">Year</label></td><td><input name="yr[]" type="text" value="'+edulist.yr+'" /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left"  valign="top" class="form-padd-01" align="left"><label for="label">Percentage</label></td><td><input name="pcntg[]" type="text"  value="'+edulist.pcntg+'"/></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remEdu">Remove</a></td></tr></table>');
					
				});
		});	   
	}
		   
	function UpdateEmployee()
	  {
		  //selectstatus();
		  
		 //alert(id);
		//alert(serviceURLHR);
		$.getJSON(serviceURLHR+'edit.php?employ_id='+id,function(data){
					
					
				   employeeslist = data.employ; 
					
					$.each(employeeslist, function(index, employeeslist) 
					{
							
						// alert('HR/upload/thumb/'+employeeslist.photo);
														$('#hid').val(id);
																  	
														//alert(employeeslist.e_gender);
														$('#fname').val(employeeslist.e_fname);
														$('#mname').val(employeeslist.e_mname);
														$('#lname').val(employeeslist.e_lname);
														$('#address').val(employeeslist.e_add);
														$('#country').val(employeeslist.country_name);
														$('#state').val(employeeslist.state);
														$('#zip').val(employeeslist.e_zip);
														$('#dob').val(employeeslist.e_dob);
														$('#phone').val(employeeslist.e_phone);
														$('#mobile').val(employeeslist.e_mob); 
														$('#gender1').val(employeeslist.e_gender);
														$('#email').val(employeeslist.e_mail);
														
														$('#passnum').val(employeeslist.pass_no);
														$('#isucountry').val(employeeslist.pass_country);
														$('#isudate').val(employeeslist.pass_issue_dat); 
														$('#pexpdate').val(employeeslist.pass_exp_dat);
														$('#natn').val(employeeslist.nation);
														
														$('#vstype').val(employeeslist.vsa_type);
														$('#plcisue').val(employeeslist.vsa_isue_place);
														$('#uidno').val(employeeslist.uid_no); 
														$('#filen').val(employeeslist.file_num);
														$('#vpasno').val(employeeslist.vsa_pass_num);
														$('#profsn').val(employeeslist.profesion);
														$('#spons').val(employeeslist.sponsor);
														$('#visuedate').val(employeeslist.vsa_isue_dat); 
														$('#viexpdat').val(employeeslist.vsa_exp_dat);
												        $('#sel_branch').val(employeeslist.branchid);
														$('#sel_depart').val(employeeslist.departid); 
														$('#imdatesupervisor').val(employeeslist.imd_supervisor_id);
														
														
																																								
														$.getJSON(serviceURLHR + 'immediatesupervisor.php?action=load',function(data){
														$('#imdatesupervisor').empty();
														
														imdsupervisor = data.imdsupervisor;
														$.each(imdsupervisor, function(index, imdsupervisor) {
								   
														if(imdsupervisor.e_id==employeeslist.imd_supervisor_id){
											$('#imdatesupervisor').append('<option value="'+imdsupervisor.e_id+'" selected="selected">'+imdsupervisor.e_fname	+'</option>');
														   }else{
															$('#imdatesupervisor').append('<option value="'+imdsupervisor.e_id+'">'+imdsupervisor.e_fname	+'</option>');
														   }
														  });
														
													});
									
								
						var depts=employeeslist.departid;								
						$.getJSON(serviceURLHR + 'designations.php?action=load&dept='+depts,function(data){
						designation = data.designation;
						$("#sel_desigs").empty(); 
						/*if(!depts)
						{
							$('#sel_desigs').append('<option value="">Select Designation</option>');
						}*/
						
						
						
						$.each(designation,function(index,designation){
   
						   if(designation.desig_id==employeeslist.e_post){
							$('#sel_desigs').append('<option value="'+designation.desig_id+'" selected="selected">'+designation.desig_name+'</option>');
						   }else{
							$('#sel_desigs').append('<option value="'+designation.desig_id+'">'+designation.desig_name+'</option>');
						   }
						  });						
					});
														
														//setTimeout($('#sel_desigs').val(employeeslist.e_post),100);
														
														
														if(employeeslist.overtime_status=='1')
														{
															$('#overtime').prop('checked', true);
														}
														
														if(employeeslist.photo=='')
														{
															photo='noimg.jpg';
															}else{ 
															if(employeeslist.e_gender=='Male' && employeeslist.photo=='noimg.jpg')
															{
															photo='noimg.jpg'; 
															
															}
															else if(employeeslist.e_gender=='Female' && employeeslist.photo=='noimg.jpg')
															{ 
															photo='Female.PNG'; 
															}
															else
															{
															photo=employeeslist.photo;	
															}
														}	
				
														$('#image').html('<img src="'+baseURL+'upload/image/'+photo+'" width="170px" height="172px" style="height:5px,width:5px">');
														// $('#resumelist').html('<a style="color:#990000" href="'+baseURL+'mookadanadmin/download_resume.php?filename='+employeeslist.resume+'" title="'+employeeslist.resume+'" style="height:5px,width:5px">Download Resume</a><br/>');
													
														  	//$('#proof').val(employeeslist.filetype);
															 //$('#id_proof').html('<a style="color:#990000" href="'+servicesUrlIm+'upload/image/'+employeeslist.file+'" title="'+employeeslist.file+'" style="height:5px,width:5px">Download Proof</a><br/>');
															 $('#rname').val(employeeslist.e_rname);
															 
															 $('#relation').val(employeeslist.e_relation);
															 $('#contact').val(employeeslist.e_contact);
															  $('#loc').val(employeeslist.e_rlocation);
															 
																if(employeeslist.e_post=="manager")
																{
																	 $('#rad').prop('checked', true);
																}
																else if(employeeslist.e_post=="supervisor")
																{
																	
																 $('#radio2').prop('checked', true);
																}
																else if(employeeslist.e_post=="kitchensuper")
																{
																	 $('#radio3').prop('checked', true);
																}
																else if(employeeslist.e_post=="leadcook")
																{
																	
																 $('#radio4').prop('checked', true);
																}
																else if(employeeslist.e_post=="cook")
																{
																	 $('#radio5').prop('checked', true);
																}
																else if(employeeslist.e_post=="Kitchenhelper")
																{
																	 $('#radio6').prop('checked', true);
																}
																else
																{
																	 $('#radio7').prop('checked', true);
																}
															
															  $('#jloc').val(employeeslist.e_plocation);
															  $('#date').val(employeeslist.e_dstart);
																$('#day').val(employeeslist.e_dweek);
																
																if(employeeslist.e_qualification=="10th"){
																	
																	 $('#level').prop('checked', true);
																	 
																}else if(employeeslist.e_qualification=="plus2"){
																	
																 $('#level1').prop('checked', true);
																 
																}else if(employeeslist.e_qualification=="graduation"){
																	
																	 $('#level4').prop('checked', true);
																	 
																}else {
																	$('#level3').prop('checked', true);
																}
																
																
															  /* $('#course').val(employeeslist.e_course);
															    if(employeeslist.e_eng_rd=="read")
																{
																  $('#radio_eng1').prop('checked', true);
																}
																if(employeeslist.e_eng_wt=="write")
																{
																  $('#radio_eng2').prop('checked', true);
																}
																if(employeeslist.e_eng_sp=="speak")
																{
																  $('#radio_eng3').prop('checked', true);
																}
																if(employeeslist.e_hin_rd=="read")
																{
																	$('#radio_hin1').prop('checked', true);
																}
																if(employeeslist.e_hin_wt=="write")
																{
																  $('#radio_hin2').prop('checked', true);
																}
																if(employeeslist.e_hin_sp=="speak")
																{
																  $('#radio_hin3').prop('checked', true);
																}
																if(employeeslist.e_mal_rd=="read")
																{																	
																  $('#radio_mal1').prop('checked', true);
																}
																if(employeeslist.e_mal_wt=="write")
																{																	
																  $('#radio_mal2').prop('checked', true);
																}
																if(employeeslist.e_mal_sp=="speak")
																{																	
																  $('#radio_mal3').prop('checked', true);
																}
																if(employeeslist.e_tam_rd=="read")
																{																	
																  $('#radio_tam1').prop('checked', true);
																}
																if(employeeslist.e_tam_wt=="write")
																{																	
																  $('#radio_tam2').prop('checked', true);
																}
																else(employeeslist.e_tam_sp=="speak")
																{																	
																  $('#radio_tam3').prop('checked', true);
																}
															
													$('#refer').val(employeeslist.refer);
															
															 $('#emp').val(employeeslist.emp);
															 
															 $('#phno').val(employeeslist.phno);
															 $('#email1').val(employeeslist.email);
															 $('#posi').val(employeeslist.posi);
															
															 $('#sal').val(employeeslist.sal);
															 
															 $('#rfl').val(employeeslist.rfl);
															 $('#from').val(employeeslist.from);
															 $('#to').val(employeeslist.to);*/
															 
															 
															 $('#emp_id').val(employeeslist.employee_id);
															 var hh=employeeslist.emp_status;
															 //alert(employeeslist.emp_status);
															 $('#empstat2').val(employeeslist.emp_status);
													
														 	 //$('.empstat2').val('1');
										  					 //$('#empstat').val(employeeslist.emp_status).attr("selected", "selected");
									
															 $('#dt_join').val(employeeslist.date_join);
															 $('#blood_grp').val(employeeslist.blood_group);
															/* $('#pf_ac_no').val(employeeslist.pf_accnum);
															 $('#pf_nominee').val(employeeslist.pf_nominee);*/
															 $('#esi_details').val(employeeslist.esi_details);
															 
															 $('#history_dt_join').val(employeeslist.hist_dt_join);
															 $('#emptype1').val(employeeslist.hist_emptype);
															 $('#dt_prev_pay_revision').val(employeeslist.hist_dt_prev_pay);
															 $('#dt_pay_revised').val(employeeslist.hist_dt_pay);
															 $('#comp_probation').val(employeeslist.hist_comp_prob);
															 $('#hist_date_releve').val(employeeslist.date_releve);
															 $('#hist_emp_num').val(employeeslist.hist_emp_num);
															 $('#hist_pre_desig').val(employeeslist.hist_pre_desig);
															 
															 $('#accountname').val(employeeslist.e_account);
															 
															 $('#bank').val(employeeslist.e_bank);
															 $('#accountno').val(employeeslist.e_accountno);
															  
																$('#bankadd').val(employeeslist.e_bankadd);
															 
															 $('#bankcode').val(employeeslist.e_code);
															 
										if(!employeeslist.phno){
											$('.work-experiance').hide();	
										}
		});
		loadEducation();
		loadLanguage();
		loadExperience();			
				

	
	       });
}


//////////////////////////////////////////////////////List Idproof(edit page)/////////////////////////////////////////////////////////////// 


	getmore();
	var employees;
function getmore()
	  {

		
		$.getJSON(serviceURLHR+'updateidproof.php?emp_id='+id,function(data){
			
					
				   employees = data.employ;
									
					$.each(employees, function(index, employees) 
					{
										   
										$('#paste').append('<p><span id="lblHeadline"><input type="hidden" name="ptype1" id="proof1" value="'+employees.idid+
											 '"><label for="username">ID Prooftype</label><input type="text" name="ptype[]" id="proof" value="'+employees.filetype+'"/><label for="username">Upload id proof</label><span id="lblHeadline"><a style="color:#990000" href="'+baseURL+'upload/image/'+employees.file+'" title="'+employeeslist.file+'" style="style="color:#3366FF"">Download Proof</a><input type="file" id="idproof" size="40" name="idproof[]" value="'+employees.file+'" placeholder="I am New" /><input type="button" name="sub2" id="push1" data-id="'+employees.idid+'" class="pushbtn1" value="submit" style="width:50px"/><input type="button" name="sub2" id="closs" data-id="'+employees.idid+'" class="pushbtn1" value="Delete" style="width:50px"/></p>');	
							});       
							
				

	
	       });
}
 
	$('#closs').live('click',function(){
		$(this).parent().parent().parent().remove();
	var e_id= $(this).attr('data-id');
	Delete1(e_id);
});

function Delete1(e_id){
	//var dataString = $('#updateproduct').serialize();

	//var id=$("#hid").val();
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'edit.php?dell_id='+e_id,  //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){
			//alert(data);
			employeeslist = data.employ1;
				
		}
	});	
}

$('#push1').live('click',function(msg){
	
	var eid= $(this).attr('data-id');
	updateMen(eid);
});


function updateMen(eid){
	//var dataString = $('#updateproduct').serialize();
//alert("hai");
	//var id=$("#hid").val();
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'addmore.php?upd_id='+eid,  //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){
			//alert(data);
			employeeslist = data.employ1;
				
		}
	});	
}



$(document).ready(function()
{ 
	$('#van').live('click',function(){
		$(this).parent().remove();
	
			
	})
	 
   		
 	
	 
	
});
$('#up').live('click',function(msg){
	var eid2= $(this).attr('data-id');
	
	update(eid2);
});
function update(eid2){
	
	
	var currentRef = $('#reference'+eid2);
	
	var refer = currentRef.find('#refer').val();
	var emp = currentRef.find('#emp').val();
	var phno = currentRef.find('#phno').val();
	var email = currentRef.find('#email1').val();
	var from = currentRef.find('#from').val();
	var to = currentRef.find('#to').val();
	var posi = currentRef.find('#posi').val();
	var sal = currentRef.find('#sal').val();
	var rfl = currentRef.find('#rfl').val();
	/*alert(refer);
	alert(emp);
	alert(phno);
	alert(email);
	alert(from);
	alert(to);
	alert(posi);
	alert(sal);
	alert(rfl);*/
	
   $.ajax({
  type: "POST",
  url: "edit.php?up_id="+eid2,
  data: { refer: refer,emp:emp, phno:phno,email:email,from:from,to:to,posi:posi,sal:sal,rfl:rfl }
})
  .done(function( msg ) {
	 // alert(msg);
    alert( "Data Saved: " );
  });


}

$('#registerButton').live('click',function(msg){
	/*var fname = $('#fname').val();
	var dob = $('#dob').val();
	var gender = $('#gender1').val();
	var email = $('#email').val();
	alert('Fname is : '+fname);
	if(fname == ''){
		$('#fname_error').html('This firld is requiered');	
	}
	else{*/
		var eid= $(this).attr('data-id');
		updateMenu1(eid);
	/*}*/
});


function updateMenu1(eid){
	//var dataString = $('#updateproduct').serialize();
//alert("hai");
	//var id=$("#hid").val();
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'addmore.php?upd_id='+eid,  //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){
			//alert(data);
			employeeslist = data.employ1;
				
		}
	});	
}


//////////////////////////////////////////////////////Addmore (edit page)/////////////////////////////////////////////////////////////// 

$(function() 
{
	
var addDiv = $('#here');
var i = $('#here p').size() + 1;
$('#click').live('click', function() 
{
	
	//alert("hai");
$('<p><input type="text" name="ptype[]" id="proof"/><input type="file" id="idproof[]" size="40" name="idproof[]" value="" placeholder="I am New" /><a href="#" id="cut">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#cut').live('click', function() 
{
	
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);
$('#finish').live('click',function(msg){
	proofinsert();
});


function proofinsert(){
	//var dataString = $('#frm1').serialize();
	var formData = new FormData($('form')[0]);
	
    $.ajax({
        url: serviceURLHR + 'edit.php?emp_id='+id,  //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'){
				alert("Item successfully inserted.");
				window.location="list.html";
			}*/
		}
	});	
}


//////////////////////////////////////////////////////Add more Refernce(insert page)/////////////////////////////////////////////////////////////// 

$(function() {

var addDiv = $('#fillup');

var i = $('#fillup p').size() + 1;

 

$('#more').live('click', function() {
	//alert($("#addinput2").html());

$('<p><tr><td  align="left">Company Name</td><td>:</td><td><span id="lblGender"><input type="text" name="work[]" id="work"/></span></td></tr><tr><td  align="left"><span id="lbldb">Address</span></td><td>:</td><td><span id="lblDOB"><textarea name="emp[]" id="emp" /></span></td></tr><tr><td height="28" align="left"  align="left" valign="middle"><span id="lblcomadd">Telephone</span></td><td align="left" valign="middle">:</td><td align="left" valign="middle"><span id="lblAddress"><input type="text" name="Contact[]" id="Contact" /></span></td></tr><tr><td height="28" align="left" valign="middle" align="left"><span id="lblcomadd">Email</span></td><td align="left" valign="middle">:</td><td align="left" valign="middle"><span id="lblAddress"><input type="text" name="send[]" id="send" /></span></td><td height="28" align="left" valign="middle" align="left"><span id="lblcomadd">From</span></td><td align="left" valign="middle">:</td><td align="left" valign="middle"><span id="lblAddress"><input type="date" id="source" name="source[]" /></span></td><td width="1%" height="28" align="left" valign="middle"><span id="lblcomadd">To</span></td><td width="0%" align="left" valign="middle">:</td><td width="14%" align="left" valign="middle"><span id="lblAddress"><input type="date" id="dest" name="dest[]" /></span></td></tr><tr><td><span id="lblcityy">Position</span></td><td>:</td><td><span id="lblCity"><input type="text" name="place[]" id="place" /></span></td><td>Salary</td><td>:</td><td><span id="lblPinCode"><input type="text" name="pay[]" id="pay" /></span></td><td><span id="lblpnumber">Reason for leaving</span></td><td>:</td><td><span id="lblPhone"><input type="text" name="leave[]" id="leave" /><a href="#" id="destro"><img src="images/closebox.png" width="20" height="15" title="Delete" /></a></span></td></tr></p>').appendTo(addDiv);
i++;

 

return false;

});

 

$('#destro').live('click', function() {


$(this).parent().parent().remove();


return false;

});

});	 
$('#subnet').live('click',function(msg){
	updateMenu();
});


function updateMenu(){
	//var dataString = $('#updateproduct').serialize();
//alert("hai");
	//var id=$("#hid").val();
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'edit.php?e_id='+id,  //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){
			//alert(data);
			employeeslist = data.employ1;
				
		}
	});	
}
$('#del').live('click',function(msg){
	$(this).parent().parent().parent().remove();
	var eid= $(this).attr('data-id');
	Delete(eid);
});
function Delete(eid){
	//var dataString = $('#updateproduct').serialize();

	//var id=$("#hid").val();
	var formData = new FormData($('form')[0]);
    $.ajax({
        url: serviceURLHR + 'edit.php?del_id='+eid,  //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){
			//alert(data);
			employeeslist = data.employ1;
				
		}
	});	
}


$(function() 
{

var addDiv = $('#addproductinput1');
var i = $('#addproductinput1 p').size() + 1;
$('#addproductNew11').live('click', function() 
{
	
	
$('<p><label for="noofresumes" class="form-fld-width-2">Document No</label><input type="text" name="docnum[]" id="docnum" class="form-fld-width-3"/><label for="website" class="form-fld-width-2">Wt Carried</label><input name="wtcarried[]" id="wtcarried" class="form-fld-width-3"/><a href="#" id="remproductNeww">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#remproductNeww').live('click', function() 
{
if( i > 1 ) 
{

$(this).parent('p').remove();
i--;
}
return false;
}
);
}
);

$(function() 
{

var addDiv = $('#addinput1');
var i = $('#addinput1 p').size() + 1;
$('#addNew11').live('click', function() 
{
	
	
$('<p><label for="username">Attribute</label><input type="text" id="attributename[]" size="40" name="attributename[]" value="" placeholder="Add Attribute" style="width:150px;"/><select name="attributetype[]" id="attributetype" style="width:150px;"><option value="Personel" >personel</option><option value="functional" >Functional</option></select><a href="#" id="remNeww">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#remNeww').live('click', function() 
{
if( i > 1 ) 
{

$(this).parent('p').remove();
i--;
}
return false;
}
);
}
);


//////////////////////////////////////////////////////Addmore Language(insert page)/////////////////////////////////////////////////////////////// 

$(function() 
{
	
	//var k=0;
var addDiv = $('#radiodiv');
var i = $('#radiodiv p').size() + 1;
$('#radio').live('change', function() 
{
$('<p><label for="Language">Language</label><input type="text" name="other[]" id="other"/><label for="Level">Level</label>'+

'<select name="level1[]" id="level1"><option selected="selected">---select---</option><option>Poor</option><option>Average</option>'+
'<option>Good</option></select><a href="#" id="radio"><img src="images/icon-add.png" width="20" height="15" title="Add More" /></a></br><a href="#" id="withdrow">Remove</a></span></p>').appendTo(addDiv);i++;// k++;
return false;
}

);
$('#withdrow').live('click', function() 
{
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);


//////////////////////////////////////////////////////Addmore Reference(insert page)/////////////////////////////////////////////////////////////// 

$(function() {

var addDiv = $('#addinput2');

var i = $('#addinput2 p').size() + 1;

 

$('#addNew2').live('click', function() {
	//alert($("#addinput2").html());
	
$('#addinput2').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="exp_bdr" "></div><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="164" valign="top"  align="left" class="form-padd-01"><label for="label">Company Name</label></td><td><input type="text" name="refer[]" id="refer"  AUTOCOMPLETE=OFF /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164" align="left" valign="top" class="form-padd-01"><label for="label">Address</label></td><td><textarea name="emp[]" id="emp" /></textarea></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Contact No</label></td><td><input type="text" name="phno[]" id="phno"  AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2"  height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Email</label></td><td><input type="text" name="email1[]" id="email1" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Position</label></td><td><input type="text" name="posi[]" id="posi" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Salary</label></td><td><input type="text" name="sal[]" id="sal" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Reason for leaving</label></td><td><input type="text" name="rfl[]" id="rfl" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">From</label></td><td><input type="text" id="fromdate'+i+'" name="from[]"  class="edit_form_date" AUTOCOMPLETE=OFF readonly/></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top"  class="form-padd-01"><label for="label">To</label></td><td><input type="text" id="todate'+i+'" name="to[]" class="edit_form_date" AUTOCOMPLETE=OFF readonly /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remNew2">Remove</a></td></tr></table>');

i++;

 

return false;

});

 

$('#remNew2').live('click', function() {

	$(this).parents('table').prev('div').remove();									
		$(this).parents('table').remove();
		var count = $('#addinput2').children('table').length;
		if(count==0)
		{
				$('#addinput2').append('<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Company Name</label></td><td><input type="text" name="refer[]" id="refer"  AUTOCOMPLETE=OFF /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Address</label></td><td><textarea name="emp[]" id="emp" /></textarea></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Contact No</label></td><td><input type="text" name="phno[]" id="phno"  AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Email</label></td><td><input type="text" name="email1[]" id="email1" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Position</label></td><td><input type="text" name="posi[]" id="posi" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Salary</label></td><td><input type="text" name="sal[]" id="sal" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">Reason for leaving</label></td><td><input type="text" name="rfl[]" id="rfl" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top" class="form-padd-01"><label for="label">From</label></td><td><input type="text" id="from" name="from[]"  align="left" class="edit_form_date" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  align="left" valign="top"  align="left" class="form-padd-01"><label for="label">To</label></td><td><input type="text" id="to" name="to[]" class="edit_form_date" AUTOCOMPLETE=OFF /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remNew2">Remove</a></td></tr></table>');

		}	
return false;
});

});	 


/*$(function() 
{
	
var addDiv = $('#resum');
var i = $('#resum p').size() + 1;
$('#res').live('click', function() 
{
	
	
$('<p> <label for="country">Upload Resume</label><input type="file" id="resume" size="20" name="resume"  value="" placeholder="Input Value" /><a href="#" id="rems">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#rems').live('click', function() 
{
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);*/
$(function() 
{
	
var addDiv = $('#poto');
var i = $('#poto p').size() + 1;
$('#changes').live('click', function() 
{
	
	
$('<p><label for="country">Upload Photo</label> <input type="file" name="photo" id="photo"/><a href="#" id="dels">Remove</a> </p>').appendTo(addDiv);
i++;
return false;
}
);
$('#dels').live('click', function() 
{
if( i > 1 ) 
{
//alert($("#addinput1").html());
$(this).parents('p').remove();
i--;
}
return false;
}
);
}
);


function ValidateEmail(email) {
        var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        return expr.test(email);
    };



function validation_employeeform(){/*
	
	var validations='';
			if ($("#fname").val().length == 0) {
				validations='Please enter first name\n';
               // alert("Please enter first name");
              //  return false;
            }
            if ($("#mname").val().length == 0) {
				validations+='Please enter middle name\n';              
				 // alert("Please enter your middle name");
                //return false;
            }

            if ($("#lname").val().length == 0) {
				validations+='Please enter your last name\n';   
              //  alert("Please enter your last name");
              //  return false;
            }

            if ($("#address").val().length == 0) {
				validations+='Please enter your address\n ';   
              //  alert("Please enter your address ");
              //  return false;
            }
			
            if ($('#country option:selected').val() == '---select---') {
				validations+='Please select country\n ';  
               // alert('Please select country');
                //return false;
            }

            if ($('#state option:selected').val() == '---select---') {
				validations+='Please select state\n '; 
                //alert('Please select state');
                //return false;
            }
			 if ($("#zip").val().length == 0) {
				 validations+='Please select state\n '; 
                //alert("Please enter your zipCode ");
                //return false;
            }
			if ($("#zip").val().length != 6) {
				validations+='Please enter 6 digit zipCode\n ';
                //alert("Please enter 6 digit zipCode.");
                //return false;
            }
			
			
            
                if ($('#dob').val().length == 0) {
					validations+='Please enter your date of birth\n ';
                    //alert('Please enter your date of birth');
                   // return false;
                }
           
			if ($("#phone").val().length == 0) {
				validations+='Please enter your phone number\n ';
               // alert("Please enter your phone number");
                //return false;
            }
			
				var H=$('#phone').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
					 validations+='Phone Number should contain Numeric Values...!\n ';
				//alert("Phone Number should contain Numeric Values...!");
				
				//return false; 
				}

            if ($("#mobile").val().length == 0) {
				validations+='enter your mobile\n ';
                //alert("Please enter your mobile");
                //return false;
            }
			
				var H=$('#mobile').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
					 validations+='Mobile Number should contain Numeric Values...!\n ';
				//alert("Mobile Number should contain Numeric Values...!");
				
				//return false; 
				}
				

            if ($("#mobile").val().length != 10) {
				 validations+='Please enter 10 digit mobile no.\n ';
                //alert("Please enter 10 digit mobile no.");
               // return false;
            }
			 if ($('#gender option:selected').val() == '---select---') {
				 validations+='Please select gender\n ';
                //alert('Please select gender');
               // return false;
            }
			
			if (!ValidateEmail($("#email").val())) {
				 validations+='Invalid email address.\n ';
				//alert("Invalid email address.");
				//return false;
			}
			
			//if($("#photo").val() !=undefined)
//			{
//			if ($("#photo").val().length == 0) {
//				 validations+='Please upload your photo.\n ';
//               // alert("Please upload your photo");
//               // return false;
//            }
//			}
//			if($("#resume").val() !=undefined)
//			{
//		if ($("#resume").val().length == 0) {
//			validations+='Please upload your resume.\n ';
//                //alert("Please upload your resume");
//                //return false;
//            }
//			}
			
			if ($("#proof").val().length == 0) {
				validations+='Please enter your Idproof type.\n ';
                //alert("Please enter your Idproof type");
                //return false;
            }
	
			if ($("#p_new").val().length == 0) {
				validations+='Please upload your Idproof.\n ';
               // alert("Please upload your Idproof");
               // return false;
            }
			if(validations!=''){
				alert(validations);
               return 0;
			}
			
*/}
function validation_employeeform1(){/*
	var validations='';

		if ($("#rname").val().length == 0) {
			validations+='Please enter  Reference name.\n ';
               // alert("Please enter  Reference name");
               // return false;
            }
			if ($("#relation").val().length == 0) {
				validations+='Please enter  relation.\n ';
               // alert("Please enter  relation");
               // return false;
            }
			if ($("#contact").val().length == 0) {
				validations+='Please enter your contact no.\n ';
                //alert("Please enter your contact no");
               // return false;
            }
			
				var H=$('#contact').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
					 validations+='contact Number should contain Numeric Values...!\n ';
				//alert("Phone Number should contain Numeric Values...!");
				
				//return false; 
				}
			if ($("#loc").val().length == 0) {
				validations+='Please enter your location.\n ';
                //alert("Please enter your location");
               // return false;
            }
			  if ($('#pos2 option:selected').val() == '--select--') {
				 validations+='Please select Designation\n ';
                //alert('Please select gender');
               // return false;
            }
			if ($("#Salary").val().length == 0) {
				validations+='Please Select Salary.\n ';
                //alert("Please Select Workplace");
               // return false;
            }
			if ($("#jloc").val().length == 0) {
				validations+='Please Select Workplace.\n ';
                //alert("Please Select Workplace");
               // return false;
            }
			  if ($('#date').val().length == 0) {
				  validations+='Please enter Date.\n ';
                   // alert('Please enter Date');
                    //return false;
                }
			if ($("#day").val().length == 0) {
				validations+='Please enter  your Working Days.\n ';
                //alert("Please enter your Working Days");
               // return false;
            }
			if(validations!=''){
				alert(validations);
               return 0;
			}
*/}

function validation_employeeform2(){/*
	var validations='';


			if ($("#refer").val().length == 0) {
				validations+='Please enter  Company name.\n ';
                //alert("Please enter  Company name");
               // return false;
            }
			if ($("#phno").val().length == 0) {
				validations+='Please enter  your contact Number.\n ';
                //alert("Please enter  Phone Number");
               // return false;
            }
			var H=$('#phno').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
					 validations+='Phone Number should contain Numeric Values...!\n ';
				//alert("Phone Number should contain Numeric Values...!");
				
				//return false; 
				}
				//if (!ValidateEmail($("#email1").val())) {
				//	validations+='Please enter email address.\n ';
				//alert("Invalid email address.");
				//return false;
			//}
			
			
			if ($("#posi").val().length == 0) {
				validations+='Please enter  position.\n ';
               // alert("Please enter  position");
                //return false;
            }
			if ($("#sal").val().length == 0) {
				validations+='Please enter  your Working Days.\n ';
                //alert("Please enter  Salary");
               // return false;
            }
			if ($("#rfl").val().length == 0) {
				validations+='Please enter  Reason for leaving.\n ';
                //alert("Please enter  Reason for leaving");
                //return false;
            }
			if(validations!=''){
				alert(validations);
               return 0;
			}
*/}

 function fnRecruitmentPage() {
	 var recsource = $('#recsource').val();
	 var department = $('#department').val();
	 var recdesg = $('#recdesg').val();
	

	 var resume = $('#resume').val();
	 if(recsource == ''){
		alert('Source is Required') ;$('#recsource').focus();
	 }else if(department == ''){
		alert('Department is Required') ;$('#department').focus();
	 }else if(recdesg == ''){
		alert('Designation is Required') ;$('#recdesg').focus();
	 }else if(resume == ''){
		alert('Resume is Required') ;$('#resume').focus();
	 }else{
		//insert_recruitment();	
		$('#refrm1').submit();
		setTimeout(function(){  $('#refrm1').submit(); },100);
	 }
	 /*
     if ($("#fname").val().length == 0) {
    	alert("Please enter first name");
        return false;
     }
	 if ($("#mname").val().length == 0) {
     	alert("Please enter your middle name");
        return false;
     }

            if ($("#lname").val().length == 0) {
                alert("Please enter your last name");
                return false;
            }

            if ($("#address").val().length == 0) {
                alert("Please enter your address ");
                return false;
            }
			
            if ($('#country option:selected').val() == '---select---') {
                alert('Please select country');
                return false;
            }

            if ($('#state option:selected').val() == '---select---') {
                alert('Please select state');
                return false;
            }
			 if ($("#zip").val().length == 0) {
                alert("Please enter your zipCode ");
                return false;
            }
			if ($("#zip").val().length != 6) {
                alert("Please enter 6 digit zipCode.");
                return false;
            }
			
			
            
                if ($('#dob').val().length == 0) {
                    alert('Please enter your dob');
                    return false;
                }
           
			if ($("#phone").val().length == 0) {
                alert("Please enter your phone number");
                return false;
            }
			
				var H=$('#phone').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}

            if ($("#mobile").val().length == 0) {
                alert("Please enter your mobile");
                return false;
            }
			
				var H=$('#mobile').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Mobile Number should contain Numeric Values...!");
				
				return false; 
				}
				

            if ($("#mobile").val().length != 10) {
                alert("Please enter 10 digit mobile no.");
                return false;
            }
			 if ($('#gender option:selected').val() == '---select---') {
                alert('Please select gender');
                return false;
            }
				
			if (!ValidateEmail($("#email").val())) {
				alert("Invalid email address.");
				return false;
			}
				/*if($("#photo").val() !=undefined)
			{
			if ($("#photo").val().length == 0) {
                alert("Please upload your photo");
                return false;
            }
			}
			if($("#resume").val() !=undefined)
			{
		if ($("#resume").val().length == 0) {
                alert("Please upload your resume");
                return false;
            }
			}*/
			
			/*if ($("#proof").val().length == 0) {
                alert("Please enter your Idproof type");
                return false;
            }
	
			if ($("#p_new").val().length == 0) {
                alert("Please upload your Idproof");
                return false;
            }
			if ($("#rname").val().length == 0) {
                alert("Please enter  Reference name");
                return false;
            }
			if ($("#relation").val().length == 0) {
                alert("Please enter  relation");
                return false;
            }
			if ($("#contact").val().length == 0) {
                alert("Please enter your contact no");
                return false;
            }
			if ($("#loc").val().length == 0) {
                alert("Please enter your location");
                return false;
            }*/
			/*if($('input[name=pa]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#jloc").val().length == 0) {
                alert("Please Select Workplace");
                return false;
            }
			  if ($('#date').val().length == 0) {
                    alert('Please enter Date');
                    return false;
                }
			if ($("#day").val().length == 0) {
                alert("Please enter your Working Days");
                return false;
            }
			if($('input[name=level]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#course").val().length == 0) {
                alert("Please Select your course");
                return false;
            }
			if($('input[name=se]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#refer").val().length == 0) {
                alert("Please enter  Company name");
                return false;
            }
			if ($("#phno").val().length == 0) {
                alert("Please enter  Phone Number");
                return false;
            }
			var H=$('#phno').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}
				if (!ValidateEmail($("#email1").val())) {
				alert("Invalid email address.");
				return false;
			}
			
			
			if ($("#posi").val().length == 0) {
                alert("Please enter  position");
                return false;
            }
			if ($("#sal").val().length == 0) {
                alert("Please enter  Salary");
                return false;
            }
			if ($("#rfl").val().length == 0) {
                alert("Please enter  Reason for leaving");
                return false;
            }
			alert('rty');*/
            
		}
		

$(function(){
	$('#refrm1').attr('action',serviceURLHR + 'recruitmentinsert.php');
});
var Submiting = 0;	
$('#refrm1').live('submit',function(){
/*	$('#busy').show();
	var formData = new FormData($('#frm1')[0]);
	
    $.ajax({
        url: serviceURLHR + 'recruitmentinsert.php',  //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){
				$('#busy').hide();
				alert("Resumes successfully inserted.");
				window.location="recruitment-list.php";
		}
	});*/	
	
	
	
	
	 var noresumes = $('#noresumes').val();
	var progressbox     = $('#progressbox');
	 var progressbar     = $('#progressbar');
	 var statustxt       = $('#statustxt');
	 var completed       = '0%';
	
	 if(Submiting == 0){
	  Submiting =1;
	 $(this).ajaxForm({
		  beforeSend: function() {
		  // console.log("beforeSend");
		   progressbox.show(); //show progressbar
		   progressbar.width(completed); //initial value 0% of progressbar
		   statustxt.html(completed); //set status text
		   statustxt.css('color','#000'); //initial color of status text
		   
		  },
		  uploadProgress: function(event, position, total, percentComplete) {
		   progressbar.width(percentComplete + '%') //update progressbar percent complete
		   statustxt.html(percentComplete + '%'); //update status text
		  console.log(percentComplete);
		   if(percentComplete>50)
			{
			 statustxt.css('color','#fff'); //change status text to white after 50%
			}
	  	// console.log(percentComplete);
	  	},
		  success: function() {
		   alert("Resumes successfully inserted.");
		  window.location="recruitment-list.php";
		  },
		  complete: function() {
		   console.log('done.');
		  }
	
	  });
	 }
	return false; 
});

function fnTimesheetPage() {
	
	  insert_timesheet();
		}
function insert_timesheet(){
	//var dataString = $('#frm1').serialize();
	$('#busy').show();
	var formData = new FormData($('form')[0]);
	//alert(formData);
	//alert(serviceURLHR);
    $.ajax({
        url: serviceURLHR + 'timesheetinsert.php',  //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){
				$('#busy').hide();
				//if(data=='success'){
				alert("Timesheet Successfully Updated.");
				window.location="timesheet-adjustable-form.php";
			//}
		}
	});	
}


function fnProductivityPage() {
	 /*
	
            if ($("#fname").val().length == 0) {
                alert("Please enter first name");
                return false;
            }
            if ($("#mname").val().length == 0) {
                alert("Please enter your middle name");
                return false;
            }

            if ($("#lname").val().length == 0) {
                alert("Please enter your last name");
                return false;
            }

            if ($("#address").val().length == 0) {
                alert("Please enter your address ");
                return false;
            }
			
            if ($('#country option:selected').val() == '---select---') {
                alert('Please select country');
                return false;
            }

            if ($('#state option:selected').val() == '---select---') {
                alert('Please select state');
                return false;
            }
			 if ($("#zip").val().length == 0) {
                alert("Please enter your zipCode ");
                return false;
            }
			if ($("#zip").val().length != 6) {
                alert("Please enter 6 digit zipCode.");
                return false;
            }
			
			
            
                if ($('#dob').val().length == 0) {
                    alert('Please enter your dob');
                    return false;
                }
           
			if ($("#phone").val().length == 0) {
                alert("Please enter your phone number");
                return false;
            }
			
				var H=$('#phone').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}

            if ($("#mobile").val().length == 0) {
                alert("Please enter your mobile");
                return false;
            }
			
				var H=$('#mobile').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Mobile Number should contain Numeric Values...!");
				
				return false; 
				}
				

            if ($("#mobile").val().length != 10) {
                alert("Please enter 10 digit mobile no.");
                return false;
            }
			 if ($('#gender option:selected').val() == '---select---') {
                alert('Please select gender');
                return false;
            }
				
			if (!ValidateEmail($("#email").val())) {
				alert("Invalid email address.");
				return false;
			}
				/*if($("#photo").val() !=undefined)
			{
			if ($("#photo").val().length == 0) {
                alert("Please upload your photo");
                return false;
            }
			}
			if($("#resume").val() !=undefined)
			{
		if ($("#resume").val().length == 0) {
                alert("Please upload your resume");
                return false;
            }
			}*/
			
			/*if ($("#proof").val().length == 0) {
                alert("Please enter your Idproof type");
                return false;
            }
	
			if ($("#p_new").val().length == 0) {
                alert("Please upload your Idproof");
                return false;
            }
			if ($("#rname").val().length == 0) {
                alert("Please enter  Reference name");
                return false;
            }
			if ($("#relation").val().length == 0) {
                alert("Please enter  relation");
                return false;
            }
			if ($("#contact").val().length == 0) {
                alert("Please enter your contact no");
                return false;
            }
			if ($("#loc").val().length == 0) {
                alert("Please enter your location");
                return false;
            }*/
			/*if($('input[name=pa]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#jloc").val().length == 0) {
                alert("Please Select Workplace");
                return false;
            }
			  if ($('#date').val().length == 0) {
                    alert('Please enter Date');
                    return false;
                }
			if ($("#day").val().length == 0) {
                alert("Please enter your Working Days");
                return false;
            }
			if($('input[name=level]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#course").val().length == 0) {
                alert("Please Select your course");
                return false;
            }
			if($('input[name=se]:checked').length<=0)
			{
			 alert("No radio checked")
			 return false;
			}
			if ($("#refer").val().length == 0) {
                alert("Please enter  Company name");
                return false;
            }
			if ($("#phno").val().length == 0) {
                alert("Please enter  Phone Number");
                return false;
            }
			var H=$('#phno').val();
				if(isNaN(H)|| H.indexOf(" ")!=-1)
				 {
				alert("Phone Number should contain Numeric Values...!");
				
				return false; 
				}
				if (!ValidateEmail($("#email1").val())) {
				alert("Invalid email address.");
				return false;
			}
			
			
			if ($("#posi").val().length == 0) {
                alert("Please enter  position");
                return false;
            }
			if ($("#sal").val().length == 0) {
                alert("Please enter  Salary");
                return false;
            }
			if ($("#rfl").val().length == 0) {
                alert("Please enter  Reason for leaving");
                return false;
            }
			alert('rty');*/
            insert_productivity();
		}

function insert_productivity(){
	//var dataString = $('#frm1').serialize();
	
	
	var formData = new FormData($('form')[0]);
		
	//alert(serviceURLHR);
    $.ajax({
        url: serviceURLHR + 'productivityinsert.php',  //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'){
				alert("Item successfully inserted.");
				//window.location="productivity-list.php";
			//}
		}
	});	
}

/*jQuery('#wtcarried').live('keyup',function(){ 
							 
    alert($(this).val());
  });*/

	

   $(document).ready(function(){
 
        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".form-fld-width-3").live('keyup',function(){
                calculateSum();
            });
    
    });
 
    function calculateSum() { 
	     var sum = 0;
        //iterate through each textboxes and add the values
        $(".form-fld-width-3").each(function() {
 			//alert(this.value);
			//alert(this.value.length);
            //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum += parseFloat(this.value);
            }
 
        });
        //.toFixed() method will roundoff the final sum to 2 decimal places
		$(".sum").html(sum.toFixed(2));
       	$(".sum").val(sum.toFixed(2));
    }

$('#remproductNeww').live('click', function() 
	{
		calculateSum();	
	});

function fnPerformancePage(){
	insert_performance();
}

function insert_performance(){
	//var dataString = $('#frm1').serialize();

	var formData = new FormData($('form')[0]);
	//alert(formData);
	//alert(serviceURLHR);
    $.ajax({
        url: serviceURLHR + 'performanceinsert.php',  //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){
			alert("Item successfully inserted.");
			location.reload(true);	
		}
	});	
}

function fill_qst_subordinate(){
	var datastring = $("#fill_qst_frm1").serialize();	
	$.post(serviceURLHR + "performanceinsert.php?action=fillSubordinate",datastring,function(data){   
		alert("Item successfully inserted.");
		location.reload(true);
	},'json');
}

function fnPerformanceview11(){
	
}

	function fnPerformancefill(){
		//$('.productivity_list').hide('blind',500,function(){ $(this).remove();})		
		//$('.contentremark').hide('blind',500,function(){ $(this).remove();})	
		$('#form-wrapper').append('<div class="content">'+
								  '<div id="form-content"><div id="form-wrapper">'+
								  '<div id="steps"><form>'+
								  '<fieldset class="step"><legend><translate>Fill Performance Questionnaire</translate></legend>'+
								  '<div class="view-button-tab">'+
								  '</div></fieldset></form></div></div></div></div>');
		$('#form-wrapper').find('#steps').hide('blind',500); 
		$.getJSON(serviceURLHR+"fill_perfomance.php",function(data){
		profile = data.qstperformance;
		$('#form-wrapper').append('<form action="" method="post" enctype="multipart/form-data" id="fill_qst_frm1" name="fill_qst_frm1"><div class="productivity_list">'+
		 						  '<ul class="productivity_ul">'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:80px;"><translate>No.</translate></li>'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:150px;"><translate>Date Added</translate></li>'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:150px;"><translate>Perfomance No.</translate></li>'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:200px;"><translate>Question</translate></li>'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:150px;"><translate>Attribute</translate></li>'+
								  '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;width:150px;"><translate>Rate</translate></li>'+
								  '</ul>'+
								  '</div>');
			$.each(profile, function(index, profile){ 
			$('.productivity_list').append('<ul class="productivity_ul">'+
				'<li class="employee-row-01" style="width:80px;"><input type="hidden" name="qst_id[]" id="qst_id" value='+profile.question_id+'>'+ k + '</li>'+
				'<li class="employee-row-01" style="width:150px;">'+ new Date(profile.perform_addate).format("dd-mm-yyyy")+ '</li>'+
				'<li class="employee-row-01 showperformdoclist" style="width:150px;" >'+ profile.perform_unique+ '</li>'+
				'<li class="employee-row-01 showperformdoclist" style="width:200px;" >'+ profile.question+ '</li>'+
				'<li class="employee-row-01 showperformdoclist" style="width:150px;" >'+ profile.attributes+ '</li>'+
				'<li class="employee-row-01 showperformdoclist" style="width:150px;" ><select name="rate_subordinate[]"><option value="">--select--</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></select></li>'+
				'</ul>');	
				itemCount = profile.totalrows;
				k++;
			});	
			$('#form-wrapper').append('</form><br /><p class="submit"><button id="registerButton2" class="add-bt-3" type="button" onclick="fill_qst_subordinate()" style="width:150px;height:50px;">Finish</button></p>');
		});
	}
	
	
	function fnPerformanceview(){
		
			
		 $('.productivity_list').hide('blind',500,function(){ $(this).remove();})		
		 $('.contentremark').hide('blind',500,function(){ $(this).remove();})	
		 $('#form-wrapper').append('<div class="content">'+
								  '<div id="form-content"><div id="form-wrapper">'+
								  '<div id="steps"><form>'+
								  '<fieldset class="step"><legend>Add Performance Rating & Remark</legend>'+
								  '<div class="view-button-tab">'+
								  '<button id="registerButton2" class="view-button" type="button" style="float:left; clear:inherit; margin-right:15px;" onclick="fnPerformanceadd()">Add Performance Review</button>'+
								  '<button id="registerButton2" class="view-button" type="button" style="float:left;  clear:inherit;" onclick="fnPerformanceRemarkview()">Add Description</button>'+
								  '</div></fieldset></form></div></div></div></div>');
		 $('#form-wrapper').find('#steps').hide('blind',500); 
		 $.getJSON(serviceURLHR+"getperformance.php",function(data){
				   //$('.productivityGrid').html('');	
				   profile = data.getperformance;
				   $('#form-wrapper').append('<div class="productivity_list">'+
												 '<ul class="productivity_ul">'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>No</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Prd No</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Daterate</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Employee Name</translate></li>'+
												 '</ul>'+
												 '</div>');
					/*'<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01">No</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Date</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Employee Name</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Branch</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Wt Carried</td>'+
					  '</tr></table>');*/
				  
					$.each(profile, function(index, profile){ 
							//tot = parseInt(tot)+parseInt(profile.prd_wt_carried);
						$('.productivity_list').append('<ul class="productivity_ul">'+
								'<li class="employee-row-01" style="width=10px;">'+ k + '</li>'+
								'<li class="employee-row-01">'+ profile.perform_unique+ '</li>'+
								'<li class="employee-row-01">'+ new Date(profile.perform_addate).format("dd-mm-yyyy")+ '</li>'+
								'<li class="employee-row-01 showperformdoclist"  data-id="'+profile.perform_unique_id+'">'+ profile.e_fname+ '</li>'+
							'</ul>');	
					itemCount = profile.totalrows;
					//tot = tot+profile.prd_wt_carried;
					k++;
					});	//'</tbody></table>';
					
			});
		 
		 
}

function performance_detailshw(){
	$this = $(this);
	$('.performance-grid').hide("blind",300,function(){ $(this).remove() });
	//alert($this);
	$currentRow = $this.parent();
	//alert($currentRow);
	console.log($currentRow);
	var did = $(this).attr('data-id');
	
	//alert(did);
	if($('.Grid_'+did).length){
		
	}else{
	
	$currentRow.after('<form name="formrate" id="formrate" method="post"><div class="testdiv" style="display:none"><table width="75%" border="0" cellspacing="0" class="performance-grid Grid_'+did+'" cellpadding="0">'+
					  '<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Attribute Name</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Description</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Rating</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Remark</translate></td>'+
					  '</tr>'+
					  '</table></div></form>');
	
	$.getJSON(serviceURLHR+"getperformance_details.php?prd_id="+did,function(data){
		getperform = data.getperformancedts;
		//alert(imdsupervisor);
		var k = 1;
		var perform_unique_id;
		$.each(getperform, function(index, getperform) {
								//	 
				    	$('.Grid_'+did).append('<tr>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+ k + '</td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+getperform.attribute_name+'</td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+getperform.perform_desc+'</td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+	
					   '<input type="text" name="rateaval_'+k+'" id="rateaval_'+k+'" value="'+getperform.perform_rate+'"/></td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+	
					   '<input type="hidden" name="performid_'+k+'"" value="'+getperform.perform_id+'"/>'+
					   '<input type="text" style="width:100px;" name="remarkaval_'+k+'" id="remarkaval_'+k+'" value="'+getperform.perform_remark+'"/>'+'</td>'+
					   '</tr>');
						
						
				perform_unique_id	=getperform.perform_unique_id;	
						
			k++;				
		});	
		
		$('.Grid_'+did).append('<tr>'+
							   '<td align="center" valign="middle" class="employee-row-01"></td>'+
							   '<td align="center" valign="middle" class="employee-row-01"></td>'+
					    '<td align="center" valign="middle" class="employee-row-01">'+
						'<td align="center" valign="middle" class="employee-row-01">'+
						'<td align="center" valign="middle" class="employee-row-01">'+
						'<input type="hidden" value="'+k+'" name="perform_totrow"/>'+
						'<input type="button" name="sub2" id="push1" class="pushbtn1" onclick="fnPerformanceupdateRating()" value="submit" style="width:50px"/>'+'</td>'+
					   '</tr>');
		$('.testdiv').show('blind',300);
	});
	}
	
}



function fnPerformanceupdateRating(){
	var datastring = $("#formrate").serialize();	
 $.post(serviceURLHR + "performance_rating_update.php?action=updateprofile",datastring,function(data){   
		alert("Item successfully inserted.");
		$('.performance-grid').hide('blind',300);  
		
 },'json');
}

function fnPerformanceadd(){
	window.location="performance-review-form.php";
}

function fnPerformanceRating(){
	var datastring = $("#formrate").serialize();	
 $.post(serviceURLHR + "performance_rating_insert.php?action=updateprofile",datastring,function(data){   
		alert("Item successfully inserted.");
		$('.performance-grid').hide('blind',300);  
		
 },'json');
}

	function fnPerformanceRemarkview(){
		
		$('.productivity_list').hide('blind',500,function(){ $(this).remove();})	
		$('#steps').hide('blind',500,function(){ $(this).remove();})	
		
		 //$('.contentremark').hide('blind',500,function(){ $(this).remove();})	
		// $('.content').hide('blind',500,function(){ $(this).remove();})	
		// $('.content').hide('blind',500,function(){ $(this).remove();})
		$('#form-wrapper').append('<div class="contentremark">'+
								  '<div id="form-content"><div id="form-wrapper">'+
								  '<div id="steps"><form>'+
								  '<fieldset class="step"><legend>Add Description</legend>'+
								  '<div class="view-button-tab">'+
								  '<button id="registerButton2" class="view-button" type="button" style="float:left; clear:inherit; margin-right:15px;" onclick="fnPerformanceadd()">Add Performance Review</button>'+
								  '<button id="registerButton2" class="view-button" type="button" style="float:left;  clear:inherit;" onclick="fnPerformanceview()">Add Performance Rating & Remark</button>'+
								  '</div></fieldset></form></div></div></div></div>');
		 
		 $('#form-wrapper').find('#steps').hide('blind',500);
		 $.getJSON(serviceURLHR+"getperformance_remark.php",function(data){
				   //$('.productivityGrid').html('');	
				   profile = data.getperformance;
				   $('#form-wrapper').append('<div class="productivity_list" style="padding-left:25px;">'+
												 '<ul class="productivity_ul">'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>No</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Prd No</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Date</translate></li>'+
												 '<li class="employee-row-01" style="background:#026091; color:#fffff; font-size:15px; font-weight:bold;"><translate>Employee Name</translate></li>'+
												 '</ul>'+
												 '</div>');
					/*'<table width="100%" border="0" cellspacing="0" class="Grid" cellpadding="0">'+
					'<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01">No</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Date</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Employee Name</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Branch</td>'+
					  '<td align="center" valign="middle" class="employee-row-01">Wt Carried</td>'+
					  '</tr></table>');*/
				  
					$.each(profile, function(index, profile){ 
							//tot = parseInt(tot)+parseInt(profile.prd_wt_carried);
						$('.productivity_list').append('<ul class="productivity_ul">'+
								'<li class="employee-row-01" style="width=10px;">'+ k + '</li>'+
								'<li class="employee-row-01">'+ profile.perform_unique+ '</li>'+
								'<li class="employee-row-01">'+ new Date(profile.perform_addate).format("dd-mm-yyyy")+ '</li>'+
								'<li class="employee-row-01 showperformremarkdoclist"  data-id="'+profile.perform_unique_id+'">'+ profile.e_fname+ '</li>'+
							'</ul>');	
					itemCount = profile.totalrows;
					//tot = tot+profile.prd_wt_carried;
					k++;
					});	//'</tbody></table>';
					
			});
		 
		 
}




function performance_Remarkdetailshw(){
	
	$this = $(this);
	$('.performance-grid').hide("blind",300,function(){ $(this).remove() });
	//alert($this);
	$currentRow = $this.parent();
	//alert($currentRow);
	console.log($currentRow);
	var did = $(this).attr('data-id');
	
	//alert(did);
	if($('.Grid_'+did).length){
		
	}else{
	
	$currentRow.after('<form name="formrate" id="formrate" method="post"><div class="testdiv" style="display:none"><table width="75%" border="0" cellspacing="0" class="performance-grid Grid_'+did+'" cellpadding="0">'+
					  '<tr>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>No</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Attribute Name</translate></td>'+
					  '<td align="center" valign="middle" class="employee-row-01"><translate>Description</translate></td>'+
					  '</tr>'+
					  '</table></div></form>');
	
	$.getJSON(serviceURLHR+"getperformance_details.php?prd_id="+did,function(data){
		getperform = data.getperformancedts;
		//alert(imdsupervisor);
		var k = 1;
		var perform_unique_id;
		$.each(getperform, function(index, getperform) {
								//	 
				    	$('.Grid_'+did).append('<tr>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+ k + '</td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+getperform.attribute_name+'</td>'+
					   '<td align="center" valign="middle" class="employee-row-01">'+	
					   '<input type="hidden" name="performid_'+k+'"" value="'+getperform.perform_id+'"/>'+
					   '<input type="text" style="width:100px;" name="descval_'+k+'" id="descval_'+k+'" value="'+getperform.perform_desc+'"/>'+'</td>'+
					   '</tr>');
						
						
				perform_unique_id	=getperform.perform_unique_id;	
						
			k++;				
		});	
		
		$('.Grid_'+did).append('<tr>'+
							   '<td align="center" valign="middle" class="employee-row-01"></td>'+
							   '<td align="center" valign="middle" class="employee-row-01"></td>'+
							   '<td align="center" valign="middle" class="employee-row-01">'+
						'<input type="hidden" value="'+k+'" name="perform_totrow"/>'+
						'<input type="button" name="sub2" id="push1" class="pushbtn1" onclick="fnPerformanceRating()" value="submit" style="width:50px"/>'+'</td>'+
					   '</tr>');
		$('.testdiv').show('blind',300);
	});
	}
	
}



/*langugae selection */

function selectlanguage()
{ 
	
	$.ajax({
	   url: serviceURLHR+"language.php?action=adm_lang",
	   success: function(data){ 
		 $(".list_lang tr:last select[name='lang[]']").html(data);
		  //$("select[name='lang[]']").html(data);
	   }
   });
}
function languageselected()
{   
	//alert('SEL ID is : '+lang_index);
	//alert('SEL VALUE is : '+language_selected);
	//sleep(20); 
	 setTimeout($("#lang"+lang_index).val(language_selected),10000);
	//alert('Val is : '+$("#lang"+lang_index).val());
}

/*************  Add More Language *************/

$(function() {
		   
	$('#addNewLang').live('click', function() { 
						
		 Rows = ($('table#myTable tr:last').index() + 1);				
		 $('.list_lang').append('<tr class="add-lang"><td width="20%" align="left" valign="top">&nbsp;</td><td align="left" valign="top"><input type="text" name="lang[]" id="lang" ></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_rd'+Rows+'" id="radio_eng_rd'+Rows+'" value="1" class="reads" /></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_wt'+Rows+'" id="radio_eng_wt'+Rows+'" value="1" class="writs" /></td><td align="left" valign="middle"><input type="checkbox" name="radio_eng_sk'+Rows+'" id="radio_eng_sk'+Rows+'" value="1" class="spks"/></td><td><a href="#" class="remLang" data-id="'+Rows+'">Remove</a></td><td><input type="hidden" id="emp_lang_id'+Rows+'" name="emp_lang_id'+Rows+'" value="" class="emplngs"></td></tr>');
			//selectlanguage();
			
			return false;
	});

});	 

	/*remove language*/
	$('.remLang').live('click', function() {  
			var emplang	= $(this).closest('td').next().find('input').val();
			var ids=$(this).attr('data-id');
			var ids=Number(ids);
			if(emplang!=""){
				if(confirm("Are you sure want to delete language?")){
					$.ajax({
					   url: serviceURLHR+"language.php?action=rm_lang&id="+emplang,
					   success: function(data){ 
					   		var count = $('.list_lang tr').length;
							if(count==1)
							$('#addNewLang').trigger("click");
					   }
				   });
				   $(this).parents('tr').remove();
				}
				
				 $('element').val('Changed Value');
				
				
				Rows = ($('table#myTable tr:last').index() + 1);
					for(q=ids;q<=Rows;q++)
					{  var qq=q-1; 
						$('#radio_eng_rd'+q).attr('name','radio_eng_rd'+qq);
						$('#radio_eng_wt'+q).attr('name','radio_eng_wt'+qq);
						$('#radio_eng_sk'+q).attr('name','radio_eng_sk'+qq);
						$('#emp_lang_id'+q).attr('name','emp_lang_id'+qq);
						
					}
			} 
			else{
				
				$(this).parents('tr').remove();
				var count = $('.list_lang tr').length; 
				if(count==1)
				$('#addNewLang').trigger("click");
				
			}
			return false;
	});

	
	$('#addNewQst1').live('click', function() {
											
		$('#addinputqst1').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr"></div><table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Question</label></td><td><input name="question[]" type="text"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Attribute</label></td><td><select name="attributetype[]" type="text" class="dyn_attribute"  ></select><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remNewQst2">Remove</a></td></tr><tr><td colspan="2" height="8"></td></tr></table>');
		
		$.getJSON(serviceURLHR + 'immediateperformancesupervisor.php?action=load_attribute',function(data){
			imdsupervisor = data.attribute;
			$('.dyn_attribute').empty();
			$.each(imdsupervisor, function(index, imdsupervisor) {
				$('.dyn_attribute').append('<option value="'+imdsupervisor.perfom_attr_id+'">'+imdsupervisor.attributes	+'</option>');
			});	
		});	
		
		return false;
		
	});
	
	
	$('#remNewQst2').live('click', function() {
		$(this).parents('table').prev('div').remove();									
		$(this).parents('table').remove();
		var count = $('#addinputqst1').children('table').length;
		if(count==0)
		{
			$('#addinputqst1').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr"></div><table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Question</label></td><td><input name="question[]" type="text"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Attribute</label></td><td><select name="attributetype[]" type="text" class="dyn_attribute"  ></select><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remNewQst2">Remove</a></td></tr><tr><td colspan="2" height="8"></td></tr></table>');
			$.getJSON(serviceURLHR + 'immediateperformancesupervisor.php?action=load_attribute',function(data){
			imdsupervisor = data.attribute;
				$.each(imdsupervisor, function(index, imdsupervisor) {
					$('.dyn_attribute').append('<option value="'+imdsupervisor.perfom_attr_id+'">'+imdsupervisor.attributes	+'</option>');
				});	
			});
		}	
		return false;
	});
	
	
	
	
	
	$('.addNewEdu').live('click', function() { 
										   
		$('#edu').append('<div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr" "></div><table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Course</label></td><td><input name="course[]" type="text"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Specialization</label></td><td><input name="spl[]" type="text"   /></td></tr><tr><td colspan="2" height="8"></td> </tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">University/Institute</label></td><td><input name="unv[]" type="text"   /></td> </tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Year</label></td><td><input name="yr[]" type="text"  /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Percentage</label></td><td><input name="pcntg[]" type="text"  /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td colspan="2"><a href="#" id="remEdu">Remove</a></td></tr></table>');
		return false;
		
	});
	
	$('#remEdu').live('click', function() {
		$(this).parents('table').prev('div').remove();									
		$(this).parents('table').remove();
		var count = $('#edu').children('table').length;
		if(count==0)
		{
			
			$('#edu').append('<table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Course</label></td><td><input name="course[]" type="text"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Specialization</label></td><td><input name="spl[]" type="text"   /></td></tr><tr><td colspan="2" height="8"></td> </tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">University/Institute</label></td><td><input name="unv[]" type="text"   /></td> </tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Year</label></td><td><input name="yr[]" type="text"  /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01" align="left"><label for="label">Percentage</label></td><td><input name="pcntg[]" type="text"  /></td></tr><tr><td colspan="2" height="8"></td></tr></table>');
			
		}
		return false;
	});

	/*remove passport*/
	$('#passport_rm').live('click', function() {  
		if(confirm("Are you sure want to delete Passport?")){
			$.ajax({
			   url: serviceURLHR+"manageEmployees.php?action=rm_passport&employ_id="+id,
			   success: function(data){ 
			   		$('#pass_doc_list').html('');
			   }
		   });
		}
		return false;
	});

	/*remove visa*/
	$('#visa_rm').live('click', function() {  
		if(confirm("Are you sure want to delete Visa?")){
			$.ajax({
			   url: serviceURLHR+"manageEmployees.php?action=rm_visa&employ_id="+id,
			   success: function(data){
				   	$('#visa_doc_list').html('');
			   }
		   });
		}
		return false;
	});
	
	/*add more documents*/
	$('#adddoc').live('click', function() {  
										
		$('#addmoredoc').show();								
		$('#addmoredoc').append('<table width="100%" border="0" cellspacing="0" cellpadding="0"  ><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Document name</label></td><td><input name="doc_name[]" type="text"  /><br /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td width="164"  valign="top" class="form-padd-01"><label for="label">Document</label></td><td><input name="doc[]" type="file"   /></td></tr><tr><td colspan="2" height="8"></td></tr><tr><td></td><td ><a href="#" class="rmmoredoc">x Remove</a></td><td><input type="hidden" name="emp_doc_id[]" value=""></td></tr><tr><td colspan="2" height="8"></td></tr></table><div style="border:1px dotted #ddd; margin:10px 0 10px 0; class="bdr" "></div>');
		return false;
	});
	
 	/*remove employee document*/
	$('.rmmoredoc').live('click', function() {
		var empdocid	= $(this).closest('td').next().find('input').val();							   
	
		if(empdocid!=""){
			if(confirm("Are you sure want to delete document?")){
				$.ajax({
				   url: serviceURLHR+"manageEmployees.php?action=rm_emp_doc&emp_doc_id="+empdocid,
				   success: function(data){
						
				   }
			   });
				$(this).parents('table').next('div').remove();									   
				$(this).parents('table').remove();
				
				var count = $('#addmoredoc').children('table').length; 
				if(count==0){
						$('#addmoredoc').hide();
				}
			}
		}
		else {
			$(this).parents('table').next('div').remove();									   
			$(this).parents('table').remove();
			
			var count = $('#addmoredoc').children('table').length; 
			if(count==0){
					$('#addmoredoc').hide();
			}
		}
		
		return false;
	});
	
	
	/*remove document file*/
	$('.doc_rm').live('click', function() { 
		var empdocid	= $(this).attr('title');
		if(confirm("Are you sure want to delete file?")){
			$.ajax({
			   url: serviceURLHR+"manageEmployees.php?action=rm_doc_file&emp_doc_id="+empdocid,
			   success: function(data){
			   }
		   });
			$(this).parents('td').html('');
		}
		return false;
	});
	
/*oad designation*/	
	
/*loadDesignation();

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

//add candidate to short listed list
function short_List(){
	
	id = shortlisted_candidate();
	if(id=="")
	 alert("No candidates were selected.");
	else{
		$.ajax({
		   url: serviceURLHR+"recruitment.php?action=cand_short_list&id="+id,
		   success: function(data){ 
			    window.location="shortlisted-page-list.php";
		   }
	   });
		
	}
}
function shortlisted_candidate()
{
	var id  = "";
	var ids =[];
	$.each($("input[name*='sel_sht']:checked"), function () {
		 ids.push($(this).val());
	});
	id= ids.join(', ');
	return id;
}
//add candidate to selected list
function sel_List(){
	
	id = selected_candidate();
	console.log(id);
	if(id=="")
	 alert("No candidates were selected.");
	else{
		$.ajax({
		   url: serviceURLHR+"recruitment.php?action=cand_sel_list&id="+id,
		   success: function(data){
			   window.location="selected-page-list.php";
		   }
	   });
		
	}
}

function selected_candidate()
{
	var id  = "";
	var ids =[];
	$.each($("input[name*='selected_list']:checked"), function () {
		 ids.push($(this).val());
	});
	id= ids.join(', ');
	return id;
}





function loadDepartment(){ 

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


function loadDepartmentSelected(deptId){ 
	$('#department').empty();
	$.getJSON(serviceURLHR + 'department.php?action=load',function(data){
		department = data.department;
		$('#department').append('<option value="">Select Department</option>');
		$.each(department, function(index, department) {
				if(deptId==department.depart_id){
				  var selected = 'selected="selected"';
				}
				else{
				  var selected = '';
				}
									
			$('#department').append('<option value="'+department.depart_id+'"'+selected+'" >'+department.depart_name	+'</option>');
							
		});	
	});
	
}



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






//loadDesignation();

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

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

