// -------------------------------------------------------------------
// RSS News - News anywhere in HTML via AJAX and ASP.NET
// Author: Hong Gyu Han added ASP.NET support
// First revision  : 2008/5/30
// -------------------------------------------------------------------

// Path to aspx page retrieving rss site
var strURL="News.aspx"

// Store the divid and get news
function rssNews(divid)
{
    // store divid for rss news items
    this.divid=divid;
 
    // get news feed
    this.xmlhttpPost(strURL)
}

// Ajax Request to a URL
function xmlhttpPost(strURL) {
    // init xmlHttpReq
    var xmlHttpReq = false;
    // need to use a self variable since callback function doesn't recognize this
    var self = this;
    // Mozilla/Safari/IE7
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE6 or lower
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    // set parameters for the URL
    var params = "count=7&length=40"    
    // open Ajax request with POST and URL
    self.xmlHttpReq.open('POST', strURL, true);
    // set the request header
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    // set parameter length
    self.xmlHttpReq.setRequestHeader("Content-length", params.length);
    self.xmlHttpReq.setRequestHeader("Connection", "close");

    // set the callback function when the request completes 
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {  // if the request completed
            rssDisplay(self.xmlHttpReq.responseText); 
        }
    }
    // Send Request 
    self.xmlHttpReq.send(params);
}

// Replace the body of the div we placed in the beginning 
function rssDisplay(response)
{
    // debug
    // alert(this.divid);
    // alert(document.getElementById(this.divid));
    document.getElementById(this.divid).innerHTML=response;
}


