﻿function pageLoad() {
    $find('ctl00_ContentPlaceHolder1_ricerca1_sli_prezzo').add_valueChanged(sli_prezzo_valueChanged);
    $find('ctl00_ContentPlaceHolder1_ricerca1_sli_distanza').add_valueChanged(sli_distanza_valueChanged);
    $find('ctl00_ContentPlaceHolder1_ricerca1_sli_mq').add_valueChanged(sli_mq_valueChanged);
}

function sli_prezzo_valueChanged() {
    var value = $find('ctl00_ContentPlaceHolder1_ricerca1_sli_prezzo').get_Value();
    $get('ctl00_ContentPlaceHolder1_ricerca1_lbl_prezzo').innerHTML = addCommas(value);   
}

function sli_distanza_valueChanged() {
    var value = $find('ctl00_ContentPlaceHolder1_ricerca1_sli_distanza').get_Value();
    $get('ctl00_ContentPlaceHolder1_ricerca1_lbl_distanza').innerHTML = addCommas(value);
}

function sli_mq_valueChanged() {
    var value = $find('ctl00_ContentPlaceHolder1_ricerca1_sli_mq').get_Value();
    $get('ctl00_ContentPlaceHolder1_ricerca1_lbl_mq').innerHTML = addCommas(value);
}

function addCommas(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;
}
