<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd ">
<title>js Calculator </title>
<script type= "text/web Effects" >
var browser = new Object ();
Browser.ismozilla = (typeof document.implementation!= ' undefined ') && (typeof Document.implementation.createdocument!= ' undefined ') && (typeof htmldocument!= ' undefined ');
Browser.isie = Window.activexobject? True:false;
Browser.isfirefox = (navigator.userAgent.toLowerCase (). indexof ("Firefox")!=-1);
Browser.issafari = (navigator.userAgent.toLowerCase (). indexof ("Safari")!=-1);
Browser.isopera = (navigator.userAgent.toLowerCase (). indexof ("opera")!=-1);
var utils = new Object ();
Utils.htmlencode = function (text)
{
Return Text.replace (/&/g, ' & '). Replace (/"/g, '"). Replace (/</g, ' < '). Replace (/>/g, ' > ');
}
Utils.trim = function (text)
{
if (typeof (Text) = "string")
{
Return Text.replace (/^s*|s*$/g, "");
}
Else
{
return text;
}
}
Utils.isempty = function (val)
{
Switch (typeof (Val))
{
Case ' string ':
Return Utils.trim (val). length = 0? True:false;
Break
Case ' number ':
return val = = 0;
Break
Case ' object ':
return val = = null;
Break
Case ' array ':
return val.length = = 0;
Break
Default
return true;
}
}
Utils.isnumber = function (val)
{
var reg =/^[d|.|,]+$/;
Return Reg.test (Val);
}
Utils.isint = function (val)
{
if (val = = "")
{
return false;
}
var reg =/d+/;
Return!reg.test (Val);
}
Utils.isemail = function (email)
{
var reg1 =/([w.] +) @ ([[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}.) | (([w-]+.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (]?) /;
return reg1.test (email);
}
Utils.istel = function (tel)
{
var reg =/^[d|-|s|_]+$/; Only use numbers-spaces, etc.
Return Reg.test (tel);
}
Utils.fixevent = function (e)
{
var evt = (typeof e = "undefined")? Window.event:e;
return evt;
}
Utils.srcelement = function (e)
{
if (typeof e = = "undefined") e = window.event;
var src = document.all? E.srcelement:e.target;
return SRC;
}
Utils.istime = function (val)
{
var reg =/^d{4}-d{2}-d{2}sd{2}:d {2}$/;
Return Reg.test (Val);
}
Utils.x = function (e)
{//current mouse x coordinates
return browser.isie?event.x + Document.documentelement.scrollleft-2:e.pagex;
}
Utils.y = function (e)
{//current mouse y-coordinate
return browser.isie?event.y + document.documentelement.scrolltop-2:e.pagey;
}
utils.request = function (URL, item)
{
var svalue=url.match (New RegExp ("[?]" "+item+" = ([^&]*) (ampersand), "I"));
return svalue?svalue[1]:svalue;
}
utils.$ = function (name)
{
return document.getElementById (name);
}
Function rowindex (tr)
{
if (Browser.isie)
{
return tr.rowindex;
& nbsp
Else
{
table = Tr.parentnode.parentnode
for (i = 0; i < table.rows.length; i + +)
{
if (table.rows[i] = = TR)
{
return i;
}
}
}
Document.getcookie = function (sname)
{
Cookies are separated by semicolons
var acookie = Document.cookie.split (";");
for (Var i=0 i < acookie.length; i++)
{
A Name/value pair (a crumb) is separated by a equal sign
var acrumb = acookie[i].split ("=");
if (sname = = Acrumb[0])
Return decodeURIComponent (acrumb[1]);
}
A cookie with the requested name does not exist
return null;
}
Document.setcookie = function (sname, svalue, Sexpires)
{
var Scookie = sname + "=" + encodeURIComponent (svalue);
if (sexpires!= null)
{
Scookie + = "; expires= "+ sexpires;
}
Document.cookie = Scookie;
}
Document.removecookie = function (Sname,svalue)
{
Document.cookie = sname + "=; Expires=fri, Dec 1999 23:59:59 GMT; ";
}
function GetPosition (o)
{
var t = o.offsettop;
var L = o.offsetleft;
while (o = o.offsetparent)
{
T + + o.offsettop;
L + + O.offsetleft;
}
var pos = {Top:t,left:l};
return POS;
}
function Cleanwhitespace (Element)
{
var element = element;
for (var i = 0; i < element.childnodes.length; i++) {
var node = element.childnodes[i];
if (Node.nodetype = = 3 &&!/s/.test (node.nodevalue))
Element.removechild (node);
}
}
</script>
<style type= "Text/css Tutorial" >
Body, Div, input {
font:12px Arial;
}
. Calculatorbutton {
Text-align:center;
width:73px;
}
. calculatorbutton2 {
Text-align:center;
width:154px;
}
*+html. Calculatorbutton2 {
width:157px;
}
#calculator. Buttonarea {
padding:3px;
Border-color: #455690 #a6b4cf #a6b4cf #455690;
Border-style:solid;
border-width:1px;
}
#calculatoroutput {
padding:2px; BORDER:2PX inset; margin:2px;
}
#topbar {
Position:absolute;
Border-right: #455690 1px solid;
Border-top: #a6b4cf 1px solid;
Border-left: #a6b4cf 1px solid;
Border-bottom: #455690 1px solid;
Background-color: #c9d3f3;
width:300px;
Visibility:hidden;
z-index:99999;
Filter:progid:dximagetransform.microsoft.basicimage (opacity=.65);
opacity:0.65;
}
</style>
<script type= "Text/javascript" >
<!--
var Calculator = object ();
Calculator.result = 0;
Calculator.current = ';
calculator.values = 0;
Calculator.handle = ';
Calculator.elem = function () {return document.getElementById (' calculator ');
Calculator.output = function () {return document.getElementById (' Calculatoroutput ');}
Calculator.input = function (n)
{
if (n = = "." && calculator.current.tostring (). indexof ('. ') >=0)
{
Return
}
var output = Calculator.output ();
if (calculator.current = = "0" && N!= ".") calculator.current = ';
Calculator.current + = "" + N;
output.innerhtml = calculator.current;
}
Calculator.backspace = function ()
{
var output = Calculator.output ();
output.innerhtml = output.innerhtml.length > 1? Output.innerhtml.substr (0, output.innerhtml.length-1): 0;
Calculator.current = output.innerhtml;
}
Calculator.clear = function ()
{
Calculator.result = 0;
Calculator.current = ';
calculator.values = 0;
Calculator.handle = ';
var output = Calculator.output ();
output.innerhtml = "0";
}
calculator.calculate = function (p)
{
if (calculator.handle!= ' && calculator.values!= ' && calculator.current!= ')
{
Try
{
var value = eval (calculator.values + calculator.handle + calculator.current)
Calculator.values = value = = ' Infinity '? 0:value;
Calculator.output (). innerHTML = Calculator.values
}
catch (E)
{
Alert (e);
}
}
Else
{
Calculator.values = calculator.current== '? Calculator.values:calculator.current;
}
if (p = = ' = ')
{
Calculator.output (). innerHTML = Calculator.values = = "? ' 0 ': calculator.values;
Calculator.current = calculator.values;
Calculator.handle = ';
}
Else
{
Calculator.handle = p;
}
Calculator.current = ';
}
onload = function () {
Window.focus ();
}
-->
</script>
<body style= "Background:buttonface" >
<div class= "Buttonarea" >
<div id= "Calculatoroutput" style= "width:95%; text-align:right;border:2px inset;background: #fff; " >0</div>
<table width= "100%" >
<tr>
<TD colspan= "2" ><input type= "button" class= "Calculatorbutton2" value= "Early Love" onclick= "Calculator.clear" () ></td>
<TD colspan= "2" ><input type= "button" class= "Calculatorbutton2" value= "backspace" onclick= "Calculator.backspace" () /></td>
</tr>
<tr>
<td><input class= "Calculatorbutton" type= "button" value= "7" onclick= "Calculator.input (7)"/></td>
<td><input type= "button" value= "8" class= "Calculatorbutton" onclick= "Calculator.input (8)"/></td>
<td><input type= "button" value= "9" class= "Calculatorbutton" onclick= "Calculator.input (9)"/></td>
<td><input type= "button" value= "/" class= "Calculatorbutton" onclick= "calculator.calculate ('/')"/></ Td>
</tr>
<tr>
<td><input type= "button" value= "4" class= "Calculatorbutton" onclick= "Calculator.input (4)"/></td>
<td><input type= "button" value= "5" class= "Calculatorbutton" onclick= "Calculator.input (5)"/></td>
<td><input type= "button" value= "6" class= "Calculatorbutton" onclick= "Calculator.input (6)"/></td>
<td><input type= "button" value= "*" class= "Calculatorbutton" onclick= "calculator.calculate (' *")/></ Td>
</tr>
<tr>
<td><input type= "button" value= "1" class= "Calculatorbutton" onclick= "calculator.input (1)"/></td>
<td><input type= "button" value= "2" class= "Calculatorbutton" onclick= "Calculator.input (2)"/></td>
<td><input type= "button" value= "3" class= "Calculatorbutton" onclick= "Calculator.input (3)"/></td>
<td><input type= "button" value= "-" class= "Calculatorbutton" onclick= "calculator.calculate ('-')"/></ Td>
</tr>
<tr>
<td><input type= "button" value= "0" class= "Calculatorbutton" onclick= "calculator.input (0)"/></td>
<td><input type= "button" value= "" class= "Calculatorbutton" onclick= "calculator.input ('. ')"/></td >
<td><input type= "button" value= "=" class= "Calculatorbutton" onclick= "calculator.calculate (' = ')"/></ Td>
<td><input type= "button" value= "+" class= "Calculatorbutton" onclick= "calculator.calculate (' + ')"/></ Td>
</tr>
<tr>
<TD height= > </td>
<TD colspan= "2" ><div align= "center" ><a href= "#" onclick= "Top.close ()" > Close window </a></div> </td>
<td> </td>
</tr>
</table>
</div>
</body>
<script type= "Text/javascript" >
<!--
Document.onkeyup = function (e)
{
var evt = utils.fixevent (e);
if (Evt.keycode >= && evt.keycode <= &&!evt.shiftkey) | |
(Evt.keycode >= && evt.keycode <=!evt.shiftkey))
{
if (Evt.keycode > 57)
{
Calculator.input (evt.keycode-96);
}
Else
{
Calculator.input (evt.keycode-48);
}
}
else if ((Evt.keycode = = &&!evt.shiftkey) | | (Evt.keycode = && Evt.shiftkey) | | (Evt.keycode = = 187 && evt.shiftkey))
{
Calculator.calculate (' + ');
}
else if ((Evt.keycode = = 109 &&!evt.shiftkey) | | (Evt.keycode = = 189 &&!evt.shiftkey))
{
Calculator.calculate ('-');
}
else if ((Evt.keycode = &&!evt.shiftkey) | | (Evt.keycode = && evt.shiftkey))
{
Calculator.calculate (' * ');
}
else if ((Evt.keycode = &&!evt.shiftkey) | | (Evt.keycode = = 191 &&!evt.shiftkey))
{
Calculator.calculate ('/');
}
else if (Evt.keycode = 13 | | (Evt.keycode = &&!evt.shiftkey) | | (Evt.keycode = = 187 &&!evt.shiftkey))
{
Calculator.calculate (' = ');
}
else if ((Evt.keycode = &&!evt.shiftkey) | | (Evt.keycode = = 190 &&!evt.shiftkey))
{
Calculator.input ('. ');
}
else if (Evt.keycode = 27)
{
Calculator.clear ();
}
else if (Evt.keycode = 8)
{
Calculator.backspace ();
}
return false;
alert (Evt.keycode);
}
-->
</script>