var dealerlocator = Class.create({
	initialize: function() {
		this.country=null;
		this.region=null;
		this.department=null;
		this.order="ASC";
		this.orderby="name";
		this.idlist=idlist;
		this.loader=0;
	},
	setCountry:function(country){
		this.country=country;
		this.region=null;
		this.department=null;
		this.order="ASC";
		this.orderby="name";
		this.setRegion(0);
		new Ajax.Request('trouverproduits_select.php', {
		  method: 'post',
		  parameters:{action:'getregion',country:this.country,idlist:this.idlist},
		  onSuccess:this.updateRegion.bind(this)
		});
	},
	setRegion:function(region){
		this.region=region;
		this.department=null;
		this.order="ASC";
		this.orderby="name";
		new Ajax.Request('trouverproduits_select.php', {
		  method: 'post',
		  parameters:{action:'getdept',country:this.country,region:this.region,idlist:this.idlist},
		  onSuccess:this.updateDepartment.bind(this)
		});
	},
	setDepartment:function(department){
		this.department=department;
		this.updateContent();
	},
	setOrderby:function(orderby){
		if(orderby==this.orderby){
			this.order= (this.order=='ASC') ? 'DESC' : 'ASC';
		}else{
			this.order='ASC';
		}
		this.orderby=orderby;
		this.updateContent();
	},
	updateRegion:function(e){
		$('regions').update(e.responseText);
		this.updateContent();
	},
	updateDepartment:function(e){
		$('departements').update(e.responseText);
		this.updateContent();
	},
	updateContent:function(){
		if(this.loader==0)
		{
			$('loader').style.display='inline';
		}
		this.loader++;
		if($('rech_geo').visible())
			$('rech_geo').hide();

		var myObj={};
		myObj.country=this.country;
		myObj.order=this.order;
		myObj.orderby=this.orderby;
		myObj.idlist=this.idlist
		if(this.region!=null && this.region!=0)
			myObj.region=this.region;
		if(this.department!=null && this.department!=0)
			myObj.department=this.department;
		new Ajax.Request('trouverproduits_items.php', {
		  method: 'post',
		  parameters:myObj,
		  onSuccess:this.displayContent.bind(this)
		});
	},
	displayContent:function(e){
		$('products-list').update(e.responseText);
		this.loader--;
		if(this.loader==0)
		{
			$('loader').style.display='none';
		}
	},
	displaydetail:function(id){
		centerDivDetail(id);
		new Ajax.Request('trouverproduits_detail.php', {
		  method: 'post',
		  parameters:{id:id,idlist:this.idlist},
		  onSuccess:this.displaydetailres.bind(this)
		});

	},
	displaydetailres:function(e){

		$('find-detail-content').update(e.responseText);
		$('find-detail').show();
	},
	hidedetail:function(){
		$('find-detail').hide();
	}

});