// JS framework by ABTOMAT
// ver. 0.1

var FW_OSEL = 0;
var FW_OTHBR = 1;

function FWRequest()
{ 
  if (typeof window.ActiveXObject != 'undefined' )
  {
    this.HTTPRObj = new ActiveXObject("Microsoft.XMLHTTP");
    this.type = FW_OSEL;
  }
  else
  {
    this.HTTPRObj = new XMLHttpRequest();
    this.type = FW_OTHBR;
  }
}

FWRequest.prototype.setOnload = function(funcname)
{
    switch(this.type)
    {
        case FW_OSEL:
        {
            this.HTTPRObj.onreadystatechange = funcname;
        }
        case FW_OTHBR:
        {
            this.HTTPRObj.onload = funcname;
        }
    }
}

FWRequest.prototype.open = function(method, URL, async, user, password)
{
    this.HTTPRObj.open(method, URL, async, user, password);
}

FWRequest.prototype.send = function(data)
{
    this.HTTPRObj.send(data);
}

FWRequest.prototype.getResponseText = function()
{
    return (this.HTTPRObj.responseText);
}

FWRequest.prototype.getResponseJSON = function()
{
    return eval("("+this.HTTPRObj.responseText+")");
}

FWRequest.prototype.getResponseXML = function()
{
    return (this.HTTPRObj.responseXML);
}

FWRequest.prototype.getStatus = function()
{
    return (this.HTTPRObj.status);
}

FWRequest.prototype.getReadyState = function()
{
    return (this.HTTPRObj.readyState);
}

FWRequest.prototype.get = function(url, data, onloadfunc)
{
    switch(this.type)
    {
        case FW_OSEL:
        {
            this.HTTPRObj.onreadystatechange = onloadfunc;
        }
        case FW_OTHBR:
        {
            this.HTTPRObj.onload = onloadfunc;
        }
    }
    this.HTTPRObj.open("GET", url, true);
    this.HTTPRObj.send(data);
}

// LOOPER

function FWLooper()
{
    this.startDelay = 5000;
    this.interval = 1000;
}

FWLooper.prototype.setFunction = function(func)
{
    this.func = func;
}

FWLooper.prototype.setIntervalDelay = function(value)
{
    this.interval = value;
}

FWLooper.prototype.setStartDelay = function(value)
{
    this.startDelay = value;
}

FWLooper.prototype.start = function()
{
    if(this.timeoutId!=undefined) clearTimeout(this.timeoutId);
    this.actAllowed = 1;

    //this.timeoutId = setTimeout(function(looper){alert(this);looper.act()}, this.startDelay, this);
    this.timeoutId = setTimeout(function(looper)
            {
                return function(){looper.act(); return false;}
            }(this), this.startDelay)
}

FWLooper.prototype.act = function()
{
    var looper = this;
    if(this.actAllowed)
    {
        this.func();
        if(this.timeoutId!=undefined) clearTimeout(this.timeoutId);
        this.timeoutId = setTimeout(function(looper){looper.act()}, this.interval, this);
    }
}

FWLooper.prototype.stop = function()
{
    if(this.timeoutId!=undefined) clearTimeout(this.timeoutId);
    this.actAllowed = 0;
}
