var currSize = 1;

function swichStyleSheetSrc(size) {
    var styleName = 'size'+size;
    $('link[@rel*=STYLE][@title]').each(function() {
        this.disabled = true;
        if($(this).attr('title')==styleName) {
            this.disabled = false;
        }
    });
    $.cookie('styles',size,{expires:7,path:'/'});
}

function disableAll() {
    $('link[@rel*=STYLE]').each(function() {
        this.disabled = true;
    });
}


function setBookmark() {
    var bookmarkurl = location.href;
    var text = document.title;
    text = text.replace(/:/ ,"");
    text = text.replace(/\*/ ,"");
    text = text.replace(/\?/ ,"");
    text = text.replace(/\\/ ,"");
    text = text.replace(/"/ ,"");
    text = text.replace(/</ ,"");
    text = text.replace(/>/ ,"");
    text = text.replace(/|/ ,"");
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(text, bookmarkurl,"");
    } else if( window.external ) { // IE Favorite
        window.external.AddFavorite( bookmarkurl, text);
    } else if(window.opera && window.print) { // Opera Hotlist
        return true;
    }
}

$().ready(function() {
    if(document.all) {
        try {document.execCommand("BackgroundImageCache",false,true);} catch(e){}
    }
    $('#AddBookmark').click(function(){setBookmark(); return false;});
    $('#TextVersion').click(function(){disableAll(); return false;});

    if($.cookie('styles')) {
        currSize = parseInt($.cookie('styles'));
        var isActive = false;
        $('link[@rel*=STYLE][@title]').each(function() {
              if($(this).attr('rel').indexOf('ALTERNATE')==-1
                && $(this).attr('title')=='size'+currSize) {
                    isActive = true;
              }
        });
        $('#fs_size'+currSize).addClass('active');
        if(!isActive) {
            swichStyleSheetSrc(currSize);
        }
    }
    var maxSizes = $('#FontSizer .size').size();
    if(maxSizes > 0) {
        if(currSize==1) {
            $('#fs_minus').addClass('disabled');
        } else if(currSize==maxSizes) {
            $('#fs_plus').addClass('disabled');
        }
        $('#FontSizer .size').click(function() {
            currSize = parseInt(this.id.replace(/fs_size/g,''));
            $('#FontSizer .size').each(function(){$(this).removeClass('active');});
            $(this).addClass('active');
            if(currSize==1) { $('#fs_minus').addClass('disabled');}
            else {$('#fs_minus').removeClass('disabled');}
            if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
            else {$('#fs_plus').removeClass('disabled');}
            swichStyleSheetSrc(currSize);
            return false;
        });
         $('#fs_minus').click(function(){
            if(currSize > 1) {
                currSize--;
                $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                $('#fs_size'+currSize).addClass('active');
                if(currSize==1) { $('#fs_minus').addClass('disabled');}
                else {$('#fs_minus').removeClass('disabled');}
                $('#fs_plus').removeClass('disabled');
                swichStyleSheetSrc(currSize);
            }
            return false;
         });
         $('#fs_plus').click(function(){
                 if(currSize < maxSizes) {
                     currSize++;
                     $('#FontSizer .size').each(function(){$(this).removeClass('active');});
                     $('#fs_size'+currSize).addClass('active');
                     if(currSize==maxSizes) { $('#fs_plus').addClass('disabled');}
                     else {$('#fs_plus').removeClass('disabled');}
                     $('#fs_minus').removeClass('disabled');
                     swichStyleSheetSrc(currSize);
                 }
                 return false;
         });
     }
     $('a[@rel*=mail]').click(function() {
                 var url = this.href;
                 if (navigator.appName == "Netscape"){
                     url = url.replace(/index\.php/,'index_ns.php');
                 }
                 window.open(url,'Mail','width=468,height=565,scrollbars=yes');
                 return false;
     });
     $('.popup img.print,.popup img.close').css({'cursor':'pointer'});
     $('.popup img.print').click(function(){
                    window.print();
                    return false;
              });
              $('.popup img.close').click(function(){
                    self.close();
                    return false;
     });
});



function myOpen(URL) {
    window.open(URL,"_blank","width=480, height=550, menubar=no, resizable=no, scrollbars=yes");
}


function bvOpenWindow(theURL,winName,winCenter,x,y,features) {
  var param = "width=" + x + ",height=" + y + ( features=="" ? "" : "," + features );
  var win = window.open(theURL,winName,param);

  if (theURL.indexOf('http://') == -1) {
    if (winCenter) win.moveTo((screen.width-x)/2,(screen.height-y)/2);
    win.focus();
  }
}

function bvRegistrieren() {
    bvOpenWindow('http://login.bayervital.de/advantix/registrieren/index.jsp?id=SEITENID','Registrieren',1,800,600,'scrollbars=yes,resizable=yes')
}

function bvPasswortVergessen() {
    bvOpenWindow('http://login.bayervital.de/advantix/zusenden/index.jsp?id=SEITENID', 'Passwort',1,800,600,'scrollbars=yes,resizable=yes')
}
function bvLogin() {
    if(document.forms("advantixLOGIN").benutzername.value == "advantix" || document.forms("advantixLOGIN").passwort.value == "advantix" ) {
        jetzt=new Date();
        d = ''+jetzt.getDate();
        m = ''+(jetzt.getMonth()+1);
        y = ''+jetzt.getYear();
        if (d < 10) d = '0'+d;
        if (m < 10) m = '0'+m;
        sec = y+''+m+''+d;
        document.location='http://www.advantix.de/1/Home.htm?sec='+sec;
        return false;
    } else {
        window.document.advantixLOGIN.passwort.value = hex_md5(window.document.advantixLOGIN.passwort.value);
        window.document.advantixLOGIN.submit();
        return true;
    }
}

qq = "Schnellsuche";
function qclearsearch() {
    if (document.forms["wkRightColumnSearch"].q.value == qq) document.forms["wkRightColumnSearch"].q.value = "";
}
function qresetsearch() {
    if (document.forms["wkRightColumnSearch"].q.value == "") document.forms["wkRightColumnSearch"].q.value = qq;
}
