am = new Array(25.4348, 90.5674, 51.39, 585.64, 2.58503, 5.74354, 12.91, 140.182, 10.14, 0.08713)
bm = new Array(18.0, 2.2, 1.5, 0.75, 60.1, 28.5, 4.0, 1.0, 7.0, 305.5)
cm = new Array(1.81, 1.4, 1.05, 1.42, 1.81, 1.92, 1.1, 1.35, 1.08, 1.85)

totpts=new Array(0,0)
function cntres(fnum,num,pts) 
{	
	a=am;	
	b=bm;	
	c=cm;	
	pts=new Number(pts)
	d=1
	res=0	

	if (num==0||num==4||num==5||num==9) 	
	{
		d*=-1;
		res=-0.01
	}
	if (num==15)
	{
		d=(26.00000-Math.pow((pts/8.73753),1.00000/1.83000))
		res = Math.ceil(100 * (d)) / 100
		if (isNaN(res)) {res=0}		pts-=1
	}
	else
	{
		d*=Math.pow((pts/a[num]),1/c[num])
		res += Math.ceil(100 * (b[num] + d)) / 100
		if (isNaN(res)) {res=0}
		pts-=1
	}

	nolla=0
	totpts[fnum]=new Number(nolla)

	for (i=0;i<10;i++)
 	{
		nextval=new Number(document.forms[fnum].elements[4*i+3].value);
		totpts[fnum]+=nextval;
	}
		document.forms[fnum].totpts.value=totpts[fnum]
	if (num==9)	{
		res=res.toString();
		oo=res.substring(4,7);
		res=res.substring(0,3);
		mm=eval(res)/60;
		mm=mm.toString();
		mm=mm.substring(0,1);
		ss=res-(60*mm);
		if (ss<10)
		{
			ss="0"+ss;
		}
				res=mm+"."+ss+","+oo;
	}
	else
	{
		res=replaceSubstring(""+res, ".", ",");
	}		return res;
}

function cntpts(fnum,num,input)
 {
	a=am;
	b=bm;
	c=cm;
		if (input==0) {input=b[num]}

		input=replaceSubstring(input, ",", ".");	
if (num==9)	
{
		input=eval(input.substring(0,1))*60+eval(input.substring(2,4))+eval(input.substring(5,7))/100;
	}
	if (num==15)
	{
		pts = Math.floor(Math.pow((26.00000-input),1.83000)*8.73753);
	}
	else
	{
		d=input-b[num]

		if (num==0||num==4||num==5||num==9)
 		{
			d*=-1
		}
		pts = Math.floor(a[num]*Math.pow(d,c[num]));
	}
	if (isNaN(pts)) {pts=0}
		document.forms[fnum].elements[4*num+3].value=pts;
	nolla=0
	totpts[fnum]=new Number(nolla)
	for (i=0;i<10;i++)
 	{
		nextval=new Number(document.forms[fnum].elements[4*i+3].value);
		totpts[fnum]+=nextval;
	}
	document.forms[fnum].totpts.value=totpts[fnum];	
return pts
}

function replaceSubstring(inputString, fromString, toString) 
{
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

