var xhr=new Array();

function getXhr(name){
	if(window.XMLHttpRequest){
		xhr[name]=new XMLHttpRequest();
	}else if(window.ActiveXObject){
		try{
			xhr[name]=new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch(e){
			xhr[name]=new ActiveXObject('Microsoft.XMLHTTP');
		}
	}else{
		window.alert('Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre à jour');
		xhr[name]=false;
	} 
}

function ajax_check(xhr_object){
	xhr_object.onreadystatechange=function(){
		if(xhr_object.readyState==4&&xhr_object.status==200){
			eval(xhr_object.responseText);
		}
	}
}

function ajax_bloc(bloc,get,form){
	randomid=Math.random();
	request='dummy=1';
	if(form!=false){
		for(i=0;i<document.getElementById(form).length;i++){
			if(document.getElementById(form).elements[i].name!=''){
				text=escape(document.getElementById(form).elements[i].value);
				text=text.replace(/\+/g,'%2B');
				request+='&'+document.getElementById(form).elements[i].name+'='+text;
			}
		}
	}
	getXhr('loadbloc_'+randomid);
	ajax_check(xhr['loadbloc_'+randomid]);
	if(get==false){
		var get='';
	}else{
		get=get.replace(/\+/g,'%2B');
	}
	xhr['loadbloc_'+randomid].open('POST','ajax-'+bloc+'.html?'+get,true);
	xhr['loadbloc_'+randomid].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr['loadbloc_'+randomid].send(request);
	return(false);
}

function ajax_bloc_floride(bloc,get,form){
	randomid=Math.random();
	request='dummy=1';
	if(form!=false){
		for(i=0;i<document.getElementById(form).length;i++){
			if(document.getElementById(form).elements[i].name!=''){
				text=escape(document.getElementById(form).elements[i].value);
				text=text.replace(/\+/g,'%2B');
				request+='&'+document.getElementById(form).elements[i].name+'='+text;
			}
		}
	}
	getXhr('loadbloc_'+randomid);
	ajax_check(xhr['loadbloc_'+randomid]);
	if(get==false){
		var get='';
	}else{
		get=get.replace(/\+/g,'%2B');
	}
	xhr['loadbloc_'+randomid].open('POST','ajax-'+bloc+'.html?'+get,true);
	xhr['loadbloc_'+randomid].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr['loadbloc_'+randomid].send(request);
	return(false);
}

function test_ajax_bloc(bloc,get,form){
	randomid=Math.random();
	request='dummy=1';
	if(form!=false){
		for(i=0;i<document.getElementById(form).length;i++){
			if(document.getElementById(form).elements[i].name!=''){
				text=escape(document.getElementById(form).elements[i].value);
				text=text.replace(/\+/g,'%2B');
				request+='&'+document.getElementById(form).elements[i].name+'='+text;
			}
		}
	}
	getXhr('loadbloc_'+randomid);
	ajax_check(xhr['loadbloc_'+randomid]);
	if(get==false){
		var get='';
	}else{
		get=get.replace(/\+/g,'%2B');
	}
	xhr['loadbloc_'+randomid].open('POST','test_ajax-'+bloc+'.html?'+get,true);
	xhr['loadbloc_'+randomid].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr['loadbloc_'+randomid].send(request);
	return(false);
}

/**
Liste les biens neufs
*/
function ajax_bloc_biens_neufs(bloc,get,form){
	randomid=Math.random();
	request='dummy=1';
	if(form!=false){
		for(i=0;i<document.getElementById(form).length;i++){
			if(document.getElementById(form).elements[i].name!=''){
				text=escape(document.getElementById(form).elements[i].value);
				text=text.replace(/\+/g,'%2B');
				request+='&'+document.getElementById(form).elements[i].name+'='+text;
			}
		}
	}
	getXhr('loadbloc_'+randomid);
	ajax_check(xhr['loadbloc_'+randomid]);
	if(get==false){
		var get='';
	}else{
		get=get.replace(/\+/g,'%2B');
	}
	xhr['loadbloc_'+randomid].open('POST','ajax-'+bloc+'.html?'+get,true);
	xhr['loadbloc_'+randomid].setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr['loadbloc_'+randomid].send(request);
	return(false);
}
