// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
var TabBox = Class.create();
TabBox.prototype = {
  initialize: function(tabSet) {
	this.tabSet = tabSet;
	this.tabListName = tabSet + "_tabs";
  },

  deselectAll: function() {
	var tabItems = $(this.tabListName).getElementsByTagName('li');
	for (var i = 0; i < tabItems.length; i++) {
		tabItems[i].className = '';
	}
  },

  paneName: function(targetTab) {
	return this.tabSet + '_' + targetTab + '_pane';
  },

  select: function(targetTab) {
	this.deselectAll();
	alert(this.tabName(targetTab));
	$(this.tabName(targetTab)).className = 'selected';
	Element.show(this.paneName(targetTab));
  },

  tabName: function(targetTab) {
	return this.tabSet + '_' + targetTab + '_tab';
  }
}

function check_all(form_name) {
	var selectr = '#' + form_name + ' input';
	$$(selectr).each(function(box){ if (box.type == 'checkbox'){ box.checked = true; }; });
	return false;
}

function toggle_inline() {
	for (i = 0; i < arguments.length; i++) {
		var element = $(arguments[i]);
		element.style.display = (Element.visible(element) ? 'none' : 'inline');
	}
	return(true);
}

function uncheck_all(form_name) {
	var selectr = '#' + form_name + ' input';
	$$(selectr).each(function(box){ if (box.type == 'checkbox'){ box.checked = false; }; });
	return false;
}

function update_select_options(target, opts_array, clear_select_list) {
    if( $(target).type.match("select" ) ){ // Confirm the target is a select box

        // Remove existing options from the target and the clear_select_list
        clear_select_list[clear_select_list.length] = target // Include the target in the clear list

        for( k=0;k < clear_select_list.length;k++){
            obj = $(clear_select_list[k]);
            if( obj.type.match("select") ){
                len = obj.childNodes.length;
                for( var i=0;i < len;i++){obj.removeChild(obj.firstChild);}
            }
        }

        // Populate the new options
        for(i=0;i < opts_array.length;i++){
            o = document.createElement( "option" );
            o.appendChild( document.createTextNode( opts_array[i][0] ) );
            o.setAttribute( "value", opts_array[i][1] );
            obj.appendChild(o);
        }
    }
}

function create_drop_down(dropDownId) {
	$(dropDownId).onclick = function() {
		if ((this.className.indexOf('showMenu')) != -1) {
			this.className = this.className.replace("showMenu", "hideMenu");
		}
		else {
			this.className = this.className.replace("hideMenu", "showMenu");
		}
	}
}