// JavaScript Document

$().ready(function(){
		//$('.conTable tr:odd').css({color:'red',backgroundColor:'blue'});
		$('.conTable input:even').css({width:40});
		

});



function calculate(obj, inform) {
    with (inform) {
        if ( U2.options[U2.selectedIndex].value != 0 && isnum(V1.value) )
            V2.value=eval(V1.value) * eval(U1.options[U1.selectedIndex].value)
                    /eval(U2.options[U2.selectedIndex].value);
        }
}

function tempconvert(obj,inform) {
   
	with (inform) {
	    var u1val = U1.options[U1.selectedIndex].value;
        var u2val = U2.options[U2.selectedIndex].value;
        var ab0c = 273.2*1;
        var T1=V1.value*1,T2=1*1-1;
	
		if (isnum(V1.value) ) { 
			if (u1val==u2val) {
				T2=T1;
			}
			else if (u2val==1) {
				if (u1val==2) {T2=(T1 - 32)*5/9;}
				else  {T2 = T1 - ab0c;}
			}
			else if (u2val==2) {
				if (u1val==1) { T2 = T1*9/5 + 32;}
				if (u1val==3) { T2 = (T1-ab0c)*9/5 + 32;}
			}
			else if (u2val==3) {
				if (u1val==1) { T2 = (ab0c+T1);}
				else { T2=(ab0c+(T1 - 32)*5/9)*1;}
			}
			V2.value=T2;	
				
		}
	}
}				

function windchillMetric(inform) {
inform.chill.value="";
         wind=inform.wind.value;
         temp=inform.temp.value;
	if(isnum(wind) && isnum(temp)) {
	  
        // chill=((5.27*(Math.pow(wind, 0.5)) + 10.45-0.28*wind)/5.27*(temp-33)+33);
         chill = 13.112 + 0.6215*temp -(11.37 - 0.3965*temp)* Math.pow(wind,0.16)
        inform.chill.value = twodp(Math.round(chill*100)/100);
}}

function windchillImperial(inform) {
inform.chill.value="";
         wind=inform.wind.value;
         temp=inform.temp.value;
	if(isnum(wind) && isnum(temp)) {
	  
        // chill=((5.27*(Math.pow(wind, 0.5)) + 10.45-0.28*wind)/5.27*(temp-33)+33);
         chill = 35.74 + 0.6215*temp -(35.75 - 0.4275*temp)* Math.pow(wind,0.16)
        inform.chill.value = twodp(Math.round(chill*100)/100);
}}
        
function PressureAtAltitude(inform) {


var T0 = inform.TemperatureAtSeaLevel.value*1.0 + 273.2;
//K Temperature at sea level

var P0 = inform.PressureAtSeaLevel.value*1;
//hpa Pressure at sea level

var z = inform.Altitude.value*1;
//altitude can be null


var R = 8314*1.0; 
//R in J K-1 mol-1 gas constant

var Ma = 28.96*1.0; 
//g mol-1 molecular weight of air


var g = 9.82*1.0;
//m s-2 acceleration due to garvity


if (isnum(z) && isnum(P0) && isnum(T0) ) {
pwr = -g*z/((2*T0-z/200)/2 * R/Ma);
P = P0*Math.exp(pwr);
inform.PressureatAltitude.value = parseInt(P);
}
}

function isnum(num) {
if ( num == 0 ) {
        return true;
    }
    if ( num == "" ) {
        return false;
    }
    for (var i=0; i < num.length; i++) {
       var ch= num.substring (i, i+1)
       if ((ch < "0" || ch > "9" ) && ch != "." && (i>1 && ch =="-") ) {
       
       	            return false;
       }
    }
    
    return true;
}
 
  function twodp(n) {

    var ns = n.toString();
   
    var dp = ns.indexOf(".");
   if (dp < 0) ns = ns+".00";
   else if (dp == ns.length-2) ns = ns+"0";
   else if (dp < ns.length-1) ns = ns.substring(0,dp+3);
   return ns;
}