/*
when any of the datefileds is changed
if arrival changed
	check if departure is at least 3 days ahead, if not, change
if departure changed
	check if arrival is at least 3 days before, if not, change
*/

function make_3_days_difference(set_which)
{
	if (set_which != 'arr' && set_which != 'dep')
	{
		return;
	}
	var arr_date = new Date(document.buscador.anho_llegada.value * 1 + 2000, document.buscador.mes_llegada.value * 1 - 1, document.buscador.dia_llegada.value);
	var dep_date = new Date(document.buscador.anho_salida.value * 1 + 2000, document.buscador.mes_salida.value * 1 - 1, document.buscador.dia_salida.value);

	diff = (dep_date.getTime() - arr_date.getTime()) / 1000 / 60 / 60 / 24;

	if (diff < 3)
	{
		switch (set_which)
		{
			case 'dep':
			var new_dep = new Date(document.buscador.anho_llegada.value * 1 + 2000, document.buscador.mes_llegada.value * 1 - 1, document.buscador.dia_llegada.value * 1 + 3);
			document.buscador.anho_salida.value = new_dep.getFullYear().toString().substr(2, 2);
			document.buscador.mes_salida.value = new_dep.getMonth() + 1;
			document.buscador.dia_salida.value = new_dep.getDate();
			break;

			case 'arr':
			var new_arr = new Date(2000 + document.buscador.anho_salida.value * 1, document.buscador.mes_salida.value * 1 - 1, document.buscador.dia_salida.value * 1 - 3);
			document.buscador.anho_llegada.value = new_arr.getFullYear().toString().substr(2, 2);
			document.buscador.mes_llegada.value = new_arr.getMonth() + 1;
			document.buscador.dia_llegada.value = new_arr.getDate();
			break;
		}
	}
}
