posLeft = -1;
posTop = -1;
availability_visibility = "hidden";
availability_visible = false;

tmp_class1 = "AVAILABILITY_CLOSE_LINK";
tmp_class2 = "CALENDAR_DIAS_LINK_TD";
tmp_class3 = "AVAILABILITY_CLOSE_BOLD";
tmp_class4 = "AVAILABILITY_DIVIDER_BOTTOM";
tmp_class5 = "AVAILABILITY_BODY";

tmp_link = "javascript: availability_compress();cal1.compress();";

var IFrameObj; // our IFrame object

function serverGetAvailability(dayChosen,monthChosen,yearChosen) {
	if (!document.createElement) {return true};
	
	var IFrameDoc;
	var URL = "http://www.harborcreektownship.org/cgi-bin/parkCalendarSystem/Park_Res_Chk_Cal/getavailability.pl?" + dayChosen + "+" + monthChosen + "+" + yearChosen;

	if (!IFrameObj && document.createElement) {
		// create the IFrame and assign a reference to the
		// object to our global variable IFrameObj.
		// this will only happen the first time 
		// callToServer() is called
		try {
			var tempIFrame=document.createElement('iframe');
			tempIFrame.setAttribute('id','COMM');
			tempIFrame.style.border='0px';
			tempIFrame.style.width='0px';
			tempIFrame.style.height='0px';
			IFrameObj = document.body.appendChild(tempIFrame);

			if (document.frames) {
				// this is for IE5 Mac, because it will only
				// allow access to the document object
				// of the IFrame if we access it through
				// the document.frames array
				IFrameObj = document.frames['COMM'];
			}
		} 
		catch(exception) {
			// This is for IE5 PC, which does not allow dynamic creation
			// and manipulation of an iframe object. Instead, we'll fake
			// it up by creating our own objects.
			iframeHTML='\<iframe id="COMM" style="';
				iframeHTML+='border:0px;';
				iframeHTML+='width:0px;';
				iframeHTML+='height:0px;';
			iframeHTML+='"><\/iframe>';
			document.body.innerHTML+=iframeHTML;
			IFrameObj = new Object();
			IFrameObj.document = new Object();
			IFrameObj.document.location = new Object();
			IFrameObj.document.location.iframe = document.getElementById('COMM');
			IFrameObj.document.location.replace = function(location) {
				this.iframe.src = location;
			}
		}
	}

	if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
		// we have to give NS6 a fraction of a second
		// to recognize the new IFrame
		setTimeout('serverGetAvailability()',10);
		return false;
	}

	if (IFrameObj.contentDocument) {
		// For NS6
		IFrameDoc = IFrameObj.contentDocument; 
	} else if (IFrameObj.contentWindow) {
		// For IE5.5 and IE6
		IFrameDoc = IFrameObj.contentWindow.document;
	} else if (IFrameObj.document) {
		// For IE5
		IFrameDoc = IFrameObj.document;
	} else {
		return true;
	}

	IFrameDoc.location.replace(URL);
		
	
	var answ = document.getElementById("ANSW");
	if (!answ) {
		return false;
	}
	var ret = "";

	ret += "<table border='0' height='260' width='500' cellpadding='0' cellspacing='0'>";
		ret += "<tr>";
			ret += "<td class=" + tmp_class1 + " align='left' valign='top'>";
				ret += "SEARCHING...";
			ret += "</td>";
		ret += "</tr>";
	ret += "</table>";

	answ.innerHTML = ret;	
	return false;
}

function handleServerResponse(pavillionCode, availabilityCode, dayChosen, monthChosen, yearChosen) {
  var answ = document.getElementById("ANSW");

  if (answ) {
	var ret = "";
	ret += "<table border='0' width='500' cellpadding='0' cellspacing='0'>";
		ret += "<tr>";
			ret += "<td class='" + tmp_class3 + "' align='left' valign='top'>Availability for " + gl_calendar_meses[cal1.month - 1] + " " + dayChosen + ", " + yearChosen + "</td>";
			ret += "<td class='" + tmp_class1 + "' align='right' valign='top'><a href=\"" + tmp_link + "\" class=" + tmp_class1 + ">" + "CLOSE WINDOW" + "<a href=\"" + tmp_link + "\" class=" + tmp_class3 + ">" + "&nbsp;X" + "</a></td>";
		ret += "</tr>";
		ret += "<tr>";
			ret += "<td height=1 colspan=2 class='" + tmp_class4 + "' valign='top'>&nbsp;</td>";
		ret += "</tr>";
	ret += "</table>";
	ret += "<table border='0' width='500' cellpadding='0' cellspacing='0'>";
		start = 1;
		end = 2;

		var code = String(availabilityCode);
		var pavillionNumbr = String(pavillionCode);
		
		ret += "<tr>";
			ret += "<td style=\"border-right: 1px solid #666666\"colspan=2>";
				ret += "<table border='0' width='190' cellpadding='0' cellspacing='0'>";
					for(x=1;x < 7;x++) {
						if (x == 1) {
							ret += "<tr>";
								ret += "<td colspan=2>";
									ret += "<b>Whitford Park</b>";
								ret += "</td>";

							ret += "</tr>";
						}
						if (x < 4) {
							ret += "<tr>";
								ret += "<td width=15>&nbsp;</td>";
								ret += "<td class=" + tmp_class5 + " width=200>";
									if (code.substring(start,end) == 1) {ret += "<font color='#cccccc'>PAVILLION (" + pavillionNumbr.substring(start,end) + ") IS RENTED</font><br>";}
									else {ret += "PAVILLION (" + pavillionNumbr.substring(start,end) + ") IS AVAILABLE<br>";}
								ret += "</td>";
							ret += "</tr>";
						}
						if(x == 4) {
							ret += "<tr>";
								ret += "<td colspan=2>";
									ret += "<hr align=left width=190><b>Shades Beach</b><br>";
								ret += "</td>";
							ret += "</tr>";
						}
						if(x > 3 && x < 6) {
							if(pavillionNumbr.substring(start,end) == 1) {var size = "SMALL";}
							else {var size = "LARGE"}
							// Shades beach is closed for the season due to construction
							/*ret += "<tr>";
								ret += "<td width=25>&nbsp;</td>";
								ret += "<td class=" + tmp_class5 + " width=200>";
									//if (code.substring(start,end) == 1) {ret += "<font color='#cccccc'>" + size + " PAVILLION IS RENTED</font><br>"}
									if(x == 4) {
									ret += "CLOSED FOR 2007 SEASON<br>";
									}else{ret += "&nbsp;";}
								ret += "</td>";
							ret += "</tr>";*/
							
							ret += "<tr>";
								ret += "<td width=15>&nbsp;</td>";
								ret += "<td class=" + tmp_class5 + " width=200>";
									if (code.substring(start,end) == 1) {ret += "<font color='#cccccc'>" + size + " PAVILLION IS RENTED</font><br>"}
									else {ret += size + " PAVILLION IS AVAILABLE</font><br>"}
								ret += "</td>";
							ret += "</tr>";
						}	
						if(x == 6) {
							ret += "<tr>";
								ret += "<td colspan=2>";
									ret += "<hr align=left width=190><b>Rolling Ridge</b><br>";
								ret += "</td>";
							ret += "</tr>";
							ret += "<tr>";
								ret += "<td width=15>&nbsp;</td>";
								ret += "<td class=" + tmp_class5 + " width=200>";
									if (code.substring(start,end) == 1) {ret += "<font color='#cccccc'>PAVILLION " + pavillionNumbr.substring(start,end) + " IS RENTED</font><br>";}
									else {ret += "PAVILLION IS AVAILABLE<br>";}
								ret += "</td>";
							ret += "</tr>";
						}
						start += 1;
						end += 1;	
					}	
				ret += "</table>";
			ret += "</td>";			
			ret += "<td width=22>";			
				ret += "&nbsp;";
			ret += "</td>";
			ret += "<td valign=top>";
				ret += "<TABLE WIDTH=\"250\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">";
					ret += "<TR><TD height=\"10\" width=\"10\" valign=\"bottom\"><IMG SRC=\"../format_images/tl_gray.gif\" WIDTH=\"10\" HEIGHT=\"10\"></TD><TD bgcolor=\"#EFEDDE\" style=\"border-top-style: solid; border-top-width: 1; border-top-color: #666666\" height=\"10\" width=\"100%\" valign=\"bottom\" align=\"right\"><img src=\"../format_images/spacer.gif\" height=\"8\"></TD><TD height=\"10\" width=\"10\" valign=\"bottom\" align=\"right\"><IMG SRC=\"../format_images/tr_gray.gif\" WIDTH=\"10\" HEIGHT=\"10\"></TD></TR>";
				ret += "</table>";					
				ret += "<table style=\"border-left-style: solid; border-left-width: 1; border-left-color: #666666; border-right-style: solid; border-right-width: 1; border-right-color: #666666\" bgcolor=\"#EFEDDE\" border='0' width='250' cellpadding='0' cellspacing='0'>";
					ret += "<tr>";
						ret += "<td>";
							ret += "<P style=\"text-align: center; text-decoration: underline; margin-left: 6px; margin-right: 0px; margin-bottom: 4px; margin-top: 0px; line-height: 10pt; font-weight: bold; font-size: 8pt; color: red; font-family: Arial, Goudy Old Style, Verdana;\">Availability Note: <P style=\"text-align: center; margin-left: 6px; margin-right: 0px; margin-bottom: 0px; margin-top: 0px; line-height: 10pt; font-size: 8pt; color: #000000; font-family: Arial, Goudy Old Style, Verdana;\"><u>Not</u> guaranteed until <u>confirmed</u> with Connie Cruz</p>";
						ret += "</td>";					
					ret += "</tr>";
				ret += "</table>";
				ret += "<TABLE WIDTH=\"250\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">";
						ret += "<TR><TD height=\"10\" width=\"10\" valign=\"bottom\"><IMG SRC=\"../format_images/bl_gray.gif\" WIDTH=\"10\" HEIGHT=\"10\"></TD><TD bgcolor=\"#EFEDDE\" style=\"border-bottom-style: solid; border-bottom-width: 1; border-bottom-color: #666666\" height=\"10\" width=\"100%\" valign=\"bottom\" align=\"right\"><img src=\"../format_images/spacer.gif\" height=\"8\"></TD><TD height=\"10\" width=\"10\" valign=\"bottom\" align=\"right\"><IMG SRC=\"../format_images/br_gray.gif\" WIDTH=\"10\" HEIGHT=\"10\"></TD></TR>";
				ret += "</TABLE>";			
			ret += "</td>";					
		ret += "</tr>";
	ret += "</table>";
	answ.innerHTML = ret;
	expand_availability();
  }
  
}

function availability_compress() {
	document.getElementById("ANSW").style.visibility = "hidden";
	availability_visible = false;
	showWindowedObjects(true);
}

function expand_availability() {
	var obj_availability = document.getElementById("ANSW");
	if (obj_availability.style.visibility != "visible") {
		if (posLeft == -1 && posTop == -1) { getMyXY(); }
		var clX = posLeft;
		var clY = posTop;
		if (isIE || isKo) {
			obj_availability.style.posLeft = clX - 206;
			obj_availability.style.posTop = clY - 2;
		} else {
			obj_availability.style.left = clX - 206;
			obj_availability.style.top = clY - 2;
		}
		showWindowedObjects(false);
		obj_availability.style.visibility = "visible";
		availability_visible = true;
	}
	availability_visibility = obj_availability.style.visibility;
}

function getMyXY() {
	var obj = document.getElementById(cal1.txtbox_name);
	for(var sumTop = 0, sumLeft = 0; obj != document.body; sumTop += obj.offsetTop,sumLeft += obj.offsetLeft, obj = obj.offsetParent) {

	}
	posLeft = sumLeft;
	posTop = sumTop;
}
