function ajaxProcess()
{
	//this.onComplete = false;
	this.comName = false;
	this.func = false;
	
	this.loadingFunction = function(){};
	this.doneLoadingFunction = function(){};
	
	
	
	this.$ = function(sId) {
		
		if (!sId) {
			return null;
		}
		var returnObj = document.getElementById(sId);
		if (!returnObj && document.all) {
			returnObj = document.all[sId];
		}
		
		return returnObj;
	}
	
	this.processResponse = function(responseTxt){

		//alert( responseTxt );
		var result = eval( responseTxt );

		for(var i=0; i<result.length;i++){
		
			var cmd 		= result[i][0];
			var id			= result[i][1];
			var property 	= result[i][2];
			var data 		= result[i][3];

			var objElement = this.$(id);
						
			switch(cmd){
				case 'as':
					if(objElement){
						eval("objElement."+property+"=  data \; ");
					}
					break;
					
				case 'ap':
					if(objElement){
						$(objElement).append(data);
					}
					break;
					
				case 'al':
					if(data){
						alert(data);
					}
					break;
				
				case 'ce':
					this.create(id, property, data);
					break;
					
				case 'rm':
					if(property){
						$('#'+id).fadeOut(property, function() {$(this).remove()});
					} else {
						$('#'+id).remove();
					}
					break;
					
				case 'cs':
					var scr = id + '(';
					if($.isArray(data)){
						scr += '(data[0])';
						for (var l=1; l<data.length; l++) {
							scr += ',(data['+l+'])';
						}
					} else {
						scr += 'data';
					}
					scr += ');';
					eval(scr);
					break;
				
				default:
					alert("Unknow action: " + cmd);
			}
		}
		
		delete responseTxt;
	}
	
	
	this.call = function(comName, func, vars, id){
		
	

		var ap_url = '/ajaxprocess.php';
		var postData = "";
		if(arguments.length > 2){
			postData = arguments[2];
			
		}
		
		ap.loadingFunction(id);
		
		$.ajax({
			type: "POST",
			url: ap_url + '?mod=' +comName+ '&do=' +func,
			
			data: postData,
			
			//dataType: "html",

			success: function(res, status){
			
				if(res){
					if (id == 5) {
						return res;
					}
					else 
						ap.processResponse(res);
				}
			},
			
			complete: function() {
				ap.doneLoadingFunction(id);
			}
			
		});
	}
	
	this.create = function(sParentId, sTag, sId){
		var objParent = this.$(sParentId);
		objElement = document.createElement(sTag);
		objElement.setAttribute('id',sId);
		if (objParent){
			objParent.appendChild(objElement);}
	}
	

}

var ap = new ajaxProcess();
