function addChar(input,character) {
if(input.value==null || input.value=="0")
input.value=character;
else
input.value+=character;
}
function changeSign(input) {
if(input.value.substring(0,1) == "-")
input.value=input.value.substring(1,input.value.length);
else
input.value="-"+input.value;
}
function deleteChar(input) {
input.value=input.value.substring(0,input.value.length-1);
}
function compute(form)  {
form.display.value=eval(form.display.value);
}
function checkNum(str) {
for(i=0;i<str.length;i++) {
ch=str.substring(i,i+1);
if(ch<"0" || ch>"9") {
if(ch!="/" && ch!="*" && ch!="+" && ch!="-" && ch!="." && ch!="(" && ch!=")") {
alert("invalid entry!");
return false;
}}}
return true;
}
var count=0;
var keys=["7","black","8","black","9","black","+","red","4","black","5","black","6","black","-","red","1","black","2","black","3","black","*","red","(","green","0","black",")","green","/","red"];
document.write("<form>");
document.write("<table border=8 cellspacing=4 cellpadding=2 bgcolor='silver'>");
document.write("<tr>");
document.write("<td align='center' colspan=4>");
document.write("<div align='center'><center>");
document.write("<table cellspacing=0 cellpadding=10 width='60%'>");
document.write("<tr>");
document.write("<td align='center' valign='center' height=30 bgcolor='black'>");
document.write("<input name='display' value='0' size='25' style='font-size:12pt;background-color:beige;color:black;'>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
document.write("</center></div>");
document.write("</td>");
document.write("</tr>");
for(y=0;y<4;y++){
document.write("<tr>");
for(x=0;x<4;x++){
document.write("<td align='center'>");
document.write("<input type='button' value='"+keys[count]+"' onClick='addChar(this.form.display,&#39;"+keys[count]+"&#39;)' style='width:45px;color:"+keys[count+1]+";font-weight:bold;'>");
document.write("</td>");
count+=2;
}
document.write("</tr>");
}
document.write("<tr>");
document.write("<td align='center'>");
document.write("<input type='button' value='CLR' onClick='this.form.display.value=0' style='width:45px;'>");
document.write("</td>");
document.write("<td align='center'>");
document.write("<input type='button' value='BSP' onClick='deleteChar(this.form.display)' style='width:45px;'>");
document.write("</td>");
document.write("<td align='center'>");
document.write("<input type='button' value='+/-' onClick='changeSign(this.form.display)' style='width:45px;color:red;font-weight:bold;'>");
document.write("</td>");
document.write("<td align='center'>");
document.write("<input type='button' value='EXE' name='enter' onClick='if(checkNum(this.form.display.value)){compute(this.form)}' style='width:45px;background-color:gray;color:black;'>");
document.write("</td>");
document.write("</tr>");
document.write("</table>");
document.write("</form>");
