var shape;function Setup(){if(document.location.toString().indexOf("?frm=")>-1)RestoreConcrete();else{Show("R",2);Demo()}}
function Show(e,a){document.images.imgType.src="images/Concrete/Conc"+e+".gif";var b=document.getElementById("tdSides");b.innerHTML="";for(var d,h=0;h<a;h++){b.innerHTML+="Side "+(h+1)+" ";d=document.createElement("input");d.setAttribute("type","text");d.setAttribute("class","Num");d.setAttribute("id","txt"+h);b.appendChild(d);b.appendChild(document.createElement("br"))}SetInput();shape=e;document.getElementById("txtShape").value=e}
function Calculate(){for(var e=document.getElementById("tdSides").getElementsByTagName("input"),a=[],b,d=0;d<e.length;d++){a[d]=parseFloat(e[d].value);if(isNaN(a[d])||a[d]<200){alert("Side "+(d+1)+" Only Numbers = > 200");return}}switch(shape){case "R":a[2]=a[0];a[3]=a[1];b=a[0]*a[1];break;case "L":if(a[2]>=a[0]){alert("Side 3 must be shorter than Side 1");return}if(a[3]>=a[1]){alert("Side 4 must be shorter than Side 2");return}a[4]=a[0]-a[2];a[5]=a[1]-a[3];b=a[0]*a[1];b-=a[3]*a[4];break;case "U":if(a[2]<=
a[4]){alert("Side 5 must be shorter than Side 3");return}if(a[3]+a[5]>=a[1]){alert("Sides 4 and 6 must add to less than Side 2");return}if(a[2]-a[4]>=a[0]){alert("Side 5 must be longer than "+(a[2]-a[0]).toString());return}a[6]=a[0]-(a[2]-a[4]);a[7]=a[1]-a[3]-a[5];b=a[0]*(a[1]-a[3]-a[5]);e=a[5]*(a[0]-a[6]);b+=e;e=a[2]*a[3];b+=e;break;case "T":if(a[2]+a[4]<=a[0]){alert("Sides 3 and 5 must add to more than Side 1");return}if(a[3]+a[5]>=a[1]){alert("Sides 4 and 6 must add to less than Side 2");return}a[6]=
a[2]+a[4]-a[0];a[7]=a[1]-a[3]-a[5];b=a[0]*a[7];e=a[2]*a[3];b+=e;e=(a[2]+a[4])*a[5];b+=e;break;case "H":if(a[2]+(a[6]-(a[4]+a[8]))>=a[0]){alert("Side 1 to short");return}if(a[7]+a[9]>=a[1]+a[3]+a[5]){alert("Sides 8 and 10 must not add to more than sides 2, 4 and 6");return}if(a[6]-a[8]-a[4]<=0){alert("Sides 5 and 9 must not add to more than side 7");return}a[10]=a[0]-a[2]+a[4]-a[6]+a[8];e=a[1]+a[3]+a[5];a[11]=e-a[7]-a[9];b=(a[0]-a[2]-a[10])*e;e=a[1]*a[2];b+=e;e=a[10]*a[11];b+=e;e=a[4]*a[5];b+=e;e=
a[7]*a[8];b+=e;break}var h=0;for(d=0;d<a.length;d++)h+=a[d];var j=parseFloat(document.getElementById("txtSlabThick").value);j=isNaN(j)?0:j;var k=parseFloat(document.getElementById("txtEdgeThick").value);k=isNaN(k)?0:k;var n=parseFloat(document.getElementById("txtEdgeWidth").value);n=isNaN(n)?0:n;d=parseFloat(document.getElementById("txtThickLength").value);d=isNaN(d)?0:d;e=parseFloat(document.getElementById("txtThickWidth").value);e=isNaN(e)?0:e;var m=parseFloat(document.getElementById("txtThickThick").value);
m=isNaN(m)?0:m;var i=b*j;if(n>0&&k>j){var l=k-j;i+=h*n*l;if(document.getElementById("cbSplay").checked)i+=l*l*h/2}if(d>0&&m>j){l=m-j;i+=d*e*l;if(document.getElementById("cbSplay").checked)i+=l*l*d}i*=1.0E-9;b*=1.0E-6;h*=0.0010;d="Area "+RoundTo(b,2)+" m&sup2;<br />Volume "+RoundTo(i,2)+" m&sup3;<br />Perimeter "+RoundTo(h,2)+" m";document.getElementById("spnResult").innerHTML=d;document.getElementById("divInput").style.display="none";document.getElementById("divResults").style.display="block";document.getElementById("hlShowForm").style.display=
"block";b=document.getElementById("cnvsSlab");if(b.getContext){h=[];for(d=0;d<a.length;d++)h[d]=a[d];var c,g;switch(shape){case "R":g=a[0];c=a[1];break;case "L":g=a[0];c=a[1];break;case "U":g=Math.max(a[0],a[2]);c=a[1];break;case "T":g=a[2]+a[4];c=a[1];break;case "H":c=a[1]+a[3]+a[5];g=a[0];if(a[4]>a[2])g+=a[4]-a[2];d=a[2]-a[4]+a[6];if(d>a[0])g+=d-a[0];break}i=b.width-4;l=i/(c/g);b.setAttribute("height",l+4);g=i/c;for(d=0;d<a.length;d++)a[d]*=g;g=[];c=b.getContext("2d");c.font="16px Verdana";c.textBaseline=
"top";c.fillStyle="#dcdcdc";c.strokeStyle="#808080";var f;c.beginPath();switch(shape){case "R":c.moveTo(0,0);c.lineTo(i,0);c.lineTo(i,l);c.lineTo(0,l);b=new Point(6,l/2-10);g[0]=b;b=new Point(i/2-c.measureText(h[1]).width/2,0);g[1]=b;break;case "L":c.moveTo(0,l);c.lineTo(0,0);b=new Point(6,l/2-10);g[0]=b;c.lineTo(i,0);c.lineTo(i,a[2]);b=new Point(i/2-c.measureText(h[1]).width-6,0);g[1]=b;c.lineTo(i-a[3],a[2]);b=new Point(i-c.measureText(h[2]).width-6,a[2]/2-6);g[2]=b;c.lineTo(i-a[3],l);b=new Point(i-
a[3]/2-c.measureText(h[3]).width/2,a[2]-20);g[3]=b;break;case "U":c.moveTo(0,a[0]);c.lineTo(0,0);b=new Point(6,a[0]/2-6);g[0]=b;c.lineTo(i,0);b=new Point(i/2-c.measureText(h[1]).width/2,0);g[1]=b;f=a[2];c.lineTo(i,f);b=new Point(i-c.measureText(h[2]).width-6,f-a[2]/2-6);g[2]=b;d=i-a[3];c.lineTo(d,f);b=new Point(d+a[3]/2-c.measureText(h[3]).width/2,f-20);g[3]=b;f-=a[4];c.lineTo(d,f);b=new Point(d+6,f+a[4]/2-10);g[4]=b;d-=a[5];c.lineTo(d,f);b=new Point(d+a[5]/2-c.measureText(h[5]).width/2,f-20);g[5]=
b;c.lineTo(d,a[0]);break;case "T":c.moveTo(0,a[0]);c.lineTo(0,0);b=new Point(6,a[0]/2-6);g[0]=b;c.lineTo(i,0);b=new Point(i/2-c.measureText(h[1]).width/2,0);g[1]=b;f=a[2];c.lineTo(i,f);b=new Point(i-c.measureText(h[2]).width-6,f-a[2]/2-6);g[2]=b;d=i-a[3];c.lineTo(d,f);b=new Point(d+a[3]/2-c.measureText(h[3]).width/2,f-20);g[3]=b;f=l;c.lineTo(d,f);b=new Point(d-c.measureText(h[4]).width-6,f-a[4]/2-10);g[4]=b;d-=a[5];c.lineTo(d,f);b=new Point(d+a[5]/2-c.measureText(h[5]).width/2,f-20);g[5]=b;c.lineTo(d,
a[0]);break;case "H":l=0;if(a[4]>a[2]){l=f=a[4]-a[2];c.moveTo(0,a[0]+f);c.lineTo(0,f)}else{f=0;c.moveTo(0,a[0]);c.lineTo(0,0)}b=new Point(2,f+a[0]/2);g[0]=b;d=a[1];c.lineTo(d,f);b=new Point(d/2-c.measureText(h[1]).width/2,f);g[1]=b;f+=a[2];c.lineTo(d,f);b=new Point(d-c.measureText(h[2]).width-6,f-a[2]/2-10);g[2]=b;d+=a[3];c.lineTo(d,f);b=new Point(d-a[3]/2-c.measureText(h[3]).width/2,f);g[3]=b;f-=a[4];c.lineTo(d,f);b=new Point(d+6,f+a[4]/2);g[4]=b;d=i;c.lineTo(d,f);b=new Point(d-a[5]/2-c.measureText(h[5]).width/
2,f);g[5]=b;f+=a[6];c.lineTo(d,f);b=new Point(d-c.measureText(h[6]).width-6,f-a[6]/2);g[6]=b;d-=a[7];c.lineTo(d,f);b=new Point(d+a[7]/2-c.measureText(h[7]).width/2,f-20);g[7]=b;f-=a[8];c.lineTo(d,f);b=new Point(d+6,f+a[8]/2-6);g[8]=b;d-=a[9];c.lineTo(d,f);b=new Point(d+a[9]/2-c.measureText(h[9]).width/2,f-20);g[9]=b;f=a[0]+l;c.lineTo(d,f);break}c.save();c.shadowOffsetY=4;c.shadowOffsetX=4;c.shadowBlur=6;c.shadowColor="#c0c0c0";c.fill();c.restore();c.stroke();c.fillStyle="#000";for(d=0;d<g.length;d++){b=
g[d];c.fillText(h[d],b._x,b._y)}}if(m>j||k>j){b=document.getElementById("cnvsSection");if(b.getContext){a=document.getElementById("cbSplay").checked;g=b.height/Math.max(k,m);h=(k-j)*g;i=j*g;k=k*g;n=n*g;c=b.getContext("2d");c.clearRect(0,0,b.width,b.height);c.beginPath();c.moveTo(0,k);c.lineTo(0,0);c.lineTo(b.width,0);l=0;f=j*g/6;for(d=0;d<6;d++){c.lineTo(b.width-l,d*f);l=l>0?0:Math.random()*10+8}c.lineTo(b.width,i);if(m>j&&e>0){j=(m-j)*g;d=b.width*0.8;a?c.lineTo(d+j,i):c.lineTo(d,i);m=m*g;c.lineTo(d,
m);e=e*g;c.lineTo(d-e,m);a?c.lineTo(d-e-j,i):c.lineTo(d-e,i)}a?c.lineTo(n+h,i):c.lineTo(n,i);c.lineTo(n,k);c.closePath();e=new Image;e.src=document.getElementById("imgBg").src;e=c.createPattern(e,"repeat");c.fillStyle=e;c.fill();c.strokeStyle="#808080";c.stroke()}document.getElementById("cnvsSection").style.display="block"}else document.getElementById("cnvsSection").style.display="none"}function Point(e,a){this._x=e;this._y=a}
function ShowForm(){document.getElementById("divInput").style.display="block";document.getElementById("hlShowForm").style.display="none"}
function Demo(){var e;switch(shape){case "R":e="3000,4000";break;case "L":e="4000,4000,2200,2000";break;case "U":e="7000,6000,6000,2000,2000,2000";break;case "T":e="2000,6000,3000,2000,2000,2000";break;case "H":e="7000,2000,2000,2000,2000,2000,6000,2000,2000,2000";break}e=e.split(",");for(var a=0;a<e.length;a++)document.getElementById("txt"+a).setAttribute("value",e[a]);Calculate()}
function RestoreConcrete(){var e=document.location.toString();if(e.indexOf("?frm=")>-1){e=e.substring(e.indexOf("?frm=")+5);if(e.indexOf("&")>-1)e=e.substring(0,e.indexOf("&"));e=e.split(",");var a=document.getElementById("tdSides");a.innerHTML="";for(var b,d=/txt[\d]/,h=0,j=0;j<e.length;j++){var k=e[j];b=k.substring(0,k.indexOf(";"));k=k.substring(k.indexOf(";")+1,k.length);if(d.test(b)){a.innerHTML+="Side "+(h+1)+" ";b=document.createElement("input");b.setAttribute("type","text");b.setAttribute("class",
"Num");b.setAttribute("id","txt"+j);b.setAttribute("value",k);a.appendChild(b);a.appendChild(document.createElement("br"));h++}else{b=document.getElementById(b);if(b.type=="text")b.setAttribute("value",k);else if(b.type=="radio"||b.type=="checkbox")b.checked=k=="1"?"true":"";else if(b.type=="select-one")b.selectedIndex=k}}SetInput();shape=document.getElementById("txtShape").value;document.images.imgType.src="images/Concrete/Conc"+shape+".gif";Calculate()}};
