/* 
(c) dbna e.V 1997-2007
*/
/* Anfang DHTML-Bibliothek */

var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false; var browserName = navigator.appName; var browserVer = parseInt(navigator.appVersion); 
var debugMode = false;
if (document.getElementById) {
  DHTML = true;
  DOM = true;
} else {
  if (document.all) {
    DHTML = true;
    MSIE4 = true;
  } else {
    if (document.layers) {
      DHTML = true;
      NS4 = true;
    }
  }
}
if (window.opera) {
  OP = true;
}

function getElement (Mode, Identifier, ElementNumber) {
  var Element, ElementList;
  if (DOM) {
    if (Mode.toLowerCase() == "id") {
      Element = document.getElementById(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      ElementList = document.getElementsByName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.getElementsByTagName(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (MSIE4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document.all(Identifier);
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      ElementList = document.all.tags(Identifier);
      Element = ElementList[ElementNumber];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      Element = document[Identifier];
      if (!Element) {
        Element = document.anchors[Identifier];
      }
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "layerindex") {
      Element = document.layers[Identifier];
      if (!Element) {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    Attribute = Element[AttributeName]
    if (!Attribute) {
       Attribute = false;
    }
    return Attribute;
  }
  return false;
}

function getContent (Mode, Identifier, ElementNumber) {
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    } else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) {
    Content = Element.innerText;
    return Content;
  }
  return false;
}

function setContent (Mode, Identifier, ElementNumber, Text) {
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) {
    Element.innerText = Text;
    return true;
  }
  if (NS4) {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
}
/* Ende DHTML Bibliothek */
/* Functions for dbna Community. (c) 2007 by Frederik - frederik@dbna.de*/
function getRandom(){/*dbna*/
	var date = Math.random()*10000;
	return date;
}
function elID(id){/*dbna*/
	return getElement("id", id);
}
function elName(id){/*dbna*/
	return getElement("name", id);
}
function askAction(txt){/*dbna*/
	return confirm(txt);
}
function timeout(fn, time, ePlace){/*dbna*/
	if(!ePlace) ePlace = window;
	ePlace.setTimeout(fn,time);
}
function disableSubmit(id){/*dbna*/
	var button=elID(id);
	if (button){ button.value = "Sendet"; button.disabled=true;}
	return true;
}
function enableSubmit(id){/*dbna*/
	var button=elID(id);
	if (button){ button.value = "Senden"; button.disabled=false;}
	return true;
}
function setHash(eHash, ePlace){/*dbna*/
	if(!ePlace) ePlace = window;
	ePlace.location.hash = '#'+eHash;
}
function href(eUrl, ePlace){/*dbna*/
	if(!ePlace) ePlace = window;
	ePlace.location.href = eUrl;
}
function formJump(form, ePlace, restore)
{
	var order = form.jumpTo.selectedIndex;
	if (form.jumpTo.options[order].value != 0)
	{
		href(form.jumpTo.options[order].value, ePlace)
	} 
	if (restore) selObj.selectedIndex=0;
}
var errorWin=false;
function debugIt(errorMessage){
	if(debugMode == false){
		return true;
	}
	else{
		if (errorWin){
			errorWin.write(errorMessage+"<br>");
		}
		else{
			errorWin=window.open("","error","width=450,height=500,scrollbars=yes,status=yes,resizable=yes");
			errorWin=errorWin.document.open();
			errorWin.write("<html><head><title>dbna JS Error</title></head><body><pre>\n");
			errorWin.write('DTHML: '+DHTML+"<br>");
			errorWin.write('DOM: '+DHTML+"<br>");
			errorWin.write('MSIE4: '+MSIE4+"<br>");
			errorWin.write('NS4: '+NS4+"<br>");
			errorWin.write('OP: '+OP+"<br>");
			errorWin.write('Browser: '+browserName+"<br>");
			errorWin.write('Version: '+browserVer+"<br><br>");
			errorWin.write(errorMessage+"<br>");
		}
	}
}
function abbrechen(eName){/*dbna*/
		if (eName.cancelable){
			eName.preventDefault();
		}
		eName.returnValue=false;
		debugIt('Event wurde abgebrochen: ' + eName);
}
function senden(){/*dbna*/
	disableSubmit('id_submit');
	var w=elID('id_load');
	/*var old_load = w.innerHTML;
	recplaceIt('id_load', '<img src="/images/common/combar/ajax_load.gif" border="0">');*/
	var count=elID('id_content').value.length;
	if (count<1){
		alert('Bitte Nachricht eingeben');
		/*recplaceIt('id_load', old_load);*/
		enableSubmit('id_submit');
		return false;
	}
	else if (count >5000){
		alert('Es sind maximal 5000 Zeichen erlaubt');
		/*recplaceIt('id_load', old_load);*/
		enableSubmit('id_submit');
		return false;
	}
	else{
		return true;
	}
}
function isArray(object) {/*dbna*/
	if (!window.Array){ 
		return false;
	}
	else{ 
		return object.constructor == window.Array;
	}
}
function displayElement(e) {/*dbna*/
	if (typeof(e) == "string"){
		e=elID(e);
	}
	if (isArray(e)){
		for (i=0; m=e[i]; i++){
			displayElement(m);
		}
	}
	else{
		e.style.display = "";
	}
}
function hideElement(e) {/*dbna*/
	if (typeof(e) == "string"){
		e=elID(e);
	}
	if (isArray(e)){
		for (i=0; m=e[i]; i++){
			hideElement(m);
		}
	}
	else{
		e.style.display = "none";
	}
}
function displayDiv(e, eHash, ePlace) {/*dbna*/
	e=elID(e);
	if (e.style.display == "none"){
		displayElement(e);
		if (eHash) setHash(eHash, ePlace);
	}
	else{
		hideElement(e);
	}
	return false;
}
function displaySmiley(){/*dbna*/
	displayDiv('id_smileys', 'smileys', window);
	elID('id_smileys').scrollIntoView();
	return false;
}
function displayFormat(){/*dbna*/
	displayDiv('id_formats', 'formats', window);
	elID('id_formats').scrollIntoView();
	return false;
}
var firstLoadAnhang = false;
function displayAnhang(member_id, zeit, ajax){/*dbna*/
	displayDiv('id_anhang', 'anhang', window);
	if(ajax == true && firstLoadAnhang == false){
		macheRequest('/nachricht.php/anhang/' + member_id + '/' + zeit, 'id_anhang');
		firstLoadAnhang = true;
	}
	elID('id_anhang').scrollIntoView();
	return false;
}
function displayCCshortcuts(){/*dbna*/
	displayDiv('id_shortcuts', 'shortcuts', window);
	return false;
}
function displayCCforyou(){/*dbna*/
	displayDiv('id_foryou', 'foryou', window);
	return false;
}
function displayCCforshow(){/*dbna*/
	displayDiv('id_forshow', 'forshow', window);
	return false;
}
function displayCCforhere(){/*dbna*/
	displayDiv('id_forhere', 'forhere', window);
	return false;
}

function displayFavsuche(){/*dbna*/
	displayDiv('id_favsuche');
	return false;
}

function displayAdmin(){/*dbna*/
	displayDiv('id_admin');
	return false;
}

function Event_init (ePlace, eName, eAct) {/*dbna*/
	if(!ePlace){return false;}
	if (ePlace.addEventListener) {
		ePlace.addEventListener(eName, eAct, false);
		return true;
	} 
	else if (ePlace.attachEvent) {
		ePlace.attachEvent('on'+eName,eAct);
		return true;
	} 
	else {
		debugIt('Fehler bei Event ' + eName);
		return false;
	}
}
function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function windowWidth () {/*dbna*/
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document && document.documentElement && document.documentElement.clientWidth) {
		return document.documentElement.clientWidth;
	} else if (document && document.body && document.body.offsetWidth) {
		return document.body.offsetWidth;
	} else {
		debugIt('Kein windowWidth ermittelbar return windowWith()');
		return 0;
	}
}
function windowHeight () {/*dbna*/
    // Netscape-Methode
    if (window && window.innerHeight) {
        return window.innerHeight;
    // Internet-Explorer-Methode
    } else if (document && document.documentElement && document.documentElement.clientHeight) {
				return document.documentElement.clientHeight;
    // andere Browser
    } else if (document && document.body && document.body.offsetHeight){
        return document.body.offsetHeight;
		//height = document.body.clientHeight;?
    }
	//Browser unterstützt es nicht
	else{
		debugIt('Kein windowHeight ermittelbar return windowHeight()');
		return 0;
	}
}
function scrollHeight(){/*dbna*/
	var id=elID('id_content');
	if (id && id.offsetHeight) {
		return id.offsetHeight+id.offsetTop;
	} else {
		return (document.height) ? document.height : document.body.scrollHeight;
	}
}

function nachrichtSize(){/*dbna*/
	var message=elID('id_content');
	var minus = elID('id_anhang').offsetHeight + elID('id_smileys').offsetHeight + elID('id_formats').offsetHeight + elID('id_links').offsetHeight;
	if(elID('id_captcha').offsetHeight)
		minus += elID('id_captcha').offsetHeight;
	if (!message) {return false;}
	var differH=windowHeight()-scrollHeight();
	var newH=message.offsetHeight;
	newH=newH+differH-minus;
	if (newH<200) {newH=200;}
	message.style.height=newH+'px';
}

var firstInsert = false;
function insert(id, aTag, eTag) {/*dbna*/
  var input = elID(id);
  input.focus();
  if (firstInsert == false){
    firstInsert = true;
    insert(id, '', '');
  }
  /* für Internet Explorer */
  if(typeof document.selection != 'undefined') {
    /* Einfügen des Formatierungscodes */
    var bereich = document.selection.createRange();
    var insText = bereich.text;
    bereich.text = aTag + ' ' + insText + ' ' + eTag;
    /* Anpassen der Cursorposition */
    /**/bereich = document.selection.createRange();
    if (insText.length == 0) {
      bereich.move('character', -eTag.length);
    } else {
      bereich.moveStart('character', aTag.length + insText.length + eTag.length);      
    }
    bereich.select();/**/
  }
  /* für neuere auf Gecko basierende Browser */
  else if(typeof input.selectionStart != 'undefined')
  {
    /* Einfügen des Formatierungscodes */
    var start = input.selectionStart;
    var end = input.selectionEnd;
    var insText = input.value.substring(start, end);
    input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
    /* Anpassen der Cursorposition */
    /**/var pos;
    if (insText.length == 0) {
      pos = start + aTag.length;
    } else {
      pos = start + aTag.length + insText.length + eTag.length;
    }
    input.selectionStart = pos;
    input.selectionEnd = pos;/**/
  }
  /* für die übrigen Browser */
  else
  {
	var pos = input.value.length;
    input.value = input.value.substr(0, pos) + aTag /*+ insText*/ + eTag + input.value.substr(pos);
  }
  return false;
}
function validateEmail(mail){
	var a = false;
	var res = false;
	if(a == false){
		if(typeof(RegExp) == 'function'){
			var b = new RegExp('abc');
			if(b.test('abc') == true){
				a = true;
			}
		}
	}
	if(a == true){
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,6})$');
		res = (reg.test(mail));
	}
	else{
		res = (mail.search('@') >= 1 &&	mail.lastIndexOf('.') > mail.search('@') &&	mail.lastIndexOf('.') >= mail.length-7);
	}
	return res;
	//debugMode = true;
	//debugIt('mailadress: ' + mail + 'valide: ' + res);
}
function submitEmail(idMail){
	mail = elID(idMail).value;
	check = validateEmail(mail);
	if (check == true){
		return true;
	}
	else{
		alert('Die eingegebene E-Mail Adresse ist nicht im Format support@dbna.de .\nBitte gib eine gültige E-Mail Adresse an.\n\nBei Problemen wende dich an unseren Support.');
		return false;
	}
}
function typeEmail(idMail, idCheck){
	mail = elID(idMail).value;
	check = validateEmail(mail);
	if (check == true){
		//elID(idMail).style.backgroundColor = '#00FF00';
		elID('check').title='Eingegebene E-Mail Adresse ist gültig';
		elID('check').src='/images/common/icons/checkok.png';
	}
	else{
		//elID(idMail).style.backgroundColor = '#FF0000';
		elID('check').title='Eingegebene E-Mail Adresse nicht gültig';
		elID('check').src='/images/common/icons/checkfalse.png';
	}
}
function newWindow(wUrl,wName,wWidth,wHeight,ret){/*dbna*/
	new_Window = window.open(wUrl,wName,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+wWidth+',height='+wHeight);
	new_Window.focus();
	if (!ret) return false;
}
function showProfile(id, ret, mid){/*dbna*/
	var height=670;
	var width=630;
	var src = windowHeight();
	if (src){
		if (src >= 900){
			height = 670;
		}
		else if (src >= 700){
			height = 670;
		}
		else{
			height = 670;
		}
	}
	if(!mid){
		return newWindow('/kurzsteckbrief.php?id='+id, 'steckbrief_'+id, width, height, ret);
	}
	else{


		return newWindow('/steckbrief.php?id='+id, 'steckbrief_'+id, width, height, ret);
	}
}
function showPicture(imgname){/*dbna*/
	return newWindow('/show_picture.php?image='+imgname, 'img', 500, 500);
}
function showPicture2(imgname){/*dbna*/
	return newWindow('/show_picture.php?image='+imgname, 'img_'+imgname, 500, 500);
}
function showHistory(id){/*dbna*/
	return newWindow('/nachricht.php/verlauf/'+id+'/read', 'hist_'+id, 350, 450);
}
function messageIsread(id)
{
	bild = new Image();
	bild.src = "/images/common/combar/mail/mail_read.png";
	elID('messageIcon_'+id).src = bild.src;
}
function messageIsread_teamer(id)
{
	bild = new Image();
	bild.src = "/images/common/combar/mail/mail_teamer_read.png";
	elID('messageIcon_'+id).src = bild.src;
}
function sendMail(id){/*dbna*/
	return newWindow('/nachricht.php/senden/'+id+'/create', 'send_'+id, 350, 450);
}
function readMail(id, teamer){/*dbna*/
	if(teamer == true) {
		messageIsread_teamer(id);
	}
	else {
		messageIsread(id);
	}
	return newWindow('/nachricht.php/lesen/'+id+'/read', 'read_'+id, 350, 450);
}
function readneuMail(id, teamer){/*dbna*/
	if(teamer == true) {
		messageIsread_teamer(id);
	}
	else {
		messageIsread(id);
	}
	return newWindow('/nachricht_neu.php/lesen/'+id+'/read', 'read_'+id, 370, 450);
}
function resizeWindow(toHeight, fromHeight){/*dbna*/
	window.resizeTo(width, height);
}
function addfriend(id){/*dbna*/
	return newWindow('/addfriend_pop.php?profile_id='+id, 'addfriend', 200, 200);
}
function deleteFavsearch (search_id, member_id){
	return newWindow('/quick_search_save.php?link='+search_id+'&id='+member_id+'&action=delete', 'quicksuche', 300, 150);
}
function faq(id){/*dbna*/
	if (id){
		return newWindow('http://www.dbna.de/intern/service/faq/index.php?action=category&cat_id='+id, 'faq', 800, 600);
	}
	else{
		return newWindow('http://www.dbna.de/intern/service/faq/index.php', 'faq', 800, 600);
	}
}
function beschwerde(user_id, user_code){/*dbna*/
	return newWindow('/profilbeschwerde.php?user_id='+user_id+'&user_code='+user_code, 'beschwerde', 620, 340); 
}
function stamp(user_id){/*dbna*/
	return newWindow('/stamp.php?user='+user_id, 'stamp_'+user_id, 500, 500); 
}
function fakecheck(){/*dbna*/
	return newWindow('/fakecheck.php', 'fakecheck', 500, 480); 
}
function openMini(){/*dbna*/
	return newWindow('/comcenter.php?seite=mini', 'dbnaMini', 190, 550);
}
function logout(){/*dbna*/
	href("/index.php?page=logout", parent);
	return false;
}
function logoutMini(){/*dbna*/
	href("/index.php?page=logout", 'dbna');
	windowClose();
	return false;
}
function resizeWindowPicture(id) {/*dbna*/
	if(!id) id = 'idPic';
	var picWidth = elID(id).width + 150;
	var picHeight = elID(id).height + 125;
	if (picWidth<510) { picWidth=510;}
			
	var wWidth = windowWidth();
	var wHeight = windowHeight();
	if (wWidth > 0) {
		window.resizeBy(picWidth - wWidth, picHeight - wHeight)
	}
	window.focus();
}
function setFocus(id){
	elID(id).focus();
}
function windowClose(ePlace){/*dbna*/
	if(!ePlace) ePlace = this;
	ePlace.close();
}
function goBack(pages, ePlace){/*dbna*/
	if (!ePlace) ePlace = window;
	if (!pages) pages = -1;
	ePlace.history.go(pages);
	return false;
}
function over(id){/*dbna*/
	elID(id).style.fontWeight = 'normal';
	elID(id).style.color = '#F8692B';
	elID(id).style.textDecoration = 'none';
}
function out(id){/*dbna*/
	elID(id).style.fontWeight = 'normal';
	elID(id).style.color = '#FFFFFF';
	elID(id).style.textDecoration = 'none';
}
function recplaceIt(id, text){/*dbna*/
	elID(id).innerHTML = text;
}
function addIt(id, text){/*dbna*/
	elID(id).innerHTML += text;
}
function loginNick (){
	if (elID("id_login").value == ""){
		elID("id_login").value = "Nickname";
		elID("id_login").select();
	}
}
function start(){/*dbna*/
	Event_init(window, 'resize', nachrichtSize);
}
