var serviceURLHR 	=localStorage['serviceURLHR'];
var hrURL =localStorage['serviceURLHR'];
var editIcon = "images/edit.png";

$(window).load(function(){
	hash = window.location.href.split('#')[1]	;
	$('*[data-page="'+hash+'"]').addClass('btn-tab-active');
	
	switch(hash){

		case "Notification" : notificationAdd();break;		
		
	}
	
	
});

$('#nfn_cat').val('passport');
var cat= $('#nfn_cat').val();
notificationList(cat);
$('#nfn_cat').change(function(){ 
	var cat= $('#nfn_cat').val();
	notificationList(cat);
});

function notificationList(cat){

	$('#notificationlist').html('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list-leaves notification">'+
										  '<tr>'+
										    '<td width="3%"><translate>Sl No</translate></td>'+
											'<td width="10%"><translate>Employee Id</translate></td>'+
											'<td width="17%"><translate>Employee Name</translate></td>'+
											'<td width="10%"><translate>Passport Expiry Date</translate></td>'+
											'<td width="10%"><translate>Visa Expiry Date</translate></td>'+
											'<td width="10%"><translate>Probation Completion Date</translate></td>'+
											'<td width="10%"><translate>Contract Expiry Date</translate></td>'+
											'<td width="10%"><translate>Emirates Expiry Date</translate></td>'+
											'<td width="10%"><translate>Labour Card Expiry Date</translate></td>'+
											'<td width="10%"><translate>No of Leaves Taken</translate></td>'+
										 '</tr>'+
										'</table>')	;

	//$.getJSON(serviceURLHR + "manageNotification.php?act=list",function(data){
		/*var notification = data.notification; 
		$.each(notification, function(index,notification){ 
			$('.list-leaves').append( '<tr>'+
				'<td></td>'+
				'<td></td>'+
				'<td></td>'+
				'<td></td>'+
				'<td></td>'+
				'<td></td>'+
				'<td></td>'+
			'</tr>');				
		});*/
		//$('.list-leaves').show('blind',500);
	//});	
	$.ajax({
		type: "GET",
		url: serviceURLHR + "manageNotification.php",
		data: "act=listNotifi",
		dataType:'json',
		success: function(result){
			$('.notification').append(result.noti_list);	
			$('#employee_name_combo').html(result.employee_combo);
			$('#employee_code_combo').html(result.employee_code);
		}
	});
}

function notification_search()
{
	var employee_id=$('#employee_name_combo').val();
	var employee_code=$('#employee_code_combo').val();
	$('#notificationlist').html('<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list-leaves notification">'+
										  '<tr>'+
										    '<td width="3%"><translate>Sl No</translate></td>'+
											'<td width="10%"><translate>Employee Id</translate></td>'+
											'<td width="17%"><translate>Employee Name</translate></td>'+
											'<td width="10%"><translate>Passport Expiry Date</translate></td>'+
											'<td width="10%"><translate>Visa Expiry Date</translate></td>'+
											'<td width="10%"><translate>Probation Completion Date</translate></td>'+
											'<td width="10%"><translate>Contract Expiry Date</translate></td>'+
											'<td width="10%"><translate>Emirates Expiry Date</translate></td>'+
											'<td width="10%"><translate>Labour Card Expiry Date</translate></td>'+
											'<td width="10%"><translate>No of Leaves Taken</translate></td>'+
										 '</tr>'+
										'</table>')	;
	$.ajax({
		type: "GET",
		url: serviceURLHR + "manageNotification.php",
		data: "act=searchlist&employee_id="+employee_id+"&employee_code="+employee_code,
		dataType:'json',
		success: function(result){
			$('.notification').append(result.noti_list);	
			//$('#employee_name_combo').html(result.employee_combo);
			//$('#employee_code_combo').html(result.employee_code);
		}
	});
	
}



/************** notification list end********************/

/****************notification add***********/
jQuery('.notification').live('click',notificationAdd);
jQuery('.savenotification').live('click',savenotification);
function notificationAdd()
{ 
	
	if($('.newnotifyform').length){
		
	}else{ 
	
	
		 $.getJSON( serviceURLHR+ "manageNotification.php?act=get",function(data){ 
		
				
				
					$('#masterlist').html('<form class="newnotifyform field-style"><table width="59%" border="0"  cellspacing="0" cellpadding="0" class="newNotification">'+
								  '<tr>'+
									'<td width="47%">&nbsp;</td>'+
									'<td width="53%">&nbsp;</td>'+
								  '</tr>'+
								  '<tr>'+
									'<td><translate>Notification Days</translate></td>'+
									'<td><input type="text" name="notify_days" id="notify_days" value="" onkeypress="return onlyNos(event,this);"/> <translate>Days</translate></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td><input type="button" name="button" class="color-button savenotification" id="button" value="Submit" style="visibility:visible" />'+
									'<input type="reset" name="button" class="color-button cancelnotification" id="button" value="Reset" style="visibility:hidden" /></td>'+
								  '</tr>'+
								  '<tr>'+
									'<td>&nbsp;</td>'+
									'<td>&nbsp;</td>'+
								  '</tr>'+
								'</table></form>');
					
					
							$('#notify_days').val(data.notify_days);
				
				
								permissions_user = data[0].permissions[0].user_id;	
				if(permissions_user!=1)
				{ 
					 if(data[0].permissions[0].edit_right==1)
					 {
						 $('.savenotification').css( 'visibility','visible' );
						 $('.cancelnotification').css( 'visibility','visible' );
						 
					 }
					 else
					 {
						 $('.savenotification').css( 'visibility','hidden' );
						 $('.cancelnotification').css( 'visibility','hidden' );
					 }
				}
				
				
				
		 });
	}
}
function savenotification(){
	if ($.trim($("#notify_days").val())!= '') {
			dataString = $('.newnotifyform').serialize();
			$.post( serviceURLHR+ "manageNotification.php?act=insert",dataString,function(data){
				alert("successfully inserted");
			},'json');
		
	}else
		{
			alert('Please Enter Notification Days.');	
		}
}

function onlyNos(e, t)
{
	           try {
                if (window.event) {
                    var charCode = window.event.keyCode;
                }
                else if (e) {
                    var charCode = e.which;
                }
                else { return true; }
                if (charCode > 31 && (charCode < 48 || charCode > 57)) {
                    return false;
                }
                return true;
            }
            catch (err) {
                alert(err.Description);
            }
    
	/*if(isNaN(obj.value))
	{
		obj.value='';
		alert("Please Enter Numeric Values");
	}*/
}