bookingNameStatus = document.getElementById('booking-name-status');
bookingEmailStatus = document.getElementById('booking-email-status');
bookingDateStatus = document.getElementById('booking-date-status');
bookingValidDateStatus = document.getElementById('booking-validdate-status');
getCalendars = document.getElementsByClassName('cs_availabilitycalendar');

if ( getCalendars.length > 0 ) {
for (g = 0; g < getCalendars.length; g ++) {
  getCalTable = getCalendars[g];
  activeCal = 0;
  prevMonthButtonID = getCalendars[g].id.replace('calendar', 'prev_month');

  if (activeCal == 0 && document.getElementById(prevMonthButtonID)) {
    document.getElementById(prevMonthButtonID).onclick = function () {
      getCalendars[activeCal].parentNode.style.display = 'none';
      getCalendars[(activeCal-1)].parentNode.style.display = 'block';
      activeCal = activeCal-1;
      return false;
    }
  }
  
  nextMonthButtonID = getCalendars[g].id.replace('calendar', 'next_month');
  
  if (document.getElementById(nextMonthButtonID)) {
		document.getElementById(nextMonthButtonID).onclick = function () {
      getCalendars[activeCal].parentNode.style.display = 'none';
      getCalendars[activeCal+1].parentNode.style.display = 'block';
      activeCal = activeCal+1;
      return false;
    }
  }

/*
	getCloseButton = document.getElementById('popup-close');
	getCloseButton.onclick = function() {
		nbm_calendar_popup(0,0); 
		return false;
	}
*/

	for (i = 0; i < getCalTable.childNodes.length; i ++ ) {
		if ( getCalTable.childNodes[i].tagName == 'TBODY' ) {
			for (j = 0; j < getCalTable.childNodes[i].childNodes.length; j ++ ) {
				if (getCalTable.childNodes[i].childNodes[j].tagName == 'TR' ) { 
					thisTR = getCalTable.childNodes[i].childNodes[j];
					for (k = 0; k < thisTR.childNodes.length; k++ ) {
						if (thisTR.childNodes[k].tagName == 'TD') {
							thisTD = thisTR.childNodes[k];             
							thisTDcontent = thisTD.innerHTML; //.replace(/^\s+|\s+$/g, '');
													
							if (thisTDcontent != '&nbsp;' && thisTDcontent != 0 && thisTDcontent != ' ' && !isNaN(parseInt(thisTDcontent))) {
								thisTD.id = getCalendars[g].id.replace('calendar', 'day')+'_'+thisTDcontent;
								thisTD.innerHTML = ''; 
								newA = document.createElement('A');
								newA.href = '#';
								newA.title = 'title';
								newA.innerHTML = thisTDcontent;
								thisTD.appendChild(newA);
								newA.onclick = function() {
									nbm_calendar_popup(this.parentNode.className.match('booked')?2:1,this.parentNode.id);
									return false;
								}
							}
						}
					}
				}
			}
			break; 
		}
	}
}
}

	  

function validateDateChanges(updobj) {
  fieldNameSp = updobj.id.split('-');
  fromInput = document.getElementById(fieldNameSp[0]+'-from');
  toInput = document.getElementById(fieldNameSp[0]+'-to');
  
  //alert(fieldNameSp[0]);
  
  
  var fromDate = new Date();
  fromValueSp = fromInput.value.split('/');
  fromDate.setFullYear(fromValueSp[2], (fromValueSp[1]-1), fromValueSp[0]);
  
  var toDate = new Date();
  toValueSp = toInput.value.split('/');
  toDate.setFullYear(toValueSp[2], (toValueSp[1]-1), toValueSp[0]);

  if ( isDate(fromInput.value) && isDate(toInput.value) ) {
		switch(fieldNameSp[0]) {
			case 'popup':
			
				
				if (fromDate > toDate) {  
				
					//alert('FROM DATE IS LATER THAN TO DATE?');
				
					dateString = 'day_'+document.getElementById('booking-property').value+'_'+(fromDate.getMonth()+1)+'-'+fromDate.getFullYear()+'_'+fromDate.getDate();
					nbm_calendar_popup(1,dateString);
					bookingDateStatus.style.display = 'block';
					bookingDateStatus.innerHTML = 'End date you have selected was earlier than start date so it has been adjusted.';
				}
				else {
				
					//alert("FROM DATE: "+date_to_datestring(fromDate)+"\r\nTO DATE: "+date_to_datestring(toDate));
					nbm_calendar_popup(1,date_to_datestring(fromDate),date_to_datestring(toDate));
					
				}
				
				
				break;
				
			case 'apsearch_dates':
				if (fromDate > toDate) { 
					toDate.setDate(fromDate.getDate()+6);				
					toInput.value = addZeros(toDate.getDate(),2)+'/'+addZeros((toDate.getMonth()+1),2)+'/'+toDate.getFullYear();
				}
				break;
		}
  }
}





if (document.getElementById('booking-real-form') ) {
	realForm = document.getElementById('booking-real-form');
	realForm.onsubmit = nbm_checkform_booking_request;
	
	/* function () {
	alert('test');
	return false;
	//
	}*/
} 		
//document.getElementById('fc-over').innerHTML = fctablehtml;


