function GetLatestDate()
 {
  var Today = new Date();
  var day = Today.getDate();
  var month = Today.getMonth();
  var year = Today.getYear();
  document.search.depDay.selectedIndex=(day-1);
  document.search.depMonth.selectedIndex=month;
 }
function getRadioButton(x)
 {
  returnvalue = false;
  for(i = 0; i < document.getElementsByName(x).length; i++) if(document.getElementsByName(x)[i].checked == true) returnvalue = document.getElementsByName(x)[i].value;
  return returnvalue;
 }

function submitPopupForm(){
  window.resizeTo(770, 500)
  document.getElementById("preload").style.display = "block";
  document.getElementById("preload").style.visibility = "visible";
  document.getElementById("load").style.visibility = "hidden";
  document.getElementById("load").style.display = "none";
  document.search.submit();
  setInterval("checkOpener()", 1000);
}

function checkOpener()
{
  if(window.opener.location.href.indexOf("Request.asp") != -1)
  {
    window.close();
  }
}

function validateSearch()
 {
  var PopupIndicator = document.getElementById("PopupIndicator").value;
  var Today = new Date();
  var day = Today.getDate();
  var month = Today.getMonth();
  var year = Today.getYear();
  var sevenDays = new Date();
  tmp = day + 1;
  sevenDays.setDate(tmp);
  var selectedDay = new Date();
  selectedDay.setYear(document.search.depYear.options[document.search.depYear.selectedIndex].text);
  selectedDay.setMonth(document.search.depMonth.selectedIndex);
  selectedDay.setDate(parseInt(document.search.depDay.value,10)+1);
  var dtDecember = new Date();
  dtDecember.setMonth(11);
  dtDecember.setDate(1);
  if (!getRadioButton("holidayType"))
   {
    alert("Please select either Accommodation & Flights or Accommodation Only");
    return false;
   }
  else if((parseInt(document.search.depDay.valuem,10)==day-1) && (document.search.depMonth.selectedIndex==month) && (document.search.depYear.options[document.search.depYear.selectedIndex].text==year))
   {
    alert("Please remember to select a date");
    document.search.depDay.focus();
    return false;
   }
  else if(selectedDay < sevenDays)
   {
    alert("All accommodation must be booked with at least 1 days notice"); //\nFor reservations departing within the next 1 days please call our reservations staff on 08000 91 32 80");
    document.search.depDay.focus();
    return false;
   }
//  else if (selectedDay<dtDecember)
//   {
//    alert("There is no availability before December");
//    document.search.depDay.focus();
//    return false;
//   }
  else if (document.search.depAirport.selectedIndex == 0 && getRadioButton("holidayType")=="FH")
   {
   alert("Please make sure you select a departure airport");
   document.search.depAirport.focus();
   return false;
   }
  else if(document.search.arrAirport.selectedIndex == 0  && PopupIndicator=="N")
   {
    alert("Please make sure you select your destination");
    document.search.arrAirport.focus();
    return false;
   }
  else if ((document.search.CR1.selectedIndex != 0) && (document.search.agesR1.value == ""))
   {
    alert("Please remember to add the ages of your children");
    document.search.agesR1.focus();
    return false;
   }
  else if ((document.search.CR2.selectedIndex != 0) && (document.search.agesR2.value == ""))
   {
    alert("Please remember to add the ages of your children");
    document.search.agesR2.focus();
    return false;
   }
  else if ((document.search.CR3.selectedIndex != 0) && (document.search.agesR2.value == ""))
   {
    alert("Please remember to add the ages of your children");
    document.search.agesR3.focus();
    return false;
   }
  else
   {	

	if (PopupIndicator=="N")
		{
		//alert('Main search')
		document.getElementById("preload").style.display = "block";
		document.getElementById("preload").style.visibility = "visible";
		document.getElementById("load").style.visibility = "hidden";
		document.getElementById("load").style.display = "none";
		return true;
		}
	else
		{
		//alert('Popup search')
		 submitPopupForm();	
		}
   }
 }
function Popup(Bool)
 {
  document.getElementById("popup").style.visibility = (Bool ? "visible" : "hidden");
  document.getElementById("popup").style.display = (Bool ? "" : "none");
  document.search.depDay.style.visibility = (Bool ? "hidden" : "visible");
  document.search.depMonth.style.visibility = (Bool ? "hidden" : "visible");
  document.search.depYear.style.visibility = (Bool ? "hidden" : "visible");
  document.search.depAirport.style.visibility = (Bool ? "hidden" : "visible");
  document.search.flexibility.style.visibility = (Bool ? "hidden" : "visible");
  document.search.country.style.visibility = (Bool ? "hidden" : "visible");
  document.search.arrAirport.style.visibility = (Bool ? "hidden" : "visible");
  document.search.resort.style.visibility = (Bool ? "hidden" : "visible");
  document.search.boardBasis.style.visibility = (Bool ? "hidden" : "visible");
  document.search.duration.style.visibility = (Bool ? "hidden" : "visible");
  document.search.AR1.style.visibility = (Bool ? "hidden" : "visible");
  document.search.AR2.style.visibility = (Bool ? "hidden" : "visible");
  document.search.AR3.style.visibility = (Bool ? "hidden" : "visible");
  document.search.CR1.style.visibility = (Bool ? "hidden" : "visible");
  document.search.CR2.style.visibility = (Bool ? "hidden" : "visible");
  document.search.CR3.style.visibility = (Bool ? "hidden" : "visible");
  document.search.IR1.style.visibility = (Bool ? "hidden" : "visible");
  document.search.IR2.style.visibility = (Bool ? "hidden" : "visible");
  document.search.IR3.style.visibility = (Bool ? "hidden" : "visible");
 }
function UpdateRooms()
 {
  var Rooms = document.getElementById("rooms").value;
  for (i=2;i<=3;i++)
   {
    if (Rooms<i)
     {
      document.getElementById("RoomRow"+i).style.visibiltiy = "hidden";
      document.getElementById("RoomRow"+i).style.display = "none";
      document.getElementById("AR"+i).value = 0;
      document.getElementById("IR"+i).value = 0;
      document.getElementById("agesR"+i).value = "";
      document.getElementById("CR"+i).value = 0;
     }
    else
     {
      document.getElementById("RoomRow"+i).style.visibiltiy = "visible";
      document.getElementById("RoomRow"+i).style.display = "";
     }
   }
 }
function holidayTypeChange(code)
 {
  if(code == "HO")
   {
    document.getElementById("flightRow").style.display = 'none';
    document.getElementById("flightRow2").style.display = 'none';
    document.getElementById("flexRow").style.display = 'none';
    document.getElementById("flexRow2").style.display = 'none';
    document.getElementById("form_top").src = "images/form_top.gif";
   }
  else
   {
    document.getElementById("flightRow").style.display = '';
    document.getElementById("flightRow2").style.display = '';
    document.getElementById("flexRow").style.display = '';
    document.getElementById("flexRow2").style.display = '';
    document.getElementById("form_top").src = "images/form_top_holiday.gif";
   }
 }
function discountPopup()
 {
  alert("Extra discounts if you ring our sales office today on 0844 482 4030");
 }
function processDate(cal)
 {
  ddDate = document.search.depDay.value = cal.date.print("%d")
  ddMonth = document.search.depMonth.value = cal.date.print("%m")
  ddYear = document.search.depYear.value = cal.date.print("%Y")
 }
