function var_dump(obj) {
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end function var_dump


function getXMLRequest() {
        if (window.XMLHttpRequest) {
                return new XMLHttpRequest();
        }
        else if (window.ActiveXObject) {
                try {
                        return new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                        try {
                                return new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e) { }
                }
        }
}

function setOptions(containerIdToChange, urlForXml) {

        var request = false;

        if (!urlForXml || urlForXml == '') { return; }

        request = getXMLRequest();

        containerToChange = document.getElementById(containerIdToChange);

		// thwart caching
		date = new Date();
		if (urlForXml.indexOf('?') > 0) {
			urlForXml += '&' + date.getTime();
		} else {
		  	urlForXml += '?'  + date.getTime();
		}
		  	
        request.open("GET", urlForXml, true);
        request.onreadystatechange = function() {
                if (request.readyState == 4) {
                        populateSelectOptions(containerToChange, request.responseXML.documentElement);
                }
        }
        request.send(null);
}

function setCustomDropDownDisplay(ids, urlForXml) {

		var request = false;

        if (!urlForXml || urlForXml == '') { return; }

        request = getXMLRequest();

		// thwart caching
		date = new Date();
		if (urlForXml.indexOf('?') > 0) {
			urlForXml += '&' + date.getTime();
		} else {
		  	urlForXml += '?'  + date.getTime();
		}
		  	
        request.open("GET", urlForXml, true);
        request.onreadystatechange = function() {
                if (request.readyState == 4) {
                        enabled = request.responseXML.documentElement.childNodes;

                        for (i=0; i < enabled.length; i++) {
                        	switch (enabled[i].nodeName) {
                        		case "jobtitle":
                        			bool = enabled[i].childNodes[0].nodeValue;
	                        		if (bool == "1") {
	                        			ids['jobtitle'].style.display = 'block';
	                        		} else {
	                        			ids['jobtitle'].style.display = 'none';
	                        		}
	                        		
                        			break;
                        			
                        		case "division":
                        			bool = enabled[i].childNodes[0].nodeValue;
                        			
	                        		if (bool == "1") {
	                        			ids['division'].style.display = 'block';
	                        		} else {
	                        			ids['division'].style.display = 'none';
	                        		}
	                        		
                        			break;
                        			
                        		case "department":
                        			bool = enabled[i].childNodes[0].nodeValue;
                        			
	                        		if (bool == "1") {
	                        			ids['department'].style.display = 'block';
	                        		} else {
	                        			ids['department'].style.display = 'none';
	                        		}
	                        		
                        			break;
                        			
                        		case "gender":	
                        			bool = enabled[i].childNodes[0].nodeValue;
                        			
	                        		if (bool == "1") {
	                        			ids['gender'].style.display = 'block';
	                        		} else {
	                        			ids['gender'].style.display = 'none';
	                        		}
	                        		
                        			break;
                        			
                        		case "ethnicity":
                        			bool = enabled[i].childNodes[0].nodeValue;
                        			
	                        		if (bool == "1") {
	                        			ids['ethnicity'].style.display = 'block';
	                        		} else {
	                        			ids['ethnicity'].style.display = 'none';
	                        		}
	                        		
                        			break;
                        	}
                        }
                }
        }
        request.send(null);
}


function populateSelectOptions(container, xml) {
        // remove all options
        for(i=container.options.length-1;i>=0;i--)
		{
			container.remove(i);
		}
		// Failsafe
        while (container.options.length > 0)
        {
          container.options[container.options.length-1] = null;
        }

		if (xml != null)
		{
	        // Get nodes in root of XML
	        tasks = xml.getElementsByTagName("option");
	
	        for (i=0; i < tasks.length; i++) {
	                var tid = 0;
	                var tname = "";
	                var tdesc = "";
	                for (j=0; j < tasks[i].childNodes.length; j++)
	                {
	                        try {
	                                switch(tasks[i].childNodes[j].nodeName)
	                                {
	                                        case "value":
	                                                tid = tasks[i].childNodes[j].firstChild.nodeValue;
	                                                break;
	                                        case "text":
	                                                tname = tasks[i].childNodes[j].firstChild.nodeValue;
	                                                break;
	                                }
	                        } catch (e) { }
	                }
	
	
	                try {
	                        option = new Option(tname, tid);
	                        container.options[i] = option;
	                }
	                catch (e) {
	                        option = new Option(tname, tid);
	                        container.add(option);
	                }
	        }
	  }
}



