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();
}

function delCookie(_cookieName){
  setCookie(_cookieName,'undefined','-1');
}

function resetAllCookie(){
  thisCookie = document.cookie.split("; ")
  for (i=0; i<thisCookie.length; i++){
    _cookieName = thisCookie[i].split("=")[0];
    delCookie(_cookieName);
  }
}

function getCookie(_cookieName){
  thisCookie = document.cookie.split("; ")
  for (i=0; i<thisCookie.length; i++) {
    if (_cookieName == thisCookie[i].split("=")[0]) {
      _cookieValue=thisCookie[i].split("=")[1];
      return unescape(_cookieValue);
    }
  }
  return;
}

function closeSubmenu(){
  if(document.cookie.indexOf("xsC")>-1){
    return document.write('<a class="backnav_link" href="javascript:resetAllCookie();document.location.reload();">close Submenue</a>');
  }
}

function writeTd(_height){
  if(_height!=''){
    if(_height!=0){
      return document.write('<td height="'+_height+'" width="19" align="center" style="cursor:default;">&nbsp;</td>');
    }else{
      return document.write('<td height="'+_height+'" width="19"></td>');
    }
  }else{
    return document.write('<td height="20" width="18" align="center" style="cursor:default;">&nbsp;</td>');
  }
}

function writeTdJs(_par_id,_this_id){
  _return='';
  _return+=document.write('<td height="20" width="18" align="center" style="cursor:hand;"><a href="javascript:subMenu('+_par_id+','+_this_id+');">');
  if(document.cookie.indexOf("xsC-"+_this_id)>-1){
    _return+=document.write('<img id="'+_par_id+'-'+_this_id+'" src="images/system/icon_less.gif" border="0">');
  }else{
    _return+=document.write('<img id="'+_par_id+'-'+_this_id+'" src="images/system/icon_more.gif" border="0">');
  }
  _return+=document.write('</a></td>');
  return _return
}

function onloadHideSub(){
  elm_array = document.getElementsByTagName("tr");
  for(var i=0; i<elm_array.length; i++) {
    if(elm_array[i].id.indexOf("sub_")>-1 ||elm_array[i].id.indexOf("nos_")>-1 || elm_array[i].id.indexOf("line_")>-1 ){
      _begin=elm_array[i].id.split('-')[0];
      _end=elm_array[i].id.split('-')[1];
      _par_id=_begin.split('_')[1];
      _this_id=_end.split('_')[0];
      if(   _par_id!=0
         && getCookie('xsC-'+_par_id+'-'+_this_id)!='visible'
         ){
        document.getElementById(elm_array[i].id).style.display='none';
      }
    }
  }
}

function subMenu(_par_id,_this_id,_action){
  if(document.getElementById(_par_id +'-' +_this_id)){
    _this_src=document.getElementById(_par_id +'-' +_this_id).src;
    if(_action!='close' && _this_src.indexOf("icon_more.gif")>-1){
      document.getElementById(_par_id +'-' +_this_id).src="images/system/icon_less.gif";
    }else if(_this_src.indexOf("icon_less.gif")>-1){
      document.getElementById(_par_id +'-' +_this_id).src="images/system/icon_more.gif";
    }
  }
  elm_array = document.getElementsByTagName("tr");
  for(var i=0; i<elm_array.length; i++) {
    if(elm_array[i].id.indexOf("sub_")>-1 ||elm_array[i].id.indexOf("nos_")>-1 ||elm_array[i].id.indexOf("line_")>-1){
      if(elm_array[i].id.indexOf('_'+_this_id)>-1){
        _begin=elm_array[i].id.split('-')[0];
        _end=elm_array[i].id.split('-')[1];
        _new_par_id=_begin.split('_')[1];
        _new_this_id=_end.split('_')[0];
        if(_action!='close' && document.getElementById(elm_array[i].id).style.display=='none'){
          //anzeigen
          document.getElementById(elm_array[i].id).style.display='';
          setCookie('xsC-'+_new_par_id+'-'+_new_this_id,'visible');
        }else{
          //verstecken
          document.getElementById(elm_array[i].id).style.display='none';
          delCookie('xsC-'+_new_par_id+'-'+_new_this_id);
          subMenu(_new_par_id,_new_this_id,'close');
        }
      }
    }
  }
}

