basic = new Basic();

function Basic()
{

    var LOAD_IMAGE_HTML = '<div style="text-align: center;"><img src="/img/loadimage.gif" alt="" /></div>';
    var HIDDEN_MSIE_CLASS_NAME = 'hidden-msie';

    this.showLoadImage = function(selector)
    {
        $(selector).each(function(){
            $(this).html(LOAD_IMAGE_HTML);
        });
    }

    this.hideLoadImage = function(selector)
    {
        $(selector).each(function(){
            $(this).empty();
        });
    }

    this.addErrorsHTML = function(fieldId, blockId, errors)
    {
        $('#' + fieldId).addClass('error');
        var errorsBlock = $('#' + blockId);
        errorsBlock.empty();
        for(error in errors) {
            errorsBlock.append('<li>' + errors[error] + '</li>');
        }
    }

    this.isEmail = function(email)
    {
        return /^([a-zA-Z0-9_+\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
    }

    this.showTab = function(defaultBlock, replaceTo, tabClass, tabLinkClass, ajaxUrl, showAnyway)
    {
        if (!tabClass) {
            tabClass = 'tab';
        }
        if (!tabLinkClass) {
            tabLinkClass = 'tab-link';
        }
        if (replaceTo) {
            location.hash = replaceTo;
        }
        $('.' + tabClass).hide();
        $('.' + tabLinkClass).removeClass('selected');
        var blockId = (!showAnyway && location.hash && $(location.hash).length ? location.hash.substring(1) : defaultBlock);
        if (!$('#' + blockId + '.' + tabClass).length) {
            blockId = defaultBlock;
        }
        if (blockId && $('#' + blockId).length) {
            $('#' + blockId).show();
            $('#tabLink-' + blockId + '.' + tabLinkClass).addClass('selected');
            if (ajaxUrl && !$('#' + blockId).html()) {
                this.showLoadImage('#' + blockId);
                $.post(
                    ajaxUrl,
                    function(response) {
                        $('#' + blockId).html(response);
                    }
                );
            }
        }
    }

}