
showModalWindow = function(content)
{
  dlg = Dialog.info(content, {width: 400, className: 'appWindows'});
}

closePopupZone = function()
{
  alert('used deprecated closePopupZone function');
}

showMessage = function(content)
{
  alert('showMessage(deprecated): '+content)
}

overlay = function()
{
  alert('overlay function is deprecated')
}

slideToggle = function(element)
{
  var element = $(element);
  var options = {duration: 0.3};
  if (typeof element.opened != undefined && element.opened) {
    new Effect.SlideUp(element, options);
    element.opened = false;
  }else{
    new Effect.SlideDown(element, options);
    element.opened = true;
  }
}

/**
* check all checkboxes with a certain class
*
*/
checkAll = function(classname, check)
{
  document.getElementsByClassName(classname).each(function(element) {
    element.checked = check;
  })
}

submitContactForm = function(actionname)
{
  var frm = $('contactfrm');
  var hidden = document.createElement('input');
  hidden.type = 'hidden';
  hidden.name = 'contactaction';
  hidden.value = actionname;
  frm.appendChild(hidden);
  frm.submit();
}

submitRequestForm = function(actionname)
{
  var frm = $('requestfrm');
  var hidden = document.createElement('input');
  hidden.type = 'hidden';
  hidden.name = 'requestaction';
  hidden.value = actionname;
  frm.appendChild(hidden);
  frm.submit();
}

getSelectValue = function(select)
{
  try {
    return select.options[select.selectedIndex].value
  }catch(e) {
    return false
  }
}

avatarUpdater = {
  pregnant: false,
  membercount: 20,
  memberlist: '',
  url: '',
  elements: [],

  getElementId: function(element)
  {
    return element.down('input').id.match(/_([0-9]+)$/).last();
  },

  getCachedDomSelection: function(element, selector)
  {
    if (typeof element.cache == 'undefined') {
      element.cache = {};
    }

    if (typeof element.cache[selector] == 'undefined') {
      element.cache[selector] = element.down(selector);
    }
    return element.cache[selector];
  },

  initialize: function(form) 
  {
    avatarUpdater.elements = new Array();
    for (i = 0; i < this.membercount+1; i++) {
      var element = $('user_' + i);
      if (element == null && i == 0) {
        var element = $('thisuser_1');
      }
      if (element != null) {
        avatarUpdater.elements.push(element);
      }
    }
    for (i = 0; i < this.membercount + 1; i++) {
      newcnt = 999 + i;
      var element = $('user_' + newcnt);
      if (element != null) {
        avatarUpdater.elements.push(element);
      }
    }

    this.elements.each(function(element) 
    {
      var id = avatarUpdater.getElementId(element);
      if (element.visible()) {
        $w('b_year role').each(function(idpart) {
          avatarUpdater.setObserved(avatarUpdater.getCachedDomSelection(element, 'select#fu_' + idpart + '_' + id))
        });
      }
    });
    avatarUpdater.setObserved($('pregnant'));
    avatarUpdater.update();
  },

  setObserved: function(element) 
  {
    if (typeof element.observed == 'undefined' || !element.observed) {
      element.observed = true;
      new Form.Element.EventObserver(element, avatarUpdater.update);
    }
  },

  update: function()
  {
    var members = avatarUpdater.elements.collect(function(element) {
      if (element.visible()) {
        var id = avatarUpdater.getElementId(element);
        var role = getSelectValue(avatarUpdater.getCachedDomSelection(element, 'select#fu_role_' + id));
        if (role > 0) {
          var member = {'role': role}
          var year = getSelectValue(avatarUpdater.getCachedDomSelection(element, 'select#fu_b_year_' + id));
          var month = getSelectValue(avatarUpdater.getCachedDomSelection(element, 'select#fu_b_month_' + id));
          var day = getSelectValue(avatarUpdater.getCachedDomSelection(element, 'select#fu_b_day_' + id));

          if (year > 0 && month > 0 && day > 0) {
            member.birthdate = year + '-' + month + '-' + day;
          }
          return member;
        }
      }
    }).compact().toJSON();
    var pregnant = $('pregnant').checked;
    if (members != avatarUpdater.memberlist || avatarUpdater.pregnant != pregnant) {
      avatarUpdater.memberlist = members;
      avatarUpdater.pregnant = pregnant;
      avatarUpdater.updateImage();
    }
  },
  updateImage: function()
  {
    $('avatarholder').src = this.url + '?json=' + escape(this.memberlist)+'&pregnant='+(this.pregnant ? 1 : 0);
  }
}

/*
2007-06-18 js (spiegel.julia@guj.de)
Hilfsskript fuer die Textareas bei bearbeiten des profils -> ueber uns
*/

/* Zaehlt, wie viele Zeichen schon ins Textfeld eingegeben wurden, und gibt einen Status darueber aus.
Ausserdem eine Fehlermeldung, wenn es mehr als 1200 Zeichen sind */
function count_textarea(text, max_chars, errorelem_id, counter_id, field_id)
{

	if (text.length >= max_chars)
	{
		$(errorelem_id).innerHTML = __('static.javascript.count_textarea.error', new Array('%COUNT%', max_chars))
		$(counter_id).innerHTML = "";
		$(field_id).value = $(field_id).value.substring(0,max_chars);
	}

	else
	{
		$(counter_id).innerHTML = __('static.javascript.count_textarea',  new Array('%COUNT%', max_chars - text.length));
		$(errorelem_id).innerHTML = "";
	}

}


/*
2007-06-20 js
f�gt ein keyword aus der liste in ein textfeld ein (familienblog-neuer eintrag)
*/
function add_keyword(word, inputfieldID)
{
	// komma rausfiltern und bei worten vorne anhaengen
	word = word.replace(', ', '');

	if ($(inputfieldID).value != '')
		$(inputfieldID).value += ", "+word;
	else
		$(inputfieldID).value += word;
}

/**********************************************************************************
*
* FUNCTIONS BELOW ARE DEPRECATED AND ONLY NEEDED IN MOCKUPS.
*
*
*
**********************************************************************************/



/*
2007-07-12 js
Gruppen -> Einladungen verschicken
Bei Klick auf "Einladen" wird die Familie zu einer Liste hinzugef�gt
*/
function add_group_invitation(strID, strName, strFamilyID)
{

	if ($(strID).innerHTML.search("invitation"+strFamilyID) == -1)
	{

		var strHTML = '<div id="invitation'+strFamilyID+'" class="invitation">'+strName+' <a class="nofloat" href="javascript: void(0)" onclick="remove_group_invitation(\''+strID+'\', \''+strName+'\', \''+strFamilyID+'\')">' + __('static.javascript.group_invitation.delete') + '</a><input type="hidden" name="invitation[]" value="'+strFamilyID+'" /></div>';

		new Insertion.Bottom($(strID),  strHTML);

		if (navigator.appName == "Microsoft Internet Explorer")
			$('count-invitations').innerHTML = $(strID).childNodes.length;
		else
			$('count-invitations').innerHTML = $(strID).childNodes.length-1;


	}
	else
		alert(__('static.javascript.group_invitation.already_exists', new Array('%NAME%', strName)));

}

/*
2007-07-12 js
Loescht einen Eintrag aus der Einladungen-Liste (Gruppen)

*/
function remove_group_invitation(strID, strName, strFamilyID)
{
	// funktioniert im IE wieder gar nicht..
	var elemDel = $('invitation'+strFamilyID);
	$(strID).removeChild(elemDel);
	if (navigator.appName == "Microsoft Internet Explorer")
			$('count-invitations').innerHTML = $(strID).childNodes.length;
		else
			$('count-invitations').innerHTML = $(strID).childNodes.length-1;


}


/*
2007-07-26 js
Slideup und Slidedown fuer Kommentare zu Videos - hier werden einige Aufrufe mehr
benoetigt als ueblicherweise, und auch von verschiedenen Stellen aufgerufen. Daher
alles in eine Funktion..
*/
function hide_video_comments(videoID)
{
	new Effect.SlideUp('comments_show_'+videoID);
	$('link_show_comments_'+videoID).style.display='block';
	$('link_hide_comments_'+videoID).style.display='none';
}

function show_video_comments(videoID)
{
	new Effect.SlideDown('comments_show_'+videoID);
	$('link_show_comments_'+videoID).style.display='none';
	$('link_hide_comments_'+videoID).style.display='block';
}


/* AKKORDEON FUNCTIONS */
slides = new Array();
slides['akkordeonMost'] = new Array('most_seen', 'most_discussed', 'most_read');
slides['akkordeonExchange'] = new Array('forum_top', 'recomm_top', 'groups_top');
slides['akkordeonTools'] = new Array('interactive_services', 'test_tools', 'lexika_tools');
var akkordeonCookieDate = new Date();
akkordeonCookieDate = new Date(akkordeonCookieDate.getTime() +1000*60*60*24);

/* set the opened/close values for the akkordeon {param akkordeonName}
   if no cookie is set then the slide {@param slideName} will be opened
*/
function initializeAkkordeonSlides(akkordeonName, slideName)
{
  cookievalue = readCookie(akkordeonName+'_openSlide');
  if(cookievalue != null) {
    slideName = cookievalue;
  }
  openAkkordeonSlide(akkordeonName, slideName, 0);
}

/* open slide {@param slideName} and close all other slides */
function openAkkordeonSlide(akkordeonName, slideName, animate)
{
  //store opened slide in cookie
  createCookie(akkordeonName+'_openSlide', slideName, 1); 
  
  if ($(slideName)) {
     if (animate != 0) {
       new Effect.SlideDown(slideName);
     }
     else {
       $(slideName).style.display='block';
     }
     $('link_'+slideName).style.display='none'
     
     for(i=0;i<slides[akkordeonName].length;i++) {
       if (slides[akkordeonName][i] != slideName) { //do not close the slide that has just been opened
         if ($(slides[akkordeonName][i]) && $(slides[akkordeonName][i]).style.display!='none') { //do not close if slide does not exist or is already closed
           closeAkkordeonSlide(akkordeonName, slides[akkordeonName][i], animate);
         }
       }
     }
  }
}

/* close slide {@param slideName} */
function closeAkkordeonSlide(akkordeonName, slideName, animate)
{
  if ($(slideName)) {
     cookievalue = readCookie(akkordeonName+'_openSlide');
     if (cookievalue == slideName) {
       eraseCookie(akkordeonName+'_openSlide');
     }
    
     if (animate != 0) {
       new Effect.SlideUp(slideName);
     }
     else {
       $(slideName).style.display='none';
     }
     $('link_'+slideName).style.display='block'
  }
}

/*
2007-06-13 js
callback funktion nach beenden des slideup-effekts+
nach eintrag eines neuen kommentars im gaestebuch

................................................................
             REMOVE ME - ONLY NEEDED FOR MOCKUPS
................................................................

*/
function submit_form_guestbook_entry_new()
{
	$('guestbook_new_btn').style.display='block';
	document.forms.guestbook_entry_new.submit();
}



/* 
 ................................................................
             COOKIE HELPERS
................................................................
*/
function createCookie(name, value, days) 
{
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}





/* 
 ................................................................
             SHOP (EXTERNAL)
................................................................
*/
/* general window opening script */
function openwindow(url,wname,w,h,scroll,resize,statusbar,menubar,toolbar,locbar)
{
 var win = null;

 LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 TopPosition = (screen.height) ? (screen.height-h)/4 : 0;
 settings = 'screenX=' + LeftPosition +
 ', screenY=' + TopPosition +
 ', left=' + LeftPosition +
 ', top=' + TopPosition +
 ', toolbar= ' + toolbar +
 ', location=' + locbar +
 ', directories=no ' +
 ', status=' + statusbar +
 ', menubar=' + menubar +
 ', resizable=' + resize +
 ', scrollbars=' + scroll +
 ', height=' + h +
 ', width=' + w;

 win = window.open(url,wname,settings);
 if(win.window.focus)
 {
 win.window.focus();
 }
}


/**********************************************************************************
*
* Login form in header and sidebar 
*
**********************************************************************************/
InputPrompt = Class.create();
InputPrompt.prototype = {
  initialize: function() {
    var obj = this;
    obj.switchPasswordField();
    obj.switchTextField();
    obj.observeOnFocus();
  },
  switchPasswordField: function() {
    var obj = this;
    $$('.inputPrompt').each(function(element) {
      if (element.name == 'password' && element.type == 'password') {
        obj.switchField(element, 'text');
      }
    });
  },
  switchTextField: function() {
    var obj = this;
    $$('.inputPrompt').each(function(element) {
      if (element.name == 'password' && element.type == 'text') {
        element.observe('focus', function() {
          obj.switchField(element, 'password', true);
        });
      }
    });
  },
  switchField: function(element, type, focus) {
    var replacement = document.createElement('input');
    replacement.type = type;
    $w('name value size maxlength id').each(function(attr) {
      var value = element.readAttribute(attr);
      if (value != null) {
        replacement[attr] = value;
      }
    });
    if (element.className != null) {
      replacement.className = element.className;
    }
    element.parentNode.insertBefore(replacement, element);
    element.remove();
    if (focus) {
      replacement.value = '';
      replacement.focus();
    }
  },
  observeOnFocus: function() {
    $$('.inputPrompt').each(function(element) {
      element.observe('focus', function() {
        if (element._cleared) {
          return;
        }
        element.clear();
        element._cleared = true;
      });
    });
  }
}

/**
 * eltTooltip class
 * Can be used to create individual layer or tooltips
 *
 * @author: Kay Schewe <schewe.kay@guj.de>
 */
var eltTooltip = Class.create();
eltTooltip.prototype = {
  initialize: function(element, markup, options) {
    this.element = element;
    this.markup = markup;
    this.options = options || {};
    this.className = this.options.className || 'eltTooltip';
    this.width = this.options.width || 200;
    this.zIndex = this.options.zIndex || 5000;
    this.position = this.options.position || 'element';
    
    this.tooltip = document.createElement('div');
    document.body.appendChild(this.tooltip);
    this.tooltip = Element.extend(this.tooltip); //< important for IE
    this.tooltip.hide();
    
    this.tooltip.className = this.className;
    this.tooltip.setStyle({
     position: 'absolute',
     left: 0+'px',
     top: 0+'px',
     width: this.width+'px',
     zIndex: this.zIndex
    });
    this.tooltip.innerHTML = this.markup;
    
    Event.observe(this.element, 'mouseover', this.show.bindAsEventListener(this));
    Event.observe(this.element, 'mouseout', this.hide.bindAsEventListener(this));
  },

  show: function(event) {
    var element = Event.element(event);
    var dim = element.getDimensions();
    var x = Event.pointerX(event) + 10;
    var y = Event.pointerY(event) + 10;
    if ('element' == this.position) {
      var pos = Position.cumulativeOffset(element);
      x = pos[0];
      y = pos[1] + 1 + dim.height;
    }
    this.tooltip.setStyle({left: x+'px', top: y+'px'});
    this.tooltip.show();
  },

  hide: function(event) {
    this.tooltip.hide();
  }
};


/**
 * Topthemen Rotated Teaser
 */
var TTTeaser = Class.create();
TTTeaser.prototype = {
  initialize: function(wrapperId, options)
  {
    this.wrapperId = wrapperId;
    this.teasers   = options.teasers || [];
    this.index     = 0;

    this.prevClass = options.prevClass || 'tt-teaser-prev';
    this.nextClass = options.nextClass || 'tt-teaser-next';

    this.teaserClass     = options.teaserClass || 'tt-teaser';
    this.titleClass      = options.titleClass || 'tt-teaser-title';
    this.headlineClass   = options.headlineClass || 'tt-teaser-headline';
    this.teasertextClass = options.teasertextClass || 'tt-teaser-teasertext';

    this.prevElement = $(this.wrapperId).down('.' + this.prevClass);
    this.prevElement.observe('click', this.changeTeaser.bindAsEventListener(this));
    this.nextElement = $(this.wrapperId).down('.' + this.nextClass);
    this.nextElement.observe('click', this.changeTeaser.bindAsEventListener(this));

    var wrapper = $(this.wrapperId);
    this.titleElement = wrapper.down('.' + this.titleClass + ' span');

    this.headlineElement = wrapper.down('.' + this.headlineClass);
    this.teasertextElement = wrapper.down('.' + this.teasertextClass + ' a');
    this.imageElement = wrapper.down('.' + this.teaserClass + ' img');
  },

  changeTeaser: function(event)
  {
    Event.stop(event);

    var element   = Event.element(event);
    var direction = element.up().hasClassName(this.prevClass) ? -1 : 1;

    this.index = this.index + direction;
    if (this.index > this.teasers.length - 1)
    {
      this.index = 0;
    }
    if (this.index < 0)
    {
      this.index = this.teasers.length - 1;
    }

    var teaser = this.teasers[this.index];

    this.titleElement.update(teaser.headline);
    this.headlineElement.update(teaser.headline);

    this.teasertextElement.update(teaser.teasertext);
    this.teasertextElement.href = teaser.url;
    this.imageElement.src = teaser.image;
  }
};


/**
 * Shop Teasers (index page and article)
 */
var ShopIndexTeaser = Class.create();
ShopIndexTeaser.prototype = {
  initialize: function(id, options) {
    this.id       = id;
    this.images   = options.images;
    this.urls     = options.urls;
    this.interval = options.interval || 2;
    this.current  = 0;
    
    var obj = this;
    Event.observe(window, 'load', function() {
      obj.startExecuter();
    });
  },
  
  startExecuter: function() {
    var obj = this;
    new PeriodicalExecuter(function() {
      var img = $(obj.id).down('img');
      img.src = obj.nextImage();
      var a = img.up('a');
      a.href = obj.nextUrl();
    }, obj.interval);
  },
  
  nextImage: function() {
    this.current++;
    if (this.current > this.images.length - 1) {
      this.current = this.images.length - this.current;
    }
    return this.images[this.current];
  },
  
  nextUrl: function() {
    return this.urls[this.current];
  }
};


/**
 * Shop Teaser (sidebar)
 */
var ShopSidebarTeaser = Class.create();
ShopSidebarTeaser.prototype = {
  initialize: function(id, options) {
    this.id          = id;
    this.images      = options.images;
    this.links       = options.links;
    this.headlines   = options.headlines;
    this.spitzmarken = options.spitzmarken;
    this.interval    = options.interval || 2;
    this.current     = 0;
    
    var obj = this;
    Event.observe(window, 'load', function() {
      obj.startExecuter();
      ['prev', 'next'].each(function(direction) {
        $$('#' + obj.id + ' .' + direction).each(function(link) {
          $(link).observe('click', function(event) {
            Event.stop(event);
            obj.exe.stop();
            
            var img        = $(obj.id).down('img', 1);
            var spitzmarke = $(obj.id).down('.spitzmarke');
            var headline   = $(obj.id).down('.headline');
            if (direction === 'prev') {
              img.src = obj.prevImage();
            }
            else {
              img.src = obj.nextImage();
            }
            img.up('a').href = obj.links[obj.current];
            headline.update(obj.headlines[obj.current]);
            headline.href = obj.links[obj.current];
            spitzmarke.update(obj.spitzmarken[obj.current]);
            
            obj.startExecuter();
          });
        });
      });
    });
  },
  
  /**
   * TODO reduce code duplication, see initialize()
   */
  startExecuter: function() {
    var obj = this;
    this.exe = new PeriodicalExecuter(function() {
      var img        = $(obj.id).down('img', 1);
      var spitzmarke = $(obj.id).down('.spitzmarke');
      var headline   = $(obj.id).down('.headline');
      
      img.src = obj.nextImage();
      img.up('a').href = obj.links[obj.current];
      headline.update(obj.headlines[obj.current]);
      headline.href = obj.links[obj.current];
      spitzmarke.update(obj.spitzmarken[obj.current]);
      
    }, obj.interval);
  },
  
  prevImage: function() {
    this.current--;
    if (this.current < 0) {
      this.current = this.images.length + this.current;
    }
    return this.images[this.current];
  },
  
  nextImage: function() {
    this.current++;
    if (this.current > this.images.length - 1) {
      this.current = this.images.length - this.current;
    }
    return this.images[this.current];
  }
};

/**
 * BabyShop Teaser (sidebar)
 */
var BabyShopSidebarTeaser = Class.create();
BabyShopSidebarTeaser.prototype = {
  initialize: function(id, options) {
    this.id          = id;
    this.images      = options.images;
    this.links       = options.links;
    this.interval    = options.interval || 2;
    this.current     = 0;
    
    var obj = this;
    Event.observe(window, 'load', function() {
      obj.startExecuter();
    });
  },
  
  /**
   * TODO reduce code duplication, see initialize()
   */
  startExecuter: function() {
    var obj = this;
    this.exe = new PeriodicalExecuter(function() {
      var img        = $(obj.id).down('img', 0);
      
      img.src = obj.nextImage();
      img.up('a').href = obj.links[obj.current];
      
    }, obj.interval);
  },
  
  prevImage: function() {
    this.current--;
    if (this.current < 0) {
      this.current = this.images.length + this.current;
    }
    return this.images[this.current];
  },
  
  nextImage: function() {
    this.current++;
    if (this.current > this.images.length - 1) {
      this.current = this.images.length - this.current;
    }
    return this.images[this.current];
  }
};
