temp_caller = null;
function ajax_caller(url, form) {
	
	switch(typeof form){
	case "undefined":
		oform = false;
		break;
	
	case "object":
		oform = form;
		break;
		
	case "string" :
		if(typeof document.forms[form] == "object"){
			oform = document.forms[form];
		}else{
			oform =  document.getElementById(form);
		}
		break;	
	}
	
	
	
	
	
	temp = new Object();
	temp = {
			s_url : url,
			o_form : oform,
			funct_def : null,
			oReq : new HttpRequest(),
			tempArray : new Array(),
			
			addParam : function (name, value) {
				this.oReq.addParam(name, value);
			},
			
			get : function (funct){
				this.__prepare_request(funct);
				this.oReq.get(this.__return_function_overdrive);
			},
			
			post : function (funct){
				this.__prepare_request(funct);
				this.oReq.post(this.__return_function_overdrive);
			},
			
			//private
			__prepare_request : function (funct) {
				this.__take_form_values();
				temp_caller = this;
				this.__lock_form();
				this.funct_def = funct;
				this.oReq.setURL(this.s_url);
			},			
			
			__take_form_values : function (){
				if(this.o_form){
					
					for(i=0; i < this.o_form.elements.length; i++){
						this.oReq.addParam(this.o_form.elements[i].name, this.o_form.elements[i].value);
					}
				
				}
				
			},
			
			__return_function_overdrive : function (text) {
			//	alert(typeof temp_caller);
			//	alert(typeof temp_caller.__unlock_form);
				temp_caller.__unlock_form();
			//	alert(typeof temp_caller.function_def);
				temp_caller.__call_tmp_funct(text);
				
			},
			
			__lock_form : function () {
				if(this.o_form){
					
					for(i=0; i < this.o_form.elements.length; i++){
						//this.oReq.addParam(oForm.elements[i].name, oForm.elements[i].value);
						if(this.o_form.elements[i].nodeName == "SELECT"){
							this.tempArray[i] = this.o_form.elements[i].options[this.o_form.elements[i].selectedIndex].innerHTML;
							this.o_form.elements[i].options[this.o_form.elements[i].selectedIndex].innerHTML = "Ładuję...";
						}else if(this.o_form.elements[i].type == "text"){
							this.tempArray[i] = this.o_form.elements[i].value;
							this.o_form.elements[i].value = "Ładuję...";
						}
						this.o_form.elements[i].disabled = true;
					}
				
				}
				
			},
			
			__unlock_form : function () {
				if(this.o_form){
					
					for(i=0; i < this.o_form.elements.length; i++){
						
						if(this.o_form.elements[i].nodeName == "SELECT"){
							this.o_form.elements[i].options[this.o_form.elements[i].selectedIndex].innerHTML = this.tempArray[i];
						}else if(this.o_form.elements[i].type == "text"){
							this.o_form.elements[i].value = this.tempArray[i];
						}
						
						this.o_form.elements[i].disabled = false;
					}
				
				}
				
			},
			
			__call_tmp_funct : function (text){
				//test = temp_caller.funct_def;
				temp_caller.funct_def(text);
			}
	
	};
	
	return temp;
}
