var newReminder;
var newTodo;
var additionalTodoSelected = false;

var isTodo = false;     //gW_AddEvent

function reminderListChanged(addingNew) {
	var listchooser = document.getElementById("reminderListChooser");		
	var listIndex = listchooser.selectedIndex;
	if ( listIndex <= 0 ) {
		document.getElementById("todoDateCheckbox").setAttribute("hidden", true );
		document.getElementById("spacer0").setAttribute("hidden", true );	
		document.getElementById("spacer1").setAttribute("hidden", true );		
		document.getElementById("spacer2").setAttribute("hidden", true );		
		document.getElementById("spacer3").setAttribute("hidden", true );		
		document.getElementById("showInTooltip").setAttribute("hidden", true );		
		
		document.getElementById("reminderDateLabel").setAttribute("hidden", false );		
		document.getElementById("remindUntilComplete").setAttribute("hidden", false );		
		if ( newReminder == null ) {
			reminderFox_saveTodoOptions( newTodo );				
			newReminder = reminderFox_convertTodoToReminder( newTodo );
			if ( newReminder.date == null ) {
				newReminder.date = new Date();
			}
		}
		
		newTodo = null;
		if ( addingNew ) {
			loadReminders(newReminder, false);		
		}
		else {
			loadReminders(newReminder, true);		
		}
	}
	else {
		document.getElementById("todoDateCheckbox").setAttribute("hidden", false );
		document.getElementById("spacer0").setAttribute("hidden", false );
		document.getElementById("spacer1").setAttribute("hidden", false );		
		document.getElementById("spacer2").setAttribute("hidden", false );		
		document.getElementById("spacer3").setAttribute("hidden", false );		
		document.getElementById("showInTooltip").setAttribute("hidden", false );		
		
		document.getElementById("reminderDateLabel").setAttribute("hidden", true );		
		document.getElementById("remindUntilComplete").setAttribute("hidden", true );		
		
        if (isTodo)   newTodo = newReminder;		        //gW_AddEvent
		if ( newTodo == null ) {
			reminderFox_saveReminderOptions( newReminder );		
			newTodo = reminderFox_convertReminderToTodo( newReminder);
			loadTodos( newTodo, additionalTodoSelected );
		}
		else {
		   if (isTodo)  loadTodos( newTodo, additionalTodoSelected );				   //gW_AddEvent
			reminderFox_saveTodoOptions( newTodo );		// if switching todo pages
		}
		newReminder = null;
		if ( !additionalTodoSelected ) {
			sizeToContent();
		}
		additionalTodoSelected = true;   // next time, we don't want to init the todo's with defaults
	}	
}

function loadEventOptions() {
	// set reminder first....
	newReminder = window.arguments[0].reminder;
   isTodo = window.arguments[0].isTodo;			//gW_AddEvent
	
	// populate user todo lists
	var reminderFox_todoLists_listbox= document.getElementById("reminderListChooser");	
	var todoListsArray = reminderFox_getValidCustomTodoLists(); 	
	for ( var i = 0; i < todoListsArray.length; i++ )  { 	
		var newItem = document.createElement("menuitem");
		newItem.setAttribute( "label", todoListsArray[i]);	
		reminderFox_todoLists_listbox.firstChild.appendChild(newItem);
	}
   if (isTodo) reminderFox_todoLists_listbox.selectedIndex = 1;		//gW_AddEvent

	var editThis = window.arguments[0].editing;
	var addNew = true;
	if (editThis != null && editThis == true ) { 
		addNew = false;
	}
	reminderListChanged(addNew);
}

function reminderFox_saveOptions() {
	var listchooser = document.getElementById("reminderListChooser");		
	var listIndex = listchooser.selectedIndex;
	if ( listIndex <= 0 ) {
		reminderFox_saveReminderOptions( newReminder );		
		window.arguments[0].reminder = newReminder;			
	}
	else {				
		reminderFox_saveTodoOptions( newTodo );					
		window.arguments[0].reminder = newTodo;
	}
	
	if ( listIndex <= 0 ) {
		window.arguments[0].listToBeAddedTo = REMINDER_FOX_DEFAULT_REMINDERS_CATEGORY;  
	}
	else if ( listIndex == 1 ) {
		window.arguments[0].listToBeAddedTo = REMINDER_FOX_DEFAULT_TODOS_CATEGORY; 
	}
	else {
		var reminderFox_todoLists_listbox= document.getElementById("reminderListChooser");						
		window.arguments[0].listToBeAddedTo = reminderFox_todoLists_listbox.firstChild.childNodes[listIndex].getAttribute( "label" );
	}
					

	window.arguments[0].addEvent = true;   
	
	window.close();
}