function wipeSetup(elTriggerId, elCibleId) {
	
	if(dojo.byId(elCibleId).style.display == 'none'){
		dojo.style(elCibleId, "display", "none");
		var wipeArgs = {
		    node: elCibleId
		};
		dojo.fx.wipeIn(wipeArgs).play();
	} else {
		 dojo.style(elCibleId, "height", "");
         dojo.style(elCibleId, "display", "block");
         var wipeArgs = {
             node: elCibleId
         };
         dojo.fx.wipeOut(wipeArgs).play();
	}
}

/*FONCTIONS GOOGLE MAP*/
var geocoder;
var map;
var markerArray = new Array;

function initializeMap(concessTab, site_acronym, url, selectedArea) {
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(47,2.333);
	var aZoom = 5;
	if(dojo.byId('zipcodeMap').value != "") aZoom = 10;
	var myOptions = {
		zoom: aZoom,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	if(document.getElementById('zipcodeMap').value != "") {
		codeAddress(dojo.byId('zipcodeMap').value, document.getElementById('countryMap').value, concessTab, site_acronym, url, selectedArea);
	}
}

function codeAddress(address, country, concessTab, site_acronym, url, selectedArea) {
	if (geocoder) {
		geocoder.geocode( { 'address': address + " " + country}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				map.setCenter(results[0].geometry.location);
				var marker = new google.maps.Marker({
					map: map,
					position: results[0].geometry.location,
					title:'Votre commune'
				});
				
				for (index in concessTab){
					var marker = makeMarker(concessTab[index], site_acronym, url, selectedArea);
				}
				//console.dir(markerArray);
				var markerCluster = new MarkerClusterer(map, markerArray,{gridSize:50, maxZoom:9});
				
			} else {
				alert("Geocode was not successful for the following reason: " + status);
			}
		});
	}
}


function makeMarker(concessElt, site_acronym, url, selectedArea) {
	
	var myMarkerImage 	= new google.maps.MarkerImage('/public/images/'+ site_acronym +'/marker.png');

	var concessionId	= concessElt[0];
	var concession		= concessElt[1];
	var civilite 		= concessElt[2];
	var nom 			= concessElt[3];
	var prenom			= concessElt[4];
	var adresse 		= concessElt[5];
	var adresse2 		= concessElt[6];
	var zipcode		 	= concessElt[7];
	var ville	 		= concessElt[8];
	var telephone 		= concessElt[9];
	var fax 			= concessElt[10];
	var email 			= concessElt[11];
	var latitude 		= concessElt[12];
	var longitude 		= concessElt[13];
	var aTitle			= concession +" - Cliquez pour en savoir plus";
	
	var departement		= zipcode.substring(0,2);
	var area			= selectedArea.toString().substring(0,2);
	
	if(area == departement){
		var aContent		= "<b><a href='" + url + "#"+ concessionId +"'>" + concession + "</a></b><br/>" + adresse + " " + adresse2 + "<br/>" + civilite + " "+ prenom +" "+ nom +"<br/>" + zipcode + " " + ville + "<br/><u>Tel.</u> " + telephone+"<br/><u>Fax</u> " + fax + "<br/><u>Mail</u> " + email;
	}else{
		var aContent		= "<b>" + concession + "</b><br/>" + adresse + " " + adresse2 + "<br/>" + civilite + " "+ prenom +" "+ nom +"<br/>" + zipcode + " " + ville + "<br/><u>Tel.</u> " + telephone+"<br/><u>Fax</u> " + fax + "<br/><u>Mail</u> " + email;
	}
	var options 		= {
			position: new google.maps.LatLng(latitude, longitude),
			title: aTitle,
			content:aContent,
			icon: myMarkerImage
		};
	
	var infoWindow 	= new google.maps.InfoWindow(options);
	var marker		= new google.maps.Marker({map:map});
	marker.setOptions(options);
	
	google.maps.event.addListener(marker, "click",function(){
		//console.log("aContent "+aContent);
		infoWindow.open(map, marker);
	});
	
	markerArray.push(marker);
	return marker;
}

function geocode(address, obj_la, obj_lo){
	geocoder = new google.maps.Geocoder();
	geocoder.geocode( { 'address': address}, function(results, status){
		if (status == google.maps.GeocoderStatus.OK){
			obj_la.value = results[0].geometry.location.lat();
			obj_lo.value = results[0].geometry.location.lng();
		}else if(status == google.maps.GeocoderStatus.ZERO_RESULTS){
			//alert("Geocode was not successful for the following reason: " + status);
			obj_la.value = "-1";
			obj_lo.value = "-1";
		}else if(status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT){
			//alert("Geocode was not successful for the following reason: " + status);
			obj_la.value = "0";
			obj_lo.value = "0";
		}
	});
}
