function get_top_panel() {
  url = ('' + window.location).toLowerCase();
  var cookie_name = (url.indexOf('admin') > 0 ? '_cache_top_panel_adm' : '_cache_top_panel');
  var cookie_content = read_cookie(cookie_name, false);
  if (!cookie_content) {
    new Ajax.Request('/top_panel', {  asynchronous:true,
                                      evalScripts:true,
                                      method:'get',
                                      onSuccess: function(transport) {
                                      $('user_bar').innerHTML = transport.responseText;
                                      create_cookie_hours(cookie_name, sanitize(transport.responseText), 1);
                                    }})
  } else {
    $('user_bar').innerHTML = desanitize(cookie_content);
  }
}
function sanitize(str) {
  sanitized='';
  for (i=0;i<str.length;i++) {
    if (sanitized != '') sanitized += ':'
    sanitized += str.charCodeAt(i)
  }
  return sanitized;
}
function desanitize(str) {
  sArr = str.split(':');
  desanitized = '';
  for (i=0;i<sArr.length;i++)
    desanitized += String.fromCharCode(parseInt(sArr[i]));
  return desanitized;
}
function check_all_invitations() {
  var found = document.getElementsByClassName('invitation_email');
  for (var i = 0; i < found.length; i++) {   
    if (!found[i].disabled) {
      found[i].checked = true;
    }  
  } 
}
function uncheck_all_invitations() {
  var found = document.getElementsByClassName('invitation_email');
  for (var i = 0; i < found.length; i++) {   
    if (!found[i].disabled) {
      found[i].checked = false;
    }  
  } 
}
function get_contact_address() {
  new Ajax.Request('/contact/get_contact_mail', { asynchronous:true,
                                                  evalScripts:true,
                                                  method:'get',
                                                  onSuccess: function(transport) {
                                                    $('c_container').innerHTML = transport.responseText;
                                                }})
}
function get_adams_address() {
  new Ajax.Request('/contact/get_adams_mail', { asynchronous:true,
                                                evalScripts:true,
                                                method:'get',
                                                onSuccess: function(transport) {
                                                  $('a_container').innerHTML = transport.responseText;
                                              }})
}
function enable_user_id_form() {
  $('person_id').disabled = false;  
  $('id_form').style.display = 'block';
}
function show_message(id) {
  $('m-'+id).style.display = "block";
  $('s-'+id).style.display = "none";
  $('h-'+id).style.display = "inline";
  if ($('n-'+id)) {
  	new Effect.Fade('n-'+id);
  	new Effect.Morph('t-'+id, {style:'color:#999;'}, {duration: 0.25}); 	
  }
}
function add_css_class(element, klass) {
  if (element.className.indexOf(klass) > -1)
    return false
  element.className += ' ' + klass
  return true 
}
function get_url_vars() {
  var vars = [], hash;
  var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  for(var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
  }
  return vars;
}
function remove_css_class(element, klass) {
  if (element.className.indexOf(klass) < 0)
    return false
  element.className = element.className.replace(klass, "")
  return true
}
function is_of_css_class(element, klass) {
  return (element.className.indexOf(klass) > -1)
}
function hide_message(id) {
  $('m-'+id).style.display = "none";
  $('s-'+id).style.display = "inline";
  $('h-'+id).style.display = "none";
}
function switch_message(id) {
  if ($('m-'+id).style.display == "block") {
    hide_message(id);	
  } else {
    show_message(id);
  }
}
function log_private_view(person_id) {
  if (!read_cookie("private_view_" + person_id, false)) {
    create_cookie_hours("private_view_"+person_id, 'true', 1)
    new Ajax.Request('/new_private_view',
                     { asynchronous:true,
                       evalScripts:true,
                       method:'get',
                       parameters: {
	                     id: person_id
                       }
                      }
                     );
  } 
}
function load_recipient_thumb(id) {
  new Ajax.Request('/people/person_thumb/'+id,
				   { asynchronous:true,
		  			 evalScripts:true,
			  		 method:'get',
		 			   onSuccess: function(transport) {
					   $('recipient_thumb').innerHTML = transport.responseText;
					 }
					});
}
function load_profile_data(srcField) {
  new Ajax.Request('/privates/person_info?field='+srcField, 
                   { asynchronous:true,
		  		     evalScripts:true,
					 method:'get',
		 			 onSuccess: function(transport) {
					   $(srcField).value = transport.responseText;
                     }
                    } 
                   );  
}
function load_private_data(srcField) {
  new Ajax.Request('/people/private_info?field='+srcField, 
                   { asynchronous:true,
		  		     evalScripts:true,
					 method:'get',
		 			 onSuccess: function(transport) {
					   $(srcField).value = transport.responseText;
                     }
                    } 
                   );
}
function set_statistics_month(month) {
  $('stats_month').selectedIndex = month
} 
function load_graph() {
  type = $('stats_type').selectedIndex
  year = $('stats_year').value
  month= $('stats_month').selectedIndex
  new Ajax.Updater('graph',
                   '/privates/graph/',
                   { asynchronous:true,
                     evalScripts:true,
                     method:'get',
                     parameters: {
	                   type: type,
	                   year: year,
	                   month: month
                     }
                    }
                   );                 
}
function load_pt_graph(type) {
  if (type==0)
    tstr = 'registration';
  else
    tstr = 'time';
  year  = $('stats_'+tstr+'_year').value
  month = $('stats_'+tstr+'_month').selectedIndex
  new Ajax.Updater('people_'+tstr,
                   '/admin/statistics/graph',
                   { asynchronous:true,
                     evalScripts:true,
                     method:'get',
                     parameters: {
	                   src:"/admin/statistics/people_time_graph_code?month="+month+"&year="+year+"&type="+tstr
                     }
                   }
                  );   
}
function load_statistics_defaults() {
  d = new Date();
  $('stats_time_month').selectedIndex = d.getMonth() + 1;
  $('stats_time_year').value = d.getYear();
  $('stats_registration_month').selectedIndex = d.getMonth() + 1;
  $('stats_registration_year').value = d.getYear();
}
function roll_section(id) {
  if ($(id+'_hide').style.display == "none") {
    $(id).style.display = "block";
	$(id+'_hide').style.display = "inline";
	$(id+'_show').style.display = "none";	
  } else {
	$(id).style.display = "none";
    $(id+'_hide').style.display = "none";
    $(id+'_show').style.display = "inline";
  }
}
function error_fade(object) {
  object.morph('background:#FFF;'); 
}
function switchMailingType() {
  if($('mailing_delivery_type').value == 'relative') {
    $('type_relative').style.display = 'block';
    $('type_absolute').style.display = 'none';
  } else {
    $('type_relative').style.display = 'none';
    $('type_absolute').style.display = 'block';
  }
}
function unlock_checkbox(id) {
  object = $(id);
  if (object.checked == true) {
    object.disabled = false;
  }
}
function hide(name) {
  $(name).style.display = 'none'
}
function show(name) {
  $(name).style.display = 'block'
}
function toggle_invitations_list() {
  if ($('invitations_list').style.display == 'none') {
    show('invitations_list')
    $('invitations_list_link').innerHTML = 'ukryj listę'
  } else {
    hide('invitations_list')  
    $('invitations_list_link').innerHTML = 'pokaż listę'    
  }
}
function show_invitations_list_if_url() {
  if (("" + document.location).indexOf("#show_list") > -1 ) {
    show('invitations_list');  
    $('invitations_list_link').innerHTML = 'ukryj listę'
  }  
}
function enable_illustration_containter(number) {
  $('illustrations_'+number+'_uploaded_data').disabled = false;
  if ($('illustrations_'+number+'_caption'))  
    $('illustrations_'+number+'_caption').disabled = false;
  show('upload_containter_illustration_'+number);
}
function reg(str) {
  return new RegExp(str.replace(/\[/g, '\\[').replace(/\]/g, '\\]').replace(/\//g, '\\/'),'g')
}
function disable_illustration_container(number) {
  $('illustrations_'+number+'_uploaded_data').disabled = true;
  if ($('illustrations_'+number+'_caption'))
    $('illustrations_'+number+'_caption').disabled = true;
  hide('upload_containter_illustration_'+number);
  container = ( $('reading_content') ? $('reading_content') : $('post_body') )
  text = $("paste_source_code").innerHTML 
  if ($('illustrations_'+number+'_caption'))    
    text = text.replace(/#CAPTION#/g, $('illustrations_'+number+'_caption').value)
  text = text.replace(/#NUMBER#/g, '#IMAGE_'+number+'#')  
  container.value = container.value.replace(reg(text), '')
  $('new_container_button').disabled = false;
}
function paste_check(number) {
  $('paste_button_'+number).disabled = false
}
function disable_unused_illustration_containers() {
  while ($(elem_id = "upload_containter_illustration_" + max)) { max++; }
  max--;
  counter=0;
  while ($(elem_id = "upload_containter_illustration_" + counter)) {
    if ($(elem_id).style.display != 'none') {
      if ($('illustrations_'+counter+'_uploaded_data').value == '' 
          && $('illustrations_'+counter+'_caption').value == '') {
        disable_illustration_container(counter);
      }  
    }
    counter++;
  }
  return true;
}
function insert_at_cursor(my_field, my_value) {
    if (document.selection) { // IE
        my_field.focus();
        sel = document.selection.createRange();
        sel.text = my_value;
    } else if (my_field.selectionStart || my_field.selectionStart == '0') { 
        my_field.focus();
        var startPos = my_field.selectionStart;
        var endPos = my_field.selectionEnd;
        my_field.value = my_field.value.substring(0, startPos) + my_value + 
                         my_field.value.substring(endPos, my_field.value.length);
        my_field.setSelectionRange(endPos+my_value.length, endPos+my_value.length);
    } else {
        my_field.value += my_value;
    }
}
function paste_illustration(number) {
  if ($('illustrations_'+number+'_uploaded_data').value != '') {
    container = ( $('reading_content') ? $('reading_content') : $('post_body') )
    text = $("paste_source_code").innerHTML 
    if ($('illustrations_'+number+'_caption'))    
      text = text.replace(/#CAPTION#/g, $('illustrations_'+number+'_caption').value)
    text = text.replace(/#NUMBER#/g, '#IMAGE_'+number+'#')
    insert_at_cursor(container, text)
  } else {
    alert("Wybierz plik ilustracji")
  }
}
function show_illustration_container() {
  counter = 0; 
  max = 0;
  while ($(elem_id = "upload_containter_illustration_" + max)) { max++; }
  max--;
  while ($(elem_id = "upload_containter_illustration_" + counter)) {
    if ($(elem_id).style.display == 'none') {
      enable_illustration_containter(counter)
      if ($('illustrations_'+counter+'_uploaded_data').value != '')
        $('paste_button_'+counter).disabled = false   
      if (counter == max)
        $('new_container_button').disabled = true;
      return true;    
    }    
    counter++;
  }
}
function pick_customer_select_div() {
  if (!$('method_all').checked) {
    if ($('method_date').checked) {
      show_customer_select_div(1)
    } else {
      show_customer_select_div(2)
    }
  }
}
function show_customer_select_div(divnum) {
  switch (divnum) {
    case 0: hide('date_range'); hide('id_range'); break;
    case 1: hide('id_range'); show('date_range'); break;
    case 2: hide('date_range'); show('id_range'); break;
  }
}
function customer_export_date_set_onclick() {
  $('date_from_3i').onchange = customer_export_date_from_error_fade
  $('date_from_2i').onchange = customer_export_date_from_error_fade
  $('date_from_1i').onchange = customer_export_date_from_error_fade
  $('date_to_3i').onchange = customer_export_date_to_error_fade
  $('date_to_2i').onchange = customer_export_date_to_error_fade
  $('date_to_1i').onchange = customer_export_date_to_error_fade
}
function customer_export_date_from_error_fade() {
  error_fade($('date_from_3i'))
  error_fade($('date_from_2i'))
  error_fade($('date_from_1i'))
}
function customer_export_date_to_error_fade() {
  error_fade($('date_to_3i'))
  error_fade($('date_to_2i'))
  error_fade($('date_to_1i')) 
}
function create_cookie_hours(name, value, hours) {
  if (hours) {
    var date = new Date();
	date.setTime(date.getTime()+(hours*60*60*1000));
	var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function create_cookie(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 read_cookie(name, defaultValue) {
  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);
  }
  if (typeof(defaultValue) != 'undefined') {
	return defaultValue;
  } else {
    return null;	
  }
}
function create_cookie(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 getSelectValue(selectId) {
	return $(selectId)[$(selectId).selectedIndex].value
}
function load_calendar_item_date_select(item) { 
  prefix = 'calendar_item_begins_at'
  begins_at = getSelectValue(prefix+'_1i')+'-'+getSelectValue(prefix+'_2i')+'-'+getSelectValue(prefix+'_3i')
  prefix = 'calendar_item_ends_at' 
  ends_at = getSelectValue(prefix+'_1i')+'-'+getSelectValue(prefix+'_2i')+'-'+getSelectValue(prefix+'_3i')
  new Ajax.Updater("calendar_item_form_date_selects",
                   "/structure/calendar_items/render_form_date_selects",
                   {asynchronous:true,
                   evalScripts:false,
                   method:"get",
                   parameters : {
                     whole_day: (item.checked ? 1 : 0),
                     begins_at: begins_at,
                     ends_at  : ends_at   
                   }});
}
function load_calendar_item_properties(item) {
  var div = $('calendar_item_form_public_properties')
  if (item.selectedIndex == 1) {
    div.style.display = 'block';
    for (i=0;i < div.childNodes.length; i++)
      div.childNodes[i].disabled = false;
  } else {
    div.style.display = 'none';
    for (i=0;i < div.childNodes.length; i++)
      div.childNodes[i].disabled = true;
    $('type').selectedIndex = 0;
    structure_form_target($('type'));
  }
}
function structure_form_target(item) {
  if ($('calendar_item_depth')) {
    str = 'calendar_item';  
  } else {
    str = 'announcement';
  }
  $(str+'_depth').disabled = true;
  $(str+'_depth_box').style.display = 'none';
  $(str+'_group_id').disabled = true;
  $(str+'_group_id_box').style.display = 'none';    
  
  if (item.selectedIndex == 1) {
    $(str+'_depth').disabled = false;
    $(str+'_depth_box').style.display = 'block';    
  } else if (item.selectedIndex == 2) {
    $(str+'_group_id').disabled = false;
    $(str+'_group_id_box').style.display = 'block';    
  } 
}
function load_calendar_structure(date) {
  new Ajax.Updater("calendar_structure", 
                   '/structure/calendar_items/render_calendar_structure', 
                   { asynchronous:true, 
                     evalScripts:false, 
                     method:'get',
                     parameters : {
                       date: date
                     },
                     onComplete: function() {
                       default_toggle_all_calendar_items_visibility();
                     }
                    }
                   );
}
function load_calendar_home(date) {
  new Ajax.Updater("calendar_home", 
                   '/structure/calendar_items/render_calendar_home', 
                   { asynchronous:true, 
                     evalScripts:false, 
                     method:'get',
                     parameters : {
                       date: date
                     }              
                    }
                   );
}
function calendar_item_adjust_ends_at_date() {  
  begin_prefix = 'calendar_item_begins_at_';  
  end_prefix = 'calendar_item_ends_at_';  
  for (i=1;i<4;i++)
    $(end_prefix+i+'i').selectedIndex = $(begin_prefix+i+'i').selectedIndex
  if ($('calendar_item_begins_at_4i')) { // hours
    $(end_prefix+'5i').selectedIndex = $(begin_prefix+'5i').selectedIndex
    if ($(begin_prefix+'4i').selectedIndex != 23) {
      $(end_prefix+'4i').selectedIndex = $(begin_prefix+'4i').selectedIndex+1          
    } else {
      $(end_prefix+'4i').selectedIndex = $(begin_prefix+'4i').selectedIndex
    }
  }
}
function calendar_item_is_marked() {  
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName('day');
  for (var i = 0; i < found.length; i++) {  
    if (is_of_css_class(found[i], 'current'))
      return true;
  }
  return false;
}
function calendar_item_unmark_previous() {
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName('day');
  for (var i = 0; i < found.length; i++) {  
    if (remove_css_class(found[i], 'current'))
      return true;
  }
}
function calendar_item_mark_current(date) {
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName('day');
  for (var i = 0; i < found.length; i++) {
    eventStr = '' + found[i].onclick;
    if (eventStr.indexOf(date) > -1) {
      add_css_class(found[i], 'current');
      return true;    
    }
  }
}
function load_calendar_items(date) {
  new Ajax.Updater("calendar_items_list", 
                   '/structure/calendar_items/render_calendar_items_list',
                   { asynchronous:true, 
                     evalScripts:false, 
                     method:'get',
                     parameters: { 
                       date: date,
                       authenticity_token: encodeURIComponent(read_cookie('auth_token'))
                     },
                     onComplete: function() {                       
                       default_toggle_all_calendar_items_visibility();
                       calendar_item_unmark_previous();
                       calendar_item_mark_current(date);                     
                     }
                    }
                   );
  Effect.ScrollTo('calendar_items_list')                   
}
function update_days_classes() {
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName('day');
  for (var i = 0; i < found.length; i++) {
    var items = found[i].getElementsByClassName('item');
    if (items.length > 0) {
      remove_css_class(found[i], 'new');
      remove_css_class(found[i], 'full');
      for (var j = 0; j < items.length; j++) {
        if (items[j].style.display != 'none') {
          c = items[j].className
          if (c.indexOf('new') > -1) {
            add_css_class(found[i], 'new');
            add_css_class(found[i], 'full');        
          }
          if (c.indexOf('private') > -1 || c.indexOf('structure') > -1 || c.indexOf('public') > -1 || c.indexOf('birthday') > -1 )
            add_css_class(found[i], 'full');  
        }      
      }      
    }
  }
}
function unhide_overflow_items() {
  var calendar = $('calendar_structure');
  var hidden = calendar.getElementsByClassName('hidden');
  for (var k = 0; k < hidden.length; k++) {
    hidden[k].style.display = ''
    remove_css_class(hidden[k], 'hidden')
  }
}
function hide_overflow_items() {
  var MAX_ITEMS = 4
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName('day');  
  for (var i = 0; i < found.length; i++) {
    var itemsContainer = found[i].getElementsByClassName('items');
    if (itemsContainer.length > 0) {
      var em = itemsContainer[0].getElementsByClassName('ellipsis_mark')      
      // First, we need to remove any possible ellipsis mark.
      if (em.length > 0) { 
        itemsContainer[0].removeChild(em[0])    
      }   
    }
    var show_ellipsis = false;    
    var items = found[i].getElementsByClassName('item');
    if (items.length > MAX_ITEMS) { // There's a chance we might have something to hide here.
      var visible_items = 0;
      for (var j = 0; j < items.length; j++) {
        if (items[j].style.display != 'none') {
          visible_items++;
          if (visible_items > MAX_ITEMS) {        
            add_css_class(items[j], 'hidden');    
            items[j].style.display = 'none';           
            show_ellipsis = true;      
          }        
        }  
      }  
      if (show_ellipsis) {
        var ellipsisDiv = document.createElement('div');
        ellipsisDiv.className = 'ellipsis_mark';
        ellipsisDiv.innerHTML = '&hellip;';
        itemsContainer[0].appendChild(ellipsisDiv);
      }    
    }
  }
}
function toggle_calendar_items_visibility(klass, show, dont_update_classes) {
  // Hide items at the calendar itself
  var calendar = $('calendar_structure');
  var found = calendar.getElementsByClassName(klass);
  for (var i = 0; i < found.length; i++)
    if (found[i].className.indexOf('item') != -1)
      found[i].style.display = show ? '' : 'none';

  // Hide items at the list beneath calendar
  var items = $('calendar_items_list');
  var found = items.getElementsByClassName(klass);
  for (var i = 0; i < found.length; i++)
    if (found[i].nodeName.toLowerCase() == 'li')
      found[i].style.display = show ? '' : 'none';

  // Check if we had hidden all items?
  var found = items.getElementsByTagName('li');
  if (found.length > 0) {
    var hidden_count = 0;
    for (var i = 0; i < found.length; i++)
      if (found[i].style.display == 'none')
        hidden_count++;
      
    // Display an information if we had hidden all items
    // or hide it if we had shown any items
    if (hidden_count == found.length) {
      $('calendar_items_blankslate').style.display = "block"
    } else {
      $('calendar_items_blankslate').style.display = "none"
    }
  }
  create_cookie("calendar_" + klass, show, 365);
}
function checkbox_toggle_all_calendar_items_visibility() {
  unhide_overflow_items();
  toggle_calendar_items_visibility('private', $('calendar_visibility_private').checked);
  toggle_calendar_items_visibility('public', $('calendar_visibility_public').checked);
  toggle_calendar_items_visibility('structure', $('calendar_visibility_structure').checked);
  toggle_calendar_items_visibility('new', $('calendar_visibility_new').checked);
  toggle_calendar_items_visibility('birthday', $('calendar_visibility_birthday').checked);
  hide_overflow_items();
  update_days_classes();
}
function default_toggle_all_calendar_items_visibility() {
  vars = get_url_vars();
  if (typeof(vars['date']) != 'undefined' && calendar_item_is_marked() == false) {
    calendar_item_mark_current(vars['date'])
  }
  toggle_calendar_items_visibility('private', read_cookie('calendar_private', 'true') == 'true', true);
  toggle_calendar_items_visibility('public', read_cookie('calendar_public', 'true') == 'true', true);
  toggle_calendar_items_visibility('structure', read_cookie('calendar_structure', 'true') == 'true', true);
  toggle_calendar_items_visibility('new', read_cookie('calendar_new', 'true') == 'true');
  toggle_calendar_items_visibility('birthday', read_cookie('calendar_birthday', 'true') == 'true');
  hide_overflow_items();
  update_days_classes();
}
function trigger_toggle() {
	Event.observe(window, 'load', function() { default_toggle_all_calendar_items_visibility(); });
}
function nWYSIWIG(obj) {
	if (document.selection) {
		obj.bound = function(prefix, sufix) {
			this.focus();
			var str = document.selection.createRange().text;
			var sel = document.selection.createRange();
			sel.text = prefix + str + sufix;
			this.focus();
			return false;
		}
		
		obj.insert = function(content) {
			this.focus();
			document.selection.createRange().text = content;
			this.focus();
			return false;
		}
	} else {
		obj.bound = function(prefix, sufix) {
			this.focus();
			startPos = this.selectionStart;
			endPos = this.selectionEnd;
			before = this.value.substr(0, startPos);
			selected = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
			after = this.value.substr(this.selectionEnd, (this.value.length - this.selectionEnd));
			this.value = before + prefix + selected + sufix + after;
			return false;
		}
		
		obj.insert = function(content) {
			this.focus();
			startPos = this.selectionStart;
			endPos = this.selectionEnd;
			before = this.value.substr(0, startPos);
			selected = this.value.substr(this.selectionStart, (this.selectionEnd - this.selectionStart));
			after = this.value.substr(this.selectionEnd, (this.value.length - this.selectionEnd));
			this.value = before + content + after;
			return false;
		}
	}
	
	obj.bold = function() {
		return obj.bound('[b]', '[/b]');
	}
	
	obj.link = function() {
	  return obj.bound('[link]', '[/link]');
	}
	
	obj.img = function() {
    return obj.bound('[img]', '[/img]')	
	}
  
  obj.quote = function() {
    return obj.bound('[quote]', '[/quote]')
  }
}
function quote_post(id) {
  new Ajax.Request('/get_post_body/'+id, 
                   { asynchronous:true,
	      	  		     evalScripts:false,
				          	 method:'get',
		 			           onSuccess: function(transport) {
					             $('post_body').value = transport.responseText;                     
                     }
                    } 
                   );
  Effect.ScrollTo('post_body')   
}
function close_splash(id) {
  sp = $('splash_main_'+id);
  bg = $('splash_background');
  sp.parentNode.removeChild(sp);
  splashes = read_cookie('splashes', false);
  if (splashes) {
    splashes_a = splashes.split(',')
    var already_marked = false;    
    for (i=0; i < splashes_a.length; i++) {
      if (1 * splashes_a[i] == id) {
        already_marked = true;
      }  
    }
    if (!already_marked) {
      splashes += (splashes.length > 0 ? ',' : '') + id;
    }
  } else {
    splashes = '' + id
  }
  create_cookie('splashes', splashes);    
  if (document.getElementsByClassName('splash_body').length == 0)
    bg.parentNode.removeChild(bg);
  return false;
}
var state = 0;
function fade_red() {
  new Effect.Morph('invite',{ style: 'background-color: #DD0000;', duration: 5})
  state = 1;
}
function fade_dark() { 
  new Effect.Morph('invite',{  style: 'background-color: #152234;', duration: 5}) 
  state = 0;
}
function invite_fade() { // starts fading invite button (red-blue-red-...)
  if (state == 1) {
    fade_dark(); 
    setTimeout('invite_fade()', 5000)
  } else {
    fade_red();
    setTimeout('invite_fade()', 5000)
  }
}
function external_fade(object) {
  object.morph('background:#FFF;'); 
}
function dashboard_activities_written(w) {
  $('written_activities').show();
  $('all_activities').hide();
  $$('#header_tabs a')[0].className = 'active_tab';
  $$('#header_tabs a')[1].className = '';
  w.blur();
}
function dashboard_activities_all(w) {
  $('written_activities').hide();
  $('all_activities').show();
  $$('#header_tabs a')[1].className = 'active_tab';
  $$('#header_tabs a')[0].className = '';
  w.blur();
}
function randomize_banners() {
  var number = $$('.random').length;
  $$('.random').each(function(obj) { obj.hide(); });
  active = (Math.random() * number).floor();
  $$('.random')[active].show();
  return true;
}

function toggle_company_description() {
  window.original_height = window.original_height || $$('.company_description')[0].getStyle('height');
  togglers = $$('.company_description_toggler');
  description = $$('.company_description')[0];
  if (togglers[0].visible()) { // Show company description
    togglers[0].hide(); 
    togglers[1].show(); 
    description.setStyle({height: 'auto'});
  } else {
    togglers[0].show();
    togglers[1].hide();
    description.setStyle({height: original_height});
  }
}

function company_profile_setup(visible) {
  elements = '.company_profile_details input, .company_profile_details textarea, .company_profile_details select';
  if (visible) {
    $$('.company_profile_details').each(function(obj) { obj.show(); });
    $$(elements).each(function(obj) { obj.disabled = false; });
  } else {
    $$('.company_profile_details').each(function(obj) { obj.hide(); });
    $$(elements).each(function(obj) { obj.disabled = true; });
  }
}

function mass_message_preview_show() {
  new Ajax.Updater('preview_content', 
                   '/mass_messages/preview', 
                   { asynchronous:true, 
                     evalScripts:false, 
                     method:'get',
                     parameters : $('new_mass_message').serialize(true),
                     onComplete: function() { $('new_mass_message_preview').show(); $('new_mass_message_form').hide(); }
                    }
                   );
}
function mass_message_preview_hide() {
  $('new_mass_message_preview').hide(); 
  $('new_mass_message_form').show();
}