// check environment
var env = document.location.href.match(/.*frontend_dev\.php/) ? 'dev' : 'prod';
var url = (env == 'dev') ? '/frontend_dev.php/ausgaben.html' : '/ausgaben.html';

// redirect direct link to issue (e.g. coming form search engine) to 'ausgaben.html', appending anchor
if (document.location.href.match(/.*ausgaben\/\d{4}\/ausgabe-\d{1,3}(-\d{1,3})?\.html/)) 
{
    var href = document.location.href.split('/ausgaben');
    var hrefParts = href[1].match(/\d{1,4}/g);
    document.location.href = url + '#issue-' + hrefParts[0] + '-' + hrefParts[1];
} 
// redirect direct link to overview (e.g. coming form search engine) 
// to 'ausgaben.html', appending anchor
else if (document.location.href.match(/.*ausgaben\/\d{4}\/zeitliche_uebersicht\.html/)) 
{
    var href = document.location.href.split('/ausgaben');
    var hrefParts = href[1].match(/\d{4}/g);
    document.location.href = url + '#overview-' + hrefParts[0];
}

// redirect direct link to register (e.g. coming form search engine) 
// to 'ausgaben.html', appending anchor
else if (document.location.href.match(/.*ausgaben\/\d{4}\/sachregister\.html/)) 
{
    var href = document.location.href.split('/ausgaben');
    var hrefParts = href[1].match(/\d{4}/g);
    document.location.href = url + '#register-' + hrefParts[0];
} 

// if URL does not contain 'ausgaben.html', but an anchor
// redirect and append anchor
else if (!document.location.href.match(/ausgaben\.html/) && document.location.hash) 
{
    document.location.href = url + document.location.hash;
}
