
function RateCapture() {
  var Update = new Date()
  var hours = Update.getHours()
  var minutes = Update.getMinutes()
  if (minutes < 10) {minutes = "0" + minutes}
  if(hours == 12){Time = 12 + ":" + minutes + " PM"}
  else if(hours > 12){Time = hours - 12 + ":" + minutes + " PM"}
  else if(hours == 0){Time = 12 + ":" + minutes + " AM"}
  else {Time = hours + ":" + minutes + " AM"}
  var month = Update.getMonth() + 1
  var day = Update.getDate()
  var year = Update.getFullYear()
  document.getElementById("RateCapture").innerHTML = Time+" on "+month + "/" + day + "/" + year
}

var xmlhttp

function UpdateRates(ID) {
  document.getElementById("RateCapture").innerHTML = "<font color='red'><B>Accessing Data</B></font>"
  xmlhttp = null
  if (window.XMLHttpRequest) {
   xmlhttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject) {
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  var CL
  var CH
  var AL
  var AH
  var LD
  var HD
  var LDtext
  var HDtext
  var inMon = document.RateDatesForm.arrivalMonth.selectedIndex + 1
  var inDay = document.RateDatesForm.arrivalDay.selectedIndex + 1
  var outMon = document.RateDatesForm.departureMonth.selectedIndex + 1
  var outDay = document.RateDatesForm.departureDay.selectedIndex + 1
  var adult = document.hotelSearchCriteriaForm.adults.selectedIndex
  var child = document.hotelSearchCriteriaForm.children.selectedIndex
  var url = "http://www.i-maps.com/hotel-locator/usa/xml_ratetable.asp?HotelID=" + ID + "&inMon=" + inMon + "&inDay=" + inDay + "&outMon=" + outMon + "&outDay=" + outDay + "&adult=" + adult + "&child=" + child
  xmlhttp.open("GET",url,true)
  xmlhttp.onreadystatechange=function() {
   if (xmlhttp.readyState==4) {
    if(xmlhttp.status == 200) {
     AL = document.getElementById("AL").innerHTML.substr(1)  //get value after $ sign
     AH = document.getElementById("AH").innerHTML.substr(1)
     var Rates = new Array();
     Rates = xmlhttp.responseText.split(',')
     CL = Rates[0]
     CH = Rates[1]
     CLtd = document.getElementById("CL")
     CHtd = document.getElementById("CH")
     LDtd = document.getElementById("LD")
     HDtd = document.getElementById("HD")
     ReqD = document.getElementById("ReqDate")
     Difft = document.getElementById("DiffText")
     if (CL==0 || CL=="na" || CL=="NaN"|| CH==0 || CH=="na" || CH=="NaN") 
       {CLtd.innerHTML = "na"; CHtd.innerHTML = "na"; 
        LDtd.innerHTML = "na"; HDtd.innerHTML = "na"; 
        ReqD.innerHTML = "For the dates " + inMon + "/" + inDay + " to " + outMon + "/"
        + outDay + " :<br>Rooms Not Available<br>There is no data available for the above dates."
        // + "<br><br><font color='Red'>If the dates above do not match your required dates,"
        // + "<br>Please enter your specific dates in the Get Room Rates box and hit the Update Rates button below.</font>"
     }
     else {
       CLtd.innerHTML = "$"+CL
       CHtd.innerHTML = "$"+CH 
       LD = CL-AL
       HD = CH-AH
		   if (LD < 0) {
		     LDtd.innerHTML = "-$"+Math.abs(LD)
		     LDtext = "The <b>low rate</b> is <b>$"+ Math.abs(LD) +" below</b> the average low rate."
		   } 
       else if (LD > 0) {
         LDtd.innerHTML = "$"+LD
         LDtext = "The <b>low rate</b> is <b>$"+ LD +" above</b> the average low rate."
       } 
       else {
         LDtd.innerHTML = "$"+LD
         LDtext = "The <b>low rate</b> is <b>equal</b> to the average low rate."
       }
		   if (HD < 0) {
		     HDtd.innerHTML = "-$"+Math.abs(HD)
		     HDtext = "The <b>high rate</b> is <b>$"+ Math.abs(HD) +" below</b> the average high rate."
		   }
       else if (HD > 0) {
         HDtd.innerHTML = "$"+HD
		     HDtext = "The <b>high rate</b> is <b>$"+ HD +" above</b> the average high rate."
		   }
       else {
         HDtd.innerHTML = "$"+HD
         LDtext = "The <b>high rate</b> is <b>equal</b> to the average high rate."
       }
       ReqD.innerHTML = "For the dates <b>" + inMon + "/" + inDay + "</b> to <b>" + outMon + "/" + outDay + "</b>" 
       Difft.innerHTML = LDtext + "<br>" + HDtext
     }
     RateCapture()
    }
   }
  }
  xmlhttp.send (null)
	setTimeout("RateCapture()",5000)
 }
 
 
 function Clear() {
   xmlhttp.abort()
   xmlhttp = null;
 }


 