﻿// Load content using XMLHttpRequest
//
// Parameters:
//        url            - source to load
//        callback        - callback function when source is loaded
//        e_callback    - callback if error (null is default)
//
function loadContent(url, callback, e_callback) {
    xmlhttp=null;
    if (window.XMLHttpRequest) {
        // For all new browsers
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // For IE5 and IE6
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlhttp != null) {
        xmlhttp.onreadystatechange=function() {
            if (xmlhttp.readyState==4) {
                if (xmlhttp.status == 200) {
                    callback(xmlhttp);
                } else {
                    e_callback(xmlhttp);
                }
            }
        }
        try {
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
            return true;
        }
        catch (e) {
            e_callback(xmlhttp);
            return false;
        }
    }
    else {        
        return false;
    }
}

