function typeDate(name, type, data, product)

{

	this.name = name;

	this.type = type;

	this.noDays = 2;

	this.data = data;

	this.make(data);

	this.flag = false;

	this.weekender = product;

}



typeDate.prototype.make = function(data)

{

	this.date = (data) ? new Date(data) : new Date();

	this.day = this.date.getDate();

	this.month = this.date.getMonth();

	this.year = this.date.getYear();

	

	var Ttoday = new Date();

	var dateDiff = ( getUTC("From") - Date.UTC(Ttoday.getYear(), Ttoday.getMonth(), Ttoday.getDate()) ) / 86400000;

	

	if ( dateDiff <= 1 && this.type == "From")

	{

			if (this.flag)

			{

				alert("Holiday Autos Web Reservations"

						+ "\n_____________________________________________________   \n\n"

						+ "We regret we are unable to take bookings departing within 2 days on our website." 

						+ "\nPlease call our reservations department on the number listed above."

						+ "\n_____________________________________________________   \n");

			}

			

			this.day += (dateDiff < 0) ? ((dateDiff * -1) + 2) : 2;



	}

}



typeDate.prototype.write = function()

{

	with (document.details)

	{

		if (this.weekender)

		{

			if (this.type != "To") 

			{ 

				this.isWeekEnd(); 

				document.details.ProductID.value = this.weekender;

			}

			

			if (this.type == "To" && this.date.getDay() == 1 && ( slToTime.options.selectedIndex < 21 || slToTimePart.options.selectedIndex == 1 ))

				{

				slToTime.options[21].selected = true;

				slToTimePart.options[0].selected = true;

			}

			else if (this.type == "From" && this.date.getDay() == 5 && slFromTimePart.options.selectedIndex == 0)

			{

				slFromTime.options[0].selected = true;

				slFromTimePart.options[1].selected = true;

			}

		}

		

/*

		if (this.type == "From" && 

			( ( /11/.test(this.month) && /25|26/.test(this.day) ) || ( /0/.test(this.month) && /1/.test(this.day) ) )

			)

		{

			if (this.flag)

			{

				alert(

				"Holiday Autos Web Reservations"

				+ "\n__________________________________________              \n\n"

				+ "\nSiamo spiacenti comunicare che le prenotazioni web con partenza 25 e "

				+ "\n26 dicembre e 1 gennaio sono sospese. "

				+ "\n\nPrego contattare il call center nal numero 848.800.820 per verificare "

				+ "\nla disponibilita', oppure inviare "

				+ "\nuna email a booking@holidayautos.it"

				+ "\n__________________________________________              \n");

			}

			this.day += 2;

		}

*/		

	}



	var element = this.getElement("document.details.sl" + this.type);

	element('Day').options[(this.day - 1)].selected = true;

	element('Month').options[this.month].selected = true;

	element('Year').options[(this.year - 2004)].selected = true;

	element('Day').onchange = this.setAction("change");

	element('Month').onchange = this.setAction("change");

	element('Year').onchange = this.setAction("change");

	element('Time').onchange = this.setAction("change");

	element('TimePart').onchange = this.setAction("change");

	document.details.duration.onblur = this.setAction("change");



}



typeDate.prototype.getElement = function(type)

{

	return function(name) {	return eval (type + name); };

}



typeDate.prototype.setAction = function(action)

{

	return eval ( this.name + "." + action );

}



typeDate.prototype.set = function()

{

	this.write();

	this.then = new typeDate("now.then", "To"

				, Date.UTC(this.year, this.month, this.day) 

				+ (86400000 * this.noDays), this.weekender);

	this.then.write();

	this.flag = true;

}



typeDate.prototype.change = function()

{

	with (document.details)

	{

		modFDays();

		var Ttoday = new Date();

		now.noDays = (( ( getUTC("From") - Date.UTC(Ttoday.getYear(), Ttoday.getMonth(), Ttoday.getDate()) ) / 86400000 < 1 

						&& duration.value <= 2 ) || (getUTC("To") - getUTC("From")) / 86400000 < 1) 

							? 2 

							: (getUTC("To") - getUTC("From")) / 86400000;

		

		duration.value = now.noDays;

		now.make(getUTC(now.type));

		now.set();

		duration.value = (now.then.data - getUTC(now.type)) / 86400000;

		now.noDays = duration.value;

	}

}



function getUTC(type)

{

	return Date.UTC(getValue("sl" + type, "Year")

		 	, (getValue("sl" + type, "Month") - 1)

		 	, getValue("sl" + type, "Day"));

}



function getValue(fix, type, swch)

{

	with (eval("document.details"))

	{

	return (type == 'Year')

		? (swch)

			? elements[fix + type].selectedIndex

			: elements[fix + type].options[elements[fix + type].selectedIndex].text

		: (elements[fix + type].selectedIndex + 1);

	}

}



typeDate.prototype.isWeekEnd = function()

{

	with (document.details)

	{

		var noDays = (this.date.getDay() && this.date.getDay() < 6)

				? 5 - this.date.getDay() : 0;

				

		if (duration.value >= 3)

		{	

			duration.value = this.noDays = 3;

		} 

		

		if (!this.date.getDay() || this.date.getDay() == 6)

		{

			duration.value = this.noDays = 2;	

		}

		

		if (this.date.getDay() >= 1 && this.date.getDay() < 6 && noDays && this.flag)

		{

			var opt = confirm(

				"Holiday Autos Weekend Offer"

				+ "\n__________________________________________              \n\n"

				+ "con questa offerta puoi prenotare la vettura soltanto per \ni weekenda , quindi con "

				+ "ritiro il venerdi' od il sabato ed il \nrilascio il lunedi' entro le 1.00." 

				+ "\n\nper continuare fai click su SI e noi selezioneremo per te il \nprossimo"

				+ "weekend, altrimenti fai click su NO per tornare al \nnostro motore di"

				+ "prenotazione abituale o ad altre offerte"

				+ "\n__________________________________________              \n");

			if (!opt)

			{

				document.location = "MainFrame.w?ctryref=ITA&lang=IT&aff=&";

			}

			else

			{

				duration.value = this.noDays = 3;

				}

		}

		

		this.flag = true;

		this.make(Date.UTC(this.year, this.month, this.day) 

					+ ((this.date.getDay()) 

						? (86400000 * noDays) 

						: -86400000));

	}

}



function loadLocations(loca)

{

	with (document.details)

	{

		station.length = loca.length + 1;

		station.options[0].text = "select a destination";

		station.options[0].value = "";

		

		for (var k = 0; k < loca.length; k++)

		{

			station.options[k + 1] = new Option(loca[k], loca[k]);

		}	

	}





window.onerror = new function() { return true; }



getParam();

if (bookinguide && bookinguide == 1) 
{

	var x = new Date();

	var now = new typeDate("now", "From", Date.UTC(x.getYear(), x.getMonth(), x.getDate()) + (86400000 * 1), ((keys['ProductID']) ? keys['ProductID'] : false));

	now.set();

}
}
