﻿var id;
var curDate;
var curWeekday;
var sel3;
		
var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  //link.style.fontWeight = 'bold';
  return false;
}

function catcalc(cal, id)
{
	var date = cal.date;
	var time = date.getTime()
	// use the _other_ field
	var field = document.getElementById(id);
	field.value = date.print("%d/%m/%Y");
	curDate = field.value;
	if (id != 'checkout_GB')
	{ 
	document.getElementById('checkin').value = date.print("%m/%d/%Y");
	setDeparture(); }
}

function showCalendar(curId, format)
{
	id = curId;
	format = format ? format : '%d/%m/%Y';
	curDate = document.getElementById(curId).value;
	
	Calendar.setup({
		inputField : curId, // id of the input field
		button : curId+'id', // id of the button
		date : curDate,
		ifFormat : format, // format of the input field
		onUpdate : catcalc
	});
}

function setDeparture()
{
	tomorrow = new Date(document.getElementById("checkin_GB").value.split('/').reverse().join('/'));
	tomorrow = tomorrow.setDate(tomorrow.getDate()+1);
	tomorrow = new Date(tomorrow);
	mydate = tomorrow;
	var theyear = mydate.getFullYear();
	var themonth = mydate.getMonth()+1;
	var theday = mydate.getDate();
	if (themonth < 10)
	{ themonth = "0" + themonth; }
	if (theday < 10)
	{ theday = "0" + theday; }
	tomorrow = theday + "/" + themonth + "/" + theyear;
	document.getElementById("checkout_GB").value = tomorrow;
	document.getElementById("checkout").value = themonth + "/" + theday + "/" + theyear;
}

function convertDatesToUS()
{
	var checkIn, checkOut;
	var tempDay, tempMonth, tempYear;

	checkIn = new Date(document.getElementById("checkin_GB").value.split('/').reverse().join('/'));
	tempYear = checkIn.getFullYear();
	tempMonth = checkIn.getMonth()+1;
	tempDay = checkIn.getDate();
	if (tempMonth < 10)
	{ tempMonth = "0" + tempMonth; }
	if (tempDay < 10)
	{ tempDay = "0" + tempDay; }
	document.getElementById('checkin').value = tempMonth + "/" + tempDay + "/" + tempYear;
	
	checkOut = new Date(document.getElementById("checkout_GB").value.split('/').reverse().join('/'));
	tempYear = checkOut.getFullYear();
	tempMonth = checkOut.getMonth()+1;
	tempDay = checkOut.getDate();
	if (tempMonth < 10)
	{ tempMonth = "0" + tempMonth; }
	if (tempDay < 10)
	{ tempDay = "0" + tempDay; }
	document.getElementById('checkout').value = tempMonth + "/" + tempDay + "/" + tempYear;
}

curDate = document.getElementById('checkout_GB').value;
Calendar.setup({
	inputField : 'checkout_GB', // id of the input field
	button : 'checkoutid', // id of the button
	date : curDate,
	ifFormat : "%d/%m/%Y",
	onUpdate : function (cal) { catcalc(cal, 'checkout_GB'); }
});
	
curDate = document.getElementById('checkin_GB').value;
Calendar.setup({
	inputField : 'checkin_GB', // id of the input field
	button : 'checkinid', // id of the button
	date : curDate,
	ifFormat : "%d/%m/%Y",
	onUpdate : function (cal) { catcalc(cal, 'checkin_GB'); }
});
