﻿function ACCAdvancedPropManager()
{
	this.strManagerType = "AdvancedPropManager";
	this.arrSelectors = new Array();
	this.arrManagers = new Array();
	this.selPedestrian = null;
	this.selBlind = null;
	this.selWheel = null;
	this.selUser = null;
	this.divForm = null;
	
	var me = this;
	
	this.AddSelectorSetting = function(selector)
	{
		selector.ExtendClickEvent(me.SelectorChanged);
		if (selector.strRole == "Pedestrian")
			me.selPedestrian = selector;
		else if (selector.strRole == "Blind")
			me.selBlind = selector;
		else if (selector.strRole == "Wheel")
			me.selWheel = selector;
		else
			me.selUser = selector;
		me.arrSelectors[me.arrSelectors.length] = selector;
	}
	
	this.AddDetailedManager = function(detailedManager)
	{
		me.arrManagers[me.arrManagers.length] = detailedManager;	
	}
	
	this.SelectorChanged = function()
	{
		var pedSetting = null;
		if (me.selPedestrian.GetChecked())
			pedSetting = g_pedPedestrian;
		else if (me.selBlind.GetChecked())
			pedSetting = g_pedBlind;
		else if (me.selWheel.GetChecked())
			pedSetting = g_pedWheel;

		if (pedSetting == null)
			return; // ha a sajat user gombon kattint, akkor nem csinal semmit 

		g_pedUser = pedSetting.GetCopy();
		me.RemoveDynamicForm();

		var j = 0;
		for (j = 0; j < me.arrManagers.length; j++)
		{
			me.arrManagers[j].SetPedSettingValue(g_pedUser);
		}
	}

	this.ManagerValueChanged = function(strRole, strSelectedValue)
	{
		g_pedUser[strRole] = strSelectedValue;
	
		if (g_pedUser.Compare(g_pedPedestrian) && me.selPedestrian != null)
		{
			me.selPedestrian.SetChecked(true);
		}
		else if (g_pedUser.Compare(g_pedBlind) && me.selBlind != null)		
		{
			me.selBlind.SetChecked(true);
		}
		else if (g_pedUser.Compare(g_pedWheel) && me.selWheel != null)
		{
			me.selWheel.SetChecked(true);
		}
		else if (me.selUser != null)
		{
			me.selUser.SetChecked(true);
		}
	}


	this.AddHiddenInput = function(strName, strValue)
	{
		if(me.divForm == null || me.divForm.parentNode == null)
		{
			var form = document.getElementsByTagName("form")[0];
			me.divForm = NewTag('div', form, form.firstChild);
		}
		//NewTextTag(strName, me.divForm);
		var input = NewTag("input");
		input.type = "hidden";
		//input.type = "text";
		input.style.width = "2em";
		input.name = strName;
		input.value = strValue;

		AddTag(input, me.divForm);
	}
	
	this.RemoveDynamicForm = function()
	{
		if(me.divForm && me.divForm.parentNode)
		{
			me.divForm.parentNode.removeChild(me.divForm);
			me.divForm = null;
		}
	}

	this.CreateOKButton = function()
	{
		var arrInputs = document.getElementsByTagName("input");
		if(arrInputs != null)
		{
			for(var i=0; i<arrInputs.length; i++)
			{
				if(arrInputs[i].name == "btnRouteParamsOK")
					return;
			}
		}
		me.AddHiddenInput("btnRouteParamsOK", "OK");
	}
	
	this.CreatePedPunishInput = function(strPedPunishItem, pedPunish)
	{
		me.AddHiddenInput("ctl00$body$"+ strPedPunishItem+ "_bEnable", pedPunish.bEnable ? "on" : "off");
		me.AddHiddenInput("ctl00$body$"+ strPedPunishItem+ "_dMul", pedPunish.dMultiplier);
		me.AddHiddenInput("ctl00$body$"+ strPedPunishItem+ "_iAbs", pedPunish.iAbsolute);
	}

	this.CreateDynamicForm = function()
	{
		me.RemoveDynamicForm();
		if (!g_pedUser.Compare(g_pedPedestrian) && !g_pedUser.Compare(g_pedBlind) && !g_pedUser.Compare(g_pedWheel))
		{
			//VehicleTypes
			me.AddHiddenInput("ctl00_body_s_iVehicles", g_pedUser.iVehicles);

			// PedPunishes
			me.CreatePedPunishInput("ppPedestrianBicycle", g_pedUser.ppPedestrianBicycle);     // Pedestrian + bicycle.
			me.CreatePedPunishInput("ppPedestrianMotorized", g_pedUser.ppPedestrianMotorized);     // Pedestrian + motorized vehicle.
			me.CreatePedPunishInput("ppPavedPoor", g_pedUser.ppPavedPoor);     // Poor quality paved.
			me.CreatePedPunishInput("ppUnPaved", g_pedUser.ppUnPaved);     // Unpaved.
			me.CreatePedPunishInput("ppNonTactiled", g_pedUser.ppNonTactiled);     // Non-tactiled route.
			me.CreatePedPunishInput("ppStairs", g_pedUser.ppStairs);     // Stairs.
			me.CreatePedPunishInput("ppHighGradient", g_pedUser.ppHighGradient);     // Sheer.
			me.CreatePedPunishInput("ppLowGradient", g_pedUser.ppLowGradient);     // Descent.
			me.CreatePedPunishInput("ppTolled", g_pedUser.ppTolled);     // Pay.
			me.CreatePedPunishInput("ppHighCurbside", g_pedUser.ppHighCurbside);     // High curbside.
			me.CreatePedPunishInput("ppPedCrossing", g_pedUser.ppPedCrossing);     // Pedestrian crossing (zebra).
			me.CreatePedPunishInput("ppOtherPassThrough", g_pedUser.ppOtherPassThrough);      // Other pass through possibility (no ped.crossing, subway, overpass).
			me.CreatePedPunishInput("ppNoTrafficLight", g_pedUser.ppNoTrafficLight);     // Crossing without traffic light.
			me.CreatePedPunishInput("ppNoNoticeSignal", g_pedUser.ppNoNoticeSignal);     // Crossing without notice signal.
			me.CreatePedPunishInput("ppNoPressButton", g_pedUser.ppNoPressButton);     // Crossing with no press button.
			me.CreatePedPunishInput("ppMovingStairs", g_pedUser.ppMovingStairs);     // Moving stairs.
			me.CreatePedPunishInput("ppElevator", g_pedUser.ppElevator);     // Elevator.

			me.CreateOKButton();
		}
	}

}