function click(){
	if(event.button==2){
		alert("Sorry."); 
		}
	}
document.onmousedown=click

// Author    : Phil Locker (phil@philsfoils.com) 
function Reynoldscalc(form){
    // velocity
	if (form.velocity.value == null || form.velocity.value.length == 0) {
            form.reynolds_num.value = "error";
		return false;
      }

	// chord
	if (form.chord.value == null || form.chord.value.length == 0) {
            form.reynolds_num.value = "error";
		return false;
      }

    // fluid constant
	if (form.fluid.value == null || form.fluid.value.length == 0) {
            form.reynolds_num.value = "error";
		return false;
      }
	var enteredvelocity = formatnumbers(form.velocity.value, form.rsize);
	var enteredchord = formatnumbers(form.chord.value, form.rsize);
	var enteredfluid = formatnumbers(form.fluid.value, form.rsize);
	
	var velftsec;
	var chordft;
   
    if (form.v_units.selectedIndex == 0){
    	velftsec = enteredvelocity;
    }
    else {
    	if (form.v_units.selectedIndex == 1){
    		velftsec = enteredvelocity * 3.28084;
    	}
    	else {
    		velftsec = enteredvelocity * 1.68781 ;
    	}
     }
	if (form.c_units.selectedIndex == 0) {
		chordft = enteredchord / 12.0;
	}
	else {
		chordft = enteredchord / 304.8;
	}
	form.reynolds_num.value = formatnumbers(velftsec * chordft / enteredfluid, form.rsize);
	return true;
}

function corecalc(form){
      // chord
	if (form.outsidechord.value == null || form.outsidechord.value.length == 0) {
            form.outputs.value = "Missing input.";
		return false;
      }

	// max thickness
	if (form.outsidethickness.value == null || form.outsidethickness.value.length == 0) {
            form.outputs.value = "Missing input.";
		return false;
      }

      // skin thickness
	if (form.skin.value == null || form.skin.value.length == 0) {
            form.outputs.value = "Missing input.";
		return false;
      }
	  var initialchord = formatnumbers(form.outsidechord.value, form.rsize);
      var initialthickness = formatnumbers(form.outsidethickness.value, form.rsize);
      var skinthickness = formatnumbers(form.skin.value, form.rsize);
     //remember to check output of formatnumber for invalid string ******

      var maxthickness = 0;
      var percentthickness = 0;

      // absolute
      if (form.thicknesstype.selectedIndex == 0){
        percentthickness = (initialthickness / initialchord) * 100.0;
        maxthickness = initialthickness;
      }
      // percentage
      else {
        maxthickness = initialchord * (initialthickness / 100.0);
        percentthickness = initialthickness;
      }
	
	if ((skinthickness * 10) > maxthickness) {
		form.outputs.value = "Skin can not exceed 10% of total thickness.  Try again.";
		return false;
	}

   	txt1="External dimensions:\n----------------\nChord: ";
      txt2="\nMax. Thickness: ";
      txt3=" (";
      txt4=" percent)";
      var outputstring;
	var internalchord;
	var internalmax;
	outputstring = txt1 + initialchord + txt2 + maxthickness + txt3 + percentthickness + txt4;

if (skinthickness == 0)
{
	internalchord = initialchord;
	internalmax = maxthickness;
	outputstring += "\nFor skin thickness of 0, core dimensions == external dimensions";
}
else
{

	internalmax = maxthickness - (skinthickness * 2);
	internalchord = internalmax / (percentthickness / 100);
	
	// now find where chord tapers down to skin thickness
	//var xoffset = 1;
	//var yoffset = 0;
	//while (yoffset < skinthickness) {
	//	xoffset -= 0.005;
	//	yoffset = calcoffsets(xoffset,maxthickness);
   //   }
   // internalchord = (initialchord * xoffset) - skinthickness;
	// internalmax = maxthickness - (skinthickness * 2);

	txt5="\n\nCore dimensions:\n----------------\nChord: ";
	txt6="\nMax. Thickness: ";   
      outputstring += txt5 + internalchord + txt6 + internalmax;
}
	outputstring += "\n\nCore Offsets: (X,Y)";
	// to be truly correct, leading edge radius = 1.1019 * percentthickness ^ 2
      for (x = 0; x <= 10; x++) {
		xindex = x / 100;
		yoffset = calcoffsets(xindex,internalmax);
            xoffset = internalchord * xindex;
		outputstring += "\n";
            outputstring += formatnumbers(xoffset,5);
		outputstring += ",";
		outputstring += formatnumbers(yoffset,5);
	}
 	for (x = 6; x <= 50; x++) {
		xindex = x / 50;
		if (x < 50) {
			yoffset = calcoffsets(xindex,internalmax);
			xoffset = internalchord * xindex;
		}
		else
		{
			yoffset = 0;
			xoffset = internalchord;
		}
		outputstring += "\n";
            outputstring += formatnumbers(xoffset,5);
		outputstring += ",";
		outputstring += formatnumbers(yoffset,5);
	}

      form.outputs.value = outputstring;
      return true;
 
}

function calcoffsets(position,maxt) {
// y(x) = t/0.20 (ax^(1/2) + bx + cx^2 + d x^3 + ex^4)
// a = +0.29690  b = -0.12600  c = -0.35160  d = +0.28430 e = -0.10150
var height;
var c1 = 0.29690 * Math.pow(position,0.5);
var c2 = -0.12600 * position;
var c3 = -0.35160 * Math.pow(position,2);
var c4 = 0.28430 * Math.pow(position,3);
var c5 = -0.10150 * Math.pow(position,4);
height = (maxt / 0.20) * (c1 + c2 + c3 + c4 + c5);
return height;
}

function formatnumbers(input, rsize) {

   var invalid = "**************************";

   var nines = "999999999999999999999999";

   var strin = "" + input;

   var fltin = parseFloat(strin);

   if (strin.length <= rsize) return strin;

   if (strin.indexOf("e") != -1 ||

       fltin > parseFloat(nines.substring(0,rsize)+".4"))

      return invalid.substring(0, rsize);

   var rounded = "" + (fltin + (fltin - parseFloat(strin.substring(0, rsize))));

   return rounded.substring(0, rsize);

}


function clearcoreform(form) {
    form.outsidechord.value = "";
    form.outsidethickness.value = "";
    form.skin.value = "";
    form.outputs.value = "cleared results";
    return true;
}

function clearReynoldsform(form) {
    form.velocity.value = "0";
    form.chord.value = "0";
    form.fluid.value = "0.0000123";
    form.reynolds_num.value = "0";
    return true;
}

