var myFRRequest = getXMLHttpRequest();

function getXMLHttpRequest() 
{
    //var activeXVersions = ["Msxml2.DOMDocument.6.0","Msxml2.DOMDocument.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
    var activeXVersions = ["Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
	try {
		return new XMLHttpRequest;
	} catch (e) {
		for (var i=0; i < activeXVersions.length; i++) {
			try {
				return new ActiveXObject(activeXVersions[i]);
			} catch (e) {}
		}
	}
	return null;
}

function calljax(url,method,data,callBack) {
	// Assign default values if not passed
	var method = (method == null) ? "GET" : method; // Default method
	var data = (data == null) ? '' : data;  // Default POST data
	var callBack = (callBack == null) ? handleAjaxResponse : callBack; //Default callBack function
	
	// Cache breaker
	var myRandom= parseInt(Math.random()*99999999);
	if (url.indexOf('?') == -1) {
		var rUrl = url + '?rand=' + myRandom;
	} else {
		var rUrl = url + '&rand=' + myRandom;
	}
	
	myFRRequest.open(method, rUrl, true);
	// Set the content type in the POST request 
	if (method == 'POST') {
		myFRRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	}
	myFRRequest.onreadystatechange  = callBack;
	myFRRequest.send(data);
}

function detach(ref) {
    var att = ref.attributes, i, l, n;
    if (att) {
        l = att.length;
        for (i = 0; i < l; i += 1) {
            n = att[i].name;
            if (typeof ref[n] === 'function') {
                ref[n] = null;
            }
        }
    }
    att = ref.childNodes;
    if (att) {
        l = att.length;
        for (i = 0; i < l; i += 1) {
            detach(ref.childNodes[i]);
        }
    }
}

//  Default callback handler
function handleAjaxResponse() {
	try {
		console.debug('readyState=' + myFRRequest.readyState);
	} catch (err) {}
	if (myFRRequest.readyState == 4) {
		if (myFRRequest.status == 200) {
			alert('Server response: ' + myFRRequest.responseText);
		} else {
			alert ('An error occurred: ' + myFRRequest.statusText);
		}
	}
}
