﻿
function updateCost(obj, chk, users) {


    var id_name = obj.id;

    //get the values from the form
    var max_qty;
    var max_fee;

    max_qty = document.forms[0].max_qty.value;
    max_fee = document.forms[0].max_fee.value;


    //identify the image being used
    //var img = id_name.replace("rpt", "img");
    //var img_obj = document.getElementById(img);

    //reset the image source to the white spacer
    //img_obj.src = "/images/white_space.gif";

    var qty = users;

    if (qty >= max_qty) {
        qty = max_qty;
        return false;
    }
    if (qty == 0) {
        qty = 1;
    }
    //get the object reference
    var cnt;
    cnt = (max_fee / qty);
    var old_cnt = cnt;



    cnt = parseFloat(cnt);
    old_cnt = parseFloat(old_cnt);
    //calculate the revised total

    //see if the checkbox that fired event if checked or unchecked
    if (chk.checked) {

        //only adjust the price if there are less than 3
        if (qty < max_qty && users > 0 && qty <= max_qty) {
            qty += 1;
        }
    }

    //    {based cost}        * (reamining spots) + 1
    cnt = max_fee / qty;
    
    var html = "<br>(";
    //write out the current clients
    if (chk.checked) {
        if (qty == 1) {
            html += "1 client)";
        }
        if (qty > 1 && qty < max_qty) {
       //     img_obj.src = "/images/price_drop.gif";
            //html += qty + " clients)";
        }
        if (qty == max_qty) {
         //   img_obj.src = "/images/price_drop.gif";
            //html += qty + " or more clients)";
        }
        if (old_cnt > cnt) {
            obj.innerHTML = "<strike>$" + old_cnt + "</strike> " + "$" + cnt;
        }
        if (old_cnt == cnt) {
            obj.innerHTML = "$" + cnt + html;
        }
    }

    if (!chk.checked) {

        //remove the image
        img_obj.src = "/images/white_space.gif";
        
        if (users == 0) {
            qty = 0;
        }

        if (qty == 0) {
            html += "0 clients)";
        }
        if (qty == 1) {
            html += "1 client)";
        }
        if (qty > 1 && qty < max_qty) {
            html += qty + " clients)";
        }
        if (qty == max_qty) {
            html += qty + " or more clients)";
        }

        obj.innerHTML = "$" + cnt; //+ html;
    }
}	