var bSelected = 0;
var iStartSetID, iStopSetID;
var iStartSetNum, iStopSetNum;
var sColorStart = "#8fe288";
var sColorStop = "#d97b88";
var iMonth, iYear, actualdate;
var iSetYear, iSetMonth, iSetDay, iStopSetDay;

function setdateblock(month,day,year) {
	if (month < 10) { month = "0" + month; }
	actualdate = String(year) + String(day) + String(month);
}

function setstartingdate(month,year) {
	iMonth = month;
	iYear = year;
}

function changecolor(id,num,comparer,year,month,day) {
	var sLink = "day" + num;
	if (typeof iStartSetID == "undefined") {
			document.getElementById(id).style.background = sColorStart;
			document.getElementById(sLink).style.color = "#fff";
	} else {				
		if (iStartSetID != id) {
			if( (year > iSetYear) || (month > iSetMonth) || ( (year == iSetYear) && (month == iSetMonth) && (day > iSetDay) ) ) {
				document.getElementById(id).style.background = sColorStop;
				document.getElementById(sLink).style.color = "#fff";
			}			
		}
	}
}

function setdate(id,num,month,year) {
	if (month < 10) { month = "0" + month; }
	var sLink = "day" + num
	var date = month + "/" + num + "/" + year;
	if (typeof iStartSetID == "undefined" || typeof iStopSetID == "undefined") {
		if (bSelected == 0) {
			bSelected = 1;
			iStartSetID = "block" + year + num + month;
			iStartSetNum = String(year) + String(num) + String(month);
			iSetYear = year;
			iSetMonth = month;
			iSetDay = num;
			document.calendarForm.departdate.value = date;
		} else {				
			var comparer = String(year) + String(num) + String(month);
			if( (year > iSetYear) || (month > iSetMonth) || ( (year == iSetYear) && (month == iSetMonth) && (num > iSetDay) ) ) { 
				iStopSetID = "block" + year + num + month;
				iStopSetNum = String(year) + String(num) + String(month);
				iStopSetDay = num;
				document.calendarForm.returndate.value = date;
			}				
		}
	}
}

function resetcolor(id,num) {
	var sLink = "day" + num
	
	if (iStartSetID != id && iStopSetID != id) {
		document.getElementById(id).style.background = "#eaf2fd";
		document.getElementById(sLink).style.color = "#699de4";
	}
}

function resetcal() {	
	document.calendarForm.departdate.value = "Departure Date*";
	document.calendarForm.returndate.value = "Return Date*";		
	if (typeof iStartSetID != "undefined") {
		if (document.getElementById(iStartSetID)) { document.getElementById(iStartSetID).style.background = "#eaf2fd"; }
		if (document.getElementById("day" + iSetDay)) { document.getElementById("day" + iSetDay).style.color = "#699de4"; }
	}	
	if (typeof iStopSetID != "undefined") {
		if (document.getElementById(iStopSetID)) { document.getElementById(iStopSetID).style.background = "#eaf2fd"; }
		if (document.getElementById("day" + iStopSetDay)) { document.getElementById("day" + iStopSetDay).style.color = "#699de4"; }
	}		
	bSelected = 0;
	iStartSetID = undefined;
	iStopSetID = undefined;	
	iStartSetNum = undefined;
	iStopSetNum = undefined;
	iSetYear = undefined;
	iSetMonth = undefined; 
	iSetDay = undefined; 
	iStopSetDay = undefined;
}

function resetform() {	
	document.calendarForm.origin.value = "Origin";
	document.calendarForm.destination.value = "Destination";
	document.calendarForm.departdate.value = "Departure Date*";
	document.calendarForm.returndate.value = "Return Date*";
	document.calendarForm.numpass.value = "# of Passengers";
	document.calendarForm.name.value = "Name";
	document.calendarForm.phone.value = "Phone";
	document.calendarForm.email.value = "Email";
	document.calendarForm.comments.innerHTML = "Special Requests";
	resetcal();
}

function changeimage(imgname, imgsrc) {
	document[imgname].src = imgsrc;
}

function getXMLHttp() {
	var xmlHttp;
	
	try {
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch(e) {
		//Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				alert("Your browser will not support the full features of this site, please download Firefox or upgrade to the latest version of Internet Explorer")
				return false;
			}
		}
	}
	return xmlHttp;
}

function MakeRequest() {
	var xmlHttp = getXMLHttp();
	
	xmlHttp.onreadystatechange = function() {
		if(xmlHttp.readyState == 4) {
			HandleResponse(xmlHttp.responseText);
		}
	}
	xmlHttp.open("GET", "calupdate.php?m="+iMonth+"&y="+iYear+"&start="+iStartSetID+"&stop="+iStopSetID, true);
	xmlHttp.send(null);
}

function HandleResponse(response) {
	document.getElementById('ajaxdates').innerHTML = response;
}