/* This notice must be untouched at all times.

CalculateFloorR.js    v. 1.00

Copyright (c) 2002-2004 Albrecht Stoecklein. All rights reserved.
Created 10 Aug 2004 by Albrecht Stoecklein
Last modified: 10. 8. 2004*/

function GetDOMs() {
  DOMFloorType = document.getElementById("idFloorType");
  DOMSusInput = document.getElementById("SusInput");
  DOMSlabInput = document.getElementById("SlabInput");
  DOMRetainingInput = document.getElementById("RetainingInput");
//  DOM = document.getElementById("");
//  DOM = document.getElementById("");
//  DOM = document.getElementById("");
//  DOM = document.getElementById("");
//  DOM = document.getElementById("");
//  DOM = document.getElementById("");
}

function ShowFloorType(x) {
  DOMSusInput.style.display = 'none';
	DOMSlabInput.style.display = 'none';
	DOMRetainingInput.style.display = 'none';
  if (x==1) {DOMSusInput.style.display = 'inline';};
  if (x==2) {DOMSlabInput.style.display = 'inline';};
  if (x==3) {DOMRetainingInput.style.display = 'inline';};
}

function CalculateSusFloorR() {
ASusFloor = 1 * document.getElementById("TxtASusFloor").value;
HPerimSusFloor = 1 * eval(1 * document.getElementById("TxtHPerimSusFloor").value);
LPerimSusFloor = 1 * eval(1 * document.getElementById("TxtLPerimSusFloor").value);
APerimSusFloor = 1 * HPerimSusFloor * LPerimSusFloor;
document.getElementById("TxtAPerimSusFloor").value = Math.round(APerimSusFloor*100)/100;
if (APerimSusFloor != 0) {
  AovPA = ASusFloor / APerimSusFloor;}
else {
  AovPA = 0;}  
SubR = AovPA * document.getElementById("PerimType").value;   
document.getElementById("TxtRSubSusFloor").value = Math.round(SubR*100)/100;

if (document.getElementById("InsulationType").value == 999) {
  document.getElementById("CustomR").style.display = 'inline';
	document.getElementById("TxtRInsSusFloor").value = eval(1 * document.getElementById("TxtCustomRInsSusFloor").value) + eval(1 * document.getElementById("SusFloorType").value);
	}
else {
  document.getElementById("CustomR").style.display = 'none';
	document.getElementById("TxtRInsSusFloor").value = eval(1 * document.getElementById("InsulationType").value) + eval(1 * document.getElementById("SusFloorType").value);
  }  
InsR = 1 * eval(document.getElementById("TxtRInsSusFloor").value);
  
TotalR = SubR + InsR; 
document.getElementById("TxtTotalSusR").value = Math.round(TotalR*100)/100; 
}


function CalculateSlabFloorR() {
ASlabFloor = 1 * document.getElementById("TxtASlabFloor").value;
LPerimSlabFloor = 1 * eval(1 * document.getElementById("TxtLPerimSlabFloor").value);
ExtWallT = 1 * eval(0.001 * document.getElementById("TxtExtWallSlabFloor").value);
SoilCond = 1 * eval(1 * document.getElementById("TxtSoilCondSlabFloor").value);
SlabInsulType = document.getElementById("SlabInsulType").value;

if (SlabInsulType==0) {
  document.getElementById("UnderSlabInsulation").style.display = "none";
  document.getElementById("TxtUnderSlabInsul").value = 0;
	document.getElementById("UnderSlabPerimInsulationWidth").style.display = "none";
	document.getElementById("TxtUnderSlabInsWidth").value = 0;
	document.getElementById("UnderSlabPerimInsulationHeight").style.display = "none";
	document.getElementById("TxtUnderSlabInsHeight").value = 0}
else {
  if (SlabInsulType==1) {
    document.getElementById("UnderSlabInsulation").style.display = "none";
    document.getElementById("TxtUnderSlabInsul").value = 0;
	  document.getElementById("UnderSlabPerimInsulationWidth").style.display = "inline";
    document.getElementById("UnderSlabPerimInsulationHeight").style.display = "none";
    document.getElementById("TxtUnderSlabInsHeight").value = 0}
  else {
    if (SlabInsulType==2) {
      document.getElementById("UnderSlabInsulation").style.display = "none";
      document.getElementById("TxtUnderSlabInsul").value = 0;
	    document.getElementById("UnderSlabPerimInsulationWidth").style.display = "none";
	    document.getElementById("TxtUnderSlabInsWidth").value = 0;
      document.getElementById("UnderSlabPerimInsulationHeight").style.display = "inline"}
	  else {
      document.getElementById("UnderSlabInsulation").style.display = "inline";
	    document.getElementById("UnderSlabPerimInsulationWidth").style.display = "none";
	    document.getElementById("TxtUnderSlabInsWidth").value = 0;
	    document.getElementById("UnderSlabPerimInsulationHeight").style.display = "none";
	    document.getElementById("TxtUnderSlabInsHeight").value = 0}
  }		  
}
		  
InsWidth = 1 * eval(1 * document.getElementById("TxtUnderSlabInsWidth").value);
InsHeight = 1 * eval(1 * document.getElementById("TxtUnderSlabInsHeight").value);
UnderR = 1 * eval(1 * document.getElementById("TxtUnderSlabInsul").value);

if (ASlabFloor != 0 && ExtWallT != 0 && LPerimSlabFloor != 0 && SoilCond != 0) {
  x = (2.0 * ASlabFloor) / (ExtWallT * LPerimSlabFloor);
  RNoIns = (Math.PI * ASlabFloor) / (SoilCond * LPerimSlabFloor * Math.log((1 + x) * Math.pow((1 + 1 / x), x)));
  TotalR = RNoIns * (2 - Math.exp(-0.4 * InsWidth)) * (1 + 0.18 * InsHeight) + UnderR;}
else {
  TotalR = 0;}  

document.getElementById("TxtTotalSlabR").value = Math.round(TotalR*100)/100; 

}

function CalculateRetainingWallR() {
ARetainingWall = 1 * document.getElementById("TxtARetainingWall").value;
LengthRetainingWall = 1 * eval(1 * document.getElementById("TxtLengthRetainingWall").value);
ExtWallT = 1 * eval(0.001 * document.getElementById("TxtExtWallRetainingWall").value);
SoilCond = 1 * eval(1 * document.getElementById("TxtSoilCondRetainingWall").value);
RetainingInsulType = document.getElementById("RetainingInsulType").value;

if (RetainingInsulType==0) {
  document.getElementById("BehindRetainingInsulation").style.display = "none";
  document.getElementById("TxtBehindRetainingInsul").value = 0;
	document.getElementById("BehindRetainingInsulationWidth").style.display = "none";
	document.getElementById("TxtBehindRetainingInsWidth").value = 0;
	document.getElementById("BehindRetainingInsulationHeight").style.display = "none";
	document.getElementById("TxtBehindRetainingInsHeight").value = 0}
else {
  if (RetainingInsulType==1) {
    document.getElementById("BehindRetainingInsulation").style.display = "none";
    document.getElementById("TxtBehindRetainingInsul").value = 0;
	  document.getElementById("BehindRetainingInsulationWidth").style.display = "inline";
    document.getElementById("BehindRetainingInsulationHeight").style.display = "none";
    document.getElementById("TxtBehindRetainingInsHeight").value = 0}
  else {
    if (RetainingInsulType==2) {
      document.getElementById("BehindRetainingInsulation").style.display = "none";
      document.getElementById("TxtBehindRetainingInsul").value = 0;
	    document.getElementById("BehindRetainingInsulationWidth").style.display = "none";
	    document.getElementById("TxtBehindRetainingInsWidth").value = 0;
      document.getElementById("BehindRetainingInsulationHeight").style.display = "inline"}
	  else {
      document.getElementById("BehindRetainingInsulation").style.display = "inline";
	    document.getElementById("BehindRetainingInsulationWidth").style.display = "none";
	    document.getElementById("TxtBehindRetainingInsWidth").value = 0;
	    document.getElementById("BehindRetainingInsulationHeight").style.display = "none";
	    document.getElementById("TxtBehindRetainingInsHeight").value = 0}
  }
}

InsWidth = 1 * eval(1 * document.getElementById("TxtBehindRetainingInsWidth").value);
InsHeight = 1 * eval(1 * document.getElementById("TxtBehindRetainingInsHeight").value);
BehindR = 1 * eval(1 * document.getElementById("TxtBehindRetainingInsul").value);

// Principle: Heatloss is the same as the loss of a slab floor with twice the size (symmetry...) because it has only half the area, but the heat flow path is half the length (90deg instead of 180deg).
// A: Retaining Area
// L: Retaining wall edge length
// D: Retaing wall depth below ground (D=A/L)
// SlabHeatloss = A*2/RSlab
// RSlabEquivalent = RSlabEqivalent(A*2, L*2+D/2*4) Assumes that half the depth below ground is treated as perimeter
// RetainingHeatLoss = SlabHeatLoss = A*2/RSlabEquivalent
// Therefore: RRetaining = RSlabEquivalent/2 !!!!!!!!!!! 
ASlabEq = 2.0 * ARetainingWall; //area of equivalent slab
PerimeterRetainingWall = LengthRetainingWall * 2.0 + (ASlabEq/LengthRetainingWall*2.0/4.0); //perimeter of equivalent slab
if (ARetainingWall != 0 && ExtWallT != 0 && LengthRetainingWall != 0 && SoilCond != 0) {
  x = (2.0 * ASlabEq) / (ExtWallT * PerimeterRetainingWall);
  RNoIns = (Math.PI * ASlabEq) / (SoilCond * PerimeterRetainingWall * Math.log((1 + x) * Math.pow((1 + 1 / x), x))) / 2.0; // (/2.0) is for retaining wall...
  TotalR = RNoIns * (2 - Math.exp(-0.4 * InsWidth)) * (1 + 0.18 * InsHeight) + BehindR;}
else {
  TotalR = 0;}

document.getElementById("TxtTotalRetainingR").value = Math.round(TotalR*100)/100;
//document.getElementById("TxtTotalRetainingR").value = ARetainingWall;

}
