 ##################################################
 
 gen_passwd = (show_note = true) ->
-	if $('#site').val() == '' || $('#salt').val() == '' || $('#passphrase').val() == ''
+	site = $('#site').val()
+	if site  == '' || $('#salt').val() == '' || $('#passphrase').val() == ''
 		$('#passwd').val ''
 		return false
 	input = gather_input()
 	p = passwdgen.generate input
 	$('#passwd').val p
-	if show_note
-		util.notify 'Password for <b>' + $('#site').val() + '</b> generated.'
+
+	msg = "Password for <b>#{site}</b> generated. <br />"
+	# If this site has never been saved, save it's options now.
+	# This allows user to change default password options
+	# without forgeting options for already used sites.
+	unless site_option_saved
+		save_site_options util.NO_NOTE
+		msg += "Options also saved."
+	util.notify msg if show_note
 	return true
 
 lastInputTime = new Date(1970, 1, 1)

	obj = {}
	obj[input.site] = optjson
	util.storage.sync.set obj, "Options for <b>#{input.site}</b>", show_note
	return

load_site_options = ->

		return
	util.storage.sync.get site, (json) ->
		if json?
			site_option_saved = true
			opt = JSON.parse(json)
			console.log "loaded options for #{site}: #{json}"
			update_passwd_options opt
			util.notify "Password option for <b>#{site}</b> loaded.", util.NOTIFY_KEEP
		set_tabindex()

##################################################
