

function gebi( id ) { 					
	return document.getElementById( id );
}

function addOption(selectbox,text,value ) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function selectOption(selectbox, value) {
	//alert('selectbox length: ' + selectbox.options.length );
	for(var i = 0; i < selectbox.options.length; i++ ) { 
		if ( selectbox.options[i].value == value ) {
			selectbox.options[i].selected = true;
		}
		else {
			selectbox.options[i].selected = false;
		}
	}	
}

// give it a bool ( or a reference to a checkbox ), and it will
//    toggle the visibility/display of elements you supply as arguments based 
//		on that bool (or checkbox's value
function toggle( ref ) {
	if ( typeof ref == 'boolean' ) var rc = ref;
	else var rc = ref.checked;
	
	for ( var i = 1, len = arguments.length; i < len; i++ ) {
		var el = (typeof arguments[i] == 'string') ? document.getElementById( arguments[i] ) : arguments[i];
		if ( el && typeof el == 'object' ) {
			el.style.display = ( rc ) ? '' : 'none';
			el.style.visibility = ( rc ) ? 'visible' : 'hidden';
			toggleChildren( el, rc );
		}
	}
	rc = i = len = el = null;
}

// helper function to toggle() above 
function toggleChildren( ref, rc ) {
	var nn = ref.nodeName.toLowerCase();
	if ( nn == 'input' || nn == 'textarea' || nn == 'select' || nn == 'a' || nn == 'button' )
	{
	  ref.style.visibility = (rc) ? 'visible' : 'hidden';
	  ref.style.display = ( rc ) ? '' : 'none';
	}
	if ( ref.childNodes.length < 1 ) return;
	for ( var i = 0, len = ref.childNodes.length; i < len; i++ ) {
		toggleChildren( ref.childNodes[i], rc );
	}
}

function buildAjaxRequest( id ) { 
	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 broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if( id && gebi(id) ) { 
				var ajaxDisplay = document.getElementById( id );
				ajaxDisplay.innerHTML = ajaxRequest.responseText;
			}
		}
	}	
	return ajaxRequest;
}