/*
#
# --------------------------------------------------------------------------------
#
#  fCMS2 Content Management System  - (http://www.fidion.de)
#
#  Copyright (C) 2002 fidion GmbH, Würzburg.  (W) Steffen Einsle, Dipl.Inf.(FH)
#  All rights reserved. This Software is subject to license issues.
#
#  Common JavaScript Base 
#
#  $Id: js.js,v 1.63 2011/03/18 10:05:04 neo Exp $
#
# --------------------------------------------------------------------------------
# $HASH$:00000000000000000000000000000000
*/



/*
    json2.js
    2008-01-17

    Public Domain

    No warranty expressed or implied. Use at your own risk.

    See http://www.JSON.org/js.html

    This file creates a global JSON object containing two methods:

        JSON.stringify(value, whitelist)
            value       any JavaScript value, usually an object or array.

            whitelist   an optional array prameter that determines how object
                        values are stringified.

            This method produces a JSON text from a JavaScript value.
            There are three possible ways to stringify an object, depending
            on the optional whitelist parameter.

            If an object has a toJSON method, then the toJSON() method will be
            called. The value returned from the toJSON method will be
            stringified.

            Otherwise, if the optional whitelist parameter is an array, then
            the elements of the array will be used to select members of the
            object for stringification.

            Otherwise, if there is no whitelist parameter, then all of the
            members of the object will be stringified.

            Values that do not have JSON representaions, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays will be replaced with null.
            JSON.stringify(undefined) returns undefined. Dates will be
            stringified as quoted ISO dates.

            Example:

            var text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'

        JSON.parse(text, filter)
            This method parses a JSON text to produce an object or
            array. It can throw a SyntaxError exception.

            The optional filter parameter is a function that can filter and
            transform the results. It receives each of the keys and values, and
            its return value is used instead of the original value. If it
            returns what it received, then structure is not modified. If it
            returns undefined then the member is deleted.

            Example:

            // Parse the text. If a key contains the string 'date' then
            // convert the value to a date.

            myData = JSON.parse(text, function (key, value) {
                return key.indexOf('date') >= 0 ? new Date(value) : value;
            });

    This is a reference implementation. You are free to copy, modify, or
    redistribute.

    Use your own copy. It is extremely unwise to load third party
    code into your pages.
*/

/*jslint evil: true */

/*global JSON */

/*members "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    charCodeAt, floor, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join, length,
    parse, propertyIsEnumerable, prototype, push, replace, stringify, test,
    toJSON, toString
*/

if (!this.JSON) {

    JSON = function () {

        function f(n) {    // Format integers to have at least two digits.
            return n < 10 ? '0' + n : n;
        }

        Date.prototype.toJSON = function () {

// Eventually, this method will be based on the date.toISOString method.

            return this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z';
        };


        var m = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

        function stringify(value, whitelist) {
            var a,          // The array holding the partial texts.
                i,          // The loop counter.
                k,          // The member key.
                l,          // Length.
                r = /["\\\x00-\x1f\x7f-\x9f]/g,
                v;          // The member value.

            switch (typeof value) {
            case 'string':

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe sequences.

                return r.test(value) ?
                    '"' + value.replace(r, function (a) {
                        var c = m[a];
                        if (c) {
                            return c;
                        }
                        c = a.charCodeAt();
                        return '\\u00' + Math.floor(c / 16).toString(16) +
                                                   (c % 16).toString(16);
                    }) + '"' :
                    '"' + value + '"';

            case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

                return isFinite(value) ? String(value) : 'null';

            case 'boolean':
            case 'null':
                return String(value);

            case 'object':

// Due to a specification blunder in ECMAScript,
// typeof null is 'object', so watch out for that case.

                if (!value) {
                    return 'null';
                }

// If the object has a toJSON method, call it, and stringify the result.

                if (typeof value.toJSON === 'function') {
                    return stringify(value.toJSON());
                }
                a = [];
                if (typeof value.length === 'number' &&
                        !(value.propertyIsEnumerable('length'))) {

// The object is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                    l = value.length;
                    for (i = 0; i < l; i += 1) {
                        a.push(stringify(value[i], whitelist) || 'null');
                    }

// Join all of the elements together and wrap them in brackets.

                    return '[' + a.join(',') + ']';
                }
                if (whitelist) {

// If a whitelist (array of keys) is provided, use it to select the components
// of the object.

                    l = whitelist.length;
                    for (i = 0; i < l; i += 1) {
                        k = whitelist[i];
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                } else {

// Otherwise, iterate through all of the keys in the object.

                    for (k in value) {
                        if (typeof k === 'string') {
                            v = stringify(value[k], whitelist);
                            if (v) {
                                a.push(stringify(k) + ':' + v);
                            }
                        }
                    }
                }

// Join all of the member texts together and wrap them in braces.

                return '{' + a.join(',') + '}';
            }
        }

        return {
            stringify: stringify,
            parse: function (text, filter) {
                var j;

                function walk(k, v) {
                    var i, n;
                    if (v && typeof v === 'object') {
                        for (i in v) {
                            if (Object.prototype.hasOwnProperty.apply(v, [i])) {
                                n = walk(i, v[i]);
                                if (n !== undefined) {
                                    v[i] = n;
                                }
                            }
                        }
                    }
                    return filter(k, v);
                }


// Parsing happens in three stages. In the first stage, we run the text against
// regular expressions that look for non-JSON patterns. We are especially
// concerned with '()' and 'new' because they can cause invocation, and '='
// because it can cause mutation. But just to be safe, we want to reject all
// unexpected forms.

// We split the first stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace all backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

                if (/^[\],:{}\s]*$/.test(text.replace(/\\./g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the second stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                    j = eval('(' + text + ')');

// In the optional third stage, we recursively walk the new structure, passing
// each name/value pair to a filter function for possible transformation.

                    return typeof filter === 'function' ? walk('', j) : j;
                }

// If the text is not JSON parseable, then a SyntaxError is thrown.

                throw new SyntaxError('parseJSON');
            }
        };
    }();
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*86400*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


var pbmode=0;
var pinanz=0;
function pinboard_start(log) {
     var ap = document.getElementsByName('pinboardbtn');
     var pc = document.getElementById('pinanzahl');
     for( var i=0; i<ap.length; i++ ) if ( ap[i].id ) {
         var d = ap[i].id.split('-');
         if ( d[1] && d[2] && pbdat[d[1]] && pbdat[d[1]][d[2]] ) {
              ap[i].src = "/storage/btn/"+pbcfg[d[1]]['file_on']+".gif";
              ap[i].alt = ap[i].title = pbcfg[d[1]]['text_on'];
         }
     }

     for(var t in pbdat) if ( t!='lsp' && typeof(pbdat[t])=="object" ) 
        for(var i in pbdat[t]) if ( pbdat[t][i]=="UID" ) pinanz++;

     if ( pc ) pc.innerHTML=pinanz;

     pbmode = log ? 1 : 2;
}


function pinsetflag(t,i,v) {
     var ap = document.getElementsByName('pinboardbtn');
     var pc = document.getElementById('pinanzahl');
     for( var n=0; n<ap.length; n++ ) 
        if ( ap[n] && ap[n].id && ap[n].id=='pin-'+t+'-'+i ) {
             if ( v ) {
                ap[n].src="/storage/btn/"+pbcfg[t]['file_on']+".gif";
                ap[n].title=ap[n].alt=pbcfg[t]['text_on'];
             } else {
                ap[n].src="/storage/btn/"+pbcfg[t]['file_off']+".gif";
                ap[n].title=ap[n].alt=pbcfg[t]['text_off'];
             }
        }
    pinanz += ( v ? 1 : -1 );
    if ( pc ) pc.innerHTML=pinanz;
}




function pinclick(e,t,i) {

     switch( pbmode ) {
        case 0 :  // noch garnichts
           window.alert("Bitte warten, die Seite ist noch im Aufbau!");
           return(false);
           ;;
        case 1 :  // angemeldeter benutzer
           var stat = ( e.title!=pbcfg[t]['text_on'] );
           if ( t!='lsp' ) {
               pinsetflag(t,i,stat);
           }
           e.src="/storage/tog/pin"+t+"/"+i+"/toggle.gif?"+Math.random();
           e.title=e.alt=pbcfg[t][stat?'text_on':'text_off'];
           if ( t=='lsp' ){
               SpacerFolding(i,stat);
           }
           return(false);
           ;;
     }

     // nicht angemeldeter benutzer

     var pd = {};
     var cd = readCookie('PINS');
     if ( cd ) var pd = JSON.parse(cd);     

     if ( !pd ) pd = {};
     if ( !pd[t] ) pd[t] = {}

     if ( pd[t][i] ) {
        pd[t][i] = 0;
     } else {
        if ( pd.length>250 ) window.alert('Mehr Einträge können Sie nur mit Anmeldung merken!');
        else pd[t][i] = 1;
     }

     var z = {};
     for( j in pd[t] ) if ( pd[t][j] ) z[j]=1;
     pd[t] = z;
     
     createCookie('PINS', JSON.stringify(pd), 90);
     pinsetflag(t,i,pd[t][i]);
     
     if ( t=='lsp' ) SpacerFolding( i, pd[t][i] );
}





function SpacerFolding( name, stat ) {
     var spans = document.getElementsByTagName('span');
     var cname = "";
     var found = 0;
     if ( spans ) 
         for( var j=0; j<spans.length; j++ ) 
             if ( cname = spans[j].className )
                 if ( cname.substr(cname.length-name.length)==name ) {
                     spans[j].style.display = ( stat ? "none" : "" );
                     found++;
                 }
     if ( !stat && !found ) document.location.href = document.location.href;
}


function checktedform( f ) {
    if ( parseInt(get_var(f,"TEDNR"))>=0 ) return(true);
    window.alert("Sie müssen eine Ted-Auswahl treffen!");
    return(false);
}




function opbasket(f) {
   var j; var S='win'; 
   for(j=0;j<10;j++) S += String.fromCharCode(97+Math.floor(26*Math.random()));
   opener.name=S; f.target=S; f.submit();
   opener.focus(); window.setTimeout("window.focus();",10000);
   return(false);
}


var to = "";              // timeout-handler
var vlist = new Array();  // current menu

// MenuDivs: Layer aufpoppen lassen
function cmsMenu( level, mdiv, lpix, expire ) {
   var ppos;
   if ( to ) window.clearTimeout(to);      // timeout loeschen

   if ( vlist[level]!=mdiv ) for(var i=level; i<=vlist.length; i++) 
      if ( vlist[i]) vlist[i] = cms_setDiv(vlist[i]);

   if ( mdiv ) {
      if ( lpix ) ppos = cms_getImagePos( lpix ); // position ermitteln
      else        ppos = [ 0, 0];  // sonst array generiren
      vlist[level] = cms_setDiv(mdiv,1,ppos[0],ppos[1]);
   }
   if ( expire ) 
       to=window.setTimeout("cmsMenu(0)",1000*expire);
   return(false);
}

// MenuDivs: Layer positioniern und ein- oder ausschalten
function cms_setDiv( name, show, xpos, ypos ) {
   var el_ = null, vis = null;
   if ( !name ) return("");
   if ( document.getElementById ) {
      el_ = document.getElementById(name);
			// Solche Referenzen mag Firefox nicht.
			// Da wird zwar in dem Style-Objekt ein Wert geändert,
			// der bezieht sich dann aber nicht auf das Ursprungsobjekt
      //if ( el_ ) el_ = el_.style;
      vis = ( show ? "visible" : "hidden" );
   } else if ( document.all ) {
      el_ = document.all[name];
      vis = ( show ? "visible" : "hidden" );
   } else if ( document.layers ) {
      el_ = document.layers[name];
      vis = ( show ? "SHOW"    : "HIDE"   );
   }
   if ( !el_ ) return(false);
   if ( xpos || ypos ) {
       if ( adjust.length ) { xpos += adjust[0]; ypos += adjust[1]; }
       el_.style.top=ypos+'px'; el_.style.left=xpos+'px';
			 // Wenn schon Style-Werte ändern, dann korekkt ;-)
   }
   el_.style.visibility = vis;
   return( show ? name : "" ); // rückgabewert
}


// MenuDivs: x/y Position des Positions-Pixels ermitteln
function cms_getImagePos( pimg ) {
   var xpos = ypos = 0;
   var el_ = document.getElementById(pimg);

   if ( document.getElementById ) { // if ( IE4 )
      if ( !el_ ) return( [0,0] );
      // MAC-Erweiterung fuer IE   20020229 dm
//      if ((navigator.userAgent.indexOf("Mac") > -1) && ( navigator.userAgent.indexOf("IE") > -1 )) {
//         xpos = el_.offsetLeft + el_.offsetWidth + 1;
//         ypos = el_.offsetTop  - el_.offsetHeight + 18;
//      } else {
         xpos = el_.offsetLeft + el_.offsetWidth;
         ypos = el_.offsetTop;
         while( (el_ = el_.offsetParent) != null ) {
             xpos += el_.offsetLeft;
             ypos += el_.offsetTop;
         }
//      }
   } else if ( document.layers ) {
      for( var i=0; !el_ && i<document.layers.length; i++)
          if ( (el_=document.layers[i].document[pimg]) ) {
             xpos = document.layers[i].x + 2;
             ypos = document.layers[i].y;
          }
      xpos += el_.x;
      ypos += el_.y;
   } else if ( document.all ) {
      if ( !el_ ) return( [0,0] );
      xpos = el_.offsetLeft + el_.offsetWidth;
      ypos = el_.offsetTop;
   } else window.alert("Huh! What browser are you using ?");
   // Werte in Array zurückliefern
   return ([xpos,ypos]);
}

function old_notframe( url ) {

   var frameurls = [ '/frametest/',
                     '/chat/',
		     '/ratgeber/finanzen/'
		   ];

   url = url.replace(/^http:\/\/[^\/]+/,''); // host wegschneiden
   url = url.replace(/\?.*/,''); // parameter wegschneiden
   for(i=0; i<frameurls.length; i++)
       if ( url.substr(0,frameurls[i].length)==frameurls[i] ) return(0);
   return(1);
}

// Login: Challenge-Response-Authentifikation ausfuehren
function cmslogin(f) {
  // passwort muss in klartext uebertragen werden! (umstellung auf sha1 etc.)

  //str = f.elements['username'].value+":"+MD5(f.elements['password'].value)+":"+f.elements['challenge'].value;
  str = f.elements['username'].value+":"+f.elements['password'].value+":"+f.elements['challenge'].value;
  if ( f.elements['username'].value.length && f.elements['password'].value.length ){
     //f.elements['response'].value = MD5(str);
     f.elements['response'].value = str;
     //f.elements['password'].value = "";
     if ( document.cookie.indexOf('fCMS')>-1 ) return(f.submit());
     window.alert('Für diese Funktion müssen Sie Cookies \nauf Ihrem Rechner zulassen!');
  }
  return(false);
}

var warr = [];
// neues Fenster oeffnen, nur wenn noch nicht geoeffnet
function cmswin( name, url, w, h ) {
	if ( warr.length && warr[name] ) {
		mw=warr[name];
	} else {
		mw=window.open(url,name,'width='+w+',height='+h+',scrollbars=yes,resizable=yes,dependent=yes,top=10,left=10');
	}
	
	if ( !mw || mw.closed ) {
		return(false);
	}
	mw.resizeTo(w,h); 
	mw.focus(0); 
	warr[name]=mw;
}


// checkbox und radiobutton: Funktion fuer Textlinks
function tlink( name,id ) {
   for( var f=0; f<document.forms.length; f++ )
     for( var i=0; i<document.forms[f].elements.length; i++) {
       var e = document.forms[f].elements[i];
       if ( e.name && e.name.substr(0,name.length)==name ) 
           switch( e.type ) {
              case 'checkbox' : e.click(); // e.checked^=1;
                                break;
              case 'radio'    : if ( e.value=="OPT-"+id ) e.click();
                                if ( e.value==id ) e.click();
                                break;
           }
     }
     return(false);
}
                                                                                         

// Sitemap: Funktion um einzelnen Knoten zu toggeln
function toggle( vn, i ) {
   var opt = document.forms[0].elements[vn].value;
   var opl = opt.length ? opt.split(",") : new Array();
   var opo = new Array();
   for( var j=0; j<opl.length; j++) if ( opl[j]!=i ) opo[opo.length]=opl[j];
   if ( opo.length==opl.length ) opo[opo.length]=i;
   opt = opo.join(",");
   document.forms[0].elements[vn].value=opt;
   document.forms[0].submit();
   return(false);
}

// Sitemap: Neue URL im Hauptfenster laden
function opgoto( url ) {
   window.opener.location.href=url;
   return(false);
}

// CMS: Cache für aktuelle Seite deaktivieren
function unlock() {
     var url = document.location.href;
     url = url.replace(/#.*/,'');
     url = url + (url.indexOf('?')>-1 ? "&" : "?") + '_UNLOCK=9da76f9786df5ef6';
     document.location.href=url;
}



// einige Macromedia Funktionen
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function printwin(pwi, phe) {
     var url = document.location.href;
     url = url.replace(/#.*/,'');

     if(!pwi) pwi=640;
     if(!phe) phe=480;

     url = url + (url.indexOf('?')>-1 ? "&" : "?") + '_FRAME=33&_FORMAT=PRINT';
     var pw = window.open(url,'PRINTWIN','width='+pwi+',height='+phe+',scrollbars=1');
     // auskommentiert von fido, 26.05.05 - beisst sich mit printfoot.tpl
     // while ( ! pw.document );
     // while ( ! pw.document.body );
     // pw.document.body.onload=pw.print;
     // pw.setTimeout('window.close()',30000);
}

// Positionsmodifikator für cmsMenu
var adjust = [ 0, -2 ];  // menu-divs ggf. 2 pixel nach oben verschieben


function cmshelp(sub) {
    cmswin('hilfe','/_/tools/hilfe.html?'+sub,250,100);
    return(false);
}

function notframe( url ) {

   var frameurls = [ '/szene/terminesaar/',
                     '/chat/',
                     '/solarchiv/',
		     '/gesund/med_katalog/',	
                     '/szimnetz/sz-archiv/',
                     '/zugang/service/',
                     '/together/chat/mainchat/'];

   url = url.replace(/^http:\/\/[^\/]+/,''); // host wegschneiden
   url = url.replace(/\?.*/,''); // parameter wegschneiden

   for(i=0; i<frameurls.length; i++)
       if ( url.substr(0,frameurls[i].length)==frameurls[i] ) return(0);
   return(1);
}

function get_form(f) {
  if ( !document.forms || !document.forms.length ) return(false);
  if ( document.forms[f] ) return(document.forms[f]);
  return( f.elements ? f : false );
}

function get_element(f,i) {
  if ( f && !i ) { i=f; f=0; }
  var frm = get_form(f);
  if ( !frm || !frm.elements || !frm.elements[i] ) return(false);
  return(frm.elements[i]);
}

function get_var(f,i) {
  if ( f && !i ) { i=f; f=0; }
  var elm = get_element(f,i);
  if ( !elm && !f && i ) elm = i; 
  if ( elm ) {
     var typ = elm.length ? elm[0].type : elm.type;
     switch( typ ) {
         case "checkbox" : return(get_cb(elm)); break;
         case "radio"    : return(get_rdo(elm)); break;
         case "select"   : return(get_sel(elm)); break;
         default         : return(elm.value); break;
     }
  }
  return(false);
}

function set_var(f,i,j) {
  if ( f && !j ) { j=i; i=f; f=0; }
  var elm = get_element(f,i);
  if ( !elm && !f && i ) elm = i;
  if ( elm ) {
      var typ = elm.length ? elm[0].type : elm.type;
      switch( typ ) {
          case "checkbox" : return(set_cb(elm,j)); break;
          case "radio"    : return(set_rdo(elm,j)); break;
          case "select"   : return(set_sel(elm,j)); break;
          default         : elm.value=j; return(true); break;
      }
  }
  return(false);
}

function get_cb( elm ) { return( elm.checked ? elm.value : "" ); }
function get_rdo( elm ) { for(var k=0; k<elm.length; k++) if ( elm[k].checked ) return( elm[k].value ); return(false); }
function get_sel( elm ) { for(var k=0; k<elm.options.length; k++) if ( elm.options[k].selected ) return(elm.options[k].value); return(false); }
function set_cb( elm, j ) { if ( j ) elm.value=j; elm.checked = ( j!="" ); }
function set_rdo( elm, j ) { for(var k=0; k<elm.length; k++) elm[k].checked = (elm[k].value==j); }
function set_sel( elm, j ) { for(var k=0; k<elm.options.length; k++) elm.options[k].selected = (elm.options[k].value==j); }

function vsubmit(f,i,j) {
    set_var(f,i,j);
    document.forms[f].submit();
}


var state = 'none';
function toggle_divs ( layer_ref ) {
    if (state == 'block')    state = 'none';
    else    state = 'block';

    //IS IE 4 or 5 (or 6 beta)
    if (document.all)    eval( "document.all." + layer_ref + ".style.display = state");

    //IS NETSCAPE 4 or below
    if (document.layers)    document.layers[layer_ref].display = state;

    if (document.getElementById && !document.all) {
        maxwell_smart = document.getElementById(layer_ref);
        maxwell_smart.style.display = state;
    }
}


function bb_insert(feld, firsttag, lasttag, offset, op) {
    feld.focus();
    if (document.getSelection) { //FF, NS
        start = feld.selectionStart;
        end = feld.selectionEnd;
        text = feld.value.substring(start, end);
        feld.value = feld.value.substring(0, start) + firsttag + text + lasttag + feld.value.substring(end);
        if (text.length > 0) {
            if (offset != 0) {
                feld.selectionStart = start + firsttag.length + text.length - offset;
            } else {
                feld.selectionStart = start + firsttag.length + text.length + lasttag.length;
            }
        } else {
            feld.selectionStart = start + firsttag.length;
        }
        feld.selectionEnd = feld.selectionStart;
     }
     else if (op && opener.document.selection) {
         position = opener.document.selection.createRange();
         text = position.text;
         position.text = firsttag+text+lasttag;
         position = opener.document.selection.createRange();
         if (text.length > 0) {
             if (offset != 0) {
                 position.move('character', firsttag.length + text.length - offset);
             } else {
                 position.move('character', firsttag.length + text.length + lasttag.length + offset);
             }
         } else {
             position.move('character', -(lasttag.length));
         }
         position.select();     
     } else if (document.selection) { //IE
         position = document.selection.createRange();
         text = position.text;
         position.text = firsttag+text+lasttag;
         position = document.selection.createRange();
         if (text.length > 0) {
             if (offset != 0) {
                 position.move('character', firsttag.length + text.length - offset);
             } else {
                 position.move('character', firsttag.length + text.length + lasttag.length + offset);
             }
         } else {
             position.move('character', -(lasttag.length));
         }
         position.select();
     }
}


function fcms_toggle(frm, name, tostat) {
    var i,e;
    frmobj = document.getElementById(frm);

    for(i=0; i<frmobj.elements.length; i++) {
        e = frmobj.elements[i];
        if (e.type == 'checkbox' && e.name.substr(0, name.length) == name)
            e.checked = tostat;
    }
}



function fcms_class_change(type, id, aktid, all, classakt, classpas, objects) {
    var fcms_ids     = all.split(",");
    var fcms_objects = objects.split(",");
    for(i=0; i < fcms_ids.length; i++) {
        if (aktid == id+"-"+fcms_ids[i]) {
            for (k=0; k < fcms_objects.length; k++) {
                document.getElementById(type+id+"-"+fcms_ids[i]+"-"+fcms_objects[k]).className = classakt;
            }
        }
        else {
            for (k=0; k < fcms_objects.length; k++) {
                document.getElementById(type+id+"-"+fcms_ids[i]+"-"+fcms_objects[k]).className = classpas;
            }
        }
    }
}

function OpenerLink(url) {

   // opener.hostname in try...catch abfangen und bei gleichlautender Domain correct "werfen"
   // bei gleichlautender Domain darf ein opener.location.href gesetzt werden, sonst muss location.href verwendet werden

   try {
       ohost = opener.location.hostname;
       if (ohost == location.hostname) {
           throw "samedomain";
       }
   } catch (e) {
       if (e != 'samedomain') {
           document.location.href = url;
           return (false);
       }
   }

   if(opener) {
       opener.location.href = url;
       opener.focus();
   }
   else {
      document.location.href = url;
   }
}


// Container tauschen, sofern beide Container existieren.
// param: jeweilige Element-IDs
function toggleIfExist(elemIdOne, elemIdTwo) {
    if (document.getElementById(elemIdOne) && document.getElementById(elemIdTwo)) {
        document.getElementById(elemIdOne).style.display = 'none';
        document.getElementById(elemIdTwo).style.display = 'block';
    }
}

// Container tauschen, wenn der aktive Container existiert (= erster Container)
function multiToggleIfExist(elemIdOne, elemIdTwo, elemIdThree) {

    if (document.getElementById(elemIdOne)) {

        if (document.getElementById(elemIdTwo)) {
            document.getElementById(elemIdTwo).style.display = 'none';
        }

        if (document.getElementById(elemIdThree)) {
            document.getElementById(elemIdThree).style.display = 'none';
        }
        
        document.getElementById(elemIdOne).style.display = '';
    }
}

// Verallgemeinertes multiToogleIfExist fÃ¼r beliebig viele Tab     
function multiToggleIfExistEx() {
    if (arguments.length <= 1 ) {
        return true;
    }

    if ( document.getElementById(arguments[0]) ) {
        for ( var i = 1; i < multiToggleIfExistEx.arguments.length; i++ ) {
            if ( document.getElementById(arguments[i]) ) {
                document.getElementById(arguments[i]).style.display = 'none';
            }
        }

        document.getElementById(arguments[0]).style.display = 'block';
    }

    return true;
}

function toggleKommentarRegisterLogin(activeId, inactiveId) {

    if (document.getElementById(activeId) && document.getElementById(inactiveId)) {
        if (document.getElementById(activeId).className == 'diskussion-login-aktiv') {
            document.getElementById(activeId).className   = 'diskussion-login-inaktiv';
        } else {
            document.getElementById(activeId).className   = 'diskussion-register-inaktiv';
        }

        if (document.getElementById(inactiveId).className == 'diskussion-login-inaktiv') {
            document.getElementById(inactiveId).className = 'diskussion-login-aktiv';
        } else {
            document.getElementById(inactiveId).className = 'diskussion-register-aktiv';
        }
    }
}


