var ss_script = "/modules/bookings/control.php"; // The server-side script

var months  = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var days    = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var seldate = null; // ISO format of selected date
var selday  = null; // the element(td) of the selected date

function processResponse(responseText){ // default function executed when response is received
	loading(false);	
	document.getElementById('calendar').innerHTML = responseText;
	setCalStyle();
}

function processAvailabilityCheck() {
  if (http.readyState == 4) {
    isWorking = false;				
    if(http.responseText != '' && http.responseText != null){
			alert(http.responseText);
			return false;
		}else{
			chooser.submit();
		}
  }
}

function checkAvailability(isoStart,isoEnd){
	var tmpDate = new Date();
	var url = ss_script + '?do=checkAvailability&start='+isoStart+'&end='+isoEnd+'&time='+tmpDate.getTime();

	if(!isWorking && http){
		isWorking = true;
		http.open('GET', url, true);
		http.onreadystatechange = processAvailabilityCheck;
		http.send(null);
	}else if(!http){
		alert('Your browser is not Ajax compatible');
	}
}

function getNewCalendar(url){
	if(!isWorking && http){
		sendHttpRequest('GET',url);
	}else if(!http){
		alert('Your browser is not Ajax compatible');
	}
}

function getCalendar(month,year){
	saveMonth(month,year);
	var type = chooser.breakType.value;
	var tmpDate = new Date();
	var url = ss_script + '?do=getMonth&t='+type+'&m='+month+'&y='+year+'&time='+tmpDate.getTime();
	if(!isWorking && http){
		loading(true);
		sendHttpRequest('GET',url);
	}else if(!http){
		alert('Your browser is not Ajax compatible');
	}
}

function nextMonth(month,year){
	getCalendar(month+1,year);
}

function prevMonth(month,year){
	getCalendar(month-1,year);
}

function saveMonth(month,year){
	chooser.my.value = month+'|'+year;
}

function loading(yn){

}

var http = getHTTPObject();

function $(el_id){
	return document.getElementById(el_id);
}
