 // <![CDATA[
  var ua= navigator.userAgent;
  var OPERA= (ua.indexOf("Opera") > 0);
  var OMNI= (ua.indexOf("Omni") > 0);
  var MAC= (navigator.platform.indexOf("PPC") > 0);
  var WIN= (navigator.platform=="Win32");

  var IE6, IE5_6, IE5_5, IE5, N4, N5, NS6, NS6_1, MOZ, MAC_IE5;

  if(!OPERA && !OMNI){

     IE6= (ua.indexOf("MSIE 6") > 0);

     // IE 5.5 and IE 5.6 are similar. IE 5.6 is released on WindowsXP
     IE5_6= (ua.indexOf("MSIE 5.6") > 0);
     IE5_5= (ua.indexOf("MSIE 5.5") > 0 || IE5_6);

     // IE5 is true for IE5.5, IE5.6, and IE6.
     IE5= (ua.indexOf("MSIE 5") > 0  || IE6);

     N4= (document.layers);
     NS6= N5= (ua.indexOf("Gecko") > 0);
     NS6_1= (N5 && ua.indexOf("6.1") != -1);
     MOZ= N5 && !(ua.indexOf("Netscape") > 0);
     MAC_IE5= (MAC && IE5);
    }
 // ]]>

 function emailcode(name,domain,subject,linktext)
{
        var str_subject = (subject == '') ? 'Anfrage www.blau-weiss-buch.de' : subject;
        var str_address = name + '@' + domain;
        var str_linktext = (linktext == undefined) ? str_address :  linktext;

        if(name != '' && domain !='')
        {
                document.write('<a href=\"mailto:'+ str_address + '?subject='+str_subject+'\">');
                document.write(str_linktext);
                document.write('</a>');
        }
        else
        {
                document.write('Keine gültige E-Mail-Adresse!');
        }
}

function phonecode(code,suffix,number)
{
	document.write(code+' '+suffix+'-'+number);
}

function BuchBookmark()
{
        window.external.AddFavorite('http://www.blau-weiss-buch.de', 'SG Blau - Weiß Buch');
}

function openPictureWindow(source,width,height)
{
        if(width == 'undefined') width = 640;
        if(height == 'undefined') height = 480;
        
        PictureWindow = window.open(source,'PictureWindow','width='+(width+20)+',height='+(height+20)+',dependent=yes, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no');
        PictureWindow.focus();
}

var objActualTextArea;

function mark(txtObj)
{
    if (txtObj.createTextRange)
    {
        txtObj.caretPos = document.selection.createRange().duplicate();
        isSelected = true;
    }
    objActualTextArea = txtObj;
}

function insertTag (objId, tag, enclose) {
    var closeTag = tag;
    if ( enclose )
    {
        var attribSplit = tag.indexOf ( ' ' );
        if ( tag.indexOf ( ' ' ) > -1 )
            closeTag = tag.substring ( 0, attribSplit );
    }

    if ( isSelected )
    {
        var txtObj = document.getElementById(objId);
        if (txtObj.createTextRange && txtObj.caretPos)
        {
             var caretPos = txtObj.caretPos;
             caretPos.text = ( ( enclose ) ? "<"+tag+">"+caretPos.text+"</"+closeTag+">" : "<"+tag+">"+caretPos.text );
             markiere( txtObj );
             if ( txtObj.caretPos.text=='')
             {
                 isSelected=false;
                 txtObj.focus();
             }
        }
    }
    else
    {
        // placeholder for loss of focus handler
    }

    //updateHTML();
}

function deleteAllTags()
{
    var txtObj = document.selection.createRange();
    var text=txtObj.text;
    var result = false;

    var search_string = /<[.a-zA-Z0-9\/\s\+=#]+>/g;

    var result = search_string.test(text);
    if(result == true)
    {
        text=text.replace(search_string,"");
    }
    txtObj.text=text;
    //updateHTML();
}

function replace_cr(text)
{
    var result = false;

    var search_string = /\r\n/g;

    var result = search_string.test(text);

    if(result == true)
    {
        text=text.replace(search_string,"<br/>");
    }
    return text;
}

function leadingOught(number)
{
    if(number<10)
    {
        number="0"+number;
    }
    return number;
}

var Aufrufzeit = new Date();
var Differenz = 0;
function Zeitberechnung()
{
    var AktuelleZeit = new Date();
    Differenz = parseInt((AktuelleZeit.getTime() - Aufrufzeit.getTime()) / 1000);
    setTimeout("Zeitberechnung()", 1000);
}

function OnlineZeitSpeichern()
{
    Differenz=String(Differenz);
    Webseite=document.URL.replace(/.*\\/,"");
    Webseite=Webseite.replace(/\./,"_");
    OnlineZeitSpeichern = window.open("onlinezeitspeichern.php?Verweildauer="+Differenz+"&amp;Webseite="+Webseite, "OnlineZeitSpeichern", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=0,height=0");
    OnlineZeitSpeichern.close();
}

function gotoYear(year)
{

    yearelement = document.getElementById('year'+year);


    if(yearelement != null)
    {
        for(yearIndex=1977;yearIndex<2078;yearIndex++)
        {
            var yearToHide = document.getElementById('year'+yearIndex);
            if(yearToHide != null)
            {
                yearToHide.style.visibility = 'hidden';
            }
        }
        yearelement.style.visibility = 'visible';
    }
}
//-->



function setActualTextArea(object)
{
    objActualTextArea = object;
}

function setSmile(smile,id)
{
    if(objActualTextArea != null)
    {
        objElement = document.getElementById(objActualTextArea.id);
    }
    else
    {
        objElement = document.getElementById(id);
    }

    if(objElement != null)
    {

        if(IE6)
        {
            if(objElement.childNodes[0] == null)
            {
                //Element muss wenigstens einen Node haben...
                var newText=document.createTextNode('');
                objElement.appendChild(newText);
            }

            objElement.childNodes[0].nodeValue += smile;

        }
        else
        {
            alert('Tragen Sie bitte   '+smile+'    an die gewünschte Stelle im Text ein!');
        }

        objElement.focus();
    }
}

function setAdminPasswordCookie()
{
	var adminpw = document.getElementById('adminpassword');
	setCookie('adminpassword', MD5(adminpw.value), 2);
}

function setCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}