var myMexaSlideStarted = "false";
var LSCTimeoutId;
function myMexaSlide(Start,End,time)
{
var id = 'mymexa';
	var speed = Math.round(time / 100);
	var timer = 0;
if(this.document.getElementById(id).style.height > Start + "px") {
	var StartT = Start; var Start = End; var End = StartT;
}
if(myMexaSlideStarted!="true"){
myMexaSlideLog();
myMexaSlideContacts();
myMexaSlideStatus();
}
	if(Start > End)
	{
		for(i = Start; i >= End; i--)
		{
			setTimeout("doSlide('" + id + "'," + i + ")",(speed * timer));
			timer++;
		}
	}
	else if(Start < End)
	{
myMexaSlideStarted = "true";
		for(i = Start; i <= End; i++)
		{
			setTimeout("doSlide('" + id + "'," + i + ")",(speed * timer));
			timer++;
		}
	}
}

/****** contacts *******/


function liveSearchContacts()
{
if(LSCTimeoutId!=0) {
clearTimeout(LSCTimeoutId);
}
LSCTimeoutId = setTimeout('myMexaSlideContacts("search")',700);
}



function myMexaSlideContacts(mode)
{

 try {		
  ajax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     alert("Fehler 1!");
     return false;	
    }
   }
  }
  var printdiv = document.getElementById("myMexaSlideContacts");
  var newContent ="<img src=\"" + CONFIGScriptPath + "/data/images/icon/loading_ajax.gif\" alt=\"lade\" /><br />lade...";
  
  if (mode == 'search') {
	var searchInput = escape(document.getElementById('myMexaSlideContactsSearchInput').value);
  }
  printdiv.innerHTML = newContent;

if (mode == 'search') {
	ajax.open("POST", CONFIGScriptPath + "/data/request/request_contacts.fm", true);
} else {
	ajax.open("GET", CONFIGScriptPath + "/data/request/request_contacts.fm", true);
}

  ajax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

if (mode == 'search') {
	ajax.send("string=" + searchInput);
} else {
	ajax.send(null);
}

  ajax.onreadystatechange = function() {

   if (ajax.readyState == 4) {

    if (ajax.status != 200 && ajax.status != 0) {
     var printerror = "<strong>Fehler:</strong> Die angeforderten Daten konnten nicht geladen werden.";
     printdiv.innerHTML = printerror;
     return false;
    }

    var item = ajax.responseXML.getElementsByTagName('item');
var newContent = "<ul>\n";
   for(var i = 0; i < item.length; i++) {
	var user = item[i].getElementsByTagName('user');
	var name = item[i].getElementsByTagName('name');
	var image = item[i].getElementsByTagName('image');
      newContent += "<li class=\"mymexaSlideContactsItem\"><table><tr><td style=\"width: 45px;\"><a href=\"" + CONFIGScriptPath + "/mexaner/" + user[0].firstChild.nodeValue + "\" title=\"" + user[0].firstChild.nodeValue + "\"><img src=\"" + image[0].firstChild.nodeValue + "\" alt=\"avatar\" /></a></td><td style=\"width: 150px;\"><strong>" + user[0].firstChild.nodeValue + "</strong><br />" + name[0].firstChild.nodeValue + "</td><td><a href=\"" + CONFIGScriptPath + "/mexaner/" + user[0].firstChild.nodeValue + "\" title=\"profil\"><img src=\"" + CONFIGScriptPath + "/data/images/mexatray/contacts_profil.gif\" alt=\"P\" /></a><br /><a href=\"" + CONFIGScriptPath + "/mymexa/messages/new/" + user[0].firstChild.nodeValue + "\" title=\"Nachricht schreiben\"><img src=\"" + CONFIGScriptPath + "/data/images/mexatray/contacts_mail.gif\" alt=\"M\" /></a></td></tr></table></li>\n";
}
if (item.length == 0){
	newContent += "<li><strong>Es wurden keine Kontakte gefunden!</strong><br />Vielleicht solltest du noch ein paar einladen.</li>\n";
}
newContent += "</ul>";
      printdiv.innerHTML = newContent;
var AJAXContactsLoaded = true;
      return true;

    var printerror = "<strong>Fehler:</strong> Die angeforderten Daten konnten nicht geladen werden.";
    printdiv.innerHTML = printerror;
    return false;
   }
  }
}

/****** log *******/

function myMexaSlideLog()
{
 try {		
  logAjax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    logAjax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     logAjax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     alert("Fehler 1!");
     return false;	
    }
   }
  }
  var printdiv = document.getElementById("myMexaSlideLog");
  var newContent ="<img src=\"" + CONFIGScriptPath + "/data/images/icon/loading_ajax.gif\" alt=\"lade\" /><br />lade...";
  printdiv.innerHTML = newContent;


  logAjax.open("GET", CONFIGScriptPath + "/data/request/request_log.fm", true);
  logAjax.setRequestHeader('Content-Type', 'text/xml');

  logAjax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  logAjax.send(null);

  logAjax.onreadystatechange = function() {

   if (logAjax.readyState == 4) {

    if (logAjax.status != 200 && logAjax.status != 0) {
     var printerror = "<strong>Fehler:</strong> Die angeforderten Daten konnten nicht geladen werden.";
     printdiv.innerHTML = printerror;
     return false;
    }

    var item = logAjax.responseXML.getElementsByTagName('item');
var newContent = "<table>\n";
   for(var i = 0; i < item.length; i++) {
	var type = item[i].getElementsByTagName('type');
	var text = item[i].getElementsByTagName('text');
	var time = item[i].getElementsByTagName('time');
      newContent += "<tr><td>" + time[0].firstChild.nodeValue + " - </td><td>" + text[0].firstChild.nodeValue + "</td></tr>\n";
}
newContent += "</table>";
      printdiv.innerHTML = newContent;
AJAXContactsLoaded = true;
      return true;

    var printerror = "<strong>Fehler:</strong> Die angeforderten Daten konnten nicht geladen werden.";
    printdiv.innerHTML = printerror;
    return false;
   }
  }
}


function myMexaSlideStatus(mode)
{
 try {		
  statusAjax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    statusAjax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     statusAjax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     alert("Fehler 1!");
     return false;	
    }
   }
  }
  var statusDiv = document.getElementById("myMexaSlideStatus");
  var emmomentDiv = document.getElementById("myMexaSlideEmmoment");
if (mode == 'save') {
var statusInput = escape(document.getElementById('myMexaSlideStatusInput').value);
var emmomentInput = escape(document.getElementById('usermood').value);
}
  var newContent ="<img src=\"" + CONFIGScriptPath + "/data/images/icon/loading_ajax.gif\" alt=\"lade\" /> lade...";
  statusDiv.innerHTML = newContent;

if (mode == 'save') {
  statusAjax.open("POST", CONFIGScriptPath + "/data/request/save_status.fm", true);
} else {
  statusAjax.open("GET", CONFIGScriptPath + "/data/request/request_status.fm", true);
}
  /* alert("owee:" + document.getElementById('myMexaSlideStatusInput').value); */
  statusAjax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  statusAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
if (mode == 'save') {
  statusAjax.send("status=" + statusInput + "&emmoment=" + emmomentInput);
} else {
  statusAjax.send(null);
}


  statusAjax.onreadystatechange = function() {

   if (statusAjax.readyState == 4) {

    if (statusAjax.status != 200 && statusAjax.status != 0) {
     var printerror = "<strong>Fehler...</strong>";
     statusDiv.innerHTML = printerror;
     emmomentDiv.innerHTML = printerror;
     return false;
    }

    var item = statusAjax.responseXML.getElementsByTagName('status');
    var itemE = statusAjax.responseXML.getElementsByTagName('moodid');

    var status = item[0].firstChild.nodeValue;
    var emmoment = itemE[0].firstChild.nodeValue;

	var newStatusContent = "<strong>Ich bin </strong> <input id=\"myMexaSlideStatusInput\" name=\"myMexaSlideStatusInput\" value=\"" + status + "\" />";
	statusDiv.innerHTML = newStatusContent;
	document.getElementById("usermood").value	=	emmoment;
      return true;
    var printerror = "<strong>Fehler...</strong>";
    statusDiv.innerHTML = printerror;
    emmomentDiv.innerHTML = printerror;
    return false;
   }
  }
}

