window.addEvent('domready', function() {
    $$('[class=tb]').each(function(el) {
        $(el).addEvents({
            'focus': function(el) {
                $(this.get('id').replace('txt', 'inp')).setStyle('background', 'transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
                $(this.get('id').replace('txt', 'right')).setStyle('background', 'transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
            },
            'blur': function(el) {
                $(this.get('id').replace('txt', 'inp')).setStyle('background');
                $(this.get('id').replace('txt', 'right')).setStyle('background');
            }
        });

    });
});

var errorcount =0;

function checktext(form_field) {
    if ($(form_field).value == '') {
        errorcount += 1;
        $(form_field).getParent().setStyle('background', 'transparent url(images/inptxt1-leftr.png) no-repeat scroll 0 0');
        $(form_field).getParent().getParent().setStyle('background', 'transparent url(images/inptxt1-rightr.png) no-repeat scroll 100% 0');
        $(form_field).removeEvents('focus');
        $(form_field).removeEvents('blur');
        $(form_field).removeEvents('keyup');
        $(form_field).addEvent('keyup', function() {
            checktext(form_field);
        });
    } else {
        $(form_field).getParent().setStyle('background', 'transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
        $(form_field).getParent().getParent().setStyle('background', 'transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
        $(form_field).addEvents({
            'focus': function() {
                $(form_field.replace('txt', 'inp')).setStyle('background', 'transparent url(images/inptxt1-leftg.png) no-repeat scroll 0 0');
                $(form_field.replace('txt', 'right')).setStyle('background', 'transparent url(images/inptxt1-rightg.png) no-repeat scroll 100% 0');
            },
            'blur': function() {
                $(form_field.replace('txt', 'inp')).setStyle('background', 'transparent url(images/inptxt1-left.png) no-repeat scroll 0 0');
                $(form_field.replace('txt', 'right')).setStyle('background', 'transparent url(images/inptxt1-right.png) no-repeat scroll 100% 0');
            }
        });

    }
}

function CheckRegisterForm() {
    errorcount = 0;
    checktext('first_name_txt');
    checktext('last_name_txt');
    checktext('email_txt');
    checktext('company_name_txt');
    checktext('user_name_txt');
    checktext('password_txt');

    if (errorcount == 0) {
        $('register_form').submit();
    } else {
        var ca1 = new Custom.Alert('', '<b>Errors</b> <br /><br /> <span class="little">You have ' + errorcount + ' errors</span>', {
                content: 'html',
                text: {
                    confirmButtonText: '',
                    closeButtonText: ''
                },
                opacify: false,
                draggable: false,
                zones: {
                    box: 'box1',
                    head: 'head1',
                    body: 'body1',
                    buttonBox: 'buttonBox1'
                },
                buttons: {
                    closeButton: 'cancelButton1',
                    confirmButton: 'confirmButton1'
                },
                overlay: false
            }
	    );
        ca1.create();
    }
}