var newMarker = "";
function addPoint2Map(type,lng,lat,xtype,id){
	opal.map.clearOverlays();
	PdMarkerCloseAll();
	
   var Addicon = new GIcon();

   Addicon.image = (type == "member") ? cpath+"gfx/maps/icons/logpone.png" : cpath+"gfx/maps/icons/023+.gif";
   Addicon.iconSize = new GSize(22, 40);
   Addicon.iconAnchor = new GPoint(10, 40);
   Addicon.infoWindowAnchor = new GPoint(5, 1);
   	
	point = (lng && lat) ? new GPoint(lng,lat) : opal.map.getCenter();
	SwapGeoLabel(point);
	
	newMarker = new PdMarker(point,Addicon);
	var tip = "";
	var html = "";
	switch(type)
	{
		case "theme" : 
			tip = "Your new Point,<br/> Click to add information.<br/> Click anywhere on Map to move it";
			//TODO : build this list dynamicaly from opal_theme table 
			html = '<select onchange="OpenFormbyType(this.value);"><option>Select a type for this point</option><option  value="mapsform.php?">Custom Map</option><option  value="lifepointsform.php?">Life Point</option><option  value="friendsform.php?">People</option><option  value="lifepointsform.php?section=form&amp;type=travel">Travel-Trip</option><option  value="lifepointsform.php?section=form&amp;type=photo">Photograph</option><option  value="lodgingsform.php?">Lodging</option><option  value="eventsform.php?">Events</option><option  value="sciencedataform.php?">Science Data</option><option  value="lifepointsform.php?section=form&amp;type=monument">Monument</option><option  value="lifepointsform.php?section=form&amp;type=spot">Spot</option></select>';
			break;
		case "custom" : 
			tip = "Pin point a new location.";
			html = '<a href="javascript:PdMarkerCloseAll(); savePinPos(\'CustomReferentialInsert\',\''+xtype+'\','+id+',newMarker.getPoint().x,newMarker.getPoint().y); getMarkerByType(\'custom\',true);" class="menugreentxt">Save this Location</a>';
			break;	
		default : //member
			tip = "Please pin point precisly your location.";
			html = '<select onchange="OpenFormbyType(this.value);"><option>What type of user :</option><option value="new_member.php?type=individual">Individual</option><option value="new_member.php?type=company">Company</option><option value="new_member.php?type=webdataprovider">WebSite</option><option value="new_member.php?type=tourismoffice">Tourism Office</option><option value="new_member.php?type=eventorganiser">Event Organiser</option></select>'; 
			break; 
	}
    newMarker.setTooltip(tip);
    newMarker.setDetailWinHTML(html);
    opal.map.addOverlay(newMarker);
}

function OpenFormbyType(path){
	var pos=newMarker.getPoint();
	var lat = pos.y;
	var lng = pos.x;
	window.location=cpath+"pages/private/user/"+path+"&section=form&lat="+lat+"&lon="+lng+"&country="+active_country+"&z="+opal.map.getZoom();
}
