﻿
function ClearText(el, value) {
    if (el.value == value)
        el.value = "";
}

function PopulateText(el, value) {
    if (el.value.length == 0)
        el.value = value;
}

$(document).ready(function() {
    
    SetRegisterSliders();    
    
    $('div.item').each(function(i, el) {
        var txt = $('label', el).text().replace('*', '').replace(':', '');

        $('input:textbox', el).focus(function() {
            if ($(this).attr('value') == txt) {
                $(this).attr('value', '');
            }
        });
        $('input:textbox', el).blur(function() {
            if ($(this).attr('value').length == 0) {
                $(this).attr('value', txt);
            }
        });
    });

    $('div.textitem').each(function(i, el) {
        var txt = $('label', el).text().replace('*', '').replace(':', '');

        $('textarea', el).focus(function() {
            if ($(this).attr('value') == txt) {
                $(this).attr('value', '');
            }
        });
        $('textarea', el).blur(function() {
            if ($(this).attr('value').length == 0) {
                $(this).attr('value', txt);
            }
        });
    });
});

function SetRegisterSliders() {
    var valFrom = $('input.inputFromReg').val();
    var valTo = $('input.inputToReg').val();
    var vto = $('.pValToReg');
    
    $('.pValToReg').text(valTo);
    $('.pValFromReg').text(valFrom);
    $('div.slide .slideitemreg').slider({
        orientation: 'horizontal',
        range: true,
        min: 0,
        max: 50000,
        values: [valFrom, valTo],
        step: 100,
        slide: function(event, ui) {
            $('.pValToReg', $(this).parent().parent()).text(ui.values[1]);
            $('.pValFromReg', $(this).parent().parent()).text(ui.values[0]);
            $('.inputToReg', $(this).parent().parent()).val(ui.values[1]);
            $('.inputFromReg', $(this).parent().parent()).val(ui.values[0]);

            if (vto != null) {
                if (vto.text() == '50000') {
                    vto.text(vto.text() + '+')
                };
            };
        }
    });
    
    if (vto != null) {
        if (vto.text() == '50000') {
            vto.text(vto.text() + '+')
        };
    };
}

