window.onload = UpdateTotal;


function insertCart() {

document.write(
'<div id="overlay">'
+'</div>'
+'<div id="window">'
+'  <div id="title">'
+'    <div id="closeWindow">'
+'      <a href="javascript:toggleCart();" id="closeWindowButton" title="Close">'
+'      Close</a>'
+'    </div>'
+'  </div>'
+''
+''
+'<div id="cartContent">'
+''
+'<form name="cart" id="cart" method="POST" action="http://purchase.tcbmi.com/">'
+'<input type="hidden" name="pid" value="43">'
+''
+'<table id="cartTable">'
+'  <tbody>'
+''
+'    <tr height="63">'
+'      <td colspan="4" id="tdHeader" style="background-repeat: repeat-x;" background="http://purchase.tcbmi.com/cart_bg_top.gif" height="63">'
+'        <img src="http://purchase.tcbmi.com/cart_logo.gif" id="imgHeader" height="63">'
+'      </td>'
+'    </tr>'
+''
+'    <tr valign="middle">'
+'      <td class="cartHeader" width="5%" >No.</td>'
+'		  <td class="cartHeader" width="71%">Item</td>'
+'		  <td class="cartHeader" width="9%" >Quantity</td>'
+'		  <td class="cartHeader" width="15%">Price (USD)</td>'
+'		</tr>'
+'		'
+'		<tr bgcolor="#eeeeee" valign="middle">'
+'      <td>1.</td>'
+'		  <td>StrokeIt License</td>'
+''
+'      <td><select style="width: 90%;" id="qty" name="qty" onChange="UpdateTotal()">'
+'  '
+'  <option selected="selected" value="1">1</option>'
+'  <option value="2">2</option>'
+'  <option value="3">3</option>'
+'  <option value="4">4</option>'
+'  <option value="5">5</option>'
+'  <option value="6">6</option>'
+'  <option value="7">7</option>'
+'  <option value="8">8</option>'
+'  <option value="9">9</option>'
+'  <option value="10">10</option>'
+'  <option value="11">11</option>'
+'  <option value="12">12</option>'
+'  <option value="13">13</option>'
+'  <option value="14">14</option>'
+'  <option value="15">15</option>'
+'  <option value="16">16</option>'
+'  <option value="17">17</option>'
+'  <option value="18">18</option>'
+'  <option value="19">19</option>'
+'  <option value="20">20</option>'
+'  <option value="21">21</option>'
+'  <option value="22">22</option>'
+'  <option value="23">23</option>'
+'  <option value="24">24</option>'
+'  <option value="25">25</option>'
+'  <option value="50">50</option>'
+'  <option value="75">75</option>'
+'  <option value="100">100</option>'
+'  </select>'
+'  '
+'		  </td>'
+'		  <td>10.00</td>'
+'		</tr>'
+''
+'		<tr height="30">'
+' 		  <td colspan="2">&nbsp;</td>'
+'		  <td bgcolor="#eeeeee"><b>Total:</b></td>'
+'		  <td bgcolor="#eeeeee"><span id="total"></span></td>'
+'    </tr>'
+''
+'    <tr height="14"><td colspan="5">&nbsp;</td></tr>'
+''
+'		<tr>'
+' 		  <td colspan="3">&nbsp;</td>'
+'			<td>'
+'        <input id="btnCheckout" value="Checkout" type="submit">'
+'      </td>'
+'		</tr>'
+'		'
+'	  </tbody>'
+'</table>'
+'</form>'
+'</div>'
+'</div>'
);

}

function toggleCart() {
  var ele = document.getElementById("overlay");
  var ele2 = document.getElementById("window");
  if(ele.style.display == "block") {
    ele.style.display = "none";
    ele2.style.display = "none";
  }
  else {
    ele.style.display = "block";
    ele2.style.display = "block";
  }
} 


function UpdateTotal() {
  var el = document.getElementById('qty');
  var qty = el.options[el.selectedIndex].value;
  document.getElementById('total').innerHTML = pad_with_zeros(qty * 10, 2);
}

function pad_with_zeros(rounded_value, decimal_places) {

  // Convert the number to a string
  var value_string = rounded_value.toString()

  // Locate the decimal point
  var decimal_location = value_string.indexOf(".")

  // Is there a decimal point?
  if (decimal_location == -1) {

    // If no, then all decimal places will be padded with 0s
    decimal_part_length = 0

    // If decimal_places is greater than zero, tack on a decimal point
    value_string += decimal_places > 0 ? "." : ""
  }
  else {

    // If yes, then only the extra decimal places will be padded with 0s
    decimal_part_length = value_string.length - decimal_location - 1
  }

  // Calculate the number of decimal places that need to be padded with 0s
  var pad_total = decimal_places - decimal_part_length

  if (pad_total > 0) {

    // Pad the string with 0s
    for (var counter = 1; counter <= pad_total; counter++)
      value_string += "0"
    }
  return value_string
}
