You are on page 1of 4

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.

01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Online Conversion - Tip Calculator</title>
<meta name="DESCRIPTION" content="Calculates the tip or determine how much each
person should pay for meals.">
<meta name="KEYWORDS" content="tip, restaurant, meals, pay">
<link href="/style.css" rel="stylesheet" type="text/css">
<link href="/print.css" rel="stylesheet" type="text/css" media="print">
<script language="JavaScript" src="/misc_functions.js" type="text/javascript"></
script>

<script language="JavaScript">
<!--
// Tip Calculator Copyright 2003 by OnlineConversion.com
// No use without permission
function netscapeKeyPress(e) {
if (e.which == 13)
calculateTip();
}
function microsoftKeyPress() {
if (window.event.keyCode == 13)
calculateTip();
}
if (navigator.appName == 'Netscape') {
window.captureEvents(Event.KEYPRESS);
window.onKeyPress = netscapeKeyPress;
}
function stripBad(string) {
for (var i=0, output='', valid="0123456789."; i<string.length; i++)
if (valid.indexOf(string.charAt(i)) != -1)
output += string.charAt(i)
return output;
}
function comma(num) {
var n = Math.floor(num);
var myNum = num + "";
var myDec = ""
if (myNum.indexOf('.',0) > -1){
myDec = myNum.substring(myNum.indexOf('.',0),myNum.length);
}
var arr=new Array('0'), i=0;
while (n>0)
{arr[i]=''+n%1000; n=Math.floor(n/1000); i++;}
arr=arr.reverse();
for (var i in arr) if (i>0) //padding zeros
while (arr[i].length<3) arr[i]='0'+arr[i];
return arr.join() + myDec;
}
function resetAnswer()
{
document.TipForm.tipResult.value = "";
document.TipForm.totalResult.value = "";
//document.TipForm.tipEachResult.value = "";
document.TipForm.totalEachResult.value = "";
}
function cent(amount)
{
amount -= 0;
amount = Math.round(amount * 100)/100;
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math
.floor(amount*10)) ? amount + '0' : amount);
}
function calculateTip()
{
var billAmount = parseFloat(stripBad(document.TipForm.billAmount.value));
if (isNaN(billAmount)) billAmount = 0.0;
document.TipForm.billAmount.value = comma(cent(billAmount));
var tipPercentage = parseFloat(stripBad(document.TipForm.tipPercentage.value))
;
if (isNaN(tipPercentage)) tipPercentage = 0.0;
document.TipForm.tipPercentage.value = tipPercentage;
var qtyPeople = parseInt(stripBad(document.TipForm.qtyPeople.value));
if (isNaN(qtyPeople)) qtyPeople = 1;
if (qtyPeople < 1) qtyPeople = 1;
document.TipForm.qtyPeople.value = qtyPeople;
var tipResult = 0;
var totalResult = 0;
//var tipEachResult = 0;
var totalEachResult = 0;
tipResult = (tipPercentage / 100) * billAmount;
totalResult = tipResult + billAmount;
//tipEachResult = tipResult / qtyPeople;
totalEachResult = totalResult / qtyPeople;
document.TipForm.tipResult.value = comma(cent(tipResult));
document.TipForm.totalResult.value = comma(cent(totalResult));
//document.TipForm.tipEachResult.value = comma(cent(tipEachResult));
document.TipForm.totalEachResult.value = comma(cent(totalEachResult));
}
//-->
</script>
</head>
</tr>
<tr><td WIDTH="310" valign="top" align="left" colspan="2"><img src="/black.gif"
WIDTH="310" height="1" alt="" border="0"></td></tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" WIDTH="310">
<tr>
<td width="470" valign="top">
<table border="0" cellpadding="10" cellspacing="0" width="470">
<tr>
<td width="470" valign="top" class="content">
<div align="LEFT">
<h2>Welcome to OnlineConversion.com</h2>
<span class="red">Tip Calculator</span>
</div>
<!-- Place main data here -->
<script language="JavaScript" src="/browser_detection.js" type="text/javascript"
></script>
<noscript>
<blockquote>
<p><font size="3" color="#FF0000"><b>You do not have JavaScript enabled.</b></fo
nt><br>
<font size="2" color="#000080">The conversions on this site require the use of J
avaScript so please enable before continuing.
For assistance in enabling JavaScript, please contact the webmaster.</font></p>
</blockquote>
</noscript>

<form name="TipForm">
<div align="LEFT">
<table border="0">
<tr>
<td>Amount of Bill:</td>
<td align="LEFT"><b>$</b><input type="text" name="billAmount" size="7" onF
ocus="javascript:resetAnswer();" onKeyPress="microsoftKeyPress();"></td>
</tr>
<tr>
<td>Percentage to Tip:</td>
<td align="LEFT"><input type="text" name="tipPercentage" size="4" value="1
5" onFocus="javascript:resetAnswer();" onKeyPress="microsoftKeyPress();"><b>%</b
></td>
</tr>
<tr>
<td>Number of People:</td>
<td align="LEFT"><input type="text" name="qtyPeople" size="4" value="1" on
Focus="javascript:resetAnswer();" onKeyPress="microsoftKeyPress();"></td>
</tr>
<tr>
<td colspan="2" align="LEFT"><input type="button" value="Calculate" onClic
k="javascript:calculateTip();"><input type="reset"></td>
</tr>
<tr>
<td>Tip Amount:</td>
<td><b>$</b><input type="text" name="tipResult" size="7" READONLY></td>
</tr>
<tr>
<td>Total to Pay:</td>
<td><b>$</b><input type="text" name="totalResult" size="7" READONLY></td>
</tr>
<!--
<tr>
<td>Tip per Person</td>
<td><b>$</b><input type="text" name="tipEachResult" size="7" READONLY></td
>
</tr>
-->
<tr>
<td>Total per Person:</td>
<td><b>$</b><input type="text" name="totalEachResult" size="7" READONLY></
td>
</tr>
</table>
</div>
</form>

</BODY>
</HTML>

You might also like