Current File : /home/inlingua/public_html/noida/icentex/leave_tracker/js/leave_form_old.js |
// JavaScript Document
$().ready(function() {
jQuery.validator.addMethod("reasons1", function(value, element) {
//alert(value);
if($("#classAffected").val()!="")
{
//alert(value);
var _test1 = $("#radio1");
var _test2 = $("#radio2");
//alert(_test1.attr("checked"));
if (_test1.attr("checked") != "undefined" && _test1.attr("checked") == true && value=="")
{
return false;
//alert("dd");
}
else
{
return true;
}
//return true;
}
else
{
return true;
}
}, "Cannot be blank");
jQuery.validator.addMethod("reasons2", function(value, element) {
//alert(value);
if($("#classAffected").val()!="")
{
//alert(value);
var _test1 = $("#radio1");
var _test2 = $("#radio2");
//alert(_test1.attr("checked"));
if (_test2.attr("checked") != "undefined" && _test2.attr("checked") == true && value=="")
{
return false;
//alert("dd");
}
else
{
return true;
}
//return true;
}
else
{
return true;
}
}, "Cannot be blank");
// validate signup form on keyup and submit
$("#leaveForm").validate({
rules: {
fromDate: "required",
toDate: "required" ,
noofdays: "required",
reasons: "required" ,
subByWhom:"reasons1",
compensated:"reasons2"
},
messages: {
fromDate: "Please enter From Date",
toDate: "Please enter To Date" ,
noofdays:"",
reasons:"Reasons cannot be blank",
subByWhom:"Substituted by Whom cannot be blank",
compensated:"When and how will the classes be compensated? cannot be blank"
}
});
});
function dateDiff(fromDate, toDate) {
return toDate.getDate() - fromDate.getDate();
}
function showhidesubstitute(getval)
{
if(getval=="Yes")
{
$('#substituted2').show();
$('#substituted3').hide();
}
else if(getval=="No") {
$('#substituted2').hide();
$('#substituted3').show();
}
else {
$('#substituted2').hide();
$('#substituted3').hide();
}
}
function setCal()
{
$(function() {
$('#fromDate').datepicker({
changeMonth: true,
changeYear: true,
minDate: dateStart(),
onClose:function(theDate) {
clearEndDate();
td=$('#toDate').val();
//$('#fromPrevious').html(theDate);
if(theDate!="")
{
$.ajax({
url: 'previousday.php',
type: 'GET',
dataType: 'html',
data:{'fromdate':theDate},
error: function(){
alert('Error loading Data.Please Check your Browser.');
},
success: function(html){
//$('#error').html('');
$('#fromPrevious').html(html);
}
});
}
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},
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('');
$('#fromNext').html('');
$('#classAffected').val('');
$('#classAffected1').html('Select from and to dates');
$('#noofdays').val('');
$('#noofdays1').html('Select from and to dates');
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) {
fd=$('#fromDate').val();
if(theDate!="" && fd!="")
{
if(fd>theDate)
{
alert("Please select value Greater Than or Equal To FromDate");
$('#toDate').val('');
//$('#toDate').focus();
}
else
{
if(theDate!="")
{
$.ajax({
url: 'nextday.php',
type: 'GET',
dataType: 'html',
data:{'fromdate':theDate},
error: function(){
alert('Error loading Data.Please Check your Browser.');
},
success: function(html){
$('#fromNext').html(html);
}
});
}
//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},
error: function(){
alert('Error loading Data.Please Check your Browser.');
},
success: function(html){
//alert(html);
if(html!="No Classes Affected")
{
getEmergencyDate('affect');
$('#classAffected').val(html);
$('#classAffected1').html(html);
//$('#substituted1').show();
//$('#substituted2').show();
$('#substituted3').hide();
//$('#subwait').html("");
$('#subsubmit').show();
$('#subwait').html("");
}
else{
getEmergencyDate('');
$('#classAffected').val('');
$('#classAffected1').html(html);
$('#substituted1').hide();
$('#substituted2').hide();
$('#substituted3').hide();
}
}
});
$('#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},
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('');
$('#fromNext').html('');
$('#classAffected').val('');
$('#classAffected1').html('Select from and to dates');
$('#noofdays').val('');
$('#noofdays1').html('Select from and to dates');
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);
$('#noofdays1').html(html);
$('#subsubmit').show();
$('#subwait').html("");
}
});
}
function datediff_15(str1,str2, affectclass)
{
//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_15.php',
type: 'GET',
dataType: 'html',
data:{'fromdate':str1,'todate':str2},
error: function(){
alert('Error loading Data.Please Check your Browser.');
},
success: function(html){
if(html < 15)
{
$('#emergencylabel').html('Note: You are applying for emergency leave.');
if(affectclass=='affect')
{
$('#substituted1').show();
}
$('#emergencyLeave').val("Yes");
}
else
{
$('#emergencylabel').html('');
$('#substituted1').hide();
$('#emergencyLeave').val("No");
}
// $('#noofdays1').html(html);
// $('#subsubmit').show();
//$('#subwait').html("");
}
});
}