﻿ // JAVASCRIPT
 
function buildCalendar(aListingID, aDate)
{       
    
    if (aDate == null || aDate == "") {
        return; // *** Don't check unless there's something to do
    } else {
        // *** main processing block:
        
       //document.getElementById("ctl00_ContentPlaceHolder1_divCalendar").style.display = "none";
       document.getElementById("ctl00_ContentPlaceHolder1_plsWait").style.display = "inline";
       var data = "ListingID=" + aListingID + "&Month=" + aDate;     
       //alert(data);
    
       var xhttp;
       if (window.XMLHttpRequest) { // Mozilla, Safari, ...         
          xhttp = new XMLHttpRequest();
       } else if (window.ActiveXObject) { // IE
          xhttp = new ActiveXObject("Microsoft.XMLHTTP");
       }        

       try
       {
          xhttp.onreadystatechange = function() { helper(xhttp) };
          xhttp.open("POST", "wsUtilities.asmx/buildCalendar", true);
          xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          xhttp.setRequestHeader("Content-length", data.length)
          xhttp.send(data);
        } catch (err) {
          alert("Unable to access the URL.");
        }  
            
   } // IF NULL
    
} // FUNCTION

function helper(x) {  
    if (x.readyState==4) {
        //alert(x.status);
        if (x.status==200) {
            //alert(x.responseXML);
            var result = x.responseXML.documentElement.firstChild.data; // *** this works for SCALAR RETURNS
            //alert(result)
            document.getElementById("ctl00_ContentPlaceHolder1_plsWait").style.display = "none";
            document.getElementById("ctl00_ContentPlaceHolder1_divCalendar").innerHTML =  result;
            //document.getElementById("ctl00_ContentPlaceHolder1_divCalendar").style.display = "inline-block";
        }
    }
}
// -->
