function createAjax() {
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   try { return new XMLHttpRequest(); } catch(e) {}
   return null;
}

function createBody(a) {
	var p = [];
	for(var key in a) {
		p.push(key + '=' + a[key]);
	}
	return p.join('&');
}

function ajaxCall(url, postBody, onSuccess){
    var A = createAjax();
	var method = 'GET';
	
	if(postBody) {
		method = 'POST';
	}

	A.open(method, url, true);

	if(method == 'POST') {
		try {A.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');} catch(e){}; 
	}

    var onreadystatechange = function(async){
		
        if (A.readyState==4 || async) if(A.status == 200 || A.status == 304){
            if (typeof onSuccess == 'function') {
				var r = A.responseText.replace(/^\s+/, '').replace(/\s+$/, '');	
                onSuccess(r);
			}
        }
		//alert(99)
    };
    A.onreadystatechange = onreadystatechange;
    A.send(postBody ? createBody(postBody) : null);
}
function ajaxLoad(url, elm) {
	
    var elm = typeof elm == 'string' ? document.getElementById(elm):elm;
    ajaxCall(url, null, function(d) {
		try {
			 evalResponse(d);
			 elm.innerHTML = d;
	//		 alert(elm.innerHTML);
		}catch(e){ return false; }
    });
	
}

function ajaxPost(url, body, elm) {
	var elm = typeof elm == 'string' ? document.getElementById(elm):elm;
	ajaxCall(url, body, function(d) {
		try {
			 evalResponse(d);
			 elm.innerHTML = d;
	//		 alert(elm.innerHTML);
		}catch(e){ return false; }						  
	});
}

function evalResponse(text){
    try {
    var script, scripts = [];
    var regexp = /<script[^>]*>([\s\S]*?)<\/script>/gi;
    while ((script = regexp.exec(text))) scripts.push(script[1]);
    scripts = scripts.join('\n');
    if (scripts) (window.execScript) ? window.execScript(scripts) : window.setTimeout(scripts, 0);
    } catch(e){}
}
