

function ValidateOrgNr2(sender, args) {
    args.IsValid = false;
}


$(document).ready(function() {
    $('input.TextBox, textarea.TextArea').focus(function() {
        $(this).addClass('Active');
    });
    $('input.TextBox, textarea.TextArea').blur(function() {
        $(this).removeClass('Active');
    });


    $('input:radio').each(function() {

        var rb = $(this);
        rb.addClass($(this).attr('id') + '_r');
        rb.hide();
        $('label[for=' + $(this).attr('id') + ']').click(function() {
            rb.click();
        });
        var replacer = null;
        replacer = $('<a href="#"/>')
            .attr('id', $(this).attr('id') + '_r')
            .addClass('RadioButton')
            .click(function() {
                rb.click();
                $(this).addClass('Checked');
                $('input:radio').each(function() {
                    if ($(this).attr('checked'))
                        $('a[id="' + $(this).attr('class') + '"]').addClass('Checked');
                    else
                        $('a[id="' + $(this).attr('class') + '"]').removeClass('Checked');
                });
                this.blur();
                return false;
            });
        rb.after(replacer);

    });
    $('input:checkbox').each(function() {
        var cb = $(this);
        cb.addClass($(this).attr('id') + '_c');
        cb.hide();
        $('label[for=' + $(this).attr('id') + ']').click(function() {
            cb.click();
        });
        var replacer = null;
        replacer = $('<a href="#"/>')
            .attr('id', $(this).attr('id') + '_c')
            .addClass('CheckBox')
            .click(function() {
                var aR = $(this);
                cb.click();
                this.blur();
                return false;
                /*if (cb.attr('checked') == true)
                aR.addClass('Checked');
                else
                aR.removeClass('Checked');*/
            });
        cb.after(replacer);
    });
    $('input').click(function(e) {
        $('a[id="' + $(this).attr('class') + '"]').toggleClass('Checked');
        $('input:radio').each(function() {
            if ($(this).attr('checked'))
                $('a[id="' + $(this).attr('class') + '"]').addClass('Checked');
            else
                $('a[id="' + $(this).attr('class') + '"]').removeClass('Checked');
        });
    });
    $('label').mouseup(function() {
        //alert("here");

        $('input:checkbox').each(function() {
            if ($(this).attr('checked'))
                $('a[id="' + $(this).attr('class') + '"]').addClass('Checked');
            else
                $('a[id="' + $(this).attr('class') + '"]').removeClass('Checked');
        });
    });

    $('input:checkbox, input:radio').each(function() {
        if ($(this).attr('checked'))
            $('a[id="' + $(this).attr('class') + '"]').addClass('Checked');
        else
            $('a[id="' + $(this).attr('class') + '"]').removeClass('Checked');
    });

    $('a.RadioButton, a.CheckBox').focus(function() {
        $(this).addClass('Focus');
    });
    $('a.RadioButton, a.CheckBox').blur(function() {
        $(this).removeClass('Focus');
    });

    $('select').each(function() {
        var ddl = $(this);
        var ddl_jq = $('<div/>')
                    .addClass('ddlHolder')
                    .addClass(ddl.attr('id'))
                    .append(
                        $('<div/>')
                            .addClass('ddlText')
                            .append(
                                $('<div/>')
                                .addClass('ddlSelected')
                            )
                    ).append(
                        $('<div/>')
                        .addClass('ddlList')
                    );
        ddl.hide();
        var list = $('<div/>').addClass('ddlScroller').append($('<ul/>'));
        ddl.find('option').each(function(i) {
            if ($(this).attr('selected'))
                ddl_jq.find('.ddlSelected').html($(this).html());
            $('<li/>')
                .append(
                    $('<a/>')
                    .attr('href', '#')
                    .html(
                        $(this)
                        .html()
                    )
                ).click(function() {
                    selectItem(ddl.attr('id'), i);
                    ddl_jq.find('.ddlList').hide();
                    this.blur();
                    return false;
                }).appendTo(list.find('ul'));
        });


        list.appendTo(ddl_jq.find('.ddlList'));

        ddl_jq.find('.ddlList').hide();
        ddl_jq.find('.ddlText').click(function(event) {
            event.stopPropagation();
            var visible = ddl_jq.find('.ddlList:visible');
            $('.ddlList:visible').hide();
            if (visible.hasClass('ddlList')) {
                ddl_jq.find('.ddlList').hide();
            } else {
                ddl_jq.find('.ddlList').show();
            }
        });
        ddl.after(ddl_jq);
    });
    $('body').click(function() {
        $('.ddlList').hide();
    });
});

function selectItem(id, i) {
    var list = $('#' + id);
    document.getElementById(id).options[i].selected = true;
    list.change();
    $('.' + id).find('.ddlSelected').html(document.getElementById(id).options[i].innerHTML);
}
