


		function generate_list(name,list_id) {
			var list = new Object();
			list.id = list_id;
			list.list = document.getElementById(name);
			list.sep = list.list.appendChild(document.createElement('br'));
			list.add           = list.list.appendChild(document.createElement('li'));
			list.add.innerHTML = '<a href="#" onclick="return false">[X] Generate new entry.</a>';
			list.add.value     = '1111';
			list.add.onclick = function() {
			  // -1 indicates a new note
			  addnote(-1, 'Click here to edit/generate your entry. - Your name',list_id);
			}
			all_lists.push(list);
		}


// the list element
//var list = document.getElementById('list');

// seperator between the actual list and the add link
//var sep  = list.appendChild(document.createElement('br'));

// the add link
//var add           = list.appendChild(document.createElement('li'));
//    add.innerHTML = '<a href="#" onclick="return false">[X] Neuen Eintrag erstellen.</a>';
//    add.value     = '83';


// from: http://www.codepost.org/view/59
function createXMLHttpRequest() {
  var types = [
    'Microsoft.XMLHTTP',
    'MSXML2.XMLHTTP.5.0',
    'MSXML2.XMLHTTP.4.0',
    'MSXML2.XMLHTTP.3.0',
    'MSXML2.XMLHTTP'
   ];

  for (var i = 0; i < types.length; i++) {
    try {
      return new ActiveXObject(types[i]);
    } catch(e) {}
  }

  try {
    return new XMLHttpRequest();
  } catch(e) { }

  return false; // XMLHttpRequest not supported
}

function getSepByID(list_id)
{
	for ( var i in all_lists )
	{
		if (all_lists[i].id == list_id) {
			return all_lists[i].sep;
		}
	} 
	alert("getSepByID: ERROR no ID "+list_id);
}
function getListByID(list_id)
{
	for ( var i in all_lists )
	{
		if (all_lists[i].id == list_id) {
			return all_lists[i].list;
		}
	} 
	alert("getListByID: ERROR no ID "+list_id);
}


// this function will be called when the add link is pressed
// and when loading the list at startup
function addnote(id, text, list_id) {

  var item = getListByID(list_id).insertBefore(document.createElement('li'), getSepByID(list_id));   
  // span containing the html
  var html = item.appendChild(document.createElement('span'));

  // input for editing
  var edit           = item.appendChild(document.createElement('input'));
      edit.type      = 'text';
      edit.value     = text;
      edit.maxLength = 255;
      edit.size      = 80;
 
  // image for the delete button
  var dele               = item.appendChild(document.createElement('img'));
      dele.src           = 'images/dele.gif';
      dele.style.display = edit.style.display = 'none';
	  dele.id = list_id;

  // new note?
  if (id == -1) {
    // use an xmlhttprequest to get a new id for the note
    var req = createXMLHttpRequest();
    req.onreadystatechange = function() {
      if (req.readyState == 4) {
        if (req.status == 200) {
          item.id = req.responseText;
        }
      }
    };
    req.open('GET', 'todolist.php?getid=1&list='+list_id, true);
    req.send('');
  } else {
    item.id = id;
  }


  item.onclick = function() {
    // switch the note to edit mode
    html.style.display = 'none';
    dele.style.display = edit.style.display = 'inline';

    edit.focus();
  };


  edit.onblur = function() {
    var t = edit.value;
        t = t.replace(/!(.+)!/g, '<i>$1</i>');   // replace !...! by italic text
        t = t.replace(/\*(.+)\*/g, '<b>$1</b>'); // replace *..* by bold text

    // has the contents of the note changed?
    if (html.innerHTML != t) {
      // use an xmlhttprequest to update the note contents in the database
      var req = createXMLHttpRequest();
          req.open('POST', 'todolist.php?list=0', true);
          req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          req.send('id=' + item.id + '&text=' + escape(edit.value));
   }

   html.innerHTML = t;
 
   // switch the note to display mode
   html.style.display = 'inline';
   dele.style.display = edit.style.display = 'none';
  }

  // catch the enter key to finish editing the note
  edit.onkeydown = function(e) {
    var key = 0;
    if (window.event) {
      key = window.event.keyCode;
    } else if (e) {
      key = e.keyCode; // e.which
    }

    if (key == 13) { // 13 is the enter key
      edit.onblur();
    }
  }


  dele.onmousedown = function() {
    // ask the user if he/she really wants to delete the note
    if (confirm('Realy delete?')) {
      // use an xmlhttprequest to remove the note from the database
      var req = createXMLHttpRequest();
          req.open('GET', 'todolist.php?del='+item.id+'&list=0', true);
          req.send('');

      getListByID(dele.id).removeChild(item);
    }
  }
 
  // trigger onblur to switch the note to display mode and update it's innerHTML
  edit.onblur();
}

var joinus_name = "";
var joinus_text = "";
function joinus_send()
{
    if (confirm('Sure join the Wolverines? This form is handled as a tender offer.')) {
      // use an xmlhttprequest 
	joinus_name = document.joinus.name.value;
	joinus_text = document.joinus.description.value;
 	document.getElementById("joinus_div").innerHTML = "Connecting...";     
	var req = createXMLHttpRequest();
		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				if (req.status == 200) {
					var id = req.responseText;
					document.getElementById("joinus_div").innerHTML = "Sending...";
					var req2 = createXMLHttpRequest();
						req2.onreadystatechange = function() {
							if (req2.readyState == 4) {
								if (req2.status == 200) {
									document.getElementById("joinus_div").innerHTML = "Success. Maybe your request will be handled due the next month.";
								} else document.getElementById("joinus_div").innerHTML = "Failed. Sorry :/";
							}
						};
					req2.open('POST', 'todolist.php?list=0', true);
					req2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					req2.send('id='+id+'&text=' + escape(joinus_name+" : "+joinus_text));
					
					
					
				} else document.getElementById("joinus_div").innerHTML = "Failed. Sorry :/";
			}
		};
		req.open('GET', 'todolist.php?getid=1&list=99999', true);
		req.send('');

		
		
	

	
    }

}


