// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
Ajax.Responders.register({
  onCreate: function() {
    if($('busy') && Ajax.activeRequestCount>0)
      Effect.Appear('busy',{duration:0.5,queue:'end'});
  },
  onComplete: function() {
    if($('busy') && Ajax.activeRequestCount==0)
      Effect.Fade('busy',{duration:0.5,queue:'end'});
  }
});

UpdatePaymentTotal = function(){
  //var total = parseFloat($('payment_credits').value) * parseFloat()
}

CopyValueTo = function(obj,target_id){
  $(target_id).value = $(obj).value;
  return true;
}

CopySelectValueTo = function(obj,target_id){
  var options = $A($(target_id).getElementsByTagName('option'));
  
  options.each(function(option){
    if(option.value == $F(obj)){
      option.selected = 'selected';
    }
  });
  return true;
}

// Edit Form Functions
var PageEditForm = {
  default_data: {},
  last_preview: {},
  last_title_slug: '',
  mode : null,
  liquid_horiz: true,
  width_offset: 325,
  // Initialize the page...
  init : function(mode) {
    this.mode = mode;
    this.default_data = Form.serialize(document.forms[0]);
    if(mode == 'new') {
      this.last_title_slug = $('title').value.toSlug();
      Event.observe('title', 'blur', PageEditForm.title_updated_aggressive);
    } else {
      Event.observe('title', 'blur', PageEditForm.title_updated);
    }
    $('title').focus();

    $('title').select();
    // Create the horizontal liquidity of the fields
  },
  // For use when updating an existing page...
  title_updated : function() {
    slug = $('name');
    if(slug.value == "") {
      title = $('title');
      slug.value = title.value.toSlug();
    }
  },
  // For use when creating a new page...
  title_updated_aggressive : function() {
    slug = $('name');
    title = $('title');
    if(slug.value == "" || slug.value == this.last_title ) {
      slug.value = title.value.toSlug();
    }
    this.last_title = slug.value;
  }
}

// String Extensions... Yes, these are from Radiant! ;-)
Object.extend(String.prototype, {
  upcase: function() {
    return this.toUpperCase();
  },
  downcase: function() {
    return this.toLowerCase();
  },
  strip: function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
  },
  toInteger: function() {
    return parseInt(this);
  },
  toSlug: function() {
    // M@: Modified from Radiant's version, removes multple --'s next to each other
    // This is the same RegExp as the one on the page model...
    return this.strip().downcase().replace(/[^-a-z0-9~\s\.:;+=_]/g, '').replace(/[\s\.:;=_+]+/g, '_').replace(/[\-]{2,}/g, '_');
  }
});

function InsertMovie(movie_name,width,height)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="'+width+'" HEIGHT="'+height+'" ALIGN="middle" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">\n');
    document.write('<param name="movie" value="http://ogg.osu.edu/media/video/'+movie_name+'.swf">\n');
    document.write('<EMBED SRC="http://ogg.osu.edu/media/video/'+movie_name+'.swf" WIDTH="'+width+'" HEIGHT="'+height+'" name="movie" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED>');
    document.write('</object>\n');
}

function ToggleLeadershipActivityTable()
{
	var value = $('leadership_activity_activity_type').value
	
	if(value == 'Presentation Made' || value == 'Course Instructed'){
		$('board_committee').hide();
		$('presentation_course').show();
		$('sponsoring').show();
	}else{
		$('presentation_course').hide();
		$('board_committee').show();
		$('sponsoring').hide();
	}
}

function HideMessagesNotices(message_id)
{
	$$('.notice').each(function(s){
		s.hide();
	});
	
	$(message_id).hide();
}
