/***************************
* OPEN/CLOSE ElEMENT
****************************/

function ocobject (foo) {

  if(this.document.getElementById(foo).style.visibility == "hidden")

  {
    this.document.getElementById(foo).style.visibility = "visible";
    this.document.getElementById(foo).style.overflow = "auto";
    this.document.getElementById(foo).style.height = "auto"; 
  }

 else
 {
    this.document.getElementById(foo).style.visibility = "hidden";
    this.document.getElementById(foo).style.overflow = "auto";
    this.document.getElementById(foo).style.height = "0px"; 
 }

}

/***************************
* SLIDE ELEMENT
****************************/

function Slide(id,Start,End,time)
{
	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(Start > End)
	{
		for(i = Start; i >= End; i--)
		{
			setTimeout("doSlide('" + id + "'," + i + ")",(speed * timer));
			timer++;
		}
	}
	else if(Start < End)
	{
		for(i = Start; i <= End; i++)
		{
			setTimeout("doSlide('" + id + "'," + i + ")",(speed * timer));
			timer++;
		}
	}
}

function doSlide(id, slidePoint)
{
	var object = document.getElementById(id).style;
	object.height = slidePoint + 'px';
}

/***************************
* FADE UP
****************************/

function fmFadeBg(Opacity,Color,time, divid)
{
	if (typeof divid === 'undefined') { var divid = ''; }
	var speed = Math.round(time / 100);
	var timer = 0;
if(!this.document.getElementById('FadeBg' + divid)){
	if (document.createElement) { 
		var fb = document.createElement('div'); 
		fb.id = 'FadeBg' + divid;	 
		with (fb.style) { 
			width = '100%';
			height = '100%';
			background = '#' + Color;
			zIndex = '0';
			opacity = '0';
			position = 'absolute';
			left = '0';
			top = '0';
		} 
		fb.innerHTML = '&nbsp;'; 
		document.body.appendChild(fb); 
 }
}
if(Opacity != '0') {

		for(i = 0; i/50 <= Opacity; i++)
		{
			setTimeout("fmDoFade('FadeBg" + divid + "'," + i/50 + ")",(speed * timer));
			timer++;
		}
	} else {

		for(i = 50 * this.document.getElementById('FadeBg' + divid).style.opacity; i >= 0; i--)
		{
			setTimeout("fmDoFade('FadeBg" + divid + "'," + i/50 + ")",(speed * timer));
			timer++;
		}
			setTimeout("document.body.removeChild(this.document.getElementById('FadeBg" + divid + "'))", (speed * timer + 1));
}
	
}

function fmDoFade(id, Opacity)
{
	var object = document.getElementById(id).style;
	object.opacity = Opacity;
	object.filter = 'alpha(opacity='+ Opacity * 100 +')';
}

function fmFUInfo(title, content)
{
	fmFadeBg('0.7','000000','400');
	this.document.getElementById('FadeBg').innerHTML = '<div style="width: 350px; height: 150px; position: absolute; left: 38%; top: 45%; border: 1px solid #666666; background-color: #cccccc; opacity: 1.0; font-family: Trebuchet MS;" id="fmFUInfoDiv"><a id="fmFUInfoClose" style="left: 325px; top:0; border: 1px solid #666666; display:block; position: relative; height: 14px; width: 23px; font-size: 0.6em; color: #ffffff; background: red; text-decoration:none;" href="javascript:fmFUClose();">close</a><h1 style="font-size: 1.0em; color: #000000;" >' + title + '</h1><p style="text-align:justify; font-size: 0.7em; color: #000000; width: 95%; margin: 0 auto;" >' + content + '</p></div>';
}

function fmFUConfirm(title, content, formid)
{
	fmFadeBg('0.7','000000','400');
	this.document.getElementById('FadeBg').innerHTML = '<div style="width: 350px; height: 150px; position: absolute; left: 38%; top: 45%; border: 1px solid #666666; background-color: #cccccc; opacity: 1.0; font-family: Trebuchet MS;" id="fmFUInfoDiv"><a id="fmFUInfoClose" style="left: 325px; top:0; border: 1px solid #666666; display:block; position: relative; height: 14px; width: 23px; font-size: 11px; color: #ffffff; background: red; text-decoration:none;" href="javascript:fmFUClose();">close</a><h1 style="font-size: 14px; color: #000000;" >' + title + '</h1><p style="text-align:justify; font-size: 12px; color: #000000; width: 95%; margin: 0 auto;" >' + content + '<br /><input type="submit" value="Ja" name="submit" id="submit" onclick="javascript:document.' + formid + '.submit();" /><input type="submit" value="Nein" name="submit" id="submit" onclick="javascript:fmFUClose();" /></p></div>';
}



function fmFUClose(divid)
{
	if (typeof divid === 'undefined') { var divid = ''; }
	fmFadeBg('0','000000','400', divid);
}

/* AJAX TEST */

function ajaxtest(tag)
{
 
 try {		
  ajax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     alert("Ihr Browser kann keine Fußnoten anzeigen.");
     return false;	
    }
   }
  }
  var testdiv = document.getElementById("ajaxtestDiv");

  ajax.open("GET", "/medialab/fmcms/inmexa/data/request/test.fm", true);
  ajax.setRequestHeader('Content-Type', 'text/xml');

  ajax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  ajax.send(null);

  ajax.onreadystatechange = function() {

   if (ajax.readyState == 4) {

    if (ajax.status != 200 && ajax.status != 0) {
     testdiv.firstChild.nodeValue = "Fussnoten-Datei konnte nicht gefunden werden!";
     return false;
    }

    var item = ajax.responseXML.getElementsByTagName(tag);
var newContent = "";
   for(var i = 0; i < item.length; i++) {
 newContent += " " + item[i].firstChild.nodeValue;
}
      testdiv.replaceChild(document.createTextNode(newContent), testdiv.lastChild);
      return true;

    var nicht_gefunden = document.createTextNode("Fehler: Inhalt wurde nicht gefunden.");
    testdiv.replaceChild(nicht_gefunden, testdiv.lastChild);
    return false;
   }
  }
}




/***************************
* MOUSE POSITION
****************************/


var offsetx = 5;
var offsety = -5;
var ie5 = (document.getElementById && document.all); 
//var ie5 = (navigator.appName.indexOf("Internet Explorer") != -1); 
var ns6 = (document.getElementById && !document.all); 
var ua = navigator.userAgent.toLowerCase();
var isopera = (ua.indexOf('opera') != -1 ? 1 : 0);
var isapple = (ua.indexOf('applewebkit') != -1 ? 1 : 0);

function newelement(newid) { 
	if (document.createElement) { 
		var el = document.createElement('div'); 
		el.id = newid;	 
		with (el.style) { 
			display = 'none';
			position = 'absolute';
		} 
		el.innerHTML = '&nbsp;'; 
		document.body.appendChild(el); 
	} 
} 

function getmouseposition(e) {

	if (document.getElementById) {
		var iebody=(document.compatMode && 
			document.compatMode != 'BackCompat') ? 
				document.documentElement : document.body;
		pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
		pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
		mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
		mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        if (isopera == 1) {
            mousex = event.screenX-5;
            mousey = event.screenY-135;
        }
        if (ie5) {
            mousex = event.clientX-5;
            mousey = event.clientY;
        }

		var info = document.getElementById('toolTip');
		info.style.left = (mousex+pagex+offsetx) + 'px';
		info.style.top = (mousey+pagey+offsety) + 'px';
    }

}


function getmousepositionl(e) {
var offsetx = -460;
var offsety = -100;
	if (document.getElementById) {
		var iebody=(document.compatMode && 
			document.compatMode != 'BackCompat') ? 
				document.documentElement : document.body;
		pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
		pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
		mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
		mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;

        if (isopera == 1) {
            mousex = event.screenX-5;
            mousey = event.screenY-135;
        }
        if (ie5) {
            mousex = event.clientX-5;
            mousey = event.clientY;
        }

		var info = document.getElementById('toolTip');
		info.style.left = (mousex+pagex+offsetx) + 'px';
		info.style.top = (mousey+pagey+offsety) + 'px';
    }

}

/***************************
* TOOL TIPS
****************************/


function infoClose(divid){
	if (typeof divid === 'undefined') { var divid = 'toolTip'; }
		document.getElementById(divid).style.display = 'none';
}


/***************************
* INFO TOOL TIP
****************************/

function infoOpen(title, text, divid){
	if (typeof divid === 'undefined') { var divid = ''; }
newelement('toolTip' + divid);

        var info = document.getElementById('toolTip' + divid);

	var html = '<div class="infoStyle" style="padding-left: 5px; padding-right:5px; color: #333333; font-family: Trebuchet MS; font-size: 11px; background-color: #f3f7f9;border: 1px solid #cccccc;" >';
    	html += '<strong>'+title+'</strong>';
        html += '<p>'+text+'</p>';
	html += '</div>';

	info.innerHTML = html;

/*	document.onmousemove = getmouseposition; */

    document.onmousemove = getmouseposition;

    info.style.display = "block";

}


/***************************
* EVENT TOOL TIP
****************************/


function infoEvent(id, title, pic, date, location, tags){
newelement('toolTip');

        var info = document.getElementById('toolTip');

	var html = '<div class="infoStyle" style="padding-left: 5px; padding-right:5px; color: #333333; font-family: Trebuchet MS; font-size: 12px; background-color: #ffffff;border: 1px solid #cccccc; width:440px; height:126px;" >';
    	html += '<table><tr><td><img src="'+pic+'" style="width:120px; height: 120px; border: 1px solid #cccccc;" /></td><td style="vertical-align:top;"><span style="color: lightgrey;">'+date+'</span><br /><strong style="font-size: 14px;">'+title+'</strong><br /><span style="color: #666666; font-size: 10px; text-transform: uppercase;">'+location+'</span><br /><span style="color: #999999; font-size: 10px">TAGS:</span> <span style="color: lightblue; font-size: 11px">'+tags+'</span></td></tr></table>';
	html += '</div>';

	info.innerHTML = html;

/*	document.onmousemove = getmouseposition; */

    document.onmousemove = getmousepositionl;

    info.style.display = "block";

}


/***************************
* UPDATE INFO
****************************/

function autoUpdateInfo() {
	var timer = 20; /* time in seconds */
	updateInfo();
	setTimeout("autoUpdateInfo()",(timer * 1000));
}

function updateInfo()
{

 try {		
  ajax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     return false;	
    }
   }
  }
  var infoDiv = document.getElementById("updateInfoDiv");

  ajax.open("GET", CONFIGScriptPath + "/data/request/request_update.fm", true);
  ajax.setRequestHeader('Content-Type', 'text/xml');

  ajax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  ajax.send(null);

  ajax.onreadystatechange = function() {

   if (ajax.readyState == 4) {

    if (ajax.status != 200 && ajax.status != 0) {
     return false;
    }
var sthnew = 0;
      var updateData = ajax.responseXML.getElementsByTagName('update');
       if (updateData.length > 0) {
	var messages = updateData[0].getElementsByTagName('messages');
	var newcons = updateData[0].getElementsByTagName('newcontacts');
	var ginvs = updateData[0].getElementsByTagName('groupinvitations');
if(messages[0].firstChild.nodeValue>0){
 var newContent = "<p class=\"uINewMail\"><a href=\"" + CONFIGScriptPath + "/mymexa/messages\">Du hast " + messages[0].firstChild.nodeValue + " neue Nachricht(en)!</a></p>";
 sthnew++;
}
if(newcons[0].firstChild.nodeValue>0){
 var newContent = newContent + "<p class=\"uINewCons\"><a href=\"" + CONFIGScriptPath + "/mymexa/contacts/invitations\">Du hast " + newcons[0].firstChild.nodeValue + " neue(n) Kontakt(e) zu best&auml;tigen!</p>";
 sthnew++;
}
if(ginvs[0].firstChild.nodeValue>0){
 var newContent = newContent + "<p class=\"uINewGInvs\"><a href=\"" + CONFIGScriptPath + "/mymexa/groups/invitations\">Du hast " + ginvs[0].firstChild.nodeValue + " neue Gruppeneinladung(en)!</p>";
 sthnew++;
}
}
if(sthnew >= 1)
{
 infoDiv.innerHTML = newContent;
 var iheight = sthnew * 27;
 if(infoDiv.style.height != iheight + 'px'){
 Slide('updateInfoDiv', '0',iheight,'80');
}
}

    return true;
   }
  }

}

function checkNewMail()
{
 try {		
  ajax = new XMLHttpRequest();
  } catch(w3c) {
   try {		
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
   } catch(msie) {
    try {	
     ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(msie_alt) {
     return false;	
    }
   }
  }
  var maildiv = document.getElementById("alertNewMail");

  ajax.open("GET", CONFIGScriptPath + "/data/request/request_newmessages.fm", true);
  ajax.setRequestHeader('Content-Type', 'text/xml');

  ajax.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
  ajax.send(null);

  ajax.onreadystatechange = function() {

   if (ajax.readyState == 4) {

    if (ajax.status != 200 && ajax.status != 0) {
     return false;
    }

    var count = ajax.responseXML.getElementsByTagName('messages');
if(count[0].firstChild.nodeValue>0){
 newContent = "<strong>Du hast " + count[0].firstChild.nodeValue + " neue Nachricht(en)!</strong>";
 maildiv.innerHTML = newContent;
 Slide('alertNewMail', '0','75','80');
}
      return true;
    return false;
   }
  }
}

var currentMP = '0';
function fmMiniProfil(uid, nick, gender, age, residence, district, zodiac, msince, family, status, emmoment)
{

	if(currentMP != 0 && currentMP != uid){ infoClose('MP' + currentMP); }else{ if(currentMP != 0) { return 0; } }
	currentMP = uid;
	newelement('MP' + uid);

      var MPdiv = document.getElementById('MP' + uid);
	MPdiv.style.display = "block";
var offsetx = 0;
var offsety = 0;
	if (document.getElementById) {
		var iebody=(document.compatMode && 
			document.compatMode != 'BackCompat') ? 
				document.documentElement : document.body;
		pagex = (isapple == 1 ? 0:(ie5)?iebody.scrollLeft:window.pageXOffset);
		pagey = (isapple == 1 ? 0:(ie5)?iebody.scrollTop:window.pageYOffset);
var	mousex = 0;
var	mousey = 0;
        if (isopera == 1) {
            mousex = event.screenX-5;
            mousey = event.screenY-135;
        }
        if (ie5) {
            mousex = event.clientX-5;
            mousey = event.clientY;
        }

		MPdiv.style.left = (mousex+pagex+offsetx) + 'px';
		MPdiv.style.top = (mousey+pagey+offsety) + 'px';
    }

	this.document.getElementById('MP' + uid).innerHTML = '<div style="position: absolute; left: 38%; top: 45%; width: 400px; height: 200px;"><div style="width: 350px; height: 150px; border: 1px solid #666666; margin-top: 50px; background-color: #cccccc; opacity: 1.0; font-family: Trebuchet MS;" id="fmFUInfoDiv"><a id="fmFUInfoClose" style="left: 325px; top:0; border: 1px solid #666666; display:block; position: relative; height: 14px; width: 23px; font-size: 0.6em; color: #ffffff; background: red; text-decoration:none;" href="javascript:infoClose(\'MP' + uid + '\');">close</a><h1 style="font-size: 1.0em; color: #000000;" >' + nick + '</h1><p style="text-align:justify; font-size: 1.2em; color: #000000; width: 95%; margin: 0 auto;" ><strong>' + uid + ' - </strong>' + nick + ' - ' + gender + ' - ' + age + ' - ' + residence + ' - ' + district + ' - ' + zodiac + ' - ' + msince + ' - ' + family + ' - ' + status + ' - ' + emmoment + '</p></div></div>';
}


function fmCheck(checkfor)
{

var checkInput = escape(document.getElementById("reg_user_" + checkfor).value);
var printdiv = document.getElementById("check" + checkfor);

if (checkInput.length != 0) {
	 try {		
	  check = new XMLHttpRequest();
	  } catch(w3c) {
	   try {		
	    check = new ActiveXObject("Msxml2.XMLHTTP");
	   } catch(msie) {
	    try {	
	     check = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch(msie_alt) {
	     alert("Error 000001");
	     return false;	
	    }
	   }
	  }
	  var printdiv = document.getElementById("check" + checkfor);
	  var newContent ="<img src=\"" + CONFIGScriptPath + "/data/images/icon/loading_ajax_m.gif\" alt=\"lade\" />";
	  

		printdiv.innerHTML = newContent;

		check.open("POST", CONFIGScriptPath + "/data/request/check.fm", true);
		check.setRequestHeader('If-Modified-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
		check.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		check.send("string=" + checkInput + "&a=" + checkfor);

	  check.onreadystatechange = function() {

	   if (check.readyState == 4) {

	    if (check.status != 200 && check.status != 0) {
	     return false;
	    }

		var code = check.responseXML.getElementsByTagName('code')[0].firstChild.nodeValue;
		if ( code == "2" ) {
		/* doppelt */
			newContent = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/fail.gif\" alt=\"fail\" />";
		} else if ( code == "1" ) {
		/* passt */
			newContent = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/check.gif\" alt=\"pass\" />";
		} else if ( code == "3" ) {
		/* registriert */
			newContent = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/fail.gif\" alt=\"fail\" />";
		} else {
		/* einfach nein! */
			newContent = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/fail.gif\" alt=\"fail\" />";
		}
		
		printdiv.innerHTML = newContent;
		return true;
		return false;
	   }
	  }
} else {
	printdiv.innerHTML = "";
}
}

function fmCheckPass()
{
	if (document.getElementById("reg_user_pass").value.length != 0) {
		if (document.getElementById("reg_user_pass").value.length >= 6 && document.getElementById("reg_user_pass_valid").value.length == 0)
		{
			document.getElementById("checkpass").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/check.gif\" alt=\"pass\" />";
		} else {
			if (document.getElementById("reg_user_pass").value.length >= 6 && document.getElementById("reg_user_pass_valid").value.length >= 6 && document.getElementById("reg_user_pass_valid").value == document.getElementById("reg_user_pass").value) {
				document.getElementById("checkpass").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/check.gif\" alt=\"pass\" />";
				document.getElementById("checkpassv").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/check.gif\" alt=\"pass\" />";
			} else if (document.getElementById("reg_user_pass").value.length >= 6 && document.getElementById("reg_user_pass_valid").value.length >= 6 && document.getElementById("reg_user_pass_valid").value != document.getElementById("reg_user_pass").value) {
				document.getElementById("checkpass").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/check.gif\" alt=\"pass\" />";
				document.getElementById("checkpassv").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/fail.gif\" alt=\"fail\" />";
			} else {
				document.getElementById("checkpass").innerHTML = "<img src=\"" + CONFIGScriptPath + "/data/images/icon/fail.gif\" alt=\"fail\" />";
			}
		}
	} else {
		document.getElementById("checkpass").innerHTML = "";
	}

return 0;

}	