function clock() {
var date=new Date()
var weekday=date.getDay()
var year=date.getYear()
var month=date.getMonth()
var day=date.getDate()
var hour=date.getHours()
var minute=date.getMinutes()
var second=date.getSeconds()
var days=new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" )
var months=new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
var monthname=months[month]
var dayname=days[weekday]
var ap;
if (year < 1000) {
year= year+ 1900 }

if (hour >= 12){ 
ap='PM';}
else
{ap='AM';}
if (hour > 12) 
hour=hour - 12;
if (minute < 10) {
minute="0"+ minute }
if (second < 10) {
second="0"+ second }
document.getElementById('time').value=hour+ ":"+ minute+ ":"+second+ ' '+ ap;
setTimeout("clock()", 1000 )}

var Result=0, Operator=0, Second=0, Ready=0, Done=1, Complete=0, Integer, CurrentValue;
function reset(value)
{document.calcsci.LED.value=value;
Result=0, Operator=0, Second=0, Ready=0; Done=1; Complete=0;}
function SetValue(NewValue)
{Integer=1;
if(Second || Done)
{Second=0;
Done=0;
CurrentValue=NewValue;}
for(var i=0; i<CurrentValue.length; i++)
if (CurrentValue[i]=='.')
Integer=0;}
function Click(Caption)
{CurrentValue=document.calcsci.LED.value;
if(Caption=='.')
{SetValue('0');
if(Integer)
{CurrentValue+= Caption;
document.calcsci.LED.value=CurrentValue;
Complete=0;}}
if (Caption.length == 1 && Caption>='0' && Caption<='9')
{SetValue('');
if(CurrentValue=='0')
CurrentValue='';
CurrentValue+= Caption;
document.calcsci.LED.value=CurrentValue;
Complete=1;}
if (Caption=='pi'){
CurrentValue=Math.PI;
document.calcsci.LED.value=CurrentValue;
Complete=1;}
if (Caption=='e'){
CurrentValue=Math.E;
document.calcsci.LED.value=CurrentValue;
Complete=1;}
if(Caption=='-' || Caption=='+' || Caption=='/' || Caption=='*' || Caption=='^')
{if(Second)
Operator=Caption
else{
if(!Ready)
{Operator=Caption;
Result=CurrentValue;
Ready=1;}
else {
if (Operator=='pow')
Result=Math.pow(Result, CurrentValue);
else
Result=eval(Result+ Operator+ CurrentValue);
Operator=Caption; document.calcsci.LED.value=Result;
} Complete=0; Second=1;}}
if(Caption=='1/x' ){
Result=eval('1/'+ CurrentValue) ; reset(Result);}
if(Caption=='sqrt'){
Result=Math.sqrt(CurrentValue);
reset(Result);}
if(Caption=='exp' ){
Result=Math.exp(CurrentValue);
reset(Result);}
if(Caption=='log' ){
Result=Math.log(CurrentValue) / Math.LN10;
reset(Result);}
if(Caption=='ln' ){
Result=Math.log(CurrentValue);
reset(Result);}
if(Caption=='sin' ){
Result=CurrentValue;
if (document.calcsci.angle[0].checked)
Result=Result*Math.PI / 180;
if (document.calcsci.angle[2].checked)
Result=Result*Math.PI / 200;
Result=Math.sin(Result);
reset(Result);}
if(Caption=='cos' ){
Result=CurrentValue;
if (document.calcsci.angle[0].checked)
Result=Result*Math.PI / 180;
if (document.calcsci.angle[2].checked)
Result=Result*Math.PI / 200;
Result=Math.cos(Result);
reset(Result);}
if(Caption=='tan' ){
Result=CurrentValue;
if (document.calcsci.angle[0].checked)
Result=Result*Math.PI / 180;
if (document.calcsci.angle[2].checked)
Result=Result*Math.PI / 200;
Result=Math.tan(Result);
reset(Result);}
if(Caption=='asin' ){
Result=Math.asin(CurrentValue);
if (document.calcsci.angle[0].checked)
Result=Result*180 / Math.PI;
if (document.calcsci.angle[2].checked)
Result=Result*200 / Math.PI;
reset(Result);}
if(Caption=='acos' ){
Result=Math.acos(CurrentValue);
if (document.calcsci.angle[0].checked)
Result=Result*180 / Math.PI;
if (document.calcsci.angle[2].checked)
Result=Result*200 / Math.PI;
reset(Result);}
if(Caption=='atan' ){
Result=Math.atan(CurrentValue);
if (document.calcsci.angle[0].checked)
Result=Result*180 / Math.PI;
if (document.calcsci.angle[2].checked)
Result=Result*200 / Math.PI;
reset(Result);}
if(Caption=='sinh' ){
Result=Math.exp(CurrentValue);
Result=(Result - 1 / Result) / 2;
reset(Result);}
if(Caption=='cosh' ){
Result=Math.exp(CurrentValue);
Result=(Result+ 1 / Result) / 2;
reset(Result);}
if(Caption=='tanh' ){
Result=Math.exp(CurrentValue);
Result=(Result - 1 / Result) / (Result+ 1 / Result);
reset(Result);}
if(Caption=='asinh' )
{
//sign(x)*log(|x|+ sqrt(x*x+1))
//alert(CurrentValue+ Math.sqrt(CurrentValue*CurrentValue+ 1));
//Result=Math.log(CurrentValue+ Math.sqrt(CurrentValue*CurrentValue+ 1));
Result=CurrentValue / Math.abs(CurrentValue)*Math.log(Math.abs(CurrentValue)+ Math.sqrt(CurrentValue*CurrentValue+ 1));
reset(Result);}
if(Caption=='acosh' )
{
//2 log(sqrt((x+1)/2)+ sqrt((x-1)/2)) 
Result=2*Math.log(Math.sqrt((CurrentValue+ 1) / 2)+ Math.sqrt((CurrentValue - 1) / 2));
reset(Result);
}
if(Caption=='atanh' )
{
//0.5*log((x-1)/(x+1))
Result=Math.log((CurrentValue - 1) / (CurrentValue+ 1)) / 2;
reset(Result);}
if(Caption=='+/-')
document.calcsci.LED.value=eval(-CurrentValue);
if(Caption=='=' && Complete && Operator!='0')
{if (Operator=='^')
{Result=Math.pow(Result, CurrentValue);
reset(Result);
} else
reset(eval(Result+ Operator+ CurrentValue));}
if (Caption=='C')
reset(0);
if(document.calcsci.LED.value[0] == '.')
document.calcsci.LED.value='0'+ document.calcsci.LED.value;}

function dclock()
{document.getElementById('LED').style.display='none';
document.getElementById('time').style.display='block';}

function dcalc()
{document.getElementById('LED').style.display='block';
document.getElementById('time').style.display='none';}

window.onload=function(){clock();dclock();}
