if (document.getElementById("yfcMiniCalDiv")==null){
var alert1="Non esiste questo giorno per il mese selezionato.";
var alert2="La data selezionata è antecedente alla data attuale.";
var alert3="La data di partenza è successiva alla data di arrivo.";
var alert4="Indicare sia la città di partenza che quella di destinazione.";
var kk_flight_dayRangeValidDate = 350;
var alert5="La data di partenza scelta è oltre i 350 giorni da oggi. Sfortunatamente non siamo in grado di aiutarti con questa ricerca.";
var month1="Gennaio";var month2="Febbraio";var month3="Marzo";var month4="Aprile";var month5="Maggio";var month6="Giugno";var month7="Luglio";var month8="Agosto";var month9="Settembre";var month10="Ottobre";var month11="Novembre";var month12="Dicembre";
var day1="D";var day2="L";var day3="M";var day4="M";var day5="G";var day6="V";var day7="S";
var todayLabel="Oggi";
var Sun="Dom";
var Mon="Lun";
var Tue="Mar";
var Wed="Mer";
var Thu="Gio";
var Fri="Ven";
var Sat="Sab";
var dayCheck = "no";
var today = new Date();
var this_year = today.getFullYear();
var cal = null;
var cal2 = null;
}
function GlastUp() {
// following condition test if new calendar is actif or not, DO NOT REMOVE IT
if (document.getElementById("yfcMiniCalDiv")==null){
kk_flight_majDate();
if (document.searchForm.country.value!="") {
AZautosuggest=new kk_autosuggest_AutoSuggest(document.getElementById('arrival'),townList,"","travel_flight_autosuggest",15,"travel_suggestion_list",true,true);
AZautosuggest.startWith=true;
}
kk_flight_relativeDates2();
kk_flight_updateWeekDay();
}
}
function kk_flight_relativeDates2() {
var v=new Array();
v["name"]=new Array();
v["val"]=new Array();
var RelativeDay;
var RelativeWeek;
var RelativeMonth;
var RelativeDelay;
var nbnights =1;
var url=location.href;
if (url.indexOf("?") > -1) { //test if it is well a result page
var urlVars=url.split("?");
//if static URL, so parameters for Relative dates are at the left of the ? and separated by /.
// So that, just test if we have one or more relative date in this part of URL to extract them
if (urlVars[0].indexOf("departureRelativeDay") !=-1 | urlVars[0].indexOf("departureRelativeWeek") != -1 |urlVars[0].indexOf("departureRelativeMonth") != -1 ) { //it is a static url
var varsStatic=urlVars[0].split("/");
for (var j=0;j<varsStatic.length;j++) { //extract parameters from the URL
if (varsStatic[j]=="departureRelativeDay") RelativeDay=varsStatic[j+1];
if (varsStatic[j]=="departureRelativeWeek") RelativeWeek=varsStatic[j+1];
if (varsStatic[j]=="departureRelativeMonth") RelativeMonth=varsStatic[j+1];
if (varsStatic[j]=="nbnights") nbnights=varsStatic[j+1];
if (varsStatic[j]=="RelativeDelay") RelativeDelay=varsStatic[j+1];
}
}
else { //the URL is not static
var vars=urlVars[1].split("&");
for (var i=0;i<vars.length;i++) { //extract parameters from the URL
v["name"][i]=vars[i].split("=")[0];
v["val"][i]=vars[i].split("=")[1];
if (v["name"][i]=="departureRelativeDay") RelativeDay=v["val"][i];
if (v["name"][i]=="departureRelativeWeek") RelativeWeek=v["val"][i];
if (v["name"][i]=="departureRelativeMonth") RelativeMonth=v["val"][i];
if (v["name"][i]=="nbnights") nbnights=v["val"][i];
if (v["name"][i]=="RelativeDelay") RelativeDelay=v["val"][i];//this parameter is retrieved to use old url
}
}
}
//if (RelativeDay==null) RelativeDay=0;
//if (RelativeWeek==null) RelativeWeek=0;
//if (RelativeMonth==null) RelativeMonth=0;
//if (nbnights==null) nbnights=0;
//Using relative dates
// if (RelativeDay!=0|RelativeWeek!=0|RelativeMonth!=0) {
if (RelativeDay!=null | RelativeWeek!=null | RelativeMonth !=null) {
if (RelativeDay==null) RelativeDay=0;
if (RelativeWeek==null) RelativeWeek=0;
if (RelativeMonth==null) RelativeMonth=0;
if (nbnights==null) nbnights=0;
if (RelativeDelay != null) {nbnights = RelativeDelay;}//returnDelay is used; So, value of nbnights have to be updated.
var calendar_current=new Date();
this_year=(calendar_current.getFullYear()).toString(10);
//extract the current date
var calendar_cur=new Date();
day=calendar_cur.getDate().toString(10);
month=(calendar_cur.getMonth()+1).toString(10);
//Set date for tests
/*calendar_cur.setMonth(2);
calendar_cur.setDate(31);
calendar_cur.setFullYear(2006);*/
//alert ('Date initiale: '+calendar_cur.getDate()+'/'+calendar_cur.getMonth()+'/'+calendar_cur.getFullYear());
var calendar_cur = computeMonth(calendar_cur,RelativeMonth);
var calendar_cur = computeWeek(calendar_cur, RelativeWeek, RelativeDay);
var calendar_cur = computeDay(calendar_cur,RelativeDay, RelativeMonth,calendar_current,RelativeWeek);
//alert ('Date calculee: '+calendar_cur.getDate()+'/'+calendar_cur.getMonth()+'/'+calendar_cur.getFullYear());
//control if there is no anterior date. If the date is anterior, the new date is the one of next year
var newDateCalculated = calendar_cur.getTime();
var CurrentDate = calendar_current.getTime();
if (newDateCalculated < CurrentDate)
{
//alert("anterior date\n");
calendar_cur.setFullYear((calendar_cur.getFullYear())+1);
calendar_cur = computeMonth(calendar_cur,RelativeMonth);
calendar_cur = computeWeek(calendar_cur, RelativeWeek, RelativeDay);
calendar_cur = computeDay(calendar_cur,RelativeDay, RelativeMonth,calendar_current, RelativeWeek);
//alert ('Date calculee anterieure: '+calendar_cur.getDate()+'/'+calendar_cur.getMonth()+'/'+calendar_cur.getFullYear());
}
/*********************** end of anterior date control *************************************/
var day = calendar_cur.getDate().toString(10);
var month = (calendar_cur.getMonth()+1).toString(10); //because JANUARY = 0
var year = calendar_cur.getFullYear();
//set on 2 digits for form
if (day<10) day = '0'+day;
if (month<10) month = '0'+month;
//send new values to form
if (this_year>=3905) {this_year=this_year - 1900;} //different behaviour between IE and Mozilla
//alert ('Date calculee avant envoi au form: '+day+'/'+month+'/'+year);
document.searchForm.dday.options[day-1].selected=true;
document.searchForm.dmonth.options[month-1].selected=true;
document.searchForm.dyear.options[year-this_year].selected=true;
/*****************************************************************************/
/********* add the number of nights to previous date calculated for return from hotel ******/
/*****************************************************************************/
//add the number of nights to previous date calculated
//alert ('Date calculee avant : '+calendar_cur.getDate()+'/'+calendar_cur.getMonth()+'/'+calendar_cur.getFullYear());
var HotelDeparture = kk_addDays(calendar_cur,nbnights);
//alert ('Date calculee: '+HotelDeparture.getDate()+'/'+HotelDeparture.getMonth()+'/'+HotelDeparture.getFullYear());
var dayD = HotelDeparture.getDate().toString(10);
var monthD = (HotelDeparture.getMonth()+1).toString(10); //because JANUARY = 0
var yearD = HotelDeparture.getFullYear();
//set on 2 digits for form
if (dayD<10) dayD = '0'+dayD;
if (monthD<10) monthD = '0'+monthD;
//send new values to form
document.searchForm.rday.options[dayD-1].selected=true;
document.searchForm.rmonth.options[monthD-1].selected=true;
document.searchForm.ryear.options[yearD-this_year].selected=true;
}
}
/*****************************************************************************/
/******************************** Month ***************************************/
/*****************************************************************************/
function computeMonth(date,departureRelativeMonthS) {
//alert ('Date mois: '+date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear());
var CodeMonth=kk_hotel_getCodeMonth(departureRelativeMonthS);
if (CodeMonth == -1) //Value of the RelativeMonth is a number. Ex : RelativeMonth=3
{
var departureRelativeMonthI = departureRelativeMonthS
if (departureRelativeMonthI !=0)//calcul relative month only if needed
{
date = kk_addMonth(date,departureRelativeMonthI); //first day of Month is set
}
//if the day of the month calculated doesn't exist, it is set to the max value of the current month.
//E.G. calendar set to 31/08/1999, add 13 months, the month is September, but the 31th day doesn't exist. So, the final result is 30/09/2000
}
else if (CodeMonth !=-1) //Value of the RelativeMonth is a text. Ex : "July"
{
date = kk_ReachMonth(date,departureRelativeMonthS);
}
return date;
}
/********************************************************************************/
/*************************** Weeks **********************************/
/********************************************************************************/
function computeWeek(date, departureRelativeWeek, departureRelativeDayS) {
//alert ('Date week: '+date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear());
var CodeDayCurrent=0;
var MONDAY = 1;
var NumberDays = 7 * departureRelativeWeek;
if (departureRelativeWeek !=0)//calcul relative week only if needed
{
date = kk_addDays(date,NumberDays);//Calcul the relative week
while (date.getDay()!=MONDAY) {//set the first day of the week : Monday
date = kk_RemoveDays(date,1);
}
}
//alert ('Week : Date calculee: '+date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear());
return date;
}
/********************************************************************************/
/*************************** Days **********************************/
/********************************************************************************/
function computeDay(date, departureRelativeDayS,departureRelativeMonthS, current_date, departureRelativeWeek) {
//alert ('Date dans Days: '+date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear());
var CodeDay=kk_hotel_getCodeDay2(departureRelativeDayS); //get the code day in a week
if (CodeDay==-1) {//Day is in number mode. So, just add the number of days
var NumberDays = departureRelativeDayS;
date = kk_addDays(date,NumberDays);
}
else { //Day is in text Mode. So, new day is the next day selected
if(departureRelativeMonthS == 0 & departureRelativeWeek == 0 & CodeDay == date.getDay()) {//we ask for the next day only; but not today. e.g. if user asks for next Friday, and today is Friday, the day returned is next Friday, not today.
date = kk_addDays(date,7);//use the nex day selected by user
}
while (date.getDay()!=CodeDay){
date = kk_addDays(date,1);
}
}
//alert ('Date calculee: '+date.getDate()+'/'+date.getMonth()+'/'+date.getFullYear());
return date;
}
function kk_hotel_isBissextile2(year) {
if (year%4==0) {return true;}
else {return false;}
}
function kk_hotel_DAY_MAX_MONTH2(mois,annee) {
if(mois==kk_hotel_getCodeMonth("January")||mois==0) return 31;
if(mois==kk_hotel_getCodeMonth("March")||mois==2) return 31;
if(mois==kk_hotel_getCodeMonth("April")||mois==3)return 30;
if(mois==kk_hotel_getCodeMonth("May")||mois==4) return 31;
if(mois==kk_hotel_getCodeMonth("June")||mois==5) return 30;
if(mois==kk_hotel_getCodeMonth("July")||mois==6) return 31;
if(mois==kk_hotel_getCodeMonth("August")||mois==7) return 31;
if(mois==kk_hotel_getCodeMonth("September")||mois==8) return 30;
if(mois==kk_hotel_getCodeMonth("October")||mois==9) return 31;
if(mois==kk_hotel_getCodeMonth("November")||mois==10) return 30;
if(mois==kk_hotel_getCodeMonth("December")||mois==11) return 31;
if(mois==kk_hotel_getCodeMonth("February")||mois==1) {if (kk_hotel_isBissextile2(annee)) return 29; else return 28;}
}
function kk_hotel_getCodeMonth(RelativeMonth) {
if (RelativeMonth=="January") return 0;
if (RelativeMonth=="February") return 1;
if (RelativeMonth=="March") return 2;
if (RelativeMonth=="April") return 3;
if (RelativeMonth=="May") return 4;
if (RelativeMonth=="June") return 5;
if (RelativeMonth=="July") return 6;
if (RelativeMonth=="August") return 7;
if (RelativeMonth=="September") return 8;
if (RelativeMonth=="October") return 9;
if (RelativeMonth=="November") return 10;
if (RelativeMonth=="December") return 11;
else return -1;
}
function kk_hotel_getCodeDay2(RelativeDay) {
if (RelativeDay=="Monday") return 1;
if (RelativeDay=="Tuesday") return 2;
if (RelativeDay=="Wednesday") return 3;
if (RelativeDay=="Thursday") return 4;
if (RelativeDay=="Friday") return 5;
if (RelativeDay=="Saturday") return 6;
if (RelativeDay=="Sunday") return 0;
else return -1;
}
function kk_addDays(date,day) //add days to the date
{
var date2 = new Date(date.getTime() + (1000 * 60 * 60 * 24 * day)); //convert into milliseconde to perform the add
var day = date2.getDate().toString(10);
var month = date2.getMonth().toString(10);
var year = date2.getFullYear().toString(10);
date.setDate(day);
date.setMonth(month);
date.setFullYear(year);
return date;
}
function kk_RemoveDays(date,day) //remove days to the date
{
var date2 = new Date(date.getTime() - (1000 * 60 * 60 * 24 * day));//convert into milliseconde to perform the add
var day = date2.getDate().toString(10);
var month = date2.getMonth().toString(10);
var year = date2.getFullYear().toString(10);
date.setDate(day);
date.setMonth(month);
date.setFullYear(year);
return date;
}
function kk_addMonth(date,NbMonth)// Calcul the date/ New month is NbMonth after the current date. Value of m is only a number.
{
var month_current = date.getMonth();
var year_current = date.getFullYear();
var day_current = date.getDate();
var DECEMBER = 11;
var JANUARY = 0;
while (NbMonth!=0) { //add months
month_current++;
if (month_current > DECEMBER) {month_current = JANUARY; year_current++;}//change year
NbMonth--;
}
if (day_current > kk_hotel_DAY_MAX_MONTH2(month_current,year_current)) { //the day of new month doesn't exist. Set it to the last day of month
day_current = kk_hotel_DAY_MAX_MONTH2(month_current,year_current);//don't change of month if the day doesn't exist
if(month_current>DECEMBER) {month_current=JANUARY;year_current++;} //change of year
}
day_current = 1;
date.setDate(day_current);
date.setMonth(month_current);
date.setFullYear(year_current);
return date;
}
function kk_ReachMonth(date,MonthName) //Calcul the date using the name of the month. The day will be the first of the month
{
var DECEMBER = 11;
var JANUARY = 0;
var day_current = date.getDate();
var year_current = date.getFullYear();
var month_current = date.getMonth();
while(month_current!=kk_hotel_getCodeMonth(MonthName)) { //add month to get the good month name
if (day_current > kk_hotel_DAY_MAX_MONTH2(MonthName,year_current)) {
day_current=1;
}
else month_current++;
if (MonthName>DECEMBER | month_current > DECEMBER) {//change year
month_current=JANUARY;
year_current++;
}
}
day_current = 1;//set to the first day of the month
date.setDate(day_current);
date.setMonth(month_current);
date.setFullYear(year_current);
return date;
}
function kk_ReachDay(date,DayName) //Calcul the date using the name of the day.
{
var DECEMBER = 11;
var JANUARY = 0;
var SATURDAY = 6;
var SUNDAY =0 ;
var day_current = date.getDate();
var year_current = date.getFullYear();
var month_current = date.getMonth();
var Code_day_current = date.getDay();
while((Code_day_current!=kk_hotel_getCodeJour(DayName))) {
if (day_current==kk_hotel_DAY_MAX_MONTH2(month_current,year_current)) { //change of month
month_current++;
day_current=1;
Code_day_current++;
if (month_current > DECEMBER) {month_current = JANUARY;year_current++;} //change of year
}
else if (Code_day_current == SATURDAY & DayName!= SATURDAY) {//change of week
Code_day_current=SUNDAY; //set to next Sunday, beginning of the next week
day_current++;
}
else { //add code days of the week, and the date of the month
Code_day_current++;
day_current++;
}
}
date.setDate(day_current);
date.setMonth(month_current);
date.setFullYear(year_current);
return date;
}
// get number of week in the year
function kk_getWeekOfYear(date) {
var day = date.getDate();
var month = date.getMonth();
var year = date.getFullYear();
var Num_Week=0;
var newYear = new Date(year,0,1);
var Day_Mod = newYear.getDay();
var Day_Number = ((Date.UTC(year,month,day,0,0,0) - Date.UTC(year,0,1,0,0,0)) / 1000 / 60 / 60 / 24) + 1;
if (Day_Mod < 4 ) {
Num_Week = Math.floor((Day_Number+Day_Mod-1) / 7) + 1;
}
else {
Num_Week = Math.floor((Day_Number+Day_Mod-1) / 7);
if (Num_Week == 0) {
year--;
var NewYear = new Date(year,0,1);
var Day_ModPrev = NewYear.getDay();
if (Day_ModPrev == 0) Day_ModPrev = 6; else Day_ModPrev--;
if (Day_ModPrev < 4) Num_Week = 53; else Num_Week = 52;
}
}
return Num_Week;
}
function checkForm(form)
{
document.searchForm.country.value="";
return kk_flight_ctrlForm(form);
}
