// startXML and processData functions do all the work here
var isPT;
//var HTTPS_PATH = "";

function startXML() {
  var rateform = document.ratefrm;
  var tdays = calcDays(fromDay, fromMonth, fromYear, "nosubtract");

  // check to see if we are doing a rates search from countryclubresort.com.au or wrestpoint.com.au
  isPT = (location.href.indexOf("countryclubbooking/rates.asp") != -1 || location.href.indexOf("wrestpointbooking/rates.asp") != -1) ? false : true;

  if (isPT)
    var contact = "1800 420 155";
  else
    var contact = (location.href.indexOf("countryclubbooking/rates.asp") != -1) ? "1800 635 344" : "1800 703 006";

  fromDay = parseInt(rateform.fromDay.value);
  fromMonth = parseInt(rateform.fromMonth.value);
  fromYear = parseInt(rateform.fromYear.value);
  fromDate = fromDay +"."+ fromMonth +"."+ rateform.fromYear.value.substring(2, 4);

  var currentstatus = true;
  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) {
    if (rtype == 1 || property_id == 1684 || property_id == 1682)
      alert("The dates selected cannot be less than the present date.\nThe select boxes will be reset.\n\nPlease select a different date range.");
    else
      alert("Your selection cannot be less than 10 days from the present date.\nThe date range will be changed to the next available date\n\nPlease revise the new date range.");

    rateform.fromDay.selectedIndex = currentDay - 1;
    rateform.fromMonth.selectedIndex = currentMonth - 1;
    changeDates();
    return void(0);
  }

  if (checkMaxPeople()) return void(0);

  if (rtype == 1) {
  	try {
		toDay = parseInt(rateform.toDay.value);
		
		toMonth = parseInt(rateform.toMonth.value);
		toYear = parseInt(rateform.toYear.value);
		toDate = toDay + "." + toMonth + "." + rateform.toYear.value.substring(2, 4);
		
		
		numAdult = parseInt(rateform.adult.selectedIndex) + 1;
		numChild = parseInt(rateform.child.selectedIndex);
	} 
	catch (e) {
		toDay = fromDay;
		toMonth = fromMonth;
		toYear = fromYear;
		toDate = fromDate;
	}
  } else {
    // single tour page
    toDay = fromDay;
    toMonth = fromMonth;
    toYear = fromYear;
    toDate = fromDate;

    numAdult = parseInt(rateform.adult.selectedIndex) + 1;
    if (rateform.child)
      numChild = parseInt(rateform.child.selectedIndex);
    else
      numChild = 0;
	  
	if (numChild < 0) 
		numChild = 0;
  }

  /*if (toYear > fromYear) {
    if ((12 - currentMonth) + fromMonth > 6) currentstatus = false;
  } else {
    if ((fromMonth - currentMonth) > 6) currentstatus = false;
  }*/

  if (!currentstatus) {
    alert("There are only 6 months of future rates available for viewing.\nThe select boxes will be reset.\n\nPlease select a date range within 6 months from the present date");
    rateform.fromDay.selectedIndex = currentDay - 1;
    rateform.fromMonth.selectedIndex = currentMonth - 1;
    if (tdays <= fromDay + 1) {
      rateform.toDay.selectedIndex = 0;
      if (fromMonth == 12) {
        rateform.toMonth.selectedIndex = 0;
        rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex + 1;
      } else
        rateform.toMonth.selectedIndex = rateform.fromMonth.selectedIndex;
    } else {
      rateform.toDay.selectedIndex = rateform.fromDay.selectedIndex + 1;
      rateform.toMonth.selectedIndex = rateform.fromMonth.selectedIndex;
      rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex;
    }
    changeDates();
    return void(0);
  }

  if (fromMonth == toMonth) {
    if (toDay - fromDay > 10) currentstatus = false;
  } else {
    if ((tdays - fromDay) + toDay > 10) currentstatus = false;
  }

  if (!currentstatus) {
    alert("The maximum number of days you can book online is 10.\n\nShould you wish to stay longer than this, please call our Customer Contact Centre\non "+ contact +" (national) or +613 6225 7016 (overseas) and they will assist\nwith your booking.");
    if (tdays <= fromDay + 1) {
      rateform.toDay.selectedIndex = 0;
      if (fromMonth == 12) {
        rateform.toMonth.selectedIndex = 0;
        rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex + 1;
      } else
        rateform.toMonth.selectedIndex = rateform.fromMonth.selectedIndex;
    } else {
      rateform.toDay.selectedIndex = rateform.fromDay.selectedIndex + 1;
      rateform.toMonth.selectedIndex = rateform.fromMonth.selectedIndex;
      rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex;
    }
    changeDates();
    return void(0);
  }


	/* *********************************************************
		EP (2008-01-03): This function is disabled.
		EP (2008-05-23): Modified and Re-enabled..
		-------------------------------------------
	*/
  // Freycinet & Wrest Point min 2 night exception
  //if (property_id == 1676 || property_id == 1679)
  if (property_id == 1679 || property_id == 1676) {
    currentstatus = true;

	var minimumStay;
	var fromDate2, toDate2;
	var startDate, finishDate;
	
	fromDate2 = new Date(fromYear, fromMonth - 1, fromDay);
	toDate2 = new Date(toYear, toMonth - 1, toDay);

    // Freycinet check
    if (property_id == 1676) {
      //alert("TRUE ID: "+property_id+" Month: "+toMonth+" Day: "+toDay);
		
		minimumStay = 2 * 24 * 60 * 60 * 1000	// 2 days
		
		startDate = new Date(2008, 12-1, 20);
		finishDate = new Date(2009, 4-1, 12);

		if (startDate <= toDate2 && toDate2 <= finishDate)	{
			if ((toDate2 - fromDate2) < minimumStay)	{
				currentstatus = false;
			}
		}
    }

    // Wrest Point check
    if (property_id == 1679) {
		
		minimumStay = 2 * 24 * 60 * 60 * 1000	// 2 days
		
		startDate = new Date(2008, 12-1, 30);
		finishDate = new Date(2009, 1-1, 1);

		if (startDate <= toDate2 && toDate2 <= finishDate)	{
			if ((toDate2 - fromDate2) < minimumStay)	{
				currentstatus = false;
			}
		}
    }

    if (!currentstatus) {
      if (property_id == 1676)
        alert("The minimum stay at all room types at Freycinet Lodge between\n20th December 2008 and 12th April 2009 is two nights.\n\nThe select boxes will be reset for you to make another date selection.");
      else
        alert("The minimum stay at all room types at Wrest Point between\n30th December 2008 and 1st January 2009 is two nights.\n\nThe select boxes will be reset for you to make another date selection.");

      if (tdays <= fromDay + 1) {
        rateform.toDay.selectedIndex = 0;
        if (fromMonth == 12) {
          if (tdays == fromDay)
            rateform.toDay.selectedIndex = 1;
          else
            rateform.toDay.selectedIndex = 0;

          rateform.toMonth.selectedIndex = 0;
          rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex + 1;
        } else
          rateform.toMonth.selectedIndex = fromMonth;
      } else
        rateform.toDay.selectedIndex = fromDay + 1;

      changeDates();
      return void(0);
    }
  }
	/*********************************************************	*/

  // display and reset hidden elements
  with (document) {
    getElementById("currentRoom_header").style.display = "block";
    getElementById("currentRoom").innerHTML = "<div style=\"padding:20px 20px 21px 12px\"><strong>LOADING...</strong></div>"
    getElementById("currentRoom").style.display = "block";
    getElementById("currentRoom_footer").style.display = "block";
    getElementById("error").style.display = "none";
    getElementById("addholiday").style.display = "none";
    getElementById("total").innerHTML = "&nbsp;";
    if (rtype == 1 || rtype == 5) {
      getElementById("otherRoom_holder").style.display = "block";
      getElementById("otherRoom").innerHTML = "<div style=\"padding:20px 20px 21px 12px\"><strong>LOADING...</strong></div>";
      getElementById("otherRoom").style.display = "block";
    }
  }

  // calculate nights
  if (fromMonth == toMonth)
    nights = toDay - fromDay;
  else
    nights = (tdays - fromDay) + toDay;

  calcDateSpan(); // function found below

  // loadxmlDoc function found in xmlhttp.js
  if (isPT)
    loadXMLDoc("includes/searchrooms.asp?property_id="+ property_id +"&rtype="+ rtype +"&fromDate="+ datearr[0] +"&adult="+ numAdult +"&child="+ numChild +"&ran="+ getRan());
  else
    loadXMLDoc("../includes/searchrooms.asp?property_id="+ property_id +"&rtype="+ rtype +"&fromDate="+ datearr[0] +"&adult="+ numAdult +"&child="+ numChild +"&ran="+ getRan());
}

function processData() {
  var output_current = "", output_other = "", daterow = "", pricerow = "", daterow_output = "";
  var ddate, dday, dmonth, dyear;
  var ndate, nday, nmonth, nyear;
  var available, check = "", firsttime = true;
  var nodecount = 0, ratecount = 0, ratetotal, rollevents, dstatus, maxpeople;
  // EP(2007-10-19)
  var cellOnclick = "", cellClass = "";

  // write html for current room, other rooms and N/A rates
  if (rtype == 1)
  	// EP (2007-10-22)
    //var output_current_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-current\"><tr class=\"top\"><th>Room Name</th>";
    var output_current_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-current\"><tr class=\"top\"><th>&nbsp;</th>";
  else
    //var output_current_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-current\"><tr class=\"top\"><th>Tour Name</th>";
    var output_current_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-current\"><tr class=\"top\"><th>&nbsp;</th>";

  // EP (2007-10-22)
  //var output_other_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-other\"><tr class=\"top\"><th>Room Name</th>";
  var output_other_head = "<table cellspacing=\"0\" cellpadding=\"4\" border=\"0\" class=\"rates-other\"><tr class=\"top\"><th>&nbsp;</th>";
  var output_na = "<td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td><td onmouseout=\"removeCallInfo()\" class=\"full\">CALL</td>";

  var searchxml =  xml.responseXML.documentElement.childNodes;
  var slength = searchxml.length;
  var dlength = slength / roomarr.length;

  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";
  }

  // reset values
  ready = true;
  price = 0;
  total = 0;


  for (var r = 0; r < roomarr.length; r++) {
    // if tour, fast forward to the node needed
		if (roomarr.length == 1) {
		  maxpeople = 10;
		  for (var i = 0; i < slength; i++) {
		    var search_child = searchxml[nodecount].childNodes;
		    if (room_id == search_child[0].firstChild.nodeValue) break;
		    nodecount += 1;
		  }
		}

		// EP (2007-11-02): Added code to find the current room
		nodecount = -1;	// initialize nodecount
		
		for (var 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;
			}
		}

//alert("nodecount: " + nodecount + ", slength: " + slength);

    if (slength > nodecount) {
      // EP (2007-11-19)
      //if (nodecount > 9 || r == 0) {
		if (nodecount < 0) {
			// Could not find matching room in XML. Show default CALL cell.
			roomnode_id = 0;
		} else {
			var search_child = searchxml[nodecount].childNodes;
			// room id of the current room
			roomnode_id = search_child[0].firstChild.nodeValue;
		}
      //}
//alert("roomnode_id: " + roomnode_id + ", roomarr[r]: " + roomarr[r]);
      if (roomnode_id != roomarr[r]) {
        rollevents = "onMouseOver=\"this.className='row-on';\" onMouseOut=\"this.className='';\" ";
        
        // EP(2007_10-19)
        /*
        if (isPT)
        	rollevents += "onClick=\"location.href='default.asp?pID="+ pagearr[r] +"&i="+ itinerary_id +"&deleteroom=true&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
        else
          	rollevents += "onClick=\"location.href='?r="+ roomarr[r] +"&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
		*/
		//rollevents = "";
        pricerow = "<tr "+ rollevents +"><th>"+ namearr[r] +"</th><td colspan=\"10\" style=\"width:400px\">This room's maximum number of people per room has been exceeded</td>";
      } else {
        for (var i = 0; i <= 9; i++) {
          // format date manually and write date row.. this is used in the loop
          datespan = datearr[i];
          dyear = datespan.substring(2, 4);
          dmonth = datespan.substring(5, datespan.indexOf("-", 5));
          dday = datespan.substring(6 + dmonth.length, datespan.length);
          ddate = dday +"."+ dmonth +"."+ dyear;

          // if current room date matches todate, then write check value
          if (roomarr[r] == room_id) {
          	// EP (2007-10-22)
            //if (ddate == fromDate) check = " class=\"checked\"";
            if (ddate == fromDate) check = "checked";
            if (rtype == 1) if (ddate == toDate) check = "";
          }

		  // EP (2007-10-22)
          //daterow += "<td"+ check +">"+ dday +"."+ dmonth +"."+ dyear +"</td>";
          daterow += "<td class=\""+ check +"\">"+ dday +"."+ dmonth +"."+ dyear +"</td>";

          if (slength > 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;
              // set max people value
              if (i == 0 && roomarr.length > 1) maxpeople = parseInt(search_child[5].firstChild.nodeValue);

              // display price, full or no rate
			 
			 
			 	if (rtype == 2){
					if(check == "checked"){
						price = parseInt(search_child[4].firstChild.nodeValue);
					}
				}else{
					price = parseInt(search_child[4].firstChild.nodeValue);
				}
			 	//alert("price: " + price)
              	displayPrice = parseInt(search_child[4].firstChild.nodeValue);
	

			  
				// Not sure why we're we're dividing the price - and equally not sure why just resetting it works
				// ** the monkey made another file called planner2.js || planner_special.js || planner_special2.js which is also called!??! - so if this fails amke sure you update it there
				// i'll mark it with *MONKEY DANCE*
				// if (rtype == 2) price = price / numAdult;

			 	
			 
			 
              available = parseInt(search_child[3].firstChild.nodeValue);
			//
			//if (rtype == 1){
				
              if (check) total += price;
			  //alert(check + " || " + ddate + " || " + price)
			//}

              if (available)	{
              	// EP (2007-10-19): Made price cells clickable.
                //pricerow += "<td"+ check +">$"+ price +"</td>";
                //pricerow += "<td class=\""+ check +"\">$"+ price +"</td>";
                //if (room_id == roomnode_id)	{
                //	cellOnclick = "";
                //	cellClass = "";
                //}
                //else	{
                	//cellOnclick = " onClick=\"location.href='default.asp?pID="+ pagearr[r] +"&i="+ itinerary_id +"&deleteroom=true&fdate="+ nday +"/"+ nmonth +"/"+ nyear +"'\" onMouseOver=\"roomRateMouseOver(this)\" onMouseOut=\"roomRateMouseOut(this)\"";
                	cellOnclick = " onClick=\"calculateSelectedDateRange(" + pagearr[r] + ", " + itinerary_id + ", '" + nday + "', '" + nmonth + "', '" + nyear + "');\" onMouseOver=\"roomRateMouseOver(this)\" onMouseOut=\"roomRateMouseOut(this)\"";
                	
                	if (check) {
                		cellClass = " room-rate-cell"
                	}
                	else	{
                		cellClass = "room-rate-cell"
                	}
                //}
                // EP (2007-10-22)
                //pricerow += "<td"+ check + cellOnclick + ">$"+ price +"</td>";
                pricerow += "<td class=\""+ check + cellClass + "\"" + cellOnclick + ">$"+ displayPrice +"</td>";
				 
              }
              else {
                if (property_id == 1885 && parseInt(nyear) <= 10 && parseInt(nmonth) < 3 || (property_id == 1885 && parseInt(nyear) == 10 && parseInt(nday) < 16 && parseInt(nmonth) == 3)) {
					pricerow += "<td class=\"full\" onmouseout=\"removeCallInfo()\">CLOSED</td>";
					if (check) 
						ready = false;
				}
				else
				{
					pricerow += "<td class=\"full\" onmouseout=\"removeCallInfo()\">CALL</td>";
					if (check) 
						ready = false;
				}
              }
            } else {
				pricerow += "<td class=\"full\" onmouseout=\"removeCallInfo()\">CALL</td>";
              if (check) ready = false;
            }

            // 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 (i == 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;

          } else {
            pricerow += "<td class=\"full\">CALL</td>";

            if (check) ready = false;
          }
			
          if (i == 0) {
            if (roomarr[r] == room_id) {
              pricerow = "<tr><th>"+ namearr[r] +"</th>" + pricerow;
            } else {
              rollevents = "onMouseOver=\"this.className='row-on';\" onMouseOut=\"this.className='';\" ";
	        // EP(2007_10-19)
	        /*
              if (isPT)
                rollevents += "onClick=\"location.href='default.asp?pID="+ pagearr[r] +"&i="+ itinerary_id +"&deleteroom=true&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
              else
                rollevents += "onClick=\"location.href='?r="+ roomarr[r] +"&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
            */
            	//rollevents = "";
              pricerow = "<tr "+ rollevents +"><th>"+ namearr[r] +"</th>" + pricerow;
            }
          }

          // if current room date matches todate, then clear check value
          if (roomarr[r] == room_id) {
            if (rtype == 2) if (ddate == toDate) check = "";
            if (nights == 10 && i == 9) check = "";
          }
          
        }
       	}
    } else {
      if (roomarr[r] == room_id) {
        ready = false;
        pricerow = "<tr><th>"+ namearr[r] +"</th>"+ output_na;
      } else {
        rollevents = "onMouseOver=\"this.className='row-on';\" onMouseOut=\"this.className='';\" ";
        // EP(2007_10-19)
        /*
        if (isPT)
          rollevents += "onClick=\"location.href='default.asp?pID="+ pagearr[r] +"&i="+ itinerary_id +"&deleteroom=true&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
        else
          rollevents += "onClick=\"location.href='?r="+ roomarr[r] +"&fdate="+ fromDay +"/"+ fromMonth +"/"+ fromYear +"&tdate="+ toDay +"/"+ toMonth +"/"+ toYear +"'\"";
		*/
		//rollevents = "";
        pricerow = "<tr "+ rollevents +"><th>"+ namearr[r] +"</th>";

        if (dstatus == "nada" || dstatus == "normal-12")
          if (slength == 0)
            pricerow += output_na;
          else
            pricerow += "<td colspan=\"10\" style=\"width:400px\">This room's maximum number of people per room has been exceeded</td>";
        else
          pricerow += "<td colspan=\"10\" style=\"width:400px\">This room's maximum number of people per room has been exceeded</td>";
      }
    }

    daterow += "</tr>";
    pricerow += "</tr>";

    // write current room type and other room type variables for output
    if (roomarr[r] == room_id) {
      // if there are rate errors
      if (!ready && dstatus != "normal") {
        daterow = "";
        for (d = 0; d < datearr.length; d++) {
          datespan = datearr[d];
          dyear = datespan.substring(2, 4);
          dmonth = datespan.substring(5, datespan.indexOf("-", 5));
          dday = datespan.substring(6 + dmonth.length, datespan.length);
          ddate = dday +"."+ dmonth +"."+ dyear;
          if (ddate == fromDate) {
          	// EP (2007-10-22)
            //check = " class=\"checked\"";
            check = "checked";
            if (rtype == 1) if (ddate == toDate) check = "";
          }
          if (ddate == toDate) {
            check = "";
            if (rtype == 2) if (ddate == toDate) check = "";
          }
          // EP (2007-10-22)
          //daterow += "<td"+ check +">"+ ddate +"</td>";
          daterow += "<td class=\""+ check +"\">"+ ddate +"</td>";
        }
        daterow += "</tr>";
      }

      output_current = daterow + pricerow;

    } else {
      output_other += pricerow;

      // if there are rate errors
      if (daterow_output.length == 0) {
        for (d = 0; d < datearr.length; d++) {
          datespan = datearr[d];
          dyear = datespan.substring(2, 4);
          dmonth = datespan.substring(5, datespan.indexOf("-", 5));
          dday = datespan.substring(6 + dmonth.length, datespan.length);
          ddate = dday +"."+ dmonth +"."+ dyear;
          daterow_output += "<td>"+ ddate +"</td>";
        }
      }
    }

    pricerow = "";
    daterow = "";
  }

  document.getElementById("currentRoom").innerHTML = output_current_head + output_current + "</table>";
  if (rtype == 1) document.getElementById("otherRoom").innerHTML = output_other_head + daterow_output + output_other + "</table><div class=\"clear\">&nbsp;</div>";

  // if availability confirmed, then display add to holiday link
  // if not, display error messages and hide add to holiday link
  if (ready) {
    calcTotal();
    document.getElementById("addholiday").style.display = "block";
  } else {
    document.getElementById("error").style.display = "block";
    document.getElementById("total").innerHTML = "Total - A$0.00";
  }
  
  /*
  **Scroll to the holiday planner at the bottom of the page by default
  * window.scroll(0,20000);
  * ROMOVED on the 07/04/2009 by Oliver
  */
}

function changeDates() {
  var rateform = document.ratefrm, toDateExist = false;

  fromDay = parseInt(rateform.fromDay.value);
  fromMonth = parseInt(rateform.fromMonth.value);
  fromYear = parseInt(rateform.fromYear.value);

  if (document.getElementById("addholiday")) {
    removeAddLink();
    if  (roomarr.length > 1 && room_id != 0 && rtype == 1)
      toDateExist = true;
    else
      toDateExist = false;
  } else
    toDateExist = false;

  if (toDateExist) {
    toDay = parseInt(rateform.toDay.value);
    toMonth = parseInt(rateform.toMonth.value);
    toYear = parseInt(rateform.toYear.value);

    // check if the "to" day is less than the "from" day, and change if so
    if (fromDay >= toDay && fromMonth == toMonth && fromYear == toYear) {
      if (calcDays(fromDay, fromMonth, fromYear, "nosubtract") == fromDay) {
        rateform.toDay.selectedIndex = 0;
        if (fromMonth == 12) {
          rateform.toMonth.selectedIndex = 0;
          rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex + 1;
        } else
          rateform.toMonth.selectedIndex = fromMonth;
      } else
        rateform.toDay.selectedIndex = fromDay;

      toDay = parseInt(rateform.toDay.value);
    }

    // check if the "to" month is less than the "from" month, and change if so
    if (fromDay < toDay && fromMonth > toMonth && fromYear == toYear && fromMonth != 12) {
      if (calcDays(fromDay, fromMonth, fromYear, "nosubtract") == fromDay) {
        rateform.toDay.selectedIndex = 0;
        rateform.toMonth.selectedIndex = fromMonth;
      } else
        rateform.toMonth.selectedIndex = fromMonth - 1;

      toDay = parseInt(rateform.toDay.value);
      toMonth = parseInt(rateform.toMonth.value);
    }

    // check if the "to" year is less than the "from" year, and change if so
    if (fromDay < toDay && fromMonth < 12 && (fromYear <= toYear || fromYear >= toYear)) {
      rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex;
      toYear = parseInt(rateform.toYear.value);
    }

    // if "to" year is greater than "from" year than set month to Jan
    //if (fromMonth == toMonth && fromYear < toYear) {
    //  rateform.toDay.selectedIndex = 0;
    //  toDay = parseInt(rateform.toDay.value);
    //  rateform.toMonth.selectedIndex = 0;
    //  toMonth = parseInt(rateform.toMonth.value);
    //}

    // if changing years, switch months to Jan
    if (fromYear > toYear) {
      rateform.fromDay.selectedIndex = 0;
      fromDay = parseInt(rateform.fromDay.value);
      rateform.fromMonth.selectedIndex = 0;
      fromMonth = parseInt(rateform.fromMonth.value);

      rateform.toDay.selectedIndex = 2;
      toDay = parseInt(rateform.toDay.value);
      rateform.toMonth.selectedIndex = 0;
      toMonth = parseInt(rateform.toMonth.value);
      rateform.toYear.selectedIndex = rateform.fromYear.selectedIndex;
      toYear = parseInt(rateform.toYear.value);
    }

    // refresh the number of days according to the month
    changeDay("to", toDay, toMonth, toYear);
  }

  // refresh the number of days according to the month
  // this function needs to run every time
  changeDay("from", fromDay, fromMonth, fromYear);
}

function removeAddLink() {
  document.getElementById("addholiday").style.display = "none";
}

function changeDay(strDay, nDay, nMonth, nYear) {
  var selectProp = eval("document.ratefrm." + strDay + "Day");
  var selectLength = selectProp.length;

  // loops through and removes current options
  for (var i = 0;  i < selectLength; i++)
    selectProp.remove(0);

  // write new options to the day field depending on which month
  for (i = 1; i <= calcDays(nDay, nMonth, nYear); i++)
    selectProp.options[i-1] = new Option(i, i);

  // select the day that was previously selected
  if (nDay >= calcDays(nDay, nMonth, nYear))
    selectProp.selectedIndex = calcDays(nDay, nMonth, nYear, "nosubtract") - 1;
  else
    selectProp.selectedIndex = nDay - 1;
}

function calcDays(nDay, nMonth, nYear, subtract) {
  // find total days in month and calculate difference
  var totalDays;

  if (nMonth == 4 || nMonth == 6 || nMonth == 9 || nMonth == 11)
    totalDays = 30;
  else if (nMonth == 2)
    if (Math.floor(nYear/4) == (nYear/4) && (Math.floor(nYear/100) != (nYear/100) || Math.floor(nYear/400) == (nYear/400)))
      totalDays = 29;
    else
      totalDays = 28;
  else
    totalDays = 31;

  if (subtract == "subtract") totalDays = totalDays - nDay;

  return (totalDays);
}

function calcDateSpan() {
  // creates date array spanning each day for 10 days
  var daysleft;
  var daycount = fromDay, monthcount = fromMonth, yearcount = fromYear, tDay, tMonth, tYear;
  var totaldays = calcDays(daycount, monthcount, yearcount, "");

  if (nights < 7) {
    if (monthcount == currentMonth && yearcount == currentYear)
      if (daycount - currentDay > 3)
        daycount = daycount - 3;
      else
        daycount = daycount - (daycount - currentDay);
    else
      daycount = daycount - 3;
  }

  if (daycount < 1) {
    monthcount = monthcount - 1;
    if (monthcount == 0) {
      monthcount = 12;
      yearcount = yearcount - 1;
    }
    daycount = calcDays(daycount, monthcount, yearcount, "") + daycount;

    if (daycount < (currentDay + 1) && monthcount == currentMonth && yearcount == currentYear) {
      if (daycount + 1 > calcDays(daycount, monthcount, yearcount, "")) {
        daycount = 1;
        monthcount = monthcount + 1;
      } else
        daycount = currentDay + 1;
    }
  }

  if ((totaldays - daycount) - 10 < 1) tMonth = monthcount + 1;
  if (monthcount != tMonth) daysleft = calcDays(daycount, monthcount, yearcount, "subtract") + 1;

  if (monthcount == 12 && daycount >= 22) {
    tYear = yearcount + 1;
    tMonth = 1;
  } else
    tYear = yearcount;

  if (monthcount == 0) {
    monthcount = 12;
    yearcount = yearcount - 1;
  }

  for (var i = 0; i <= 9; i++) {
    if (i == daysleft) {
      daycount = 1;
      monthcount = tMonth;
      yearcount = tYear;
    }
    datearr[i] = yearcount +"-"+ monthcount +"-"+ daycount;
    daycount = daycount + 1;
  }
}

function writePeopleSelect(mppl) {
  var selectPeople, selectLength, i;
//  if (roomarr.length > 1)
    var peopleArr = new Array("adult","child");
//  else
//    var peopleArr = new Array("adult");

  for (var p = 0; p <= peopleArr.length - 1; p++) {
    selectPeople = eval("document.ratefrm." + peopleArr[p]);
    if (selectPeople)	{
    	selectLength = selectPeople.length;

	    // loops through and removes current options
	    for (i = 0;  i < selectLength; i++)
	      selectPeople.remove(0);

	    if (peopleArr[p] == "adult") {
	      for (i = 1; i <= mppl; i++)
	        selectPeople.options[i-1] = new Option(i,i);
	    } else {
	      mppl += -1;
	      for (i = 0; i <= mppl; i++)
	        selectPeople.options[i] = new Option(i,i);
	    }
    }


    // write new options to the day field depending on which month
    //for (i = 0; i <= mppl; i++) {
    //  if (peopleArr[p] == "adult")
    //    selectPeople.options[i] = new Option(i,i);
    //  else
    //    selectPeople.options[i] = new Option(i,i);
    //}

    if (peopleArr[p] == "adult")
      if (numAdult == "")
        if (mppl >= 2)
          if (roomarr.length > 1)
            selectPeople.selectedIndex = 1;
          else
            selectPeople.selectedIndex = 0;
        else
          selectPeople.selectedIndex = mppl;
      else	{
    	if (selectPeople.options.length > 0)	{
	    	if (selectPeople.options.length >= numAdult)	{
	    		if (numAdult > 0)	{
        selectPeople.selectedIndex = numAdult - 1;
	      		}
	    	}
	    	else	{ // no available number of adults
	    		// choose the maximum number of adults
	    		selectPeople.selectedIndex = selectPeople.options.length - 1;
	    		numAdult = selectPeople.options.length;
	    	}
		}
		else	{
			numAdult = 0;
		}
		//selectPeople.selectedIndex = numAdult - 1;
      }
    else
    	if (selectPeople)	{
	    	if (selectPeople.options.length > 0)	{
		    	if (selectPeople.options.length >= numChild)	{
	      selectPeople.selectedIndex = numChild;
	  }
		    	else	{ // no available number of children
		    		// choose the maximum number of children
		    		selectPeople.selectedIndex = selectPeople.options.length - 1;
		    		numChild = selectPeople.options.length;
		    	}
			}
			else	{
				numChild = 0;
			}
		}
		else	{
			numChild = 0;
		}
  }
}

function selectSpecialOptions(seating, times, depart) {
  if (property_id == 1682) {
    if (seating.length > 0)
      if (seating == "Lower") document.ratefrm.searchstring1.selectedIndex = 1;

    if (times.length > 0)
      if (times == "Evening") document.ratefrm.searchstring2.selectedIndex = 1;
  } else {
    if (seating.length > 0)
      if (seating == "Tourist") document.ratefrm.searchstring1.selectedIndex = 1;

    if (times.length > 0)
      if (times == "PM") document.ratefrm.searchstring2.selectedIndex = 1;

    if (depart.length > 0)
      if (depart == "Strahan") document.ratefrm.searchstring3.selectedIndex = 1;
  }
}

function checkMaxPeople() {
  var adulttotal = parseInt(document.ratefrm.adult.value);
  if (document.ratefrm.child)
    var childtotal = parseInt(document.ratefrm.child.value);
  else
    var childtotal = 0;

  if (adulttotal + childtotal > maxppl) {
		if (property_id != 1885)
			alert("Error: The maximum amount of people allowed for this room is "+ maxppl +".");
		else
			alert("Rollaways for an extra guest are available on request. Please call us on 1800 SAFFIRE (toll free Australia) or +613 6256 7888 (international – applicable call rates apply), or email ea@saffire-freycinet.com.au with your enquiry.");
    return true;
  } else if (adulttotal == 0) {
    alert("Error: There must be at least one adult chosen for booking a room.");
    return true;
  }
}

function calcTotal() {
	
	
//if (roomarr.length == 1) <-- Silliest guard for the total price. Was giving the wrong totals for certain experiences
if (rtype == 2) //<-- BETTER!
	total = price * parseInt(document.ratefrm.adult.value);


//alert(total)
if (total == 99999999)
total = 0;

else {
// adds a comma for totals with 4 digits and under 6 digits
	if (total > 999 && total < 10000) {
		total = ""+ total +"";
		total = total.substring(0, 1) +","+ total.substring(1, 4);
	}
	else if (total > 9999)
	{
		total = ""+ total +"";
		total = total.substring(0, 2) +","+ total.substring(2, 5);
	}
}
document.getElementById("total").innerHTML = "Total - A$"+ total +".00";
document.ratefrm.totalamount.value = total;
}

function submitForm() {
  var rateform = document.ratefrm;
  if (parseInt(rateform.adult.value) > 0) {
  	  // EP (2008-10-01): Hard-coded to override the default room id passed in.
  	  if (new_room_id != 0)	{
  	  	  room_id = new_room_id;
  	  }
  	  //alert("room_id: " + room_id + ", new_room_id: " + new_room_id);
    if (isPT)
      rateform.action = "functions/addroom.asp?itinerary_id="+ itinerary_id +"&property_id="+ property_id +"&room_id="+ room_id +"&rtype="+ rtype;
    else
      rateform.action = "details.asp?p="+ property_id +"&r="+ room_id;
    rateform.submit();
  } else
    alert("Error: There must be at least one adult selected when booking accommodation.");
}

function submitQuickForm() {
  var rateform = document.ratefrm;
  if (parseInt(rateform.adult.value) > 0) {
    if (isPT)
      rateform.action = HTTPS_PATH + "quickbook/details.asp?p="+ property_id +"&r="+ room_id;
    else
      rateform.action = "details.asp?p="+ property_id +"&r="+ room_id;
    rateform.submit();
  } else
    alert("Error: There must be at least one adult selected when booking accommodation.");
}

function submitQuickBooking() {
  var quickform = document.quickfrm;
  var property_id;
  var room_id;
  //var fromDay = parseInt(quickform.fromDay.value);
  //var fromMonth = parseInt(quickform.fromMonth.value);
  //var fromYear = parseInt(quickform.fromYear.value);
  var fromDate = quickform.fromDate.value;
  if (fromDate == "Select Date") fromDate = "";
  var sAlert = "";

	if ($('#accommodations').is(':visible'))	{	// Accommodation
		property_id = quickform.property.value;
		room_id = quickform.roomtype.value;
		sAlert = "To continue you must choose a destination and room type.\nPlease select one of each before proceeding.";
	}
	else	{	// Experiences
		property_id = quickform.experienceproperty.value;
		room_id = quickform.experiencetype.value;
		sAlert = "To continue you must choose an experience and type.\nPlease select one of each before proceeding.";
	}

	//alert("property_id " + property_id + ", room_id: " + room_id);
	if (property_id == 0 || room_id == 0) {
		alert(sAlert);
		return;
	}
	

  var currentstatus = true;
  //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.");
    quickform.fromDay.selectedIndex = currentDay - 1;
    quickform.fromMonth.selectedIndex = currentMonth - 1;
    return;
  } else {
    //quickform.action = "functions/addroom.asp?itinerary_id=0&property_id="+ property_id +"&room_id="+ room_id +"&rtype=3";
    quickform.action = "default.asp?property_id="+ property_id +"&room_id="+ room_id + "&fdate=" + fromDate
    quickform.submit();
  }
}

function loadRoomTypeSelect() {
  var roomselect = document.quickfrm.roomtype;
  var roomlength = roomselect.length;

  if (!xml) {
    var property_id = document.quickfrm.property.value;

	if (property_id.indexOf("http://") != -1 || property_id.indexOf("https://") != -1)	{
		// refresh room type dropdown list
		roomselect.options.length = 0;
		roomselect.options[0] = new Option("Room Type", 0);
		// open in a new window
		window.open(property_id);
	}
	else	{
	    // remove existing options
	    for (i = 0; i < roomlength; i++)
	      roomselect.remove(0);

	    if (property_id != 0) {
	      roomselect.options[0] = new Option("Choose Room", "0");
	      loadXMLDoc("includes/searchproperty.asp?property_id="+ property_id +"&quickbook=true&ran="+ getRan());
	    } else	{
	      roomselect.options[0] = new Option("Choose Room", "0");
	    }
	}
  } else {
	    var roomtypes = xml.responseXML.documentElement.getElementsByTagName("roomtype");

	    // remove loading option
	    //roomselect.remove(0);

	    // replace with new options
	    for (i = 0; i < roomtypes.length; i++)
	      roomselect.options[i] = new Option(roomtypes[i].getAttribute("name"), roomtypes[i].getAttribute("id"));

	    xml = null;
  }
}

function loadExperienceTypeSelect() {
	var experiencetypeselect = document.quickfrm.experiencetype;
	var property_id = document.quickfrm.experienceproperty.value;
	var objOptions;
// Hard-coded experiences quickbook

	objOptions = experiencetypeselect.options;
	// clear the type select.
	objOptions.length = 0;

	switch (parseInt(property_id,10))	{
		case 1682:	// Strahan - Gordon River Cruises
			objOptions[objOptions.length] = new Option("Captains Premier Upper Deck", 5048);
			objOptions[objOptions.length] = new Option("Standard Atrium Seating", 5050);
			objOptions[objOptions.length] = new Option("Premium Window Seating", 6925);
			break;
		case 1683:	// Strahan - Tours
			objOptions[objOptions.length] = new Option("Piners and Miners", 5045);
			objOptions[objOptions.length] = new Option("Gordon River Paddle", 6875);
			objOptions[objOptions.length] = new Option("Gordon River Scenic Flights", 5046);
			objOptions[objOptions.length] = new Option("Strahan Helicopters", 5047);
			objOptions[objOptions.length] = new Option("Jet Boating", 5044);
			break;
		case 1684:	// Strahan - West Coast Wilderness Railway
			objOptions[objOptions.length] = new Option("Premier from Strahan", 5067);
			objOptions[objOptions.length] = new Option("Tourist from Strahan", 5071);
			objOptions[objOptions.length] = new Option("Premier from Queenstown", 5077);
			objOptions[objOptions.length] = new Option("Tourist from Queenstown", 5081);
			break;
		case 1681:	// Freycinet Tours
			objOptions[objOptions.length] = new Option("Wineglass to wine glass", 6770);
			objOptions[objOptions.length] = new Option("Bluestone Bay 4WD Tour", 5036);
			objOptions[objOptions.length] = new Option("Taste of Tasmania", 5037);
			objOptions[objOptions.length] = new Option("Wineglass Bay Lookout Guided Walk", 5039);
			objOptions[objOptions.length] = new Option("Wineglass Bay Self Discovery Walk", 5040);
			objOptions[objOptions.length] = new Option("Oysters on The Bay Morning", 6988);
			objOptions[objOptions.length] = new Option("Oysters on The Bay Morning", 6989);
			break;
		case 1823:	// Hobart Experiences
			objOptions[objOptions.length] = new Option("Bruny Wildlife Adventure", 6979);
			objOptions[objOptions.length] = new Option("Peppermint Bay Cruise", 6984);
			break;
	}
}
// add mouse move event for FireFox
if (window.addEventListener) {
  document.captureEvents(Event.MOUSEMOVE);

  Event.prototype.__defineGetter__("srcElement", function() {
    var eElement = this.target;
    return eElement;
  });
}

document.onmousemove = moveCallInfo;
var blnRemoveCallInfo = true;

function moveCallInfo(oEvent) {
	var eCall;
	
  if (!oEvent) oEvent = window.event;

  if ((oEvent.srcElement.innerHTML == "CALL" || oEvent.srcElement.innerHTML == "CLOSED") && oEvent.srcElement.nodeName == "TD") {
    if (!document.getElementById("call")) {
      	eDiv = document.createElement("div");
		document.body.insertAdjacentElement("beforeEnd", eDiv);

      with (eDiv) {
        id = "call";
        if (browser.isIE) {
          style.top = (event.clientY + document.documentElement.scrollTop + 1) + "px";
          style.left = (event.clientX + document.documentElement.scrollLeft + 1) + "px";
        } else {
          style.top = (oEvent.pageY + 1) + "px";
          style.left = (oEvent.pageX + 1) + "px";
        }
        style.position = "absolute";
        style.width = "180px";
        style.zIndex = "100";
        style.color = "#FFF";
        style.backgroundColor = "#C0BB9C";
        style.textAlign = "left";
        style.border = "1px solid #6D6763";
        style.padding = "2px 4px";
        
        // EP (2008-03-28) : Commented out for Henry Jones Hotel
        innerHTML = "Please call our Customer Contact Centre on <strong>1800 420 155</strong> (toll free Australia) or <strong>+613 6225 7016</strong> (international - applicable call rates apply) for further options. Or email <strong>bookings@puretasmania.com.au</strong>";
      }
    }
    eCall = document.getElementById("call");

	blnRemoveCallInfo = false;
	eCall.style.display = "block";

	if (browser.isIE) {
	  eCall.style.top = (event.clientY + document.documentElement.scrollTop + 1) + "px";
	  eCall.style.left = (event.clientX + document.documentElement.scrollLeft + 1) + "px";
	} else {
	  eCall.style.top = (oEvent.pageY + 1) + "px";
	  eCall.style.left = (oEvent.pageX + 1) + "px";
	}

//	if (oEvent.srcElement.offsetParent.id == "hobart_2") {
	if (property_id == 1819) { // Henry Jones Specific
		eCall.innerHTML = "Please call <strong>1300 665 581</strong><br /> or <a href=\"http://www.thehenryjones.com/suites.html\" target=\"_blank\">click here</a> to make a booking.";
	} else if (oEvent.srcElement.className == "full")	{
		if (property_id == 1885) {
			eCall.innerHTML = "Please call us on <strong>1800 SAFFIRE</strong> (toll free Australia) or <strong>+613 6256 7888</strong> (international - applicable call rates apply), or email <strong><a href=\"mailto:ea@saffire-freycinet.com.au\">ea@saffire-freycinet.com.au</a></strong>";
		}
		else {
			eCall.innerHTML = "Please call our Customer Contact Centre on <strong>1800 420 155</strong> (toll free Australia) or <strong>+613 6225 7016</strong> (international - applicable call rates apply) for further options. Or email <strong><a href=\"mailto:bookings@puretasmania.com.au\">bookings@puretasmania.com.au</a></strong>";
		}
	}
  }
  else	{
	eCall = document.getElementById("call");
  }

	var top, left, right, bottom;
	var x, y;

	if (eCall)	{
		top = parseInt(eCall.style.top.replace("px", "")) - 1;
		left = parseInt(eCall.style.left.replace("px", "")) - 1;
		right = left + eCall.offsetWidth + 1;
		bottom = top + eCall.offsetHeight + 1;
		if (browser.isIE) {
		  	y = event.clientY + document.documentElement.scrollTop;
		  	x = event.clientX + document.documentElement.scrollLeft;
		} else {
		  	y = oEvent.pageY;
		  	x = oEvent.pageX;
		}
		if (left > x || x > right || top > y || y > bottom)	{
			//alert("x: " + x + ", left: " + left + ", right: " + right + ", y: " + y + ", top: " + top + ", bottom: " + bottom);
			blnRemoveCallInfo = true;
			removeCallInfo();
		}
	}
}

function removeCallInfo() {
	if (blnRemoveCallInfo)	{
		if (document.getElementById("call")) document.getElementById("call").style.display = "none";
	}
}

function getRan() {
  var ran = new Date();
  ran = ran.getDate() +""+ ran.getMonth() +""+ ran.getYear() +""+ ran.getHours() +""+ ran.getMinutes() +""+ ran.getSeconds() +""+ ran.getMilliseconds();
  return ran;
}

/* EP (2007-10-22)	*/
function roomRateMouseOver(objSource)	{
	objSource.className += " room-rate-cell-over";
}

function roomRateMouseOut(objSource)	{
	objSource.className = objSource.className.replace(" room-rate-cell-over", "");
	// just in case,
	objSource.className = objSource.className.replace("room-rate-cell-over", "");
}

function calculateSelectedDateRange(pageid, itinerarayid, cellDay, cellMonth, cellYear)	{
	var rateform = document.ratefrm;
	var adult = parseInt(rateform.adult.value);
	
	var child;
	try {
		child = parseInt(rateform.child.value);
	} catch (err) {
		child = 0;
	}
	
	var fromDay = parseInt(rateform.fromDay.value);
	var fromMonth = parseInt(rateform.fromMonth.value);
	var fromYear = parseInt(rateform.fromYear.value);
	
	var toDay;
	try { toDay = parseInt(rateform.toDay.value); }
	catch (err) { toDay = fromDay + 1; }
	
	var toMonth 
	try { toMonth = parseInt(rateform.toMonth.value); }
	catch (err) { toMonth = fromMonth; }
	
	var toYear 
	try { toYear = parseInt(rateform.toYear.value); }
	catch (err) { toYear = fromYear; }
	//var one_day = 1000*60*60*24

	var d;
	var t1 = Date.UTC(fromYear, fromMonth - 1, fromDay);
	var t2 = Date.UTC(toYear, toMonth - 1, toDay);
	cellYear = "20" + cellYear;
	var t3 = Date.UTC(cellYear, cellMonth - 1, cellDay);
	var tdate = "";

	if (t2 >= t1)	{
		d = new Date(Math.round(t3 + (t2 - t1)));
		tdate = d.getUTCDate() + "/" + parseInt(d.getUTCMonth() + 1, 10) + "/" + d.getUTCFullYear();
	}
	else	{	// ignore date selection in the dropdownlists
		tdate = "";
	}

	if ((adult + child) > maxppl)	{
		if (property_id != 1885)
			alert("Error: The maximum amount of people allowed for this room is "+ maxppl +".");
		else
			alert("Rollaways for an extra guest are available on request. Please call us on 1800 SAFFIRE (toll free Australia) or +613 6256 7888 (international – applicable call rates apply), or email ea@saffire-freycinet.com.au with your enquiry.");
	}
	else if (adult == 0)	{
		alert("Error: There must be at least one adult chosen for booking a room.");
	}
	else	{
		location.href="default.asp?pID="+ pageid +"&i="+ itinerarayid +"&deleteroom=true&fdate="+ cellDay +"/"+ cellMonth +"/"+ cellYear + "&tdate=" + tdate + "&adult=" + adult + "&child=" + child;
	}
}
/* ------------------- */

/* -------- Message div for Quick and normal booking buttons --- */

var eDiv = null;

function showBookInfo(oEvent, isQuickBook) {
	if (!oEvent) oEvent = window.event;
	
	if (!eDiv)	{
		eDiv = document.createElement("div");
		document.body.insertAdjacentElement("beforeEnd", eDiv);
	}
	eDiv.style.display = "block";
	
	with (eDiv) {
		id = "bookinfo";
		if (browser.isIE) {
			style.top = (event.clientY + document.documentElement.scrollTop + 6) + "px";
			style.left = (event.clientX + document.documentElement.scrollLeft + 6) + "px";
		} else {
			style.top = (oEvent.pageY + 6) + "px";
			style.left = (oEvent.pageX + 6) + "px";
		}
		style.position = "absolute";
		style.width = "180px";
		style.zIndex = "100";
		if (isQuickBook)	{
			style.color = "#000";
			style.backgroundColor = "#E8E7E6";
		} else {
			style.color = "#FFF";
			style.backgroundColor = "#928D8A";
		}
		style.textAlign = "left";
		style.border = "1px solid #6D6763";
		style.padding = "2px 4px";
		if (isQuickBook)	{
			innerHTML = "Click here to make this single booking";
		}
		else	{
			innerHTML = "Click here to make a multiple itinerary booking";
		}
	}

    var eCall = document.getElementById("bookinfo");

    if (browser.isIE) {
		eCall.style.top = (event.clientY + document.documentElement.scrollTop + 6) + "px";
		eCall.style.left = (event.clientX + + document.documentElement.scrollLeft + 6) + "px";
    } else {
		eCall.style.top = (oEvent.pageY + 6) + "px";
		eCall.style.left = (oEvent.pageX + 6) + "px";
    }
}

function removeBookInfo() {
	if (eDiv)	{
		eDiv.style.display = "none";
	}
}
