var shape = new Array();
var curshape = 0;
shape["name"] = new Array();
//Area = (AreaBottom) + (Circumference * ((DepthMin x DepthMax)/2))
shape["areabottom"] = new Array();
shape["circumference"] = new Array();
shape["values"] = new Array();
shape["picture"] = new Array();
var myvalues = new Array();
//--Measurement Options
myvalues[0] = "L"
myvalues[1] = "W"
myvalues[2] = "L1"
myvalues[3] = "L2"
myvalues[4] = "L3"
myvalues[5] = "L4"
myvalues[6] = "W1"
myvalues[7] = "W2"
myvalues[8] = "D"
myvalues[9] = "D1"
myvalues[10] = "D2"
//----SHAPES
//Round
shape["name"][0] = "Round";
shape["areabottom"][0] = "Math.PI*(D/2)*(D/2)";
shape["circumference"][0] = "Math.PI*D";
shape["values"][0] = "D";
shape["picture"][0] = "round.png";
//Oval
shape["name"][1] = "Oval";
shape["areabottom"][1] = ".8*L*W";
shape["circumference"][1] = "(2*Math.PI*Math.sqrt(.5*((L*L)+(W*W))))/2";
shape["values"][1] = "L|W";
shape["picture"][1] = "oval.png";
//Rectangular
shape["name"][2] = "Rectangular";
shape["areabottom"][2] = "L*W";
shape["circumference"][2] = "2*(L+W)";
shape["values"][2] = "L|W";
shape["picture"][2] = "rectangle.png";
//Lazy L
shape["name"][3] = "Lazy L";
shape["areabottom"][3] = ".5*(W1*(L1+L2)+W2*(L3+L4))";
shape["circumference"][3] = "L1+L2+L3+L4+W1+W2";
shape["values"][3] = "L1|L2|L3|L4|W1|W2";
shape["picture"][3] = "lazyl.png";
//Roman
shape["name"][4] = "Roman";
shape["areabottom"][4] = "(L1*W)+.8*((L2-L1)*W)";
shape["circumference"][4] = "W+L1+L1+(2*Math.PI*Math.sqrt(.5*(((L2-L1)*(L2-L1))+((W/2)*(W/2)))))/2";
shape["values"][4] = "W|L1|L2";
shape["picture"][4] = "roman.png";
//Kidney Bean
shape["name"][5] = "Kidney Bean";
shape["areabottom"][5] = "(Math.PI*(D1/2)*(D1/2))+(Math.PI*(D2/2)*(D2/2))";
shape["circumference"][5] = "(Math.PI*D1)+(Math.PI*D2)";
shape["values"][5] = "D1|D2";
shape["picture"][5] = "bean.png";
//
shapesct = shape["name"].length
function calcload(){
selectshape(curshape)
setInterval("getinput()", 100);
}
function getinput(){
L = parseInt(document.calculator.L.value)
W = parseInt(document.calculator.W.value)
L1 = parseInt(document.calculator.L1.value)
L2 = parseInt(document.calculator.L2.value)
L3 = parseInt(document.calculator.L3.value)
L4 = parseInt(document.calculator.L4.value)
W1 = parseInt(document.calculator.W1.value)
W2 = parseInt(document.calculator.W2.value)
D = parseInt(document.calculator.D.value)
D1 = parseInt(document.calculator.D1.value)
D2 = parseInt(document.calculator.D2.value)
N = parseInt(document.calculator.N.value)
X = parseInt(document.calculator.X.value)
//Update total
document.getElementById("calctotal").innerHTML = "Total: "+getarea(eval(shape["areabottom"][curshape]),eval(shape["circumference"][curshape]))+" sq ft.";
}
function selectshape(id){
	for(i=0;i<shapesct;i++){
		if(i == id){
			document.getElementById("shape"+i).className = "selected";
			curshape = i
			//Close measure options
			for(j=0;j<myvalues.length;j++){
				document.getElementById("calcM"+myvalues[j]).style.display = "none"
			}
			//Show measure options
			allvalues = shape["values"][i].split("|");
			document.calcpic.src="http://www.poolrestoration.com/poolcalculator/large/"+shape["picture"][i]
			for(j=0;j<allvalues.length;j++){
				document.getElementById("calcM"+allvalues[j]).style.display = "inline"
			}
		}else{
			document.getElementById("shape"+i).className = "";
		}
	}
}
function getarea(areabottom,circumference){
	depthavg = (N+X)/2;
	sidearea = circumference * depthavg;
	//sidearea = circumference * depthavg;
	//Round up by adding .4
	area = parseInt((areabottom + sidearea)+.4);
	if(isNaN(area)){
		area = 0
	}
	return area;
}