//--Returns the current system time
function nowStr() {
var now=new Date()
var hours=now.getHours()
if (hours < 10) {
	hours = "0"+hours;
	}

var minutes=now.getMinutes()
if ((minutes%5) != 0) {
	minutes -= minutes%5;
}
if ((minutes%30) != 0) {
	minutes -= minutes%30;
}
minutes = ""+minutes;
if (minutes.length == 1) {
	minutes = minutes+"0";	
}

timeStr=hours+""+minutes;

theform = document.getElementById("holidayconnect");
for (i=0; i<theform.arrivaltime.options.length; i++) {
	if (theform.arrivaltime.options[i].value == timeStr) {
		theform.arrivaltime.options[i].selected = true;
		theform.depart_time.options[i].selected = true;
	} else {
		theform.arrivaltime.options[i].selected = false;
		theform.depart_time.options[i].selected = false;
	}
}

todayStr();
}

//--Returns the current date
var months = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC")
var maxdays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var selection = 0;
function todayStr() {
	var today=new Date()

	todaymonth = today.getMonth()+1;
	month = months[(todaymonth-1)];
	//month = transformMonth(month);
	day = today.getDate();
	if (day <10) { day = "0"+day; }
	year = (today.getYear() + 1900);
	year -= 2000;
	if (year < 10) { year = "0"+year; }
	month_year = month+year;
	
	theform = document.getElementById("holidayconnect");
	for (i=0; i<=30; i++) {
		if (theform.day.options[i].value == day) {
			theform.day.options[i].selected = true;
			theform.checkin_day.options[i].selected = true;
			selection = i;
		} else {
			theform.day.options[i].selected = false;
			theform.checkin_day.options[i].selected = false;
		}
	}
	if ((selection+8) < maxdays[(todaymonth-1)]) {	
			theform.day_to.options[selection+7].selected = true;
			month_to = months[(todaymonth-1)];
	} else {
		if (todaymonth == 2) {
			if (day == 22 && (year%4) == 0) {
				theform.day_to.options[selection+7].selected = true;
				month_to = months[(todaymonth-1)];
			} else {
				theform.day_to.options[6].selected = true;
				month_to = months[(todaymonth)];
			}
		} else {
			theform.day_to.options[6].selected = true;
			month_to = months[(todaymonth)];
		}

	}
	
	for (i=0; i<theform.month_year.options.length; i++) {
			if (theform.month_year.options[i].value == (month+year)) {
				theform.month_year.options[i].selected = true;
				theform.checkin_monthyear.options[i].selected = true;
			} else { theform.month_year.options[i].selected = false; theform.checkin_monthyear.options[i].selected = false; }
			if (theform.month_year.options[i].value == (month_to+year)) {
				theform.month_year_to.options[i].selected = true;
			} else {
				theform.month_year_to.options[i].selected = false;
			}
	}
	var carpark_table = document.getElementById("carpark_table");
	var submitbutton = document.getElementById('submitbutton');
	if(document.holidayconnect.choice[0].checked) {	
		submitbutton.style.paddingLeft = (carpark_table.scrollWidth-90)+"px";
	} else {
		submitbutton.style.paddingLeft = "180px";
	}
	
}

function transformMonth(month) {
	switch (month) {
		case 1:
			month = "JAN";
		break;
		case 2:
			month = "FEB";
		break;
		case 3:
			month = "MAR";
		break;
		case 4:
			month = "APR";
		break;
		case 5:
			month = "MAY";
		break;
		case 6:
			month = "JUN";
		break;
		case 7:
			month = "JUL";
		break;
		case 8:
			month = "AUG";
		break;
		case 9:
			month = "SEP";
		break;
		case 10:
			month = "OCT";
		break;
		case 11:
			month = "NOV";
		break;
		case 12:
			month = "DEC";
		break;

	}
	 return month;
	 
}