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

jQuery.noConflict();

function select_all(form, name, value) {
  fm = $(form);
  forminputs = fm.getElementsByTagName('input');
  for (i = 0; i < forminputs.length; i++) {
    // regex here to check name attribute
    var regex = new RegExp(name, "i");
    if (regex.test(forminputs[i].getAttribute('name'))) {
      if (value == '1') {
        forminputs[i].checked = true;
      } else {
        forminputs[i].checked = false;
      }
    }
  }
}

function confirm_destroy(element, action, remote) {
  if (confirm("Are you sure?")) {
    var f = document.createElement('form');
    f.style.display = 'none';
    element.parentNode.appendChild(f);
    f.method = 'POST';
    f.action = action;
    var m = document.createElement('input');
    m.setAttribute('type', 'hidden');
    m.setAttribute('name', '_method');
    m.setAttribute('value', 'delete');
    f.appendChild(m);
    if(remote) { Remote.Form.attach( f ); } 
    alert(remote);
    alert(f.onclick);
    //f.submit();
  }
  return false;
}

// Returns the id (pk) from the end of a DOM id
function parseID(el) {
  var parts = el.id.split('_');
  return parts.last();
}

// jQuery ready event
jQuery(document).ready( function() {
  jQuery('.advertiser_link').fancybox();
});
