extern function convert(){
	var scur = WMLBrowser.getVar("startCur");
	var ecur = WMLBrowser.getVar("endCur");
	var cur = WMLBrowser.getVar("cur");
	var curVal = Lang.parseInt(cur);
	if(curVal){
	 if(scur != ecur){ //if you're not converting, don't bother...
	    var endval = convertVal(scur, ecur, curVal);
	 }
	 else { endval = cur;}
	 endval = String.format("%1.2f", endval);
	 WMLBrowser.setVar("ans", endval);
	 WMLBrowser.go("currency.wml#convD");
	}
	else{
		error(cur);
	}
}

function error(badVal){
	Dialogs.alert("Your value " + badVal + " is bad");
	WMLBrowser.setVar("cur", "");
	WMLBrowser.go("#valCard");
}

function convertVal(scur, ecur, val){
	// set the conversion values
	var usd = 1;
	var lira = 1858.22;
	var dmark = 1.6535;
	var franc = 5.5425;
	
	// convert it all to usd
	if (scur == "USD"){
	} else if (scur == "Lira"){
		val = val / lira;
	} else if (scur == "DMark"){
		val = val / dmark;
	} else if (scur == "Franc"){
		val = val / franc;
	}
	
	// convert to dest currency
	if (ecur == "Lira"){		// going to Lira
		return(val*lira);
	}else if (ecur == "DMark"){	// going to Deutch Mark
		return(val*dmark);
	}else if (ecur == "Franc"){	// going to French Franc
		return(val*franc);
	}else{				// going to US Dollar
		return(val); 		
	}

}

