var rstSignUp = (function() {
    function adjust_error_form() {
   	    $('td:has(.fielderror)').each(function() {
	        //tmp_fieldhelp = $(this).find('.fieldhelp').clone();
	        $(this).find('.fieldhelp').remove();
	        //$(this).find('.fielderror').after(tmp_fieldhelp);
	    });    
    }
    function adjust_html() {
        //HTML adjustments
        $('#submit\\.container').remove();
    }
    function adjust_css() {
        //CSS adjustments
    }
    function set_events() {
        //Events       
        $('.submitbtn').click(function() {
	        $('.signup-form').ajaxSubmit({
	            beforeSend: function() {
	                $('.submitbtn').after('<img id="wait" src="/images/site/wait30trans.gif"></img>');
	            },
				success: function(responseText, statusText) {
				    $('#load-buffer').html(responseText);
				    var err = false;
                    	if ($('#load-buffer .has_error').length != 0) {
                        adjust_error_form();
                        err = true;
                    }
                    adjust_html();
                    adjust_css();
                    setTimeout(function() {
                    	if (err)
                        	$('#signup').html($('#load-buffer').html()).show();
                        else
                        	$('#main').html($('#load-buffer').html()).show();
                        $('#load-buffer').empty();
                        //set_events();
                        if ('rstDialog' in window)
                            rstDialog.init();
                        $('#wait').remove();
                    }, 1000);
				}
			});
		});
    }
    return {
        init: function() {
            adjust_html();
            adjust_css();
            set_events();
        }
    }
})()
$(document).ready(function() {
	rstSignUp.init()
});

