// DESCRIPTION:
// load options of a selectfield dynamic with ajax
// PARAMETER:
// - scriptUrl: url to the php script that loads the options from the DB incl GET Parameters!
//              this.options[selectedIndex].value contains the selected value.
// - selectId: HTML ID of the select field where the options should be written in
// USE:
// call the function onchange in the selectbox
// EXAMPLE:
// onchange="ajaxLoadOptions('url.php?pid='+this.options[selectedIndex].value,'selectid')"


function ajaxLoadOptions (scriptUrl,selectId) {
	try { 
		req = new XMLHttpRequest(); 
	}
	catch (ms) {		
		try { 
			req = new ActiveXObject("Msxml2.XMLHTTP"); 
		}
		catch (nonms) {			
			try { 
				req = new ActiveXObject("Microsoft.XMLHTTP"); 
			}
			catch (failed) { 
				alert("Error creating request object!"); 
			}
		}  
	}
	req.open("GET",scriptUrl,true);
	req.onreadystatechange = function() {            
		switch(req.readyState) {
			case 4:
				if(req.status!=200) { 
					alert("Error "+req.status+": Select option could not be fetched. Please press (F5)."); 
				}
				else {
					document.getElementById(selectId).innerHTML = req.responseText;
				}
				break;
		  
			default:
				return false;
			break;     
		}
	};
	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	req.send(null);
}
