$(document).ready(function() {
replaceChecks();
    var $table = $('#pricelist');
    //$($table).addClass('table');
   // $('thead tr', $table).addClass('head');
   // $('tbody tr:odd', $table).addClass('td');
    $('tbody tr:even td', $table).removeClass().addClass('tdalt');
    //$('caption', $table).addClass('caption');

});

var inputs;
var imgFalse = "/cmsfiles/price/false.gif";
var imgTrue = "/cmsfiles/price/true.gif";
function replaceChecks() {
    inputs = $('input', '#pricebox');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].getAttribute('type') == 'checkbox') {
            var img = document.createElement('img');
            if (inputs[i].checked) {
                img.src = imgTrue;
            } else {
                img.src = imgFalse;
            }
            img.id = 'checkImage' + i;
            img.onclick = new Function('checkChange(' + i + ')');
            img.style.cursor = 'pointer';
            var b = eval("(" + inputs[i].value + ")");
            img.alt = b.price + '  تومان  ';
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            inputs[i].style.display = 'none';
        }
    }
}
function checkChange(i) {
    var b = eval("(" + inputs[i].value + ")");
    if (inputs[i].checked) {
        inputs[i].checked = '';
        document.getElementById('checkImage' + i).src = imgFalse;
        updateprice(-1 * parseInt(b.price), b.type);

    } else {
        inputs[i].checked = 'checked';
        document.getElementById('checkImage' + i).src = imgTrue;
        updateprice(parseInt(b.price), b.type);
    }
}
function updateprice(price, type) {
    if (type == 1) {
        $('#p_personal').val(parseInt($('#p_personal').val()) + price);
        $('#p_personal1').val(parseInt($('#p_personal1').val()) + price);
    }
    if (type == 2) {
        $('#p_corp').val(parseInt($('#p_corp').val()) + price);
        $('#p_corp1').val(parseInt($('#p_corp1').val()) + price);
    }
    if (type == 3) {
        $('#p_org').val(parseInt($('#p_org').val()) + price);
        $('#p_org1').val(parseInt($('#p_org1').val()) + price);
    }
    if (type == 4) {
        $('#p_platinum').val(parseInt($('#p_platinum').val()) + price);
        $('#p_platinum1').val(parseInt($('#p_platinum1').val()) + price);
    }
}
