//By Daniel C. Peterson
//Web Winder Website Services, 1997-2008  All Rights Reserved.
//Distribution, editing or reselling of this script is strictyly prohibited
//without expressed written permission from Daniel C. Peterson.
//For commercial grade (professional) versions of this and many other
//calculators, visit http://www.webwinder.com.

function checkNumber(input, min, max, msg)

{

    msg = msg + " field has invalid data: " + input.value;


    var str = input.value;

    for (var i = 0; i < str.length; i++) {

        var ch = str.substring(i, i + 1);        
        if ((ch < "0" || "9" < ch) && ch != '.') {

            alert(msg);

            return false;
        }

    }
    var num = 0 + str

    if (num < min || max < num) {

        alert(msg + " not in range [" + min + ".." + max + "]");

        return false;

    }

    input.value = str;
   return true;

}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num);
}


function computeworth(input) {
//  alert(closewin);

    if (input.value != null && input.value.length != 0) 
        input.value = "" + eval(input.value);

    computeWorthForm(input.form);
}
//Get cookie routine by Shelley Powers 
function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    // if cookie exists
    if (offset != -1) { 
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1) end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}


function computeWorthForm(form) {

    if (form.conx.value == null ) {
        return;
    }

    if (!checkNumber(form.conx, 1, 5000, "Number of connections")) {
//        form.fv.value = "Invalid";
        return;

    }


//    var i = form.conx.value;
/*
    if (i > 1.0) {

        i = i / 100.0;

        form.reward_percentage.value = i;

    }                                         
        i /= 12;


   var pow = form.dealsize.value;
    

    for (var j = 0; j < form.payments.value *12; j++)

        pow = (pow * i) + (pow *1);

    form.fv.value = pow
*/                              
form.your_worth.value = formatCurrency(form.conx.value * 750);               
document.cookie="worth="+form.your_worth.value;
//alert(get_cookie("worth"));

//alert(form.conx.value * 1000);

//form.provider_payment.value = (form.reward_percentage.value * form.dealsize.value)

}

function clearForm(form)

{

//    form.payments.value = "";

    form.conx.value = "";

//    form.dealsize.value = "";

}
