var opt; /* stores the option for the ajax request */
var current_url;

function request404(t) {
	alert("Error 404: Location was not found.");
}

function requestFailure(t) {
	alert('Error ' + t.status + ' -- ' + t.statusText);
}

/* Sets the options for the ajax request */
function setOpt(queryString) {
	opt = {
    // Use POST
    method: 'post',
    // Send this lovely data
    postBody:queryString,
    // Handle successful response
    onSuccess:updateSuccess,
    // Handle 404
    on404:request404,
    // Handle other errors
    onFailure:requestFailure,
    // set asynchronous
    asynchronous:true
    };  
}

function loading_animation(mode) {
	var elem = document.getElementById('loading');
	if (mode == 'on') {
		elem.style.visibility = "visible";
	} else {
		elem.style.visibility = "hidden";
	}
}

/* Call back function used for sucessful ajax request */
function updateSuccess(t) {
	var response = t.responseText;
	// set div to the new panel
	//loading_animation('off');
	document.getElementById('dyn-panel').innerHTML = response;
}

function all_black() {
	document.getElementById('tab1').style.color = "#000";
	document.getElementById('tab2').style.color = "#000";
	document.getElementById('tab3').style.color = "#000";
	document.getElementById('tab4').style.color = "#000";
	document.getElementById('tab5').style.color = "#000";

}

/* Makes ajax request */
function switch_panel(page,id){
	all_black();
	document.getElementById(id).style.color = "#990000";
	if(page != current_url){
		setOpt("");
		//loading_animation('on');
		new Ajax.Request('include/' + page, opt);
	}
	current_url = page;
}
