//Create a new object of a date then get the current date and year
var ds_i_date = new Date();
ds_c_month = ds_i_date.getMonth() + 1;
ds_c_year = ds_i_date.getFullYear();

var xmlhttp = GetXmlHttpObject();

function forward_month(x) {
	ds_c_month ++;
	if (ds_c_month > 12){
		ds_c_year ++;
		ds_c_month = 1;		
	}
	if(!x){
		make_cal();
	}else {
		make_search_cal()
	}
}

function forward_year(x){
	ds_c_year ++;
	if(!x){
		make_cal();
	}else {
		make_search_cal()
	}
}

function back_month(x) {
	ds_c_month = ds_c_month - 1;
	if (ds_c_month < 1){
		ds_c_year =ds_c_year - 1;
		ds_c_month = 12;		
	}	
	if(!x){
		make_cal();
	}else {
		make_search_cal()
	}
}

function back_year(x){
	ds_c_year = ds_c_year - 1;	
	if(!x){
		make_cal();
	}else {
		make_search_cal()
	}
}
function make_cal() {
	if (xmlhttp == null) {
		  alert ("Your browser does not support XMLHTTP!");
		  return;
  	}		
	var url="http://www.ednwelfare.com.au/getdates.php";
	url=url+"?m="+ds_c_month;
	url=url+"&y="+ds_c_year;
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(null);
	xmlhttp.onreadystatechange = function statechanged() {
  	if ( xmlhttp.readyState == 4 || xmlhttp.readyState == "complete" ) {	
		if(xmlhttp.status == 200) {				
			document.getElementById("calendar").innerHTML = xmlhttp.responseText;					
		}
    }
	
  }	
}
function make_search_cal() {
	if (xmlhttp == null) {
		  alert ("Your browser does not support XMLHTTP!");
		  return;
  	}		
	var url="http://www.ednwelfare.com.au/getspecialcal.php";
	url=url+"?m="+ds_c_month;
	url=url+"&y="+ds_c_year;
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(null);
	xmlhttp.onreadystatechange = function statechanged() {
  	if ( xmlhttp.readyState == 4 || xmlhttp.readyState == "complete" ) {	
		if(xmlhttp.status == 200) {				
			document.getElementById("calendar").innerHTML = xmlhttp.responseText;					
		}
    }
	
  }	
}

function search_day(day) {
	get_search(day,ds_c_month,ds_c_year,day,ds_c_month,ds_c_year);
}
function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
  	}
	if (window.ActiveXObject){
  		// code for IE6, IE5
  		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return null;
}

function get_search(sday,smonth,syear,eday,emonth,eyear) {
	if (xmlhttp == null) {
		  alert ("Your browser does not support XMLHTTP!");
		  return;
  	}
	var fname = document.getElementById('fname').value;
	var lname = document.getElementById('lname').value;
	if(!sday)var sday = document.getElementById('sday').value;
	if(!smonth)var smonth = document.getElementById('smonth').value;
	if(!syear)var syear = document.getElementById('syear').value;
	if(!eday)var eday = document.getElementById('eday').value;
	if(!emonth)var emonth = document.getElementById('emonth').value;
	if(!eyear)var eyear = document.getElementById('eyear').value;
	var ref = document.getElementById('ref').value;	
	var url="http://www.ednwelfare.com.au/ShacksBookings/getsearch.php";
	url=url+"?fname="+fname;
	url=url+"&lname="+lname;
	url=url+"&sday="+sday;
	url=url+"&smonth="+smonth;
	url=url+"&eyear="+eyear;
	url=url+"&eday="+eday;
	url=url+"&emonth="+emonth;
	url=url+"&syear="+syear;
	url=url+"&ref="+ref;
	url=url+"&sid="+Math.random();
	xmlhttp.open("GET",url,true);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.send(null);
	xmlhttp.onreadystatechange = function statechanged() {
  	if ( xmlhttp.readyState == 4 || xmlhttp.readyState == "complete" ) {	
		if(xmlhttp.status == 200) {				
			document.getElementById("search_results").innerHTML = xmlhttp.responseText;					
		}
    	} 
	}
}
