/**
 * Javascript ajax.js
 * 
 * 
 * @todo look into jquery replacement, cake doesn't seem to like it though.
 * @author Pontus Sahlberg <pontus.sahlberg@gmail.com>
 * @package intranet
 */

/**
 * Creates a XMLHttpRequest
 * 
 * Creates a XMLHttpRequest, unless the user lives under a rock and uses
 * Internet Explorer, in that case we return an ActiveXObject which
 * provides the same functionality.
 * This gives us basic AJAX support.
 * 
 */
function getXMLHttpRequest(){
    var request;
    if (window.XMLHttpRequest){
        request = new XMLHttpRequest();
    }
    else{
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    return request;

}
/**
 * Fetch file by ajax
 * 
 * Just download file and put data in div
 * 
 * @param url The url to fetch
 * @param div The element in which to put the response
 */
function fetchByAjax(url,div){
    var ajax = getXMLHttpRequest();
    ajax.onreadystatechange=function(){
        if (ajax.readyState==4 && ajax.status==200){
            if(div != undefined)
                document.getElementById(div).innerHTML=ajax.responseText;
        }
    }
    ajax.open("GET",url,true);
    ajax.send();
}



