function calculator() {
if (document.inputform.od.value == 0) { alert("Please select the External pipe diameter"); return false;
}
OD = document.inputform.od.value;
if (document.inputform.mrs.value == 0) { alert("Please select the Minimum Required Strength (MRS)"); return false;
}
MRS = document.inputform.mrs.value;
if (document.inputform.fos.value == 0) { alert("Please select the desired design Factor of Safety (C)"); return false;
}
C = document.inputform.fos.value;
if (document.inputform.sdr.value == 0 && document.inputform.mop.value == "")
{ alert("Select the SDR OR enter a MOP"); return false;
}
if (document.inputform.sdr.value != 0 && document.inputform.mop.value != "")
{ alert("Only the SDR should be selected OR the MOP entered but not both"); return false;
}
SDR = document.inputform.sdr.value;
if (document.inputform.mop.value < 0 || document.inputform.mop.value > 25 ) { alert("Please enter a MOP value between 0 and 25 Bar"); return false;
}
tempMOP = document.inputform.mop.value;
if (SDR != 0) {
T=Math.round((OD/SDR)*100)/100;
ID=Math.round((OD-(2*T))*100)/100;
if (T < 1.8 || T >= 100 || T >65 && SDR == 7.4 || T < 2.0 && SDR == 33) { alert("The SDR selected is not availble for the external pipe diameter selected"); return false;
}

}
if (SDR != 0) {
MOP=Math.round(((20*MRS)/(C*(SDR-1)))*100)/100;
//document.write("the MOP is" + MOP + "<br>");
}
if (tempMOP !="") {
// set SDR to minimum value of 7.4
SDR=7.4;
DR = Math.round(((20*MRS)/(C*tempMOP))+1);

var newSDR=new Array(9);
newSDR[0]=7.4;
newSDR[1]=9;
newSDR[2]=11;
newSDR[3]=13.6;
newSDR[4]=17;
newSDR[5]=17.6;
newSDR[6]=21;
newSDR[7]=26;
newSDR[8]=33;
newSDR[9]=41;
// for loop start
for (i = 0; i < 10; i++) {
if (DR >= newSDR[i]) {
SDR=newSDR[i];
}
T=Math.round((OD/SDR)*100)/100;
ID=Math.round((OD-(2*T))*100)/100;
}
if (OD==32 && SDR >= 21) {SDR=17.6; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
if (OD==40 && SDR >= 26) {SDR=21; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
if (OD >= 50 && OD <= 63 && SDR >= 33) {SDR=26; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
if (OD >= 500 && OD <= 800 && SDR <= 7.4) {SDR=9; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
if (OD >= 900 && OD <= 1000 && SDR <= 9) {SDR=11; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
if (OD >= 1100 && OD <= 1200 && SDR <= 11) {SDR=13.6; T=Math.round((OD/SDR)*100)/100; ID=Math.round((OD-(2*T))*100)/100;}
MOP=Math.round(((20*MRS)/(C*(SDR-1)))*100)/100;
}
document.inputform.id.value=ID;
document.inputform.t.value=T;
document.inputform.mop.value=MOP;
document.inputform.sdr.value=SDR;
}
