function addmax(num, price) {
if (num == "na") {
document.getElementById("max").innerHTML = "";
}
else {
document.getElementById("max").innerHTML = "Quantity: <input type=\"text\" name=\"qn\" size=\"3\" onblur=\"calcprice('" + price + "', this.value)\"> (<font color=\"red\">maximum " + numformat(num) + "</font>) <input type=\"button\" value=\"max\" onClick=\"document.f.qn.value = " + num + ";\"> <div id=\"price\"></div>";
}
return true;
}

function calcprice(price, num) {
if (num == "" || num == 0 || IsNumeric(num) == false) {
document.getElementById("price").innerHTML = "";
}
else {
var calc = num * price;
document.getElementById("price").innerHTML = "<small>" + num + " shares @ $" + numformat(price) + " = $" + numformat(calc) + "</small>";
}
return true;
}

function dosubmit() {
document.getElementById("submit").disabled = true;
return true;
}

function confrm(msg, url) {
if (confirm(msg)) location.href = url;
}

function storeConfirm() {
var num = document.f.amount.value;
if (num == "" || num == 0 || IsNumeric(num) == false) {
alert("Please enter a valid amount!");
}
else {
if (confirm("Are you sure you want to buy $"+num+",000 for $"+num+"?")) {
document.f.submit();	
}
}
return true;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

function numformat(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}

function addlink() {
var link_url = prompt("Enter the URL of the link:", "http://");
var link_name = prompt("Enter the name of the link:", "");
if ((link_name == "") || (link_name == null)) {
var url = "[url]" + link_url + "[/url]";
}
else {
var url = "[url=" + link_url + "]" + link_name + "[/url]";
}
insert(url);
}

function insert(code) {
insertAtCursor(document.f.msg, code);
}

function updateShares_cb(d) {
if (d !== "complete") {
alert("There was a problem with the update, please try again!");
}
window.location.reload();
}

function updateShares(user) {
document.getElementById("btn").innerHTML = '<small>Please Wait</small>&nbsp;<br><img src="http://www.alexashare.com/images/progressbar.gif">';
x_updateShares(updateShares_cb);
}

function selectAll(theform) {
if (document.all||document.getElementById){
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="checkbox")
tempobj.checked = (tempobj.checked == true) ? false : true;
}
}
}

function deleteSelected() {
if (confirm("Delete selected message(s)?")) {
document.fr.submit();
}
}

function showReplyBox() {
document.getElementById("reply").style.display = "";
document.getElementById("msg").focus();
}

function showcomparefield() {
document.getElementById("compare").style.display = "";
document.getElementById("user2").focus();
}

function doCompareUsers() {
var u = document.getElementById("user2").value;
if (u == "") {
alert("Enter a username!");
return false;
}
else {
window.location.href = window.location + "&compare=" + u;
return true;
}
}

function doDelete(domain, value) {
x = confirm("This will delete "+domain+" from your portfolio and credit your account $"+value+" - are you sure?");
if (x) {
window.location.href = 'canceldomain.php?url=' + domain;
}
}

function zoom(url) {
open('/zoom.php?domain=' + url, 'zoom','toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=400,height=250');
return true;
}
