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

function _ajax_request(url, data, callback, type, method) {
    if (jQuery.isFunction(data)) {
        callback = data;
        data = {};
    }
    return jQuery.ajax({
        type: method,
        url: url,
        data: data,
        success: callback,
        dataType: type
        });
}

/* son of suckerfish code for IE */
sfHover = function() {
 var sfEls = document.getElementById("nav").getElementsByTagName("LI");
 sfEls = $$("#nav li");
 //alert("found li tags: "+sfEls);
 for (var i=0; i<sfEls.length; i++) {
   sfEls[i].onmouseover=function() {
     //alert("mouseover: "+sfEls[i]);
     this.className+=" sfhover";
     //alert(" classname for "+this+" is now "+this.className)
   }
   sfEls[i].onmouseout=function() {
     this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
     //alert(" classname for "+this+" is now "+this.className)
   }
 }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function stopFlashMovie() {
	var flashMovie = getFlashMovieObject("flashmovie");
	alert("Flash movie variable is "+flashMovie);
	flashMovie.StopPlay();
}

function getFlashMovieObject(movieName) {
  if (window.document[movieName])   {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)   {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else { // if (navigator.appName.indexOf("Microsoft Internet")!=-1)   	
    return document.getElementById(movieName);
  }
}

function set_end_date_fields(type, id) {
  if(typeof id == "undefined") {
    id = "";
  }
  checkbox_id = type + '_end_date_checkbox_'+id
  elem =  $(checkbox_id)
  if (elem != null) {
    enabled = elem.checked
    selects = $$('#'+type+'_end_date_'+id+' select');
    selects.each(function(element){
      enabled ? element.disable() : element.enable();
    })    
  }
}


function show_tips(tips_content) {
  elem = $('tips');
  // if there's a helpbox currently on-screen, get rid of it
  if (elem != null) {
     $('tips').remove();  
   } 
  $('wrap').insert ({ 'before': tips_content });
  new Effect.Appear($('tips'), { duration: 0.5 });  
}


function close_tips() {
  if ($('tips') != null) {
    new Effect.Fade($('tips'), { duration: 0.5 });  
  }
}


// turn on or off the extra text box for international states
function update_state_fields(selector_id, div_id) {
  if ($(selector_id) != null && $(div_id) != null) {
    if ($F(selector_id) == "Non-US") {
      //alert("updating "+selector_id+" "+div_id)
      $(div_id).show();
    } else  {
      $(div_id).hide();
    }
  }
}


function initialize_state_fields(selector_id, input_id, value) {
  if($(selector_id) != null ) {
    $(input_id).setValue(value);
    $(selector_id).setValue("Non-US");
  }  
}


