function setarrivalday()
{ var orig_day=0;
  var date=new Date(document.booking.arrivalMonth.value.substring(3,7),document.booking.arrivalMonth.value.substring(0,2),document.booking.arrivalDate.value);
  var year=date.getFullYear();
  var month=date.getMonth();
  var day=date.getDate();
  if(month<10)
  { month="0"+month;
  }
  document.booking.arrivalMonth.value=month+"-"+year;
  
  //document.booking.arrivalYear.value=year;
  document.booking.arrivalDate.value=day;
  
  var dow=date.getDay();
  var word="";
  if(dow==0) word="Sunday";
  if(dow==1) word="Monday";
  if(dow==2) word="Tuesday";
  if(dow==3) word="Wednesday";
  if(dow==4) word="Thursday";
  if(dow==5) word="Friday";
  if(dow==6) word="Saturday";
  document.getElementById("arrival_display").innerHTML=word;
  
  var otherdate=new Date(document.booking.departureMonth.value.substring(3,7),document.booking.departureMonth.value.substring(0,2),document.booking.departureDate.value);
  var otheryear=otherdate.getFullYear();
  var othermonth=otherdate.getMonth();
  if(othermonth<10)
  { othermonth="0"+othermonth;
  }
  var otherday=otherdate.getDate();
  if(otherday<10)
  { otherday="0"+otherday;
  }
  orig_day=day;
  if(day<10)
  { day="0"+day;
  }

  if((otheryear+""+othermonth+""+otherday)<=(year+""+month+""+day))
  { otherdate.setYear(year);
    otherdate.setMonth(month);
    
    otheryear=otherdate.getFullYear();
    othermonth=otherdate.getMonth();
    
    	

	
	if(othermonth<10)
    { othermonth="0"+othermonth;
    }

	if((otheryear+""+othermonth+""+otherday)<=(year+""+month+""+day))
    { otherdate.setDate(orig_day+1);
    }
	
	
  	
	year=otherdate.getFullYear();
    month=otherdate.getMonth();
    day=otherdate.getDate();
    if(month<10)
    { month="0"+month;
    }

	document.booking.departureMonth.value=month+"-"+year;
    
	//document.booking.departureYear.value=year;
    document.booking.departureDate.value=day;
	  
	var dow=otherdate.getDay();
    var word="";
    if(dow==0) word="Sunday";
    if(dow==1) word="Monday";
    if(dow==2) word="Tuesday";
    if(dow==3) word="Wednesday";
    if(dow==4) word="Thursday";
    if(dow==5) word="Friday";
    if(dow==6) word="Saturday";
    document.getElementById("departure_display").innerHTML=word;
  }

}


function setdepartureday()
{ 
  var date=new Date(document.booking.departureMonth.value.substring(3,7),document.booking.departureMonth.value.substring(0,2),document.booking.departureDate.value);
  var year=date.getFullYear();
  var month=date.getMonth();
  var day=date.getDate();

  if(month<10)
  { month="0"+month;
  }

  document.booking.departureMonth.value=month+"-"+year;
  document.booking.departureDate.value=day;
  
  var dow=date.getDay();
  var word="";
  if(dow==0) word="Sunday";
  if(dow==1) word="Monday";
  if(dow==2) word="Tuesday";
  if(dow==3) word="Wednesday";
  if(dow==4) word="Thursday";
  if(dow==5) word="Friday";
  if(dow==6) word="Saturday";
  document.getElementById("departure_display").innerHTML=word;
}

function arrival_dates(day, month, year, current_month, current_year) {
	var i;
	var c;
	
	if(month.length > 1 && month.length < 2 && month < 10) {
		month = "0"+month;
	}
	
	document.write("<select id='arrivalDate' name ='FDAY' style='width: 50px' class='dd3' onchange='setarrivalday()'>");
	document.write("<option value=''>Day</option>");
	
	for(i = 1; i < 32; i++) {
		document.write("<option");
		if(day==i) {
			document.write(" selected");
		}
		document.write(" value='"+i+"'>"+i+"</option>");
	}
	
	document.write("</select><select id='arrivalMonth' name='FMONTH' style='width: 110px' class='dd3' onchange='setarrivalday()'>");
	document.write("<option value=''>Month/Year</option>");
	
	var now_month = current_month-2;
	var now_year = current_year;
	var dmonth;
	
	i=0;
	
	for(c = 0; c < 25; c++) {
		now_month++;
		
		if(now_month>11) {
			now_month=0;
			now_year++;
		}
		
		dmonth=now_month;
		if(dmonth<10) {
			dmonth="0"+dmonth;
		}
		
		document.write("<option");
		
		if(month==dmonth && year==now_year) {
			document.write(" selected");
		}
		
		document.write(" value='"+dmonth+"-"+now_year+"'>");
		if(now_month==0) document.write("January");
		if(now_month==1) document.write("February");
		if(now_month==2) document.write("March");
		if(now_month==3) document.write("April");
		if(now_month==4) document.write("May");
		if(now_month==5) document.write("June");
		if(now_month==6) document.write("July");
		if(now_month==7) document.write("August");
		if(now_month==8) document.write("September");
		if(now_month==9) document.write("October");
		if(now_month==10) document.write("November");
		if(now_month==11) document.write("December");
		document.write(" "+now_year+"</option>");
	}
	document.write("</select>");
}

function departure_dates(day, month, year, current_month, current_year) {
	var i;
	var c;
	
	if(month.length < 2 && month < 10) {
		month="0"+month;
	}
	
	document.write("<select id='departureDate' name ='TDAY' style='width: 50px' class='dd3' onchange='setdepartureday()'>");
	document.write("<option value=''>Day</option>");
	
	for(i = 1; i < 32; i++) {
		document.write("<option");
		
		if(day==i) {
			document.write(" selected");
		}
		
		document.write(" value='"+i+"'>"+i+"</option>");
	}
	
	document.write("</select><select id='departureMonth' name='TMONTH' style='width: 110px' class='dd3' onchange='setdepartureday()'>");
	document.write("<option value=''>Month/Year</option>");
	
	var now_month=current_month-2;
	var now_year=current_year;
	var dmonth;
	i=0;
	
	for(c = 0; c < 25; c++) {
		now_month++;
		
		if(now_month > 11) {
			now_month=0;
			now_year++;
		}
		
		dmonth=now_month;
		if(dmonth<10) {
			dmonth="0"+dmonth;
		}
		
		document.write("<option");
		if(month==dmonth && year==now_year) {
			document.write(" selected");
		}
		
		document.write(" value='"+dmonth+"-"+now_year+"'>");
		if(now_month==0) document.write("January");
		if(now_month==1) document.write("February");
		if(now_month==2) document.write("March");
		if(now_month==3) document.write("April");
		if(now_month==4) document.write("May");
		if(now_month==5) document.write("June");
		if(now_month==6) document.write("July");
		if(now_month==7) document.write("August");
		if(now_month==8) document.write("September");
		if(now_month==9) document.write("October");
		if(now_month==10) document.write("November");
		if(now_month==11) document.write("December");
		document.write(" "+now_year+"</option>");
	}
	document.write("</select>");
}

function adults(adults, count) {
	var i;
	if(!count) count = 3;
  document.write("<select name='adults' class='dd3' style='width:45px'>");
  for(i=1;i<count;i++)
  { document.write("<option value='"+i+"'");
    if(adults==i)
    { document.write(" selected ");
    }
    document.write(">"+i+"</option>");
  }
  document.write("</select>");
}
function children(children, count) {
	var i;
	if(!count) count = 3;	
  document.write("<select name='children' class='dd3' style='width:45px'>");
  for(i=0;i<count;i++)
  { document.write("<option value='"+i+"'");
    if(children==i)
    { document.write(" selected ");
    }
    document.write(">"+i+"</option>");
  }
  document.write("</select>");
}
function rooms(rooms, count)
{ var i;
  document.write("<select name='rooms' class='dd3' style='width:45px'>");
  for(i=1;i<count;i++)
  { document.write("<option value='"+i+"'");
    if(rooms==i)
    { document.write(" selected ");
    }
    document.write(">"+i+"</option>");
  }
  document.write("</select>");
}
function beds(beds, count)
{ var i;
  document.write("<select name='beds' class='dd3' style='width:45px'>");
  for(i=1;i<count;i++)
  { document.write("<option value='"+i+"'");
    if(beds==i)
    { document.write(" selected ");
    }
    document.write(">"+i+"</option>");
  }
  document.write("</select>");
}