
function setDate(y, m, d)
{
	document.availabilityCheck.room_availability_date.value = d + "/" + m + "/" + y;
	
	return true;
}

//var calendar = new CalendarPopup();  
var now = new Date(); 
var calendar = new CalendarPopup("calendarDiv");
calendar.addDisabledDates(null,formatDate(now,"yyyy-MM-dd"));
calendar.showNavigationDropdowns();
calendar.setReturnFunction("setDate");
calendar.addDisabledDates(null, "19-Nov-2008");

function checkAvailForm(thisForm)
{
	if(thisForm.holiday_type_id.value == "holiday_type_0" || thisForm.holiday_type_id.value == "" || thisForm.holiday_type_id.value == "NULL")
	{
		alert ("Please select a type of holiday");
		thisForm.holiday_type_id.focus();
		
		return false;
	}

	if (thisForm.noadults.value == "0")
	{
		alert ("Please select the number of adults");
		thisForm.noadults.focus();
		
		return false;
	}
	
	if (thisForm.room_availability_date.value == "Date" || thisForm.room_availability_date.value == "" || checkDate(thisForm.room_availability_date.value) == false)
	{
		alert ("Please enter a date");
		thisForm.room_availability_date.focus();
		
		return false;
	}
	
	if (thisForm.airport_code.value == "0")
	{
		alert ("Please select an airport from the list");
		thisForm.airport_code.focus();
		
		return false;
	}
	
	if (thisForm.nonights.value == "0")
	{
		alert ("Please select the number of nights");
		thisForm.nonights.focus();
		
		return false;
	}
	
	if (checkRules() == false)
	{
		return false;
	}
	
	return true;
	
}

holiday_type_0 = new Array("Area","0");
holiday_type_7 = new Array("Area","0","View All","0","Central Algarve", "2","South West Spain","5","Vale do Lobo Area","4","Western Algarve","3");
holiday_type_5 = new Array("Area","0","View All","0","Central Algarve", "2","Vale do Lobo Area","4","Western Algarve","3");
holiday_type_6 = new Array("Area","0","View All","0","Central Algarve", "2","South West Spain","5","Vale do Lobo Area","4","Western Algarve","3");
holiday_type_8 = new Array("Area","0","View All","0","Lisbon Area", "7");
holiday_type_4 = new Array("Area","0","View All","0","Central Algarve", "2","Vale do Lobo Area","4","Western Algarve","3");


function fillRes(selObj)
{
   var i = j = 0;
   var newItem;
   var src;
   var srcName = "";

   for (i = 0; i < selObj.length; i++)
      if (selObj.options[i].selected)
         srcName = selObj.options[i].value;

   src = eval(srcName);

   with (document.availabilityCheck.area_id) 
   {
      options.length = 0;
      for (i = 0; i < src.length; i++)
      {

         newItem = options.length;
   	     options[newItem] = new Option(src[i]);
         options[newItem].value = src[i+1];
         i++;
      }
      options[0].selected = true;
   }
}

function checkRules()
{
	var tempno;
	var holiday_type_id;
	
	holiday_type_id = document.availabilityCheck.holiday_type_id.value;
	
	if (holiday_type_id == "holiday_type_4" || holiday_type_id == "holiday_type_5")
	{
		if (parseInt(document.availabilityCheck.nochildren.value) > parseInt(document.availabilityCheck.noadults.value))
		{
			alert ("Number of child prices cannot exceed number of adults");
			tempno = document.availabilityCheck.noadults.value
			document.availabilityCheck.noadults.value = document.availabilityCheck.nochildren.value;
			document.availabilityCheck.nochildren.value = tempno;
			
			return false;
		}
	}
	else if (holiday_type_id == "holiday_type_6" || holiday_type_id == "holiday_type_7" || holiday_type_id == "holiday_type_8")
	{
		if ((document.availabilityCheck.noadults.value == 1 && document.availabilityCheck.nochildren.value == 1) || (document.availabilityCheck.nochildren.value > document.availabilityCheck.noadults.value / 2))
		{
			alert ("Only 1 child can share a standard room with 2 adults. Please contact us on 08707 50 54 50 for a different room quotation.");
			
			return false;
		}
	}
	
	return true;
}

function populate_nights()
{
	var newItem;
	var i;
	var holiday_type_id = document.availabilityCheck.holiday_type_id.value;

	with (document.availabilityCheck.nonights)
	{
		options.length = 0;

		options[0] = new Option("Number of nights");
		options[0].value = "0";
	
		//Villas and apartments
		if (holiday_type_id == "holiday_type_4" || holiday_type_id == "holiday_type_5")
		{
			options[1] = new Option("7");
			options[1].value = "7";
			options[2] = new Option("14");
			options[2].value = "14";
		}
		//
		else if (holiday_type_id == "holiday_type_6" || holiday_type_id == "holiday_type_7" || holiday_type_id == "holiday_type_8")
		{
			
			for (i=3; i <=30; i++)
			{
				newItem = options.length;
				options[newItem] = new Option(i);
				options[newItem].value = i;
			}
		}
	}
}
