// JavaScript Document
// Search & FilterScripts
<!--
// global flag
var isIE = false;
var destField;
// global request and XML document objects
var req;

// retrieve XML document (reusable generic function);
// parameter is URL string (relative or complete) to
// an .xml file whose Content-Type is a valid XML
// type, such as text/xml; XML source must be from
// same domain as HTML file
function loadXMLDoc(url) {
    // branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        isIE = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}

// handle onreadystatechange event of req object
function processReqChange() {
    // only if req shows "loaded"
	if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            buildTopicList();
         } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
         }
    }
}

// invoked by "Category" select element change;
// loads chosen XML document, clears Topics select
// element, loads new items into Topics select element
function loadDoc(evt,field) {
    // equalize W3C/IE event models to get event object
	clearTopicList();	
	destField = field
	clearTopicList(1);	
    evt = (evt) ? evt : ((window.event) ? window.event : null);
    if (evt) {
        // equalize W3C/IE models to get event target reference
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            try {
                if (elem.selectedIndex > 0) {
					loadXMLDoc("/nl/categories.asp?view=xml&parents=false&main="+elem.options[elem.selectedIndex].value);	
                }	
            }
            catch(e) {
                var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
                alert("Unable to get XML data:\n" + msg);
                return;
            }
        }
    }
}

// retrieve text of an XML document element, including
// elements using namespaces
function getElementTextNS(prefix, local, parentElem, index) {
    var result = "";
    if (prefix && isIE) {
        // IE/Windows way of handling namespaces
        result = parentElem.getElementsByTagName(prefix + ":" + local)[index];
    } else {
        // the namespace versions of this method 
        // (getElementsByTagNameNS()) operate
        // differently in Safari and Mozilla, but both
        // return value with just local name, provided 
        // there aren't conflicts with non-namespace element
        // names
        result = parentElem.getElementsByTagName(local)[index];
    }
    if (result) {
        // get text, accounting for possible
        // whitespace (carriage return) text nodes 
        if (result.childNodes.length > 1) {
            return result.childNodes[1].nodeValue;
        } else {
            return result.firstChild.nodeValue;    		
        }
    } else {
        return "n/a";
    }
}

// empty Topics select list content
function clearTopicList() {
    var selectbox = document.getElementById("sub");
    while (selectbox.length > 0) {
        selectbox.remove(0);
    }
    opt = document.createElement("option");
    opt.value = 0;
    //opt.appendChild(document.createTextNode("Alles (zoek in hoofdrubriek)"));
	opt.appendChild(document.createTextNode("Subrubriek"));			

    selectbox.appendChild(opt);
}

// empty Topics select list content
function clearTopicList(bMode) {
    var selectbox = document.getElementById("sub");
	setTimeout("void(0)",10);
    opt = document.createElement("option");
    opt.value = 0;
	if (bMode == "1"){
	    opt.appendChild(document.createTextNode("Loading..."));
		while (selectbox.length > 0) {
			try		{
				eval("selectbox.remove(0);");
			}
			catch (err)		{
				//alert(err.description)	
			}
		}
	}
	else{
		try		{
			eval("selectbox.remove(0);");
		}
		catch (err)		{
			//alert(err.description)	
		}
		opt.appendChild(document.createTextNode("Alles (zoek in hoofdrubriek)"));
	}
    selectbox.appendChild(opt);
}

// add item to select element the less
// elegant, but compatible way.
function appendToSelect(select, value, content) {
    var opt;
    opt = document.createElement("option");
    opt.value = value;
    opt.appendChild(content);
    select.appendChild(opt);
}

// fill Topics select list with items from
// the current XML document
function buildTopicList() {
	clearTopicList(0)	
    var select = document.getElementById(destField);
    var items = req.responseXML.getElementsByTagName("category");
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    for (var i = 0; i < items.length; i++) {
        appendToSelect(select,getElementTextNS("", "id", items[i], 0),document.createTextNode(getElementTextNS("", "name", items[i], 0)));
    }
}	

	function outLinks(myURL1,myURL2,myURL3){
		linkTarget="_blank";
		for (var i=0; i<=(document.links.length-1); i++){
			if(document.links[i].href.indexOf(myURL1)>-1){
				isExternal=false;	
			}
			else if(document.links[i].href.indexOf(myURL2)>-1){
				isExternal=false;	
			}				
			else if(document.links[i].href.indexOf(myURL3)>-1){
				isExternal=false;	
			}
			else {
				isExternal=true;	
			}				

			if(isExternal){
				document.links[i].target = linkTarget;
			}
		}
	}

	outLinks(document.domain,"www.ictzorgjaargids.nl");
	
	function addToFavorites() {
		window.external.AddFavorite(location.href, document.title);
	}
	
	function makeCurrentPageStartPage(x) {
		x.style.behavior='url(#default#homepage)';
		x.setHomePage(location.href);
	}

// -->