
/**
 * 
 */
function stripTags(str) {
    return str.replace(/<\/?[^>]+>/gi, '');
}

/**
 * Toggle bg images within form fields
 */
$(function() {
    // Login slide out
    $('#loginSubmit').click(function() {
        if (false == $('#loginSlide').is(':visible')) {
            $('#loginSlide').show("slide", {direction: "right"}, 500);
            return false;
        }

        return true;
    });

    // Remove bg images if not empty    
    if ('' != $('#loginUsername').val()) {
        $('#loginUsername').addClass('active');
    }
    if ('' != $('#loginPassword').val()) {
        $('#loginPassword').addClass('active');
    }
    // Remove bg images when typing in sth.
    $('#loginForm .username,#loginForm .password').focus(function() {
        if (this.value == '') {
            $(this).addClass('active')
        }
    });
    // Validate fields
    $('#loginForm').submit(function() {
        if ('' == $('#loginUsername').val()) {
            alert('Bitte gib deinen Username ein');
            $('#loginUsername').focus();
            return false;
        }
        if ('' == $('#loginPassword').val()) {
            alert('Bitte gib dein Passwort ein');
            $('#loginPassword').focus();
            return false;
        }
        return true;
    });
});

/**
 * Newsletter form, same as above...
 */
$(function() {
    if ('' != $('#sidebarNewsletterEmail').val()) {
        $('#sidebarNewsletterEmail').addClass('active');
    }
    $('#sidebarNewsletterEmail').focus(function() {
        if (this.value == '') {
            $(this).addClass('active')
        }
    });
    $('#sidebarFormNewsletter').submit(function() {
        if ('' == $('#sidebarNewsletterEmail').val()) {
            alert('Bitte gib deine E-Mail-Adresse ein');
            $('#sidebarNewsletterEmail').focus();
            return false;
        }

        return true;
    });
});

/**
 * Mouse over images
 */
$(function() {
    $('#nav li a.hover, #navSub li a.hover').mouseover(function() {
        navSrc = $(this).children('img').attr('src');
        if (navSrc.match(/-active\.png/)) {
            return;
        }
        $(this).children('img').attr('src', navSrc.replace(/\.png/, '-active.png'));
    })
    .mouseout(function() {
        navSrc = $(this).children('img').attr('src');
        $(this).children('img').attr('src', navSrc.replace(/-active.png/, '.png'));
    })
});

/**
 * Toggle collapsed table rows
 */
$(function() {
    $('.tableRowExpand th, .tableRowExpand td').each(function() {
        completeContents = $(this).html().trim();
        contents = stripTags(completeContents).substr(0,10) + '...';
        $(this).html( contents );
        $(this).append('<div class="completeContents" style="display: none">' + completeContents + '</div>');
    });
    // Add toggle handler
    $('.tableRowExpand th').each(function() {
        contents = '<a href="#" title="Ausklappen" class="toggle">&#9658</a> ';
        $(this).prepend(contents);
        $(this).find('.toggle').click(function() {
            $(this).parents('tr').children('th,td').each(function() {
                completeContents = $(this).find('.completeContents').html();
                $(this).html(completeContents);
            });

            return false;
        })
    });
})

$(function() {
    $('a[rel="facebook_coupon"]').click(function() {
        var d=document;
        f='http://www.facebook.com/share';
        l=d.location;
        e=encodeURIComponent;
        p='.php?src=bm&v=4&i=1290860643&u='+e(l.href)+'&t='+e(d.title);
        1;
        try{
            if(!/^(.*\.)?facebook\.[^.]*$/.test(l.host))throw(0);
            share_internal_bookmarklet(p)
        } catch(z) {
            a=function() {
                if (!window.open(f+'r'+p,'sharer','toolbar=0,status=0,resizable=1,width=626,height=436'))
                    l.href=f+p
            };
            if (/Firefox/.test(navigator.userAgent))setTimeout(a,0);
            else{
                a()
                }
            }
        void(0) ;
    });
})
