// ********************************************************
// * All scripts on this page (c)1999-2001 Michiel Jelijs *
// ********************************************************



// foutmelding bij onjuiste invoer

function error(elem,text) {
 window.alert(text);
 document.tijden.ratn.value = "error!";
 document.tijden.relaratn.value = "error!";
 elem.select();
 elem.focus();
 document.tijden.vltot.value = "";
 document.tijden.rctot.value = "";
 document.tijden.sstot.value = "";
 document.tijden.bctot.value = "";
 document.tijden.witot.value = "";
 document.tijden.tot50.value = "";
 document.tijden.tot100.value = "";
 document.tijden.tot200.value = "";
 document.tijden.tot400.value = "";
 fouttest = 1;
 return;
}

function errorok(text) {
   window.alert(text);
   document.tijden.ratn.value = "";
   document.tijden.relaratn.value = "";
   document.tijden.vltot.value = "";
   document.tijden.rctot.value = "";
   document.tijden.sstot.value = "";
   document.tijden.bctot.value = "";
   document.tijden.witot.value = "";
   document.tijden.tot50.value = "";
   document.tijden.tot100.value = "";
   document.tijden.tot200.value = "";
   document.tijden.tot400.value = "";
   foutok = 1;
   return;
}



// van string naar seconden rekenen

function getTijd(field,text) {

    if ( fouttest == 1 ) return tim;

    timetex = text;
     hundreths = parseInt(timetex.charAt(6)) + 10*parseInt(timetex.charAt(5));
     seconds = parseInt(timetex.charAt(3)) + 10*parseInt(timetex.charAt(2));
     minutes = parseInt(timetex.charAt(0));

    tim = 0;
    tim = parseFloat((minutes * 60) + seconds + (hundreths / 100));

    if (timetex == "") {
    return tim;
	}

    if (timetex == "0.00.00") {
	error(field,"If you don't have a time for a certain event, \nyou can just leave that field blank.");
    field.value = "";
    return tim;
	}

    if (timetex.length < 7) {
	error(field,"Enter 1 digit for minutes, 2 digits for seconds \nand 2 digits for hundredths, and a dot (.) inbetween \n(so: '0.26.51', etc.).");
    return tim;
	}

    if (timetex.charAt(1) != ".") {
	error(field,"Enter 1 digit for minutes, 2 digits for seconds \nand 2 digits for hundredths, and a dot (.) inbetween \n(so: '0.26.51', etc.).");
    return tim;
	}

    if (timetex.charAt(4) != ".") {
	error(field,"Enter 1 digit for minutes, 2 digits for seconds \nand 2 digits for hundredths, and a dot (.) inbetween \n(so: '0.26.51', etc.).");
    return tim;
	}

	if (isNaN(tim)) {
	error(field,"Enter 1 digit for minutes, 2 digits for seconds \nand 2 digits for hundredths, and a dot (.) inbetween \n(so: '0.26.51', etc.). \n\nIf you don't have a time for a certain event, you can just leave that field blank.");
    field.value = "";
    return tim;
	}

   return tim;
}



// rating berekenen

function SecTime() {

fouttest = 0; foutok = 0; rating = 0; ratingvl = 0; ratingrc = 0; ratingss = 0; ratingbc = 0; ratingwi = 0; rating50 = 0; rating100 = 0; rating200 = 0; rating400 = 0;

   if (document.tijden.yarmet[0].checked == true) { 
     if (document.getElementById) document.getElementById("ym400500").innerHTML = "500/400:";
   }
   else if (document.tijden.yarmet[1].checked == true) { 
     if (document.getElementById) document.getElementById("ym400500").innerHTML = "400:";
   }

   dateName = new Date();
   curyear = dateName.getYear();
    if (curyear < 1900) curyear = curyear + 1900;
   lt = document.tijden.leeftijd.value;
    if (lt < 1900) error(document.tijden.leeftijd,"Enter your year of birth!");
    if (lt > curyear) error(document.tijden.leeftijd,"Enter your year of birth!");
    if (fouttest == 1) return;
   age = ((curyear - lt) - 9);
    if (age > 10) age = 10;
    if (age < 1) age = 1;

    if (document.tijden.islogin.value > 0) {
        sex = document.tijden.geslacht.value;
    }
    else {
        if (document.tijden.geslacht[0].checked) sex = document.tijden.geslacht[0].value;
        else if (document.tijden.geslacht[1].checked) sex = document.tijden.geslacht[1].value;
        else sex = 0;
    }

    if (sex == "female") sex = "1";
    else if (sex == "male") sex = "2";

    sex = parseInt(sex);
    if (sex == 0) error(document.tijden.leeftijd,"You did not select your sex!");
    if (fouttest == 1) return;

// specialty ratings

  ratingvl += getTijd(document.tijden.vl50,document.tijden.vl50.value);
  rating50 += getTijd(document.tijden.vl50,document.tijden.vl50.value);
  ratingrc += getTijd(document.tijden.rc50,document.tijden.rc50.value);
  rating50 += getTijd(document.tijden.rc50,document.tijden.rc50.value);
  ratingss += getTijd(document.tijden.ss50,document.tijden.ss50.value);
  rating50 += getTijd(document.tijden.ss50,document.tijden.ss50.value);
  ratingbc += getTijd(document.tijden.bc50,document.tijden.bc50.value);
  rating50 += getTijd(document.tijden.bc50,document.tijden.bc50.value);

  ratingvl += getTijd(document.tijden.vl100,document.tijden.vl100.value)/2;
  rating100 += getTijd(document.tijden.vl100,document.tijden.vl100.value)/2;
  ratingrc += getTijd(document.tijden.rc100,document.tijden.rc100.value)/2;
  rating100 += getTijd(document.tijden.rc100,document.tijden.rc100.value)/2;
  ratingss += getTijd(document.tijden.ss100,document.tijden.ss100.value)/2;
  rating100 += getTijd(document.tijden.ss100,document.tijden.ss100.value)/2;
  ratingbc += getTijd(document.tijden.bc100,document.tijden.bc100.value)/2;
  rating100 += getTijd(document.tijden.bc100,document.tijden.bc100.value)/2;
  ratingwi += getTijd(document.tijden.wi100,document.tijden.wi100.value)/2;
  rating100 += getTijd(document.tijden.wi100,document.tijden.wi100.value)/2;

if (age >= 4) {
  ratingvl += getTijd(document.tijden.vl200,document.tijden.vl200.value)/4;
  rating200 += getTijd(document.tijden.vl200,document.tijden.vl200.value)/4;
  ratingrc += getTijd(document.tijden.rc200,document.tijden.rc200.value)/4;
  rating200 += getTijd(document.tijden.rc200,document.tijden.rc200.value)/4;
  ratingss += getTijd(document.tijden.ss200,document.tijden.ss200.value)/4;
  rating200 += getTijd(document.tijden.ss200,document.tijden.ss200.value)/4;
  ratingwi += getTijd(document.tijden.wi400,document.tijden.wi400.value)/8;
  rating400 += getTijd(document.tijden.wi400,document.tijden.wi400.value)/8;
 }
  ratingbc += getTijd(document.tijden.bc200,document.tijden.bc200.value)/4;
  rating200 += getTijd(document.tijden.bc200,document.tijden.bc200.value)/4;
  ratingwi += getTijd(document.tijden.wi200,document.tijden.wi200.value)/4;
  rating200 += getTijd(document.tijden.wi200,document.tijden.wi200.value)/4;

if (age >= 2) {
 if (document.tijden.yarmet[0].checked == true) { 
  ratingbc += getTijd(document.tijden.bc400,document.tijden.bc400.value)/10;
  rating400 += getTijd(document.tijden.bc400,document.tijden.bc400.value)/10; }
 if (document.tijden.yarmet[1].checked == true) { 
  ratingbc += getTijd(document.tijden.bc400,document.tijden.bc400.value)/8;
  rating400 += getTijd(document.tijden.bc400,document.tijden.bc400.value)/8; }
}

// rating berekenen

  rating += getTijd(document.tijden.vl50,document.tijden.vl50.value);
    if (seconds >= 60) error(document.tijden.vl50,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.rc50,document.tijden.rc50.value);
    if (seconds >= 60) error(document.tijden.rc50,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.ss50,document.tijden.ss50.value);
    if (seconds >= 60) error(document.tijden.ss50,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.bc50,document.tijden.bc50.value);
    if (seconds >= 60) error(document.tijden.bc50,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.vl100,document.tijden.vl100.value)/2;
    if (seconds >= 60) error(document.tijden.vl100,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.rc100,document.tijden.rc100.value)/2;
    if (seconds >= 60) error(document.tijden.rc100,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.ss100,document.tijden.ss100.value)/2;
    if (seconds >= 60) error(document.tijden.ss100,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.bc100,document.tijden.bc100.value)/2;
    if (seconds >= 60) error(document.tijden.bc100,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.wi100,document.tijden.wi100.value)/2;
    if (seconds >= 60) error(document.tijden.wi100,"A minute has only 60 seconds!");
if (age >= 4) {
  rating += getTijd(document.tijden.vl200,document.tijden.vl200.value)/4;
    if (seconds >= 60) error(document.tijden.vl200,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.rc200,document.tijden.rc200.value)/4;
    if (seconds >= 60) error(document.tijden.rc200,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.ss200,document.tijden.ss200.value)/4;
    if (seconds >= 60) error(document.tijden.ss200,"A minute has only 60 seconds!");
}
  rating += getTijd(document.tijden.bc200,document.tijden.bc200.value)/4;
    if (seconds >= 60) error(document.tijden.bc200,"A minute has only 60 seconds!");
  rating += getTijd(document.tijden.wi200,document.tijden.wi200.value)/4;
    if (seconds >= 60) error(document.tijden.wi200,"A minute has only 60 seconds!");
if (age >= 2) {
 if (document.tijden.yarmet[0].checked == true) { 
     rating += getTijd(document.tijden.bc400,document.tijden.bc400.value)/10; }
 if (document.tijden.yarmet[1].checked == true) { 
     rating += getTijd(document.tijden.bc400,document.tijden.bc400.value)/8; }
    if (seconds >= 60) error(document.tijden.bc400,"A minute has only 60 seconds!");
}
if (age >= 4) {
  rating += getTijd(document.tijden.wi400,document.tijden.wi400.value)/8;
    if (seconds >= 60) error(document.tijden.wi400,"A minute has only 60 seconds!");
}

if (fouttest == 1) return;

// correctie voor yards of meters

   if (document.tijden.yarmet[0].checked == true) {
   cv = 1.116;
   rating = (rating * cv);
   ratingvl = (ratingvl * cv);
   ratingrc = (ratingrc * cv);
   ratingss = (ratingss * cv);
   ratingbc = (ratingbc * cv);
   ratingwi = (ratingwi * cv);
   rating50 = (rating50 * cv);
   rating100 = (rating100 * cv);
   rating200 = (rating200 * cv);
   rating400 = (rating400 * cv);
   }

// relatieve rating berekenen

   relrat = 0;
   if (age == 1 && sex == 1) { relrat = (472.230 / rating); vltot = (82.785 / ratingvl); rctot = (85.685 / ratingrc); sstot = (96.985 / ratingss); bctot = (116.033 / ratingbc); witot = (90.743 / ratingwi); tot50 = (166.560 / rating50); tot100 = (219.675 / rating100); tot200 = (85.995 / rating200); tot400 = 0; }
   if (age == 2 && sex == 1) { relrat = (480 / rating); vltot = (76.973 / ratingvl); rctot = (79.865 / ratingrc); sstot = (90.172 / ratingss); bctot = (147.831 / ratingbc); witot = (85.158 / ratingwi); tot50 = (153.409 / rating50); tot100 = (204.909 / rating100); tot200 = (82.242 / rating200); tot400 = (39.440 / rating400); }
   if (age == 3 && sex == 1) { relrat = (456.379 / rating); vltot = (73.185 / ratingvl); rctot = (75.935 / ratingrc); sstot = (85.735 / ratingss); bctot = (140.556 / ratingbc); witot = (80.968 / ratingwi); tot50 = (145.860 / rating50); tot100 = (194.825 / rating100); tot200 = (78.195 / rating200); tot400 = (37.499 / rating400); }
   if (age == 4 && sex == 1) { relrat = (602 / rating); vltot = (109.549 / ratingvl); rctot = (111.374 / ratingrc); sstot = (126.798 / ratingss); bctot = (135.789 / ratingbc); witot = (118.490 / ratingwi); tot50 = (139.407 / rating50); tot100 = (186.943 / rating100); tot200 = (197.903 / rating200); tot400 = (77.747 / rating400); }
   if (age == 5 && sex == 1) { relrat = (585.452 / rating); vltot = (106.538 / ratingvl); rctot = (108.313 / ratingrc); sstot = (123.313 / ratingss); bctot = (132.056 / ratingbc); witot = (115.233 / ratingwi); tot50 = (135.575 / rating50); tot100 = (181.805 / rating100); tot200 = (192.463 / rating200); tot400 = (75.610 / rating400); }
   if (age == 6 && sex == 1) { relrat = (575.500 / rating); vltot = (104.198 / ratingvl); rctot = (105.976 / ratingrc); sstot = (121.693 / ratingss); bctot = (129.635 / ratingbc); witot = (113.998 / ratingwi); tot50 = (132.422 / rating50); tot100 = (178.440 / rating100); tot200 = (190.177 / rating200); tot400 = (74.461 / rating400); }
   if (age == 7 && sex == 1) { relrat = (566.605 / rating); vltot = (102.588 / ratingvl); rctot = (104.338 / ratingrc); sstot = (119.813 / ratingss); bctot = (127.631 / ratingbc); witot = (112.236 / ratingwi); tot50 = (130.375 / rating50); tot100 = (175.682 / rating100); tot200 = (187.238 / rating200); tot400 = (73.310 / rating400); }
   if (age == 8 && sex == 1) { relrat = (558 / rating); vltot = (101.563 / ratingvl); rctot = (102.753 / ratingrc); sstot = (115.868 / ratingss); bctot = (126.875 / ratingbc); witot = (110.940 / ratingwi); tot50 = (127.730 / rating50); tot100 = (172.547 / rating100); tot200 = (184.657 / rating200); tot400 = (73.065 / rating400); }
   if (age == 9 && sex == 1) { relrat = (550.990 / rating); vltot = (100.288 / ratingvl); rctot = (101.463 / ratingrc); sstot = (114.413 / ratingss); bctot = (125.281 / ratingbc); witot = (109.546 / ratingwi); tot50 = (126.125 / rating50); tot100 = (170.380 / rating100); tot200 = (182.338 / rating200); tot400 = (72.148 / rating400); }
   if (age == 10 && sex == 1) { relrat = (547 / rating); vltot = (99.561 / ratingvl); rctot = (100.728 / ratingrc); sstot = (113.584 / ratingss); bctot = (124.374 / ratingbc); witot = (108.753 / ratingwi); tot50 = (125.212 / rating50); tot100 = (169.146 / rating100); tot200 = (181.017 / rating200); tot400 = (71.625 / rating400); }

   if (age == 1 && sex == 2) { relrat = (458.755 / rating); vltot = (79.085 / ratingvl); rctot = (83.385 / ratingrc); sstot = (94.535 / ratingss); bctot = (112.983 / ratingbc); witot = (88.768 / ratingwi); tot50 = (161.56 / rating50); tot100 = (213.325 / rating100); tot200 = (83.87 / rating200); tot400 = 0; }
   if (age == 2 && sex == 2) { relrat = (472 / rating); vltot = (75.181 / ratingvl); rctot = (78.874 / ratingrc); sstot = (88.742 / ratingss); bctot = (145.228 / ratingbc); witot = (83.975 / ratingwi); tot50 = (150.667 / rating50); tot100 = (201.394 / rating100); tot200 = (80.890 / rating200); tot400 = (39.048 / rating400); }
   if (age == 3 && sex == 2) { relrat = (447.229 / rating); vltot = (71.235 / ratingvl); rctot = (74.735 / ratingrc); sstot = (84.085 / ratingss); bctot = (137.606 / ratingbc); witot = (79.568 / ratingwi); tot50 = (142.76 / rating50); tot100 = (190.825 / rating100); tot200 = (76.645 / rating200); tot400 = (36.999 / rating400); }
   if (age == 4 && sex == 2) { relrat = (580 / rating); vltot = (104.386 / ratingvl); rctot = (108.251 / ratingrc); sstot = (121.238 / ratingss); bctot = (131.183 / ratingbc); witot = (114.943 / ratingwi); tot50 = (133.476 / rating50); tot100 = (180.218 / rating100); tot200 = (190.908 / rating200); tot400 = (75.398 / rating400); }
   if (age == 5 && sex == 2) { relrat = (551.532 / rating); vltot = (99.263 / ratingvl); rctot = (102.938 / ratingrc); sstot = (115.288 / ratingss); bctot = (124.744 / ratingbc); witot = (109.301 / ratingwi); tot50 = (126.925 / rating50); tot100 = (171.372 / rating100); tot200 = (181.538 / rating200); tot400 = (71.698 / rating400); }
   if (age == 6 && sex == 2) { relrat = (532 / rating); vltot = (95.929 / ratingvl); rctot = (98.637 / ratingrc); sstot = (110.191 / ratingss); bctot = (121.068 / ratingbc); witot = (106.175 / ratingwi); tot50 = (120.675 / rating50); tot100 = (164.188 / rating100); tot200 = (176.680 / rating200); tot400 = (70.458 / rating400); }
   if (age == 7 && sex == 2) { relrat = (515.689 / rating); vltot = (92.988 / ratingvl); rctot = (95.613 / ratingrc); sstot = (106.813 / ratingss); bctot = (117.356 / ratingbc); witot = (102.920 / ratingwi); tot50 = (116.975 / rating50); tot100 = (159.145 / rating100); tot200 = (171.263 / rating200); tot400 = (68.298 / rating400); }
   if (age == 8 && sex == 2) { relrat = (504 / rating); vltot = (91.614 / ratingvl); rctot = (92.530 / ratingrc); sstot = (103.907 / ratingss); bctot = (114.768 / ratingbc); witot = (101.182 / ratingwi); tot50 = (113.642 / rating50); tot100 = (155.224 / rating100); tot200 = (167.765 / rating200); tot400 = (67.368 / rating400); }
   if (age == 9 && sex == 2) { relrat = (495.054 / rating); vltot = (89.988 / ratingvl); rctot = (90.888 / ratingrc); sstot = (102.063 / ratingss); bctot = (112.731 / ratingbc); witot = (99.386 / ratingwi); tot50 = (111.625 / rating50); tot100 = (152.469 / rating100); tot200 = (164.788 / rating200); tot400 = (66.173 / rating400); }
   if (age == 10 && sex == 2) { relrat = (491 / rating); vltot = (89.251 / ratingvl); rctot = (90.143 / ratingrc); sstot = (101.227 / ratingss); bctot = (111.808 / ratingbc); witot = (98.572 / ratingwi); tot50 = (110.711 / rating50); tot100 = (151.221 / rating100); tot200 = (163.438 / rating200); tot400 = (65.631 / rating400); }

   if (relrat == 0) return;

   relrat = (relrat * 10000);
   relrat = Math.round(relrat);
   relrat = (relrat / 100);

   vltot = (vltot * 10000);
   vltot = Math.round(vltot);
   vltot = (vltot / 100);
   rctot = (rctot * 10000);
   rctot = Math.round(rctot);
   rctot = (rctot / 100);
   sstot = (sstot * 10000);
   sstot = Math.round(sstot);
   sstot = (sstot / 100);
   bctot = (bctot * 10000);
   bctot = Math.round(bctot);
   bctot = (bctot / 100);
   witot = (witot * 10000);
   witot = Math.round(witot);
   witot = (witot / 100);
   tot50 = (tot50 * 10000);
   tot50 = Math.round(tot50);
   tot50 = (tot50 / 100);
   tot100 = (tot100 * 10000);
   tot100 = Math.round(tot100);
   tot100 = (tot100 / 100);
   tot200 = (tot200 * 10000);
   tot200 = Math.round(tot200);
   tot200 = (tot200 / 100);
   tot400 = (tot400 * 10000);
   tot400 = Math.round(tot400);
   tot400 = (tot400 / 100);
      if (tot400 == 0) tot400 = "-";

   rating = (rating * 1000);
   rating = Math.round(rating);
   rating = (rating / 1000);

// rating weergeven in vak

   if (isNaN(rating)) rating = "0.000";
   if (isNaN(relrat)) relrat = "0.00";
   if (isNaN(vltot)) vltot = "";
   if (isNaN(rctot)) rctot = "";
   if (isNaN(sstot)) sstot = "";
   if (isNaN(bctot)) bctot = "";
   if (isNaN(witot)) witot = "";
   if (isNaN(tot50)) tot50 = "";
   if (isNaN(tot100)) tot100 = "";
   if (isNaN(tot200)) tot200 = "";
   if (isNaN(tot400)) tot400 = "";
   if (document.getElementById) {
     if (document.getElementById("updateknop")) {
       document.getElementById("updateknop").style.visibility = "visible";
     }
   }
   document.tijden.ratn.value = rating;
   document.tijden.relaratn.value = relrat;
   document.tijden.vltot.value = vltot;
   document.tijden.rctot.value = rctot;
   document.tijden.sstot.value = sstot;
   document.tijden.bctot.value = bctot;
   document.tijden.witot.value = witot;
   document.tijden.tot50.value = tot50;
   document.tijden.tot100.value = tot100;
   document.tijden.tot200.value = tot200;
   document.tijden.tot400.value = tot400;
   if (age < 4) document.tijden.ratn.value = "";
   if (relrat > 118) error(document.tijden.ratn,"Are you from Mars?! Nobody is that fast! Sorry, I can't accept that...");
   if (fouttest == 1) return;

}



// rating controleren voor opsturen

function Confrm() {
SecTime();
if (document.tijden.ratn.value == "error!") {
   alert("Error in form!");
   return false;
   }
return true;
}


