
function socList(usedOccId, usedSocId, occId){



	var cluster = document.getElementById(usedOccId).value;
	document.getElementById(usedSocId).innerHTML = "&nbsp;";
	document.getElementById(occId).innerHTML = "&nbsp;";
	
	if(cluster == '00') {	
		return false;
	} else
		ajaxTrcSocCodeFunction(cluster, usedSocId, occId);

		
	return false;
}

function ajaxTrcSocCodeFunction(clusterCode, usedSocId, occId) {

	 var xmlhttp = new getXMLObject();
	 if(xmlhttp) { 
		xmlhttp.onreadystatechange  = function() { showSocInfo(xmlhttp, usedSocId, occId) };
		xmlhttp.open("GET","/iut/trcDataList?cl=" + clusterCode, true); //gettime will be the servlet name
	    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	    xmlhttp.send(null);
	  }

}


function showSocInfo(request, usedSocId, occId) {

	
 
 
	if ((request.readyState == 4) && (request.status == 200)) {
		var xmlDocument = request.responseXML;
		var errors = getXmlValues(xmlDocument, "errors");	
		var soclist = xmlDocument.getElementsByTagName("item");
		var rows = new Array(soclist.length);
		var subElementNames = ["itemcode", "itemtitle"];

		for(var i=0; i<soclist.length; i++) {
			rows[i] = 	getElementValues(soclist[i], subElementNames);
		}				
		createSelectElement(rows, usedSocId, occId);
	}
	
	
}


function createSelectElement( rows, usedSocId, occId) {


	

	myselect = document.createElement("select");
	myselect.setAttribute("id","selectID");
	myselect.setAttribute("class","selectnowidth");
	myselect.setAttribute("name","soc");
	myselect.setAttribute("size","1");
	theOption=document.createElement("OPTION");
	theText=document.createTextNode("All Occupations");
	theOption.appendChild(theText);
	theOption.setAttribute("value","");
	
	myselect.appendChild(theOption);

	for(var i=0; i<rows.length; i++) {	
			var row = rows[i];
			theOption=document.createElement("OPTION");
			theText=document.createTextNode(row[1]);
			theOption.appendChild(theText);
			theOption.setAttribute("value",row[0]);
			myselect.appendChild(theOption);
	}

	document.getElementById(occId).innerHTML = "<label for=\"soc\">Occupation (within selected subject category):</label>"; 
	
	document.getElementById(usedSocId).appendChild(myselect); 
	
	return (myselect);  
}



function getElementValues(element, subElementNames) {

	

	  var values = new Array(subElementNames.length);
	  for(var i=0; i<subElementNames.length; i++) {
	    var name = subElementNames[i];
	    var subElement = element.getElementsByTagName(name)[0];
	    values[i] = getBodyContent(subElement);
	  }
	  
	  
		
	  
	return(values);
}

function getBodyContent(element) {



	  element.normalize();
	  return(element.childNodes[0].nodeValue);
	  
	  

}

function getXmlValues(xmlDocument, xmlElementName) {

	

	  var elementArray = 
	     xmlDocument.getElementsByTagName(xmlElementName);
	  var valueArray = new Array();
	  for(var i=0; i<elementArray.length; i++) {
	     valueArray[i] = getBodyContent(elementArray[i]);
	  }
	  
	  

	return(valueArray);
}

function getXMLObject()  //XML OBJECT
{





   var xmlHttp = false;
   try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP")  // For Old Microsoft Browsers
   }
   catch (e) {
     try {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")  // For Microsoft IE 6.0+
     }
     catch (e2) {
       xmlHttp = false   // No Browser accepts the XMLHTTP Object then false
     }
   }
   if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
     xmlHttp = new XMLHttpRequest();        //For Mozilla, Opera Browsers
   }
   
   
   

   
   
   return xmlHttp;  // Mandatory Statement returning the ajax object created
}



