/*
* Layers.jsp
* Expanding / Collapsing of div layers
* AKA Document rewriting
*/
/*
* Method to replace a layers content
* @param div_id id of the div element
* @param ContentInfo contains the html that should be replaced
*/

function showContent(div_id,content_title, content) {
	html_content="<table class='sidebar_content'><tr><td class='sidebarHeader'>"+content_title+"</td><td class='sidebarHeader' align='right'><a href=\"javascript:hideContent('"+div_id+"');\" alt='close'>X</a></td></tr><tr><td colspan='2' class='sidebarBody'>"+content+"</td></tr></table>";
	replaceContent(div_id,html_content);
	makeVisible(div_id);
}
function showContentASync(div_id,content) {
	getApiDoc(div_id, content);
	makeVisible(div_id);
}

function makeVisible(div_id) {

	if (document.all) {
		eval("document.all."+div_id+".style.visibility = 'visible'");
	} else if (document.getElementById)	{
		document.getElementById(div_id).style.visibility = 'visible';
	} else if (document.layers) {
		eval("document."+div_id+".visibility = 'visible'");
	} 

	if (document.all) {
		eval("document.all."+div_id+".style.zIndex = 100");
	} else if (document.getElementById)	{
		document.getElementById(div_id).style.zIndex = 100;
	} else if (document.layers) {
		eval("document."+div_id+".zIndex = 100");
	} 

	if (document.body.scrollTop) {
		if (document.all) {
			eval("document.all."+div_id+".style.top = " + (eval(15) + document.body.scrollTop));
		} else if (document.getElementById)	{
			document.getElementById(div_id).style.top = (eval(15) + document.body.scrollTop);
		} else if (document.layers) {
			eval("document."+div_id+".top = " + (eval(15) + document.body.scrollTop));
		} 
	} else {
		if (document.all) {
			eval("document.all."+div_id+".style.top = 15");
		} else if (document.getElementById)	{
			document.getElementById(div_id).style.top = 15;
		} else if (document.layers) {
			eval("document."+div_id+".top = 15");
		} 
	}
	if (document.all) {
		eval("document.all."+div_id+".style.left = 15");
	} else if (document.getElementById)	{
		document.getElementById(div_id).style.left = 15;
	} else if (document.layers) {
		eval("document."+div_id+".left = 15");
	} 

} 


function hideContent(div_id) {
	replaceContent(div_id,"");
	if (document.all) {
		eval("document.all."+div_id+".style.visibility = 'hidden'");
	} else if (document.getElementById)	{
		document.getElementById(div_id).style.visibility = 'hidden';
	} else if (document.layers) {
		eval("document."+div_id+".visibility = 'hidden'");
	} 
}


var slepenOK = false // flag
var targ;
var x,y;
var xOrig, yOrig; // oude pos onthouden 
	
function InitDrag() {
//	document.onmousedown=new Function("return false"); //disable selecteren van gewone tekst
//	document.onmousemove=new Function("return false");
//  dit verhelpt het probleem van het loslaten van de muisknop BUITEN de boks
//  maar stopt de normale werking van een hyperlink 
	 
//	document.onmouseup=new Function("slepenOK=false");
// capture muisevents down en up voor collectie versleepbare dozen
	var dragboksen = getElementsByTagClass(document,'div','sidebar_float'); // collection versleepbare dozen
	for (var i=0;i<dragboksen.length;i++){
		dragboksen[i].onmousedown = sleep; // als de muisknop ingedrukt wordt op een dragboks
		dragboksen[i].onmouseup = new Function("slepenOK=false"); //als hij losgelaten wordt
	}

}
//*************************************************************
function move(e){
	if (!e) var e = window.event;
	if (slepenOK){
		targ.style.left = xOrig+e.clientX-x // beweeg hor  
		targ.style.top  = yOrig+e.clientY-y  //beweeg ver  
		return false; // nodig? 
	}
}
//*************************************************************
function sleep(e){
	if (!e) var e = window.event;
	 // op welk element wordt er geklikt?
	if (e.target)  targ = e.target;
	else if (e.srcElement)  targ = e.srcElement;
	while (targ.className!="sidebar_float"){
		targ=targ.parentNode
	}

	slepenOK = true
	xOrig = parseInt(targ.style.left+0) //onthou huidige hor positie 
	yOrig = parseInt(targ.style.top+0)//onthou huidige ver positie 
	x = e.clientX // huidige muispos hor 
	y = e.clientY// huidige muispos ver 
	targ.onmousemove = move // registreer muisbeweging, geef door aan Eventhandler 
	return false;

}

function replaceContent(div_id,content){

	if (document.all)	{
		eval("document.all."+div_id+".innerHTML = content");
	} else if (document.getElementById)	{
		document.getElementById(div_id).innerHTML = content;
	} else if (document.layers) {
		with(eval("document."+div_id+".document") )
		{ 
		   open(); 
		   write(content); 
		   close(); 
		}
	}
}

/*
* Gets the current content of the div layer
*/
function getContent(div_id){
		
	if (document.all)	{
		return eval("document.all."+div_id+".innerHTML");
	} else if (document.getElementById)	{
		return document.getElementById(div_id).innerHTML;
	} else if (document.layers) {
// this is a wild guess as I have no clue if the write has a read
		return eval("document."+div_id+".value");

	}
}

/*
* Checks visibility of the layer
*/
function isVisible(div_id) {
	if (document.all) {
		if (eval("document.all."+div_id+".style.visibility == 'visible'"))
			return true;
		else 
			return false;
	} else if (document.getElementById)	{
		if (document.getElementById(div_id).style.visibility == 'visible')
			return true;
		else 
			return false;
	} else if (document.layers) {
		if (eval("document."+div_id+".visibility == 'visible'"))
			return true;
		else 
			return false;
	} 
}		

function showCollaps(imageResources, div_id)
{
	if (document.images)
	{
    	eval("(document.images['item"+div_id+"'].src='"+imageResources+"collapse.gif')");
	}
	else
  	{
    	eval("(document.item"+div_id+".src='"+imageResources+"collapse.gif')");
	}
}

//------------------------------------------------------------------

function showExpand(imageResources, div_id)
{
  if (document.images)
  {
    eval("(document.images['item"+div_id+"'].src='"+imageResources+"expand.gif')");
  }
  else
  {
    eval("(document.item"+div_id+".src='"+imageResources+"expand.gif')");
  }
}


/*
* do the actual expand or collaps of the layer
*/
function doCollapsExpand(div_id, content, imageResources) {
		
	if(!isVisible(div_id)){
// expanding
		if (document.all) {
			eval("document.all."+div_id+".style.visibility = 'visible'");
		} else if (document.getElementById)	{
			document.getElementById(div_id).style.visibility = 'visible';
		} else if (document.layers) {
			eval("document."+div_id+".visibility = 'visible'");
		} 
		showCollaps(imageResources, div_id);
		replaceContent(div_id,content);
	} else {
		if (document.all) 	{
			eval("document.all."+div_id+".style.visibility = 'hidden'");
		} else if (document.getElementById)	{
			document.getElementById(div_id).style.visibility = 'hidden';
		} else if (document.layers) {
			eval("document."+div_id+".visibility = 'hidden'");
		}
		content = getContent(div_id);
		showExpand(imageResources, div_id);
		replaceContent(div_id," " );
	}
	return content;
}

function getElementsByTagClass(container, tagName, className){
    if (document.getElementsByTagName){
	
    	var returnedCollection = new Array();
		var collection;
		if (arguments.length!=3){
			throw new Error ("functie verwacht 3 argumenten");
			return;
	     	} else {
			collection  = container.getElementsByTagName(tagName);	
		}
		
    	for(var i=0;i< collection.length; i++){
		//className is officieel DOM HTML
        	if(collection[i].className == className)
            		returnedCollection[returnedCollection.length] = collection[i];
		}
   		return returnedCollection;
	}
	alert('uw browser kan dit script niet aan');
}
