/*
   functions to calculate the total contribution to the club
*/

var table = {

// 31 de ludo escrime removed
licenseList:new Array( 39, 54, 54, 54, 54, 54, 54, 54, 54, 29 ),

// 100 de ludo escrime removed
contributionList:new Array( 200, 200, 200, 200, 200, 200, 200, 350, 150, 0 ),

ypos:0,

keep:function()
{
  if (document.all)
    var srcy = document.body.scrollTop;
  else
    var srcy = window.pageYOffset;

  this.ypos += (srcy - this.ypos) * 0.12;

  document.getElementById('conTable').style.top = this.ypos + 50;

  setTimeout("table.keep()", 10);
},

close:function()
{
  document.getElementById('conTable').style.visibility = 'hidden';

},
amount:function(x)
{
  var euros = Math.floor(x);

  var cents = 100 * ( x - euros );

  if( cents == 0 )
    return euros + ',00 €';
  else
    return euros + ',' + cents + '€';
},

calculate:function()
{
  var catIndex  = document.getElementById('cotisation').selectedIndex;
  var expIndex  = document.getElementById('experiency').selectedIndex;

  var text = '<br/>';

// category

  if(catIndex < 9)
  {
    var category = document.getElementById('cotisation').options[catIndex].text;

    text += 'Catégorie : ' + category + '<br/>';
  }
  else
  {
    text += 'Vous êtes dirigeant du club<br/>';

    text += 'Vous ne pratiquez pas l\'escrime<br/><br/>';
  }

// year of birth

  if(catIndex < 7)
  {
    var yearIndex = document.getElementById('birth').selectedIndex

    var yearText = document.getElementById('birth').options[yearIndex].text;

    text += 'Année de naissance : ' + yearText + '<br/>';
  }

  if(catIndex == 7)  /*  category 'Groupe Compétition' */
      text += 'A partir de Benjamins<br/><br/>';

// experience

  if(catIndex < 9 && catIndex != 7)
  {
    var expText = document.getElementById('experiency').options[expIndex].text;

    text += expText + '<br/><br/>';
  }

// licence

  text += 'Licence : ' + this.amount(this.licenseList[catIndex]) + '<br/><br/>';

  var sum = this.licenseList[catIndex];

// cotisation

  if(catIndex < 9)
  {
    text += 'Cotisation : ' + this.amount(this.contributionList[catIndex]) + '<br/><br/>';

    sum += this.contributionList[catIndex];
  }

// rent of equipment

  if(catIndex > 0 && catIndex < 9 && catIndex != 7 && expIndex < 3)
  {
    text += '<u>SOUS-TOTAL : ' + this.amount(sum) + '</u><br/><br/>';

    text += 'EN CAS de participation aux<br/> modalités d\’acquisition progressive de l\'équipement :<br/><br/>'; 

    switch (expIndex) 
    {
      case 0:

        text+= 'A louer: Veste et pantalon : 50,00€<br/><br/>';

        sum += 50;

        break;

      case 1:
        if(catIndex < 5)
        {
          text += 'A louer (sauf épéiste): Cuirasse électrique : 20,00 €<br/><br/>';

          sum += 20;
        }

        break;

      case 2:
        text += 'Plus rien à louer<br/><br/>';

        break;
    }
  }

  text += '<u>TOTAL : ' + this.amount(sum) + '</u>';

// bought of equipment

  if(catIndex > 0 && catIndex < 9 && catIndex != 7 && expIndex < 3)
  {
    text += '<br/><br/>';

    switch (expIndex) 
    {
    case 0:
      text+= 'A acheter : Cuirasse de protection, gant, masque, arme et 2 fils de corps<br/><br/>';

      break;

    case 1:
      text += 'A acheter : Veste et pantalon<br/><br/>';

      break;

    case 2:
      if(catIndex < 5)
        text += 'A acheter (sauf épéiste): Cuirasse électrique<br/><br/>';

      break;
    }
  }

  document.getElementById('divtext').innerHTML =  text;

  document.getElementById('conTable').style.visibility = 'visible';
},

update1:function()
{
  /*
     when category changed:
       update, show/hide year of birth 
       show/hide experiemce
  */

  catIndex = document.getElementById('cotisation').selectedIndex;

  if(catIndex < 7)
    document.getElementById('birth').selectedIndex = catIndex;

  if(catIndex < 7)
    document.getElementById('form2').style.visibility = 'visible';
  else
    document.getElementById('form2').style.visibility = 'hidden';

  if(catIndex == 7 || catIndex == 9)
    document.getElementById('cell2').style.visibility = 'hidden';
  else
    document.getElementById('cell2').style.visibility = 'visible';
},

update2:function()
{
  /*
     update category when year of birth changed
  */

  document.getElementById('cotisation').selectedIndex = document.getElementById('birth').selectedIndex;
}
}

