sfHover = function() {
	var navList = document.getElementById("navContainer").getElementsByTagName("LI");
	var flagList = document.getElementById("flagContainer").getElementsByTagName("LI");
	var sfEls = document.getElementById("flagDiv").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function allTest(min_book) {
	chkPage(min_book); 
}

onload = function init() {
	termsConfirm=0;
	document.getElementById('javaNote').innerHTML = '';
}

function chkPage(min_book) {
	var terms=document.booking.theterms.value;
	arrival_date=document.booking.date_arrive.value;
	no_days=document.booking.no_days.value;
	no_guests=document.booking.no_guests.value;
	room_id=document.booking.room_id.value;
	todayDate = new Date();
	var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9])?$/;
	var parts=document.booking.date_arrive.value.replace(regex,"$1 $2 $3").split(' ');
	Georgian = new Date(parts[0],parts[1]-1,parts[2]);
	Georgian = new Date(Georgian);
	timeDiff = Georgian - todayDate;
	exactTime = eval((((timeDiff/1000)/60)/60)/24);
	critTime = Math.ceil(exactTime);
	
	parts=document.booking.aug_date_start.value.replace(regex,"$1 $2 $3").split(' ');
	augDateStart = new Date(parts[0],parts[1]-1,parts[2]);
	parts=document.booking.aug_date_end.value.replace(regex,"$1 $2 $3").split(' ');
	augDateEnd = new Date(parts[0],parts[1]-1,parts[2]);
	
	var myMonth = Georgian.getMonth();
	var myDate = Georgian.getDate();
	
	// Double or Twin room check two guests
	if(room_id == 5 || room_id == 6) {
		if(no_guests != 2) {
			alert("For a double or twin room, please select two guests only");
			document.booking.no_guests.focus();
			flag=1;
			return false;
		}
	}
		
	// Triple room check three guests
	if(room_id == 7) {
		if(no_guests != 3) {
			alert("For a triple room, please select three guests only");
			document.booking.no_guests.focus();
			flag=1;
			return false;
		}
	}
	
	if(arrival_date =="") {
		alert("Please enter an arrival date");
		document.booking.date_arrive.focus();
		flag=1;
		return false;
	}
	if(myMonth==11 && (myDate==29 || myDate==30 || myDate==31) && no_days < 3)
	{
		alert("You must book at least three nights for bookings over the New Year period");
		document.booking.no_days.focus();
		flag=1;
		return false;
	}
	if(myMonth==7 && myDate>=augDateStart.getDate() && myDate<=augDateEnd.getDate() && no_days<3)
	{
		alert("You must book at least three nights for bookings over this period in August");
		document.booking.no_days.focus();
		flag=1;
		return false;
	}	
	if(critTime <0)
	{
		alert("The date you are trying to book for has already passed. Please select a date in the future!");
		document.booking.date_arrive.focus();
		flag=1;
		return false;
	}		

	if(critTime < min_book)
	{
		alert("Online bookings must be made "+min_book+" days in advance. For bookings at shorter notice, please call the hostel on +44 (0) 131 667 9991 to check on availability.");
		document.booking.day.focus();
		flag=1;
		return false;
	} 

	if(no_days > 7)
	{
		alert("For bookings for greater than 7 days please call the hostel directly on +44 (0) 131 667 9991.");
		document.booking.no_days.focus();
		flag=1;
		return false;
	} 

	if(no_guests > 7)
	{
		alert("For bookings of more than 7 beds or 7 rooms please call the hostel directly on +44 (0) 131 667 9991.");
		document.booking.no_guests.focus();
		flag=1;
		return false;
	} 


	if (termsConfirm=="0")
	{
		alert("Please confirm that you have read and agreed to the Argyle Backpackers \'Terms & Conditions\'. Tick the checkbox to continue.");
		document.booking.theterms.focus();
		flag=1;
		return false;
	}

	else
	{
		document.booking.submit();
	}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
  	d=parent.frames[n.substring(p+1)].document;
  	n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++)
  	x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
  	x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) 
  	x=d.getElementById(n); 
  return x;
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
