function showCalculator(calcType){
  if (calcType == 'advanced'){
    document.getElementById("calculator_simple").style.visibility = 'hidden';
    document.getElementById("calculator_simple").style.display = 'none';
    document.getElementById("calculator_simple_title").style.background = '#EEEEEE';
    document.getElementById("calculator_simple_title").style.borderTop = 'solid 1px #AAAAAA';
    document.getElementById("calculator_simple_title").style.borderLeft = 'solid 1px #AAAAAA';
    document.getElementById("calculator_simple_link").style.color = '#333333';
    document.getElementById("calculator_advanced").style.visibility = 'visible';
    document.getElementById("calculator_advanced").style.display = 'block';
    document.getElementById("calculator_advanced_title").style.background = '#1D5FA4';
    document.getElementById("calculator_advanced_title").style.borderTop = 'solid 1px #1D5FA4';
    document.getElementById("calculator_advanced_title").style.borderRight = 'solid 1px #1D5FA4';
    document.getElementById("calculator_advanced_link").style.color = '#FFFFFF';
  }
  else {
    document.getElementById("calculator_simple").style.visibility = 'visible';
    document.getElementById("calculator_simple").style.display = 'block';
    document.getElementById("calculator_simple_title").style.background = '#1D5FA4';
    document.getElementById("calculator_simple_title").style.borderTop = 'solid 1px #1D5FA4';
    document.getElementById("calculator_simple_title").style.borderLeft = 'solid 1px #1D5FA4';
    document.getElementById("calculator_simple_link").style.color = '#FFFFFF';
    document.getElementById("calculator_advanced").style.visibility = 'hidden';
    document.getElementById("calculator_advanced").style.display = 'none';
    document.getElementById("calculator_advanced_title").style.background = '#EEEEEE';
    document.getElementById("calculator_advanced_title").style.borderTop = 'solid 1px #AAAAAA';
    document.getElementById("calculator_advanced_title").style.borderRight = 'solid 1px #AAAAAA';
    document.getElementById("calculator_advanced_link").style.color = '#333333';
  }
}

function calculateSimple(){
  myErr = "";
  tWidthVal = document.calcSimple.tWidth.value;
  if (tWidthVal == ""){myErr = myErr + "* Kirjuta plaadi laius\n";}
  else if (isNaN(tWidthVal)){myErr = myErr + "* Kirjuta õigesti plaadi laius\n";}
  tLengthVal = document.calcSimple.tLength.value;
  if (tLengthVal == ""){myErr = myErr + "* Kirjuta plaadi kõrgus\n";}
  else if (isNaN(tLengthVal)){myErr = myErr + "* Kirjuta õigesti plaadi kõrgus\n";}
  aWidthVal = document.calcSimple.aWidth.value;
  if (aWidthVal == ""){myErr = myErr + "* Kirjuta plaaditava pinna laius\n";}
  else if (isNaN(aWidthVal)){myErr = myErr + "* Kirjuta õigesti plaaditava pinna laius\n";}
  aLengthVal = document.calcSimple.aLength.value;
  if (aLengthVal == ""){myErr = myErr + "* Kirjuta plaaditava pinna pikkus\n";}
  else if (isNaN(aLengthVal)){myErr = myErr + "* Kirjuta õigesti plaaditava pinna pikkus\n";}
  if (myErr == ""){

// this calculation is by area
    aArea = aWidthVal * aLengthVal;
    tArea = tWidthVal * tLengthVal;
    tilesNeeded = Math.ceil(aArea / tArea);
/*
// this calculation is by coverage
    xWidth = Math.ceil(aWidthVal / tWidthVal);
    xLength = Math.ceil(aLengthVal / tLengthVal);
    tilesNeeded = xWidth * xLength
*/
    tilesNeeded = Math.round(1.1 * tilesNeeded);
    document.calcSimple.cResult.value = tilesNeeded;
  }
  else{
    alert("Leidsime mõned vead:\n\n" + myErr);
  }
}

function updateDimensions(){
  tCommonVal = document.calcSimple.tCommon[document.calcSimple.tCommon.selectedIndex].value;
  tCommonArray = tCommonVal.split("x");
  document.calcSimple.tWidth.value = tCommonArray[0];
  document.calcSimple.tLength.value = tCommonArray[1];
}
