
//dmain should be defined before this script
switch (dmain)
{
	case 'http://146.145.17.83':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhSxyZNWhkADlWX7gjmaCnpO0a3PIBRzlVLlfoFBeVqzfkCCneuwE4wEAA' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.airfrance-holidays.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhRRYbM37FSMom6vWKf2cFvhdvdnlxQ5fbf0O7ScdTL5Lj78htSjHrONSA' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.virgin-vacations.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTXfWYqaOZmVkbNjsx4lWBnk94z9RTJIgELR8zeKadrZ7-LUJa830nGVw' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.europeexpress.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhRWTSs81XH6oUUTyniztFhv21Wc5hQ0jIew9bqXA3Q0VjU7dSl05qR2Pw' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.europevacations.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhS2JOhqMtqzECeOXrUebYUYDJI8GhR1yeeJqGrjZCK51TEEbFZRY9gmhQ' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.go-today.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhRmhL_2lQ93Oa-BqtBOMfhW75EuUhTJCo_--LlOMWYgF5wzp1R-Q6V1Xg' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.bmit.com':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTYAeohulxAI8CtPjIVOU0xXkatGBSelymlDiS-If9j_Ilkr1QYKPmA7A' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://stage.travelse.co.uk':
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhQ-Ujf4IMZeUVdTWkfv4A8i_oPKYxR-SjrN6r-tzNfbc11LbkHLmQcAlQ' type='text/javascript'%3E%3C/script%3E"));
		break;
	//******* Production domain name ********//
	case 'http://www.airfrance-holidays.com':  
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTG2abDarpgOgEeq_apWZPpjPc4MRTWdSDHeGsFdhEI1bH4Y8eZXLKb9g' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.virgin-vacations.com':   
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTWnHces9sLs0AKBDzLlXHNa2ZVphQv___Ly0UObfbSF4gwBKC3kOnB_g' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.europeexpress.com':  
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTEncTTYCI0N9KEW7RLox69iWePKxTznzbNoHZTvR4uZOMTVOM01p0b9A' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.europevacations.com': 
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhQqMtjuoNC54euIowOLuCOt6uODghQCV7MW5NTatlVDMD2ttviB_FlOKQ' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.go-today.com':  
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTfIXRlIWkUfUALrXcSHIVgNKgUORR6DdfWxhkX9o9P8Gy8KI6isseACg' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.bmit.com':  
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhSqNCQKQodu1L8u1x-SMH1u4sLzrBQoaRVXIN1Qf9POszHbvXx_rIhTgQ' type='text/javascript'%3E%3C/script%3E"));
		break;
	case 'http://www.travelse.co.uk':  
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhQk_iEgq5jgJsTzvwyAPQfTNST0iRQv5wVtYb9F1P-H4KBU60tporDUjw' type='text/javascript'%3E%3C/script%3E"));
		break;
		
	default:
		document.write(unescape("%3Cscript src='http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=ABQIAAAAP5nC6JXpB26JWJSzvb0EyhTC03BwBj7M-nlsG9EXoVvPKnFagBRjUh2BYDPY6qoCTt6PmttUJ2kbkw' type='text/javascript'%3E%3C/script%3E"));
		break;
}

//<![CDATA[
var map; // = null;
var geocoder; // = null;
var point;
var polyline;

var NumOfMapMarked = 0;						// Map location sequence
var MapId				= 'map_container';	// Default div id for the map container
var defLat				= 0;				// Default Lat - this section is use to find the first point
var defLng				= 0;				// Default Lng - this section is use to find the first point
var lastLat				= 0;				// Use this if you are using the points.push class
var lastLng				= 0;				// This will set the travel line direction (i.e. for Itinerary)
var SetMapControl		= true;				// Set false to hide Map Control	
var SetOverviewControl	= true;				// Set false to hide Map Overview Control
var SetTypeControl		= true;				// Set false to hide Map Type Control
var EnableInfoWindow	= true;				// Set false to hide Map Info Window
var MapZoom				= 14;				// Set Map zoom default value; Zoom Range [0-20]; 
var MapAutoZoom			= false;			// Set true to auto zoom.
var MapAutoCenter		= false;			// Set true to auto center the map.
var MapBounds			= [];				// Set Map auto zoom;
var MapPoints			= [];				// Array used to draw the connecting lines
var MapLineColor		= "#0000FF"			// Map connecting lines color
var MapLineSize			= 3					// Map line thickness
var MapLineOpacity		= 0.75				// Map line opacity [0 - 1]
var IsCentered			= false;			// To check if map is already set to center.
var EnableScrollWheelZoom = true			// Mouse Scroll Wheel for zooming

//Below is used to get the Marker bounderies
var mapArrLat			= [];
var mapArrLng			= [];
var mapFarEast          = 0;				// Farthest East Latitude
var mapFarWest			= 0;				// Farthest West Latitude
var mapFarNorth			= 0;				// Farthest Nort Longtitude
var mapFarSouth			= 0;				// Farthest South Longtitude


//loadmap() - Function to load the map 
function loadmap() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById(MapId));
    MapBounds = new GLatLngBounds();	
    geocoder = new GClientGeocoder();
    showMap(); //Make sure showMap() is build in the template page
    if (EnableScrollWheelZoom){map.enableScrollWheelZoom();}
  }
  else {
    alert("Sorry, your browser is not compatible with Google Maps.");
  }
}

function isBrowserCompatible()
{
  if (GBrowserIsCompatible()) {
	map = new GMap2(document.getElementById("map"));
	geocoder = new GClientGeocoder();
	return true
  }
  else {
	return false
  }
}
function setMaxZoomCenter(map, latlng) 
{
	map.getCurrentMapType().getMaxZoomAtLatLng(latlng, function(response) 
	{
		if (response && response['status'] == G_GEO_SUCCESS) 
			{map.setCenter(latlng, response['zoom']);}
	}
	);
}

//DisplayMarkMap() - Function to display the specific Marker with InfoWindow Pop-up
//windowInfo - Element ID to be displayed on the Marker Window Pop-up
//Lat		 - Lattitude
//Lng        - Longtitude
function DisplayMarkMap(windowInfo,Lat,Lng)
{
	if (Lat!=0 && Lng!=0)
	{
		var point =  new GLatLng(Lat, Lng);
		var bounds = new GLatLngBounds();
		bounds.extend(point);
		map.panTo(bounds.getCenter());
		//map.setCenter(bounds.getCenter(), map.getZoom());	
		map.openInfoWindow(bounds.getCenter(),document.getElementById(windowInfo).innerHTML)
	}
	else {alert('Map not available');}
}

//Syntax: MarkMap(-26.2, 28.083, 0, 'idwindowInfo')
// Lat       : Lattitude  
// Lng       : Longtitude
// Pnts		 : Point of connections (connecting lines)
// windowInfo: Map pop-up information
function MarkMap(Lat,Lng, Pnts, windowInfo)
{
	try
	{
		if (Lat!=0 && Lng!=0)
		{	
			var point =  new GLatLng(Lat, Lng); 
			
			if (!IsCentered)
			{
				   if(SetMapControl){map.addControl(new GSmallMapControl());}
				   if(SetOverviewControl){map.addControl(new GOverviewMapControl());}
				   if(SetTypeControl){map.addControl(new GMapTypeControl());}
				   defLat=Lat;
				   defLng=Lng;
				   map.setCenter(point,MapZoom);    
				   IsCentered=true;
			}

		   var icon = new GIcon();
		   if (!document.getElementById('idMapMarkerPath')){var mrkPath='pics';}
		   else {var mrkPath=document.getElementById('idMapMarkerPath').value;}
		   
		   icon.image = mrkPath+'/MapPointer'+NumOfMapMarked+'.gif';
		   icon.shadow = mrkPath+'/MapPointerShadow.png';
		   icon.iconSize = new GSize(26, 31);
		   icon.shadowSize = new GSize(42, 31);
		   icon.iconAnchor = new GPoint(14, 30);
		   icon.infoWindowAnchor = new GPoint(10, 0);     

	//*** Please don't delete this section **
	//		opts = {
	//				  "icon": icon,
	//				  "clickable": true,
	//				  "labelClass":"mapLabel",
	//				  "labelText": NumOfMapMarked,
	//				  "labelOffset": new GSize(-12, -27)
	//				};
	//		var marker = new LabeledMarker(point, opts);
	
			var marker=  new GMarker(point,icon); 

			if (EnableInfoWindow)
			{
				if (!document.getElementById(windowInfo))
				{
					GEvent.addListener(marker, "click", function() {
    					marker.openInfoWindow(windowInfo)
					});		
				}
				else
				{
					GEvent.addListener(marker, "click", function() {
    					marker.openInfoWindow(document.getElementById(windowInfo).innerHTML)
					});
				}
			}
		   
		   map.addOverlay(marker);

		   if (Pnts>0) //This section is used to generate connecting lines. If this section is used, need to call MarkLines() after all location has been marked.
		   {
				MapPoints.push(new GLatLng(Lat, Lng));
		   }
		   setNSWE(Lat, Lng)
		   MapBounds.extend(new GLatLng(Lat, Lng));
		   
		}
	}
	catch (ex)
	{return true;}
}


//setNSWE() - Function to find the farthest location of the Markers.
// Lat       : Lattitude  
// Lng       : Longtitude
function setNSWE(Lat,Lng)
{
	if (mapFarNorth==0 && mapFarSouth==0 && mapFarEast==0 && mapFarWest==0)
	{
		mapFarNorth=Lat;
		mapFarSouth=Lat;
		mapFarEast=Lng
		mapFarWest=Lng;
	}
	else
	{
		if (Lat>=mapFarNorth){mapFarNorth=Lat;}
		else if (Lat<mapFarSouth) {mapFarSouth=Lat}
		
		if (Lng>=mapFarEast){mapFarEast=Lng;}
		else if (Lng<mapFarWest) {mapFarWest=Lng}
	}
}


//AutoZoomMap() - Function to find the correct zoom level based on the Markers
function AutoZoomMap()
{
	map.setZoom(map.getBoundsZoomLevel(MapBounds));
}

//centerMap() - Function to center the map based on the Markers
// Note: if centerMap() is called, make sure that you set the MapAutoZoom to true to make sure that Markers will all be displayed.
function centerMap()
{
	var vLen=0;
	var hLen=0
	var cLat=0;
	var cLng=0;
	
	vLen=mapFarNorth		
	vLen=vLen-mapFarSouth
	
	hLen=mapFarEast		
	hLen=hLen-mapFarWest
	
	cLat=mapFarNorth-(vLen/2)
	cLng=mapFarEast-(hLen/2)
	
	bounds = new GLatLngBounds();
	bounds.extend(new GLatLng(cLat, cLng))
	if (MapAutoZoom){AutoZoomMap();map.setCenter(new GLatLng(cLat, cLng))}
	else{map.setCenter(new GLatLng(cLat, cLng), MapZoom);}
}

//MarkLines() - Function to create the connecting lines
function MarkLines()
{
	try
	{
		if (MapPoints)
		{
			var polyline = new GPolyline(MapPoints, MapLineColor, MapLineSize,MapLineOpacity);
			map.addOverlay(polyline);
		}
	}
	catch (ex)
		{return true;}
}

function DisplayMap()
{
	if(map)
    {
	    map.checkResize(); //If Map container is hidden, this checkResize() will check the visibility of the map.
	    if (MapPoints){MarkLines()}
	    if (MapAutoCenter){centerMap();}
	    else if (MapAutoZoom){AutoZoomMap();map.setCenter(new GLatLng(defLat, defLng))}
	    else {map.setCenter(new GLatLng(defLat, defLng),MapZoom)}	
	}
}


