// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// used to make external URL's open in a new window and also be XHTML valid
function externalLinks() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors .length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
      anchor.target = "_blank";
      anchor.title = (anchor.title != "") ? anchor.title+" (opens in a new window)" : "opens in a new window";
      anchor.className = (anchor.className != '') ? anchor.className+' external' : 'external';
    }
  }
}
window.onload = externalLinks;

function widgets_checkall(frm) {
//    var form = $('edit_widget_form');
//    all_checkboxes = form.getInputs('checkbox');

    var all_checkboxes = [];
    all_checkboxes = $$('input').each(function(e){ if(e.type == 'checkbox') all_checkboxes.push(e) });

    all_checkbox = $('all_pages');
    elements = all_checkboxes.reject(function(n) { return n.getAttribute('id') == 'all_pages' })

    if (all_checkbox.checked) {
        elements.invoke('setAttribute', 'checked', true);
        $$('.placement').invoke('removeAttribute', 'disabled');
    }
    else {
        elements.invoke('removeAttribute', 'checked');
        $$('.placement').invoke('setAttribute', 'disabled', 'disabled');
    }
}

function mark_for_destroy(element, hide) {
    $(element).next('.should_destroy').value = 1;
    $(element).up('.' + hide).hide();
}

function toggle_disable(elem) {
  elem = $(elem);
  if (elem.getAttribute('disabled')) {
    elem.removeAttribute('disabled');
  }
  else {
    elem.setAttribute('disabled', true);
  }
}

function toggleNewsLink(newsId, newsIdToggle) {
    if (newsId.style.display == "none") {
        newsIdToggle.innerHTML = "Click here to read the whole story";
    } else {
        newsIdToggle.innerHTML = "Hide";
    }
}

function clearSearchText() {
    search_field = document.getElementById('search_term');

    if (search_field.value == "Search") {
        search_field.value = "";
    }
}

// Globals
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 24;
