// Used for pricing pages
var locationname, tempname, accomname, accom_id, tour_id, cruise_id = 1684, railway_id = 1682, count, icon, rname, adult;
var accomstatus, accomcount, tourstatus, tourcount, cruisestatus = false, cruisecount = 12, railwaystatus = false, railwaycount = 16, henryjonesstatus, henryjonescount = 0;
var output, output_days, output_dates, oDate, process = false;
var fromYear, fromMonth, fromDay, fromDate;

var hjOpen = false;
var wpOpen = false;
var expOpen = false;

function displayPricingTables(locname) {
	var i, d; var rateform = document.ratefrm;
	// EP (2007-11-02): Fixed array construction for WeekDays.
	//var weekday = new Array(6);
	var weekday = new Array(7);
	weekday[0] = "SUN"; weekday[1] = "MON"; weekday[2] = "TUE"; weekday[3] = "WED"; weekday[4] = "THU"; weekday[5] = "FRI"; weekday[6] = "SAT";
	
	if (locname.length == 0)
		var locationarr = new Array("Strahan", "Cradle", "Freycinet", "Hobart", "Launceston");
		//var locationarr = new Array("Strahan", "Cradle", "Freycinet", "Hobart", "Hobart_2", "Launceston");
	else
		var locationarr = new Array(locname);
	
	output = ""; output_days = ""; output_dates = "";
	
	fromYear = parseInt(rateform.fromYear.value);
	fromMonth = parseInt(rateform.fromMonth.value);
	fromDay = parseInt(rateform.fromDay.value);
	fromDate = fromDay +"/"+ fromMonth +"/"+ fromYear;
	toYear = fromYear;
	toMonth = fromMonth;
	toDay = fromDay;
	
	var currentstatus = true;
	// EP (2007-11-02): Reinforcing if statement conditions for year bit, just in case!
	if (fromDay < currentDay && fromMonth == currentMonth && fromYear <= currentYear) currentstatus = false;
	if (fromDay >= currentDay && fromMonth < currentMonth && fromYear <= currentYear) currentstatus = false;
	if (fromDay < currentDay && fromMonth < currentMonth && fromYear <= currentYear) currentstatus = false;
	//if (fromDay < currentDay && fromMonth == currentMonth && fromYear == currentYear) currentstatus = false;
	//if (fromDay >= currentDay && fromMonth < currentMonth && fromYear == currentYear) currentstatus = false;
	//if (fromDay < currentDay && fromMonth < currentMonth && fromYear == currentYear) currentstatus = false;
	
	if (!currentstatus) {
		alert("The dates selected cannot be less than the present date.\nThe select boxes will be reset.\n\nPlease select a different date range.");
		changeDay("from", currentDay, currentMonth, currentYear);
		rateform.fromDay.selectedIndex = currentDay - 1;
		rateform.fromMonth.selectedIndex = currentMonth - 1;
		return void(0);
	}
	
	if (currentDay == 0) {
		if ((currentMonth - 1) == 0) {
			currentMonth = 12;
			currentYear -= 1;
		}
		// calculate the number of days in the month and year.
		currentDay = calcDays(1, currentMonth, currentYear, "");
	}
	
	calcDateSpan(); // function found in js/planner.js
	
	// get date and day name span
	for (d = 0; d <= 9; d++) {
		datespan = datearr[d];
		// EP (2007-11-02): Fixed length of year to 4 for Date() object to pickup the date correctly
		//dyear = datespan.substring(2, 4);
		dyear = datespan.substring(0, 4);
		dmonth = datespan.substring(5, datespan.indexOf("-", 5));
		dday = datespan.substring(6 + dmonth.length, datespan.length);
		ddate = dday +"/"+ dmonth +"/"+ dyear;
		
		oDate = new Date(dmonth +"/"+ dday +"/"+ dyear);
		// EP (2007-11-02): We need to have two digit year now.
		dyear = dyear.substring(2);

		output_dates += "<td class=\"type\">"+ dday +"."+ dmonth +"."+ dyear +"</td>";

		if (d == 9)
			// EP (2007-11-02): No if statement needed
			output_days += "<th class=\"border\">"+ weekday[oDate.getDay()] +"</th>";
			//if (oDate.getDay() == 0)
			//	output_days += "<th class=\"border\">"+ weekday[6] +"</th>";
			//else
			//	output_days += "<th class=\"border\">"+ weekday[oDate.getDay() - 1] +"</th>";
		else
			// EP (2007-11-02): No if statement needed
			output_days += "<th>"+ weekday[oDate.getDay()] +"</th>";
			//if (oDate.getDay() == 0)
			//	output_days += "<th>"+ weekday[6] +"</th>";
			//else
			//	output_days += "<th>"+ weekday[oDate.getDay() - 1] +"</th>";
	}
	
	// EP (2007-11-02): Code looks confusing.
	//for (i = 0; i <= (locationarr.length - 1); i++) {
	for (i = 0; i < locationarr.length; i++) {
		locationname = locationarr[i];
		locname2 = locationname.substring(0, (locationname.indexOf("_") == -1 ? locationname.length : locationname.indexOf("_")));
		output += "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\""+ locationname.toLowerCase() + "-rates\" id=\""+ locationname.toLowerCase() +"\">";
		output += "<tr><th class=\"indent-title\">";
		
		if (locname2 == "Cradle")
			tempname = "Cradle Mountain";
		else if (locname2 == "Hobart_2")
			tempname = "The Henry Jones Art Hotel"
		else
			tempname = locname2;
		
		output += tempname + "</th>" + output_days;
		
		if (locationname == "Hobart") {
			output += "<tr><td class=\"indent\" onClick=\"displayRates('hobart', 5);\"><img src=\"Images/icons/booknow_plus.gif\" name=\"accomhobart_2\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">The Henry Jones Art Hotel</td>";
			output += output_dates;
		}
		
		if (locationname == "Hobart")
			accomname = "Wrest Point";
			
		else if (locationname == "Launceston")
			accomname = "Country Club Resort & Villas";
/*		else if (locationname == "Hobart_2")	{
			output += "<tr><td class=\"indent\" onClick=\"displayRates('"+ locationname.toLowerCase() +"', 1);\"><img src=\"Images/icons/booknow_plus.gif\" name=\"accom"+ locationname.toLowerCase() +"\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">Henry Jones</td>";
			output += output_dates;
			output += "</table>";
			continue;
		}*/
		else
			accomname = "Accommodation";
		
		output += "<tr><td class=\"indent\" onClick=\"displayRates('"+ locationname.toLowerCase() +"', 1);\"><img src=\"Images/icons/booknow_plus.gif\" name=\"accom"+ locationname.toLowerCase() +"\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">"+ accomname +"</td>";
		output += output_dates;
		if (locationname != "Launceston" && locationname != "Saffire") {
			output += "<tr><td class=\"indent\" onClick=\"displayRates('"+ locationname.toLowerCase() +"', 2);\"><img src=\"Images/icons/booknow_plus.gif\" name=\"tour"+ locationname.toLowerCase() +"\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">Experiences</td>";
			output += output_dates;
		}
		output += "</table>";
	}
	
	document.getElementById("displayrates").innerHTML = output;
	document.getElementById("display").style.display = "block";
}

function displayRates(lname, rt) {
	var aTemp, i;
	
	tourcount = 0;
	locationname = lname;
	rtype = rt;
	
	if (process) return void(0);
	
	switch (locationname) {
		case "strahan" : accom_id = 1678; tour_id = 1683; break;
		case "cradle" : accom_id = 1677; tour_id = 1680; break;
		case "freycinet" : accom_id = 1676; tour_id = 1681; break;
		case "saffire" : accom_id = 1885; break;
		case "hobart" : accom_id = 1679; tour_id = 1823; break;
		case "hobart_2" : accom_id = 1819; break;
		case "launceston" : accom_id = 1675;
	}
	

	if (rtype == 5 && locationname == "hobart") {
		accom_id = 1819;
		tour_id = 0;
	}
	
	if (rtype != 5) {
		accomcount = eval("id" + accom_id).split(",").length;
	}
	if (document.images["accom" + locationname])	{
		if (document.images["accom" + locationname].src.indexOf("minus") > -1)
			accomstatus = false;
		else
			accomstatus = true;
	}
	else
		accomstatus = false;
	
	

	/*	EP (2008-03-28) : Hard code for Henry Jones Hotel	*/
	if (rtype == 5 && document.images["accomhobart_2"])	{
		if (document.images["accomhobart_2"].src.indexOf("minus") > -1)
			henryjonesstatus = false;
		else
			henryjonesstatus = true;
	}
	else
		henryjonesstatus = false;
	
		
	if (locationname == "hobart" || locationname == "hobart_2")	{
		aTemp = eval("page"+ accom_id).split(",");
		accomcount = 0;
		//if (rtype != 2) henryjonescount = 0;
		if (rtype == 5) henryjonescount = 0;
		for (i = 0; i < aTemp.length; i++)	{
			if (rtype == 1 || rtype == 2)	{
				if (aTemp[i] != 0)	{
					accomcount++;
				}
			}
			else if (rtype == 5)	{
				if (aTemp[i] != 0)	{
					henryjonescount++;
				}
			}
		}
		if (rtype == 2) {
			accomcount = accomcount - henryjonescount;
			if (accomcount < 0) accomcount = 0;
		}
	}
	
	/*	END of Hard code	*/
	
	
	if (locationname != 'launceston' && locationname != 'saffire') {
		var accomrow = $("img[name='accom" + locationname + "']").parent().parent();
		// Determine number of accoms
		var currentrow = accomrow.next();
		accomcount = 0;
		while (currentrow != tourrow) {
			if (currentrow.children(".indent").children("img").length > 0) {
				break;
			}
			else {
				accomcount++;
				currentrow = currentrow.next();
			}
		}
	}
				
	
	if (accom_id != 1675 && accom_id != 1819) {
		try {
			tourcount = eval("id" + tour_id).split(",").length;
			if (document.images["tour" + locationname].src.indexOf("minus") > -1) 
				tourstatus = false;
			else 
				tourstatus = true;
		} catch (e) {
			tourstatus = false;
		}
	}
	// EP (2008-10-01): Hard-coded for PBC removing two room types.
	//if (accom_id == 1679)	{
	//	tourcount -= 2;
	//}

	//alert("accom_id: "  + accom_id + ", tourcount: " + tourcount);

	if (rtype == 3)
		if (document.images["cruise"].src.indexOf("minus") > -1)
			cruisestatus = false;
		else
			cruisestatus = true;
	
	if (rtype == 4)
		if (document.images["railway"].src.indexOf("minus") > -1)
			railwaystatus = false;
		else
			railwaystatus = true;
	
	// swap plus and minus sign respectively
	switch (rtype) {
		case 1 : rname = "accom" + locationname; property_id = accom_id; adult = 2; break;
		case 2 : rname = "tour" + locationname; property_id = tour_id; adult = 1; break;
		case 3 : rname = "cruise"; property_id = cruise_id; adult = 1; break;
		case 4 : rname = "railway"; property_id = railway_id; adult = 1; break;
		case 5 : rname = "accomhobart_2"; property_id = accom_id; adult = 2; break;
	}
	
	if (document.images[rname].src.indexOf("minus") > -1)
		icon = "plus";
	else
		icon = "minus";
	
	document.images[rname].src = eval(icon + ".src");
	
	// edit table rows
	var tbl = document.getElementById(locationname);
	var rowcol = tbl.rows;
	
	
	// calculate number of rows to delete/add and where to start/end
	if (rowcol.length == 3 || rowcol.length == 4) {
		if (locationname == "hobart") {
			if (rtype == 1) 
				count = 3;
			else if (rtype == 2) 
				count = 4;
			else if (rtype == 5) 
				count = 2;
		}
		else {
			if (rtype == 1) 
				count = 2;
			else if (rtype == 2) 
				count = 3;
			else if (rtype == 5) 
				count = 4;
		}
			
	} else {
		if (rtype == 1) {
			if (!accomstatus) 
				if (locationname == "hobart") {
					wpOpen = false;
					if (hjOpen) 
						deleteRows(tbl, henryjonescount + 2, accomcount);
					else 
						deleteRows(tbl, 2, accomcount);
				}
				else 
					deleteRows(tbl, 1, accomcount);
			else {
				if (locationname == "hobart") {
					if (!hjOpen)
						count = 3;
					else	
						count = tourcount + 4;
				}
				else 
					count = 2;
			}
		} else {
			if (rtype == 3) {
				if (!cruisestatus)
					if (accomstatus)
						deleteRows(tbl, tourcount + 3, cruisecount);
					else
						deleteRows(tbl, accomcount + tourcount + 3, cruisecount);
				else
					if (accomstatus)
						count = tourcount + 4;
					else
						count = accomcount + tourcount + 4;
			} else if (rtype == 4) {
				if (!railwaystatus)
					if (accomstatus)
						if (cruisestatus)
							deleteRows(tbl, tourcount + cruisecount + 4, railwaycount);
						else
							deleteRows(tbl, tourcount + 4, railwaycount);
					else
						if (cruisestatus)
							deleteRows(tbl, accomcount + tourcount + cruisecount + 4, railwaycount);
						else
							deleteRows(tbl, accomcount + tourcount + 4, railwaycount);
				else
					if (accomstatus)
						if (cruisestatus)
							count = tourcount + cruisecount + 5;
						else
							count = tourcount + 5;
					else
						if (cruisestatus)
							count = accomcount + tourcount + cruisecount + 5;
						else
							count = accomcount + tourcount + 5;
			}
			//	EP (2008-03-28) : Hard coded for Henry Jones Hotel
			else if (rtype == 5) {
				//Determine how many tours are open

				var tourrow = $("img[name='tourhobart']").parent().parent();
				var henryjonesrow = $("img[name='accomhobart_2']").parent().parent();				
				
				// Determine number of tours
				var currentrow = tourrow.next();
				tourcount = 0;
				while (currentrow.length != 0) {
					if (currentrow.children(".indent").children("img").length > 0) {
						break;
					}
					else {
						tourcount++;
						//currentrow.css("border", "4px solid green");
						currentrow = currentrow.next();
					}
				}

				//henryjonesstatus = henryjonesrow.nextAll().length > 0;
				henryjonesstatus = hjOpen;
				if (henryjonesstatus)	{
					hjOpen = false;
					deleteRows(tbl, 1, henryjonescount);
					//henryjonesstatus = henryjonesrow.nextAll().length > 0;
					henryjonesstatus = hjOpen;
				} else {
					count = 2;
					henryjonesstatus = true;
				}
			}
			//	END of hard code
			else {
				if (!tourstatus) 
					if (locationname == "strahan") 
						if (accomstatus) {
							if (cruisestatus && railwaystatus) {
								deleteRows(tbl, 2, tourcount + cruisecount + railwaycount + 2);
								cruisestatus = false;
								railwaystatus = false;
							}
							else 
								if (cruisestatus && !railwaystatus) {
									deleteRows(tbl, 2, tourcount + cruisecount + 2);
									cruisestatus = false;
								}
								else 
									if (!cruisestatus && railwaystatus) {
										deleteRows(tbl, 2, tourcount + railwaycount + 2);
										railwaystatus = false;
									}
									else 
										deleteRows(tbl, 2, tourcount + 2);
						}
						else {
							if (cruisestatus && railwaystatus) {
								deleteRows(tbl, accomcount + 2, tourcount + cruisecount + railwaycount + 2);
								cruisestatus = false;
								railwaystatus = false;
							}
							else 
								if (cruisestatus && !railwaystatus) {
									deleteRows(tbl, accomcount + 2, tourcount + cruisecount + 2);
									cruisestatus = false;
								}
								else 
									if (!cruisestatus && railwaystatus) {
										deleteRows(tbl, accomcount + 2, tourcount + railwaycount + 2);
										railwaystatus = false;
									}
									else 
										deleteRows(tbl, accomcount + 2, tourcount + 2);
						}
					else {
						// EP (2008-09-22): Hard coded for Hobart Experiences
						
						if (locationname == "hobart") {
							expOpen = false;
							tourcount += 2;
						}
						if (accomstatus) 
							if (locationname == "hobart") {
								if (!wpOpen && !hjOpen) 
									deleteRows(tbl, 3, tourcount);
								else 
									if (wpOpen && !hjOpen) 
										deleteRows(tbl, accomcount + 4, tourcount);
									else 
										if (!wpOpen && hjOpen) 
											deleteRows(tbl, henryjonescount + 3, tourcount);
							}
							else 
								deleteRows(tbl, 2, tourcount);
						else {
							if (locationname == "hobart") {
							
								if (wpOpen && hjOpen) 
									deleteRows(tbl, henryjonescount + accomcount + 3, tourcount);
								else if (!wpOpen && hjOpen) 
									deleteRows(tbl, henryjonescount + 2, tourcount);
								else if (wpOpen && !hjOpen)
									deleteRows(tbl, accomcount + 3, tourcount);
								else
									deleteRows(tbl, 2, tourcount);	
							}
							else
							{
								deleteRows(tbl, accomcount + 2, tourcount);	
							}							
						}
					}
				else {
					if (locationname == "hobart") {
						if (wpOpen && !hjOpen)
							count = accomcount + 4;
						else if (hjOpen && !wpOpen)
							count = henryjonescount + 4;
						else if (hjOpen && wpOpen)
							count = henryjonescount + accomcount + 4;
						else
							count = 4;
					}
					else 
						count = accomcount + 3;
				}
			}
		}
	}
	
	if ((rtype == 1 && accomstatus) 
	|| (rtype == 2 && tourstatus) 
	|| (rtype == 3 && cruisestatus) 
	|| (rtype == 4 && railwaystatus) 
	|| (rtype == 5 && henryjonesstatus)) {
	//if ((rtype == 1 && accomstatus) || (rtype == 2 && tourstatus) || (rtype == 3 && cruisestatus) || (rtype == 4 && railwaystatus)) {

		// display loading
		var row = tbl.insertRow(count);
		var cellcol = row.cells;
		var loading = rowcol[row.rowIndex].insertCell(cellcol.length);
		loading.colSpan = 11;
		loading.innerHTML = "LOADING...";
		
		if (rtype == 1 || rtype == 5)
		//if (rtype == 1)
			property_id = accom_id;
		else if (rtype == 2)
			property_id = tour_id;
		else if (rtype == 3)
			property_id = 1682;
		else
			property_id = 1684;
		
		process = true;
		loadXMLDoc("includes/searchrooms.asp?property_id="+ property_id +"&rtype="+ rtype +"&fromDate="+ datearr[0] +"&adult="+ adult +"&child=0&ran="+ getRan());
		//alert("includes/searchrooms.asp?property_id="+ property_id +"&rtype="+ rtype +"&fromDate="+ datearr[0] +"&adult="+ adult +"&child=0&ran="+ getRan());
	}
}

function processPricingRates() {
	var nodecount = 0; var roomarr, namearr, pagearr;
	var row, cellcol, celltitle, cell, rowlink, dstatus, firsttime = true;
	var tbl = document.getElementById(locationname);
	var rowcol = tbl.rows, ratecount = 0;
	var sClassName = "";

	//alert("rtype = "+ rtype +"\naccomstatus = "+ accomstatus +"\ntourstatus = "+ tourstatus +"\ncruisestatus = "+ cruisestatus +"\nrailwaystatus = "+ railwaystatus);
	
	// delete loading row
	if (rtype == 1) {
		if (locationname == "hobart") {
			wpOpen	 = true;
			
			if (count < 6) 
				tbl.deleteRow(3);
			else 
				tbl.deleteRow(tourcount + 4);
		}
		
		else 
			tbl.deleteRow(2);
	}
	else 
		if (rtype == 2) {
			if (locationname == "hobart") {
				expOpen = true;
				
				if (accomstatus) 
					if (count > 5) 
						tbl.deleteRow(tourcount + 5);
					else 
						tbl.deleteRow(4);
				else {
					if (hjOpen && wpOpen)
						tbl.deleteRow(accomcount + tourcount + 5);
					else
						tbl.deleteRow(accomcount + 4);
				}
			}
			else {
				if (accomstatus) 
					tbl.deleteRow(3);
				else 
					tbl.deleteRow(accomcount + 3);
			}
		}
		else 
			if (rtype == 3) 
				if (accomstatus) 
					tbl.deleteRow(tourcount + 4);
				else 
					tbl.deleteRow(accomcount + tourcount + 4);
			// EP (2008-03-28) : hard coded for Henry Jones Hotel
			else 
				if (rtype == 5) {
					sClassName = "-henryjones";
					//tbl.deleteRow(2);
					$("td:contains('LOADING...')").parent().remove();
					hjOpen = true;
				}
				else 
					if (accomstatus && cruisestatus) 
						tbl.deleteRow(tourcount + cruisecount + 5);
					else 
						if (accomstatus && !cruisestatus) 
							tbl.deleteRow(tourcount + 5);
						else 
							if (!accomstatus && cruisestatus) 
								tbl.deleteRow(accomcount + tourcount + cruisecount + 5);
							else 
								if (!accomstatus && !cruisestatus) 
									tbl.deleteRow(accomcount + tourcount + 5);
								else 
									tbl.deleteRow(accomcount + tourcount + 4);
	
	roomarr = eval("id"+ property_id).split(",");
	namearr = eval("name"+ property_id).split(",");
	pagearr = eval("page"+ property_id).split(",");
	
	var searchxml =  xml.responseXML.documentElement.childNodes;
	var slength = searchxml.length;
	var dlength = slength / roomarr.length;
	var z;
	
//alert("slength: " + slength + ", dlength: " + dlength);

	if (dlength == 12)
		dstatus = "normal";
	else if (dlength == 0)
		dstatus = "nada";
	else {
		var divide = (slength / 12) + "";
		if (divide.indexOf(".") > -1)
			dstatus = "abnormal";
		else
			dstatus = "normal-12";
	}
	
	var iRoomMarker = 0;
	
	for (var r = 0; r < roomarr.length; r++) {
		// EP (2007-11-02): Added code to find the current room
		nodecount = -1;	// initialize nodecount
//alert("count: " + count);

		/* EP (2008-09-22) : Hard coded groups and rooms for Hobart Experiences */
		if (property_id == 1823)	{
			if (roomarr[r] == 6979 || roomarr[r] == 6980 || roomarr[r] == 6981)	{	// Bruny Wildlife Adventure (BWA)
				if (parseInt(iRoomMarker & 1,10) == 0)	{
					row = tbl.insertRow(count);
					cellcol = row.cells;
					cell = row.insertCell(cellcol.length);
					cell.colSpan = 11;
					cell.className = "indent";
					cell.Align = "left";
					cell.innerHTML = "Bruny Wildlife Adventure";
					iRoomMarker |= 1;
					count++;
					tourcount++;
				}
			}
			else if (roomarr[r] == 6984 || roomarr[r] == 6985 || roomarr[r] == 6986)	{	// Peppermint Bay Cruise (PBC)
				if (parseInt(iRoomMarker & 2,10) == 0)	{
					row = tbl.insertRow(count);
					cellcol = row.cells;
					cell = row.insertCell(cellcol.length);
					cell.colSpan = 11;
					cell.className = "indent";
					cell.Align = "left";
					cell.innerHTML = "Pepperminit Bay Cruise";
					iRoomMarker |= 2;
					count++;
					tourcount++;
				}
			}
		}
		
		for (z = 0; z < slength; z++)	{
			if (parseInt(roomarr[r],10) == parseInt(searchxml[z].childNodes[0].firstChild.nodeValue,10))	{
				// matching room id is found. Go on with the rest of code.
				nodecount = z;
				break;
			}
		}
		
		/*	EP (2008-03-28) : Hard-coded for Henry Jones Hotel	*/
		if (locationname == "hobart" && (rtype == 1 || rtype == 2 || rtype == 5)) {
			if (pagearr[r] == 0) {
				continue;
			}
		}
		else if (locationname == "hobart_2" && rtype == 5	) {
			if (pagearr[r] != 0) {
				continue;
			}
		} 
		/*	END of hard-code */
		
		// setup table row and cells
		row = tbl.insertRow(count);
		cellcol = row.cells;
		celltitle = rowcol[row.rowIndex].insertCell(cellcol.length);
		
		// write table row events
		row.id = "default.asp?pID="+ pagearr[r] +"&i=0&fdate="+ fromDate;
		row.onmouseover = function() { this.className = "row-on"; };
		row.onmouseout = function() { this.className = ""; };
		row.onclick = function() {
			if (rtype == 5)	{	// Henry Jone Hotel
				window.open("http://www.thehenryjones.com/suites.html");
			}
			else {
		 		location.href = this.id;
		 	}
		};
		
		// setup price cells
		celltitle.className = "indent-room";
		celltitle.innerHTML = namearr[r];
		
		count += 1;
		
		for (var s = 0; s <= 9; s++) {
			// format date manually and write date row.. this is used in the loop
			datespan = datearr[s];
			dyear = datespan.substring(2, 4);
			dmonth = datespan.substring(5, datespan.indexOf("-", 5));
			dday = datespan.substring(6 + dmonth.length, datespan.length);
			ddate = dday +"."+ dmonth +"."+ dyear;
			
			// create cell
			cell = rowcol[row.rowIndex].insertCell(cellcol.length);
			
			if (slength > nodecount && nodecount != -1) {
				//alert(nodecount);
				var search_child = searchxml[nodecount].childNodes;
				roomnode_id = search_child[0].firstChild.nodeValue;
				
				// format date from xml
				datespan = search_child[2].firstChild.nodeValue;
				datespan = datespan.substring(0, datespan.indexOf("T"));
				nyear = datespan.substring(2, 4);
				nmonth = datespan.substring(5, 7);
				nday = datespan.substring(8, 10);
				
				// strip any zeros out of dates
				if (nmonth.substring(0, 1) == "0") nmonth = nmonth.substring(1);
				if (nday.substring(0, 1) == "0") nday = nday.substring(1);
				
				ndate = nday +"."+ nmonth +"."+ nyear;
				
				if (ddate == ndate) {
					ratecount += 1;
					// display price, full or no rate
					price = parseInt(search_child[4].firstChild.nodeValue);
					available = parseInt(search_child[3].firstChild.nodeValue);
					
					if (available) {
						cell.innerHTML = "$"+ price;
					} else {
						cell.className = "full" + sClassName;
						cell.innerHTML = "CALL";
						cell.onmouseout = function () { removeCallInfo() };
					}
				} else {
					cell.className = "full" + sClassName;
					cell.innerHTML = "CALL";
					cell.onmouseout = function () { removeCallInfo() };
				}
			} else {
				cell.className = "full" + sClassName;
				cell.innerHTML = "CALL";
				cell.onmouseout = function () { removeCallInfo() };
			}
			
			// xml holds 12 sets of dates for each room type (we only need 10)
			// sometimes there isnt 12 sets as there might not be available rates
			if (s == 9) {
				if (firsttime) {
					ratetotal = ratecount;
					firsttime = false;
				}
				if (dstatus == "normal") 
					nodecount += (slength / roomarr.length) - 9;
				else if (dstatus == "normal-12")
					nodecount += (slength / divide) - 9;
				else {
					divide = (slength / ratetotal) + "";
					nodecount += (slength / divide) - 9;
				}
			} else
				nodecount += 1;
		}
	}
	
	// Cruise and Railway exceptions
	if (locationname == "strahan" && rtype == 2) {
		// Gordon River Cruise
		row = tbl.insertRow(count);
		cellcol = row.cells;
		celltitle = rowcol[row.rowIndex].insertCell(cellcol.length);
		celltitle.className = "indent-special";
		celltitle.onclick = function() { displayRates("strahan", 3); };
		celltitle.innerHTML = "<img src=\"Images/icons/booknow_plus.gif\" name=\"cruise\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">Gordon River Cruises";
		
		// get date and day name span
		for (d = 0; d <= 9; d++) {
			cell = rowcol[row.rowIndex].insertCell(cellcol.length);
			datespan = datearr[d];
			dyear = datespan.substring(2, 4);
			dmonth = datespan.substring(5, datespan.indexOf("-", 5));
			dday = datespan.substring(6 + dmonth.length, datespan.length);
			cell.className = "special";
			cell.innerHTML = dday +"."+ dmonth +"."+ dyear;
		}
		
		count += 1;
		
		// West Coast Railway
		row = tbl.insertRow(count);
		cellcol = row.cells;
		celltitle = rowcol[row.rowIndex].insertCell(cellcol.length);
		celltitle.className = "indent-special";
		celltitle.onclick = function() { displayRates("strahan", 4); };
		celltitle.innerHTML = "<img src=\"Images/icons/booknow_plus.gif\" name=\"railway\" alt=\"\" width=\"9\" height=\"9\" border=\"0\" class=\"sign\">West Coast Railway";
		
		// get date and day name span
		for (d = 0; d <= 9; d++) {
			cell = rowcol[row.rowIndex].insertCell(cellcol.length);
			datespan = datearr[d]; 
			dyear = datespan.substring(2, 4);
			dmonth = datespan.substring(5, datespan.indexOf("-", 5));
			dday = datespan.substring(6 + dmonth.length, datespan.length);
			cell.className = "special";
			cell.innerHTML = dday +"."+ dmonth +"."+ dyear;
		}
	}
	
	process = false;
}

function deleteRows(dtbl, start, total) {
	//alert("deleteRows(start: " + start + ", total: " + total);
	d = total + start;
	while (d > start) {
		//alert("deleting(d: " + d);
		dtbl.deleteRow(d);
		d -= 1;
	}
}