var map = null;
var pinID = 1;
var pict='Images/submit.jpg';
var obj

function GetDataViaAjax()
	{
		try
		{
			obj=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e1)
		{
			try
			{
				obj=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e2)
			{
				obj=null;
			}
		}
		if (obj!=null)
		{
			//try
			//{
			//alert('Before Process');
			var ddlTypeVal=document.getElementById('ddlType').value
			var ddlStateVal=document.getElementById('ddlState').value
			//alert(ddlTypeVal);
			//alert(ddlStateVal);
			obj.onreadystatechange=ProcessResponse			
			//obj.open("GET","http://www.desicrunch.com/GetMapInfo.aspx?strPlaceType="+ ddlTypeVal + "&strState=" + ddlStateVal,  true);
			obj.open("GET","GetMapInfo.aspx?strPlaceType="+ ddlTypeVal + "&strState=" + ddlStateVal,  true);
			obj.send(null);
			//}
			//catch(err)
			//{ alert(err.message); }
			
		}
		return false;
	}
function ProcessResponse()
	{
		if (obj.readystate==4)
		{
			if (obj.status==200)
			{
			 
			
				var dsPlace=obj.responseXML.documentElement; 				
				var PlaceName= dsPlace.getElementsByTagName("PlaceName");
				var PlaceAddress= dsPlace.getElementsByTagName("PlaceAddress");
				var City= dsPlace.getElementsByTagName("City");
				var State= dsPlace.getElementsByTagName("State");
				var PhoneNo= dsPlace.getElementsByTagName("PhoneNo");
				var PlaceType= dsPlace.getElementsByTagName("PlaceType");
				var Description= dsPlace.getElementsByTagName("Description");
				var Lat= dsPlace.getElementsByTagName("Lat");
				var Long= dsPlace.getElementsByTagName("Long");
				var Address
				//alert(PlaceName.length);
				for (var count = 0; count < PlaceName.length; count++)
				{	
					//Address=trim(PlaceAddress[count].text) +', ' + trim(City[count].text) +', '+ trim(State[count].text) + ', ' + trim(PhoneNo[count].text);
					//Address=trim(PlaceAddress[count].text) +', ' + trim(PhoneNo[count].text);
					var pin1 = new VEPushpin(pinID, new VELatLong(Lat[count].text, Long[count].text),null, 
					PlaceName[count].text,PlaceAddress[count].text+'  '+PhoneNo[count].text);
					map.AddPushpin(pin1);
					pinID++;
				}
				map.SetZoomLevel(5);
			}
			else
			{
				alert("Error in retrivieing data");
			}
		}
	}
function AddPins()
	{
		var pin1 = new VEPushpin(pinID, 
					new VELatLong(39.42631, -74.50224), 
					null, 
					'Shreeji Grocery', 
					'200 New Jersey Ave Absecon, NJ, (609)272-1044'
					);
		map.AddPushpin(pin1);
		pinID++;
	}
function GetMap()
	{
		try
		{
			map = new VEMap('myMap');
			map.LoadMap();
			//AddPinGrocery();
			//map.ShowDashboard();
			//map.Find('Midland Park','31 Oak Ave, Paramus,NJ','1',onFindResults);
		}
		catch(err)
		{ alert(err.message); }
	}
function FindDetails()
{
	//alert('In Details');
	map.Find(document.getElementById('txtWhat').value,document.getElementById('txtWhere').value,'1',onFindResults);
}
function FindBoth()
	{
		try
		{
			
			var ddlTypeTxt=document.getElementById('ddlType')[document.getElementById('ddlType').selectedIndex].innerHTML;
			var ddlTypeVal=document.getElementById('ddlType').value
			var ddlStateTxt=document.getElementById('ddlState')[document.getElementById('ddlState').selectedIndex].innerHTML;
			var ddlStateVal=document.getElementById('ddlState').value
			var varWhere='Elizabeth,' +','+ddlStateVal+', '+ddlStateTxt			
			//alert(ddlTypeVal);
			switch(ddlTypeVal)
			{
				case 'Indian Grocery Store':
					if(ddlStateVal=='NJ')
					{
						AddPinGrocery();
					}
					else
					{
						alert('Only NJ currently');
					}
					break;
				case 'Indian Movie Theater':
					//alert('Movie');
					break;
			}	
			
			
			//map.Find(document.getElementById('txtWhat').value,varWhere,'1',onFindResults);			
			
		}			
		catch (err)
		{ alert(err.message); }
	}
function AddPinTheater()
	{
		
	}
function AddPinGrocery()
	{
		var pin1 = new VEPushpin(pinID, 
					new VELatLong(39.42631, -74.50224), 
					null, 
					'Shreeji Grocery', 
					'200 New Jersey Ave Absecon, NJ, (609)272-1044'
					);
		map.AddPushpin(pin1);
		pinID++;
		var pin2 = new VEPushpin(pinID, 
					new VELatLong(39.425615,-74.50672), 
					null, 
					'Pinkys Corner', 
					'209 S New Rd Apt D,Absecon, NJ, (609)407-0033'
					);
		map.AddPushpin(pin2);
		pinID++;
		var pin3 = new VEPushpin(pinID, 
					new VELatLong(39.42631, -74.50224), 
					null, 
					'V G Deli'
					);
		map.AddPushpin(pin3);
		pinID++;
	}
function ShowControl()         
	{            
		map.ShowDashboard();         
	}         
function AddPinShreeji()
	{
		var pin1 = new VEPushpin(pinID, 
					new VELatLong(39.42631, -74.50224), 
					null, 
					'Shreeji Grocery', 
					'A Indian grocery store in New Jersey'
					);
		map.AddPushpin(pin1);
		pinID++;		
	}  
function HideControl()         
	{            
		map.HideDashboard();         
	}
function FindLoc()
	{
		try
		{
			map.FindLocation(document.getElementById('txtWhere').value);
		}			
		catch (err)
		{ alert(err.message); }
	}

function onFindResults(findResults)
	{
		var results="Find Results:\n";
		for (r=0; r<findResults.length; r++)
		{
		//results+=findResults[r].Name + ", " + findResults[r].Description+"\n";
			results+=findResults[r].Name + ", " + findResults[r].LatLong + ", " + findResults[r].Description+"\n";
		}
		alert(results);
	}
function ClearMap()
	{		
		//alert('Clear Map');
		try
		{
			//VEMap.Clear();
			map.DeleteAllPushpins();
		}			
		catch (err)
		{
			alert(err.message);
		}
	}
function FindRoute()			
	{
		try
		{
			//document.Form1.chkRoute.value
			//alert(document.Form1.chkRoute.checked.value);
			var varFrom=document.getElementById('txtFrom').value
			var varTo=document.getElementById('txtTo').value
			//map.GetRoute("Space Needle", "Microsoft",null,null,onGotRoute);
			map.GetRoute(varFrom,varTo,null,null,onGotRoute);
			/*if (document.Form1.chkRoute.checked)
			{
				alert('Yes');
				map.GetRoute(varFrom,varTo,null,null,onGotRoute);
			}
			else
			{
				alert('No');
				//map.GetRoute(varFrom,varTo);
				map.GetRoute(varFrom,varTo,null,null,onGotRoute);
			}*/
		}			
		catch (err)
		{
			alert(err.message);
		}
	}
function show()
	{
		var theContents = document.getElementById('ddlState')[document.getElementById('ddlState').selectedIndex].innerHTML;
		window.alert(theContents);
	}
function onGotRoute(route)
	{           
	var routeinfo="Route info:\n\n";            
	routeinfo+="Total distance: ";            
	routeinfo+=   route.Itinerary.Distance+" ";            
	routeinfo+=   route.Itinerary.DistanceUnit+"\n";                        
	var steps="";            
	var len = route.Itinerary.Segments.length;               
	for(var i = 0; i < len ;i++)               
	{                  
	steps+=route.Itinerary.Segments[i].Instruction+" -- (";                  
	steps+=route.Itinerary.Segments[i].Distance+") ";                  
	steps+=route.Itinerary.DistanceUnit+"\n";               
	}            
	routeinfo+="Steps:\n"+steps;            
	alert(routeinfo);         
	}
function AddMyControl()         
	{   
		var el = document.createElement("div");
		el.style.top ="10px";
		el.style.left = "10px";
		el.style.border = "2px solid black";
		el.style.background = "White";
		el.innerHTML = "my control";
		map.AddControl(el);         
	}
function AddPinHinduTemple()
	{
		var pin1 = new VEPushpin(pinID, 
				new VELatLong(39.836474,-75.000559), 
				null, 
				'Hindu Temple', 
				'A Hindu Temple in Burlington, New jersey'
				);
		map.AddPushpin(pin1);
		pinID++;
	}
function AddPin()
	{   
		var pin1 = new VEPushpin(pinID, 
					new VELatLong(27.69, 85.313), 
					null, 
					'Kathmandu', 
					'A street scene in Kathmandu'
					);
		map.AddPushpin(pin1);
		pinID++;
		var pin2 = new VEPushpin(pinID, 
					new VELatLong(32.78612, -96.79985), 
					null, 
					'Dallas', 
					'A street scene in Dallas'
					);
		map.AddPushpin(pin2);
		pinID++;
		
		var pin3 = new VEPushpin(pinID, 
					new VELatLong(32.915333, -96.638489), 
					null, 
					'Garland', 
					'A street scene in Garland'
					);
		map.AddPushpin(pin3);
		pinID++;
		
	}