if (document.all)
{
  document.styleSheets[0].addRule(".RightAlign","text-align: right");
  document.styleSheets[0].addRule(".CalcTable","background-color: buttonface");
  document.styleSheets[0].addRule(".CalcCaptionBack","background-color: activecaption");
  document.styleSheets[0].addRule(".CalcCaptionText","color: captiontext");
}

  ResultsOpen=false;HelpOpen=false;
  var ResultsArray=new MakeArray(80);
  ResultIndex=1;
  wrapped=false;
 function ValidateCalls()
	{var CallsValue;
	with (document.calls_form)
	{CallsValue=CallsNumber();
	if (((CallsValue<1) || (CallsValue>10000)) && ef)
		{alert("Number of calls must be between 1 and 10000");
		Calls_Edit.value=""}
}}
 function ValidateDuration()
	{var DurationValue;
	with (document.calls_form)
	{DurationValue=DurationNumber();
	if ((DurationValue<10) || (DurationValue>1800))
		{alert("Call duration must be between 10 and 1800 seconds");
		Duration_Edit.value=""}
}}
 function ValidateDelay()
	{var DelayValue;
	with (document.calls_form)
	{DelayValue=DelayNumber();
	if ((DelayValue<1) || (DelayValue>600))
		{alert("Average delay must be between 1 and 600 seconds");
		Delay_Edit.value=""}
}}
 function ResultsPressed()
    {var index,HasWrapped;
     if ((ResultIndex==1) && (!wrapped))
     {
        alert("There are no results to display yet!");
     }
    else {
//   Specifying size sometimes causes problems in IE4
//   ResultsWindow=window.open('','ResultsW','height=250,width=348,menubar,scrollbars,resizable');

     ResultsWindow=window.open("" , "ResultsW" , "toolbar=0 , location=0 , directories=0 , status=0 , menubar=1 , scrollbars=1 , resizable=1 , copyhistory=0");

     ResultsWindow.document.writeln("<HTML>");
     ResultsWindow.document.writeln("<HEAD>");
     ResultsWindow.document.writeln("<TITLE>Erlang C Calculator Results Table</TITLE>");
       ResultsWindow.document.writeln("</HEAD>");
     ResultsWindow.document.write("<BODY BGCOLOR='#ffffff' LINK='#000080' VLINK='#008000'><P><font color='#000080' size='3' face='Arial'><strong>Erlang C Calculator Results Table</strong></font></P>")
     ResultsWindow.document.write("<P><font size='2' face='Arial'><strong>Here are the results (max 20) of the Erlang C ");
     ResultsWindow.document.write("Calculator. The unknown figures are shown in red.</strong></font></p>");
     ResultsWindow.document.write("<P><table border='1' cellpadding='2' cellspacing='0'><TR><td align='center' bgcolor='#003399'><font size='2'");
     ResultsWindow.document.write("face='Arial' color='#FFFFFF'><strong>Calls per hour</strong></font></td>");
     ResultsWindow.document.write("<td align='center' bgcolor='#003399'><font size='2'");
     ResultsWindow.document.write("face='Arial' color='#FFFFFF'><strong>Call duration (s)</strong></font></td>");
     ResultsWindow.document.write("<td align='center' bgcolor='#003399'><font size='2'");
     ResultsWindow.document.write("face='Arial' color='#FFFFFF'><strong>Avge delay (s)</strong></font></td>");
     ResultsWindow.document.write("<td align='center' bgcolor='#003399'><font size='2'");
     ResultsWindow.document.write("face='Arial' color='#FFFFFF'><strong>Agents required</strong></font></td></TR>");
     HasWrapped=!wrapped;
     if (wrapped) {index=ResultIndex} else {index=1};
     for (;(index!=ResultIndex) || (!HasWrapped);index++)
     {
     ResultsWindow.document.write("<TR><td align='center' bgcolor='#FFFFCC'><font size='2' face='Arial'>");
     ResultsWindow.document.write(ResultsArray[index]);
     ResultsWindow.document.write("</FONT></TD><td align='center' bgcolor='#FFFFCC'><font size='2' face='Arial'>");
     ResultsWindow.document.write(ResultsArray[index+20]);
     ResultsWindow.document.write("</FONT></TD><td align='center' bgcolor='#FFFFCC'><font size='2' face='Arial'>");
     ResultsWindow.document.write(ResultsArray[index+40]);
     ResultsWindow.document.write("</FONT></TD><td align='center' bgcolor='#FFFFCC'><font size='2' color='#FF0000' face='Arial'>");
     ResultsWindow.document.write(ResultsArray[index+60]);
     ResultsWindow.document.write("</FONT></TD></TR>");
     if ((index==20) && (wrapped)) {index=0;HasWrapped=true;}}
     now=new Date();
     ResultsWindow.document.write("</TABLE><HR><FONT face='Arial' Size='2' COLOR='Gray'>&copy Westbay Engineers Ltd. 2001.<BR><I>");
     ResultsWindow.document.write("Results displayed -  "+now.toLocaleString()+"</FONT></I></BODY>");
     ResultsWindow.document.write("</HTML>");
     ResultsWindow.document.close();
     ResultsOpen=true;
}}
 ef=(window.location.hostname.indexOf("lang.co")!=-1) || (window.location.hostname.indexOf("bay-en")!=-1);
 function HelpPressed()
    {HelpWindow=window.open('help.html','HelpW','height=300,width=348,menubar,scrollbars,resizable');
     HelpOpen=true;
}
 function CalcPressed()
    {var agents,traffic,DurationValue,DelayValue;
	with (document.calls_form)
	{if ((Calls_Edit.value=="") || (Duration_Edit.value=="") || (Delay_Edit.value==""))
		{alert("All three boxes must be filled in")}
	else
	{DurationValue=DurationNumber();
	CallsValue=CallsNumber();
	DelayValue=DelayNumber();
	agents=Math.round((DurationValue*CallsValue/3600)-0.5)+1;
	traffic=CallsValue*DurationNumber()/3600;
	while (ECDelayAll(traffic,agents,DurationValue)>DelayValue) {agents++}
	alert("The number of agents required during this hour is "  + agents + ".")
	ResultsArray[ResultIndex]=CallsValue;
	ResultsArray[ResultIndex+20]=DurationValue;
	ResultsArray[ResultIndex+40]=DelayValue;
	ResultsArray[ResultIndex+60]=agents;
	ResultIndex++;
	if (ResultIndex==21) {ResultIndex=1;wrapped=true;}
	if (ResultsOpen) {ResultsPressed()};
	}
}}
 function CallsNumber()
	{return parseInt(ef*document.calls_form.Calls_Edit.value)
}
 function DurationNumber()
	{return parseInt(document.calls_form.Duration_Edit.value)
}
 function DelayNumber()
	{return parseInt(document.calls_form.Delay_Edit.value)
}
 function EB(traffic,plines)
  {var PBR,index;
  if (traffic>0) 
    {PBR=(1+traffic)/traffic;
     for (index=2;index!=plines+1;index++)
      {PBR=index/traffic*PBR+1;
       if (PBR>10000) {return 0;}}
     return 1/PBR;}
  else {return 0;}
}
 function EC(traffic,plines)
  {var EBResult,probability;
	EBResult=EB(traffic,plines);
	probability=EBResult/(1-(traffic/plines)*(1-EBResult));
	if (probability>1) {return 1} else {return probability};
}
 function ECDelayAll(traffic,plines,HoldTime)
 {return EC(traffic,plines)*HoldTime/(plines-traffic);
}
 function MakeArray(n) {
   this.length = n;
   for (var i = 1; i <= n; i++) { 
     this[i] = 0 }
     return this
}