/**
* @version      $Id: rss_checker.js
* @package      My RSS Reader Scrolling News
* @copyright    Copyright (C) 2009 FalsinSoft. All rights reserved.
* @license      GNU/GPL
* @website      http://www.falsinsoft.co.nr
* @email        falsinsoft@gmail.com
* 
*/

function MyRSSReaderScrollingNewsChecker()
{
	this.RSSList = null;
	this.RootPath = "";
	this.MaxFeeds = 10;
	this.MaxErrors = 3;
	this.HttpReq = null;
	this.RSSIdx = 0;
	this.CallbackCheckFunc = null;
};

MyRSSReaderScrollingNewsChecker.prototype.CreateXmlHttpReq = function() 
{
	if(this.HttpReq != null) return;
	
    if(window.XMLHttpRequest) 
    {
        this.HttpReq = new XMLHttpRequest();
    } 
    else if(window.ActiveXObject) 
    {
        try 
        {
            this.HttpReq = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch(e) 
        {
            try 
            {
                this.HttpReq = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch(e) 
            {
                this.HttpReq = null;
            }
        }
    }
};

MyRSSReaderScrollingNewsChecker.prototype.CheckNextRSSFeeds = function()
{
	if(this.HttpReq.readyState == 4) 
    {
        if(this.HttpReq.status == 200)
        {
			this.RSSIdx++;
			
			if(this.RSSIdx < this.RSSList.length)
			{
				var CheckerURL = this.RootPath+"components/com_myrssreader/js/rss_checker.php";
				
				this.HttpReq.onreadystatechange = this.CallbackCheckFunc;
				
				CheckerURL += "?id="+escape(this.RSSList[this.RSSIdx]);
				CheckerURL += "&maxfeeds="+escape(this.MaxFeeds);
				CheckerURL += "&maxerrors="+escape(this.MaxErrors);
				CheckerURL += "&rand="+escape(Math.random());
				
				this.HttpReq.open("GET", CheckerURL, true);
				this.HttpReq.send(null);
			}
		}
	}
}

MyRSSReaderScrollingNewsChecker.prototype.CheckRSSFeeds = function()
{
	var CheckerURL = this.RootPath+"components/com_myrssreader/js/rss_checker.php";
	
	if(this.CallbackCheckFunc == null || this.RSSList == null || this.RSSList.length == 0) return;
	
	this.CreateXmlHttpReq();

	this.HttpReq.onreadystatechange = this.CallbackCheckFunc;

	CheckerURL += "?id="+escape(this.RSSList[0]);
	CheckerURL += "&maxfeeds="+escape(this.MaxFeeds);
	CheckerURL += "&maxerrors="+escape(this.MaxErrors);
	CheckerURL += "&rand="+escape(Math.random());
	
	this.RSSIdx = 0;
	
	this.HttpReq.open("GET", CheckerURL, true);
	this.HttpReq.send(null);
}
