// sets up search fields to be observed unobtrusively
// also adds specified text to search field when blank
function setupField(text, element){
  restoreIfBlank(this, text, element)
  Event.observe(element, 'focus', clearIfDefault.bindAsEventListener(this, text, element));
  Event.observe(element, 'blur', restoreIfBlank.bindAsEventListener(this, text, element));
}       

// restores the text field to an original phrase if blank
function restoreIfBlank(event, text, element){
  if ($(element).value == undefined || $(element).value == "") {
    $(element).value = text
    $(element).addClassName('suppressed')
  }
}

// clears the text field if it matches an original phrase
function clearIfDefault(event, text, element){
  if ($(element).value == text) {
    $(element).value = ''
    $(element).removeClassName('suppressed')
  }
}

// Displays tooltips on Training page
function training_tooltip(item){
	// Collect all of the items
	var itemlinks = $$('a.training_list_itemlink');
	
	// Hide all of the items
	itemlinks.each(function(s){
		s.up().nextSiblings()[1].removeClassName('tooltip');
		s.up().up().removeClassName('active');
	});
	
	// Show the requested item
	item.up().nextSiblings()[1].addClassName('tooltip');
	item.up().up().addClassName('active');
}

// Hides all tooltips on Training page
function hide_training_tooltips(){
  // Collect all of the items
  var itemlinks = $$('a.training_list_itemlink');
  
  // Hide all of the items
  itemlinks.each(function(s){
    s.up().nextSiblings()[1].removeClassName('tooltip');
    s.up().up().removeClassName('active');
  });
}

// Opens New Window for Course
function new_course_window(url, pre){
  pre;
  window.open(url, 'course', 'width=940,height=600,scrollbars=yes,resizable=yes,status=yes,toolbar=no,location=no,menubar=no,titlebar=yes');
}

// ******************************************* //

// Displays tooltips on Supporting Articles page
function sa_tooltip(item){
  // Collect all of the items
  var itemlinks = $$('.pdf_list li');
  
  // Hide all of the items
  itemlinks.each(function(s){
    s.childElements()[0].removeClassName('active');
	s.childElements()[1].style.display = 'none';
	document.getElementById('sidebar_blurb').innerHTML = '';
  });
  
  // Show the requested item
  item.childElements()[0].addClassName('active');
  item.childElements()[1].style.display = 'block';
  document.getElementById('sidebar_blurb').innerHTML = item.childElements()[2].innerHTML;
}

// Hides all tooltips on Supporting Articles page
function hide_sa_tooltips(){
  // Collect all of the items
  var itemlinks = $$('.pdf_list li');
  
  // Hide all of the items
  itemlinks.each(function(s){
    s.childElements()[0].removeClassName('active');
	s.childElements()[1].style.display = 'none';
  });
  document.getElementById('sidebar_blurb').innerHTML = '';
}

// Opens New Window for Supporting Articles
function new_sa_window(url){
  window.open(url, 'OM360 Training Course','width=650, height=600');
}

// Creates Popups From Title Attributes for Course Links
function course_title_popups(){
  var links = $$('a.training_list_itemlink');
  
  links.each(function(s){
    var title_text = s.readAttribute('title');
    Element.insert(s, {bottom: '<span class="title_text">' + 'Click to read Course Abstract' + '</span>' });
  });
}