// JavaScript Document
// 0 = cubic feet, 1 = cubic meters
var volume_array = new Array(2);
// cubic feet to cubic feet, cubic meters
volume_array[0] = new Array(1, 0.028317);
// cubic feet to cubic feet, cubic meters
volume_array[1] = new Array(35.3145, 1);

function calculatevolume()
{
	var in_from = document.calcform.volfrom.options[document.calcform.volfrom.selectedIndex].value;
	var in_to = document.calcform.volto.options[document.calcform.volto.selectedIndex].value;
	var in_value = parseInt(document.calcform.volvalue.value);
	var strresult = "";
	
	if (isNaN(in_value) == false)
	{
		in_value = in_value * volume_array[in_from][in_to];
		strresult = in_value;
	}
	// Display the result on the page
	document.calcform.vol_result.value = strresult;
}

// 0 = cms, 1 = inches, 2 = feet, 3 = meters
var distance_array = new Array(4);
// cms to cms, inches, feet, meters
distance_array[0] = new Array(1, 0.3937, 0.0328083, 0.01);
// inches to cms, inches, feet, meters
distance_array[1] = new Array(2.54, 1, 0.08333333, 0.0254);
// feet to cms, inches, feet, meters
distance_array[2] = new Array(30.48, 12, 1, 0.3048);
// meters to cms, inches, feet, meters
distance_array[3] = new Array(100, 39.37, 3.201, 1);

function calculatedistance()
{
	var in_from = parseInt(document.calcform.distfrom.options[document.calcform.distfrom.selectedIndex].value);
	var in_to = parseInt(document.calcform.distto.options[document.calcform.distto.selectedIndex].value);
	var in_value = parseInt(document.calcform.distvalue.value);
	var strresult = "";
	
	if (isNaN(in_value) == false)
	{
		in_value = in_value * distance_array[in_from][in_to];
		strresult = in_value;
	}
	// Display the result on the page
	document.calcform.dist_result.value = strresult;
}

// 0 = lbs, 1 = kgs, 2 = ton (short), 3 = ton (long), 4 = tonne (metric)
var weight_array = new Array(5);
// lbs to lbs, kgs, short ton, long ton, metric tonne
weight_array[0] = new Array(1, 0.4536, 0.0005, 0.0004464286, 0.0004535924);
// kgs to lbs, kgs, short ton, long ton, metric tonne
weight_array[1] = new Array(2.2046, 1, 0.0011023, 0.0009842, 0.001);
// short ton to lbs, kgs, short ton, long ton, metric tonne
weight_array[2] = new Array(2000, 907.1847, 1, 0.8928571, 0.9072);
// long ton to lbs, kgs, short ton, long ton, metric tonne
weight_array[3] = new Array(2240, 1016.047, 1.12, 1, 1.016);
// metric tonne to lbs, kgs, short ton, long ton, metric tonne
weight_array[4] = new Array(2204.623, 1000, 1.102, 0.9842, 1);

function calculateweight()
{
	var in_from = parseInt(document.calcform.weightfrom.options[document.calcform.weightfrom.selectedIndex].value);
	var in_to = parseInt(document.calcform.weightto.options[document.calcform.weightto.selectedIndex].value);
	var in_value = parseInt(document.calcform.weight_value.value);
	var strresult = "";
	
	if (isNaN(in_value) == false)
	{
		in_value = in_value * weight_array[in_from][in_to];
		strresult = in_value;
	}
	// Display the result on the page
	document.calcform.weight_result.value = strresult;
}

// 0 = celsius, 1 = fahrenheit
function calculatetemperature()
{
	var in_from = document.calcform.tempfrom.options[document.calcform.tempfrom.selectedIndex].value;
	var in_to = document.calcform.tempto.options[document.calcform.tempto.selectedIndex].value;
	var in_value = parseInt(document.calcform.tempvalue.value);
	var strresult = "";

	if (isNaN(in_value) == false)
	{
		if (in_from != in_to)
		{
			if (in_from == 0)		// celsius to fahrenheit
				in_value = (in_value / (5/9)) + 32;
			else					// fahrenheit to celsius
				in_value = (in_value - 32) * (5/9);
		}
		strresult = in_value;
	}
	// Display the result on the page
	document.calcform.temp_result.value = strresult;
}

var l=0;
var r=0;
var tc="";
var al=" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
var ns="0123456789";
function iA(){
 this.length=iA.arguments.length;
 for (var i=0;i<this.length;i++){
  this[i]=iA.arguments[i];
 }
}

var a=new iA(35);
a[0]="Berlin, Germany*   ciagchdcheihh dadeee gcaa hdef egeghfaciibf da  cifdcd ebehe eddegagecehadhfaa gcgh e debbfageedkbgdca";
a[1]="Bombay, India*   ibga deacde dhabfgh bbiifhgddfhg caefa igbcacggiei dacigddcfbifbffgcgeaihbfchdj dggdcacbdcdaigfhbhf";
a[2]="Buenos Aires, Argentina*   jbddbgiaceifkdfgefgegggffibfabk dgbcdfchchec hhegfacchfhhkiggcfefhga abbfic gffialb ihfkd fbffdb";
a[3]="Calcutta, India*   f ccgdeebaecg dcfefccdiehaebaieeeie cdegibebgddfjaadhib bceagdhedaichde jiigbbbaaagicaig dchf";
a[4]="Capetown, South Africa*   fiee hgcgkecebbjccf aiiggecfdaheafbigh jaafdig aehdh edeighfgaacggebee  jb h ff bi gg bbce";
a[5]="Darwin, Australia*   ibgbfdecfgcigaahf ghdaihaifi hg eiiffbdh bjcehehcgcgafigbhfciifhaihifgfbcadb hccgccafda";
a[6]="Gibraltar*   fhch hahgebga ieidgdhjh efcbdacfced agidic iff abahcchb edgha cfdaedfffegbcfiil fda ";
a[7]="Hong Kong, China*   eeddihefceihgbd fidfahghdddh edeeecdj heifabcdihgfef ck  eggkfafdg ggafeah eheeda";
a[8]="Honolulu, Hawaii, USA*   ha bhbgbcbefec eeacghg cdifc  fghebegdce ghgde  f hhaih bfgibfhdicfgachedgajhg";
a[9]="Istanbul, Turkey*   ee aeefhdeffi iga a ie aea aebfgead dch fidfdbeffd  hehagf fdifecgeefjffcca";
a[10]="Juneau, Alaska, USA*   ddbahdehgh dcbbdecbhea id eddfdfcdebfbbbffcbggf ebegbg i dhggbdd agdhhh ";
a[11]="London, England, UK*   eddffgje eedaeecdfdch gaebh bae ebaeca aagegg higbfdghegafgdeidkfhdf ";
a[12]="Los Angeles, CA, USA*   gbggicaedf gbdebhheccc  ef fbegecbehdcafc fcceec iffdhhggedgfgaj b";
a[13]="Manilla, Luzon, Phillipines*   cidhhceachdidhbf bjbhffgaggefbhabffekbefdfjicffdaaeadhahfeafegf";
a[14]="Melbourne, Australia*   hdbhifjcfgefiici bjd efghffje jedhaiiicg  haie acgfe iaf fh ";
a[15]="Mexico City, Mexico*   ffib idcaegaae egaggcgfgbdedfbdggfced ebcdh djcag dfi idh";
a[16]="Moscow, Russia*   dffd da bfgaaedcf agadbdb fgb adghgieb dbdebddfejbhdbg";
a[17]="New York City, NY, USA*   cggcfgbbccfbfhbeei ddbehdhbdbge ibdagcfifcfgdhiegg ";
a[18]="Nome, Alaska, USA*   chdeeddegcdcegecdiccgheie hhcfaihcghfaebihgchhba";
a[19]="Oslo, Norway*   efi hcdcfbbacbfa hfdhabdgiadeie bfbeebbjigdh ";
a[20]="Panama City, Panama*   echhiagaebffdgacbiei bidcfeicbkfihdbgdchbe";
a[21]="Paris, France*   ea aihcbdacheg  fhgbediiegeffgf ckgidd ";
a[22]="Peking, China*   dehfdbdi jgge ekgged  ffbggacafg eh ";
a[23]="Port Said, Suez Canal, Egypt*   ebecbcfbdacbh ifgfeace iehdjbebgc";
a[24]="Quebec, Quebec, Canada*   baieaccidee bcefihia fdbibcgdd";
a[25]="Reykjavik, Faxa Bay, Iceland*   fabb dgbccfaeefgafedgjgbegf";
a[26]="Rio de Janeiro, Brazil*   efiahffhikcdiggkedgceeei";
a[27]="Rome, Italy*   gdbeffefhfbcfabkebcga";
a[28]="Santiago, Chile*   fbckfejbcjfdegigah";
a[29]="Seattle, Washington, USA*   eg h fdghgbdicf";
a[30]="Shanghai, China*   bcha if eeig";
a[31]="Singapore, Singapore*   cc ebiddh";
a[32]="Tokyo, Japan*   egfg d";
a[33]="Wellington, New Zealand*   hab";
a[34]="Zanzibar City, Tanzania*   ";
var b=new iA(4);
b[0]=1;
b[1]=10;
b[2]=100;
b[3]=1000;
b[4]=10000;
function getMiles(form){
 lf=(document.isn.isn1.options[document.isn.isn1.selectedIndex].value);
 rf=(document.isn.isn2.options[document.isn.isn2.selectedIndex].value);
 l=al.indexOf(lf);
 r=al.indexOf(rf);
 if (r<l){
  l=r;
  r=al.indexOf(lf);
  }
 ls=a[l];
 pos=ls.indexOf("*")
 ls1="From "+ls.substring(0,pos)+" to "
 +a[r].substring(0,a[r].indexOf("*"))+" is about ";
 ls=ls.substring(pos+1,ls.length);
 tc=ls.substring(((r*3)-(l*3)),ls.length);
 if (document.isn.rb[1].checked){
  dispKm();
  }
 else{
  dispMi();
  }
}
function dispMi(){
 ch=tc.charAt(0);
 ls1+=al.indexOf(ch);
 ch=tc.charAt(1);
 ls1+=al.indexOf(ch);
 ch=tc.charAt(2);
 if (ch!=" "){
  ls1+=(al.indexOf(ch)*10)+" miles";
  } //1.613
  else ls1+="00 miles";
 document.isn.disp.value=ls1;
}
function dispKm(){
 ch=tc.charAt(0);
 km="";
 km+=al.indexOf(ch);
 ch=tc.charAt(1);
 km+=al.indexOf(ch);
 ch=tc.charAt(2);
 if (ch!=" "){
  km+=(al.indexOf(ch)*10);
  }
  else{
   km+="00";
  }
  num=0;
  kml=km.length;
  for (var i=kml-1;i>-1;i--){
   cr=km.substring(i,i+1);
   pos=ns.indexOf(cr);
   num+=pos*b[kml-i-1];
  }
  km="";
  km+=num*1.613;
  pos=km.indexOf(".");
  if (pos>-1){
   km=km.substring(0,pos);
  }
  ls1+=km+" kilometers";
  document.isn.disp.value=ls1;
}

function calculatetime()
{
	var strresult
	
	// Calculate the difference between the two cities.
	var time_diff =	parseInt(document.timeform.second.options[document.timeform.second.selectedIndex].value)
					- parseInt(document.timeform.first.options[document.timeform.first.selectedIndex].value) 
					
	// Get the time the user entered
	var base_time = parseInt(document.timeform.compare_time.options[document.timeform.compare_time.selectedIndex].value);

	// Determine if morning or afternoon, if it is the afternoon we have to add 12 hours
	if (document.timeform.ampm.options[document.timeform.ampm.selectedIndex].value == 'PM')
		base_time = base_time + 720;

	// Apply the calculated difference to the user entered time
	var dest_time = base_time + time_diff
	
	// Check if it is the same day, previous or next...
	strresult = " on the same day"
	if (dest_time < 0)
	{
		dest_time = 1440 - Math.abs(dest_time);
		strresult = " on the previous day";
	}
	else if (dest_time > 1410)
	{
		dest_time = Math.abs(dest_time) - 1440;
		strresult = " on the next day";
	}

	// Check for afternoon or morning and adjust
	if (dest_time >= 720)
	{
		strresult = " PM" + strresult;
		dest_time -= 720;
	}
	else
		strresult = " AM" + strresult;

	// Convert the minutes into an actual time....
	var minutes = dest_time%60;
	var hours = (dest_time - minutes) / 60;
	if (hours == 0)
		hours = "12";
	if (minutes == 0)
		minutes = "00";
	strresult = hours + ":" + minutes + strresult;
	
	// Display the time on the page
	document.timeform.result.value = strresult;
}

