// ----------------------------------------------
// Erstellt:  10.05.2006
// Anmerkung: Verschiedene Funktionen
// Autor:     (c) Andreas 'decoman' Fay
// ----------------------------------------------


var blnIE                                        =  self.innerHeight ? false : true;
var blnIE6                                       =  (document.documentElement && document.documentElement.scrollTop) ? true : false;
var blnIEother                                   =  document.body ? true : false;



// Browse
function openBrowseWindow(strParent, strURL)
{
    switch (strParent)
    {
        default:
            strURLAppendix                       =  "";
            break;
    }

    var BrowseWindow                             =  window.open(strURL+strURLAppendix, "browseWindow", "width=560,height=600,left=100,top=100,location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,dependent=yes,hotkeys=no");
    BrowseWindow.focus();
}


function openBrowseWindow4Information(strParent, strURL)
{
    switch (strParent)
    {
        case "group_category":
            arrMatch                             =  strURL.match(/([0-9]+)\/?$/);
            strURLAppendix                       =  document.getElementsByName('category['+arrMatch[1]+']')[0].value;
            break;
            
        case "pm_user":
            strURLAppendix                       =  document.getElementsByName('receiver')[0].value;
            break;
            
        case "quiz_category":
            strURLAppendix                       =  document.getElementsByName('category')[0].value;
            break;
    }

    var BrowseWindow                             =  window.open(strURL+"needle="+strURLAppendix, "browseWindow", "width=1,height=1,left=10000,top=100,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,dependent=yes,hotkeys=no");
    BrowseWindow.focus();
}


function closeBrowseWindow(strParent, arrInformation)
{
    window.close();
    opener.focus();

    switch (strParent)
    {
        case "group_category":
            intId                                =  arrInformation[0];

            opener.document.getElementsByName('request_category['+intId+']').value           =  "";
            opener.document.getElementsByName('category_new_head['+intId+']').value          =  "";
            opener.document.getElementById('create_category_'+intId).style.display           =  "none";
            
            if (arrInformation.length == 1)
            {
                opener.document.getElementById('group_category_mismatch_'+intId).style.display= "block";
                opener.document.getElementById('group_category_match_'+intId).style.display  =  "none";
            }
            else
            {
                opener.document.getElementsByName('category['+intId+']')[0].value            =  arrInformation[1];

                opener.document.getElementById('group_category_mismatch_'+intId).style.display=  "none";
                opener.document.getElementById('group_category_match_'+intId).style.display  =  "block";
            }
            break;
            
        case "pm_user":
            if (arrInformation.length == 0)
            {
                opener.document.getElementById('pm_send_receiver_mismatch').style.display    =  "block";
                opener.document.getElementById('pm_send_receiver_match').style.display       =  "none";
            }
            else
            {
                opener.document.getElementsByName('receiver')[0].value                       =  arrInformation[0];

                opener.document.getElementById('pm_send_receiver_mismatch').style.display    =  "none";
                opener.document.getElementById('pm_send_receiver_match').style.display       =  "block";
            }
            break;
            
        case "quiz_category":
            if (arrInformation.length == 0)
            {   
                opener.document.getElementsByName('category')[0].className                   =  opener.document.getElementsByName('category')[0].className+" highlight";
            
                opener.document.getElementById('quiz_category_mismatch').style.display       =  "block";
                opener.document.getElementById('quiz_category_match').style.display          =  "none";
            }
            else
            {
                opener.document.getElementsByName('category')[0].value                       =  arrInformation[0];
                
                bowdlerizeClass(opener.document.getElementsByName('category')[0], "highlight");

                opener.document.getElementById('quiz_category_mismatch').style.display       =  "none";
                opener.document.getElementById('quiz_category_match').style.display          =  "block";
            }
            break;
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        bowdlerizeClass
// Description:
// Input:       Field,
//              Classname
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (08.05.2007)
// ----------------------------------------------
function bowdlerizeClass(objField, strClassName)
{
    objField.className                           =  objField.className.replace(strClassName, "");
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        checkSelectedText
// Description:
// Input:       Field-Id
// Output:      TRUE if text is selected,
//              FALSE if no text is selected
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (10.05.2007)
// ----------------------------------------------
function checkSelectedText(strField)
{
    objField                                     =  document.getElementById(strField);

    // IE
    if (document.selection)
    {
        objField.focus();
        sel                                      =  document.selection.createRange();
        if (sel.text.length)
            return true;
        else
            return false;
    }

    // MOZILLA/NETSCAPE
    else if (objField.selectionStart || objField.selectionStart == "0")
    {
        var startPos                             =  objField.selectionStart;
        var endPos                               =  objField.selectionEnd;

        if (startPos != endPos)
            return true;
        else
            return false;
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        closeAdvancedSearch
// Description:
// Input:       Layer
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (25.05.2007)
// ----------------------------------------------
function closeAdvancedSearch(strLayerId)
{
    objLayer                                  =  document.getElementById(strLayerId);
    objLayer.style.zIndex                     =  -1;
    objLayer.style.display                    =  "none";
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        closeImageView
// Description:
// Input:       
// Output:
// ----------------------------------------------
// Version:     0.2
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (12.06.2007)
// v0.2 (23.08.2007)
// ----------------------------------------------
function closeImageView(strLayerId)
{
    objLayer                                  =  document.getElementById("image_view");
    objIframe                                 =  document.getElementById("image_view_iframe");
    
    objLayer.style.zIndex                     =  -1;
    objIframe.style.zIndex                    =  -1;
    objLayer.style.display                    =  "none";
    objIframe.style.display                   =  "none";
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        closePreview
// Description:
// Input:       Fields
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// ----------------------------------------------
function closePreview(strLayerId)
{
    objLayer                                  =  document.getElementById(strLayerId);
    objLayer.style.zIndex                     =  -1;
    objLayer.style.display                    =  "none";
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        disableFields
// Description:
// Input:       Fields
// Output:
// ----------------------------------------------
// Version:     0.3
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (11.04.2007)
// v0.2 (12.08.2007)
//      - added support of selectbox
// v0.3 (15.08.2007)
//      - adjusted class-set
// ----------------------------------------------
function disableFields(arrField)
{
    for (var intFieldId in arrField)
    {
        for (var i=0; i<document.getElementsByName(arrField[intFieldId]).length; i++)
        {
            if ((document.getElementsByName(arrField[intFieldId])[i].type == "radio")
                || (document.getElementsByName(arrField[intFieldId])[i].type == "checkbox")
                || (document.getElementsByName(arrField[intFieldId])[i].type == "select-one"))
                document.getElementsByName(arrField[intFieldId])[i].disabled
                                                 =  true;
            else if (document.getElementsByName(arrField[intFieldId])[i].name)
            {
                document.getElementsByName(arrField[intFieldId])[i].readOnly
                                                 =  true;
                document.getElementsByName(arrField[intFieldId])[i].className
                                                 =  document.getElementsByName(arrField[intFieldId])[i].className + " readonly";
            }
        }
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        enableFields
// Description:
// Input:       Fields
// Output:
// ----------------------------------------------
// Version:     0.3
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (11.04.2007)
// v0.2 (12.08.2007)
//      - added support of selectbox
// v0.3 (15.08.2007)
//      - adjusted class-set
// ----------------------------------------------
function enableFields(arrField)
{
    for (var intFieldId in arrField)
    {
        for (var i=0; i<document.getElementsByName(arrField[intFieldId]).length; i++)
        {
            if ((document.getElementsByName(arrField[intFieldId])[i].type == "radio")
                || (document.getElementsByName(arrField[intFieldId])[i].type == "checkbox")
                || (document.getElementsByName(arrField[intFieldId])[i].type == "select-one"))
                document.getElementsByName(arrField[intFieldId])[i].disabled
                                                 =  false;
            else if (document.getElementsByName(arrField[intFieldId])[i].name)
            {
                document.getElementsByName(arrField[intFieldId])[i].readOnly
                                                 =  false;
                bowdlerizeClass(document.getElementsByName(arrField[intFieldId])[i], "readonly");
            }
        }
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        formatTextInArea
// Description:
// Input:       Field-Id,
//              Prefix,
//              Suffix
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (10.05.2007)
// ----------------------------------------------
function formatTextInArea(strField, strPrefix, strSuffix)
{
    objField                                     =  document.getElementById(strField);

    // IE
    if (document.selection)
    {
        objField.focus();
        sel                                      =  document.selection.createRange();

        // Delete format
        if ((sel.text.substr(0, strPrefix.length) == strPrefix) && (sel.text.substr(sel.text.length-strSuffix.length) == strSuffix))
        {
            sel.text                             =  sel.text.substring(strPrefix.length, sel.text.length-strSuffix.length);
        }
        else
        {
            oldSel                               =  sel.duplicate();
            sel.moveStart("character", strPrefix.length*-1);
            sel.moveEnd("character", strSuffix.length);

            if ((sel.text.substr(0, strPrefix.length) == strPrefix) && (sel.text.substr(sel.text.length-strSuffix.length) == strSuffix))
            {
                sel.text                         =  sel.text.substring(strPrefix.length, sel.text.length-strSuffix.length);
            }
            // Add format
            else
            {
                oldSel.text                      =  strPrefix+oldSel.text+strSuffix;
            }
        }
    }

    // MOZILLA/NETSCAPE
    else if (objField.selectionStart || objField.selectionStart == "0")
    {
        var startPos                             =  objField.selectionStart;
        var endPos                               =  objField.selectionEnd;

        // Delete format
        if ((objField.value.substring(startPos, endPos).substr(0, strPrefix.length) == strPrefix) && (objField.value.substring(startPos, endPos).substr(objField.value.substring(startPos, endPos).length-strSuffix.length) == strSuffix))
        {
            objField.value                       =  objField.value.substring(0, startPos)
                                                    + objField.value.substring(startPos+strPrefix.length, endPos-strSuffix.length)
                                                    + objField.value.substring(endPos, objField.value.length);
        }
        else if ((objField.value.substring(0, startPos).substr(objField.value.substring(0, startPos).length-strPrefix.length) == strPrefix) && (objField.value.substring(endPos, objField.value.length).substr(0, strSuffix.length) == strSuffix))
        {
            objField.value                       =  objField.value.substring(0, startPos-strPrefix.length)
                                                    + objField.value.substring(startPos, endPos)
                                                    + objField.value.substring(endPos+strSuffix.length, objField.value.length);
        }
        // Add format
        else
        {
            objField.value                       =  objField.value.substring(0, startPos)
                                                    + strPrefix
                                                    + objField.value.substring(startPos, endPos)
                                                    + strSuffix
                                                    + objField.value.substring(endPos, objField.value.length);
        }
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        formatTextInArea_withCheck
// Description: see also formatTextInArea
//              added check for selected text
// Input:       Field-Id,
//              Prefix,
//              Suffix,
//              Errormessage
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (10.05.2007)
// ----------------------------------------------
function formatTextInArea_withCheck(strField, strPrefix, strSuffix, strMessage)
{
    if (checkSelectedText(strField))
        formatTextInArea(strField, strPrefix, strSuffix);
    else
        alert(strMessage);
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        getInnerDimensions
// Description: 
// Input:
// Output:      (arr) x: innerWidth
//                    y: innerHeight
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (26.07.2007)
// ----------------------------------------------
function getInnerDimensions()
{
    var x,y;
    var arrDimension                             =  new Array();
    
    // All except Explorer
    if (self.innerHeight)
    {
    	x                                        =  self.innerWidth;
    	y                                        =  self.innerHeight;
    }
    
    // Explorer 6 Strict Mode
    else if (document.documentElement && document.documentElement.clientHeight)
    {
    	x                                        =  document.documentElement.clientWidth;
    	y                                        =  document.documentElement.clientHeight;
    }
    
    // Other Explorers
    else if (document.body)
    {
    	x                                        =  document.body.clientWidth;
    	y                                        =  document.body.clientHeight;
    }
    
    arrDimension['x']                            =  x;
    arrDimension['y']                            =  y;
    
    return arrDimension;
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        getPointerPosition
// Description:
// Input:
// Output:      Pointer position
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// ----------------------------------------------
function getPointerPosition(mousemove)
{
    if (!mousemove)
        mousemove                                =  window.event;

    arrPointer                                   =  new Array();

    if (self.pageYOffset) // all except Explorer
    {
        x                                       =  self.pageXOffset;
        y                                       =  self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
    {
        x                                        =  document.documentElement.scrollLeft;
        y                                        =  document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        x                                        =  document.body.scrollLeft;
        y                                        =  document.body.scrollTop;
    }

    arrPointer["x"]                              =  mousemove.clientX+x;
    arrPointer["y"]                              =  mousemove.clientY+y;

    return arrPointer;
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        insertAtCursor
// Description:
// Input:       Field,
//              Text
// Output:      Offset at the end of new text
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// ----------------------------------------------
function insertAtCursor(objField, strValue)
{
    // IE
    if (document.selection)
    {
        objField.focus();
        sel                                      =  document.selection.createRange();
        sel.text                                 =  strValue;
    }

    // MOZILLA/NETSCAPE
    else if (objField.selectionStart || objField.selectionStart == "0")
    {
        var startPos                             =  objField.selectionStart;
        var endPos                               =  objField.selectionEnd;

        objField.value                           =  objField.value.substring(0, startPos)
                                                    + strValue
                                                    + objField.value.substring(endPos, objField.value.length);
    }

    else
        objField.value                           += objField;

    return endPos+strValue.length;
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        insertEmailVariable
// Description:
// Input:       Fields
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// ----------------------------------------------
function insertEmailVariable(objField, strValue, objActivator)
{
    intOffset                                    =  insertAtCursor(objField, strValue);

    objActivator.selectedIndex                   =  0;
    setCursor(objField, intOffset);
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        installSearchEngine
// Description: (external from firefox)
// Input:       Language
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (26.05.2007)
// ----------------------------------------------
function installSearchEngine(strLanguage) {
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.neemoy.com/files/search-plugins/neemoy_"+strLanguage+".xml");
 /*} else if (window.sidebar && ("addSearchEngine" in window.sidebar)) {
   // Firefox <= 1.5, Sherlock
   window.sidebar.addSearchEngine("http://example.com/search-plugin.src",
                                  "http://example.com/search-icon.png",
                                  "Search Plugin", "");*/
 } else {
   // No search engine support (IE 6, Opera, etc).
   alert("No search engine support");
 }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        neemoy_scroll_offset_get2field
// Description: 
// Input:       (str) Field-Id
// Output:      
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (07.02.2008)
// ----------------------------------------------
function neemoy_scroll_offset_get2field(strFieldId)
{
    // Get scrolloffset
    arrOffset                                    =  page_scroll_offset_get();
    
    // Write offset to field
    document.getElementById(strFieldId).value    =  arrOffset['x'] + "|" + arrOffset['y'];
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openAdvancedSearch
// Description:
// Input:       Layer,
//              Event
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (25.05.2007)
// ----------------------------------------------
function openAdvancedSearch(strLayerId, event)
{
    objLayer                                  =  document.getElementById(strLayerId);

    // Position layer
    arrPointer                                =  getPointerPosition(event);
    objLayer.style.left                       =  arrPointer['x']-300 + "px";
    objLayer.style.top                        =  arrPointer['y']+10 + "px";

    objLayer.style.zIndex                     =  3;
    objLayer.style.display                    =  "block";
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openImageView
// Description:
// Input:       (str) Imagesource,
//              (int) Imagewidth,
//              (int) Imageheight
// Output:
// ----------------------------------------------
// Version:     0.4
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (12.06.2007)
// v0.2 (14.07.2007)
// v0.3 (23.08.2007)
// v0.4 (24.08.2007)
// ----------------------------------------------
function openImageView(strImage, intWidth, intHeight)
{
    closeImageView();
    
    arrDimensions                                =  getInnerDimensions();
    
    
    objLayer                                     =  document.getElementById("image_view");
    objIframe                                    =  document.getElementById("image_view_iframe");
    objSubLayer                                  =  document.getElementById("image_view_img");
    
    // Dimensions
    intHeightOri                                 =  intHeight;
    intWidthOri                                  =  intWidth;
    if (arrDimensions['x'] - 50 < intWidth)
    {
        intWidth                                 =  arrDimensions['x'] - 50;
        intHeight                                =  intWidth/intWidthOri * intHeightOri;
    }
    if (arrDimensions['y'] - 50 < intHeight)
    {
        intHeight                                =  arrDimensions['y'] - 50;
        intWidth                                 =  intHeight/intHeightOri * intWidthOri;
    }
    objSubLayer.style.height                     =  intHeight;
    objSubLayer.style.width                      =  intWidth;
    
    objIframe.style.height                       =  intHeight*1 +(blnIE ? 30 : 18);
    objIframe.style.width                        =  intWidth*1 +(blnIE ? 14 : 4);

    if (objLayer.style.display == "none")
    {
        arrDimension                             =  getInnerDimensions();
        arrOffset                                =  page_scroll_offset_get();

        // Position layer
        objLayer.style.left                      =  arrDimension['x']/2 - intWidth/2 + (blnIE ? arrOffset['x'] : 0);
        objIframe.style.left                     =  arrDimension['x']/2 - intWidth/2 + (blnIE ? arrOffset['x'] : 0);
        objLayer.style.top                       =  arrDimension['y']/2 - intHeight/2 + (blnIE ? arrOffset['y'] : 0);
        objIframe.style.top                      =  arrDimension['y']/2 - intHeight/2 + (blnIE ? arrOffset['y'] : 0);
        
        objSubLayer.innerHTML                    =  '<a href="#" onClick="closeImageView(); return false;"><img src="'+strImage+'" alt="" width="'+intWidth+'" height="'+intHeight+'"></a>';

        objLayer.style.zIndex                    =  3;
        objIframe.style.zIndex                   =  2;
        objLayer.style.display                   =  "block";
        objIframe.style.display                  =  "block";
        
        // Fade in
        objFader                                 =  new fader(objSubLayer, "objFader");
        objFader.stepFade                        =  0.05;
        objFader.stepTime                        =  10;
        objFader.fadeIn();
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openPreview
// Description:
// Input:       Fields
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// v0.2 (05.02.2008)
// ----------------------------------------------
function openPreview(strLayerId, strContentId, event)
{
    openPreview_withContent(strLayerId, document.getElementById(strContentId).value, event);
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openPreview_raw
// Description:
// Input:       (str) Layer-Id
//              (str) Content
//              (int) X
//              (int) Y
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (05.02.2008)
// v0.2 (14.02.2008)
//      - adjusted for latex-support
// ----------------------------------------------
function openPreview_raw(strLayerId, strContent, intX, intY)
{
    objLayer                                     =  document.getElementById(strLayerId);
    
    // Kill surrounding paragraph recursively
    /* if ((strContent.substr(0, 3) == "<p>") && (strContent.substr(strContent.length-4) == "</p>"))
    {
        strContent                               =  strContent.substring(3,strContent.length-4);
        openPreview_raw(strLayerId, strContent, intX, intY);
        return;
    } */
    
    // Replace paragraphs by <br>
    strContent                                   =  strContent.replace(/<p>/g, "");
    strContent                                   =  strContent.replace(/<\/p>/g, "");

    // Replace [tex]-passages by images
    strContent                                   =  strContent.replace(/\[\/tex\]/g, "†");
    
    while (strContent.search(/(\[tex\][^†]*)\+([^†]*†)/) != -1)
        strContent                               =  strContent.replace(/(\[tex\][^†]*)\+([^†]*†)/g, '$1-pl-$2');
    while (strContent.search(/(\[tex\][^†]*)\n([^†]*†)/) != -1)
        strContent                               =  strContent.replace(/(\[tex\][^†]*)\n([^†]*†)/g, '$1-lf-$2');
    while (strContent.search(/(\[tex\][^†]*)\r([^†]*†)/) != -1)
        strContent                               =  strContent.replace(/(\[tex\][^†]*)\r([^†]*†)/g, '$1-cr-$2');
    while (strContent.search(/(\[tex\][^†]*)\r([^†]*†)/) != -1)
        strContent                               =  strContent.replace(/(\[tex\][^†]*)\r([^†]*†)/g, '$1-ta-$2');
    while (strContent.search(/(\[tex\][^†]*)(&amp;|&)([^†]*†)/) != -1)
        strContent                               =  strContent.replace(/(\[tex\][^†]*)(&amp;|&)([^†]*†)/g, '$1-am-$3');

    // Replace newlines by <br>
    strContent                                   =  strContent.replace(/\n/g, "<br>");
    
    strContent                                   =  strContent.replace(/\[tex\]([^†]+)†/g, '<img src="http://en.neemoy.com/latex/?t=$1" alt="$1" title="$1" align="absmiddle" class="latex">');
    
    document.getElementById(strLayerId+"_content").innerHTML
                                                 =  strContent;

    // Position layer
    objLayer.style.left                          =  intX;
    objLayer.style.top                           =  intY;

    objLayer.style.zIndex                        =  3;
    objLayer.style.display                       =  "block";
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openPreview_withContent
// Description:
// Input:       (str) Layer-Id
//              (str) Content
//              (obj) Events
// Output:
// ----------------------------------------------
// Version:     0.2
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (05.02.2008)
// v0.2 (18.07.2008)
//      - adjusted offset for x-value
// ----------------------------------------------
function openPreview_withContent(strLayerId, strContent, event)
{
    arrPointer                                   =  getPointerPosition(event);
    openPreview_raw(strLayerId, strContent, arrPointer['x']-480, arrPointer['y']-200);
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        openPreview_withContent_centered
// Description:
// Input:       (str) Layer-Id
//              (str) Content
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (05.02.2008)
// ----------------------------------------------
function openPreview_withContent_centered(strLayerId, strContent)
{
    arrDimension                                 =  getInnerDimensions();
    arrOffset                                    =  page_scroll_offset_get();
    openPreview_raw(strLayerId, strContent, arrDimension['x']/2 - 200 + arrOffset['x'], arrDimension['y']/2 + arrOffset['y']);
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        page_scroll_offset_get
// Description: 
// Input:
// Output:      (arr) x: offsetWidth
//                    y: offsetHeight
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (22.08.2007)
// ----------------------------------------------
function page_scroll_offset_get()
{
    var x,y;
    var arrOffset                                =  new Array();
    
    // All except Explorer
    if (self.pageYOffset) // all except Explorer
    {
    	x                                        =  self.pageXOffset;
    	y                                        =  self.pageYOffset;
    }
    
    // Explorer 6 Strict Mode
    else if (document.documentElement && document.documentElement.scrollTop)
    {
    	x                                        =  document.documentElement.scrollLeft;
    	y                                        =  document.documentElement.scrollTop;
    }
    
    // Other Explorers
    else if (document.body)
    {
    	x                                        =  document.body.scrollLeft;
    	y                                        =  document.body.scrollTop;
    }
    
    arrOffset['x']                               =  x;
    arrOffset['y']                               =  y;

    return arrOffset;
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        page_scroll_offset_set
// Description: 
// Input:       (int) X
//              (int) Y
// Output:      
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (06.02.2008)
// ----------------------------------------------
function page_scroll_offset_set(intX, intY)
{
    // All except Explorer
    if (self.pageYOffset) // all except Explorer
    {
    	self.pageXOffset                         =  intX;
    	self.pageYOffset                         =  intY;
    }
    
    // Explorer 6 Strict Mode
    else if (document.documentElement && document.documentElement.scrollTop)
    {
    	document.documentElement.scrollLeft      =  intX;
    	document.documentElement.scrollTop       =  intY;
    }
    
    // Other Explorers
    else if (document.body)
    {
    	document.body.scrollLeft                 =  intX;
    	document.body.scrollTop                  =  intY;
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        setCursor
// Description:
// Input:       Field,
//              Offset
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (19.04.2007)
// ----------------------------------------------
function setCursor(objField, intOffset)
{
    objField.focus();

    // IE
    if (document.selection)
    {
        sel                                      =  document.selection.createRange();
    }

    // MOZILLA/NETSCAPE
    else if (objField.selectionStart || objField.selectionStart == "0")
    {
        objField.selectionStart                  =  intOffset;
        objField.selectionEnd                    =  intOffset;
    }
}


// ----------------------------------------------
// Function
// ----------------------------------------------
// Name:        swapAdvancedSearch
// Description:
// Input:       Object icon,
//              Image maximize,
//              Image minimize,
//              Event
// Output:
// ----------------------------------------------
// Version:     0.1
// ----------------------------------------------
// ChangeLog
// ----------------------------------------------
// v0.1 (25.05.2007)
// ----------------------------------------------
function swapAdvancedSearch(objIcon, strImageMax, strImageMin, event)
{
    strLayerId                                   =  "search_advanced";

    objLayer                                     =  document.getElementById(strLayerId);

    if (objLayer.style.display == "none")
    {
        objIcon.src                              =  strImageMin;
        openAdvancedSearch(strLayerId, event);
    }
    else
    {
        objIcon.src                              =  strImageMax;
        closeAdvancedSearch(strLayerId);
    }
}