Current File : /home/inlingua/public_html/dwarka/icentex/admin_cert/js/admin_leave_form.js
// JavaScript Document
$().ready(function() {

// validate signup form on keyup and submit
	$("#leaveForm").validate({
		rules: {
			fromDate: "required",
			toDate: "required" ,
			noofdays: "required"
			
		},
		messages: {
			fromDate: "Please enter From Date",
			toDate: "Please enter To Date" ,
		noofdays:"Please enter No. Of Days"
			}
			
	});
	
	
	

});

function dateDiff(fromDate, toDate) {
 return toDate.getDate() - fromDate.getDate();
}
function showhidesubstitute(getval)
{
	if(getval=="Yes")
	{
		$('#substituted2').show();
		$('#substituted3').hide();
	}
	else 
	{
		$('#substituted2').hide();
		$('#substituted3').show();
	}
}
	
function setCal()
{
$(function()
	{
	$('#fromDate').datepicker({
	changeMonth: true,
	changeYear: true,
	minDate: dateStart(),
	onClose:function(theDate) {
	clearEndDate();
	timesheet_user_id=$('#timesheet_user_id').val();
	kVid=$('#kVid').val();
	td=$('#toDate').val();
	if(theDate!="" && td!="")
		{
		 if(theDate>td)
			 {
			 alert("Please select value Less Than or Equal To ToDate");
			 $('#fromDate').val('');
			 //$('#toDate').focus();
			 }
		 else
			 {
			 //alert(fd);
			 datediff(theDate,td);
			 $('#subsubmit').hide();
             $('#subwait').html("<img src='../images/ajax-loader.gif' style='border:0px'><br><font color='red'>Please Wait</font>");
       	     $.ajax({
    		url: 'leaveleft_ajax.php',
    		type: 'GET',
    		dataType: 'html',
			data:{'fromdate':fd,'todate':theDate,'timesheet_user_id':timesheet_user_id,'kVid':kVid},
    		error: function(){
        	alert('Error loading Data.Please Check your Browser.');
    		},
    		success: function(html){
	//$('#classAffected').val(html);
		if(html!=1)
			{	
			$('#leave_find_error').html(html);
			$('#toDate').val('');
			$('#classAffected').val('');
			$('#noofdays').val('');
			alert(html);
			$('#subsubmit').show();
			$('#subwait').html("");
			}
		else
			{
			$('#leave_find_error').html('');
			}
	//leave_find_error
	//alert(html);
	//$('#classAffected').val(html);
        // do something with xml
    	}
		});
	  }
	 }
	}
	});
	});
}
setCal();

$(function() 
{
$('#toDate').datepicker({
beforeShow: setMinDateForEndDate,
changeMonth: true,
changeYear: true,
minDate: new Date(),
//maxDate: new Date(),
onClose:function(theDate) {
timesheet_user_id=$('#timesheet_user_id').val();
kVid=$('#kVid').val();

fd=$('#fromDate').val();
if(theDate!="" && fd!="")
	{
	if(fd>theDate)
		{
		 alert("Please select value Greater Than or Equal To FromDate");
		 $('#toDate').val('');
		 //$('#toDate').focus();
		 }
	 else
		 {
			 //alert(fd);
		 datediff(fd,theDate);
          
			
		//$("#classAffected").load('classaffect_ajax.php',);
			$('#subsubmit').hide();
			$('#subwait').html("<img src='../images/ajax-loader.gif' style='border:0px'><br><font color='red'>Please Wait</font>");
		$.ajax({
    	url: 'classaffect_ajax.php',
    	type: 'GET',
    	dataType: 'html',
		data:{'fromdate':fd,'todate':theDate,'timesheet_user_id':timesheet_user_id,'kVid':kVid},
    	error: function(){
        alert('Error loading  Data.Please Check your Browser.');
    	},
    	success: function(html){
		if(html!=1)
		
			{	$('#classAffected').val(html);
			
				$('#substituted1').show();
				$('#substituted2').show();
				$('#substituted3').hide();
				$('#subsubmit').show();
			    $('#subwait').html("");
			}
		else{
				$('#classAffected').val('');
				$('#substituted1').hide();
				$('#substituted2').hide();
				$('#substituted3').hide();
	
			}
	
    }
});

//////////////////////////////////////////////////////check leAVE LEFT/////////////////////////////////////////////////////////////////////
$('#subsubmit').hide();
$('#subwait').html("<img src='../images/ajax-loader.gif' style='border:0px'><br><font color='red'>Please Wait</font>");
		$.ajax({
    url: 'leaveleft_ajax.php',
    type: 'GET',
    dataType: 'html',
	data:{'fromdate':fd,'todate':theDate,'timesheet_user_id':timesheet_user_id,'kVid':kVid},
    error: function(){
        alert('Error loading Data.Please Check your Browser.');
    },
    success: function(html){
		//alert(timesheet_user_id);
	//$('#classAffected').val(html);
	if(html!=1)
	{	$('#leave_find_error').html(html);
	$('#toDate').val('');
	$('#classAffected').val('');
	$('#noofdays').val('');
	alert(html);
	$('#subsubmit').show();
	$('#subwait').html("");
	}
	else{
	$('#leave_find_error').html('');
		}
	}
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
			}
			}
			}
		});
		
		

		
	});
	
	 //var checkInDate = $('#<%= CheckInDate.ClientID  %>');
            //var checkOutDate = $('#<%= CheckOutDate.ClientID  %>');
			
	function setMinDateForEndDate() {
                var d = $('#fromDate').datepicker('getDate');
                if (d) return { minDate: d }
            }
			
			function clearEndDate() {
                 $('#toDate').val('');
            }
	
	function getDateObject(str) {
      var arr = str.split("-");
      return new Date(arr[0], arr[1], arr[2]);
	  
	  
}

function dateStart()
	  { 
	       leaveAfterorBefore=$('input[name=leaveAfterorBefore]:checked').val();
		    //alert(leaveAfterorBefore);
			if(leaveAfterorBefore=="Before")
			{
	        var myDate=new Date();
			myDate.setDate(myDate.getDate()-2);
			}
			else
			{
			var myDate=new Date();
            myDate.setDate(myDate.getDate()-2);
			}
			return myDate;
      }

function datediff(str1,str2)
{
//date1=getDateObject(str1);
//date2=getDateObject(str2);
//var days = (date2 - date1) / 86400000;
//return days + (1*1);
$('#subsubmit').hide();
$('#subwait').html("<img src='../images/ajax-loader.gif' style='border:0px'><br><font color='red'>Please Wait</font>");

$.ajax({
    url: 'noofdays_ajax.php',
    type: 'GET',
    dataType: 'html',
	data:{'fromdate':str1,'todate':str2},
    error: function(){
        alert('Error loading Data.Please Check your Browser.');
    },
    success: function(html){
	//$('#classAffected').val(html);
	//alert(html);
	 $('#noofdays').val(html);
	 $('#subsubmit').show();
	$('#subwait').html("");
    }
});

}