/*****







 * Copyright © FASTBOOKING  2000-2006
 * 24/11/2006
*/

var FBRESA = "http://www.fastbookings.biz/DIRECTORY/";


// search availabilities for selected promotions
function hhotelSearchPromo(cluster, lg, theme)
{
	hhotelSearch(cluster, lg, "", "", "", theme, "");
}

// 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");
}

// 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);
}

// 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");
}

///////////////////////////////////////////////////////////////////////////////////////
// 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 languetype = typeof myForm.action;
	myForm.action = FBRESA + "dispoprice.phtml";
	window.open('','dispoprice', 'toolbar=no,width=800,height=550,menubar=no,scrollbars=yes,resizable=yes');
	myForm.submit();
	return (true);
}

// 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);
}


// 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 ];
jour = 7;
	
build_year_select();

MD = new Date();
	
nday = MD.getDate();
aday = MD.getDay();
amois = MD.getMonth();
ayear = takeYear(MD);
cur_year = ayear;
		
nday += jour;

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;

document.idForm.fromday.selectedIndex = indexDay;
document.idForm.frommonth.selectedIndex = indexMois;
document.idForm.fromyear.selectedIndex = indexYear;

}

//
// build year select
function build_year_select() {
		
var cur_date = new Date();
var cur_year = takeYear(cur_date);
	
cur_y = new Option(cur_year, cur_year, true, true);
document.idForm.fromyear.options[0] = cur_y;
if(document.idForm.toyear != null) {
	cur_yb = new Option(cur_year, cur_year, true, true);
	document.idForm.toyear.options[0] = cur_yb;
}
	
next_y = new Option(cur_year + 1, cur_year + 1, false, false);
document.idForm.fromyear.options[1] = next_y;
next_yb = new Option(cur_year + 1, cur_year + 1, false, false);
if(document.idForm.toyear != null) {
	document.idForm.toyear.options[1] = next_yb;
	}
}
	

function takeYear(theDate)
{
        x = theDate.getYear();
        var y = x % 100;
        y += (y < 38) ? 2000 : 1900;
        return y;
}

