/* functions.js 2005/01/06 rohr */

/**
  * ARo
  *


  */
function openwin(windowname, url, width, height, status) {
   if (navigator.windowname && (navigator.windowname.closed == false)) {
       navigator.windowname.focus();
   }
   else {
       if (status == "")
          status = no;
       ProviderWindow = window.open(url ,windowname ,"toolbar=,location=no,directories=no,menubar=no,scrollbars=yes,status="+status+",resizable=yes,width="+width+",height="+height+",left=100,top=0");
       ProviderWindow.resizeTo(width, height);
       ProviderWindow.focus();
   }
}

function insertValue(formname, elementname, text) {
    var myform = document.forms[formname].elements[elementname];

    myform.value = text;
    return true;
}

function remove_all_html_tags(formname, elementname) {
    var myform = document.forms[formname].elements[elementname];

    //Internet Explorer
    if (document.selection) {
        myform.focus();
        sel = document.selection.createRange();
        sel.text = remove_all_html_tags_auxfunc(sel.text);

    }
    //MOZILLA/NETSCAPE
    else if (myform.selectionStart || myform.selectionStart == "0") {
        var startPos = myform.selectionStart;
        var endPos = myform.selectionEnd;
        var origintext = myform.value;

        myform.value = origintext.substring(0, startPos) + remove_all_html_tags_auxfunc(origintext.substring(startPos, endPos)) + origintext.substring(endPos, origintext.length);
    }
    return;
}

function remove_all_html_tags_auxfunc(mytext) {
    a = mytext.indexOf("<");
    b = mytext.indexOf(">");

    mytextlen = mytext.length;
    c = mytext.substring(0, a);

    if(b == -1) {
       b = a;
    }

    d = mytext.substring((b + 1), mytextlen);

    Word = c + d;

    tmp = Word.indexOf("<");

    if (tmp != -1) { // prüfen, ob keine tags mehr da...
       Word = remove_all_html_tags_auxfunc(Word);
    }

    return Word;
}

function setFocus()
{
    if (document.authform)
    {
       document.authform.user.focus();
       return;
    }
    if (document.webboxsearch)
    {
       document.webboxsearch.searchstring.focus();
       return;
    }
    if (document.googleform)
    {
       document.googleform.q.focus();
       return;
    }
    if (document.adduserform)
    {
       document.adduserform.library_number.focus();
       return;
    }
}

function js_insert_internalimage(editor_obj, editor, imagebase)
{
	//result = document.getElementsByName(editor);
    openwin('InsertImage','/getimageref-1.3.1_2.php?editor='+editor+'&imagebase='+imagebase,850,660,'yes');
}

function js_insert_internallink(editor_obj, editor, type, linkbase)
{
    openwin('InsertImage'+type,'/getbrickref-1.4.1.php?editor='+editor+'&type='+type+'&linkbase='+linkbase,850,660,'yes');
}

function js_insert_externallink_image(editor_obj, imagebase)
{
    editor_obj.insertImage("/image_bricks/external.gif","Symbol für einen externen Verweis","18","16","0");
    editor_obj.flushEvents();
}

function js_insert_opennewwindow_image(editor_obj, imagebase)
{
    editor_obj.insertImage("/image_bricks/new_window_icon.gif","Symbol für Link wird in einem neuen Fenster geöffnet","15","13","0");
    editor_obj.flushEvents();
}

function show_access_protection(brick_id)
{
	openwin('ShowAccessProtection','/show_access_protection-current.php?brick_id=' + brick_id,500,500,'yes');
}
