/*## MicroAJAX 1.1 (29.05.2007) ##*/

/*# HTTP Request Object Creator #*/
function create_connector(){
var http_conn=false;

if(window.XMLHttpRequest){
http_conn=new XMLHttpRequest();
if(http_conn.overrideMimeType){
http_conn.overrideMimeType('text/plain');
}
}
else if(window.ActiveXObject){
try{
http_conn=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{
http_conn=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}

if(!http_conn){
alert("Ajax Error: Cannot create XMLHTTP instance!");
return false;
}

return http_conn;
}


/*## HTTP request sender ##*/
function send_request(url,args){
http=create_connector();
if(http){
http.onreadystatechange=function(){ manage_response(http); };
http.open('GET',url+"?"+args,true);
http.send(null);
}
else{
alert("Ajax Error: No http connection.");
}
return;
}

/*## HTTP request sender ##*/
function send_post_request(url,args){
http=create_connector();
if(http){
http.onreadystatechange=function(){ manage_response(http); };
http.open('POST',url,true);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
http.send(args);
}
else{
alert("Ajax Error: No http connection.");
}
return true;
}


/*## HTTP request output manager ##*/
function manage_response(http){
if(http.readyState==4){
if(http.status==200){
var res_txt=http.responseText;

if(res_txt=="refresh"){
if(window.document.location.href.indexOf("?")!=-1){
window.document.location.href=window.document.location.href.substring(0,window.document.location.href.indexOf("?"));
}
else{
window.document.location.reload();
}

}
else if(res_txt=="refresh_this"){
window.document.location.reload();
}
else if(res_txt.indexOf("alert@")!=-1){
alert(res_txt.replace("alert@",""));
}
else if(res_txt.indexOf("exec@")!=-1){
eval(res_txt.replace("exec@",""));
}
else if(res_txt!="true"){
alert("Ajax Error: PHP function call failed.\n"+res_txt);
return false;
}
}
else{
alert("Ajax Error: Request error.");
}
}
return true;
}


/*## HTTP XHTML request sender ##*/
function send_xhtml_request(url,args,xhtml_cref){
http=create_connector();
if(http){
http.onreadystatechange=function(){ write_down_xhtml(http,xhtml_cref); };
http.open('POST',url,true);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
http.send(args);
}
else{
alert("Ajax Error: No http connection.");
}
return true;
}


/*## HTTP XHTML request printer ##*/
function write_down_xhtml(http,xhtml_cref){
if(http.readyState==4){
if(http.status==200){
var res_txt=http.responseText;

xhtml_cref.innerHTML=res_txt;
}
else{
alert("Ajax Error: Request error.");
}
}
return true;
}