﻿function ExtraInfo(div, pTopoliszMap)
{
	this.div = div;
	this.pTopoliszMap = pTopoliszMap;

	this.cbxDisplayCoords = null;

	this.cbxDailyNews = null;
	this.cbxTrafficChanges = null;
	this.cbxWeather = null;
	this.cbxUTV = null;
	this.cbxTMC = null;

	this.bDailyNews = false;
	this.bTrafficChanges = false;
	this.bWeather = false;

	this.pPoiTree = null;
	this.bResendNeeded = false;
	this.bUnderPoiDrawing = false;

	this.pPoiBox = new POIBOX (null, pTopoliszMap, "layertype");

	var me = this;

	this.SetDailyNews = function(bEnable)
	{
		me.bDailyNews = bEnable;
		if(me.cbxDailyNews)
		{
			me.cbxDailyNews.checked = bEnable;
		}
		if(bEnable)
			me.SetTrafficChanges(false);
	}

	this.SetTrafficChanges = function(bEnable)
	{
		me.bTrafficChanges = bEnable;
		if(me.cbxTrafficChanges)
		{
			me.cbxTrafficChanges.checked = bEnable;
		}
		if(bEnable)
			me.SetDailyNews(false);
	}

	this.SetWeather = function(bEnable)
	{
		me.bWeather = bEnable;
		if(me.cbxWeather)
		{
			me.cbxWeather.checked = bEnable;
		}
	}

	this.SetUTV = function(bEnable)
	{
		me.bUTV = bEnable;
		if(me.cbxUTV)
		{
			me.cbxUTV.checked = bEnable;
		}
	}
	
	this.Init = function()
	{
		me.pTopoliszMap.AddDrawRouteCallbackListener (me.OnDrawRouteReturned);
		g_Babel.AddListener(me.Show);
	}
	
	this.Show = function()
	{
		while(me.div.hasChildNodes())
			me.div.removeChild(me.div.firstChild);
	
		// Extra infok

		var panel = new Panel(me.div);
		panel.CreateCaption(g_Babel.GetWord("capMapSettings"), "design/ICON_settings_off.gif", 14, 14);
		var colorpanel = new ColorPanel(me.div);

		var fieldset = NewTag('fieldset', colorpanel.td);
		var legend = NewTag('legend', fieldset);
		NewTextTag(g_Babel.GetWord("capFunctionality"), legend);
		
		var input = NewTag('input');
		input.setAttribute('type', 'checkbox');
		input.style.marginRight = "4px";
		input.style.paddingRight = "0px";
		input.setAttribute("id", "cbxDisplayCoords");
		AddTag (input, fieldset);
		AddEvent(input, "click", me.SwitchDisplayCoords);
		input.checked = me.pTopoliszMap.bDisplayCoords;
		me.cbxDisplayCoords = input;

		var label = NewTag('label', fieldset);
		label.setAttribute('for', 'cbxDisplayCoords');
		NewTextTag(g_Babel.GetWord('cDisplayCoords'), label);
		NewTag('br', fieldset);


		var fieldset = NewTag('fieldset', colorpanel.td);
		var legend = NewTag('legend', fieldset);
		NewTextTag(g_Babel.GetWord("capExtraInformations"), legend);

		var divFovinform = NewTag('div', fieldset);
		divFovinform.className = "fovinform";
		var a = NewTag('a', divFovinform);
		a.style.color = "blue";
		a.setAttribute('href', 'http://fovinform.hu');
		a.setAttribute('target', '_blank');
		var img = NewTag('img', a);
		SetImage(img, "images/partners/fovinformlogo.jpg", 46, 62, "Fővinform");
		NewTag('br', divFovinform);
		var a = NewTag('a', divFovinform);
		a.style.color = "blue";
		a.setAttribute('href', 'http://www.fovinform.hu/home/copyright.php');
		a.setAttribute('target', '_blank');
		a.setAttribute('alt', 'Copyright');
		NewTextTag("\u00A9 Copyright", a);


		var table = NewTag('table', fieldset);
		table.cellPadding = 0;
		table.cellSpacing = 5;
		var tbody = NewTag('tbody', table);

		var tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		td.style.verticalAlign = "top";
		td.style.padding = "0px";
		var input = NewTag ('input');
		input.setAttribute('type', 'checkbox');
		input.style.paddingRight = "0px";
		input.setAttribute("id", "cbxDailyNews");
		AddTag (input, td);
		AddEvent(input, "click", me.SwitchDailyNews);
		me.cbxDailyNews = input;

		var td = NewTag('td', tr);
		var label = NewTag('label', td);
		label.setAttribute('for', 'cbxDailyNews');
		NewTextTag(g_Babel.GetWord('cDailyNews'), label);

		var tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		td.style.verticalAlign = "top";
		td.style.padding = "0px";
		var input = NewTag ('input');
		input.setAttribute('type', 'checkbox');
		input.style.paddingRight = "0px";
		input.setAttribute("id", "cbxTrafficChanges");
		AddTag (input, td);
		AddEvent(input, "click", me.SwitchTrafficChanges);
		me.cbxTrafficChanges = input;

		var td = NewTag('td', tr);
		var label = NewTag('label', td);
		label.setAttribute('for', 'cbxTrafficChanges');
		NewTextTag(g_Babel.GetWord('cTrafficChange'), label);
/*
		var tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		td.style.verticalAlign = "top";
		td.style.padding = "0px";
		var input = NewTag ('input');
		input.setAttribute('type', 'checkbox');
		input.style.paddingRight = "0px";
		input.setAttribute("id", "cbxWeather");
		AddTag (input, td);
		AddEvent(input, "click", me.SwitchWeather);
		me.cbxWeather = input;

		var td = NewTag('td', tr);
		var label = NewTag('label', td);
		label.setAttribute('for', 'cbxWeather');
		NewTextTag(g_Babel.GetWord('cWeather'), label);
*/
        // UTV
		var tr = NewTag('tr', tbody);
		var td = NewTag('td', tr);
		td.style.verticalAlign = "top";
		td.style.padding = "0px";
		var input = NewTag ('input');
		input.setAttribute('type', 'checkbox');
		input.style.paddingRight = "0px";
		input.setAttribute("id", "cbxUTV");
		input.checked = me.pTopoliszMap.IsDrawUTV();
		AddTag (input, td);
		AddEvent(input, "click", me.SwitchUTV);
		me.cbxUTV = input;
		
		me.pTopoliszMap.AddDrawUTVChangedListener(me.RefreshDrawUTVState);

		var td = NewTag('td', tr);
		var label = NewTag('label', td);
		label.setAttribute('for', 'cbxUTV');
		NewTextTag(g_Babel.GetWord('utv'), label);
		
		var divUTV = NewTag('div', td);
		divUTV.style.display = "inline";
		divUTV.style.fontSize = "10px";
		var a = NewTag("a", divUTV);
		a.setAttribute("href", "javascript:void(0)");
		a.style.paddingLeft = "10px";
		a.onclick = function () { window.open("http://www.utv.hu"); }
		NewTextTag("www.utv.hu", a);

		// TMC
		if(g_InitSettings.bTMC)
		{
			var tr = NewTag('tr', tbody);
			var td = NewTag('td', tr);
			td.style.verticalAlign = "top";
			td.style.padding = "0px";
			var input = NewTag ('input');
			input.setAttribute('type', 'checkbox');
			input.style.paddingRight = "0px";
			input.setAttribute("id", "cbxTMC");
			input.checked = me.pTopoliszMap.Get_bDrawTMC();
			AddTag (input, td);
			AddEvent(input, "click", me.SwitchTMC);
			me.cbxTMC = input;
			
			me.pTopoliszMap.AddDrawTMCChangedListener(me.RefreshDrawTMCState);

			var td = NewTag('td', tr);
			var label = NewTag('label', td);
			label.setAttribute('for', 'cbxTMC');
			NewTextTag(g_Babel.GetWord('cbxTMC'), label);
			
			var divTMC = NewTag('div', td);
			divTMC.style.display = "inline";
			divTMC.style.fontSize = "10px";
			var a = NewTag("a", divTMC);
			a.setAttribute("href", "javascript:void(0)");
			a.style.paddingLeft = "10px";
			a.onclick = function () { window.open("http://www.trafficnav.hu"); }
			NewTextTag("www.trafficnav.hu", a);
		}


		// Réteges poik
		var fieldset = NewTag('fieldset', colorpanel.td);
		var legend = NewTag('legend', fieldset);
		NewTextTag(g_Babel.GetWord("capMapLayers"), legend);
		var div = NewTag('div', fieldset);
		me.FillTree(div);
		
		NewTag('hr', me.div);
		
		var div = NewTag('div', me.div);
		me.pPoiBox.SetDiv(div);
		me.pPoiBox.Show();
	}
	
	this.FillTree = function(div)
	{
		if (g_TopoliszControls.pLayerPoiTreeMemo == null)
		{
			if(g_arrPoiTypes != null)
			{
				var arrTreeItems = new Array();
				//arrTreeItems[0] = new CTreeItem(0, g_Babel.GetWord('AllPoiTypes'), 0, false, false);
				var bAllPoisOnMap = true;
				for(var i=0; i<g_arrPoiTypes.length; i++)
				{
					var pType = g_arrPoiTypes[i];
					var label = g_Babel.GetWord("poi" + pType.iID);
					if(g_arrPoiTypes[i].iCount > 0)
						label += " (" + g_arrPoiTypes[i].iCount +")";
					//if (label == "") label = "*" + pType.iID + " " + pType.strName;
					arrTreeItems[arrTreeItems.length] = new CTreeItem(pType.iID, label/*pType.strName*/, pType.iLevel, pType.bOnMap, false, pType.bShowInTree);
					if(!pType.bOnMap)
						bAllPoisOnMap = false;
				}
				arrTreeItems[0].SetChecked(bAllPoisOnMap);
				
				me.pPoiTree = new CTree(div, arrTreeItems);
													
				me.pPoiTree.OnCheckChanged = function () {me.OnTreeCheckChanged()};
				me.pPoiTree.Show();
				arrTreeItems[0].Open();
			}
		}
		else
		{
			me.pPoiTree = g_TopoliszControls.pLayerPoiTreeMemo;		
		}
	}	
	
	
	this.Hide = function()
	{
		Hide(me.div);
	}
	
	this.Unhide = function()
	{
		Show(me.div);
			me.pTopoliszMap.SetPoiLayers (me.pPoiTree.GetCheckedIDsInStr());		
			me.pTopoliszMap.DrawRoute ();				
		
	}

	this.SwitchDisplayCoords = function()
	{
		me.pTopoliszMap.SetDisplayCoords(!me.pTopoliszMap.bDisplayCoords);
		if(me.cbxDisplayCoords)
		{
			me.cbxDisplayCoords.checked = me.pTopoliszMap.bDisplayCoords;
		}
	}

	this.SwitchDailyNews = function ()
	{
		me.SetDailyNews(!me.bDailyNews);

		me.pTopoliszMap.RemovePinBoxes ("dailynews");
		me.pTopoliszMap.RemovePinLabels ("dailynews");
		me.pTopoliszMap.pMarkers.DeleteAllWithType ("dailynews");

		if (me.bDailyNews)
		{
			me.pTopoliszMap.NoSessionServer.CallFunction("GetNapiHirek", "categories=1", 0, me.DrawDailyNews);
		}
	}

	this.SwitchTrafficChanges = function ()
	{
		me.SetTrafficChanges(!me.bTrafficChanges);

		me.pTopoliszMap.RemovePinBoxes ("dailynews");
		me.pTopoliszMap.RemovePinLabels ("dailynews");
		me.pTopoliszMap.pMarkers.DeleteAllWithType ("dailynews");

		if (me.bTrafficChanges)
		{
			me.pTopoliszMap.NoSessionServer.CallFunction("GetNapiHirek", "categories=3", 0, me.DrawDailyNews);
		}
	}

	this.DrawDailyNews = function (dailynewslist, pDummy, iCommandID) 
	{
		var length = dailynewslist.length;
		var i = 0;
		for ( i = 0; i < length; i++)
		{				
            /*NEW*/
            
            var type = "dailynews";
            var dX = dailynewslist [i].eovx;
            var dY = dailynewslist [i].eovy;
                                                                                                
            var marker = new Marker(me.pTopoliszMap, type, dX, dY, null, null);
            marker.SetProperty ("start_button", false);
            marker.SetProperty ("through_button", false);
            marker.SetProperty ("stop_button", false);
            marker.SetProperty ("panorama_button", false);
            marker.SetProperty ("pinnumber", 0);
            marker.SetProperty ("handle_details", true);                        
			marker.SetProperty ("pin_css_class", "markerDailyNews");
			marker.SetProperty ("div_label_sign_class", "markerDailyNews");
			marker.SetProperty ("pin_img_url", "http://utvonal.bkv.hu/napihir/public.ashx?appID=NapiHirek&Command=GetImage&id=" + dailynewslist [i].signid);
			marker.SetProperty ("pin_img_width", 38);
			marker.SetProperty ("pin_img_height", 38);
			marker.SetProperty ("pin_img_refx", 20);
			marker.SetProperty ("pin_img_refy", 20);			
			marker.SetProperty ("label_dx", 0);
			marker.SetProperty ("label_dy", -9);						
			marker.SetProperty ("delete_marker_on_label_close", false);
			marker.SetProperty ("caption", unescape(dailynewslist [i].shortdescription));
			marker.SetProperty ("show_coordinates", me.pTopoliszMap.bDisplayCoords);
																	
									
			var divDetails = NewTag("div");
			NewTextTag(unescape(dailynewslist [i].longdescription), divDetails);			
			marker.SetProperty ("details_to_show", divDetails);     
			marker.SetProperty("fix_label_on_click", true);				
		    me.pTopoliszMap.pMarkers.Add (marker) ;	 //dailynews						
		}						
		
		// Bp
		me.pTopoliszMap.ZoomToPoint (19.1,47.48, 10000);
	}



	this.SwitchWeather = function ()
	{
		me.SetWeather(!me.bWeather);

		if (me.bWeather)
		{
			me.pTopoliszMap.NoSessionServer.CallFunction("GetWeather", "", 0, me.DrawWeather);
		}
		else
		{
			me.pTopoliszMap.RemovePinBoxes ("weather");	
			me.pTopoliszMap.RemovePinLabels ("weather");
			me.pTopoliszMap.pMarkers.DeleteAllWithType ("weather");
		}
	}

	this.DrawWeather = function (weatherlist, pDummy, iCommandID) 
	{
		if (weatherlist == null)
			return;
		var length = weatherlist.length;
		var i = 0;
		for ( i = 0; i < length; i++)
		{
			var pMarker = me.pTopoliszMap.pMarkers.AddWeather (me.pTopoliszMap, weatherlist[i]); //weather
		}
		me.pTopoliszMap.DrawRoute ();
	}

	this.SwitchUTV = function () 
	{
		me.pTopoliszMap.SetDrawUTV(!me.pTopoliszMap.IsDrawUTV());
		me.RefreshDrawUTVState();
	}
	
	this.RefreshDrawUTVState = function()
	{
		if(me.cbxUTV)
		{
			me.cbxUTV.checked = me.pTopoliszMap.IsDrawUTV();
		}
	}

	this.OnTreeCheckChanged = function ()
	{
		if (me.pTopoliszMap)
		{
			if (me.pTopoliszMap.SetPoiLayers)
			{
				me.pTopoliszMap.SetPoiLayers (me.pPoiTree.GetCheckedIDsInStr());
				if (me.bUnderPoiDrawing == false)
				{
					me.bUnderPoiDrawing = true;
					//me.pTopoliszMap.SetPoiLayers (me.pPoiTree.GetCheckedIDsInStr());
					me.pTopoliszMap.DrawRoute ();
				}
				else
				{
					me.bResendNeeded = true;
				}
			}
		}
	}

	this.OnDrawRouteReturned = function ()
	{
		me.bUnderPoiDrawing = false;
		if (me.bResendNeeded == true)
		{
			me.bResendNeeded = false;
			me.OnTreeCheckChanged();
		}
	}

	this.ResetPoiLayers = function ()
	{
		me.pPoiBox.ResetLayerPoi ();
		//me.pPoiTree.Reset ();
		//me.pTopoliszMap.SetPoiLayers (me.pPoiTree.GetCheckedIDsInStr());
		me.pTopoliszMap.SetPoiLayers ("");
		me.pTopoliszMap.DrawRoute ();
	}


	this.SwitchTMC = function () 
	{
		me.pTopoliszMap.SetDrawTMC(!me.pTopoliszMap.Get_bDrawTMC());
		me.RefreshDrawTMCState();
	}
	
	this.RefreshDrawTMCState = function()
	{
		if(me.cbxTMC)
		{
			me.cbxTMC.checked = me.pTopoliszMap.Get_bDrawTMC();
		}
	}


	me.Init();
}