	var http_handler = null ;

	function fetch_object(idname)
	{
		if (document.getElementById)
		{
			return document.getElementById(idname);
		}
		else if (document.all)
		{
			return document.all[idname];
		}
		else if (document.layers)
		{
			return document.layers[idname];
		}
		else
		{
			return null;
		}
	}

	function getHTTPObject() {
		if (!http_handler) {
			try
			{
				handler = new XMLHttpRequest();
				return handler;
			}
			catch(e)
			{
				try
				{
					handler = eval("new A" + "ctiv" + "eX" + "Ob" + "ject('Micr" + "osoft.XM" + "LHTTP');");
					return handler;
				}
				catch(e)
				{
					return false;
				}
			}
		}
	}


	function addToMyCourses(course_id) {
		if (!http_handler) http_handler = getHTTPObject();
		http_handler.open('POST', 'courses_ajax.php', false);
		http_handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_handler.onreadystatechange = contentMyCourses;
		http_handler.send('action=add&course_id=' + course_id);
	}
	
	function removeFromMyCourses(course_id) {
		if (!http_handler) http_handler = getHTTPObject();
		http_handler.open('POST', 'courses_ajax.php', false);
		http_handler.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http_handler.onreadystatechange = contentMyCourses;
		http_handler.send('action=remove&course_id=' + course_id);
	}

	function contentMyCourses() {
		html_my_courses = fetch_object('my_courses');
		if (http_handler.readyState == 4) {
		    if (http_handler.status == 200) {
				html_my_courses.innerHTML = http_handler.responseText;
		    } else {
				html_my_courses.innerHTML = '';
            }
	        http_handler.abort();
        }
	}
