h = '<script type="text/javascript">document.location.href = "index.php"</script>';<!-- ';

var map=null, conn=null, commands=[];
function onError() { alert('An Error Occured!'); }
function onTimeout() { alert('A Timeout Occured!'); }
function map24Java(div_id) {
  if (!document.getElementById(div_id)) { return; }
  //show_loader('loader_panel');
  map = new Map24.Map();
  map.addCanvas(new Map24.Canvas({NodeName: div_id}), "myCanvas");
  map.addMapClient(new Map24.MapClient.Applet(), "Applet");
  map.show("Applet", "myCanvas");
  conn = map.WebServices.openConnection();
  conn.onSuccess = null; conn.onError = null; conn.onTimeout = null;
}
var show_loader = function(div_id)
{
	$(div_id).innerHTML = '<img src="/images/ajax-loader.gif" alt="se incarca..." title="se incarca..." />&nbsp;incarc harta...';
}
var hide_loader = function(div_id)
{
	$(div_id).innerHTML = '&nbsp;';
}
function map24Java_callback(div_id, callback_function) {
  if (!document.getElementById(div_id)) { return; }
  map = new Map24.Map();
  map.addCanvas(new Map24.Canvas({NodeName: div_id}), "myCanvas");
  map.addMapClient(new Map24.MapClient.Applet(), "Applet");
  map.show("Applet", "myCanvas");
  conn = map.WebServices.openConnection();
  conn.onSuccess = null; conn.onError = null; conn.onTimeout = null;
  window.setTimeout(function(){eval(callback_function+'()');},4000)
}
function map24Js(div_id) {
  if (!document.getElementById(div_id)) { return; }
  map = new Map24.Map();
  map.addCanvas(new Map24.Canvas({NodeName: div_id}), "myCanvas");
  map.addMapClient(new Map24.MapClient.Static(), "Static");
  map.show("Static", "myCanvas");
  conn = map.Local.openConnection();
  conn.onSuccess = null; conn.onError = null; conn.onTimeout = null;
}
var center_ro = function()
{
	Map24.MapApplication.center({Latitude:2770, Longitude:1517 , MinimumWidth: 1000000});
}
function map24Js2()
{
	var args = map24Js2.arguments;
	Map24.loadApi( ["core_api", "wrapper_api"] , function(){
	Map24.MapApplication.init( { NodeName: args[0], MapType: "Static" } );
	Map24.MapApplication.center({Latitude:2770, Longitude:1517 , MinimumWidth: 1000000});
	if (args[1])
	{
		eval(args[1]+'()');
	}
	});
}
function zoomCoordinates(lat, lon, min_width)
{
	Map24.MapApplication.center({Longitude: lon, Latitude: lat, MinimumWidth: min_width})
	return;
}

function center2(latitude, longitude)
{
	var args = center2.arguments;
	return Map24.MapApplication.center({Longitude: longitude, Latitude: latitude, MinimumWidth: (args[2] != 'null' && args[2] != 'undefined' && args[2]) ? args[2] : 0 })	
}

function loadLabel(objId, lng, lat, objText) {
  var mapObjectIDs = [];
  var objColor = new Map24.WebServices.Color({red: 0, green: 0, blue: 0, alpha: 0});
  var objBgColor = new Map24.WebServices.Color({red: 255, green: 255, blue: 255, alpha: 100});
  var borderColor = new Map24.WebServices.Color({red: 64, green: 64, blue: 64, alpha: 100});
  commands.push( new Map24.WebServices.XMLCommandWrapper({ DeclareMap24Label: new Map24.WebServices.DeclareMap24Label({ MapObjectID: objId, Coordinate: new Map24.Coordinate( lng, lat ), Text: objText, Color: objColor, BgColor: objBgColor, BorderColor: borderColor, Anchor: "CENTER" }) }) );
  mapObjectIDs.push(objId);
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: mapObjectIDs, Control: "ENABLE" }) }) );
}

function shapeLocation(objId, stringCallback) {
  var mapObjectIDs = [];
  commands.push( new Map24.WebServices.XMLCommandWrapper({
    DeclareMap24Location: new Map24.WebServices.DeclareMap24Location({
      MapObjectID: objId, SymbolID : 20950,
      Customize: new Map24.WebServices.MapObjectCustomSettings({
        Handler: "MAP24_LOCATION_DIGITIZER",
        Properties: [
          new Map24.WebServices.Property({ Key: "SUBMIT_URL", Value: "javascript:getMapletSession('Location', '"+objId+"', '"+stringCallback+"')" }),
          new Map24.WebServices.Property({ Key: "SUBMIT_ON_MOVE", Value: "true" }),
          new Map24.WebServices.Property({ Key: "SUBMIT_TARGETFRAME", Value: "_self" }),
          new Map24.WebServices.Property({ Key: "HIGHLIGHT_SYMBOL_ID", Value: "20950" })
        ]
      })
    })
  }) );
  mapObjectIDs.push(objId);
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: mapObjectIDs, Control: "ENABLE" }) }) );
}

function shapePolygon(objId, stringCallback) {
  var z = eval("new Array('" + objId + "')");
  var rgb_color = new Map24.WebServices.Color({red: Math.floor(Math.random()*255), green: Math.floor(Math.random()*255), blue: Math.floor(Math.random()*255), alpha: 100});
  commands.push( new Map24.WebServices.XMLCommandWrapper({
    DeclareMap24Polygon: new Map24.WebServices.DeclareMap24Polygon({
      MapObjectID: objId, Coordinates: new Map24.WebServices.CoordinatesArray({ Longitudes: "1517", Latitudes: "2750" }), FillColor: rgb_color,
      Customize: new Map24.WebServices.MapObjectCustomSettings({
        Handler: "MAP24_SHAPER",
        Properties: [ new Map24.WebServices.Property({ Key: "SUBMIT_URL", Value: "javascript:getMapletSession('Polygon', '"+objId+"', '"+stringCallback+"')" }) ]
      })
    })
  }) );
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: z, Control: "ENABLE" }) }) );
}
function transformPolygon(objId, lng_string, lat_string, stringCallback) {
  var z = eval("new Array('" + objId + "')");
  var rgb_color = new Map24.WebServices.Color({red: Math.floor(Math.random()*255), green: Math.floor(Math.random()*255), blue: Math.floor(Math.random()*255), alpha: 100});
  commands.push( new Map24.WebServices.XMLCommandWrapper({
    DeclareMap24Polygon: new Map24.WebServices.DeclareMap24Polygon({
      MapObjectID: objId, Coordinates: new Map24.WebServices.CoordinatesArray({ Longitudes: lng_string, Latitudes: lat_string }), FillColor: rgb_color,
      Customize: new Map24.WebServices.MapObjectCustomSettings({
        Handler: "MAP24_TRANSFORMER",
        Properties: [
          new Map24.WebServices.Property({ Key: "KEEP_ACTIVE", Value: "true" }),
          new Map24.WebServices.Property({ Key: "SUBMIT_URL", Value: "javascript:getMapletSession('Polygon', '"+objId+"', '"+stringCallback+"')"
          })
        ]
      })
    })
  }) );
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: z, Control: "ENABLE" }) }) );
  commands.push( new Map24.WebServices.XMLCommandWrapper({ SetMapView: new Map24.WebServices.SetMapView({ MapObjectIDs: z }) }) );//, ClippingWidth: new Map24.WebServices.SetMapViewClippingWidth({ MinimumWidth: minwidth })
}
function getMapletSession(objType, objId, stringCallback) {
  var z = eval("new Array('" + objId + "')");
  conn.getMapletSession(
    new Map24.WebServices.Message.getMapletSessionRequest({ GetMapletSessionRequest: new Map24.WebServices.GetMapletSessionRequest({ Map24MRCMapObjectIDsFilter: z }) }),
    function(connection, request, response) { onSuccessGetMapletSession(connection, request, response, objType, stringCallback); }, conn.onError, conn.onTimeout );
}
function onSuccessGetMapletSession(connection, request, response, objType, stringCallback) {
  var getMapletSessionResponse = response.getProperty("GetMapletSessionResponse");
  var commands = getMapletSessionResponse.getProperty("Commands");
  if (objType == 'Polygon') {
    var shaperCoordinates = commands[0].getProperty("DeclareMap24Polygon").getProperty("Coordinates");
    longitudes = shaperCoordinates.getProperty("Longitudes").split("|");
    latitudes = shaperCoordinates.getProperty("Latitudes").split("|");
  }
  else if (objType == 'Location') {
    var locationCoordinate = commands[0].getProperty("DeclareMap24Location").getProperty("Coordinate");
    longitudes = [];
    latitudes = [];
    longitudes[0] = locationCoordinate.getProperty("Longitude");
    latitudes[0] = locationCoordinate.getProperty("Latitude");
  }
  eval(stringCallback);
}

function removeObject(objId) {
  var mapObjectIDs = []; mapObjectIDs.push(objId);
  commands.push( new Map24.WebServices.XMLCommandWrapper({ RemoveMapObject: new Map24.WebServices.RemoveMapObject({ MapObjectIDs: mapObjectIDs }) }) );
}

function loadLocation() {
  var a=loadLocation.arguments;
  var mapObjectIDs = [];
  var objId = a[0];
  var lngString = a[1];
  var latString = a[2];
  var objText = a[3];
  var SymID = a[4];
	if (typeof a[6] != 'undefined')
	{
		commands.push( new Map24.WebServices.XMLCommandWrapper({ DeclareMap24Location: new Map24.WebServices.DeclareMap24Location({ MapObjectID: objId, Coordinate: new Map24.WebServices.Coordinate({ Longitude: lngString, Latitude: latString }), SymbolID: SymID, LogoURL: a[5], Description: a[6] }) }) );
	}
	else if (typeof a[5] != 'undefined') {
    commands.push( new Map24.WebServices.XMLCommandWrapper({ DeclareMap24Location: new Map24.WebServices.DeclareMap24Location({ MapObjectID: objId, Coordinate: new Map24.WebServices.Coordinate({ Longitude: lngString, Latitude: latString }), SymbolID: SymID, LogoURL: a[5], LogoURLOnMouseOver: a[5] }) }) );
  }
  else {
    commands.push( new Map24.WebServices.XMLCommandWrapper({ DeclareMap24Location: new Map24.WebServices.DeclareMap24Location({ MapObjectID: objId, Coordinate: new Map24.WebServices.Coordinate({ Longitude: lngString, Latitude: latString }), SymbolID: SymID }) }) );
  }
  mapObjectIDs.push(objId);
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: mapObjectIDs, Control: "ENABLE" }) }) );
}
function loadPolygon(objId, lngString, latString, objText) {
  var mapObjectIDs = [];
  var rgb_color = new Map24.WebServices.Color({ red: Math.floor(Math.random()*255), green: Math.floor(Math.random()*255), blue: Math.floor(Math.random()*255), alpha: 100 });
  commands.push( new Map24.WebServices.XMLCommandWrapper({ DeclareMap24Polygon: new Map24.WebServices.DeclareMap24Polygon({ MapObjectID: objId, Coordinates: new Map24.WebServices.CoordinatesArray({ Longitudes: lngString, Latitudes: latString }), FillColor: rgb_color, Description: objText }) }) );
  mapObjectIDs.push(objId);
  commands.push( new Map24.WebServices.XMLCommandWrapper({ ControlMapObject: new Map24.WebServices.ControlMapObject({ MapObjectIDs: mapObjectIDs, Control: "ENABLE" }) }) );
}

function lonToMetres (dlon, pointlat) {
  return dlon * 111200 * Math.cos(pointlat * (Math.PI/180));
}

function metresToLon(m,lat) {
  return m / (111200*Math.cos(lat * (Math.PI/180)));
}
function zoomObject() {
  var a=zoomObject.arguments, mapObjectIDs=[];
  mapObjectIDs.push(a[0]);
  if (typeof a[1] != "undefined") { commands.push( new Map24.WebServices.XMLCommandWrapper({ SetMapView: new Map24.WebServices.SetMapView({ MapObjectIDs: mapObjectIDs, ClippingWidth: new Map24.WebServices.SetMapViewClippingWidth({ MinimumWidth: a[1] }) }) }) ); }
  else { commands.push( new Map24.WebServices.XMLCommandWrapper({ SetMapView: new Map24.WebServices.SetMapView({ MapObjectIDs: mapObjectIDs }) }) ); }
}
function applyCommands(callback) {
  conn.mapletRemoteControl( new Map24.WebServices.Message.mapletRemoteControlRequest({ MapletRemoteControlRequest: new Map24.WebServices.MapletRemoteControlRequest({ Map24MRC: new Map24.WebServices.Map24MRC({ Commands: commands }) }) }), callback, conn.onError, conn.onTimeout );
}
function searchGeocode( searchText, stringCallback ){
  conn.searchFree( new Map24.WebServices.Message.searchFreeRequest({
    MapSearchFreeRequest: new Map24.WebServices.MapSearchFreeRequest({ SearchText: searchText, MaxNoOfAlternatives: 10, CTRY: "RO" })
  }),
  function (connection, request, response) {
    var mapSearchResponse = response.getProperty("MapSearchResponse");
    var alternatives = mapSearchResponse.getProperty("Alternatives");
    try{
	    var n = alternatives.length;
	    if (n > 0)
			{
	      longitudes = [];
	      latitudes = [];
				countries = []
	      for (var i=0; i < n; i++)
				{
	        longitudes[i] = alternatives[i].getProperty("Coordinate").getProperty("Longitude");
	        latitudes[i] = alternatives[i].getProperty("Coordinate").getProperty("Latitude");
	        var propsMajor = alternatives[i].getProperty('PropertiesMajor');
	        var jn = propsMajor.length;
					var name = '';
	        for (var j = 0; j < jn ; j++) {
         if (propsMajor[j].getProperty('Key') == 'Street') {
            name +=' Str. '+propsMajor[j].getProperty("Value");
          }
					if (propsMajor[j].getProperty('Key') == 'City')
					{
            name +=' '+propsMajor[j].getProperty("Value");
					}
				 if (propsMajor[j].getProperty('Key') == 'Cty')
				 {
           if (name.length)
					  name +='( Jud. '+propsMajor[j].getProperty("Value")+')';
  			 }
         if (propsMajor[j].getProperty('Key') == 'Sta')
         {
           if (name.length)
            name +=' - '+propsMajor[j].getProperty("Value");
         }
				 if (propsMajor[j].getProperty('Key') == 'Ctry')
				 {
            countries[i] = propsMajor[j].getProperty("Value");
				 }
	        }
					names[i] = name;
	      }
	    }

		}
		catch(Ex)
		{
			alert(Ex.message)
		}
    eval(stringCallback);
  }, conn.onError, conn.onTimeout );
}
function drawPolygon(lat, lng, labelName, hidePolygon){
	var poly_centroid = computeCentroid(lat.split(","), lng.split(","));

	var red_color = Math.floor(Math.random()*255);
	var green_color = Math.floor(Math.random()*255);
	var blue_color = Math.floor(Math.random()*255);
	var rgb_color = new Map24.WebServices.Color({red: red_color, green: green_color, blue: blue_color, alpha: 100});

	var polygon = new Map24.Polygon({
		Longitudes: lng.replace(/,/g,"|"),
 		Latitudes: lat.replace(/,/g,"|"),
 		FillColor: rgb_color
 	});
	try
	{
		polygon.commit();
		polygon.center({MinimumWidth: 1000, ViewPercentage:20});
	}
	catch(Ex)
	{
		alert(Ex.message)
	}

	if(hidePolygon) {
 		polygon.hide();
 	}

	if(labelName) 
	{
		var label = new Map24.Label({
	 		Longitude: lng.split(',')[0],
	 		Latitude: lat.split(',')[0],
	 		Text: labelName,
	 		Color: "#FFF",
	 		Background: ["#FC0",250]
	 	});
	 	label.commit();
	}
}
function computeCentroid(lat_coords, lng_coords){
	var lat_center = 0;
	var lng_center = 0;
	 for(var i=0; i<lat_coords.length;i++)
	 {
		 lat_center += lat_coords[i]*1;
		 lng_center += lng_coords[i]*1;
	 }
	lat_center = parseFloat(lat_center / lat_coords.length);
	lng_center = parseFloat(lng_center / lng_coords.length);
	return lat_center+","+lng_center;
}h = ' -->';