
// Gallery Array
var RoomPath     = 'images/roomgallery/';
var RoomArray    = ['Bottom Hallway', 
                    'Top Hallway', 
                    'Dining Room', 
                    'Room 4', 
                    'Room 6', 
                    'Room 7', 
                    'Room 7b', 
                    'Room 8', 
                    'Room 8b', 
                    'Room 9', 
                    'Room 9b' ];
var RoomArrayImg = ['bottom_hallway.jpg', 
                    'top_hallway.jpg', 
                    'dining_room.jpg', 
                    'room_4.jpg', 
                    'room_6.jpg', 
                    'room_7.jpg', 
                    'room_7b.jpg', 
                    'room_8.jpg', 
                    'room_8b.jpg', 
                    'room_9.jpg', 
                    'room_9b.jpg' ];


var RoomIndex    = 0;
var RoomIndexMax = RoomArray.length - 1;

function RoomNext() {
	var OldRoomIndex = RoomIndex;
	RoomIndex++;
    if (RoomIndex > RoomIndexMax) {
		RoomIndex = 0;
	}
	
	var SitePath = document.getElementById('SitePath').value;
	
    document.getElementById('RoomGalleryCaption' + OldRoomIndex).style.display = 'none';
    document.getElementById('RoomGalleryCaption' + RoomIndex).style.display    = '';
	document.getElementById('RoomGallery').src   = SitePath + RoomPath + RoomArrayImg[RoomIndex];
    document.getElementById('RoomGallery').title = RoomArray[RoomIndex];
}

function RoomPrev() {
	var OldRoomIndex = RoomIndex;
	RoomIndex--;
    if (RoomIndex < 0) {
		RoomIndex = RoomIndexMax;
	}
	
	var SitePath = document.getElementById('SitePath').value;	
	
    document.getElementById('RoomGalleryCaption' + OldRoomIndex).style.display = 'none';
    document.getElementById('RoomGalleryCaption' + RoomIndex).style.display    = '';
    document.getElementById('RoomGallery').src   = SitePath + RoomPath + RoomArrayImg[RoomIndex];
    document.getElementById('RoomGallery').title = RoomArray[RoomIndex];
}

function RoomCaptions() {
    for (i = 1; i <= RoomIndexMax; i++) {
	    document.write("<div id=\"RoomGalleryCaption" + i + "\" style=\"display: none; \" class=\"GalleryCaption\">" + RoomArray[i] + "</div>");
	}
}

function ChangeLanguage(language) {
	var SitePath = document.getElementById('SitePath').value;
	var newPage = SitePath + language + sPage;
	window.location = newPage;
}

var sPath = window.location.pathname;
var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);


function MM_validateForm() { //v4.0
  if (document.getElementById){
    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
      if (val) { nm=val.name; if ((val=val.value)!="") {
        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
        } else if (test!='R') { num = parseFloat(val);
          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
    } if (errors) alert('The following error(s) occurred:\n'+errors);
    document.MM_returnValue = (errors == '');
} }

function check_rooms() {
	var errors = '';
	
	if (document.MM_returnValue) {
		room_totals = document.getElementById('Doubles').value + document.getElementById('Singles').value;
		if (room_totals == 0) {
			errors+='- You must select at least one double or single room.\n';
			alert('The following error(s) occurred:\n'+errors);	
		}
		document.MM_returnValue = (errors == '');
	}
}

function check_dates() {
	var start_date = new Date(document.getElementById('from').value);
	var end_date = new Date(document.getElementById('to').value);
	var today_date = new Date();
	var errors = '';
	
	//end_date.setFullYear(document.getElementById('YearTo').value,
 	//					 document.getElementById('MonthTo').value - 1,
	//					 document.getElementById('DayTo').value);
	
	//start_date.setFullYear(document.getElementById('YearFrom').value,
 	//					   document.getElementById('MonthFrom').value - 1,
	//					   document.getElementById('DayFrom').value);
	
	if (end_date.getMonth() != document.getElementById('MonthTo').value - 1) {
		errors+='- You must select a valid end date.\n';
	} else if (start_date.getMonth() != document.getElementById('MonthFrom').value - 1) {
		errors+='- You must select a valid start date.\n';
	} else if (start_date < today_date) {
		errors+='- You must select an start date that is in the future.\n';
	} else if (start_date > end_date) {
		errors+='- You must select an end date that is later than the start date.\n';
	}
	
	if (errors != '') {
		alert('The following error(s) occurred:\n'+errors);	
	}
	document.MM_returnValue = (errors == '');
}

function validate() {
	MM_validateForm('Name','','R','Phone','','R','Email','','RisEmail');
	if (document.MM_returnValue) {
		check_rooms();
	}
	if (document.MM_returnValue) {
		check_dates();
	}
}