function clearSearchForm() {
   document.search.search_by.value = "all";
   document.search.track_events.value = "all";
   document.search.track.value = "all";
   document.search.type.value = "all";
   document.search.keyword.value = "";
   
   updateTrackDropDownMenu("all");
}

/*
 * track drop down
 */
var conferenceEvents = [];
var conferences = [];
var selectedConferenceEvent;
var selectedConferenceId;

function conference(id, event, name) {
	if(conferenceEvents.indexOf(event)==-1) {
		conferenceEvents.push(event);
	}	
	this.id = id;
	this.event = event;
	this.name = name;
}

function buildTrackDropDownMenu(id) {
	var dd = document.getElementById(id);
	if(dd) {
		if(selectedConferenceEvent==null){
			selectedConferenceEvent = getConferenceEvent(selectedConferenceId);
		}
	    for(var i=0;i<conferenceEvents.length;i++){
			var option = document.createElement('option');
			option.value = conferenceEvents[i];
			option.text = conferenceEvents[i];
			if(option.value==selectedConferenceEvent) {
				option.selected = true;
			}
			dd.appendChild(option);
	    }
	    updateTrackDropDownMenu(dd.value);
	}
}

function getConferenceEvent(id_string) {
	var ids = id_string.split(',');
	if(ids.length>0) for(var i=0;i<conferences.length;i++) 	if(conferences[i].id==ids[0]) return conferences[i].event;
	return '';
}

function updateTrackDropDownMenu(eventName) {
	var dd = document.getElementById('vault_search_track');
        var option;

	// hide the drop down first.
	dd.style.display = 'none';

	// remove all child nodes.
	while(dd.hasChildNodes()) 
		dd.removeChild(dd.firstChild);

	if(eventName=='all') {
	   option = document.createElement('option'); 
	   option.value = 'all';
	   option.text = 'All';
	   dd.appendChild(option);
	}	
	else {
		var options = [];
		var ids = [];
		for(var i=0;i<conferences.length;i++){
			if(conferences[i].event == eventName) {
			    option = document.createElement('option');
			    option.value = conferences[i].id;
			    option.text = conferences[i].name;
			    if(option.value==selectedConferenceId) {
			    		option.selected = true;
			    }
			    ids.push(option.value);
			    options.push(option);
			}
		}
		
		if(ids.length>0) {
			option = document.createElement('option');
			option.value = ids.join(',');
			option.text = 'All';
			dd.appendChild(option);
			
			for(i=0;i<options.length;i++){
				dd.appendChild(options[i]);
			}
		}
		
		dd.style.display = 'block';
	}
}

/*
 * Makes DIV expandable..
 *
 * @param div_name, name of div that contains expand/collapse link.
 * @param class_name, apply expand/collapse function to all the divs that have this class_name.
 * @return void
 */
var setExpandableDivs = function(div_name, class_name) {
	var textExpandAll   = '<img src="'+ImageURL+'/btn_pinkplus.gif" alt="Expand" title="Expand" style="vertical-align:middle"/> Expand All';
	var textCollapseAll = '<img src="'+ImageURL+'/btn_pinkminus.gif" alt="Collapse" title="Collapse" style="vertical-align:middle"/> Collapse All'; 
	var expandableDivs = $(class_name);

	if(expandableDivs.length>0 && $(div_name)!=null) {
		$(div_name).attr('expand',0);
		$(div_name).html(textExpandAll);
		$(div_name).click( function() {
			var expand = $(this).attr("expand")==1 ? 0 : 1;
			var text =  expand==0 ? textExpandAll : textCollapseAll;
			
			// expand all divs
			if(expandableDivs!=null) {
				for(var i=0;i<expandableDivs.length;i++){
					expandableDivs[i].style.display = (expand==0) ? 'none' : 'block';
				}
			}
			
			// update the link text
			$(this).attr("expand",expand);
			$(this).html(text);
		});
	}
	else if(expandableDivs.length<1 && $(div_name)!=null){
		$(div_name).css('display','none');
	}
};

// find all expandable divs...
$(document).ready(function() {
   setExpandableDivs("#expand_collapse_all_link",".expand_collapse");
});

