function putInElement(element, s) {
	document.getElementById(element).innerHTML = s.toString();
}


function get_tag_menu() {
	s = "here comes the links";
	document.getElementById("blog_tags").innerHTML = s.toString();
}

function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
    }else{
      document.getElementById(divid).style.display = 'none';
    }
  }

 function makeRequest(url, id) {
     var http_request = false;

     if (window.XMLHttpRequest) { // Mozilla, Safari, ...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
             http_request.overrideMimeType('text/xml');
             // See note below about this line
         }
     } else if (window.ActiveXObject) { // IE
         try {
             http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
             try {
                 http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
         }
     }

     if (!http_request) {
         alert('Giving up :( Cannot create an XMLHTTP instance');
         return false;
     }
     http_request.onreadystatechange = function() { updateContents(http_request, id); };
     http_request.open('GET', url, true);
     http_request.send(null);

 }
 
 function makePostRequest(url, parameters) {
     var http_request = false;
     if (window.XMLHttpRequest) { // Mozilla, Safari, ...
     http_request = new XMLHttpRequest();
     if (http_request.overrideMimeType) {
         http_request.overrideMimeType('text/xml');
         }
     } else if (window.ActiveXObject) { // IE
     try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) {
         try {
             http_request = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) {}
         }
     }
     if (!http_request) {
         alert('Cannot create an XMLHTTP instance');
         return false;       
     }
     http_request.onreadystatechange = function() { alertContents(http_request); };
     http_request.open('POST', url, true);
     http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
     http_request.setRequestHeader("Content-length", parameters.length);
     http_request.setRequestHeader("Connection", "close");
     http_request.send(parameters);            
 }

 function alertContents(http_request) {
     if (http_request.readyState == 4) {
         if (http_request.status == 200) {
             result = http_request.responseText;
             document.getElementById('test').innerHTML = result;  
         } else {
             alert('There was a problem with the request.');
         }
     }
 }
 
 function get(obj) {
   var poststr = "title=" + encodeURI( document.getElementById("title").value ) +
                 "&description=" + encodeURI( document.getElementById("description").value ) +
                 "&tags=" + encodeURI( document.getElementById("tags").value );
   makePostRequest('http://lumotic.se/komplish/functions/post_goal.php', poststr);
}
 
 function updateContents(http_request, id) {
     if (http_request.readyState == 4) {
         if (http_request.status == 200) {
             document.getElementById(id).innerHTML = http_request.responseText;
         } else {
             alert('There was a problem with the request.'); 
         }
     }
 }

function getBlogMenu($view) {
	makeRequest('http://surfskolan.nu/withblog/xml/blogmenu.php', 'blog_menu');
}

function getEntry(id) {
	document.getElementById('blog_entry').innerHTML = "Laddar...";  
	makeRequest('http://surfskolan.nu/withblog/xml/entries.php?id='+id, 'blog_entry');
}

function editBlogEntry(id) {
	document.getElementById('blog_entry').innerHTML = "Laddar...";  
	makeRequest('http://surfskolan.nu/withblog/xml/editBlogEntry.php?id='+id, 'blog_entry');
}

function addBlogEntry(id) {
	document.getElementById('blog_entry').innerHTML = "Laddar...";  
	makeRequest('http://surfskolan.nu/withblog/xml/addBlogEntry.php', 'blog_entry');
}

function load() {
    makeRequest('http://lumotic.se/komplish/xml/goals.php?user=<?php echo $username;?>', 'page');
    makeRequest('http://lumotic.se/komplish/xml/lists.php<?php echo $username;?>', 'lists');
    makeRequest('http://lumotic.se/komplish/xml/tags.php<?php echo $username;?>', 'tags');
}

function addGoal() {
    makeRequest('http://lumotic.se/komplish/elements/add_goal.php', 'content');
}

function addList() {
    makeRequest('http://lumotic.se/komplish/elements/add_list.php', 'content');
}

