var question = {
  myConn:      false,
  body:        false,
  target:      false,
  loader:      false,

  init: function( queryId, targetId ){
    if( !document.getElementById ||
        !document.getElementsByTagName ||
        !document.getElementById( targetId ) ) return;
    question.myConn = new XHConn();
    if( !question.myConn ) return;
    question.body    = document.getElementsByTagName( 'body' )[0];
    question.target  = document.getElementById( targetId );
	answer.target 	 = document.getElementById( 'ansbox' );
	if( question.target != '' ){
     	question.target.innerHTML = '';
   	};
	if( answer.target != '' ){
     	answer.target.innerHTML = '';
   	};	
	question.id 	 = queryId;
   	if( question.id != '' ){
     	question.getQuestion( question.id );
   	} else {
     	question.target.innerHTML = '';
   	};
  },
 
 getQuestion: function( id ){
    question.buildLoader();
    var fnWhenDone = function(oXML) {
      question.killLoader();
      question.target.innerHTML = oXML.responseText;
    };
    question.myConn.connect("questions.php", "POST", "id="+id, fnWhenDone);
  },

  buildLoader: function(){
    question.loader = document.createElement( 'div' );
    question.loader.setAttribute( 'id', 'loading' );
    question.loader.style.position   = 'absolute';
    question.loader.style.top        = '50%';
    question.loader.style.left       = '50%';
    question.loader.style.width      = '300px';
    question.loader.style.lineHeight = '100px';
    question.loader.style.margin     = '-50px 0 0 -150px';
    question.loader.style.textAlign  = 'center';
    question.loader.style.border     = '1px solid #c1272d';
    question.loader.style.background = '#fff';
    question.loader.appendChild( document.createTextNode( 'Fragen werden geladen, bitte warten\u2026' ) );
    question.body.appendChild( question.loader );
  },

  killLoader: function(){
    question.body.removeChild( question.loader );
  }


};



var answer = {
  myConn:      false,
  body:        false,
  target:      false,
  loader:      false,

  init: function( queryId, targetId ){
    if( !document.getElementById ||
        !document.getElementsByTagName ||
        !document.getElementById( targetId ) ) return;
    answer.myConn = new XHConn();
    if( !answer.myConn ) return;
    answer.body    = document.getElementsByTagName( 'body' )[0];
    answer.target  = document.getElementById( targetId );
	if( answer.target != '' ){
     	answer.target.innerHTML = '';
   	};

	answer.id 	 = queryId;
   if( answer.id != '' ){
     answer.getAnswer( answer.id );
   } else {
     answer.target.innerHTML = '';
   };
  },
 
 getAnswer: function( id ){
    answer.buildLoader();
    var fnWhenDone = function(oXML) {
      answer.killLoader();
      answer.target.innerHTML = oXML.responseText;
    };
    answer.myConn.connect("answers.php", "POST", "id="+id, fnWhenDone);
  },

  buildLoader: function(){
    answer.loader = document.createElement( 'div' );
    answer.loader.setAttribute( 'id', 'loading' );
    answer.loader.style.position   = 'absolute';
    answer.loader.style.top        = '50%';
    answer.loader.style.left       = '50%';
    answer.loader.style.width      = '300px';
    answer.loader.style.lineHeight = '100px';
    answer.loader.style.margin     = '-50px 0 0 -150px';
    answer.loader.style.textAlign  = 'center';
    answer.loader.style.border     = '1px solid #c1272d';
    answer.loader.style.background = '#fff';
    answer.loader.appendChild( document.createTextNode( 'Antwort wird geladen, bitte warten\u2026' ) );
    answer.body.appendChild( answer.loader );
  },

  killLoader: function(){
    answer.body.removeChild( answer.loader );
  }


};



