// Zeigt eine Variable im Debugfenster an
function showConfirm(url, text)
{
  check = confirm(text);
  if (check == true)
  {
    location.href = url;
  }
}
function debug(i) {
	if(e=$('jsDebug'))
		e.innerHTML = e.innerHTML+"<hr />"+i;
}

function appSend(form,target,action) {
  if(form) {
    if(action)
      form.action = action;
    form.request({
      onSuccess: function(transport) {
        $(target).innerHTML = transport.responseText;
      }
    })
  }
}

var appAfterLoad = '';
function appLoader(url, targetElement) {
    $(targetElement).innerHTML = '<div style="background:url(/wGlobal/layout/img/ico/load.gif) no-repeat center;height:50px;">&nbsp;</div>';
    if(appAfterLoad)
      new Ajax.Request(url, {
  		method: 'get',
          onSuccess: function(transport) {
              $(targetElement).innerHTML = transport.responseText;
              eval(appAfterLoad);
              appAfterLoad = '';
          }
      });
    else
      new Ajax.Request(url, {
  		method: 'get',
          onSuccess: function(transport) {
              $(targetElement).innerHTML = transport.responseText;
          }
      });
}

var appTmp = '';
var appTmpId = '';
function appWindow(url,t,id,hide) {
  if (url!=undefined && url!=null && url!='') {
    appLoader(url,'appIn');
  } else if (id!=undefined && id!=null && (e=$(id))) {
    $('appIn').innerHTML = e.innerHTML;
    if (hide){
      appTmpId = id;
      appTmp = e.innerHTML;
      e.innerHTML = '';
    }
  }
  if (t!=undefined && t!=null)
    $('appTit').innerHTML = t;
  new Effect.Opacity('lOut', { from: 1.0, to: 0.6, duration: 0.4 });
  $('appOut').appear({duration:0.4});
}

function appClose() {
  $('appOut').fade({duration:0.4});
  new Effect.Opacity('lOut', { from: 0.6, to: 1.0, duration: 0.4 });
  if(appTmp!='') {
    if(e=$(appTmpId))
      e.innerHTML = appTmp;
    appTmp = '';
  }
}

function appEval(id) {
//  alert("begin eval from "+id);
  if(e=$(id)) {
//    alert(e.innerHTML);
    eval(e.innerHTML);
  }
//  alert("end eval from "+id);
}

function showLoadingImg()
{
//  var load = document.createElement("img");
//  load.src = '/apps/system/load.gif';
  var txt = document.createTextNode(" ");
  var divload = document.createElement("div");
  divload.id = 'loading';
  divload.name = 'loading';
  divload.setAttribute('style', 'background:#ffffff url("/wGlobal/layout/img/ico/load.gif") no-repeat center; scroll-position:fixed;  opacity:0.5; position:absolute; z-index:1000000; left:0; top:0; height:100%; width:100%;');
//  divload.height = '100%';
//  divload.width = '100%';
  divload.style.display = 'block';

  divload.appendChild(txt);
  document.body.appendChild(divload);
}

function hideLoadingImg()
{
  document.body.removeChild(document.body.lastChild);
  return;
}


/* Servicebox - Blendet Block ein/aus */
function togParClass(e) {
	pE = e.parentNode.parentNode;
	if(pE.className == 'bContOpen')
		pE.className = 'bContClose';
	else
		pE.className = 'bContOpen';
}

/* Blendet Boxcontent/-lead ein/aus */
function changeBox(nr,req) {
	eL = gE('zL'+nr);
	eR = gE('zR'+nr);
	eB = gE('zB'+nr);
	if(eL) {
		c=eL.parentNode.childNodes;
		for(i=0;i<c.length;i++){
			if(c[i].id && c[i].id=='zL'+nr)c[i].style.display='block';
			else if(c[i].id)c[i].style.display='none';
		}
	}
	if(eR) {
		c=eR.parentNode.childNodes;
		for(i=0;i<c.length;i++){
			if(c[i].id && c[i].id=='zR'+nr)c[i].className='bRa';
			else if(c[i].id)c[i].className='bRi';
		}
	}
	if(eB) {
		c=eB.parentNode.childNodes;
		for(i=0;i<c.length;i++){
			if(c[i].id && c[i].id=='zB'+nr)c[i].style.display='block';
			else if(c[i].id)c[i].style.display='none';
		}
	}
	if(req!=null)
		appLoader(req,'zB'+nr);
}

/* Setzt die Symbole bei einem Radio-select und setzt den Wert ins hidden-Field */
function setRate(e,nr) {
	c=e.parentNode.parentNode.childNodes;
	for(i=0;i<c.length;i++){
		if((i+1)<=nr) c[i].childNodes[0].className = 'eROnHov';
		else if(c[i].tagName=='DIV') c[i].childNodes[0].className = 'eRUnset';
	}
	c[(i-1)].value = nr;
}

/* Tooltipp - schreibt Events in Links */
function setToolEvents() {
	l = document.getElementsByTagName('a');
	for(i=0;i<l.length;i++) {
		//alert(i+"= href:"+e.href);
		c = null;
		if(l[i].className == 'tooltip' || l[i].className == 'tooltipBox' || l[i].className == 'tooltipExt') {
			if(l[i].className == 'tooltipExt') {
				if(l[i].href!='')
					c = function () {Tip(function () {getTip(this.href);});};
				l[i].removeAttribute('href');
			} else if(l[i].title!=''){
				c = function () {this.last_title = this.title;Tip(this.title,WIDTH, 255, SHADOW, true, FADEIN, 300, FADEOUT, 300, STICKY, 1, CLOSEBTN, true, CLICKCLOSE, true);};
			}
			if(c!=null) {
				l[i].onmouseout = function () {UnTip();this.title = this.last_title;};
				l[i].onmouseover = c;
			}
		}
	}
}
document.observe('dom:loaded', setToolEvents);

function gE(name)
{
	return document.getElementById(name);
}

function getObjPos (o)
{
    var r = { top:0, left:0, width:0, height:0 };

    if(!o) return r;
    else if(typeof o == 'string' ) o = document.getElementById(o);

    if( typeof o != 'object' ) return r;

    if(typeof o.offsetTop != 'undefined')
    {
         r.height = o.offsetHeight;
         r.width = o.offsetWidth;
         r.left = r.top = 0;
         while (o && o.tagName != 'BODY')
         {
              r.top  += parseInt( o.offsetTop );
              r.left += parseInt( o.offsetLeft );
              o = o.offsetParent;
         }
    }
    return r;
}

function setBewertung(bewertung, re_id)
{
	window.location.href = "http://localhost/cma/zend/Rezept/bewertung/bew/" + bewertung + "/id/" + re_id;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Textbox mit Tabs
//
////////////////////////////////////////////////////////////////

var oldDivId = Array();
var oldThisObj = Array();

function tabShow(boxid,showdivid,thisobj){

  if (oldThisObj[boxid]){
    oldThisObj[boxid].className  = "eBoxTxtLnk";
  }

  if (oldDivId[boxid]){
    document.getElementById("eBoxTxtCon_" + oldDivId[boxid] + "_" + boxid).style.display = "none";
  }

  document.getElementById("eBoxTxtCon_1" + "_" + boxid).style.display = "none";
  document.getElementById("eBoxTxtCon_" + showdivid + "_" + boxid).style.display = "block";

  document.getElementById("eBoxTxtLnk_1" + "_" + boxid).className = "eBoxTxtLnk";
  thisobj.className  = "eBoxTxtLnkAkt";

	oldDivId[boxid] = showdivid;
	oldThisObj[boxid] = thisobj;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Textbox mit Expander
//
////////////////////////////////////////////////////////////////

var oldDivIdExp = Array();
var oldThisObjExp = Array();
var oldDivIdExpLnk = Array();

function expanderShow(boxid,showdivid,thisobj,ExpLinkId){

	if (thisobj){
		if(thisobj.className == "lArrExpRig"){
			thisobj.style.display  = "none";
			if (oldDivIdExpLnk[boxid]){
				if(oldDivIdExpLnk[boxid] != showdivid){
					document.getElementById("eBoxExpLnk_" + oldDivIdExpLnk[boxid] + "_" + boxid).style.display = "block";
				}
			}
		}else{
			document.getElementById("eBoxExpLnk_" + showdivid + "_" + boxid).style.display = "block";
		}
  }

		if (showdivid == oldDivIdExp[boxid]){
			if(document.getElementById("eBoxExp_" + showdivid + "_" + boxid).style.display == "block"){
				document.getElementById("eBoxExp_" + showdivid + "_" + boxid).style.display = "none";
				if (oldThisObj[boxid]){
					oldThisObj[boxid].style.display  = "block";
				}
			}else{
				document.getElementById("eBoxExp_" + showdivid + "_" + boxid).style.display = "block";
			}
		}else{
			document.getElementById("eBoxExp_" + showdivid + "_" + boxid).style.display = "block";
			if(oldDivIdExp[boxid]) {
				document.getElementById("eBoxExp_" + oldDivIdExp[boxid] + "_" + boxid).style.display = "none";
			}
		}
		oldDivIdExp[boxid] = showdivid;
		oldThisObjExp[boxid] = thisobj;
		if(ExpLinkId){
			oldDivIdExpLnk[boxid] = ExpLinkId;
		}
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Textbox zum Ausklappen
//
////////////////////////////////////////////////////////////////
function aufklappenShow(boxid,thisobj){
	if (document.getElementById("eBoxAufTit" + "_" + boxid).style.display == "block"){
		document.getElementById("eBoxAufTit" + "_" + boxid).style.display = "none";
		document.getElementById("bTRTab" + "_" + boxid).style.backgroundImage = "none";
		document.getElementById("bTL" + "_" + boxid).style.backgroundImage = "none";
		if (thisobj){
			thisobj.className = "lArrExpRigWhi";
		}
	}else{
		document.getElementById("eBoxAufTit" + "_" + boxid).style.display = "block";
		document.getElementById("bTRTab" + "_" + boxid).style.backgroundImage = "url(/wGlobal/layout/img/bg/bgbr.gif)";
		document.getElementById("bTRTab" + "_" + boxid).style.backgroundRepeat = "no-repeat";
		document.getElementById("bTRTab" + "_" + boxid).style.backgroundPosition = "right 0px";
		document.getElementById("bTL" + "_" + boxid).style.backgroundImage = "url(/wGlobal/layout/img/bg/bgbl.gif)";
		if (thisobj){
			thisobj.className = "lArrExpDowWhi";
		}
	}
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Attikboxen
//
////////////////////////////////////////////////////////////////
var oldAttId = '';
var oldAttType = '';
var oldnext1Id = '';
var oldnext2Id = '';
function showAtt(attType,attId){

	next1attId = attId + 1;
	next2attId = attId + 2;

	//Verarbeitung Old Attik Element
	if(oldAttId){
		if(oldAttType == "eAttBoxTea_" || oldAttType == "eAttBoxClo_" || attType == "eAttBoxOpeBckLnk"){
			Effect.BlindUp("eAttBoxOpe_" + oldAttId,{duration: 0.3});
			//document.getElementById("eAttBoxOpe_" + oldAttId).style.display = "none";
			document.getElementById("eAttBoxClo_" + oldAttId).style.display = "block";
		}

		if(document.getElementById("eAttBoxClo_" + oldnext1Id)){
			document.getElementById("eAttBoxClo_" + oldnext1Id).style.display = "block";
			document.getElementById("eAttBoxTea_" + oldnext1Id).style.display = "none";
		}
		if(document.getElementById("eAttBoxClo_" + oldnext2Id)){
			document.getElementById("eAttBoxClo_" + oldnext2Id).style.display = "block";
			document.getElementById("eAttBoxTea_" + oldnext2Id).style.display = "none";
		}

	}

	//Reser Start Status
	if (attType == "eAttBoxOpeBckLnk"){
		next1attId=1;	next2attId=2;
	}
	if(document.getElementById("eAttBoxTea_" + next1attId)){
		document.getElementById("eAttBoxClo_" + next1attId).style.display = "none";
		document.getElementById("eAttBoxTea_" + next1attId).style.display = "block";
	}
	if(document.getElementById("eAttBoxTea_" + next2attId)){
		document.getElementById("eAttBoxClo_" + next2attId).style.display = "none";
		document.getElementById("eAttBoxTea_" + next2attId).style.display = "block";
	}

	//Verarbeitung New Attik Element
	if(attType != "eAttBoxOpeBckLnk"){
		Effect.BlindUp(attType + attId,{duration: 0.3});
		//document.getElementById(attType + attId).style.display = "none";
	}

	//Delet Start Status
	if(document.getElementById("eAttBoxTea_" + 1) != '' && next1attId != 1 && next2attId != 1 && attId != 1){
		document.getElementById("eAttBoxTea_" + 1).style.display = "none";
		document.getElementById("eAttBoxClo_" + 1).style.display = "block";
	}
	if(document.getElementById("eAttBoxTea_" + 2) != '' && next1attId != 2 && next2attId != 2 && attId != 2){
		document.getElementById("eAttBoxTea_" + 2).style.display = "none";
		document.getElementById("eAttBoxClo_" + 2).style.display = "block";
	}


	if(attType == "eAttBoxTea_"){
		//Teaser
		Effect.BlindDown("eAttBoxOpe_" + attId,{duration: 0.3});
		//document.getElementById("eAttBoxOpe_" + attId).style.display = "block";
		document.getElementById("eAttBoxClo_" + attId).style.display = "none";
	}
	if(attType == "eAttBoxClo_"){
		//Closed Link
		Effect.BlindDown("eAttBoxOpe_" + attId,{duration: 0.3});
		//document.getElementById("eAttBoxOpe_" + attId).style.display = "block";
	}
	if(attType == "eAttBoxOpeBckLnk"){
		Effect.BlindDown('eAttHeaImg',{duration: 0.3});
		//document.getElementById("eAttHeaImg").style.display = "block";
	}else{
		Effect.BlindUp("eAttHeaImg",{duration: 0.3});
		//document.getElementById("eAttHeaImg").style.display = "none";
	}

	//Old Zuweisungen
  oldnext1Id = next1attId;
  oldnext2Id = next2attId;
	oldAttId = attId;
	oldAttType = attType;
}
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/
/********************************************************************************/

function getObjPos (o)
{
    var r = { top:0, left:0, width:0, height:0 };

    if(!o) return r;
    else if(typeof o == 'string' ) o = document.getElementById(o);

    if( typeof o != 'object' ) return r;

    if(typeof o.offsetTop != 'undefined')
    {
         r.height = o.offsetHeight;
         r.width = o.offsetWidth;
         r.left = r.top = 0;
         while (o && o.tagName != 'BODY')
         {
              r.top  += parseInt( o.offsetTop );
              r.left += parseInt( o.offsetLeft );
              o = o.offsetParent;
         }
    }
    return r;
}

/*function setBewertung(bewertung, re_id)
{
	window.location.href = "http://localhost/cma/zend/Rezept/bewertung/bew/" + bewertung + "/id/" + re_id;
}*/

function sendMail(r_id, titel)
{
	 subject = "Rezept von www.cma.de";
	 body = "Hier ein tolles Rezept von www.cma.de\n " + window.location;
	 var a = false;
	 var res = 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,4})$');
	  res = (reg.test(gE('friendmail').value));
	 }
	 else
	 {
	   res = (gE('friendmail').value.search('@') >= 1 &&
	   s.lastIndexOf('.') > gE('friendmail').value.search('@') &&
	   s.lastIndexOf('.') >= gE('friendmail').value.length-5)
	 }

	 if (res == false)
	 {
	   appWindow('', 'E-Mail Prüfung', 'emailmsg')
//       alert('Dies ist keine Korrekte E-Mail Adresse!');
	 }
	 else
	 {
	   email_adr = gE('friendmail').value;
	   appWindow('/apps/rezept/index/sendmailtofriend/emailadr/' + email_adr + '/r_id/' + r_id + '/r_titel/' + titel, 'E-Mail Senden', '')
//	   location.href = "mailto:" + gE('friendmail').value + "?subject="+subject+"&body=" + body;
//	   location.href = '';
	 }
}
function getRequestWochenplanForm(form, keylock)
{
//  getZutatenValue()                                                            // versendet die Daten der Zutaten box
//  alert(gE('Tabelle').getElementsByTagName("td")[0].innerHTML);
  $(form).request(
  {
    onSuccess: function(response)
    {
       gE('cInr').innerHTML = response.responseText;
//	    setResponseListValue(response.responseText);
    }
  });
}


function getRequestSaisonString(str, urlStr)
{
  if (str != "")
    var url = '/apps/'+urlStr+'/id/'+str+'/';
  else
    var url = '/apps/'+urlStr+'/';
  showLoadingImg();

  new Ajax.Request(url,
  {
    method: 'get',
    onSuccess: function(transport)
    {
//      alert(transport.responseText);
      setDetailValue(transport.responseText);
      hideLoadingImg();
    }
  });
}


/**
 * Bereitet das erw. Rezeptsuchformular auf das Senden vor
 */
function setRecipeExtForm(form) {
  if (gE('ckb_allezutaten') && gE('ckb_allezutaten').checked == true) {
    gE('allezutaten').value = 1;
  }
    getZutatenValue();  // schreibt die Zutaten in das Zutatenfeld (hidden)
  return true;
}

/**
 * Ajax aufruf mit Prototype
 */
function getRequestServiceBoxForm(form, keylock)
{
//  getZutatenValue()                                                            // versendet die Daten der Zutaten box
//  alert(gE('Tabelle').getElementsByTagName("td")[0].innerHTML);
  $(form).request(
  {
    onSuccess: function(response)
    {
//      gE('zutatenliste').style.display = 'none';
      gE('cInr').innerHTML = response.responseText;
	  }
  });
}

function getRequestKommentar(form, keylock)
{
//  getZutatenValue();                                                            // versendet die Daten der Zutaten box
//  alert(gE('Tabelle').getElementsByTagName("td")[0].innerHTML);
  $(form).request(
  {
    onSuccess: function(res)
    {
//      alert(res.responseText);
      setKommentarValue(res.responseText);
    }
  });
}


function getRequestString(str, urlStr)
{
  if (str != "")
    var url = '/apps/'+urlStr+'/id/'+str+'/';
  else
    var url = '/apps/'+urlStr+'/';
  showLoadingImg();

  new Ajax.Request(url,
  {
    method: 'get',
    onSuccess: function(transport)
    {
      setDetailValue(transport.responseText);
      hideLoadingImg();
    }
  });
}

function setDetailValue(val)
{
  if (gE('result_list'))
    gE('result_list').style.display = 'none';

  if (gE('search'))
    gE('search').style.display      = 'none';

  if (gE('detail'))
  {
    gE('detail').innerHTML          = val;
  }
  else
  {

    gE('cInr').innerHTML            = val;
  }
}

function setResponseValue(val)
{
  gE('search').style.display  = 'none';
  alert("tets " + screen.width);
  gE('result_list').style.left  = (screen.width / 2) + "px";
  gE('result_list').style.top   = (screen.height / 2) + "px";
  gE('result_list').innerHTML = val
}

function setTextValue(text, id)
{
  gE('kat_suche').value                 = text;
  gE('kat_id').value                    = id;
  gE('result_kat_search').style.display = 'none';
}

/*******************************************************************************/
/*                  STEUERUNG DER ZUTATEN BOX                                  */
/*******************************************************************************/
/**
 * erstellt und erweitert die zutatentabelle um die eingegebenen daten
 */
lineNr = 0;
function addInputText()
{
  oldVal = gE('tmp_zutat_suche').value;
  if (oldVal != '')
  {
    gE('tmp_zutat_suche').value = '';                                           // Löscht die input box wo die zutaten eingegeben werden

    var newTr       = document.createElement("tr");                                 // Tabellen funktionen zum erstellen der Anzeige box der Zutaten
    newTr.id        = "tr" + lineNr;
    var newTd       = document.createElement("td");
    newTd.id        = "zutat";
    var delTd       = document.createElement("td");
    delTd.setAttribute('align', 'right');
//    delTd.id = "td2";

    var newTdText   = document.createTextNode(oldVal);
    newTd.appendChild(newTdText);

    var delTdText   = document.createTextNode('Entfernen');

    var link        = document.createElement("a");
    link.href       = "javascript:delTableRow('" + lineNr + "')";               // integriert den Funktionsaufruf zum löschen der row
    link.appendChild(delTdText);
    delTd.appendChild(link);

    newTr.appendChild(newTd);
    newTr.appendChild(delTd);

    document.getElementById("Tabelle").appendChild(newTr);
    lineNr++;

    thisObj = getObjPos(gE('tmp_zutat_suche'));
    gE('zutatenliste').style.top     = (thisObj.top) + "px";
    gE('zutatenliste').style.left    = (thisObj.left - 203) + "px";

//    gE('zutatenliste').style.left = 500;                                        // positionieren der Zutatenbox
//    gE('zutatenliste').style.top = 200;
    gE('zutatenliste').style.display = 'block';

//    gE('tmp_zutat_suche').focus();
  }
}

/**
 * funktion zum löschen einer Zeile in der Tabelle
 * @param integer row
 */
function delTableRow(row)
{
  gE('tr' + row).parentNode.removeChild(gE('tr' + row));
}

/**
 * zum abfangen der Return Taste. Wird diese ausgelösst wird ein eintrag in
 * der Zutatenbox erstellt
 * @param event Ereignis
 */
function onKeyPress(Ereignis)
{
  if (!Ereignis)
  {
    Ereignis = window.event;
  }
  if (Ereignis.keyCode == 13)
  {
    addInputText();                                                             // eintrag in die Tabellen Box
  }
}

/**
 * liest alle daten aus der Tabelle aus. Dies geschieht vor dem senden der
 * Formular informationen. die Daten werden in ein Hidden Textfeld geschrieben
 * und versendet.
 */
function getZutatenValue()
{
  if (!gE('Tabelle'))
   return;

  trLength = gE('Tabelle').getElementsByTagName("tr").length;
  gE('zutat_suche').value = '';

  for (i=0; i<= trLength; i++)                                                  // alle Tabellen inhalte einlesen
  {
    valTr = gE('Tabelle').getElementsByTagName("tr")[i];

    if (valTr != undefined)
      gE('zutat_suche').value = gE('zutat_suche').value + valTr.getElementsByTagName("td")[0].innerHTML + ",";
  }

  if (gE('tmp_zutat_suche').value != '')                                        // falls das eingabefeld nicht hinzugefügt wurde. wird dies noch gemacht
  {
    gE('zutat_suche').value = gE('zutat_suche').value + gE('tmp_zutat_suche').value + ","
  }

  gE('zutatenliste').style.display = 'none';
}


function getKommentarData(r_id)
{
  getRequestKommentar('alle_kommentare', false);
//  gE('overviewcomment').style.display = 'none';

}

function setKommentarValue(responseVal)
{
  if (gE('k_anzeigen').innerHTML != '')
  {
    gE('k_anzeigen').innerHTML = '';
    return;
  }
  valarr = eval(responseVal);
  document.getElementById("full_kommentare").innerHTML = '';
  for (i=0; i <= valarr.length-1; i++)
  {
    var newTr           = document.createElement("tr");                                 // Tabellen funktionen zum erstellen der Anzeige box der Zutaten
    newTr.id            = "tr" + lineNr;

    var bildTd          = document.createElement("td");
    bildTd.setAttribute("width", "40px");

    var userInfoTd      = document.createElement("td");
    userInfoTd.setAttribute("width", "60px");

    var datumTd         = document.createElement("td");
    datumTd.setAttribute("width", "120px");

    var kommentarTd     = document.createElement("td");
    kommentarTd.setAttribute("width", "350px");

    var bildTdText   = document.createElement("img");
    bildTdText.src = gE('bild_pfad').value + valarr[i]['b_image'];
    bildTdText.setAttribute("width", "40px");
    bildTd.appendChild(bildTdText);

    var userInfoTdText   = document.createTextNode(valarr[i]['b_nutzername']);
    userInfoTd.appendChild(userInfoTdText);

    var datumTdText   = document.createTextNode(valarr[i]['create_date']);
    datumTd.appendChild(datumTdText);

    var komTdText   = document.createTextNode(valarr[i]['rc_comment']);
    kommentarTd.appendChild(komTdText);

    newTr.appendChild(bildTd);
    newTr.appendChild(userInfoTd);
    newTr.appendChild(datumTd);
    newTr.appendChild(kommentarTd);

    document.getElementById("full_kommentare").appendChild(newTr);
    lineNr++;
  }
  gE('k_anzeigen').innerHTML = gE('overviewcomment').innerHTML;
//  appWindow('', 'Alle Kommentare zu diesem Rezept', 'overviewcomment');
}

function showCooksteps(show,num) {
  for (i=1; i <= num; i++) {
    if(e=$('txt'+i)) {
      if (show == i)
        e.style.display = 'block';
      else
        e.style.display = 'none';
    }
  }
}

function selectABC(name, alle, monatNr)
{
  param_1 = '';
  param_2 = '';
  if (alle)
    param_1 = '&alle=' + alle;
  if (monatNr)
    param_2 = '&monatNr=' + monatNr;

  var tmp_str =  String(location);
  try
  {
    loc_arr = tmp_str.split("?");
  }
  catch(e){}

  if (gE(name).value == 1)
  {
    location.href = loc_arr[0] + '?alle=1&abc=';
    return;
  }
  if (gE(name).value == 2)
  {
    location.href = loc_arr[0] + '?alle=&abc=';
    return;
  }
  location.href = loc_arr[0] + '?abc=' + gE(name).value + param_1 + param_2;
}

/************************KOCHGURPPEN*********************************************/
b_id_kochgruppe = '';
kochgruppe_arr = new Array();
function setKochgruppen(id_kochgruppe)
{
  kochgruppe_arr.push(id_kochgruppe);
}

function showKochgruppen(b_id)
{
  appWindow('', 'Kochgruppen', 'kochgruppen');
//  gE('kochgruppen').style.display = 'block';
  b_id_kochgruppe = b_id;
}

function sendAdd()
{
  appLoader('/apps/kochgruppe/addmember/?add=' + b_id_kochgruppe + '&id_kochgruppe=' + kochgruppe_arr.join(","), 'appIn');

//  location.href = '/content/community/kochgruppen.php?add=' + b_id_kochgruppe + '&id_kochgruppe=' + kochgruppe_arr.join(",");
//  location.href = '/content/community/kochgruppen.php?mygroups=1';
}

function toKochgruppe(b_id, k_id)
{
  appWindow('/apps/kochgruppe/addmember/?add=' + b_id + '&id_kochgruppe=' + k_id, 'Kochgruppe beitreten');
//  alert('test');
//  location.href = '/content/community/kochgruppen.php?add=' + b_id_kochgruppe + '&id_kochgruppe=' + kochgruppe_arr.join(",");
//  location.href = '/content/community/kochgruppen.php?mygroups=1';
}
function showAllComment(id)
{
  getAllComment('', 'kochgruppe/index/allcomment/1/event_id/'+id);
}
function getAllComment(str, urlStr)
{
  if (str != "")
    var url = '/apps/'+urlStr+'/id/'+str+'/';
  else
    var url = '/apps/'+urlStr+'/';
  showLoadingImg();

  new Ajax.Request(url,
  {
    method: 'get',
    onSuccess: function(transport)
    {
//      var arr = new Array;
      setGruppenKommentare(transport.responseText)
      hideLoadingImg();
    }
  });
}
function setGruppenKommentare(responseVal)
{
  valarr = eval(responseVal);
  document.getElementById("full_kommentare").innerHTML = '';
  for (i=0; i <= valarr.length-1; i++)
  {
    var newTr           = document.createElement("tr");                                 // Tabellen funktionen zum erstellen der Anzeige box der Zutaten
    newTr.id            = "tr" + lineNr;

    var bildTd          = document.createElement("td");
    bildTd.setAttribute("width", "40px");

    var userInfoTd      = document.createElement("td");
    userInfoTd.setAttribute("width", "60px");

    var datumTd         = document.createElement("td");
    datumTd.setAttribute("width", "120px");

    var kommentarTd     = document.createElement("td");
    kommentarTd.setAttribute("width", "350px");

    var bildTdText   = document.createElement("img");
    bildTdText.src = gE('bild_pfad').value + valarr[i]['b_old_id'];
//    alert(gE('bild_pfad').value + valarr[i]['b_old_id']);
    bildTdText.setAttribute("width", "40px");
    bildTd.appendChild(bildTdText);

    var userInfoTdText   = document.createTextNode(valarr[i]['b_nutzername']);
    userInfoTd.appendChild(userInfoTdText);

    var datumTdText   = document.createTextNode(valarr[i]['date_created']);
    datumTd.appendChild(datumTdText);

    var komTdText   = document.createTextNode(valarr[i]['comment_text']);
    kommentarTd.appendChild(komTdText);

    newTr.appendChild(bildTd);
    newTr.appendChild(userInfoTd);
    newTr.appendChild(datumTd);
    newTr.appendChild(kommentarTd);

    document.getElementById("full_kommentare").appendChild(newTr);
    lineNr++;
  }
  appWindow('', 'Alle Kommentare zu Treffen', 'alle_kommentare', true);
}
function setKommGroup(id)
{
  appWindow('', 'Treffen Kommentieren', 'kommentar', true);
  gE('kommentar_group_id').value = id;
}

function mitmachenKochgruppen(user_id, gruppe_id)
{
  appWindow('/apps/kochgruppe/index/add/'+user_id+'/id_kochgruppe/'+gruppe_id, 'Kochgruppe beitreten');
  return;
  if (gruppe_id)
    setMember('', 'kochgruppe/index/add/'+user_id+'/id_kochgruppe/'+gruppe_id);
  else
    location.href = '/content/community/kochgruppen.php?suche=1&b_id=' + user_id;
}
function setMember(str, urlStr)
{
  if (str != "")
    var url = '/apps/'+urlStr+'/id/'+str+'/';
  else
    var url = '/apps/'+urlStr+'/';
  showLoadingImg();

  new Ajax.Request(url,
  {
    method: 'get',
    onSuccess: function(transport)
    {
//      var arr = new Array;
//      alert(transport.responseText);

//      appWindow('/apps/message/send?appLoad&uid='+id, 'Nachricht senden');
      hideLoadingImg();
    }
  });
}

lineZutatNr = 5;
function addZutatenBox()
{

  var newTr           = document.createElement("tr");                                 // Tabellen funktionen zum erstellen der Anzeige box der Zutaten
//  newTr.id            = "tr" + lineNr;

  var leerTd          = document.createElement("td");
  newTr.appendChild(leerTd);
  var zutatTd          = document.createElement("td");
  newTr.appendChild(zutatTd);
  var zutat2Td          = document.createElement("td");
  newTr.appendChild(zutat2Td);

  var inputTd = document.createElement("input");
  inputTd.name = "anzahl" + lineZutatNr
  inputTd.className = "input";
  zutatTd.appendChild(inputTd);

  var input2Td = document.createElement("input");
  input2Td.name = "zutat" + lineZutatNr
  input2Td.className = "input";
  zutat2Td.appendChild(input2Td);

  document.getElementById("tbl_zutat").appendChild(newTr);
  lineZutatNr++;
}

function getRequestZutat(str, urlStr)
{
  if (str != "")
    var url = '/apps/'+urlStr+'/id/'+str+'/';
  else
    var url = '/apps/'+urlStr+'/';
  showLoadingImg();

  new Ajax.Request(url,
  {
    method: 'get',
    onSuccess: function(transport)
    {
      var arr = new Array;
      changeZutat(transport.responseText);
      hideLoadingImg();
    }
  });
}

function changeZutat(json_str)
{
  json_arr = json_str.split(",");
  gE('td' + json_arr[1]).innerHTML = json_arr[0];
}


function getNewMsg() {
  if($('newMsg')) {
    new Ajax.Request('/apps/profile/getnewmsg', {
		  method: 'get',
      onSuccess: function(transport) {
        t = transport.responseText.split(';');
        e = $('newMsg')
        e.innerHTML = t[0];
        e.parentNode.title=t[1];
      }
    })
  }
}

function getNewFriends() {
  if($('newFriends')) {
    new Ajax.Request('/apps/Freunde/getnewfriends', {
		  method: 'get',
      onSuccess: function(transport) {
        t = transport.responseText.split(';');
        e = $('newFriends')
        e.innerHTML = t[0];
        e.parentNode.title=t[1];
      }
    })
  }
}

/**
 * Diese Funktion wird aufgerufen, sobald der DOM-Baum geladen wurde.
 * Hier können Funktionen aufgerufen werden, die nach dem Laden erst aufgerufen
 * werden sollen
 */
function afterLoad() {
  getNewMsg();
  getNewFriends();
}
document.observe('dom:loaded', function () { afterLoad(); });

function sendMsg(id) {
  appWindow('/apps/message/send?appLoad&uid='+id, 'Nachricht senden');
}

function toggleRezCom(rezId,page) {
  if(!rezId)
    return;
  if(!page)
    page = 0;
  if((i=$('comBoxClosed')) && (c=$('comBox'))) {
    if(!i.style.display || i.style.display=='block') {
      i.style.display='none';
      c.style.display='block';
      appLoader('/apps/rezept/index/comments/?id='+rezId+'&page='+page,'comInn');
    } else {
      c.style.display='none';
      i.style.display='block';
    }
  }
}

function setBewertungStar(nr) {
  $('bew').value = nr;
  for (i=1; i <= 5; i++) {
    if(e=$('bewStar'+i)) {
      if (nr == i)
        e.className = 'bewStarAct';
      else
        e.className = 'bewStar';
    }
  }
}
/*function goToLocation(monat, abc)
{
  alert('test');
  alert(location + "?alle=1&abc=" + abc + "&monatNr=" + monat);
  //$_SERVER['PHP_SELF'].'?alle=1&abc='.@$_GET['abc'].'&monatNr='.date('n', mktime(0, 0, 0, $cm));
  location.href = location + "?alle=1&abc=" + abc + "&monatNr=" + monat;
  document.anchors[0].name;

}*/

function getRandom(min, max) {
    if(min > max) {
        return(-1);
    }
    if(min == max ) {
        return(min);
    }
    return(min + parseInt( Math.random() * ( max-min+1 )));
}

/*  Zuletzt eingeloggte Köche  */
var last_teaser = 0;
var interval;
var interval_time = 7; //sec

function showKochDetail(nr) {
    if(kochArray[nr] != undefined) {
        $('cImage').src = '/content/profil/profilbild/'+kochArray[nr].b_id+'?size=medium';
        if(kochArray[nr].online) {
            $('cNutzername').innerHTML = '<a href="/content/profil/anzeigen/'+kochArray[nr].b_nutzername+'">'+kochArray[nr].b_nutzername+'</a>&nbsp;|&nbsp;<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[nr].gender+'on.gif"/>&nbsp;Online';
        } else {
            $('cNutzername').innerHTML = '<a href="/content/profil/anzeigen/'+kochArray[nr].b_nutzername+'">'+kochArray[nr].b_nutzername+'</a>&nbsp;|&nbsp;<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[nr].gender+'off.gif"/>&nbsp;Offline';
        }
        $('cAlter').innerHTML = kochArray[nr].alter+' Jahre';
        $('cWohnort').innerHTML = kochArray[nr].b_ort;


				if(kochArray[nr].b_suche){
					txtb_suche = '<strong>Warum ich im CMA Treffpunkt bin:</strong><p id="cWhyCMATre">'+kochArray[nr].b_suche+'</p>';
				}else{
					txtb_suche = '';
				}
				if(kochArray[nr].empfehlung){
					txtb_rezVor = '<strong>Mein Rezeptvorschlag:</strong><p id="cMeiRezVor"><strong>"'+kochArray[nr].empfehlung.titel+'"</strong><br/>'+kochArray[nr].empfehlung.comment+'</p>';
				}else{
					txtb_rezVor = '';
				}

				if(kochArray[nr].b_suche || kochArray[nr].empfehlung){
					$('eComKochStatm').innerHTML = '<div class="eComKochStatm">'+txtb_suche+txtb_rezVor+'</div>';
				}else{
					$('eComKochStatm').innerHTML = '<div class="eComKochStatmOhne"></div>';
				}

        /*$('cWarum').innerHTML = kochArray[nr].b_nutzername;
        $('cRezeptvorschlag').innerHTML = kochArray[nr].b_nutzername;*/
        restartInterval(); // nächster automatischer wechsel frühestens in 7 sekunden
    }
}

function showKoeche(nr) {
	if(nr != last_teaser) {
		$('koecheBox'+last_teaser).hide();
		$('koecheBox'+nr).appear();
		last_teaser = nr;
		restartInterval();
        showKochDetail(getRandom((nr+1)*8-8, (nr+1)*8-1))
	}
}

function showNextKoeche() {
	if(last_teaser >= 2) {
		showKoeche(0);
	} else {
		showKoeche(last_teaser+1);
	}
}

function restartInterval() {
	clearInterval(interval);
	interval = setInterval(showNextKoeche, interval_time*1000);
}

function initKoeche() {
    var koecheString0 = '';
    var koecheString1 = '';
    var koecheString2 = '';

    for(var i=0; i<8;i++) {
        if(kochArray[i] != undefined) {
            if(i==7) {
                koecheString0 += '<div style="float:left;width:60px;padding:0px 8px;cursor:pointer;">';
            } else {
                koecheString0 += '<div style="float:left;width:60px;padding:0px 8px;border-right:1px dashed #999;">';
            }
            koecheString0 += '<img src="/content/profil/profilbild/'+kochArray[i].b_id+'?size=small" style="cursor:pointer;" onclick="showKochDetail('+i+')" />';
            koecheString0 += '<p><a style="display:block;color:#4D4D4D;font-weight:bold;margin:5px 0px 10px 0px;" href="#" onclick="showKochDetail('+i+')">'+kochArray[i].b_nutzername_short+'</a></p>';
            if(kochArray[i].online) {
                koecheString0 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'on.gif"/>&nbsp;Online';
            } else {
                koecheString0 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'off.gif"/>&nbsp;Offline';
            }
            koecheString0 += '<br /></div>';
        }
    }
    $('koecheBox0').innerHTML = koecheString0;

    for(var i=8; i<16;i++) {
        if(kochArray[i] != undefined) {
            if(i==15) {
                koecheString1 += '<div style="float:left;width:60px;padding:0px 8px;">';
            } else {
                koecheString1 += '<div style="float:left;width:60px;padding:0px 8px;border-right:1px dashed #999;">';
            }
            koecheString1 += '<img src="/content/profil/profilbild/'+kochArray[i].b_id+'?size=small" style="cursor:pointer;" onclick="showKochDetail('+i+')" />';
            koecheString1 += '<p><a style="display:block;color:#4D4D4D;font-weight:bold;margin:5px 0px 10px 0px;" href="#" onclick="showKochDetail('+i+')">'+kochArray[i].b_nutzername_short+'</a></p>';
            if(kochArray[i].online) {
                koecheString1 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'on.gif"/>&nbsp;Online';
            } else {
                koecheString1 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'off.gif"/>&nbsp;Offline';
            }
            koecheString1 += '<br /></div>';
        }
    }
    $('koecheBox1').innerHTML = koecheString1;

    for(var i=16; i<24;i++) {
        if(kochArray[i] != undefined) {
            if(i==23) {
                koecheString2 += '<div style="float:left;width:60px;padding:0px 8px;">';
            } else {
                koecheString2 += '<div style="float:left;width:60px;padding:0px 8px;border-right:1px dashed #999;">';
            }
            koecheString2 += '<img src="/content/profil/profilbild/'+kochArray[i].b_id+'?size=small" style="cursor:pointer;" onclick="showKochDetail('+i+')" />';
            koecheString2 += '<p><a style="display:block;color:#4D4D4D;font-weight:bold;margin:5px 0px 10px 0px;" href="#" onclick="showKochDetail('+i+')">'+kochArray[i].b_nutzername_short+'</a></p>';
            if(kochArray[i].online) {
                koecheString2 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'on.gif"/>&nbsp;Online';
            } else {
                koecheString2 += '<img alt="w" src="/wGlobal/layout/img/ico/'+kochArray[i].gender+'off.gif"/>&nbsp;Offline';
            }
            koecheString2 += '<br /></div>';
        }
    }
    $('koecheBox2').innerHTML = koecheString2;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Service Boxen aus- und einklappen
//
////////////////////////////////////////////////////////////////
function eSerBoxChaSta(elementId,thisElement,sessionEleId){
	new Effect.toggle('cSerEle_' + elementId, 'blind',{duration:0.5});
	if(thisElement.className == 'aContHeadOpe'){
		thisElement.className = 'aContHeadClo';
		param = sessionEleId+":1";
	}else{
		thisElement.className = 'aContHeadOpe';
		param = sessionEleId+":0";
	}
  new Ajax.Request('/apps/index/setservicebox?param='+param, {method: 'get'});
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Downloaden des aktuellen Bildes der Gallery
//
////////////////////////////////////////////////////////////////
function dowLoaImg(CurImgElement){
	window.open('/content/wGlobal/scripts/wDownloadDocument.php?path='+CurImgElement,'mywindow');
}

function toHref(url) {
  location.href = url;
}

var ljsf;
var schonEingebunden = ""; // Speichert die bereits eingebundenen Scripts
function loadJSFile(filename,einmaligEinbinden) {
         if (einmaligEinbinden) {
            // schon einbebunden?
            if (schonEingebunden.indexOf("|"+filename+"|")!=-1) return true;
            // Nein, in die Liste damit
            schonEingebunden = schonEingebunden + "|" + filename + "|";
         }

        // Instanz einmalig erstellen
        if (ljsf == null) ljsf = (navigator.userAgent.indexOf("MSIE")+1)?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest;

        ljsf.open('get',filename,true);
        ljsf.setRequestHeader("Connection","close");
        ljsf.onreadystatechange = function() {
                if(ljsf.readyState == 4){
                        eval(ljsf.responseText);
                }
        }
        ljsf.send(null);
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Forum auswahl
//
////////////////////////////////////////////////////////////////
function selectForum(param){
  param_1 = '';
  if (param)
    param_1 = '?sort=' + param;
  var tmp_str =  String(location);
  try{
    loc_arr = tmp_str.split("?");
  }
  catch(e){}

  location.href = loc_arr[0] + param_1;
}

////////////////////////////////////////////////////////////////
//
// Beschreibung: Forum Smilies
//
////////////////////////////////////////////////////////////////
function addCode(aTag) {
	var input = document.forms['frmAddThread'].elements['beitrag'];
	var eTag = "";
	input.focus();
	/* für Internet Explorer */
	if(typeof document.selection != 'undefined') {
		/* Einfügen des Formatierungscodes */
		var range = document.selection.createRange();
		var insText = range.text;
		range.text = aTag + insText + eTag;
		/* Anpassen der Cursorposition */
		range = document.selection.createRange();
		if (insText.length == 0) {
			range.move('character', -eTag.length);
		} else {
			range.moveStart('character', aTag.length + insText.length + eTag.length);      
		}
		range.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
	{
		/* Abfrage der Einfügeposition */
		var pos;
		var re = new RegExp('^[0-9]{0,3}$');
		while(!re.test(pos)) {
			pos = prompt("Einfügen an Position (0.." + input.value.length + "):", "0");
		}
		if(pos > input.value.length) {
			pos = input.value.length;
		}
		/* Einfügen des Formatierungscodes */
		var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
		input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
	}
}