<?xml     version="1.0"   encoding="UTF-8" ?>
<Module>
 <ModulePrefs
              width="250"  
              height="350"
              category="tools"
              category2="technology"
              scrolling="false"
               title="Advanced math calculator"
              title_url="http://my-google-gadgets.blogspot.com/"
              description="Advanced math calculator is more advanced then the Windows calculator. I've done this after I've noticed most of the calculators can't process X/0.0Y ecuations. As a bonus, the PI number is included"
              author="Alice Thai"
              author_email="the.gadget.architect@gmail.com"
              thumbnail="http://www.motifake.com/image/demotivational-poster/small/0904/nerd-girls-life-time-librarian-school-girl-glasses-sexy-demotivational-poster-1240508590.jpg"
              screenshot="http://www.brandspankingnew.net/img/headers/usb_calculator.jpg"
              author_location="Athens, Greece">

 </ModulePrefs>

<Content type="html">

<![CDATA[


<head>
<meta http-equiv="Content-Language" content="en-us">
</head>

<div align="center"><SCRIPT>
 
//flags to mark previous function
var opFlag=false   //indicates previous entry was an operator
var eqFlag=false   //indicates previous function was a calculation
 
 
function checkDec() {
//prevents multiple decimal points in entry
  if (document.calc.screen.value.indexOf('.') == -1){
    enterVal('.')
    return
  }
 
    if ((document.calc.screen.value.indexOf('.') >= 0) && ((eqFlag) || (opFlag))){
    enterVal('.')
    return
  }
 
  
}
 
function enterVal(num){    
//determine how to handle entry based on previous function
 
    
  if (eqFlag) {
  //last entry gave a total, no operators entered, so replace both stores
    document.calc.input.value=num
    document.calc.screen.value=num
    eqFlag=false
    return
  }
  
  if ((!opFlag) && (!eqFlag)){
  //no operators or totals entered, still entering numbers
    document.calc.input.value += num
    document.calc.screen.value += num
    return        
  }
 
  if (opFlag) {
  //operator entered, change screen value, build on input
    document.calc.screen.value =num
    document.calc.input.value += num
    opFlag=false
    return
  }  
 
}
 
function compute() {
//if last entry is an operator, input is not complete so do nothing
 
  len=document.calc.input.value.length
  var oneChar=document.calc.input.value.charAt(len-1)
  if ((oneChar == '+') || (oneChar == '-') || (oneChar == '*') ||
    (oneChar == '/')) {  
    return
  }
 
  document.calc.screen.value = eval(document.calc.input.value)
  document.calc.input.value = eval(document.calc.input.value)
  
  eqFlag=true
  
  
}
 
function operator(op) {
  //can't enter operator before entering a value
  if (document.calc.screen.value == ''){
    return
  }
 
  //if last entry is not an operator, use the one just entered
  eqFlag=false
  len=document.calc.input.value.length
  var oneChar=document.calc.input.value.charAt(len-1)
  if ((oneChar != '+') && (oneChar != '-') && (oneChar != '*') &&
    (oneChar != '/') && (oneChar != '.')){
      document.calc.screen.value = eval(document.calc.input.value)
      document.calc.input.value = eval(document.calc.input.value)
      document.calc.input.value += op
      
  }
  else {     
  //if last entry is an operator, replace it with this one
  //this returns input store less operator
    document.calc.input.value=parseFloat(document.calc.input.value)
    document.calc.input.value+=op
  }
  opFlag=true
}
 
function clearAll() {
  document.calc.input.value = ''
  document.calc.screen.value=''
  
}
 
function clearEntry() {
  //don't do anything if the last entry is not a number
  len=document.calc.input.value.length
  var oneChar=document.calc.input.value.charAt(len-1)
  if ((oneChar == '+') || (oneChar == '-') || (oneChar == '*') ||
    (oneChar == '/')) {  
    return
  }
  
  if (document.calc.screen.value == ''){
  //nothing here to clear
    return
  }
  
  if (document.calc.screen.value==document.calc.input.value) {  
  //only one entry, so clear it
    document.calc.screen.value=''
    document.calc.input.value=''
    return
  }
    //get last number entered and clear it, return previous value to screen
    str1=document.calc.screen.value
    str2=document.calc.input.value
    ind=str2.lastIndexOf(str1)
    document.calc.input.value=document.calc.input.value.substring(0,ind)
    document.calc.screen.value=parseFloat(document.calc.input.value)
    
}
function sqrRT() {
 
  if (document.calc.input.value == ''){
  //nothing entered, do nothing
    return
  }
 
  document.calc.screen.value=Math.sqrt(document.calc.screen.value)
  document.calc.input.value=document.calc.screen.value
  eqFlag=true
}
 
function sqr() {
 
  if (document.calc.input.value == ''){
    return
  }
  
  document.calc.screen.value=(document.calc.screen.value)*(document.calc.screen.value)
  document.calc.input.value=document.calc.screen.value
  eqFlag=true
}
 
function neg() {//get last entry and negate it
  str1=document.calc.screen.value
  str2=document.calc.input.value
  ind=str2.lastIndexOf(str1)
 
  document.calc.input.value=document.calc.input.value.substring(0,ind)
  document.calc.screen.value=(document.calc.screen.value)*-1
  document.calc.input.value += "(" + document.calc.screen.value + ")"
  //placed in () to solve double operator problem
}
  
 
function pcnt() {
 
  if (document.calc.input.value == ''){ //nothing here
    return
  }
  //if last entry is an operator, do nothing
  len=document.calc.input.value.length  
  var oneChar=document.calc.input.value.charAt(len-1)
  if ((oneChar == '+') || (oneChar == '-') || (oneChar == '*') ||
    (oneChar == '/')) {  
 
    return
  }
  //check that there are two numbers entered
  if ((document.calc.input.value.indexOf('+') == -1)&&
  (document.calc.input.value.indexOf('-') == -1)&&
  (document.calc.input.value.indexOf('*') == -1)&&
  (document.calc.input.value.indexOf('/') == -1)){
    return
  }
  //calculate percentage
 
  if ((document.calc.input.value.indexOf('+') != -1) ||
  (document.calc.input.value.indexOf('-') != -1)) {
 
    percent=((document.calc.screen.value)/100)*parseFloat(document.calc.input.value)
  
  }
 
  else {
    percent=((document.calc.screen.value)/100)
    
  }
  
  //replace last entry with percentage and evaluate expression
  str1=document.calc.screen.value
  str2=document.calc.input.value
  ind=str2.lastIndexOf(str1)
 
  document.calc.input.value=document.calc.input.value.substring(0,ind)
  document.calc.input.value+=percent
  document.calc.screen.value = eval(document.calc.input.value)
  document.calc.input.value = eval(document.calc.input.value)
  
 
  eqFlag=true
}
 
function memory_p() {
  if (document.calc.screen.value ==''){
    return
  }
  //add screen value to memory store
  document.calc.memory.value+= "+" + document.calc.screen.value
  document.calc.memory.value=eval(document.calc.memory.value)
  eqFlag=true
  document.calc.mem_win.value='M' //indicator of something in memory
  
}
 
function memory_s() {
 
  if (document.calc.screen.value ==''){
    return
  }
 
  document.calc.memory.value += "-(" + (document.calc.screen.value) +")"
  document.calc.memory.value=eval(document.calc.memory.value)
 
  eqFlag=1
  document.calc.mem_win.value='M'
 
}
 
function memory_r() {
  //recall memory store to screen
  document.calc.screen.value=''
  enterVal(document.calc.memory.value)
  eqFlag=true
  
  
  
}
 
function memory_c() {
  //clear memory indicator
  document.calc.memory.value=0
  document.calc.mem_win.value=''  
 
}
 
function constant(what) {
  if (what == 'pi') {
    document.calc.screen.value=''
    enterVal(Math.PI)
    eqFlag=true
    
  }
}
      
 
 
 
 
 
</SCRIPT>

<FORM NAME="calc"><div align="center">
  <table width="240" border=0 style="border-collapse: collapse" cellpadding="0"><tbody>
  <tr>
    <td valign="middle" align="center">
    <INPUT placeholder="Use / symbol to divide" TYPE="text" NAME="screen" SIZE="24" onFocus="refresh(); this.blur();" style="font-family: serif; font-size: 14pt; background-color: rgb(0,0,0); color: #00FF00"></td>
  </tr>
  <tr><td valign="middle" align="center"><center><iframe border=0 frameborder=0 height=60 marginheight=0 marginwidth=0 name=explain scrolling=no src=http://atat.ro/about.html title=Proxy width=234></iframe></center></td></tr><tr><td ALIGN="center">
    <TABLE BORDER=1 cellspacing="3" cellpadding="2" style="border-collapse: collapse"><TR>
      <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="mem_p"  VALUE="  M+  " OnClick="memory_p()"> </TD>
      <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="mem_s"  VALUE="  M-  " OnClick="memory_s()"> </TD>
      <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="mem_r"  VALUE=" MR " OnClick="memory_r()"> </TD>
      <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="mem_c"  VALUE=" MC " OnClick="memory_c()"> </TD></TR><TR ALIGN="center">
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="sq_root"  VALUE=" sqrt " OnClick="sqrRT()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="square"  VALUE=" sqr  " OnClick="sqr()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="percent"  VALUE="  %   " OnClick="pcnt()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="negate"  VALUE="  +/-  " OnClick="neg()"></TD></TR><TR ALIGN="center">
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="seven" VALUE="  7  " OnClick="enterVal('7')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="eight" VALUE="  8  " OnClick="enterVal('8')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="nine"  VALUE="  9  " OnClick="enterVal('9')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="div"   VALUE="   /  " OnClick="operator('/')"></TD></TR><TR ALIGN="center">
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="four"  VALUE="  4  " OnClick="enterVal('4')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="five"  VALUE="  5  " OnClick="enterVal('5')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="six"   VALUE="  6  " OnClick="enterVal('6')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="times" VALUE="  x  " OnClick="operator('*')"></TD></TR><TR ALIGN="center">
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="one"   VALUE="  1  " OnClick="enterVal('1')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="two"   VALUE="  2  " OnClick="enterVal('2')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="three" VALUE="  3  " OnClick="enterVal('3')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="minus" VALUE="   -  " OnClick="operator('-')"></TD></TR><TR ALIGN="center">
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="zero"  VALUE="  0  " OnClick="enterVal('0')"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="deci"  VALUE="  .   " OnClick="checkDec()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="doIt"  VALUE="  =  " OnClick="compute()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="plus"  VALUE="  +  " OnClick="operator('+')"></TD></TR><TR ALIGN="center">
        <TD COLSPAN=2 bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="clear" VALUE="CLEAR" OnClick="clearAll()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="clear_entry" VALUE=" CE " OnClick="clearEntry()"></TD>
        <TD bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF">&nbsp;<INPUT TYPE="button" NAME="pi" VALUE=" pi " OnClick="constant('pi')"></TD><center></TR></TABLE></td></tr></table><INPUT TYPE=hidden NAME=input SIZE=16><INPUT TYPE=hidden NAME=memory VALUE=0 SIZE=16></FORM></font></strong></div>
  

]]>
</Content>

</Module>