// JavaScript Document
function checkMiniSearch(){
	var miniPlaceFinder = document.getElementById('miniPlaceFinder');
	if (miniPlaceFinder.destination.selectedIndex == 0){
		alert('Please select a location.');
		return false; 
	}
	if (miniPlaceFinder.month.selectedIndex == 0){
		alert('Please select a check in month.');
		return false; 
	}
	if (miniPlaceFinder.day.selectedIndex == 0){
		alert('Please select a check in day.');
		return false; 
	}
		if (miniPlaceFinder.depart_month.selectedIndex == 0){
		alert('Please select a check out month.');
		return false; 
	}
	if (miniPlaceFinder.depart_day.selectedIndex == 0){
		alert('Please select a check out day.');
		return false; 
	}
	var result = validateDates('miniPlaceFinder');
	if( result == 1 ) {
		alert('The Check in date must be before the Check out date. A date earlier than today is considered next year.');
		return false;
	}
	if( result == 2) {
		alert('You cannot book a room more than 51 weeks in the future. A date earlier than today is considered next year.');
		return false;
	}
}
function openCalendar(str_ctrl,str_month,str_day,str_form){
	var vWinCal = window.open("http://www.choicehotelsmexico.com/mx/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)
}
function submitCCForm(frmName) {
	var choiceclubform = document.getElementById('ccform');
	if (choiceclubform.username.value == ''){
		alert('Please enter your Choice Club number.');
	return false; 
}
	if (choiceclubform.password.value == ''){
		alert('Please enter your Choice Club password.');
	return false; 
}
	choiceclubform.submit();
	choiceclubform.username.value = '';
	choiceclubform.password.value = '';
}
function MM_showHideLayersHiding() { //v6.0
	var i,p,v,obj,args=MM_showHideLayersHiding.arguments;
	for (i=0; i<(args.length-2); i+=3) {
	if ((obj=MM_findObj(args[i]))!=null) { 
		v=args[i+2];
		if (obj.style) { 
			obj=obj.style; 
				if(v == 'show') {
				//v = 'visible';
					v = 'block';
					hideSelect();
				} else if(v == 'hide') {
					//v = 'hidden';
					v = 'none';
					unhideSelect();
					}
			//v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
				}
			//obj.visibility=v;
			obj.display=v;
		}
	}
}
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;

}

 

 

 

//used for the index and mini seach forms to 'hide' the specific drop boxes when the info div is open

function hideSelect(){

for (j=0; j<document.forms.length; j++) {

var theForm = document.forms[j];

if (theForm.id=='placeFinder') {

theForm.nchild.style.visibility = 'hidden';

theForm.xbed.style.visibility = 'hidden';

}

//if (theForm.id=='miniPlaceFinder') {

//theForm.srp.style.visibility = 'hidden';

//theForm.nroom.style.visibility = 'hidden';

//theForm.nadult.style.visibility = 'hidden';

//theForm.nchild.style.visibility = 'hidden';

//theForm.xbed.style.visibility = 'hidden';

//} 

if (theForm.id=='sortSelect') {

theForm.sort.style.visibility = 'hidden';

}

if (theForm.id=='availability') {

theForm.nroom.style.visibility = 'hidden';

theForm.nights.style.visibility = 'hidden';

}

}

} 

//used for the index and mini seach forms to 'unhide' the drop boxes when the info div is closed

function unhideSelect(){

for (j=0; j<document.forms.length; j++) {

var theForm = document.forms[j]

for(i=0; i<theForm.elements.length; i++){

theForm.elements[i].style.visibility = 'visible';

}

}
}
//-->
function checkGoogle(searchMsg) {
      var google = document.getElementById('google');
      if( google.q.value == searchMsg ) {
            return false;
      }
      return true;
}
