﻿		var CFCCMap=null;
		var Addr='5006 Randall Parkway,Wilmington,NC,28403';
		function CFCC_IsDefined(oE){
			var ri=false;
			if(typeof(oE)!=='undefined'&&oE!==null&&oE!=='null'){
				ri=true;
			}
			return ri;
		}
		function CFCCMap_Load(){
			var oLatLng = new VELatLong(34.23111342915868,-77.87908673286438);
			CFCCMap = new VEMap('CFCCMap');
			CFCCMap.LoadMap(oLatLng,14);
			CFCCMap.SetMapMode(VEMapMode.Mode2D);
            CFCCMap.SetMapStyle(VEMapStyle.Hybrid);
            CFCCMap_onLoadComplete(oLatLng);
		}
		function CFCCMap_onLoadComplete(oLatLng){
			if(CFCC_IsDefined(oLatLng)){
				var icon=new VEShape(VEShapeType.Pushpin,oLatLng);
				icon.SetCustomIcon('<img src="/Portals/3/Skins/CFWI-Content/images/icons/cfwi-icon.png" title="CFWebmasters.com" />');
				icon.SetTitle('CFWebmasters.com');
				icon.SetDescription('<b style="font-size: 120%">5006 Randall Pkwy.</b><br /><span style="font-size: 92%">Wilmington, NC 28403</span>');
				CFCCMap.AddShape(icon);
			}
		}
		function CFCCMap_composeAddress(){
			var street=$get('txtStartStreet').value;
			var city=$get('txtStartCity').value;
			var state=$get('ddlStartState').options[$get('ddlStartState').selectedIndex].value;
			var zip=$get('txtStartZip').value;
			var address='';
			if(CFCC_IsDefined(street)&&street.length>0){ address+=street; }
			if(CFCC_IsDefined(city)&&city.length>0){ if(address.length > 0){ address+=',' + city; }else{ address+=city; }}
			if(CFCC_IsDefined(state)&&state.length>0){ if(address.length > 0){ address+=',' + state; }else{ address+=state; }}
			if(CFCC_IsDefined(zip)&&zip.length>0){ if(address.length > 0){ address+=',' + zip; }else{ address+=zip; }}
			if((CFCC_IsDefined(street)&&street.length===0)&&(CFCC_IsDefined(city)&&city.length===0)&&(CFCC_IsDefined(zip)&&zip.length===0)){
				address='';
			}
			return address;
		}
		function CFCCMap_GetDirections(e){
			var address = CFCCMap_composeAddress();
			if(!(address.length===0)){
				var points = [address,Addr];
				var options = new VERouteOptions;
				options.DrawRoute = true;
				options.SetBestMapView = true;
				options.RouteCallback = CFCCMap_onGetDirectionsComplete;
				options.DistanceUnit = VERouteDistanceUnit.Mile;
				options.ShowDisambiguation = true;
				options.ShowErrorMessages=true;
				CFCCMap.GetDirections(points, options);
            }else{
				alert('In order to provide the most accurate directions,\r\nplease provide one or all of the following:\r\n\r\n-- Street Address\r\n-- City\r\n-- Zip\r\n\r\nand be sure to select your state of residence.');
            }
            if(e.preventDefault){e.preventDefault();}
            return false;
		}
		function CFCCMap_onGetDirectionsComplete(route){
			var directions='',totalDistance=$get('cfccTotalDistance'),legs=route.RouteLegs,leg=null,turn=null,legDistance=null,turnNum=0;
			for(var i=0;i<legs.length;i++){
				leg=legs[i];
				totalDistance.innerHTML='<b>'+leg.Distance.toFixed(1)+' miles</b>';
				directions+='<ol>';
				for(var x=0;x<leg.Itinerary.Items.length;x++){
					turnNum++;
					turn=leg.Itinerary.Items[x];
					directions+='<li>'+turn.Text;
					legDistance=turn.Distance;
					if(legDistance>0){
						// Round distances to 1/10ths
                        directions += " <b>(" + legDistance.toFixed(1) + " miles)</b>";
					}
					directions += "</li>";
				}
				directions+='</ol>';
			}
			CFCCMap_populateDirections(directions);
		}
		
		function CFCCMap_populateDirections(directions){
			var oDiv=$get('CFCCDirections');
			if(typeof(oDiv)!=='undefined'&&oDiv!==null){
				oDiv.innerHTML=directions;
			}
		}