// JavaScript Document
function checkChildren(){
	var miniPlaceFinder = document.getElementById('miniPlaceFinder');
	if (miniPlaceFinder.nchild.selectedIndex != 0){ //not '0 children'
		alert('There may be extra charges that apply for Children, which will be added to your bill when checking out of the Hotel.');
		return false; 
	}	
}
function openCalendar(str_ctrl,str_month,str_day,str_form){
	var vWinCal = window.open("http://www.clarionhotelsuiteslimerick.com/common/calendar/calendar2.cfm?ctrl="+str_ctrl+"&month="+str_month+"&day="+str_day+"&form="+str_form, "Calendar", "width=350,height=250,status=no,resizable=yes,top=200,left=200");
	vWinCal.focus();
}
function checkDates(ctrl, formName){
	//get the values of these dates so we can validate
	var myform = document.getElementById(formName);
	var ONE_DAY = 1000 * 60 * 60 * 24;
	var today = new Date();
	var arrivalDate = new Date(today.getFullYear(),myform.month.options.selectedIndex-1,myform.day.options.selectedIndex);
	var departDate = new Date(today.getFullYear(),myform.depart_month.options.selectedIndex-1,myform.depart_day.options.selectedIndex);
	if(myform.month.options.selectedIndex < today.getMonth()){
		arrivalDate.setFullYear(today.getFullYear()+1);
	}	
	if(myform.depart_month.options.selectedIndex < today.getMonth()){
		departDate.setFullYear(today.getFullYear()+1);
	}	
	if(ctrl == 'arrival'){
	   if (arrivalDate.getTime() >= departDate.getTime()){
	      departDate.setTime(arrivalDate.getTime()+ONE_DAY);			
	   }        
	}else if(ctrl == 'depart'){
	   if (departDate.getTime() <= arrivalDate.getTime()){
	      arrivalDate.setTime(departDate.getTime()-ONE_DAY);
	   }
	}
	myform.day.options.selectedIndex=eval(arrivalDate.getDate());
	myform.month.options.selectedIndex=eval(arrivalDate.getMonth()+1);
	myform.depart_day.options.selectedIndex=eval(departDate.getDate());
	myform.depart_month.options.selectedIndex=eval(departDate.getMonth()+1);
}
function validateDates(formName){
	//get the values of these dates so we can validate
	var myform = document.getElementById(formName);
	var today = new Date();
	var arrivalDate = new Date(today.getFullYear(),myform.month.options.selectedIndex-1,myform.day.options.selectedIndex);
	var departDate = new Date(today.getFullYear(),myform.depart_month.options.selectedIndex-1,myform.depart_day.options.selectedIndex);

	//if selected arrival date is earlier than the current date, add 1 year to the arrival date
	if (myform.month.options.selectedIndex < today.getMonth()){
	  arrivalDate.setFullYear(today.getFullYear()+1);
	}	
	//if selected departure date is earlier than the current month, add 1 year to the departure date
	if (myform.depart_month.options.selectedIndex < today.getMonth()){
	  departDate.setFullYear(today.getFullYear()+1);
	}
	if (arrivalDate.getTime() > departDate.getTime()){	
		return 1;
	}
	//if arrival departure booking is more than 51 weeks(357 days) in advance inform the
	//user this isn't possible to book
	//Call the weeks_between function
	var days_left = daysBetween(today, arrivalDate)
	if (days_left > 357){
		return 2;
	}
	
	// Call the weeks_between function
	days_left = daysBetween(today, departDate)
	if (days_left > 357){	
		return 5; 
	}
}
function daysBetween(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24
    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()
    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)
}