// Based on: 
// http://programmerassist.com/article/340

function SimpleAjax(action, params)
{
    //
    // Set PHP ajax URL.
    //
    //
    var url = (JS_IS_LOCALHOST) ?
        'http://localhost/ipaper/html/ips/site/ronen/ajax.php?action='+action+'&params='+params+'&sid='+siteId :
        //siteUrl+'/12512/ajax.php?action='+action+'&params='+params+'&sid='+siteId;
        '/ajax.php?action='+action+'&params='+params+'&sid='+siteId;
    //var url = 'http://localhost/ipaper/html/ips/mod/cat/ajax.php?action='+action+'&params='+params+'&sid='+siteId;
        
    //
    // Add / Delete 'www' from PHP agax URL, according to 
    // the appearance of 'www' in document location.
    //
    // This is because at FF, http://www.<domain> and
    // http://<domain>, are considered foreign domains
    // to each other.
    //
    if (document.location.toString().match(/www./))
    {
        if (!url.match(/www./))
        {
            url = url.replace("http://","http://www.");
        }
    }
    
    else
    {
        url = url.replace("http://www.","http://");
    }
    
    
    //
    // Initialze http-request.
    //
    var http_request = false;

    //
    // Case Mozilla, Safari,... 
    //
    if (window.XMLHttpRequest)
    {
        http_request = new XMLHttpRequest();

        if (http_request.overrideMimeType)
        {
            http_request.overrideMimeType('text/xml');
        }
    
    } 

    //
    // Case IE
    //
    else if (window.ActiveXObject)
    {
        try
        {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        
        catch (e)
        {
            try
            {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
    }

    //
    // Case error - cannot creat ajax instance.
    //
    if (!http_request)
    {
        alert('Giving up: Cannot create an XMLHTTP instance');
        return false;
    }

    //
    // Send the request.
    //
    http_request.onreadystatechange = function() { EvalResponse(http_request, action, params); };
    http_request.open('GET', url, true);
    http_request.send(null);
    alert(url);
}


function EvalResponse(http_request, action, params)
{
    if (http_request.readyState == 4)
    {
        if (http_request.status == 200)
        {
            response = http_request.responseText;
            
            if (response != '')
            {
                eval(response);
            }
        }
        
        else
        {
            alert('There was a problem with the request.');
        }
    }
}
