/****************************************************************************************
 * This file is part of the "New Nestle Web Application / Framework".
 * Written by Sogeti India for Nestlé Corporate.
 ****************************************************************************************/
var map, locationJS, positionJS, controlId, url;
var latitudes = new Array();
var longitudes = new Array();
var postingIds = new Array();
var infoDetails = new Array();
function ApplyImage(objId, imgName)
{
	var obj = document.getElementById(objId);
	if(obj != null) obj.src = '../Img/' + imgName;
}
function initialize() 
{
	if (GBrowserIsCompatible()) 
	{
		var obj = document.getElementById('dottedLine');
		if(obj != null) obj.style.styleFloat = 'none';
  
		// define the crosshair tile layer and its required functions
		var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
		crossLayer.getTileUrl =  function(tile, zoom) {
			return "./include/tile_crosshairs.png";
    }
    crossLayer.isPng = function() {return true;}

    // Create a new map type incorporating the tile layer
    var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0], crossLayer ];
    var mtTerCross = new GMapType(layerTerCross, G_PHYSICAL_MAP.getProjection(), "Ter+");

    map = new GMap2(document.getElementById("divMapCanvas"), { size: new GSize(600,320) } );
    map.addMapType(G_PHYSICAL_MAP);
    map.addMapType(mtTerCross);
    map.setCenter(new GLatLng(37.4419, 0), 1);
    map.addControl(new GLargeMapControl())
    var mapControl = new GHierarchicalMapTypeControl();
    
    // Set up map type menu relationships
    mapControl.clearRelationships();
    mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
    mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");

    // Add control after you've specified the relationships
    map.addControl(mapControl);
    
    eval(locationJS);
    eval(positionJS);
  }
}
function CreateMarker(point, postingId) 
{ 
   var marker = new GMarker(point); 
   GEvent.addListener(marker, "mouseover", function() { 
      for(i =0;i<postingIds.length;i++)
      {
         if(postingIds[i] == postingId)
         {
            map.openInfoWindowHtml(point, infoDetails[i]);
	         if(map.getZoom() == 1) map.setZoom(2);
	         break;
         }
      }
   }); 
   return marker; 
}
function GetDetails(postingId, objId) 
{
	var obj = document.getElementById(controlId + '_' + objId);
	if(obj != null)
	{
	   if(obj.style.display == '')
	   {
	   	ApplyImage(objId.replace('Div', 'Img'), 'OrangeArrow1.gif');
	      obj.style.display = 'none';
	   }
	   else
	   {
	      CloseOpenDivs();
	      obj.style.display  = '';
	      // Display Info Popup
	      for(i =0;i<postingIds.length;i++)
         {
            if(postingIds[i] == postingId)
            {
               map.openInfoWindowHtml(new GLatLng(latitudes[i], longitudes[i]), infoDetails[i]);
	            if(map.getZoom() == 1) map.setZoom(2);
	            break;
            }
         }
	   }
	}
}
function CloseOpenDivs()
{
	var tblObj = document.getElementById(controlId + '_tblCenterList');
	if(tblObj != null)
	{
	   var len = tblObj.rows.length;
	   var dataRow, dataRowId;
	   for(i=0;i<len;i++)
	   {
	      dataRow = tblObj.rows[i];
	      dataRowId = dataRow.id;
		   if(dataRowId.indexOf('RowDiv') != -1)
		   {
		      if(dataRow.style.display == '')
		      {
		         var index = dataRowId.indexOf('_');
		         if(index != -1)
		            ApplyImage(dataRowId.substring(index+1).replace('RowDiv', 'RowImg'), 'OrangeArrow1.gif');
		         else   
		            ApplyImage(dataRowId.replace('RowDiv', 'RowImg'), 'OrangeArrow1.gif');
               dataRow.style.display = 'none';   
			   }
		   }
	   }
	}
}