function CreateRequestObject() {
     var myObject;
     var browser = navigator.appName;
     if(browser == "Microsoft Internet Explorer"){
          myObject = new ActiveXObject("Microsoft.XMLHTTP");
     }else{
          myObject = new XMLHttpRequest();
     }
     return myObject;
}
var HTTP = CreateRequestObject();

function SendRequest(Action, QueryString) {
     HTTP.open('get', BasePath + 'backend/action.php?action='+Action+'&'+QueryString);
     HTTP.onreadystatechange = HandleResponse;
     HTTP.send(null);
}

function HandleResponse() {
			// SPLIT AJAX STRING			
			if(HTTP.readyState == 4){
					var Response = new String(HTTP.responseText);
					var Update = new Array();
					
																													
					while(Response.indexOf('</ajax>') != -1){
						ProcessString = Response.substring(6, Response.indexOf('</ajax>')-1);
						ProcessString += ' ';
						
						SetID = null;
						SetAction = null;
						SetAttribute = null;
						SetContent = null;
						
						while(ProcessString.indexOf(' ') != -1){
							ProcessElement = ProcessString.substring(0, ProcessString.indexOf('='));
							ProcessValue = unescape(ProcessString.substring(ProcessString.indexOf('=')+2, ProcessString.indexOf(' ')-1));
								switch(ProcessElement){
									case "id":
										SetID = ProcessValue;
									break;
									case "action":
										SetAction = ProcessValue;
									break;
									case "attribute":
										SetAttribute = ProcessValue;
									break;
									case "content":
										SetValue = ProcessValue;
									break;
								}							
							ProcessString = ProcessString.substring(ProcessString.indexOf(' ')+1);
						}
						
						if(document.getElementById(SetID)){
							switch(SetAction){
								case "Write":
									document.getElementById(SetID).innerHTML = 	document.getElementById(SetID).innerHTML + DoReplace('+', ' ', SetValue);
								break;
								case "Replace":
									document.getElementById(SetID).innerHTML = 	SetValue;
								break;
								case "SetClass":
									document.getElementById(SetID).className = 	SetValue;
								break;
								case "SetAttribute":
								default:
									if(SetAttribute.length > 0){
										eval("document.getElementById('" + SetID + "')." + SetAttribute + "=" + SetValue);
									}
								break;
							}
							
						}
						
						Response = Response.substring(Response.indexOf('</ajax>')+7);						
					}
			}
}

function DoReplace(FindString, SetString, MyString){
		while(MyString.indexOf(FindString) != -1){
			MyString = MyString.substring(0, MyString.indexOf(FindString)) + SetString + MyString.substring(MyString.indexOf(FindString) + FindString.length);
		}
		return MyString;
}
