function popup($url)
{
	var $day	= new Date();
	var $id	= $day.getTime();

	eval("page" + $id + " = window.open('" + $url + "' , '" + $id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=600,height=400,left = 400,top = 325');");
}

/**
* get HTML element by ID
*/
function g(id)
{
	if(document.getElementById(id))
	{
	   return document.getElementById(id);
	}
	else
	{
	   return false;
	}
}
function html_entity_decode(str) 
{
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}

function h($id , $effect)
{
	try
	{
		switch ($effect)
		{
			case 'BlindUp':

				new Effect.BlindUp($id);

				break;

			case 'Fade':

				new Effect.Fade($id);

				break;

			default:
				if($($id) != undefined)
				{
					$($id).style.display = 'none';
				}
				
		}
	}
	catch($e)
	{		
		$($id).style.display = 'none';
	}
}


function s($id , $effect)
{
	try
	{
		switch ($effect)
		{
			case 'Appear':

				new Effect.Appear($id);

				break;

			case 'BlindDown':

				new Effect.BlindDown($id);

				break;

			default:

				$($id).style.display = 'block';
		}
	}
	catch($e)
	{
		try
		{
			$($id).style.display = 'block';
		}
		catch(e){};
	}
}


function tog($id , $hide_effect , $show_effect)
{
	var $element = $($id);

	if (!$hide_effect)
	{
		var $hide_effect = '';
	}

	if (!$show_effect)
	{
		var $show_effect = '';
	}

	if ($element.style.display == 'none')
	{
		s($id , $show_effect);
	}
	else
	{
		h($id , $hide_effect);
	}
}


/**
 * @desc: Checks if javascript is enabled
 */
function check_js(element)
{
	if ($(element))
	{
		h(element + '_nojs');
		s(element);
	}
}


/**
 * goes to page
 */
function goTo(page)
{
	location.href=page;
}

/**
 * checks if value is in array
 */
function in_array(needle, haystack)
{
	for(var i=0;i<haystack.length;i++)
	{
	   if(haystack[i] == needle)
	   {
	      return true;
	   }
	}

	return false;
}

/**
 * validates URL
 */
function isUrl(s)
{
	var v = new RegExp();

	v.compile("^[^:/?#]+://[^/?#]+\\.[a-z]{2,}[^?#]*(\\?[^#]*)?(#.*)?"    , "i");
	//          [scheme:][  //authority.tld  ][path][ ?query ] [#fragment]
	
	return v.test(s);
}

/**
 * filters out bad chars
 */
function safeName(name)
{
   name = name.replace(/ /g , '_');

   noalpha = '�����������������������������������������������������@���';
   alpha   = 'AEIOUYaeiouyAEIOUaeiouAEIOUaeiouAEIOUaeiouyAaOoAaNnCcaooa';

   for(i=0; i<alpha.length; i++)
   {
   	name = name.replace(noalpha[i], alpha[i]);
   }

   return name;
}

/**
 * creates popup page
 */
function popup(page, width, height)
{
	popupframe=window.open(page, 'popupframe', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left=100,top=60');
	popupframe.focus();
}

/**
 * select award and close popup
 */
function selectaward(date)
{
	var txtarea = window.opener.document.forms[0]["award_date"];

	txtarea.value = date;

	txtarea.focus();

	self.close();
}

/**
 * adds a contribution to favorites
 */
function addContributionToFavorites(objectId)
{
   if(confirm(lang.addContributionToFavorites))
   {
      alert('nog te doen');
   }
}

/**
 * change height of HTML element
 */
function changeSize(id, offset, minSize)
{
   // get element
   el = id;

   // if element is an id and not a reference: get reference
   if ($(id))
   {
      el = $(id);
   }

   // set minimum size
   if (minSize == undefined)
   {
      minSize = 77;
   }

   // get height
   height = parseInt(el.style.height);

   if(!height && el.offsetHeight)
	{
		height = el.offsetHeight;
	}

	// calculate new height
	height += offset;

	if(height <= minSize)
	{
	   height = minSize;
	}

	// set new height
   el.style.height = height+"px";
}

/**
 * change TinyMCE textarea
 */
function changeTinyMCESize(textareaId, offset)
{
   var el = $(textareaId);
   var parent = el.parentNode;
   var set = false;
   var nEditor = 0;

   // expand table
   for(var i in parent.childNodes)
   {
      // if this is first element of tiny_mce
      if (set)
      {
         // table from tiny_mce
         table = parent.childNodes[i].firstChild;

         // get id for iframe
         nEditor = parent.childNodes[i].id;
         nEditor = nEditor.substr(11, 1);
         nEditor = 'mce_editor_' + nEditor;

         // set sizes
         changeSize(table, offset);
         changeSize(nEditor, offset);

         // sizes are set
         set = false;
      }
      // this is the textarea we made in a .tpl
      if (parent.childNodes[i].id == el.id)
      {
         // set = true (so next item is a span of tiny_mce)
         set = true;
      }
   }
}
function getCheckedValue(radioObj) 
{	
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
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);
}

function lang_text(key)
{
	if(typeof lang_strings == 'undefined' || typeof lang_strings[key] == 'undefined')
	{
		return '[='+key+'=]';
	}
	else if(lang_strings[key] == '')
	{
		return '[~'+key+'~]';
	}
	else
	{
		return lang_strings[key];
	}
}

function DialogOverlay(content, contentHeader, container) {
	 
	// Manage arguments and assign defaults,
	if (typeof container == 'undefined' ) container = document.body;
	if (null == (this.container = $(container))) throw("container is not valid");
 
	// Assign instance variables
	this.content = content;
	this.overlay = new Element('div', { 'class': 'overlay' }).hide();
	this.header = new Element('div', {'class': 'dialogHeader'}).hide();
	this.dialog = new Element('div', { 'class': 'dialog' }).hide();
 
	// Hide the overlay when clicked. Ignore clicks on the dialog.
	Event.observe(this.overlay, 'click', this.hide.bindAsEventListener(this));
	Event.observe(this.dialog, 'click',  function(event) { Event.stop(event); });
 
	// Insert the elements into the DOM
	this.dialog.insert(this.content);
	this.header.insert(contentHeader);
	this.container.insert(this.overlay);
	this.container.insert(this.header);
	this.container.insert(this.dialog);
 
	// Content may have been hidden if it is embedded in the page
	content.show();
	this.dialog.hide();
}
 
DialogOverlay.prototype.show = function(url) {
	if(url != undefined){
		var iframe = this.dialog.firstChild.lastChild;
		iframe.setAttribute('src',url);
	}
	new Effect.Appear(this.overlay, { duration: 0.5,  to: 0.8 });
	this.dialog.show();
	this.dialog.firstChild.show();
	this.header.show();
	this.header.firstChild.show();
	return this;
};
DialogOverlay.prototype.hide = function(event) {
	this.dialog.hide();
	this.overlay.hide();
	this.header.hide();
	return this;
};