// AJAX Function
// This function is used to make an ajax request

function sortPos(a, b){
	if (parseInt(a.getAttribute("position")) == parseInt(b.getAttribute("position"))) {
		return 0;
	} else if (parseInt(a.getAttribute("position")) < parseInt(b.getAttribute("position"))) {
		return 1;
	} else {
		return -1;
	}
}

function ajaxFunction(str, params, where, a_loading, method, special) {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
		  try {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		  catch (e) {
			alert("Your browser does not support AJAX!");
			return false;
		   }
		}
	}
	xmlHttp.onreadystatechange=function()
	{
	  if((xmlHttp.readyState<2) && (a_loading))	{
		openLoadingWindow();
	  }
	  if(xmlHttp.readyState==4)	{
		document.getElementById(where).innerHTML=xmlHttp.responseText;
		switch(special) {
			case "timetable_bar": 
				uu_timetable_nowbar();
				break;
		}
		var cgroups = 1;
		while ((itemselems = getElementsByClassName("ttgroup_"+cgroups)).length > 0) {
			itemselems.sort(sortPos);
			var biggestpos = parseInt(itemselems[0].getAttribute("position"))+1;
			var width = 145/biggestpos;
			for (i=0; i<itemselems.length; i++) {
				itemselems[i].style.width = width+"px";
				itemselems[i].style.left = (width*parseInt(itemselems[i].getAttribute("position")))+"px";
				itemselems[i].style.zIndex = 100*parseInt(itemselems[i].getAttribute("position"));
				
			}
			cgroups++;
		}
		
		closeLoadingWindow();
	  }
	}
	if (method == "get") {
		xmlHttp.open("GET",str+"?"+params,true);
		xmlHttp.send(null);
	} else {
		xmlHttp.open("POST",str,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	}
}

function ajaxParamValue(elem) {
	return elem+"="+document.getElementById(elem).value;
}