﻿function createDropDown(x, selParentItem, child) {
	child.innerHTML = "";
	
	document.getElementById("displayPanel").innerHTML = "<div style='text-align:center; width:100%'><img src='gfx/spacer.gif' id='home_thumb' name='home_thumb' /></div><p id='caption' ></p><a href='' id='link' style='' ></a>";

	for(i=0; i<=x.length-1; i++){
		if(x[i].childNodes.length != 0){
			xAtt = x[i].getAttribute("name");
			x2Att = x[i].getAttribute("abbr");

			//if the series attribute matches the selected series									
			if(xAtt == selParentItem){
				//loop through collection of child nodes

				for(j=0; j<= x[i].childNodes.length-1; j++){
					if(x[i].childNodes[j].nodeType != "3"){
						//For Internet Explorer
						if(x[i].childNodes[j].text != null){
							if(x[i].childNodes[j].nodeName == "img"){
								document.getElementById("home_thumb").src = x[i].childNodes[j].text;
								}
							else if(x[i].childNodes[j].nodeName =="caption"){
								document.getElementById("caption").innerHTML = x[i].childNodes[j].text;
								}
							else if(x[i].childNodes[j].nodeName =="link"){
								document.getElementById("link").href = ""+ x[i].childNodes[j].text + "";
								document.getElementById("link").innerHTML = xAtt ;
								}
							else{
								model = x[i].childNodes[j].text;
								document.getElementById("childMenu").options[j] = new Option(model, model);
								}
							}

							
						else{
							if(x[i].childNodes[j].nodeName == "img"){
								document.getElementById("home_thumb").src = x[i].childNodes[j].textContent;
								}
							else if(x[i].childNodes[j].nodeName =="caption"){
								document.getElementById("caption").innerHTML = "<p id='caption'>"+ x[i].childNodes[j].textContent + "</p>";
								}
							else if(x[i].childNodes[j].nodeName =="link"){
								document.getElementById("link").href = ""+ x[i].childNodes[j].textContent + "";
								document.getElementById("link").innerHTML = xAtt ;
								}
							else{
								model = x[i].childNodes[j].textContent;
								child.innerHTML += "<option name='"+x2Att+ "_"  +model+"' id='"+x2Att+ "_"  +model+"' title='"+model+"' value='"+ model +"'>" + model + "</option>";
								}
							}
					}
				}
			}
		}
	}
}







//Create XHR Request and Return Result
function ajaxRequest(){
	var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP" ];	//activeX versions to check for in IE
		if (window.ActiveXObject){ 		//Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
			for (var i=0; i<activexmodes.length; i++){
				try{
					return new ActiveXObject(activexmodes[i]);
					}
					catch(e){
					//suppress error
					}
				}
			}

		else if (window.XMLHttpRequest){
			return new XMLHttpRequest();
			}
		else
			return false;
	}


//Loading XML File:  This is called by the event handler
//This function calls the creation of the AJAX XHR.
function loadXmlDoc(xmlFile, parent, child){
	parent = document.getElementById(parent);
	child = document.getElementById(child);
	
	var selIndex = parent.selectedIndex;
	var selParentItem = parent.options[selIndex].value;

	xmlDoc=new ajaxRequest()
    xmlDoc.onreadystatechange=function(){
	    if (xmlDoc.readyState==4){
	    	if (xmlDoc.status==200){
	    		var dom = xmlDoc.responseXML;
	    		if(dom.documentElement.nodeName == "parsererror"){	}
	    		else{
	    			var root = dom.documentElement;
	    			if(root.hasChildNodes){
						parentMenuList = root.childNodes;
						createDropDown(parentMenuList, selParentItem, child);
						}
					else{	}
	           		}
	        }
	
	   		else{	}
	
	   	}
	        	
	   	else{	}
		}

	xmlDoc.open("GET", xmlFile, true)
	xmlDoc.send(null)
}