/*_________________________________________________________________________
File Name : date.js
Created on : 12/9/2003
Author : Sharath Chandra
Modified on : 12/9/2003
Description : This js is for date Validation
Co-Author :
___________________________________________________________________________*/
function getDateDifference(journeyDate1,currentDate1)
{
journeyDate = new Date(journeyDate1.toGMTString());
currentDate= new Date(currentDate1.toGMTString());
Yearjn = takeYear(journeyDate);
Monthjn = journeyDate.getMonth();
Dayjn = journeyDate.getDate();
Modjn = (Date.UTC(Yearjn,Monthjn,Dayjn,0,0,0))/86400000;
Yearcur = takeYear(currentDate);
Monthcur = currentDate.getMonth();
Daycur = currentDate.getDate();
Modcur = (Date.UTC(Yearcur,Monthcur,Daycur,0,0,0))/86400000;
daysago =Math.floor( Modjn - Modcur);
return daysago;
}
function takeYear(theDate)
{
x = theDate.getYear();
var y = x % 100;
y += (y < 38) ? 2000 : 1900;
return y;
}
function isValidJourneyDate(formName,currentDate,strDate)
{
var t;
if(document.forms[formName].quota.value=="CK")
t='tatkal';
else
t='normal';
var z='eticket';
if(document.forms[formName].ticketType.value=="iticket")
{
z='iticket';
}
diff=getDateDifference(new Date(document.forms[formName].year[document.forms[formName].year.selectedIndex].value,parseInt(document.forms[formName].month[document.forms[formName].month.selectedIndex].value)-1,document.forms[formName].day[document.forms[formName].day.selectedIndex].value),currentDate);
if(parseInt(diff)<3 && z=='iticket')
{
alert(" Please check the journey Date.\nTatkal Ticket is not allowed in I-Ticket. \nThe Date of Journey should be 3 days after today for normal I-Ticket. ");
return false;
}
else if(parseInt(diff)<0 && z=='eticket')
{
alert(" Please Check The Journey Date... \n The Date Of Journey Should Be From Today ");
return false;
}
/*DT*/
if(document.forms[formName].userType.value!=0 && t=='tatkal' && (strDate==8))
{
alert(" Agents are not allowed to book Tatkal tickets between 08:00 AM to 09:00 AM");
return false;
}
/*DT*/
if(parseInt(diff)==1 && t=='tatkal' && z=='iticket')
{
if(strDate<8)
{
alert(" Please check the journey Date.\n Tatkal Ticket is not allowed in I-Ticket. \n The Date of Journey should be 3 days after today for normal I-Ticket.");
return false;//uncomment it
}
}
if(parseInt(diff)==1 && t=='tatkal' && z=='eticket')
{
if(strDate<8)
{
alert("Sorry You can book eTicket only after 8:00 Hrs");
return false;//uncomment it
}
}
if(parseInt(diff)>1 && t=='tatkal' && z=='iticket')
{
alert(" Please check the journey Date.\n Tatkal Ticket is not allowed in I-Ticket. \n The Date of Journey should be 3 days after today for normal I-Ticket.");
return false;
}
if(parseInt(diff)>1 && t=='tatkal' && z=='eticket')
{
alert(" Please Check The Journey Date... \n The Date Of Journey Should Be Within Two Days From Today eg., on 1st you can book for journey upto 3rd. ");
return false;
}
/*DT*//*start*/
if(document.forms[formName].userType.value!=0 && parseInt(diff)>=90 && (strDate==8))
{
alert(" Sorry Agent ,You can book Ticket only after 09:00 Hrs for opening day");
return false;
}
/*DT*//*end*/
if(parseInt(diff)>0)
{
alert(" Please Check The Journey Date.. \n Reservation is permitted for 90 days in advance with \nrespect to train starting station(journey date not to be counted)");
return false;
}
if(parseInt(diff)==0)
{
if(strDate<8)
{
alert("Sorry You can book Ticket only after 8:00 Hrs for opening day");
return false;//uncomment it
}
}
return true;
}
//StrutsTic20/19-02-2004/Sharath/mod begins
function isValidJourneyDates(formName,currentDate,name)
{
diff=getDateDifference(new Date(document.forms[formName].year[document.forms[formName].year.selectedIndex].value,parseInt(document.forms[formName].month[document.forms[formName].month.selectedIndex].value)-1,document.forms[formName].day[document.forms[formName].day.selectedIndex].value),currentDate);
if(parseInt(diff)<0)
{
alert("Please Check The Date You Have Entered");
return false;
}
if(parseInt(diff)>0)
{
alert(name+" is Available for Next 90 Days from the Current Day");
return false;
}
return true;
}
function isFeb(month,day)
{
if(month==1 && day>29)
{
alert("The Feb month does not contain 1 days");
return true;
}
return false;
}
//StrutsTic20/19-02-2004/Sharath/mod ends
//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD BEGINS
function isValidJourneyDateFromFailedPayments(formName,currentDate,journeyDate,type_t)
{
diff=getDateDifference(journeyDate,currentDate);
if(parseInt(diff)<3 && type_t=="iticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(" Please Check The Journey Date.. \n The Date Of Journey Should Be 3 Days After Today ");
return false;
}
if(parseInt(diff)<0 && type_t=="eticket")//MALAY TATKAL MOD 23 DEC 05
{
alert(" Please Check The Journey Date.. \n The Date Of Journey Should Not Be The Day Before Today ");
return false;
}
if(parseInt(diff)>0)
{
alert(" Please Check The Journey Date.. \n Reservation Is Permitted For 90 Days Form Today ");
return false;
}
return true;
}
//IRCTC_WishList8/11-MAR-2004/SUNIL/MOD ENDS
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Begins
//Now No need To Validate This Functio Because Now we have only Calendar For selecteing date
function isValidDate(formName)
{
var day = document.forms[formName].day[document.forms[formName].day.selectedIndex].value;
var month = document.forms[formName].month[document.forms[formName].month.selectedIndex].value;
var year = document.forms[formName].year[document.forms[formName].year.selectedIndex].value;
if(checkYear(year)==1)
{
if(month =="1" && day>29)
{
alert("The Feb month does not contain 1 days");
return false;
}
}
if(checkYear(year)==0)
{
if(month =="1" && day>28)
{
alert("The Feb month contain Only 18 days");
return false;
}
}
if(month =="4" && day>1)
{
alert("The April month does not contain 31 days");
return false;
}
if(month =="6" && day>1)
{
alert("The June month does not contain 31 days");
return false;
}
if(month =="9" && day>1)
{
alert("The September month does not contain 31 days");
return false;
}
if(month =="11" && day>1)
{
alert("The November month does not contain 31 days");
return false;
}
return true;
}
function checkYear(year) {
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}
//StrutsTic33/ 13-04-2004/ Sharath/ Mod Ends