function write_captcha() {
    document.getElementById('captImage').src = PATH + 'captcha?noheader=true&sid=' + Math.random();
    return false;
}

function disable_othe_inp_where_select($id) {
    if ($id == "price") {
        document.getElementById("price").style.background = "white";
        document.getElementById("mortgagePrice").style.background = "#CCCCCC";
        document.getElementById("hirePrice").style.background = "#CCCCCC";
        document.getElementById("button_other").disabled = true;
        document.getElementById("button_purchase").disabled = false;
    }
    else if ($id == "mortgagePrice" || $id == "hirePrice") {
        document.getElementById("mortgagePrice").style.background = "white";
        document.getElementById("hirePrice").style.background = "white";
        document.getElementById("price").style.background = "#CCCCCC";
        document.getElementById("button_other").disabled = false;
        document.getElementById("button_purchase").disabled = true;
    }
}

function SwitchInputs(el1, el2, el3) {
    el2.css({'opacity':'0.5'}).find('input[type=submit]').attr('disabled', 'true');
    el2.find('input[type=text],select').addClass('disabled');
    el1.css({'opacity':'1'}).find('input[type=submit]').removeAttr('disabled');
    el1.find('input[type=text],select').each(function() {
        $(this).removeClass('disabled');
    });
}
function SwitchInputs2(el) {

    if (el.attr('id') == 'price') {
        $('#priceBuyMin,#priceBuyMax').addClass('disabled');

    } else{
        $('#price').addClass('disabled');
        $('#price').val(0);
    }
}

function intFormat(n, obj) {
    var regex = /(\d)((\d{3},?)+)$/;
    n = n.split(',').join('');

    while (regex.test(n)) {
        n = n.replace(regex, '$1,$2');
    }
    obj.value = n;
}

//---------------------------------------------
function numFormat(obj) {
    n = obj.value;
    var result = number_test(n);
    if (result == true) {
        var pointReg = /([\d,\.]*)\.(\d*)$/, f;
        if (pointReg.test(n)) {
            f = RegExp.$2;
            return intFormat(RegExp.$1, obj) + '.' + f;
        }
        return intFormat(n, obj);
    }
}
//---------------------------------------------
function number_test(n) {

    var reg = /[^0-9,]/i;
    if (reg.test(n)) {
        alert('در این کادر فقط عدد وارد نمائید');

        return false;
    }
    else
        return true;
}
//--------------------------


