var map=null;
var LA=new VELatLong(34.0540, -118.2370);
var pinPoint=null;
var pinPixel=null;
var pinno=0;
var confidenceStrings=$__l.map_confidence_list.split('|');
var precisionStrings=$__l.map_precision_list.split('|');
var pushpinUrls=[$img_root+"pins/pin1.png",$img_root+"pins/pin2.png",$img_root+"pins/pin1.png"];
var distanceUnit=$distance_unit=='km' ? VEDistanceUnit.Kilometers : VEDistanceUnit.Miles;
				 
function GetMap(selected){
//	alert("selected"+selected);
	VERouteOptions.DistanceUnit=distanceUnit;
	map = new VEMap("myMap");
	map.LoadMap();
	map.SetScaleBarDistanceUnit(distanceUnit);
	$map_default_pos=$map_default_pos.split(',');
	mapCenterAndZoom($map_default_pos[1],$map_default_pos[2],$map_default_pos[0]);
	if(selected==1){
		var recordsonpage=parseInt(document.getElementById("recordstoshow").value);
//		alert("zipcode="+document.getElementById("zipcode").value);
  //alert("recordsonpage="+recordsonpage);
			var latitude=document.getElementById("base_latitude").value!='' ? document.getElementById("base_latitude").value : document.getElementById("center_latitude").value;
			var longitude=document.getElementById("base_longitude").value!='' ? document.getElementById("base_longitude").value : document.getElementById("center_longitude").value;
			if(latitude!='' && longitude!=''){
				var LA = new VELatLong(latitude, longitude);
			}
			
			map.LoadMap(LA, 14, VEMapStyle.Road, false, VEMapMode.Mode2D, true, 1);
			map.SetScaleBarDistanceUnit(distanceUnit);
	//		map.SetCenter(LA);
			ShowSelectedPins(document.getElementById('zoom') ? document.getElementById('zoom').value : null);
	}else{

		if(selected==2)
		{
			var recordsonpage=parseInt(document.getElementById("recordstoshow").value);
			var latitude=document.getElementById("base_latitude").value;
			var longitude=document.getElementById("base_longitude").value;
			var isCompany=document.getElementById("companyaccount").value;
//			alert("isCompany="+isCompany);
//		alert("latitude="+latitude);
//			alert("longitude="+longitude);
		
				var LA = new VELatLong(latitude, longitude);
			

			map.SetCenter(LA);
			var pin = new VEShape(VEShapeType.Pushpin, LA);
//			alert("recordsonpage="+recordsonpage);
			if(recordsonpage==0){
				//pin.SetCustomIcon("<img src='" +pushpinUrls[1] +"'>");
				pin.SetCustomIcon('<img src="'+pushpinUrls[1]+'" style="margin-top:-35px">');
	//		 	map.SetCenter(LA);
	//		 	alert("Am pus centrul");
	//			map.SetZoomLevel(11);	 
				pin.SetTitle($__l.map_your_location);                                
				map.AddShape(pin);
				
				if(isCompany==1)
				{
						latitude1=document.getElementById("request_latitude").value;
						longitude1=document.getElementById("request_longitude").value;
						LA1 = new VELatLong(latitude1, longitude1);
						pin1 = new VEShape(VEShapeType.Pushpin, LA1);
						//pin1.SetCustomIcon("<img src='" + pushpinUrls[0] +"'>");
						pin1.SetCustomIcon('<img src="'+pushpinUrls[0]+'" style="margin-top:-35px">');
						map.AddShape(pin1);
				}
			  }else{
				  ShowSelectedPins();
			  }
		
//	pin.SetTitle(companyname);
//		pin.SetDescription(desc);
//		map.AddShape(pin);
		}else{
				if(selected==3)
					{
						
						var latitude=document.getElementById("company_latitude").value;
						var longitude=document.getElementById("company_longitude").value;
						var location=new VELatLong(latitude, longitude);
						pin = new VEShape(VEShapeType.Pushpin, location);
						//pin.SetCustomIcon("<img src='" + pushpinUrls[0] +"'>");
						pin.SetCustomIcon('<img src="'+pushpinUrls[0]+'" style="margin-top:-35px">');
						var CalagaryCenter = new VELatLong(latitude,longitude, 0, VEAltitudeMode.Default);

						map.LoadMap(CalagaryCenter, 8);
						map.SetScaleBarDistanceUnit(distanceUnit);
//	           			map.SetCenter(location);
						map.AddShape(pin);						
					}else{
						if(typeof selected=='object'){
							var pin=new VEShape(VEShapeType.Pushpin,new VELatLong(selected[0],selected[1]));
							pin.SetCustomIcon('<img src="img/no/1.png" style="position:absolute;margin-top:-35px"><img src="'+pushpinUrls[0]+'" style="margin-top:-35px">');
							map.AddShape(pin);
							mapCenterAndZoom(selected[0],selected[1],15);
						}else{
							PostBusinessMap(selected);
						}
					}
		
		
			}
	}
}
		 
function PostBusinessMap(address){
	if(address!=''){
		map = new VEMap("myMap");
		map.LoadMap();
		map.SetScaleBarDistanceUnit(distanceUnit);
		StartGeocoding(address);
	}
}

 function GetRouteMap()
 {
	var locations;
	var startPoint="";
	
	var destinationPoint="";
	if(document.getElementById("company_zipcode")!=null)
		destinationPoint=document.getElementById("company_zipcode").value;
//	alert("destinationPoint="+destinationPoint);
	if(document.getElementById("starpoint")!=null)
					startPoint=document.getElementById("starpoint").value;
//alert("startPoint="+startPoint);					
	if(destinationPoint!=''){
		
			if(startPoint!=''){
				locations = new Array(startPoint,destinationPoint);
				var options = new VERouteOptions;
			
				// Otherwise what's the point?
				options.DrawRoute      = true;
			
				// So the map doesn't change:
				options.SetBestMapView = false;
			
				// Call this function when map route is determined:
				options.RouteCallback  = ShowTurns;
			
				// Show as miles
				options.DistanceUnit   = VERouteDistanceUnit.Kilometer;
			
				// Show the disambiguation dialog
				options.ShowDisambiguation = true;
			
				map.GetDirections(locations, options);
		}else{
				alert($__l.map_err_route);
		}
	}
	else
	{
		alert($__l.map_err_route2);
	}
 }
		 
		function ShowTurns(route)
		 {
			var startPoint=document.getElementById("starpoint").value;
			var destinationPoint=document.getElementById("company_address").value;
			var turns = "<p><b>"+$__l.map_start_point+"</b>: "+startPoint+"</p>";
			  turns += "	<p>"+$__l.map_length+": "+route.Distance.toFixed(1)+"Km | "+$__l.map_approx_time+": "+GetTime(route.Time)+"</p>";
			  turns += "	<table cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" border=\"0\">";
	//        turns += "<p><b>Distance:</b> " + route.Distance.toFixed(1) + " km";

	  //      turns += "<br/><b>Time:</b> " + GetTime(route.Time) + "</p>";

	  //      if (dirsForm.dirsType[0].checked)
	  //      {
			   // Unroll route and populate DIV
			   var legs          = route.RouteLegs;
			   var leg           = null;
			   var turnNum       = 0;  // The turn #

			   // Get intermediate legs
			   for(var i = 0; i < legs.length; i++)
			   {
				  // Get this leg so we don't have to derefernce multiple times
				  leg = legs[i];  // Leg is a VERouteLeg object

				  var legNum = i + 1;
//                  turns += "<br/><b>Distance for leg " + legNum + ":</b> " + leg.Distance.toFixed(1) + " km" +
//                           "<br/><b>Time for leg "     + legNum + ":</b> " + GetTime(leg.Time) + "<br/><br/>";

				  // Unroll each intermediate leg
				  var turn        = null;  // The itinerary leg
				  var legDistance = null;  // The distance for this leg
				  
				  for(var j = 0; j < leg.Itinerary.Items.length; j ++)
				  {
					 turnNum++;
					 
					 turn = leg.Itinerary.Items[j];  // turn is a VERouteItineraryItem object
					 legDistance    = turn.Distance;
   //                turns += "<b>" + turnNum + "</b>\t" + turn.Text;
					 
					
					 // So we don't show 0.0 for the arrival
					 if(legDistance > 0)
					 {
						 turns += "<tr>";
						 turns +="<td class=\"numDir\">"+turnNum+"</td>";
						 turns +="<td class=\"pointDir\">"+GetFormattedText(turn.Text)+"</td>";
						
						 turns +="<td class=\"distDir\">";
						// Round distances to 1/10ths
						turns += legDistance.toFixed(1) + " km";

  /*                      // Append time if found
						if(turn.Time != null)
						{
						   turns += "; " + GetTime(turn.Time);
						}
*/
					  //  turns += " <br/>";
					   turns +="</td>";
					 }
					 turns += "</tr>";
				  }

				  turns += "<br/>";
			   }
			turns += "</table>";
			turns += "<p><b>"+$__l.map_end_point+"</b>: "+destinationPoint+"</p>";
			turns += "<p><a href=\"javascript:window.print();\">"+$__l.map_print+"</a></p>";
			  // Populate DIV with directions
			   SetDirections(turns);
  //          }dir forms
		 }


	function GetFormattedText(text){
		var str=new String(text);
		var start=-1;
		var start2=-1;
		
		if(str.indexOf("Depart",0)>=0)
		{
			start=str.indexOf("Depart",0)+7;
			
			left=str.substring(0,start);
			right=str.substr(start);
			str=left+"<b>"+right+"</b>";
//			alert(text);
//			alert(left);
//			alert(right);
//			alert(str);
		}

		if(str.indexOf("changes to",0)>=0)
		{
			start=str.indexOf("changes to",0)+10;
			
			left=str.substring(0,start);
			right=str.substr(start);
			str=left+"<b>"+right+"</b>";
//			alert(text);
//			alert(left);
//			alert(right);
//			alert(str);
		}

		if(str.indexOf("right",0)>=0)
			str=getFormated(str,"right");
		
		if(str.indexOf("left",0)>=0)
			str=getFormated(str,"left");
		
		return str;
	}
	
	function getFormated(str, word)
	{
	
		start=str.indexOf(word,0);
		var index1=str.indexOf(" ",start);
//				alert("index1="+index1);
		var index2=str.indexOf(" ",index1+1);
//					alert("index2="+index2);
		var wordAfter=new String(str.substring(index1+1,index2));
		var wordAfter2="";
//				alert(">>"+wordAfter+"<<");
		if(wordAfter=="to")
		{
			start2=str.indexOf("to stay",start);
			index1=str.indexOf(" ",start2);
			index2=str.indexOf(" ",index1+1);
			index2=str.indexOf(" ",index2+1);
	//		index2=str.indexOf(" ",index+1);
			var wordAfter2=str.substring(index1,index2);
			
		}
		left=str.substring(0,start)+"<b>"+word+"</b>"+" "+wordAfter+" "+wordAfter2+" ";	
//			alert(left);
//			alert(right);
		right=str.substr(start+index2-start+1);			
		
		str=left+"<b>"+right+"</b>";		
		return str;
				
	}
		// time is an integer representing seconds
		 // returns a formatted string
		 function GetTime(time)
		 {
			if(time == null)
			{
			   return("");
			}

			if(time > 60)
			{                                 // if time == 100
			   var seconds = time % 60;       // seconds == 40
			   var minutes = time - seconds;  // minutes == 60
			   minutes     = minutes / 60;    // minutes == 1


			   if(minutes > 60)
			   {                                     // if minutes == 100
				  var minLeft = minutes % 60;        // minLeft    == 40
				  var hours   = minutes - minLeft;   // hours      == 60
				  hours       = hours / 60;          // hours      == 1

				  //return(hours + " hour(s), " + minLeft + " minute(s), " + seconds + " second(s)");
				  return(hours + " "+$__l.hours+", " + minLeft + " "+$__l.minutes);
			   }
			   else
			   {
				 // return(minutes + " minutes, " + seconds + " seconds");
				 return(minutes + " "+$__l.minutes);
			   }
			}
			else
			{
			   return(time + " "+$__l.seconds);
			}
		 }
		
		 function ClearAll()
		 {
			map.DeleteRoute();
			SetDirections("");
			map.LoadMap(SeattleEastside, 8);
			map.SetScaleBarDistanceUnit(distanceUnit);
		 }

		 function SetDirections(s)
		 {
			var d = document.getElementById("getDirResults");
			d.innerHTML = s;
		 }
		 
function GetCoordinates(){
	address=document.getElementById("zip_reg").value;
	if(address!=''){
		map = new VEMap("myMap");
		map.LoadMap();
		map.SetScaleBarDistanceUnit(distanceUnit);
		StartGeocoding(address);
	}
}

function PostMap(str){
	address=document.getElementById(str).value;
	if(address!=''){
		map = new VEMap("myMap");
		map.LoadMap();
		map.SetScaleBarDistanceUnit(distanceUnit);
		StartGeocoding(address);
	}
}

function ShowSelectedPins(zoom){
	var recordsonpage=parseInt(document.getElementById("recordstoshow").value);
	var groups=[];
	var count=[];
	var take=[];
	for(i=1;i<=recordsonpage;i++){
		var group=jQuery('#group'+i).val();
		if(count[group]){
			if(count[group]==1){
				jQuery('#companyaddress'+groups[group]).val('<b>'+jQuery('#companyname'+groups[group]).val()+'</b><br />'+jQuery('#companyaddress'+groups[group]).val());
				jQuery('#companyname'+groups[group]).val('');
			}
			jQuery('#companyaddress'+groups[group]).get(0).value+='<br /><br /><b>'+jQuery('#companyname'+i).val()+'</b><br />'+jQuery('#companyaddress'+i).val();
			count[group]++;
		}else{
			groups[group]=i;
			count[group]=1;
			take[i]=1;
		}
	}
	var nr=0;
	for(i=1;i<=recordsonpage;i++){
		if(take[i]){
			nr++;
			AddPin(i,nr);
		}
	}

	if(document.getElementById("base_latitude")!=null){
		var latitude=document.getElementById("base_latitude").value;
		var longitude=document.getElementById("base_longitude").value;

		if ( latitude != -999 && longitude != -999 && latitude!='' && longitude!='') {
			var LA = new VELatLong(latitude, longitude);

			//var zoom="15";
			map.SetCenter(LA);

			var pin = new VEShape(VEShapeType.Pushpin, LA);
			//pin.SetCustomIcon("<img src='" +pushpinUrls[1] +"'>");
			pin.SetCustomIcon('<img src="'+pushpinUrls[1]+'" style="margin-top:-35px">');

			pin.SetTitle($__l.map_your_location);
			map.AddShape(pin);
		}
		map.SetZoomLevel(zoom==null ? 11 : zoom);
	}
	
}
function AddPin( pos,nr ) {
	var company_name = document.getElementById( 'companyname' + pos );
	var company_address = document.getElementById( 'companyaddress' + pos );
	var company_zip = document.getElementById( 'companyzipcode' + pos );
	var company_lat = document.getElementById( 'companylatitude' + pos );
	var company_long = document.getElementById( 'companylongitude' + pos );
	if ( ( company_long && !isNaN(company_long.value) ) && ( company_lat && !isNaN( company_lat.value ) ) ) {
		//Add pin by long & lat
		var desc = "";
		if ( company_address.value != "" ) desc = company_address.value;

		var location = new VELatLong( company_lat.value, company_long.value );
		var pin = new VEShape( VEShapeType.Pushpin, location );
		//pin.SetCustomIcon( "<img src='"+pushpinUrls[0] + "'>" );
		pin.SetCustomIcon('<img src="img/no/'+(nr==null ? pos : nr)+'.png" style="position:absolute;margin-top:-35px"><img src="'+pushpinUrls[0]+'" style="margin-top:-35px">');
		pin.SetTitle( company_name.value );
		pin.SetDescription( desc );
		
		map.AddShape( pin );

		/*var pin2 = new VEShape(VEShapeType.Pushpin, location);
		pin2.SetCustomIcon("<img src='img/no/"+(nr==null ? pos : nr)+".png'> ");
		map.AddShape(pin2);*/
	} else if ( company_zip.value != '' ) {
		StartGeocoding( company_zip.value );
	}
	
}

function AddPinNou(){
	pinno++;
	strCompanyZipcode="companyzipcode"+pinno;
	address=document.getElementById(strCompanyZipcode).value;

	if(address!='')
	{
		strLatitude="companylatitude"+pinno;
		strLongitude="companylongitude"+pinno;
		strCompanyName="companyname"+pinno;
		latitude=document.getElementById(strLatitude).value;
		longitude=document.getElementById(strLongitude).value;
		companyname=document.getElementById(strCompanyName).value;

		pin.SetTitle(companyname);
		pin.SetDescription(desc);
		map.AddShape(pin);

		document.getElementById("btnLat").value='';
	}
}

function UnloadMap(){
	if(map != null){
		map.Dispose();
	}
}
		 
function StartGeocoding(address){
	map.Find(null,         // what
			address,           // where
			null,              // VEFindType (always VEFindType.Businesses)
			null,              // VEShapeLayer (base by default)
			null,              // start index for results (0 by default)
			null,              // max number of results (default is 10)
			null,              // show results? (default is true)
			false,              // create pushpin for what results? (ignored since what is null)
			null,              // use default disambiguation? (default is true)
			null,              // set best map view? (default is true)
			GeocodeCallback);  // call back function	
}
		 
function GeocodeCallback(shapeLayer, findResults, places, moreResults, errorMsg){
//	alert("intrare");
	var resHtml = "";
	pinno++;

	// if there are no results, display the error message and return
	if (places == null){
			alert( (errorMsg == null) ? $__l.map_no_results : errorMsg );
			return;
	}

	// Create an entry for each VEPlace in the result set
	for (var p = 0; p < places.length; p++){
		// Gather some info up front
		var place = places[p];
		var location = place.LatLong;
		var confString = confidenceStrings[place.MatchConfidence];
		var precString = precisionStrings[place.Precision];
		var mcVal = MatchCode(place.MatchCode);

		var latitude = location.Latitude;
		var longitude = location.Longitude;

		/*if(document.getElementById("zip_reg")!=null&&place.Name!="T2E 3R8")
			   document.getElementById("zip_reg").value=place.Name;*/
   //**********************************************************************
		var recordsonpage=parseInt(document.getElementById("recordstoshow").value);
		var currentIndex=0;
  
		if(recordsonpage>1){
			for(ic=1;ic<=recordsonpage;ic++){
				strCompanyZipcode="companyzipcode"+ic;
				address=document.getElementById(strCompanyZipcode).value;
			
				if(address==place.Name)
				{
					currentIndex=ic;
					break;
				}
				
			}

			//If we don't find any find the ones that match the first 3 characters of the zip code'
			if(currentIndex == 0){
				var found=0;
				for(ic=1;ic<=recordsonpage;ic++){
					strCompanyZipcode="companyzipcode"+ic;
					address=document.getElementById(strCompanyZipcode).value;
					str=address.substring(0,3);
					if(str==place.Name)
					{
						found++;
						currentIndex=ic;
					}
					
				}
				if(found>1)
					currentIndex=-1;
			}
				
		}else
			currentIndex=1;
   //********************************************************************** 
		 
		var strCompanyAddrees="companyaddress"+currentIndex;
	
		var	strCompanyName="companyname"+currentIndex;
		var	companyAddress="";
		var	companyname="";
		if(document.getElementById(strCompanyAddrees)!=null)
				companyAddress=document.getElementById(strCompanyAddrees).value;

		if(document.getElementById(strCompanyName)!=null)
			companyname=document.getElementById(strCompanyName).value;

		if(document.getElementById("longitude")!=null)
			document.getElementById("longitude").value=longitude;
		if(document.getElementById("latitude")!=null)
			document.getElementById("latitude").value=latitude;

		// Create a pin at that location, list the latitude & longitude
		// create the info box description
		var desc = "";
		if(companyAddress!='')
			desc += "					"+$__l.map_address+": " + companyAddress;
//		desc = desc + "<br>Zipcode: " + place.Name;
//		desc = desc + "<br>Address: " + companyAddress;
//		desc = desc + "<br>Match Code: " + mcVal;
//		alert(companyname);

		var pin = new VEShape(VEShapeType.Pushpin, location);
		//pin.SetCustomIcon("<img src='" + pushpinUrls[0] +"'> ");
		pin.SetCustomIcon((currentIndex>0 ? '<img src="img/no/'+currentIndex+'.png" style="position:absolute;margin-top:-35px">' : '')+'<img src="'+pushpinUrls[0]+'" style="margin-top:-35px">');
		
		pin.SetTitle(companyname);
		pin.SetDescription(desc);
		map.AddShape(pin);

		/*if(currentIndex>0){
			var pin2 = new VEShape(VEShapeType.Pushpin, location);
			 pin2.SetCustomIcon("<img src='img/no/"+currentIndex+".png'> ");
			map.AddShape(pin2);
		}*/
	}
}
		 
function MatchCode(code){
	if(code == VEMatchCode.None) {
		return "No match";
	}
	var codeDesc = "";   
	var cVal;
	cVal=code & VEMatchCode.Good;
	if(cVal>0){
		codeDesc += "Good ";
	}
	cVal = code & VEMatchCode.Ambiguous;
	if(cVal>0){
		codeDesc += "Ambiguous ";
	}
	cVal = code & VEMatchCode.UpHierarchy;
	if(cVal>0){
		codeDesc += "UpHierarchy ";
	}
	cVal = code & VEMatchCode.Modified;
	if(cVal>0){
		codeDesc += "Modified ";
	}
	return(codeDesc + "Match");
}
		   
function getInfo(){
	var info;
	if(map.IsBirdseyeAvailable()){
		var be = map.GetBirdseyeScene();

		info  = "ID: "          + be.GetID() + "\n";
		info += "orientation: " + be.GetOrientation()+ "\n";
		info += "height: "      + be.GetHeight() + "\n";
		info += "width: "       + be.GetWidth() + "\n";

		var pixel = be.LatLongToPixel(map.GetCenter(), map.GetZoomLevel());
		info += "LatLongToPixel: " + pixel.x + ", " + pixel.y + "\n";

		// Check to see if the current birdseye view contains the pushpin pixel point.
		info += "contains pixel " + pinPixel.x + ", " + pinPixel.y + ": " + be.ContainsPixel(pinPixel.x, pinPixel.y, map.GetZoomLevel()) + "\n";

		// Check to see if the current view contains the pushpin LatLong.
		info += "contains latlong " + pinPoint + ": " + be.ContainsLatLong(pinPoint) + "\n";

		// This method may return null, depending on the selected view and map style.
		info += "latlong: " + map.PixelToLatLong(pixel);
		alert(info);
	}else{
		var center = map.GetCenter();

		info  = "Zoom level:\t" + map.GetZoomLevel() + "\n";
		info += "Latitude:\t"   + center.Latitude    + "\n";
		info += "Longitude:\t"  + center.Longitude+ "\n";
		info+='Config:'+map.GetZoomLevel()+','+center.Latitude+','+center.Longitude;

		alert(info);
	}
}
		 /*
function AddPin(){
	// Add a new pushpin to the center of the map.
	pinPoint = map.GetCenter();
	pinPixel = map.LatLongToPixel(pinPoint);
	map.AddPushpin(pinPoint);
}
*/

function GetLatLong(e){
	//Get the pixel coordinates from the click event, convert to LatLong value
	var x = e.mapX;
	var y = e.mapY;
	pixel = new VEPixel(x, y);
	latLong = map.PixelToLatLong(pixel);
	divInfo.innerHTML = latLong;
}
	 
function SetCenterAndZoom(){   
	map.SetCenterAndZoom(latLong, zoomLevel);
}
	 
function SetCenter(){
	map.SetCenter(latLong);
}

function ZoomIn(){
	//Increase zoom level by a factor of 1
	if(!map.IsBirdseyeAvailable()){
		map.ZoomIn();
		document.getElementById('txtZoom').value=map.GetZoomLevel();
	}
}
	 
function ZoomOut(){
	if(!map.IsBirdseyeAvailable()){	
		//Decrease zoom level by a factor of 1
		map.ZoomOut();
		document.getElementById('txtZoom').value = map.GetZoomLevel();
	}		
}
	 
function ValidateEntry(){
 //Check to make sure zoom level is within range
	if(document.getElementById('txtZoom').value > 0 && document.getElementById('txtZoom').value <= 19){
		zoomLevel = document.getElementById('txtZoom').value;
	}else{
		alert($__l.map_msg_zoom.replace('%1$s',1).replace('%2$s',19));
	}
}

function ToggleMode(){
	var mode = map.GetMapMode();

	if(mode == VEMapMode.Mode2D){
		map.SetMapMode(VEMapMode.Mode3D);
	}else if (mode == VEMapMode.Mode3D){
		map.SetMapMode(VEMapMode.Mode2D);
	}
}


function SetMapStyle(){
	if (styleForm.styleType[0].checked){
		 var style = map.GetMapStyle();

		 if (style == VEMapStyle.Aerial){
				alert($__l.map_msg_aerial);
		 }else{
				map.SetMapStyle(VEMapStyle.Aerial);
				alert($__l.map_msg_aerial2);
		 }
	}else if (styleForm.styleType[1].checked){
		 var style = map.GetMapStyle();

		 if (style == VEMapStyle.Birdseye){
				alert($__l.map_msg_birdseye);
		 }else{
				map.SetMapStyle(VEMapStyle.Birdseye);
				alert($__l.map_msg_birdseye2);
		 }
	}else if (styleForm.styleType[2].checked){
		 var style = map.GetMapStyle();

		 if (style == VEMapStyle.Road){
				alert($__l.map_msg_road);
		 }else{
				map.SetMapStyle(VEMapStyle.Road);
				alert($__l.map_msg_road2);
		 }
	}else if (styleForm.styleType[3].checked){
		 var style = map.GetMapStyle();

		 if (style == VEMapStyle.Hybrid){
				alert($__l.map_msg_hybrid);
		 }else{
				map.SetMapStyle(VEMapStyle.Hybrid);
				alert($__l.map_msg_hybrid2);
		 }
	}
}

function mapCenterAndZoom(latitude,longitude,zoom){   
	map.SetCenterAndZoom(new VELatLong(latitude,longitude),zoom==null ? 11 : zoom);
}
	 
function GeoCode(address,callback,hideResults){
	map.Find(null,				// what
			address,			// where
			null,				// VEFindType (always VEFindType.Businesses)
			null,				// VEShapeLayer (base by default)
			null,				// start index for results (0 by default)
			null,				// max number of results (default is 10)
			!hideResults,		// show results? (default is true)
			false,				// create pushpin for what results? (ignored since what is null)
			!hideResults,		// use default disambiguation? (default is true)
			!hideResults,		// set best map view? (default is true)
			callback);			// call back function	
}
