/**
 *  Author: Wagner Paul
 *  CreationDate: 07.08.08
 *  Revision 1: 21.08.08
 *  - updated createRequestObject (http://bytes.com/forum/thread719447.html) 
 *
 **/

/*******************************************************************************
 * Global variables
 ******************************************************************************/
var http = createRequestObject();

/*******************************************************************************
 *  Div overlay functions
 ******************************************************************************/

function toggleVis(PUNKT)
{
    if (document.getElementById(PUNKT).style.display=="none") {
        document.getElementById(PUNKT).style.display="block";
    } else {
        document.getElementById(PUNKT).style.display="none";
    }
}

function showVis(PUNKT,WIDTH,HEIGHT) 
{
    document.getElementById(PUNKT).style.display="block";
    document.getElementById(PUNKT).height=HEIGHT;
    document.getElementById(PUNKT).width=WIDTH;
}

function showVis(PUNKT) 
{
    document.getElementById(PUNKT).style.display="block";
}

function hideVis(PUNKT) 
{
  document.getElementById(PUNKT).style.display="none";
}

/*******************************************************************************
 *  Ususal Ajax functions
 ******************************************************************************/
function createRequestObject() 
{
  var xmlHttp=null;
  try
  {
  // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
  }
  return xmlHttp;
}





// sndReq without Post
function sndReq(HOSTANDQUERY) 
{
  sndReq(HOSTANDQUERY,null);
}

// sndReq with Post
function sndReq(HOSTANDQUERY,POST) 
{
    http.open('GET', HOSTANDQUERY,false);
   // http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    //http.onreadystatechange = function() { handleResponse()};
    http.send(POST);
    /*while (http.readyState != 4) {
      document.getElementById("innerContentDiv").innerHTML = http.responseText;
    }*/
    return http.responseText;
}

function handleResponse() 
{
    document.getElementById("innerContentDiv").innerHTML = http.readyState;
    if (http.readyState == 4) {
        document.getElementById("innerContentDiv").innerHTML = http.responseText;
    }
}

function getResponse()
{
    return http.responseText;
}

/*******************************************************************************
 *  Text functions
 ******************************************************************************/

function trim(s) 
{
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

/*******************************************************************************
 *  DIV-Sliding functions and vars
 *  http://www.dhtmlgoodies.com/index.html?whichScript=show_hide_content_slide
 ******************************************************************************/

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;

function showHideContent(e,inputId)
{
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;

	if(!answerDiv.style.display || answerDiv.style.display=='none'){
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
		}else{

			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';

			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}
}

function slideContent(inputId,direction)
{

	var obj =document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none';
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}

function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='dhtmlgoodies_question'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px';
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			answer.style.display='none';
			answer.style.height='1px';
			divCounter++;
		}
	}
}

//window.onload = initShowHideDivs;
