/*****
 * Copyright © FASTBOOKING  1999-2007
 * version XHTML 03/08/2007
 *
 * Please do NOT modify this file
 * Please do NOT use the final IP adress for Fastbooking links:
 *   IP address may be changed at any time
 *
*/

var FBRESA = "http://www.fastbookings.biz/DIRECTORY/";
var FB_nb_day_delay = 7;

// following code is used to optimize booking access and a better client experience
var FB_book_image = new Image();
FB_book_image.src = FBRESA + "trans.gif";
var FB_version_code = (typeof(FB_VERSION) == "undefined")? "" : "&version="+FB_VERSION ;

// Form: show arrival date
// this function to replace the traditional start function
// in this case no update is required every year.
function start() {
	var nbm = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
		
	if(document.getElementById) thisform = document.getElementById("idForm");
	else thisform = document.all["idForm"];

	build_year_select(thisform);

	MD = new Date();
		
	nday = MD.getDate();
	aday = MD.getDay();
	amois = MD.getMonth();
	ayear = takeYear(MD);
	cur_year = ayear;
			
	nday += FB_nb_day_delay;

	if(nday > nbm[amois])
	{
		nday -= nbm[amois];
		amois++;
		if(amois > 11) {
			ayear++;
			amois = 0;
		}
	}

	indexDay = nday - 1;
	indexMois = amois;
	indexYear = ayear - cur_year;
		
	if(indexDay < 0 || indexDay > 30)
		indexDay = 0;
	if(indexMois < 0 || indexMois > 11)
		indexMois = 0;
	if(indexYear < 0 || indexYear > 1)
		indexDay = 0;

	thisform.fromday.selectedIndex = indexDay;
	thisform.frommonth.selectedIndex = indexMois;
	thisform.fromyear.selectedIndex = indexYear;

	update_departure();
}

// standard search availabilities in a group for a partner
function hhotelSearchPartner(cluster, lg, price, codetrack, title)
{
	if (codetrack != "") args = "&from="+codetrack;
	else	args = "";
	hhotelSearch(cluster, lg, price, "", title, "", args);
}

// search availabilities for selected promotions
function hhotelSearchPromo(cluster, lg, theme)
{
	hhotelSearch(cluster, lg, "", "", "", theme, "");
}

// go to the cancel reservation page
function hhotelcancel(cname,lg)
{
	var waction = FBRESA + "cancel.phtml?state=77&Hotelnames="+cname;
	if (lg != "") waction += "&langue="+lg;
	window.open(waction,"reservation","toolbar=no,width=400,height=350,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

// Main Search function
function hhotelSearch(cluster, lg, price, nights, title, theme, args)
{
	var waction = FBRESA + "crs.phtml?clusterName="+cluster;
	if (lg != "") waction += "&langue="+lg;
	if (price != "") waction += "&FSTBKNGCode="+price;
	if (nights != "") waction += "&nights="+nights;
	if (title != "") waction += "&title="+escape(title);
	if (theme != "") waction += "&theme="+theme;
	if (args != "" && (args.indexOf("=")!= -1) ) waction += "&"+args;
	window.open(waction,"search","toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

///////////////////////////////////////////////////////////////////////////////////////
// Form functions
// Simple form validation (used for compatibility issues)
function hhotelDispoprice(myForm)
{
	hhotelFormValidation(myForm, 0);
}

// Form validation with control
function hhotelFormValidation(myForm, mandatoryCode){
	if (mandatoryCode == 1 && myForm.AccessCode.value == "") {
		alert("You must type in your code ID");
		return (false);
	}
	var waction = FBRESA + "dispoprice.phtml";
	waction += "?clusterName=" + myForm.Clusternames.value;
	waction += "&Hotelnames=" + myForm.Hotelnames.value;
	waction += "&langue=" + myForm.langue.value;
	waction += "&showPromotions=" + myForm.showPromotions.value;
	waction += "&theme=" + myForm.theme.value;
	waction += "&fromday=" + myForm.fromday.value;
	waction += "&frommonth=" + myForm.frommonth.value;
	waction += "&fromyear=" + myForm.fromyear.value;
	waction += "&nbdays=" + myForm.nbdays.value;
	waction += "&adulteresa=" + myForm.adulteresa.value;
	waction += "&enfantresa=" + myForm.enfantresa.value;
	window.open(waction, 'dispoprice', 'toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes');
	//myForm.submit();
	return (true);
}
function hhotelValidateSubmit()
{
	return false;
}

// Form: update the selected hotel name
function hhotelFormUpdateHotelnames(myForm)
{
	menuNum = myForm.HotelList.selectedIndex;
	if (menuNum == null)
		return;
	myForm.Hotelnames.value = myForm.HotelList.options[menuNum].value;
}

// Form: show the cancel page
function hhotelFormCancel(myForm){
	var CName = myForm.Hotelnames.value;
	var languetype = typeof myForm.langue;
	var langue;
	if (languetype == "undefined")
		langue = "";
	else
		langue = myForm.langue.value;
	if (CName == null || CName == 'All' || CName == ''){ alert('Please select a hotel first'); return (false); }
	return hhotelcancel(CName, langue);
}

// date manager ////////////////////////////////////////////
// build year select
function build_year_select(thisform) {
	var cur_date = new Date();
	var cur_year = takeYear(cur_date);
		
	cur_y = new Option(cur_year, cur_year, true, true);
	thisform.fromyear.options[0] = cur_y;
	if(thisform.toyear != null) {
		cur_yb = new Option(cur_year, cur_year, true, true);
		thisform.toyear.options[0] = cur_yb;
	}
		
	next_y = new Option(cur_year + 1, cur_year + 1, false, false);
	thisform.fromyear.options[1] = next_y;
	next_yb = new Option(cur_year + 1, cur_year + 1, false, false);
	if(thisform.toyear != null) {
		thisform.toyear.options[1] = next_yb;
	}
}
	
// update departure : check 
function update_departure() {
	if(document.getElementById) thisform = document.getElementById("idForm");
	else thisform = document.all["idForm"];

	if(thisform.today == null)
		return;
		
	var ar_day = parseInt(thisform.fromday.value) + 1;
	var ar_month = parseInt(thisform.frommonth.value);
	var ar_year = parseInt(thisform.fromyear.value);
			
	var de_day = parseInt(thisform.today.value) + 1;
	var de_month = parseInt(thisform.tomonth.value);
	var de_year = parseInt(thisform.toyear.value);
	
	if(de_year < ar_year) {
		check_departure();
	} else {
		if(de_year == ar_year) {
			if(de_month < ar_month) {
				check_departure();
			} else {
				if(de_month == ar_month) {
					if(de_day <= ar_day) {
						check_departure();
					}
				}
			}
		}
	}
}

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}


