Index: schedule/Module/calendar.php
===================================================================
--- schedule/Module/calendar.php	(revision 16559)
+++ schedule/Module/calendar.php	(revision 16573)
@@ -12,6 +12,7 @@
     <script src="Module/src/js/jscal2.js"></script>
     <script src="Module/src/js/unicode-letter.js"></script>
-	<script src="Module/Graph.js"></script>
+	<script src="js/Graph.js"></script>
     <script src="Module/src/js/lang/en.js"></script>
+    <script src="js/xmlrequest.js"></script>
 <style type="text/css">
       .highlight { color: #0f0 !important; font-weight: bold; }
@@ -94,74 +95,5 @@
 					</script>
                 <script type="text/javascript">//<![CDATA[
-				var index = 0;
-				var xmlhttp = new Array();
-                var testXML;
-				var source = ['Mrk 421','Mrk 501'];
-				var sourceData = [[]];
-				var obj;
-				var day;
-				var year;
-				var month;
-				function getXML() 
-				{
-                    xmlhttp.push(new XMLHttpRequest());
-					index = xmlhttp.length - 1;
-                }
-
-				function getXMLData()
-				{
-					getXML();
-                    xmlhttp[index].onload=xmlStateChange();
 				
-					xmlhttp[index].open("GET","/smartfact/index.php?source="+escape(source[index])+"&time="+year+"-"+month+"-"+day,true);
-					xmlhttp[index].send();
-				}
-				
-				function xmlStateChange()
-				{
-                     alert(index+" "+xmlhttp[index].readyState+" "+xmlhttp[index].status + " " + xmlhttp[index].statusText);
-					 if (xmlhttp[index].readyState==4 && xmlhttp[index].status==200)
-						{
-						//sourceData[index]= new Array(); //--> remove this if you use sourceData[[]]
-						line=xmlhttp[index].responseText.split('\n');
-							for(row=0;row<line.length;row++)
-							{
-							rows=line[row].split(',');
-							sourceData[index].push(rows[4]);
-							}
-						}
-				}
-
-				
-				function displayData() //--> you can use the content of this function in the event listener
-				{
-					for (i=0; i<source.length; i++)
-					{
-					getXMLData();
-					//display source data here sourceData[i]
-					document.getElementById('data').innerHTML=sourceData[i];
-					}	
-				}
-
-                function testData() 
-                {
-                    var url = "https://www.fact-project.org/smartfact/index.php?source=Mrk%20421&time=2012-12-10"
-                    testXML = new XMLHttpRequest();
-                    testXML.open("GET",url,true);
-                    alert ("test data");
-                    testXML.onload=function() {
-                        alert (" status: " + testXML.readyState + " " + testXML.status);
-                        if (testXML.status==200)
-						{
-                            alert ("request ok");
-                    }
-                    else
-                    {
-                        alert("status: " + testXML.statusText + " " + testXML.status);
-                    }
-                    };
-					
-                    testXML.send();
-                }
                  CAL.addEventListener("onSelect", function(){
 							 day =this.selection.print("%d").join("\n");
@@ -169,12 +101,6 @@
 							year =this.selection.print("%Y").join("\n");	
 							//document.getElementById('data').innerHTML="Calendar selected! ";
-							                       
-                        alert ("event here");
-                        //testData();
-						for (i=0; i<source.length; i++)
-                        {
-                        getXMLData();
-                        document.getElementById('data').innerHTML=sourceData[i];
-                        }	
+							 testData();                   
+                        	
                 });
 						
Index: schedule/js/xmlrequest.js
===================================================================
--- schedule/js/xmlrequest.js	(revision 16573)
+++ schedule/js/xmlrequest.js	(revision 16573)
@@ -0,0 +1,41 @@
+function testData() 
+{
+   	//calls the xml request in a loop based on the current sources                
+	var source = ['Mrk 421','Mrk 501'];
+	for (i = 0; i<source.length; i++) {
+		testXMLData(i, source);
+	}
+}
+
+function testXMLData(index, source) 
+{
+	var testXML;
+	testXML = new XMLHttpRequest();
+	//NOTE: previous errors on the request was caused by appending "http://www.fact-project.org"
+	testXML.open("GET","/smartfact/index.php?source="+escape(source[index])+"&time="+year+"-"+month+"-"+day,true);
+	dataSource = new Array();
+	testXML.onload=function() {
+		if (testXML.status==200)
+		{
+			line=testXML.responseText.split('\n');
+			dataSource.push(line);
+			if (dataSource.length == source.length)
+				displayXMLData(dataSource, source); //this will be called when the last data from the list is read
+		}
+	testXML.send();
+}
+
+function displayXMLData(dataSource, source)
+{
+	//This function splits the lines of data per data source
+	var dataGraph = new Array(source.length); 
+	for (i=0; i<source.length; i++) {
+		dataGraph[i] = new Array(); //dataGraph contains the individual points for each source i
+		for(row=0;row<dataSource[i].length;row++)
+		{
+			rows=line[row].split(',');
+			dataGraph[i].push(rows[4]);
+			$('#data').append(i + ' GRAPH DATA ' + dataGraph[i]);
+		}
+	}
+}
