ajax = {
	obj: false,
	url: '',
	init: function(){
			try {
			        this.obj = new XMLHttpRequest();
			}
			catch (trymicrosoft) {
				try {
				        this.obj = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (othermicrosoft) {
				        try {
					        this.obj = new ActiveXObject("Microsoft.XMLHTTP");
					} 
					catch (failed) {
					        ajax.obj = false;
					}
				}
			}
		},
	get: function(url_u){
		       if(!this.obj){
		                alert('Error initializing XMLHttpRequest!');
			        return false;
		        }
		        url = ajax.url;
		        //url = (url_u.length > 0)? url_u : (this.url.length > 0)? this.url : '' ;
		        //alert(url);
		        this.obj.open('GET',url,true);
		        this.obj.onreadystatechange = this.answer;
		        this.obj.send(null);
	},
	post: function(_form){
		       if(!this.obj){
		                alert('Error initializing XMLHttpRequest!');
			        return false;
		        }//alert(this.url);
		        data = this.splitForm(_form);//alert(data);		        
		        this.obj.open('POST',this.url,true);
		        this.obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		        this.obj.onreadystatechange = this.answer;
		        this.obj.send(data);
	},
	answer: function(){
		          if (ajax.obj.readyState == 4){
			        if (ajax.obj.status == 200){
			                if(ajax.obj.getResponseHeader('Content-Type') == 'text/xml'){
				                ajax.parseXML();
			                }
			                else{
			                        ajax.parseText();
			                }
			        }
	                        else if (ajax.obj.status == 404){}
	                        else{
	                                alert("Error: status code is " + ajax.obj.status);
	                                //alert("URL: " + ajax.url);
	                        }
	                  }
	                  _fit();// подогнали размер экрана
	},
	parseXML: function(){
			    if(this.obj.responseXML == null || this.obj.responseXML.documentElement == null){
			        try {
				        this.obj.responseXML.loadXML(this.obj.responseText)
				}
				catch(e){alert("Can't load");}
			    }
			    _xml = this.obj.responseXML.documentElement;
		            node_list = _xml.getElementsByTagName('error');
		            for(i=0; i<node_list.length; i++){
		                node = node_list.item(i);
				_text = node.text || node.textContent; //alert(_text);
				id = node.getAttribute('id');
				try{
				document.getElementById(id).innerHTML = _text;
				//document.getElementById(id).innerHTML = '';				
				}catch(e){}  //alert(_text);
			    }
			    _eval_list = _xml.getElementsByTagName('eval');
			    if(_eval_list.length > 0){
			        script = _eval_list.item(0).text || _eval_list.item(0).textContent;
			        try{eval(script);}catch(error){/*alert('AJAX: произошла ошибка eval'+"\n"+script.length);*/}
			    }
	},
	parseText: function(){
		             text = this.obj.responseText;
			     alert(text);
	},
	splitForm: function(_form){
	                var _param = new Array();
	                _input = _form.getElementsByTagName('input');
	                _textarea = _form.getElementsByTagName('textarea');
	                _select = _form.getElementsByTagName('select');
	                _li = _input.length;
	                _lt = _textarea.length;
	                _ls = _select.length;
	                for(i=0; i<_li; i++){
	                        if(_input.item(i).type != 'checkbox'){
	                                try{_el = encodeURIComponent(_input.item(i).name)+'='+encodeURIComponent(_input.item(i).value);}
	                                catch(e){}
	                                _param.push(_el);
	                        }
	                        else if(_input.item(i).type == 'checkbox' && _input.item(i).checked){//alert(_input.item(i).checked);
	                                try{_el = (_input.item(i).name)+'='+encodeURIComponent(_input.item(i).value);}
	                                catch(e){}
	                                _param.push(_el);
	                        }
	                }
	                for(i=0; i<_lt; i++){
	                        if(_textarea.item(i).value.length > 0){
	                                try{_el = encodeURIComponent(_textarea.item(i).name)+'='+encodeURIComponent(_textarea.item(i).value);}
	                                catch(_e){}
	                                _param.push(_el);
	                        }
	                }
	                for(i=0; i<_ls; i++){
	                        if(_select.item(i).value.length > 0){
	                                try{_el = encodeURIComponent(_select.item(i).name)+'='+encodeURIComponent(_select.item(i).value);}
	                                catch(_e){}
	                                _param.push(_el);
	                        }
	                }//alert(_param.join('&'));
	                //_param.push('ajax=true');
	                return _param.join('&');
	                
	}
}
ajax.init();

