var map = null;

function GetMap(city, state) {
	map = new VEMap('city_map');
   	map.LoadMap();
	map.HideDashboard();
	map.HideScalebar();
	map.Find(null,"'"+city+","+state+"'",null,null,null,null,null,null,null,true,null);
}

function GetMap2(city,state,lat,lon) {
	map = new VEMap('city_map');
   	map.LoadMap();
	map.HideDashboard();
	map.HideScalebar();
	//map.style.width = "430px";
	//map.style.height = "424px";
	map.LoadMap(new VELatLong(lat,lon),12);
}


function dropPin(lon,lat,restID,storeName,address1,address2,city,state,zip,storeURL,photo,walmart) {
	//alert(lon, lat, restID, storeName);
	var location= new VELatLong(lat,lon);
	var shape = new VEShape(VEShapeType.Pushpin, location);
	if (walmart == 0) {
		var title = "McDonald's #"+restID;
	} else {
		var title = "<img src='/images/walmart_map_icon.jpg'> McDonald's #"+restID;
	}	
	var info = storeName+"<br/>"+address1+" "+address2+"<br/>"+city+", "+state+" "+zip;
	var url ='<br><a href="http://'+storeURL+'/'+restID+'"><img src="/bing_portal_map/Restaurant_hp_button.jpg" alt="Restaurant Homepage" title="Visit this McDonald\'s!"></a>';
	shape.SetTitle(title);
	shape.SetDescription(photo+" "+info+"<br/>"+url);
	shape.SetCustomIcon('<img src="/images/maplogo.jpg">');
	map.AddShape(shape);
}


function cities(x) {	
	$.ajax({url:'/feeds/cities/' + x + '.xml', dataType:"xml", cache:false, success: function(xml) {
			$(xml).find('city').each(function(i) {	
				var label = $(this).attr("label");
				var data = $(this).attr("data");
				$("#cityList").append('<option value="' + data + '">' + label + '</option>');
			});
		}
	});
}


function findStores() {	
	var vars = $("#cityList").val().split(':');
	var cityState = $("#cityList").val().split('-');
	var name =  cityState[1].replace("_", " ");
	var id = cityState[0];
	
	// --> Bing Map
	$.ajax({
		type: "POST",
		url: "/bing_portal_map/city_map.php",
		dataType: "script",
		data: ({cityname: name, stateid: id, statename: vars[1]}),
		beforeSend: function () {
			var prehtml = '<div id="city_map" style="width:515px"></div>';
			$("#portalMap").html(prehtml);
			$("#portalMap").css({background: '#ffe'});
		},
		success: function() {
			//var html = '<div id="city_selector" style="border:1px solid gray;"><select id="cityList" class="cityList" name="cityList"><option>Select a City</option></select></div><div id="city_map" style="border:1px solid gray;"></div>';
			//var html = '<select id="cityList" class="cityList" name="cityList"><option>Select a City</option></select>';
			//$("#portalMap").append(html);
			//$("#portalMap").html(html);
			// cities(id);
			// $("#cityList").css("z-index",99);
			// alert( "Data Saved: " + msg );
		}
	});

	// --> to text results page
	//document.location.href = "/"+name;
}
