// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var sub_nav_timer_id;


function ShowPreloader(target_div) {
  $(target_div).innerHTML = $('preloader').innerHTML;
}
function ShowPreloaderSmall(target_div) {
  $(target_div).innerHTML = $('preloader_small').innerHTML;
}

function ClosePopup() {
  $('popup_shade_div').remove();
  $('popup_inner').remove();
  $('popup_wrapper').remove();
  
}

function AboutPaneSwitch(target_div) {
  $('about_about').hide();
  $('about_org').hide();
  $('about_staff').hide();
  $(target_div).show();
}

function ShowDropdown() {
  var pos = $('combo_box').cumulativeOffset();
  var results_top = pos[1] + $('combo_box').getHeight() + 1 + 'px';
  var results_left = pos[0] + 6 + 'px';
  $('results').setStyle({
     'left':results_left,
     'top':results_top
  });
  $('clear_results').show();
  $('results').show();
}

function HideDropdown()	{
  $('results').hide();
  $('clear_results').hide();
}

function SelectStore(store_name,destination) {
  HideDropdown();
  window.location = destination;
}

function ShowLoginReminder() {
  $('shade_div').setOpacity(0.5);
  $('shade_div').show();
  $('login_reminder_wrapper').show();
  $('login_reminder').show();
}

function CloseLoginReminder() {
  $('shade_div').hide();
  $('login_reminder_wrapper').hide();
  $('login_reminder').hide();
}

function CloseLoginReminderAndContinue(dest_url) {
  CloseLoginReminder();
  RedirectTo.delay(3,dest_url);
}

function RedirectTo(dest_url) {
  window.location=dest_url;
}

function LoginReminderShowForm(show_div,hide_div) {
  $(hide_div).hide();
  $(show_div).show();
}

function ShowUniversalLogin() {

  var shade_div = $('shade_div');
  var universal_login = $('universal_login');
  var universal_login_show = $('universal_login_show');
  var universal_login_hide = $('universal_login_hide');

  shade_div.setOpacity(0.5);
  shade_div.show();
  //universal_login.blindDown({'duration':'0.5'});
  Effect.SlideDown('universal_login', { duration: 0.5 });
  universal_login_show.hide();
  universal_login_hide.show();
}

function HideUniversalLogin() {
  var shade_div = $('shade_div');
  var universal_login = $('universal_login');
  var universal_login_show = $('universal_login_show');
  var universal_login_hide = $('universal_login_hide');

  shade_div.hide();
  //universal_login.blindUp({'duration':'0.5'});
  Effect.SlideUp('universal_login', { duration: 0.5 });
  universal_login_hide.hide();
  universal_login_show.show();
}

function ShowSubNav(show_div) {
  $$('[rel="sub_nav"]').each(function(the_div) {
			if (the_div.visible) {
			  the_div.hide();
			}
	});
	//$(show_div).show();
}

function HideSubNav() {
  sub_nav_timer_id = setTimeout ( "ShowDefaultSubNav()", 2000 );
  //ShowDefaultSubNav();
  
}

function ShowDefaultSubNav() {
  ShowSubNav(default_sub_nav);
}

function isMouseLeaveOrEnter(e, handler)
{		
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget :
	e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler);
}

function ClearFormBackground(this_element) {
 
  Element.setStyle(this_element, {
    backgroundImage:'none'
  });
  
  $$('[rel="form_element"]').each(function(ele) {
    if (ele.value.length > 0) {
      ele.setStyle({
        backgroundImage:'none'
      });
    }
  });
}

function SlideFormField(this_element) {
  var ele = $(this_element);
  if (!ele.visible()) {
    Effect.BlindDown(this_element, { duration: 0.2 });
  }
}

function ScaleChosenCharityHeader() {

  var max_height = 50;
  var current_height;
  var dimensions;
  var current_font_size;
  var new_font_size;

  dimensions = $('chosen_charity_font_container').getDimensions();
  current_height = dimensions.height;

  while (current_height <= max_height) {
    current_font_size = $('chosen_charity_font_container').getStyle('font-size');
    new_font_size = parseInt(current_font_size) + 1;
    $('chosen_charity_font_container').setStyle({ fontSize: new_font_size + 'px' });
    dimensions = $('chosen_charity_font_container').getDimensions();
    current_height = dimensions.height;
  }

  current_font_size = $('chosen_charity_font_container').getStyle('font-size');
  new_font_size = parseInt(current_font_size) - 1;
  $('chosen_charity_font_container').setStyle({ fontSize: new_font_size + 'px' });
}


