//------------------------------------------------------------------------------
// Analytics.js 
//
// <copyright from='2004' to='2005' company='Microsoft Corporation'> 
// Copyright (c) Microsoft Corporation. All Rights Reserved. 
// Information Contained Herein is Proprietary and Confidential. 
// </copyright>
//
// Owner: CodyE
// Modified by brsnow for street side
// <header>	$Header$</header>
//------------------------------------------------------------------------------

// Empty constructor, needed to use the class name.
function VE_Analytics()
{
	
}


function VE_Range(min,max)
{
	this.min = min;
	this.max = max;
}

VE_Range.prototype.IsInRange=function(val)
{
	return val >= this.min && 
	       val <= this.max;
	       
};

VE_Range.prototype.toString=function()
{
	return this.min+"-"+this.max;
};
                                        
VE_Analytics.distanceBuckets = new Array(new VE_Range(0,10),
									   new VE_Range(11,25),
									   new VE_Range(26,100),
									   new VE_Range(101,200),
									   new VE_Range(201,500),
									   new VE_Range(501,1000));
// Whether or not analytics is enabled.
VE_Analytics.analyticsEnabled = true;

// Logs the user opening the help from the main header.
VE_Analytics.LogHelp=function()
{
	VE_Analytics.Log("VE | Help Pane","Help");
};


VE_Analytics.Log=function(pageName,NavAction,NavControl,routeLengthObj)
{	
	// Only log if analytics is enabled.
	if (!VE_Analytics.analyticsEnabled)
	{
		return;
	}
	
	s.pageName = pageName;
	var style = window["map"] ? map.GetMapStyle() : "";
	switch(style)
		{
			case 'h':
				s.prop3 = "Hybrid";
			break;
			case 'c':
				s.prop3 = "Street";
			break;
			case 'r':
				s.prop3 = "Road";
			break;
			default:
				s.prop3 = "";	
		}
		
	s.prop4 = window["map"] ? map.GetZoomLevel() : "" ;
	s.prop5 = window["map"] ? VE_Analytics.FormatLatLong(map.GetCenterLatitude(),map.GetCenterLongitude()) : "";
	s.prop6 = NavAction ? NavAction : "";
	s.prop7 = NavControl ? NavControl : "";
	s.prop8 = document.getElementById("what") ? document.getElementById("what").value :"" ;
	s.prop9 = document.getElementById("address") ? (document.getElementById("address").value == "[Type street address...]" ? "" : document.getElementById("address").value) : "";
	
	
	// Fill in City Prop
	var el = document.getElementById("where");
	switch(el.value)
	{
	 case "2": 
		//SFO
		s.prop10 = "San Francisco";
		break;
	 case "1":
		//SEA
		s.prop10 = "Seattle";
		break;
	}
	
	// Fill in View Prop (Race Car, Sports Car, Walk)
	var el = document.getElementById("skin");
	switch(el.value)
	{
	 case "0": 
		//Small Blue
		s.prop11 = "Sports Car";
		break;
	 case "1": 
		//Small Yellow
		//Change car
		//Change dashboard
		s.prop11 = "Race Car";
		break;	 	 
	 case "99":
		//No Skin
		//Change car
		//Change dashboard
		s.prop11 = "Walk";
		break;
	}
		
	var elem = document.getElementById("logging");
	if(elem)
	{
		elem.innerHTML = s.t();
	}
	VE_Analytics.ResetLogProps();
};
/* For Ominiture logging region codes needs to be formatted as follows
 * latitude (1 decimal place)+","+longitude (0 decimal places or an integer)

 */
VE_Analytics.FormatLatLong=function(latitude,longitude)
{	
	return latitude.toFixed(6)+","+longitude.toFixed(6);
};

VE_Analytics.ConvertDistanceToBucket=function(routeLengthObj)
{
	var distance  = routeLengthObj.distance;
	
	if(!distance)
	{
		return "";
	}
    
	if(routeLengthObj.distanceUnit && 
	   routeLengthObj.distanceUnit.indexOf("mi") != -1)
	{ /* convert miles to kilometers first */
		distance = Math.round(distance*1.6093);
	}
	//find the range bucket
	
	for(var i =0;i < VE_Analytics.distanceBuckets.length; i++)
	{
		if(VE_Analytics.distanceBuckets[i].IsInRange(distance))
		{
			return VE_Analytics.distanceBuckets[i].toString();
		}
	}
	
	return "1001 and Above";
};

VE_Analytics.ResetLogProps=function()
{
	s.prop11 = "";
	s.prop12 = "";
	s.prop32 = "";
	s.prop33 = "";
	s.prop34 = "";
	s.prop35 = "";
};