//when modifyfield is modified, targetfield takes the result of phppage?value=modifyfield
function ajaxFunction(modifyfield,targetfield,phppage,thetype,formName){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser is not equipped to view this website. Please use the latest version of Firefox, Safari, or Internet Explorer.");
				return false; 
			}
		}
	}
	
	var ele = document.forms[formName].elements;
	
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			//document.myForm.element_1_select_table_display_name.value = ajaxRequest.responseText; (THIS IS FOR INPUT, THE OTHER IS FOR SELECT)
			//alert(ajaxRequest.responseText);
			if(thetype == "input") {
			   ele[targetfield].value = ajaxRequest.responseText;
			}
			else {
			   //this doesn't work in ie	
			   //ele[targetfield].innerHTML = ajaxRequest.responseText;
			   
			   //ie workaround
			    
				
				//remove all existing options from the dom
				for(i=ele[targetfield].length-1; i>=0; i--)
				{
				 
					ele[targetfield].options[i] = null;
			
				}

				//append the new ones
				
				var responseArray = ajaxRequest.responseText.split('|'); 
				
				for(i=0; i < responseArray.length; i++) {
				
					
				
				}
				
				for(i=0; i < responseArray.length; i+=2)
				{
				 
					
					var newOption = window.document.createElement('OPTION');
					newOption.text = responseArray[i+1];
					newOption.value = responseArray[i];
					ele[targetfield].options.add(newOption);
			
				}
				
				
			   
			}
		}
	}
	//ajaxRequest.open("GET", "/ajax/fieldlist.php?value=" + document.myForm.getElementById(modifyfield).value, true);
	ajaxRequest.open("GET", "" + encodeURI(phppage) + "&value=" + encodeURI(ele[modifyfield].value), true);
	ajaxRequest.send(null); //was null
}
