$.fn.geoinsee_change = function(source,parent,cible,code_postal,ville){
	mpage='geoinsee_selecteur';
	p=$(this).parent();
	gp=p.parent();
	mid=$(this).val();
	if (mid) {
		gp.find('select.geoinsee_'+parent).removeClass('geoinsee').attr('name',gp.attr('class'));
		$(this).addClass('geoinsee').attr('name','geoinsee_1');	
	}
	else {
		gp.find('select.geoinsee_'+parent).addClass('geoinsee').attr('name','geoinsee_1');
		$(this).removeClass('geoinsee').attr('name',$(this).attr('class'));
	
	}
	if (cible){
		if (mid){
			p.find('div.geoinsee_'+cible).attr('id','geoinsee_cible');
			$.get("/spip.php",
				{page : mpage, geoinsee : mid, geoinsee_type : cible, code_postal : code_postal, ville : ville},
				function(txt){
					$('#geoinsee_cible').html(txt).attr('id','');
			});
		}
		else p.find('div.geoinsee_'+cible).html('');
	}
		
}
$.fn.geoinsee_populate = function(cp,ville){
	mid=$(this).val();
	moption=$(this).find('option[@value='+mid+']');
	mform=$(this).parent();
	while (mform && mform.get(0).tagName.toLowerCase()!='form')
		mform=mform.parent();
	if (cp) mform.find(cp).val(moption.attr('rel'));
	if (ville) mform.find(ville).val(moption.html());
	
}
$.fn.geoinsee_switch = function(cible,div,parent){
	mpage='geoinsee_selecteur_'+cible+'s';
	gp=$(this).parent().parent();
	gp.find(div).html('').attr('id','geoinsee_cible');
	p=gp.find('select[@name=geoinsee_1]');
	p.removeClass('geoinsee').attr('name',p.parent().attr('class'));
	mid=gp.find('select.geoinsee_'+parent+' option:selected').attr(cible);
	$.get("/spip.php",
				{page : mpage, geoinsee : mid, geoinsee_type : cible},
				function(txt){
					$('#geoinsee_cible').html(txt).attr('id','').find('select').attr('name','geoinsee_1');
				});
		
}
$.fn.geoinsee_unswitch = function(cible,vider){
	mpage='geoinsee_selecteur';
	gp=$(this).parent().parent();
	gp.find(vider).html('');	
	p=gp.find('select.geoinsee_'+cible);
	while(!p.val()) p=p.parent().parent().find('select');
	p.addClass('geoinsee').attr('name','geoinsee_1');
}
