function GetParam(param){
	var s = location.hash;
	var nmIdx = s.indexOf(param + '=');
	if (nmIdx > -1){
		s = s.substr(nmIdx + param.length + 1, s.length - nmIdx);
		for (var i = 0; (i < s.length) && (s.charAt(i) != '&'); ++i);
		return s.substr(0, i);
	}
	return '';
}
function GetID(param){
	if (param) return new Number(GetParam(param));
}
function ModelOutput(Kind){
	this.Kind = Kind;
}
function Model(Description, Fake, Type, GroupOutputCount, GroupOutputCountAdd){
	this.Description = Description;
	this.Outputs = new Array();
	this.Fake = Fake;
	this.Type = Type;
	this.GroupOutputCount = GroupOutputCount;
	this.GroupOutputCountAdd = GroupOutputCountAdd;
}
function MOStr(MN, Out, idx, CtrlCount){
	var
	M = ModelList[MN],
	O = M.Outputs[Out],
	n = 1;
	for (var i = 0; i < Out; i++){
		if (M.Outputs[i].Kind == O.Kind) {n++;}
	}
	if (M.Fake > 0) {

		if (Number(M.Type) == 0){
			n = n+idx*(Number(M.GroupOutputCount) + Number(M.GroupOutputCountAdd));
		}
		if (Number(M.Type) == 1) {
				if (Out >= M.Outputs.length - Number(M.GroupOutputCountAdd)){					
					n = Number(M.GroupOutputCountAdd)*idx + (Number(M.GroupOutputCountAdd)+1)-(M.Outputs.length-Out) + Number(M.GroupOutputCount)*CtrlCount;
				}
				else n = n+idx*Number(M.GroupOutputCount); 			
		}
		
	}		
	return n;
}
function ControllerOutput(Trend, TrendOutput){
	this.Trend = Trend;
	if (TrendOutput > -1)
		this.TrendOutput = TrendOutput;
	else
		this.TrendOutput = -1;
}
function Controller(Type, LampKind){
	this.Type = Type;
	this.LampKind = LampKind;
	this.Outputs = new Array();
}
function KDMOutput(ControllerNumber, OutNumber){
	this.CtrlNumber = ControllerNumber;
	this.OutNumber = OutNumber;
}
function KDM(){
	this.Outputs = new Array();
}
function TrendOutput(Controller, Output){
	this.Controller = Controller;
	this.Output = Output;
}
function Trend(Kind, CtrlI, CtrlU){
	this.Kind = Kind;
	this.CtrlI = CtrlI;
	this.CtrlU = CtrlU;
	this.Outputs = new Array();
	this.Times = new Array();
	this.CalcTimes = new Array();
}
function TrendGroup(Kind){
	this.Kind = Kind;
	this.Trends = new Array();
}
function Step(PhaseNumber, Number, Duration, Tmin, Caption){
	this.PhaseNumber = PhaseNumber;
	this.Number = Number;
	this.Tmin = Tmin;
	this.Duration = Duration;
	this.Caption = Caption;
	this.TrendStates = new Array();
}
function Program(Period, MinPeriod, Name, Offset){
	this.Period = Period;
	this.MinPeriod = MinPeriod;
	this.Name = Name;
	this.Offset = Offset;
	this.Steps = new Array();
}
function Phase(Number){
	this.No = Number;
	this.Cycles = new Array();
        this.NextNo = -1;
}
function PhaseEx(Number, NextPhaseNo){
	this.No = Number;
	this.Cycles = new Array();
        this.NextNo = NextPhaseNo;
}
function DayPlanItem(Time, Cycle, Checked){
	this.Time = Time;
	this.Cycle = Cycle;
	this.Checked = Checked;
}
function DayPlan(Description){
	this.Description = Description;
	this.Items = new Array();
}
function WeekPlanItem(DW, DayPlan){
	this.DW = DW;
	this.DayPlan = DayPlan;
}
function WeekPlan(Description){
	this.Description = Description;
	this.Items = new Array();
}
function YearPlanItem(Dt, WeekPlan){
	this.Dt = Dt;
	this.WeekPlan = WeekPlan;
}
function AdaptiveAlgorithms(algs,l1,l2,l67){
// Все параметры адаптивного управления
	this.algs = algs; // массив алгоритмов
	this.l1 = l1; // true, если используются датчики 1..8
	this.l2 = l2; // true, если используются датчики 9..16
	this.l67 = l67; // true, если микроцикл для l1 - 6, для l2 - 7, иначе - false
}
function AdaptiveAlgorithm(number,title,params,detectors){
// Алгоритм адаптивного управления
	this.number = number; // внутренний номер алгоритма (int)
	this.title = title; // заголовок (string)
	this.params = params; // массив параметров и их значений (AlgParam)
	this.detectors = detectors; // массив детекторов (Detector)
}
function AlgParam(name,value){
// Параметр алгоритма адаптивного управления
	this.name = name; // название параметра (string)
	this.value = value; // значение параметра
}
function Detector(number,phase_number,weight,comment){
// Детектор адаптивного управления
	this.number = number; // Номер (int)
	this.pnumber = phase_number; // Номер фазы (int). если < 0, значит не задана.
	this.weight = weight; // Весовой коэффициент (int)
	this.comment = comment; // Комментарий (string)
}

var 
	CreationDate = "00.00.0000 00:00:00",
	Version = "",
	Description = "",
	SystemID = 0,
	AllRedTime = "",
	ASSUDSystem = "",
	ASUDDFilter = "",
	SeasonTime = "",
	BittDU = "",
	IsExtYearPlan = false,
	IsCalcTimes = false,
	TimeZoneOffset = null,
	ModelList = new Array(),
	ControllerList = new Array(),
	KDMList = new Array(),
	TrendGroupList = new Array(),
	CycleList = new Array(),
	DayPlanList = new Array(),
	WeekPlanList = new Array(),
	YearPlan = new Array(),
	TrendList = new Array(),
	IsAdaptiveControl = false,
	AdaptiveAlgs = AdaptiveAlgorithms(new Array(),false,false,false),
	LampType = ['Есть','Нет (светодиоды)'],
	ModelOutputStr = ['к', 'ж', 'з', 'у'],
	ModelOutputImg = ['RedLight.gif', 'YellowLight.gif', 'GreenLight.gif', 'UniLight.gif'],
	TrendOutputStr = ['красн.', 'желт.', 'зел.', 'лев.', 'центр.', 'прав.', 'нижн.'],
	TrendOutputImg = ['RedLight.gif', 'YellowLight.gif', 'GreenLight.gif', 'UL.gif', 
	  'UM.gif', 'UR.gif', 'DM.gif'],
	TrendGroupKindStr = ['Транспортное','Пешеходное','Пешеходное ЗМ','Стрелка',
	  'Трамвай','ТВП','Стрелка ЗМ', 'Реверсивное', 'Реверсивное с желтым', 'Светильник'],
	TrendGroupImg = ['Transport.gif','Walkman.gif','WalkmanGB.gif','Arrow.gif',
	  'TramL.gif','Call.gif','ArrowGB.gif','reverse.png','reverse3.png', 'LedLight.png'],
	TrendKindStr = ['Т','П','Пм','C','Тл','Тв','Тп','Тс','ТВП','См','Р','Рж', 'СВ'],
	TrendImg = ['Transport.gif','Walkman.gif','WalkmanGB.gif',
	  'Arrow.gif','TramL.gif','TramU.gif','TramR.gif','TramStop.gif','Call.gif','ArrowGB.gif',
	  'reverse.png','reverse3.png', 'LedLight.png'],

	WorkProgs = new Array(),
	Call1Prog = null,
	Call2Prog = null,

	WorkPhaseList = new Array(),
	DispPhaseList = new Array(),
	Call1PhaseList = new Array(),
	Call2PhaseList = new Array(),
	PhaseList = new Array(),

	TPromImg = ['tpGreen.gif','tpGreen.gif','tpGreenBlink.gif',
						'tpYellow.gif','tpRed.gif','tpRed.gif','tpRed.gif','tpRedYellow.gif',
						'tpGreen.gif','tpRed.gif','tpYB.png','tpOff.png'],
						
	TPromImgPrint = ['tpGreenPrint.gif','tpGreenPrint.gif','tpGreenBlinkPrint.gif',
		'tpYellowPrint.gif','tpRedPrint.gif','tpRedPrint.gif','tpRedPrint.gif','tpRedYellowPrint.gif',
		'tpGreenPrint.gif','tpRedPrint.gif','tpYBPrint.png','tpOffPrint.png'],
		
	TPromStr = ['З','З','ЗМ','Ж','К','К','К','КЖ','З','К','ЖМ','ОС'],
	//CycleList = new Array('Минимальный рабочий цикл'),
	DayPlanList = new Array(),
	WeekPlanList = new Array(),
	YearPlan = new Array(),
	DWs = new Array('Пн','Вт','Ср','Чт','Пт','Сб','Вс');
		
function Copyright()
{
	document.writeln('<br /><p class="Copyright">Сформировано ' +
	CreationDate +
	' <i>Конфигуратором контроллеров КДУ</i> ' +
        (Version.length > 0 ? ('v.' + Version) : ('')) + 
        '<br />Copyright&nbsp;&copy&nbsp;2002-2020&nbsp;<a class="Copyright" href="http://comsignal.ru/"><u>ООО&nbsp;&laquo;Комсигнал&raquo;</u></a></p> ');
}

function PageHeader(Items, Links, printHref, printDivId){
	document.write('<table border="0" cellpadding="0" width="100%"><tr><td>');
	document.write('<p class="NavBar">');
	for (var I = 0; I < Items.length;I++) {
		if  (Links[I])
			document.write('<a class="NavLink" href="' + Links[I] + '">' + Items[I] + '</a>');
		else
			document.write(Items[I]);

		if(I < Items.length - 1)
			document.write('<img src="Prev.gif" width="18" height="12" align="top" />');
	}
	document.write('</p></td><td align="right">');
	if (printHref && printHref.length > 0)
		writeLinkMenu('Версия для печати', printHref, printDivId);
	document.write('</td></tr></table><hr>');
}
		
function GetPhase(PhaseNo) 
{
	for (var I = 0; I < WorkPhaseList.length; I++) {
		if (WorkPhaseList[I].No == PhaseNo) return WorkPhaseList[I];
	}
	for (var I = 0; I < DispPhaseList.length; I++) {
		if (DispPhaseList[I].No == PhaseNo) return DispPhaseList[I];
	}
	for (var I = 0; I < Call1PhaseList.length; I++) {
		if (Call1PhaseList[I].No == PhaseNo) return Call1PhaseList[I];
	}
	for (var I = 0; I < Call2PhaseList.length; I++) {
		if (Call2PhaseList[I].No == PhaseNo) return Call2PhaseList[I];
	}
	return null;
}












/***********************************************
* AnyLink CSS Menu script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Ссылка с выпадающим меню */

var disappeardelay = 400; //menu disappear speed onMouseout (in miliseconds)
var enableanchorlink = 1; //Enable or disable the anchor link when clicked on? (1=e, 0=d)
var hidemenu_onclick = 1; //hide menu when user clicks within menu? (1=yes, 0=no)

var ie5 = document.all;
var ns6 = document.getElementById && !document.all;

function getposOffset(what, offsettype){
  var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
  var parentEl = what.offsetParent;
  while (parentEl != null) {
	totaloffset = (offsettype == "left") ? totaloffset + parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
	parentEl = parentEl.offsetParent;
  }
  return totaloffset;
}

function showhide(obj, e, visible, hidden){
  if (ie5 || ns6)
	dropmenuobj.style.left=dropmenuobj.style.top = -500;
  if (e.type == "click" && obj.visibility == hidden || e.type == "mouseover")
	obj.visibility = visible;
  else if (e.type == "click")
	obj.visibility = hidden;
}

function iecompattest(){
  return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge){
  var edgeoffset = 0;
  if (whichedge == "rightedge"){
	var windowedge = ie5 && !window.opera ? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
	dropmenuobj.contentmeasure = dropmenuobj.offsetWidth
	if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
		edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
  }
  else{
	var topedge = ie5 && !window.opera ? iecompattest().scrollTop : window.pageYOffset;
	var windowedge = ie5 && !window.opera ? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
	dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
	if (windowedge - dropmenuobj.y < dropmenuobj.contentmeasure) { 
		edgeoffset = dropmenuobj.contentmeasure+obj.offsetHeight;
		if ((dropmenuobj.y-topedge) < dropmenuobj.contentmeasure) //up no good either?
			edgeoffset = dropmenuobj.y + obj.offsetHeight - topedge;
	}
  }
  return edgeoffset;
}

function dropdownmenu(obj, e, dropmenuID){
  if (window.event) 
	event.cancelBubble=true;
  else 
	if (e.stopPropagation) 
	  e.stopPropagation();
  if (typeof dropmenuobj != "undefined") //hide previous menu
	dropmenuobj.style.visibility="hidden";
  clearhidemenu();
  if (ie5 || ns6){
	obj.onmouseout = delayhidemenu;
	dropmenuobj = document.getElementById(dropmenuID);
	if (hidemenu_onclick) 
		dropmenuobj.onclick = function(){ 
			dropmenuobj.style.visibility = 'hidden';
		}
	dropmenuobj.onmouseover = clearhidemenu;
	dropmenuobj.onmouseout = ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
	showhide(dropmenuobj.style, e, "visible", "hidden");
	dropmenuobj.x = getposOffset(obj, "left");
	dropmenuobj.y = getposOffset(obj, "top");
	dropmenuobj.style.left = dropmenuobj.x-clearbrowseredge(obj, "rightedge") + "px";
	dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight + "px";
  }
  return clickreturnvalue();
}

function clickreturnvalue(){
  if ((ie5 || ns6) && !enableanchorlink) 
	return false;
  return true;
}

function contains_ns6(a, b) {
  while (b.parentNode) {
	if ((b = b.parentNode) == a)
		return true;
  }
  return false;
}

function dynamichide(e){
  if (ie5 && !dropmenuobj.contains(e.toElement))
	delayhidemenu()
  else {
	if (ns6 && e.currentTarget != e.relatedTarget && !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
  }
}

function delayhidemenu(){
  delayhide = setTimeout("dropmenuobj.style.visibility='hidden'", disappeardelay);
}

function clearhidemenu(){
  if (typeof delayhide != "undefined")
	clearTimeout(delayhide);
}


function writeLinkMenu(linkText, linkHref, dropedDivId) {
  enableanchorlink = (linkHref.length < 2) ? 0 : 1;
  if (enableanchorlink == 0)
    document.write('<a href="' + linkHref +
      '" onClick="return clickreturnvalue()"' + 
      ' onMouseover="dropdownmenu(this, event, \'' + dropedDivId + '\')">' + linkText + '</a>');
  else
    document.write('<a href="' + linkHref + '">' + linkText + '</a>');
}
