// $Revision: 4268 $

var IDRoundFieldErrorCaption = "IDRoundFieldErrorCaption";
var IDRoundFieldErrorLimitCaption = "IDRoundFieldErrorLimitCaption";
var IDRoundFieldSpeedCaption = "IDRoundFieldSpeedCaption";
var IDRoundFieldTimeCaption = "IDRoundFieldTimeCaption";
var IDRoundFieldProgressCaption = "IDRoundFieldProgressCaption";

var RoundFieldErrorCaption = new TRoundField(IDRoundFieldErrorCaption, "white", "#AB0000");
var RoundFieldErrorLimitCaption = new TRoundField(IDRoundFieldErrorLimitCaption, "white", "#939393");
var RoundFieldSpeedCaption = new TRoundField(IDRoundFieldSpeedCaption, "white", "#5FAC20");
var RoundFieldTimeCaption = new TTimeRoundField(IDRoundFieldTimeCaption, "white", "#3B91D3");

function TError(iDErrorSpan)
{
  this.Header = "Ошибки";
  this.IDErrorSpan = iDErrorSpan;
  this.IDBody = "ErrorPnlBody";
  this.IDHeader = "ErrorPnlHeader";
  this.Width = "180";
  this.BRemoved = false;
  
  this.NumOfMistakes = 0;
  this.MaxNumOfMistakes = -1;
  this.MaxNumOfMistakesCaption = "Лимит";
  
  this.SetNumOfMistakes = SetNumOfMistakes;
  this.SetMaxNumOfMistakes = SetMaxNumOfMistakes;
  this.SetMaxNumOfMistakesCaption = SetMaxNumOfMistakesCaption;
  this.GetNumOfMistakes = GetNumOfMistakes;
  this.GetMaxNumOfMistakes = GetMaxNumOfMistakes;
  this.Generate = Generate;
  this.Update = Update;
  
  this.Hide = function()
  {
    document.getElementById(this.IDErrorSpan).style.display = "none";
  };
  this.Show = function()
  {
    document.getElementById(this.IDErrorSpan).style.display = "";
  };
  
  this.Remove = function()
  {
    document.getElementById(this.IDErrorSpan).innerHTML = "";
    this.BRemoved = true;
  };

function SetNumOfMistakes(num)
{
  this.NumOfMistakes = num;
}

function SetMaxNumOfMistakes(num)
{
  this.MaxNumOfMistakes = num;
}

function SetMaxNumOfMistakesCaption(text)
{
  this.MaxNumOfMistakesCaption = text;
}

function Update()
{
if(this.BRemoved) return;
//alert("test");
//document.getElementById('NumOfMistakes').innerHTML = RoundFieldErrorCaption.Place();
//stop;

//RoundFieldErrorCaption.Update(this.NumOfMistakes);

if(GetExType() != 32  &&
    GetExType() != 3  &&
    GetExType() != 4)
{
//  RoundFieldErrorLimitCaption.SetStrPre(this.MaxNumOfMistakesCaption);
//  document.getElementById('MaxNumOfMistakes').innerHTML = RoundFieldErrorLimitCaption.Place();
//  RoundFieldErrorLimitCaption.Update(this.MaxNumOfMistakes);
}
else
{
//  RoundFieldErrorCaption.Hide();
//  RoundFieldErrorLimitCaption.SetStrPre("&nbsp;");
//  document.getElementById('MaxNumOfMistakes').innerHTML = "&nbsp;";
  //RoundFieldErrorLimitCaption.Update("&nbsp;");
}

}

function GetNumOfMistakes()
{
  return this.NumOfMistakes;
}

function GetMaxNumOfMistakes()
{
  return this.MaxNumOfMistakes;
}

this.isAllowableMistakes = function()
{
  return  (this.NumOfMistakes <= this.MaxNumOfMistakes);
};

this.SetFat = function(bFat)
{
  var sFat = "";
  if(bFat)
    var sFat = "Fat";
    
  for(var i = 1; i < 10; i++)
    document.getElementById("IDTdPanelError"+String(i)).className =
      "PanelError" + String(i) + sFat;    
};

function Generate()
{
  /*
  // old variant
  var EmptyPanel = new TEmptyPanel(this.IDHeader, this.IDBody, "Error", this.Width);
  return EmptyPanel.Generate();*/
  
	var res = "<table style='width: 150px; table-layout: fixed; margin-top: 5px;' border='0' cellpadding='0' cellspacing='0'>" +
		"<tr height='18'>" +
			"<td id='IDTdPanelError1' class='PanelError1' width='4'/>" +
			"<td id='IDTdPanelError2' width='54' class='PanelError2'/>" +
			"<td id='IDTdPanelError3' class='PanelError3'/>" +
			"<td id='IDTdPanelError4' class='PanelError4' width='4'/>" +
		"</tr><tr>" +
			"<td id='IDTdPanelError5' class='PanelError5'/>" +
			"<td colspan='2'>" +
				"<table width='100%'><tr><td width='54' align='center'>" +
				"<div id='NumOfMistakes'></div>" +
				"</td><td  align='center'>" +
				"<div id='MaxNumOfMistakes'>10</div>" +
			"</td></tr></table>" +
	  	"</td>" +
			"<td id='IDTdPanelError6' class='PanelError6'/>" +
		"</tr><tr height='4'>" +
			"<td id='IDTdPanelError7' class='PanelError7'/>" +
			"<td id='IDTdPanelError8' colspan='2' class='PanelError8'/>" +
			"<td id='IDTdPanelError9' class='PanelError9'/>" +
		"</tr></table>"/*"<div id='NumofMistakes'></div><div id='MaxNumOfMistakes'></div>"*/;
 
   return res;      
}

}


function TSpeed()
{
  this.Header = "Скорость";
  
  this.IDBody = "SpeedPnlBody";
  this.IDHeader = "SpeedPnlHeader";
  this.Width = "180";
  
  this.Speed = 0;
  this.MaxSpeed = 1000;
  this.MinSpeed = 20;
  
  this.SetSpeed = SetSpeed;

  this.GetSpeed = GetSpeed;
  
  this.Generate = Generate;
  this.Update = Update;

  this.SpeedSum = 0;
  this.SpeedSumCnt = 0;

  this.bInited = false;

function SetSpeed(speed)
{
//  return;
  if(speed > this.MinSpeed)
    this.Speed = speed;
  else
    this.Speed = 0;
  this.UpdateSpeedSum(this.Speed);
}

this.ClearSpeedSum = function()
{
  this.SpeedSum = 0;
  this.SpeedSumCnt = 0;
};

this.UpdateSpeedSum = function(val)
{
  this.SpeedSum += val;
  this.SpeedSumCnt++;
};

this.GetTotalSpeed = function()
{		
  var speed = Math.round(60 * NumOfTypedChars / Math.floor( Time.GetTime() / 1000 ) );
  if(speed == Infinity) speed = SupposeSpeed_;
  return  speed;
};

function GetSpeed()
{
  return this.Speed;
}

/*function Update()
{

  var str = "";

  if(this.bInited == false)
  {
    str = BeginCenter();
    str += SpeedObj.Place();
    RoundFieldSpeedCaption.SetStrPost("знак&nbsp;/&nbsp;мин."); 
    str += RoundFieldSpeedCaption.Place(); 
    str += EndCenter();
    document.getElementById(this.IDBody).innerHTML = str;
    this.bInited = true;
  }
  
  RoundFieldSpeedCaption.Update(this.Speed);

  var speed_ = this.Speed;
  
  if(speed_ > 800)  speed_ = 800;
  SpeedObj.UpdatePercents(100.0 * speed_ / 800);
}*/

function Generate()
{
/*  var EmptyPanel = new TEmptyPanel(this.IDHeader, this.IDBody, "Speed", this.Width);
  return EmptyPanel.Generate();*/
  
var res = "<table style='width: 150px; table-layout: fixed; margin-top: 5px;' border='0' cellpadding='0' cellspacing='0'>" +
		"<tr height='18'>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_0.png' width='4'/>" +
			"<td width='61' style='background: url(" + Environment.getResourceDirectory() + "SpeedField/speed_1.png) no-repeat'/>" +
			"<td style='background: url(" + Environment.getResourceDirectory() + "SpeedField/speed_2.png) repeat-x'/>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_4.png' width='4'/>" +
		"</tr><tr>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_5.png'/>" +
			"<td colspan='2'>" +
				"<span id='" + this.IDBody + "'></span>" +
	  	"</td>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_9.png'/>" +
		"</tr><tr height='4'>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_15.png'/>" +
			"<td colspan='2' background='" + Environment.getResourceDirectory() + "SpeedField/speed_17.png'/>" +
			"<td background='" + Environment.getResourceDirectory() + "SpeedField/speed_19.png'/>" +
		"</tr></table>";  
  return res;
}

}


function TTime()
{
  this.Header = "Время";
  
  this.IDBody = "TimePnlBody";
  this.IDHeader = "TimePnlHeader";
  this.Width = "180";
  
  this.Time = 0;
  
  this.GetTimeSec = function()
  {
    return Math.floor( this.Time / 1000 );
  }

  this.SetTime = function(time)
  {
    this.Time = time;
  }
  
  this.IncTypingTime = function(valMs)
  {
    this.Time += valMs;
  }
  
  this.GetTime = function()
  {
    return this.Time;
  }
}

function FingerZonesMouseOver()
{
  //alert("mouse over");
  //return;
  FingerZonesObj.BHighlighted = true;
  FingerZonesCloseOpenDirect();
}
function FingerZonesMouseOut()
{
  //alert("mouse out");
  //FingerZonesObj.SetHighlighted(true);
  //FingerZonesCloseOpenDirect();
}

function FingerZonesCloseOpenDirect()
{
  if(FingerZonesObj.IsClosed())
    FingerZonesObj.Close();
  else
    FingerZonesObj.Open();
}

function FingerZonesCloseOpen()
{
  //alert("FingerZonesObj.IsClosed()="+FingerZonesObj.IsClosed());
  if(FingerZonesObj.IsClosed())
    FingerZonesObj.Open();
  else
    FingerZonesObj.Close();
    
//  FlashInput.ShowTypeHere();
}

function TFingerZones(id)
{
  this.Header = "Пальцы";
  
  this.IDBody = "FingerZonesPnlBody";
  this.IDHeader = "FingerZonesHeader";
  this.Width = "200";
  this.BClosed = false;
  this.BHighlighted = false;
  this.SetHighlighted = function(bVal)
  {
    this.BHighlighted = bVal;
  };
  this.Time = 0;
  
  this.ID = id;
  this.MapName = this.ID + "MapName";

this.GetID = function()
{
  return this.ID;
};

this.Generate = function()
{
/*  var EmptyPanel = new TEmptyPanel(this.IDHeader, this.IDBody, "FingerZones", this.Width);
  return EmptyPanel.Generate();*/
  
  var res = this.ExportAreas();
  res += "<span id='" + this.ID + "'>"; 
  res += "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "FingerZones/fingers.png' style='display: block'>";
  res += "</span>";
  
  return res;   
};

this.ExportAreas = function()
{
    var res = "";
    
    res += "<MAP name=\'" + this.MapName + "\'>";
    res += "<AREA shape='rect' coords=\'53, 0, 70, 14\' alt='Скрыть/раскрыть распальцовку' onclick='FingerZonesCloseOpen();'>";
    res += "</MAP>";
    
    return res;
};

this.Open = function()
{
  if(this.BHighlighted == false)
  {
//    alert("this.BHighlighted = false");
    document.getElementById(this.ID).innerHTML = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "FingerZones/fingers.png' style='display: block'>";
  }
  else
  {
//    alert("this.BHighlighted = true");
    document.getElementById(this.ID).innerHTML = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "FingerZones/fingers_highlighted.png' style='display: block'>";
  }    
  this.BClosed = false;
};

this.Close = function()
{
  if(this.BHighlighted == false)
    document.getElementById(this.ID).innerHTML = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "FingerZones/fingers_closed.png' style='display: block'>";
  else
    document.getElementById(this.ID).innerHTML = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "FingerZones/fingers_closed_highlighted.png' style='display: block'>";
  this.BClosed = true;
};

this.IsClosed = function()
{
  return this.BClosed;
};

this.Insert = function() // does not insert span
{
/*  var EmptyPanel = new TEmptyPanel(this.IDHeader, this.IDBody, "FingerZones", this.Width);
  return EmptyPanel.Generate();*/
  

  if(this.BClosed)
    var res = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "img/FingerZones/fingers_closed.png' style='display: block'>";
  else
    var res = "<img usemap='#" + this.MapName + "' src='" + Environment.getResourceDirectory() + "img/FingerZones/fingers.png' style='display: block'>";
  
  return res;   
};

}


function TResultPanel()
{
  this.Header = "Результат";
  
  this.IDBody = "ResultPnlBody";
  this.IDHeader = "ResultPnlHeader";
  this.Width = "180";
  
  
  this.Generate = Generate;
  this.Update = Update;
  
  this.Rhythmicity = "";
  this.NumOfErrors = "";
  this.Speed = "";
  
  this.SetRhythmicity = SetRhythmicity;
  this.SetNumOfErrors = SetNumOfErrors;
  this.SetSpeed = SetSpeed;

function SetRhythmicity(val)
{
  this.Rhythmicity = val;
}

function SetNumOfErrors(val)
{
  this.NumOfErrors = val;
}

function SetSpeed(val)
{
  this.Speed = val;
}

function Update()
{
  var str = "";

  str = BeginDiv('class', 'fontDoubleLineheight');
  str += "&nbsp;&nbsp;&nbsp;&nbsp;Ритмичность&nbsp;" + this.Rhythmicity + Br();
  str += "&nbsp;&nbsp;&nbsp;&nbsp;Количество&nbsp;ошибок&nbsp;" + this.NumOfErrors + Br();
  str += "&nbsp;&nbsp;&nbsp;&nbsp;Скорость&nbsp;" + this.Speed;
  str += EndDiv();

//  document.getElementById(this.IDBody).innerHTML = str;
    
  document.getElementById(this.IDHeader).innerHTML = "<center>" + this.Header + "</center>";
  
}

function Generate()
{
  var EmptyPanel = new TEmptyPanel(this.IDHeader, this.IDBody, "Speed", this.Width);
  return EmptyPanel.Generate();
  
}

}


function TEmptyPanel(idCaption, idBody, borderStyle, width)
{
  this.IdCaption = idCaption;
  this.IdBody = idBody;
  this.BorderStyle = borderStyle; 
  this.Width = width;
  
  this.Generate = Generate;

  

function Generate()
{
  var res = "";
  
  TableBuilder.ResetT();
  TableBuilder.SetTCellspacing("0");
  TableBuilder.SetTCellpadding("0");
  TableBuilder.SetTWidth(width);
  res += TableBuilder.BeginTable();


  TableBuilder.ResetT();
  res += TableBuilder.BeginTr();
  TableBuilder.SetTClass('ex' + borderStyle + 'CornerTopLeft');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.SetTClass('ex' + borderStyle + 'BkTop');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();  
  TableBuilder.SetTClass('ex' + borderStyle + 'CornerTopRightCenter');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd(); 
  TableBuilder.ResetT();
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.EndTr();     

  TableBuilder.ResetT();
  res += TableBuilder.BeginTr();
  TableBuilder.SetTClass('ex' + borderStyle + 'BkLeft');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.ResetT();
  res += TableBuilder.BeginTd();
  res += BeginFont("color", "#3b91d3");
  res += BeginDiv("id", this.IdCaption);
  res += EndFont();
  res += EndDiv();
  res += TableBuilder.EndTd();  
  TableBuilder.SetTClass('ex' + borderStyle + 'BkRightCenter');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd(); 
  TableBuilder.ResetT();
  res += TableBuilder.BeginTd();
  
  for(var i = 0; i < 20; i++)
    res += "&nbsp;";
  
  res += TableBuilder.EndTd();
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.EndTr();   
  

  TableBuilder.ResetT();
  res += TableBuilder.BeginTr();
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'BkLeft');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.ResetT();
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();  
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'CornerBottomLeftCenter');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd(); 
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'BkBottomTopVCenter');

  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'CornerTopRightVCenter');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.EndTr();  


  TableBuilder.ResetT();
  res += TableBuilder.BeginTr();
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'BkLeft');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.ResetT();
  
  TableBuilder.ResetT();
  TableBuilder.SetTColspan('3');
  res += TableBuilder.BeginTd();
  res += BeginDiv("id", this.IdBody);
  res += EndDiv();
  res += TableBuilder.EndTd();  
  
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'BkRight');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.EndTr();  

  TableBuilder.ResetT();
  res += TableBuilder.BeginTr();
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'CornerBottomLeft');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  TableBuilder.ResetT();
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'BkBottom');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd(); 
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();  
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd(); 
  TableBuilder.SetTClass('ex' + this.BorderStyle + 'CornerBottomRight');
  res += TableBuilder.BeginTd();
  res += TableBuilder.EndTd();
  res += TableBuilder.EndTr(); 


  res += TableBuilder.EndTable();

  return res;  
}
}