/*
 * Copyright (c) 2006 A&B FACE2NET GmbH
 *
 * author JDE
 * version $Revision: 1.7 $
 *
 * additional javascripts for contactform and searchform
 */

var domSupport = (document.getElementById) ? true : false;
var agt = navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var onclicktxt = "javascript: showOrHideFormcontainer('container_moreFieldsets');"
var sendback = false;

function addLoadEvent(func_name) {
  var lastonload = window.onload;
  if (typeof window.onload != 'function')
    { window.onload = func_name; }
  else {  window.onload = function() {
            lastonload(); func_name(); }
    }
}

/**
* diverse functions for setting special attributes to a node.
* @param elem name of node
* @param attr kind of attribute
* @param value attribute value
*/
function set_attr(elem, attr, value) {      var myNode = elem; myNode.setAttribute(attr, value ); }
function set_href(elem, url) {          var myNode = elem; myNode.setAttribute("href",url );  }
function set_title(elem, title) {       var myNode = elem; myNode.setAttribute("title", title ); }

/**
* sets a link into the more-container
*/
function set_Link (){
  if(!domSupport) return false;
  var containerID= 'more';
  var formcontainerID= 'container_moreFieldsets';
  
  var searchForm = document.getElementById('search');
  if(!searchForm) var check_sf = false; else  var check_sf = true;
  
  linkBox = document.getElementById(containerID);
  formBox = document.getElementById(formcontainerID);
  if (!linkBox ||!formBox ) return false;
  else{
     /*define status of formcontainer in case of serverside error handling*/
    if(sendback==false) formBox.style.display="none";
    remove_allchildren( containerID );
    var myLink = showLink(containerID, formcontainerID, formBox, check_sf);
    linkBox.appendChild(myLink);
    myLink.onclick = function () {
        if(formBox.style.display == "none") {
		  //this.setAttribute doesn't work in ie
		  if(ie){document.all.onclickID.className = "up";}
		  else this.setAttribute("class", "up" );
		
      } else {
	     if(ie){document.all.onclickID.className = "down";}
         else this.setAttribute("class", "down" );
		
      }
    }
  }

}

/**
* removes all child notes of a container wit a certain ID
*/
function remove_allchildren( containerID ){
  if (!document.getElementById) return false;
  var myParent  = document.getElementById(containerID);
    var myChildren  = myParent.childNodes;
    var numChildren = myChildren.length;
    for(var i = numChildren-1; i >= 0; i--) {
        var c = myParent.removeChild(myChildren[i]);
    }
}

/**
* removes all child notes of a container with a certain ID
*/
function showLink(containerID, formcontainerID, formBox, check_sf) {
  var url = onclicktxt; 
  if(check_sf) var stxt = 'Erweiterte Suche';
  else var stxt = 'Weitere Empfänger';
  var ltitle = 'Einblenden';

  var myNode = document.createElement("a");
  var myNode_text = document.createTextNode(stxt);
  myNode.appendChild(myNode_text);
  set_title(myNode, ltitle); set_href(myNode, url) ; 
  set_attr(myNode, "id", "onclickID");
  if(sendback==true) set_attr(myNode, "class", "up");
  return myNode;
}

/**
* set the style display: none or display: block to the container with the id formcontainerID
*/
function showOrHideFormcontainer(formcontainerID) {
  formBox = document.getElementById(formcontainerID);
    if(formBox.style.display == "none") formBox.style.display = "block";
    else formBox.style.display = "none";
}

addLoadEvent(set_Link);

