var notatXmlHttp;
var urlString;
	

	<!-- Makes the main AJAX Object --------------------------------->
	function createNotatXMLHttpRequest(){
		if(window.ActiveXObject){
			notatXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else if(window.XMLHttpRequest){
			notatXmlHttp = new XMLHttpRequest();
		}
	}
	
	function saveNotat(modulId, modulPk, brukerId){
		
		urlString = "?modulId="+modulId+"&modulPk="+modulPk+"&brukerid="+brukerId+"&saveVerdi="+document.getElementById("notatReg").value+"";
		document.getElementById("notatReg").value = "";
		startRequest(urlString);
	}
	function saveNotatKommentar(modulId, modulPk, brukerId)
	{
		var str =document.getElementById("notatReg").value;
		/*
		var intIndexOfMatch = str.indexOf("\r\n"); // skift ut alle java linjeskift med html
		while (intIndexOfMatch != -1)
		{
			// Relace out the current instance.
			str=str.replace("\r\n","<br>");
			// Get the index of any next matching substring. ("\\\\n", 
			intIndexOfMatch = str.indexOf("\r\n");
		}
		
		*/
		str=str.replace(/[\r\n]+/g ,"<br>");//[\n\r\u2028\u2029] // /\n/g 
		
		urlString = "?modulId="+modulId+"&modulPk="+modulPk+"&brukerid="+brukerId+
		"&saveVerdi="+str+"&kommentarNavn="+
		document.getElementById("notatKommentarNavn").value+"";
		document.getElementById("notatReg").value = "";		
		startRequest(urlString);
	}
	
	function show(modulId, modulPk, tkReg, tkred, tkslett, kommentar){
		urlString = "?modulId="+modulId+"&modulPk="+modulPk+"&vis=true&tkred="+tkred+"&tkslett="+tkslett+"&tkreg="+tkReg+"&kommentar="+kommentar;
		startRequest(urlString);
	}
	
	function startRequest(verdi){
		createNotatXMLHttpRequest();
		notatXmlHttp.onreadystatechange = handleStateChange;
		notatXmlHttp.open("POST", "../system/notatResponse.php"+verdi, true);
		notatXmlHttp.send(null);
		
		// === FOR DEBUG ===
		//document.write("../system/notatResponse.php"+verdi);
	}
	
	function handleStateChange(){
		if(notatXmlHttp.readyState == 4){
			//if(notatXmlHttp.status == 200){
				document.getElementById("NotatListDiv").innerHTML = notatXmlHttp.responseText;
			//}
		}
	}
	
	// ---------------------------------------------------
	function slettRequest(){
		createNotatXMLHttpRequest();
		notatXmlHttp.open("POST", "../system/notatResponse.php"+urlString, true);
		notatXmlHttp.send(null);
	}
	
	function slettNotat(notatId, modulId, modulPk,kommentar){	
		var agree=confirm("Er du sikker på at du ønsker å slette dette notatet?");
		
		if (agree){
			urlString = "?notatId="+notatId+"&modulId="+modulId+"&modulPk="+modulPk+"&slett=true";
			slettRequest();
			show(modulId, modulPk,kommentar);
		}
	}
	
	// ---------------------------------------------------
	function redigerNotat(id, modulId, modulPk, kommentar){	
		redigerRequest(id, modulId, modulPk, kommentar);
	}
	
	var redigerDiv
	
	function redigerRequest(id, modulId, modulPk, kommentar){
		redigerDiv = id;
		createNotatXMLHttpRequest();
		notatXmlHttp.onreadystatechange = handleRedigerStateChange;
		notatXmlHttp.open("POST", "../system/notatResponse.php?redigerPost=true&id=" + id+"&modulId="+modulId+"&modulPk="+modulPk+"&kommentar="+kommentar, true);
		notatXmlHttp.send(null);
	}
	
	function handleRedigerStateChange(){
		if(notatXmlHttp.readyState == 4){
			//if(notatXmlHttp.status == 200){
				document.getElementById(redigerDiv).innerHTML = notatXmlHttp.responseText;
			//}
		}
	}
	
	// ---------------------------------------------------
	/*function svarNotat(id, modulId, modulPk){	
		svarRequest(id, modulId, modulPk);
	}
	
	var svarDiv
	
	function svarRequest(id, modulId, modulPk){
		redigerDiv = id;
		createNotatXMLHttpRequest();
		notatXmlHttp.onreadystatechange = handleRedigerStateChange;
		notatXmlHttp.open("POST", "../system/notatResponse.php?redigerPost=true&id=" + id+"&modulId="+modulId+"&modulPk="+modulPk+"", true);
		notatXmlHttp.send(null);
	}
	
	function handleRedigerStateChange(){
		if(notatXmlHttp.readyState == 4){
			//if(notatXmlHttp.status == 200){
				document.getElementById(redigerDiv).innerHTML = notatXmlHttp.responseText;
			//}
		}
	}*/
	
	
	