// JavaScript Document
/*
Algemeen bruikbare functies voor de Javascript DOM test

*/



//********************************************************************

function getElementsWithClass(containingEl, tagName, className){    
    var returnedCollection = new Array(0);
	// voor oude IE versies
    var collection  = (containingEl.all && tagName == "*") ? containingEl.all : containingEl.getElementsByTagName(tagName);
    for(var i = 0; i < collection.length; i++)
        if(collection[i].className == className)
            returnedCollection[returnedCollection.length] = collection[i];
    return returnedCollection;
}


//*********************************************************************
/* maakElement
returned een ElementNode met veel attributen en styles

	type = soort tag (string)
	position = absolute/relative/fixed of niks
	posTop = style top position (int)
	posLeft = style left position (int)
	klasse = class attrib (string)
	id = id attrib(string)
	tekstInhoud = tekstuele inhoud geen childNode(string) 
	url = a tag wordt erin aangemaakt: url(string); indien aanwezig wordt de tekstInhoud in de a tag geplaatst
	zichtbaar = style visibility(boolean)
	tonen = style display (string): mogelijke opties zijn 'none', 'block', 'inline', etc..

te gebruiken als:
	var ssdiv = new MaakElement("div", posBoven , posLinks,"submenu",idee, label, uerel, false);
	sdiv.appendChild(ssdiv);
	
function maakElement(type,positie,posTop, posLeft, klasse, id, tekstInhoud, url, zichtbaar)
*/	
/* OPMERKINGEN: 
		- indien je nieuw argumenten toevoegt, doe het dan achteraan
		- event handlers kunnen beter via registratie aan een nieuw el gekoppeld worden, IE problemen met setAttribute
*/
function maakElement(type, positie, posTop, posLeft, klasse, id, tekstInhoud, url, zichtbaar, tonen){

	if(document.createElement){
		var o = document.createElement(type);
	// anker of niet inside
		if (url!=''){
		// een a element wordt 
			var a =  document.createElement("a") // maak een hyperlink
			a.setAttribute("href",url) //stel het attrib href in op
			a.appendChild(document.createTextNode(tekstInhoud)) //voeg textnode toe aan link
			o.appendChild(a)
		}
		else
		{
			o.appendChild(document.createTextNode(tekstInhoud)) ;
		}
		
		// class en id attributen
		if (id!=''){o.setAttribute('id',id)}
		if (klasse!=''){o.className = klasse }
		
		// inline style attributen
		if (positie!=''){
			o.style.position = positie;
			if (posTop!=''){o.style.top = posTop}
			if (posLeft!=''){o.style.left = posLeft}
		}
		// visibility als inline style
		if (zichtbaar!=''){ // indien leeg geen vis style instellen
			if (zichtbaar==false){o.style.visibility = 'hidden'}
			else if (zichtbaar==true){o.style.visibility = 'visible'} 
		}
		// display als inline style, geen foutcontrole
		if (tonen!=''){
			o.style.display = tonen;
		}
		
	//return object
		return o;
	}
	else{
		return Null;
	}
}

//*****************************************************************************

function getCookie(naam){

var zoek=naam+"=";
	if (document.cookie.length>0)
	{
		var start = document.cookie.indexOf(zoek);
		if (start!= -1){
		start+=zoek.length;
		var einde = document.cookie.indexOf(";",start);
			if(einde==-1){
			einde=document.cookie.length;
			}
			return unescape(document.cookie.substring(start,einde));
		}
	}
}
//--------------------------------------------------------------

function vernietigCookie(naam){
//vernietigt een cookie door de expiration date achterwege te laten
		if (getCookie(naam)){
			document.cookie= naam + '=' + ';expires=Thu, 01-Jan-70 00:00:01 GMT';
		}
}

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

function bevestigVerwijder(url){
//vraagt bevestigign voor het verwijderen van een cursist
var antwoord=confirm('zeker om deze record te verwijderen?');

if(antwoord){location.href=url}
		
}

/**
*
* Javascript trim, ltrim, rtrim
* http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
