basic.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * JavaScript
  3. */
  4. // dist and co2 calculation
  5. var Orig=new Array();
  6. var Dest=new Array();
  7. var nm=0;
  8. var tc=0;
  9. function DoCalc(form) {
  10. from_airport=form.from.options[form.from.selectedIndex].value;
  11. dest_airport=form.to.options[form.to.selectedIndex].value;
  12. if (from_airport=="" || dest_airport=="") {
  13. alert("Please select Origin and Destination City.");
  14. //alert not working in s40 to check with forum
  15. }
  16. else {
  17. Orig=from_airport.split("/");
  18. Dest=dest_airport.split("/");
  19. d=Math.acos(Math.sin(Orig[2])
  20. *Math.sin(Dest[2])
  21. +Math.cos(Orig[2])
  22. *Math.cos(Dest[2])
  23. *Math.cos(Orig[4]-Dest[4]));
  24. nm=Math.round(3437.747*d);
  25. if (Math.sin(Dest[4]-Orig[4]) < 0) {
  26. tc=Math.acos((Math.sin(Dest[2])
  27. -Math.sin(Orig[2])*Math.cos(d))
  28. /(Math.sin(d)*Math.cos(Orig[2])));
  29. }
  30. else {
  31. tc=2*Math.PI
  32. -Math.acos((Math.sin(Dest[2])
  33. -Math.sin(Orig[2])
  34. *Math.cos(d))/(Math.sin(d)
  35. *Math.cos(Orig[2])));
  36. }
  37. tc=Math.round(tc*(180/Math.PI));
  38. var aircarbon = Math.round((nm*1.13636)*0.45);
  39. aircarbon + 'lbs\n'
  40. var carcarbon = Math.round(((nm*1.13636)/23.5)*19.42);
  41. if (aircarbon<=carcarbon){
  42. reccom = "TRAVEL BY AIR";
  43. }
  44. else {
  45. reccom = "TRAVEL BY CAR";
  46. }
  47. form.textarea.value ='BY AIR - '+aircarbon +' lbs' + '\nBY CAR - ' + carcarbon +' lbs [23 miles/gallon]\n'+reccom+'\n';
  48. }
  49. }
  50. // End -->