$(function(){

    // init tabs
    if( $('#tabs').length > 0 ) {
        var tabs = $("#tabs").tabs();

        // activate first tab containing errors
        var errorTab = $('ul.form-errors:first').parents('div[id^=tab]');
        $('form div[id^=tab]').each(function(i){
            if(i>0 && $(this).find('ul.form-errors').length > 0) {
                tabs.tabs('select',i);
                i = -1;
            }
        });

    }

    // add * to label for required fields
    $('label.required').each(function() {
        $(this).html($(this).html()+' *');
    });
    // add * to label for required fields
    $('.externalInfoBlock a').each(function() {
        if($(this).attr('href') && $(this).attr('href').indexOf(siteUrl) !== 0 && $(this).attr('href').indexOf(baseUrl) !== 0) {
            $(this).attr('target', '_blank');
        }
    });
    // add * to label for required fields
    $('.marketingBlock').bind('click', function() {
        document.location = $('a:first', this).attr('href');
    });
    
    
    // set actions keyword
    if($('input[name=search]').length > 0) {
        $('input[name=search]').bind('focus',function(){
                if($(this).val() == defaultKeywordValue) {
                    $(this).val('')
                           .css('font-style','normal')
                           .css('color','inherit');
                }
            })
            .bind('blur',function(){
                if($(this).val() == '') {
                    $(this).val(defaultKeywordValue)
                           .css('font-style','italic')
                           .css('color','#777');
                }
            })
            .val(defaultKeywordValue)
            .css('font-style','italic')
            .css('color','#777');

        $('form').bind('submit',function(){
            if($(this).find('input[name=search]').val() == defaultKeywordValue) {
                $(this).find('input[name=search]').val('');
            }
        });
    }



    // init tabs
    if( $('#tabs').length > 0 ) {
        var tabs = $("#tabs").tabs();

        // activate first tab containing errors
        var errorTab = $('ul.form-errors:first').parents('div[id^=tab]');
        $('form div[id^=tab]').each(function(i){
            if(i>0 && $(this).find('ul.form-errors').length > 0) {
                tabs.tabs('select',i);
                i = -1;
            }
        });

    }

});

function toggleShortList() {
    cn = $('#shortlist').attr('class');
    if(cn.indexOf(' inactive') == -1) {
        cn = cn + ' inactive'
    }else {
        cn = cn.replace(' inactive', '');
    }
    $('#shortlist').attr('class', cn);
}
