#!/usr/bin/expectk -f
# xSMBrowser - Samba GUI that emulates Network Neighborhood
# You are free to modify this code under the GPL License

# The following "default_pixmap_dir" specifies where xsmbrowser
# looks for the pixmaps the first time it starts ... i.e. this is
# only for people making rpm-type packages!

set default_pixmaps_dir "/usr/share/pixmaps/xsmbrowser"
# you might change this to /usr/share/pixmaps/xsmbrowser, for example

proc UserFileExist {} {
	##############################################
	# -> creates user files that keep the networks,
	#    favorites, and config
	#
	global readfmt
	puts -nonewline [format "$readfmt" "Checking for .xsmbrowser/* "]; flush stdout
	global env_name
	global default_pixmaps_dir
	global env
	set nl "\n"
	set dirmain  [file isdirectory "~/.xsmbrowser"]
	set filemain [file exists "~/.xsmbrowser/xsmbrowser-config"]
	set filenets [file exists "~/.xsmbrowser/xsmbrowser-networks"]
	set filefavs [file exists "~/.xsmbrowser/xsmbrowser-favorites"]
	set filecache [file isdirectory "~/.xsmbrowser/xsmbrowser-temp"]
	set filecommands [file exists "~/.xsmbrowser/xsmbrowser-commands"]
	set filequeue [file exists "~/.xsmbrowser/xsmbrowser-queue"]
	if {$dirmain == "0"} {
		catch [exec mkdir "$env(HOME)/.xsmbrowser"]
		puts "$nl... created .xsmbrowser directory"
		set nl ""
	}
	if {$filemain == "0"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-config" w 0600]
		puts $userfile "# Values defined in /etc/xsmbrowser/xsmbrowser-config take first priority."
		puts $userfile "#"
		puts $userfile "Timeout = 90"
		puts $userfile "Image Path = $default_pixmaps_dir"
		puts $userfile "Object Spacing = 5"
		puts $userfile "Button Pixmaps = yes"
		puts $userfile "Show License = full"
		puts $userfile "Smbmount = yes 0"
		puts $userfile "Execute = xterm -e mc \$MOUNTPOINT"
		puts $userfile "Mount Tree = \$HOME/mnt"
		puts $userfile ""
		puts $userfile "# EOF will end this config file"
		puts $userfile "EOF"
		close $userfile
		puts "$nl... created .xsmbrowser/xsmbrowser-config"
		set nl ""
	}
	if {$filenets == "0"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-networks" w 0600]
		puts $userfile "# Networks in /etc/xsmbrowser/xsmbrowser-networks are read first."
		puts $userfile "#"
		puts $userfile ":Samba Config"
		puts $userfile "Type = broadcast"
		puts $userfile "IP Num = default_samba"
		puts $userfile "Workgroup = default_samba"
		puts $userfile ""
		puts $userfile ":Samba Config (Wins Service)"
		puts $userfile "Type = wins"
		puts $userfile "IP Num = default_samba"
		puts $userfile "Workgroup = default_samba"
		puts $userfile ""
		puts $userfile ""
		puts $userfile "# EOF will end this config file"
		puts $userfile "EOF"
		close $userfile
		puts "$nl... created .xsmbrowser/xsmbrowser-networks"
		set nl ""
	}
	if {$filefavs == "0"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-favorites" w 0600]
		puts $userfile "# Favorites and mounts in /etc/xsmbrowser/xsmbrowser-favorites are read first."
		puts $userfile "#"
		puts $userfile ":Your Computer"
		puts $userfile "Type = ip_only"
		puts $userfile "IP Num = 127.0.0.1"
		puts $userfile "Workgroup = "
		puts $userfile "Username = $env_name"
		puts $userfile ""
		puts $userfile "# Mount memory..."
		puts $userfile "@//SAMPLE/entry"
		puts $userfile "Mount Point = default"
		puts $userfile "Mount UID = 500"
		puts $userfile "Mount GID = 500"
		puts $userfile "Mount FMask = 644"
		puts $userfile "Mount DMask = 755"
		puts $userfile "Execute = yes"
		puts $userfile "History = no"
		puts $userfile "Mount IP = 127.0.0.1"
		puts $userfile "Mount Workgroup = none"
		puts $userfile "Mount NetBios = SAMPLE"
		puts $userfile "Mount Share = entry"
		puts $userfile "Mount Username = none"
		puts $userfile "Mount Password = "
		puts $userfile ""
		puts $userfile "# EOF will end this config file"
		puts $userfile "EOF"
		close $userfile
		puts "$nl... created .xsmbrowser/xsmbrowser-favorites"
		set nl ""
	}
	if {$filecommands == "0"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-commands" w 0600]
		puts $userfile "# Commands in /etc/xsmbrowser/xsmbrowser-commands are read first."
		puts $userfile "#"
		puts $userfile ":Netscape"
		puts $userfile "Types = .HTM .HTML .SHTML"
		puts $userfile "Command = netscape \$FILE"
		puts $userfile ""
		puts $userfile ":Gimp"
		puts $userfile "Types = .BMP .TIF .TIFF .AI .PSD .PNG .PCX .XPM .XBM .PPM .XWD .JPG .JPEG .JPE .GIF"
		puts $userfile "Command = gimp \$FILE"
		puts $userfile ""
		puts $userfile ":emacs"
		puts $userfile "Types =" 
		puts $userfile "Command = xterm -e emacs \$FILE"
		puts $userfile ""
		puts $userfile ":Ghost View"
		puts $userfile "Types = .PS"
		puts $userfile "Command = gv \$FILE"
		puts $userfile ""
		puts $userfile ":xPDF"
		puts $userfile "Types = .PDF"
		puts $userfile "Command = xpdf \$FILE"
		puts $userfile ""
		puts $userfile ":xanim"
		puts $userfile "Types = .AVI .QT .MOV .MPEG .MPG .MPE .MPA .M1V .MP2 .MP2V .MPV2"
		puts $userfile "Command = xanim +f \$FILE"
		puts $userfile ""
		puts $userfile "# EOF will end this config file"
		puts $userfile "EOF"
		close $userfile
		puts "$nl... created .xsmbrowser/xsmbrowser-commands"
		set nl ""
	}
	if {$filecache == "0"} {
		catch [exec mkdir "$env(HOME)/.xsmbrowser/xsmbrowser-temp"]
		puts "$nl... created .xsmbrowser/xsmbrowser-temp"
		set nl ""
	}
	if {$filequeue == "0"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-queue" w 0600]
		puts $userfile "EOF"
		puts "$nl... created .xsmbrowser/xsmbrowser-queue"
		set nl ""
	}
	if {$nl == "\n"} {
		puts "\[ok\]"
	}
}

set avi_l ".AVI .ASF"
set dwg_l ".DWG"
set gif_l ".GIF"
set ini_l ".INI"
set jpg_l ".JPG .JPEG .JPE"
set lnk_l ".LNK"
set pdf_l ".PDF .PS .EPS"
set rm_l ".RA .RAM .RM"
set wav_l ".WAV"
set xls_l ".XLS"
set bmp_l ".BMP .TIF .TIFF .AI .PSD .PNG .PCX .XPM .XBM .PPM .XWD"
set cplusplus_l ".C .H .O"
set text_l ".TXT .NFO"
set wri_l ".DOC .WRI .RTF .WPD .WPS"
set html_l ".HTM .HTML .CGI .SHTML"
set mid_l ".MID .MIDI .RMI .SND .AU .AIF .AIFC .AIFF .WMA .VOC"
set mp3_l ".MP3 .M3U"
set movie_l ".QT .MOV .MPEG .MPG .MPE .MPA .M1V .MP2 .MP2V .MPV2"
set windows_l ".EXE .BAT .COM"
set zip_l ".ZIP .ARC .RAR .RPM .ARJ .B64 .BHX .BZ .BZ2 .CAB .GZ .HQX .LZH .MIM .TAR .TAZ .TGZ .TZ .UU .UUE .XXE .Z"
set system_l ".SYS .DLL .REG"
set cd_l ".CIF .ISO .CL3 .CDA"

set all_l [list $gif_l $jpg_l $html_l $avi_l $movie_l $windows_l $zip_l $system_l $text_l $wri_l $lnk_l $pdf_l $rm_l $wav_l $xls_l $bmp_l $ini_l $cplusplus_l $mid_l $cd_l $dwg_l]

proc ReadImages {} {
	#################################################
	global image_path
	global readfmt
	puts -nonewline [format "$readfmt" "Loading image files from $image_path "]; flush stdout
	if ![file exists "$image_path/networks.gif"] {
		puts "\[failed\]\n... W: cannot find images in $image_path. See setup."
		set image_path "Use Geo"
		return
	}
	set check [catch {
		image create photo networks_i -format gif -file "$image_path/networks.gif"
		image create photo workgroups_i -format gif -file "$image_path/workgroups.gif"
		image create photo computers_i -format gif -file "$image_path/computers.gif"
		image create photo share_i -format gif -file "$image_path/share.gif"
		image create photo folder_i -format gif -file "$image_path/folder.gif"
		image create photo default_i -format gif -file "$image_path/default.gif"
		image create photo h_default_i -format gif -file "$image_path/h_default.gif"
		image create photo h_folder_i -format gif -file "$image_path/h_folder.gif"
		image create photo bmp_i -format gif -file "$image_path/bmp.gif"
		image create photo cplusplus_i -format gif -file "$image_path/c.gif"
		image create photo text_i -format gif -file "$image_path/txt.gif"
		image create photo html_i -format gif -file "$image_path/html.gif"
		image create photo mid_i -format gif -file "$image_path/mid.gif"
		image create photo mp3_i -format gif -file "$image_path/mp3.gif"
		image create photo movie_i -format gif -file "$image_path/mpg.gif"
		image create photo windows_i -format gif -file "$image_path/exe.gif"
		image create photo zip_i -format gif -file "$image_path/zip.gif"
		image create photo system_i -format gif -file "$image_path/sys.gif"
		image create photo cd_i -format gif -file "$image_path/cd.gif"
		image create photo wri_i -format gif -file "$image_path/wri.gif"
		image create photo avi_i -format gif -file "$image_path/avi.gif"
		image create photo dwg_i -format gif -file "$image_path/dwg.gif"
		image create photo gif_i -format gif -file "$image_path/gif.gif"
		image create photo ini_i -format gif -file "$image_path/ini.gif"
		image create photo jpg_i -format gif -file "$image_path/jpg.gif"
		image create photo lnk_i -format gif -file "$image_path/lnk.gif"
		image create photo pdf_i -format gif -file "$image_path/pdf.gif"
		image create photo rm_i -format gif -file "$image_path/rm.gif"
		image create photo wav_i -format gif -file "$image_path/wav.gif"
		image create photo xls_i -format gif -file "$image_path/xls.gif"
		image create photo back_c -format gif -file "$image_path/back_c.gif"
		image create photo forward_c -format gif -file "$image_path/forward_c.gif"
		image create photo stop_c -format gif -file "$image_path/stop_c.gif"
		image create photo refresh_c -format gif -file "$image_path/refresh_c.gif"
		image create photo workgroups_c -format gif -file "$image_path/workgroups_c.gif"
		image create photo favorites_c -format gif -file "$image_path/favorites_c.gif"
		image create photo networks_c -format gif -file "$image_path/networks_c.gif"
		image create photo transfer_c -format gif -file "$image_path/transfer_c.gif"
		image create photo network_c -format gif -file "$image_path/network_c.gif"
		image create photo favorite_c -format gif -file "$image_path/favorite_c.gif"
		image create photo queue_c -format gif -file "$image_path/queue_c.gif"
		image create photo help_c -format gif -file "$image_path/help_c.gif"
		image create photo exit_c -format gif -file "$image_path/exit_c.gif"
		image create photo setup_c -format gif -file "$image_path/setup_c.gif"
		image create photo explore_c -format gif -file "$image_path/explore_c.gif"
		image create photo mount_c -format gif -file "$image_path/mount_c.gif"
		image create photo unmount_c -format gif -file "$image_path/unmount_c.gif"
		image create photo history_c -format gif -file "$image_path/history_c.gif"
		image create photo printer_c -format gif -file "$image_path/printer.gif"
	} error]
	if {$check == "0"} {
	        puts "\[ok\]"
	} else {
		puts "\[failed\]\n\[!\] W: $error"
		set image_path "Use Geo"
		return
	}
}

proc ChooseIcon {name} {
	############################################
	global mp3_l
	global all_l
	if {[string range $name 0 0] == "."} {
		return h_default_i
	}
	set char_index [string last "." $name]
	if {$char_index == "-1"} {
		return default_i
	} else {
		set end [string toupper [string range $name $char_index [expr [string length $name] - 1]]]
	}
	set test [lsearch -exact $mp3_l $end]
	if {$test != "-1"} {
		return mp3_i
	}
	set test [expr [lsearch -glob $all_l "*$end*"] + 1]
	switch -exact $test {
		1 {
			return gif_i
		}
		2 {
			return jpg_i
		}
		3 {
			return html_i
		}
		9 {
			return text_i
		}
		8 {
			return system_i
		}
		10 {
			return wri_i
		}
		16 {
			return bmp_i
		}
		18 {
			return cplusplus_i
		}
		12 {
			return pdf_i
		}
		19 {
			return mid_i
		}
		13 {
			return rm_i
		}
		6 {
			return windows_i
		}
		7 {
			return zip_i
		}
		5 {
			return movie_i
		}
		4 {
			return avi_i
		}
		14 {
			return wav_i
		}
		20 {
			return cd_i
		}
		11 {
			return lnk_i
		}
		17 {
			return ini_i
		}
		15 {
			return xls_i
		}
		21 {
			return dwg_i
		}
		default {
			return default_i
		}
	}
}

proc SmbClientList {computer ip_num get_what workgroup} {
	########################################################
	# -> issues "smbclient -L [computer] -I [ip_num]" and
	#    collects data into corresponding global matrices
	#
	# [computer] is the netbios name of destination computer
	# [ip_num] is the destination ip address
	# [get_what] can be set to: shares_only
	#                           computers_workgroups
	#                           shares_checkgroups
	#                           computers_only
	#
	global computers_m
	global workgroups_m
	global shares_m
	global spawn_pid
	global cancel_password
	global env
	global set_timeout
	global user_name
	global password
	global default_password
	global default_user_name
	if {$get_what == "shares_checkgroups"} { set get_what "shares_only"}
	set list_pattern "\t+(\[^\r\n]*)\r\n"
	set passgood "yes"
	set n_count 0
	while { $n_count < 2 } {
		set n 0
		if {$user_name == "" & $password == ""} {
			set spawn_pid [spawn smbclient -N -L $computer -I $ip_num -W $workgroup]
		} else {
			set spawn_pid [spawn smbclient -N -U $user_name -L $computer -I $ip_num -W $workgroup]
		}
		set id $spawn_id
		set timeout 3600
		expect {
			-i $id -indices -re $list_pattern {
				set dummy($n) $expect_out(1,string)
				incr n
				exp_continue
			}
			-i $id -indices -re "ERRDOS( - \[^ ]+)*" {
				set error_message "ERRDOS$expect_out(1,string)"
				exp_continue
			}
			-i $id -indices -re " - (ERR\[^ ]+)" {
				if {$expect_out(1,string) == "ERRbadpw"} {
					set passgood "no"
				} else {
					set error_message [Error $expect_out(1,string)]
				}
				exp_continue
			}
			-i $id "failed" {
				set error_message "Connection to $computer failed"
				exp_continue
			}
			-i $id "Error" {
				set error_message "Connection to $computer failed"
				exp_continue
			}
			-i $id "ERRDOS" {
				set error_message "Error: ERRDOS"
				exp_continue
			}
			-i $id timeout { close -i $id }
		}
		wait -i $id
		if {$passgood == "no"} {
			if { $n_count == 0 } {
				set passgood "yes"
				PasswordPrompt
				if {$cancel_password == "yes"} {
					.info.info2.stats config -text ""
					. config -cursor left_ptr
					return
				}
			} else {
				.info.info2.stats config -text "Password Not Accepted"
				. config -cursor left_ptr
				return
			}
			if [info exists env(USER)] {
				set env(USER) "$user_name%$password"
			} elseif [info exists env(LOGNAME)] {
				set env(LOGNAME) "$user_name%$password"
			} else {
				set env(USER) "$user_name%$password"
			}
		} else {
			break
		}
		incr n_count
	}
	.info.info0.stats delete 0 1024
	.info.info0.stats insert 0 $password
	.info.info0.statU delete 0 1024
	.info.info0.statU insert 0 $user_name
	if [info exists error_message] {
		.info.info2.stats config -text $error_message
	}
	if {[info exists dummy] == 0 } {
		if ![info exists error_message] {
			.info.info2.stats config -text "Rejected / No Data to Display"
		}
		. config -cursor left_ptr
		return
	}
	set p 0
	if { [regexp -nocase {Sharename\s+Type\s+Comment} $dummy(0)] } {
		if [info exists shares_m] {unset shares_m}
		set i 2
	} else {
		set i 0
	}
	while {$i < $n && $dummy($i) != "Server               Comment" && $dummy($i) != "Workgroup            Master"} {
		if {$get_what != "computers_only"} {
			if {[string trim [string range $dummy($i) 15 24]] == "Disk" | [string trim [string range $dummy($i) 15 24]] == "Printer"} {
				set shares_m($p,1) [string trim [string range $dummy($i) 0 14]]
				if {[string length $dummy($i)] == 25} {
					set shares_m($p,2) " "
				} else {
					set shares_m($p,2) [string trim [string range $dummy($i) 25 [string length $dummy($i)]]]
				}
				set shares_m($p,3) [string trim [string range $dummy($i) 15 24]]
				incr p
			} else {
				if { [regexp {.*Disk      } $dummy($i)] } {
					regsub {Disk      .*$} $dummy($i) "" share_name
					regsub {.*Disk      (.*)$} $dummy($i) {\1} share_comment
					set share_name [string trim $share_name]
					if { $share_comment == "" } { set share_comment " " }
					set shares_m($p,1) $share_name
					set shares_m($p,2) $share_comment
					set shares_m($p,3) "Disk"
					incr p
				}
			}
		}
		incr i
	}
	if {$get_what == "shares_only"} {
		if ![info exists shares_m] {
			.info.info2.stats config -text "No Shares Offered";. config -cursor left_ptr
		} else {
			SortShares
		}
		return
	}
	set p 0
	if [info exists dummy($i)] {
		if {$dummy($i) != "Workgroup            Master"} {
			if {$get_what != "shares_checkgroups"} {
				if [info exists computers_m] {unset computers_m}
			}
			set i [expr $i + 2]
		}
	}
	while {$i < $n && $dummy($i) != "Workgroup            Master"} {
		if {$get_what != "shares_checkgroups"} {
			set computers_m($p,1) [string trim [string range $dummy($i) 0 20]]
			if {[string length $dummy($i)] == 21} {
				set computers_m($p,2) " "
			} else {
				set computers_m($p,2) [string trim [string range $dummy($i) 21 [string length $dummy($i)]]]
			}
		}
		incr i; incr p
	}
	if {$get_what != "shares_checkgroups" & [array exists computers_m] == "0"} {
		.info.info2.stats config -text "No Computers Found"
		. config -cursor left_ptr
	}
	set i [expr $i + 2] 
	if {$get_what == "shares_checkgroups"} {set workgroups_list [array get workgroups_m]}
	set wgadded 0
	while {$i < $n & $get_what == "shares_checkgroups"} {
		set wg_index [lsearch -exact $workgroups_list [string trim [string range $dummy($i) 0 20]]]
		if {$wg_index == -1 | [expr $wg_index % 2] != 1} {
			set wg_spot [expr [array size workgroups_m] / 2]
			set workgroups_m($wg_spot,1) [string trim [string range $dummy($i) 0 20]]
			set workgroups_m($wg_spot,2) [string trim [string range $dummy($i) 21 [string length $dummy($i)]]]
			incr wgadded
		}
		incr i
	}
	if {$wgadded != 0} {.info.info2.stats config -text "$wgadded Workgroups Added";. config -cursor left_ptr}
	if {$get_what == "shares_checkgroups"} {
		if ![info exists shares_m] {
			.info.info2.stats config -text "No Shares Offered";. config -cursor left_ptr
		} else {
			SortShares
			SortWorkgroups
		}
		return
	}
	for {set p 0} {$i < $n} {incr p; incr i} {
		set workgroups_m($p,1) [string trim [string range $dummy($i) 0 20]]
		set workgroups_m($p,2) [string trim [string range $dummy($i) 21 [string length $dummy($i)]]]
	}
	SortWorkgroups
}

proc SmbClientFiles {computer computer_ip_num share directory workgroup} {
	##############################################################################
	# -> issues "smbclient \\\\[computer]\\[share] [password] -I [computer_ip_num]
	#    -D [directory] -c dir" command for the reasons of getting a listing for
	#    the files_m and folders_m global matrices
	#
	# [computer] is the netbios computer name
	# [computer_ip_num] is the destination ip address
	# [share] is the user share to go into
	# [directory] is the users directory, if one exists
	# [password] is the password, if one exists
	#
	global files_list
	global folders_list
	global selected_file_size
	global files_m
	global folders_m
	global user_name
	global mstatus
	global env
	global mount_addon
	global password
	global cancel_password
	global default_password
	global default_user_name
	global directory_a
	global spawn_pid
	global set_timeout
	global checker
	set dir_pattern {  ([^ ]([^ ]| [^ ]|  [^ ]|   [^ ]|    [^ ])*)     +([^0-9]*) *([0-9]+) +(........................)}
	set password [.info.info0.stats get]
	set user_name [.info.info0.statU get]
	if [info exists env(USER)] {
		set env(USER) "$user_name%$password"
	} elseif [info exists env(LOGNAME)] {
		set env(LOGNAME) "$user_name%$password"
	} else {
		set env(USER) "$user_name%$password"
	}
	set passgood "yes"
	set n_count 0
	while { $n_count < 2 } {
		set n 0
		set n_dir 0
		set files_good "no"
		if {[string length $directory] == 0} {
			if {$user_name == "" & $password == "" } { 
				set spawn_pid [spawn smbclient \\\\$computer\\$share -I $computer_ip_num -N -W $workgroup -c dir]
			} else {
				set spawn_pid [spawn smbclient \\\\$computer\\$share -U $user_name -I $computer_ip_num -N -W $workgroup -c dir]
			}
		} else {
			if {$user_name == "" & $password == "" } { 
				set spawn_pid [spawn smbclient \\\\$computer\\$share -I $computer_ip_num -D $directory -W $workgroup -c dir]
			} else {
				set spawn_pid [spawn smbclient \\\\$computer\\$share -U $user_name -I $computer_ip_num -D $directory -W $workgroup -c dir]
			}
		}
		set id $spawn_id
		set timeout 3600
		expect {
			-i $id -indices -re $dir_pattern {
				if {[string match "*D*" $expect_out(3,string)] != 1} {
					set dummy($n,1) $expect_out(1,string)
					set dummy($n,2) $expect_out(3,string)
					set dummy($n,3) $expect_out(4,string)
					regexp {[^ ]*} $expect_out(1,string) temp_holder
					lappend dummy_list [string toupper $temp_holder]/$n
					incr n
				} elseif {$expect_out(1,string) != "." & $expect_out(1,string) != ".."} {
					set dummy_dir($n_dir,1) $expect_out(1,string)
					set dummy_dir($n_dir,2) $expect_out(3,string)
					set dummy_dir($n_dir,3) $expect_out(4,string)
					regexp {[^ ]*} $expect_out(1,string) temp_holder
					lappend dummy_list_dir [string toupper $temp_holder]/$n_dir
					incr n_dir
				}
				exp_continue
			}
			-i $id -indices -re "\[0-9]* blocks of size \[0-9]*\. \[0-9]* blocks available" {
				set files_good "yes"
				exp_continue
			}
			-i $id -indices -re "ERRDOS( - \[^ ]+)*" {
				set error_message "ERRDOS$expect_out(1,string)"
				exp_continue
			}
			-i $id -indices -re " - (ERR\[^ ]+)" {
				if {$expect_out(1,string) == "ERRbadpw"} {
					set passgood "no"
				} else {
					set error_message [Error $expect_out(1,string)]
				}
				exp_continue
			}
			-i $id -indices -re "Error in \[^:]*: code \[0-9]*" {
				set error_message $expect_out(0,string)
				exp_continue
			}
			-i $id "Error" {
				set error_message "Connection to $computer failed"
				exp_continue
			}
			-i $id "failed" {
				set error_message "Connection to $computer failed"
				exp_continue
			}
			-i $id timeout { close -i $id }
		}
		wait -i $id
		if {$passgood == "no"} {
			if { $n_count == 0 } {
				set passgood "yes"
				PasswordPrompt
				if {$cancel_password == "yes"} {
					.info.info2.stats config -text ""
					. config -cursor left_ptr
					if {$directory == ""} {
						set directory_a(1) "shares"
					} else {
						unset directory_a([array size directory_a])
					}
					incr checker
					return
				}
				if [info exists env(USER)] {
					set env(USER) "$user_name%$password"
				} elseif [info exists env(LOGNAME)] {
					set env(LOGNAME) "$user_name%$password"
				} else {
					set env(USER) "$user_name%$password"
				}
			} else {
				.info.info2.stats config -text "Password Not Accepted"
				. config -cursor left_ptr
				if {$directory == ""} {
					set directory_a(1) "shares"
				} else {
					unset directory_a([array size directory_a])
				}
				incr checker
				return
			}
		} else {
			break
		}
		incr n_count
	}
	if [info exists error_message] {
		.info.info2.stats config -text $error_message
		if {$error_message == "ERRDOS - ERRbadpath" | $error_message == "ERRDOS - ERRnoaccess"} {
			set files_good "no"
		}
	}
	if {$files_good == "no" & [info exists dummy] == "0" & [info exists dummy_dir] == "0"} {
		if ![info exists error_message] {
			.info.info2.stats config -text "Rejected / No Files To Display"
		}
		. config -cursor left_ptr
		if {$directory == ""} {
			set directory_a(1) "shares"
		} else {
			unset directory_a([array size directory_a])
		}
		incr checker
		return
	}
	.info.info0.stats delete 0 1024
	.info.info0.stats insert 0 $password
	.info.info0.statU delete 0 1024
	.info.info0.statU insert 0 $user_name
	if [info exists files_m] {unset files_m}
	if [info exists folders_m] {unset folders_m}
	if [info exists files_list] {unset files_list}
	if [info exists folders_list] {unset folders_list}
	set selected_file_size 0
	if {$n_dir == 0} {
		if {$n == 0} {
			if ![info exists error_message] {
				.info.info2.stats config -text "Directory Is Empty"
			}
			. config -cursor left_ptr
			.info.info1.stats config -text " Total:"
			.cscroll.c delete all
			set checker [expr $checker + 2]
			.status.stats config -text " Dir: \\$directory  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
			if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
			if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
			HistoryAdd "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3]
			return
		}
	}
	if {$n != 0} {
		set numerated_list [lsort -ascii $dummy_list]
		for {set i 0} {$i < [llength $numerated_list]} {incr i} {
			regexp {/([0-9]+)$} [lindex $numerated_list $i] stuff alpha_index
			set files_m($i,1) $dummy($alpha_index,1)
			set files_m($i,2) $dummy($alpha_index,2)
			set files_m($i,3) $dummy($alpha_index,3)
		}
	}
	if {$n_dir == 0} {return}
	set numerated_list_dir [lsort -ascii $dummy_list_dir]
	for {set i 0} {$i < [llength $numerated_list_dir]} {incr i} {
		regexp {/([0-9]+)$} [lindex $numerated_list_dir $i] stuff alpha_index
		set folders_m($i,1) $dummy_dir($alpha_index,1)
		set folders_m($i,2) $dummy_dir($alpha_index,2)
		set folders_m($i,3) $dummy_dir($alpha_index,3)
	}
}

proc NmbLookup {computer net_type ip_num} {
	######################################################
	# -> issues "nmblookup" command for WINS or
	#    broadcast type network and returns ip
	#    number in global computer_ip_num variable
	#
	# [computer] is the netbios destination name
	# [net_type] can be set to "wins" or "broadcast"
	# [ip_num] is the broadcast ip for "broadcast" or
	# the WINS server address for "wins" type
	#
	global computer_ip_num
	global spawn_pid
	global checker
	global set_timeout
	set chad "no"
	set nmb_pattern "\r\n(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+)+ +.*(<..>)+"
	if {$net_type == "wins"} {
		set spawn_pid [spawn nmblookup -d 1 -U [NameSubstitution $ip_num] -R [NameSubstitution $computer]]
	} else {
		if {$ip_num != "default_samba"} {
			set spawn_pid [spawn nmblookup -d 1 -B [NameSubstitution $ip_num] [NameSubstitution $computer]]
		} else {
			set spawn_pid [spawn nmblookup -d 1 [NameSubstitution $computer]]
		}
	}
	set id $spawn_id
	set timeout $set_timeout
	expect {
		-i $id -indices -re $nmb_pattern {
			set computer_ip_num $expect_out(1,string)
			set chad "yes"
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	if {$chad != "yes"} {incr checker}
}

proc NmbLookupMaster {workgroup ip type} {
	######################################################
	# -> issues "nmblookup" command to find the master
	#    of the workgroup in a broadcast network, and
	#    returns netbios name in broadcast_master
	#
	global broadcast_master
	global broadcast_master_ip_num
	global wins_domain_master
	global wins_domain_master_ip
	global spawn_pid
	global set_timeout
	global checker
	set nmb_pattern "\r\n(\[0-9]+\.\[0-9]+\.\[0-9]+\.\[0-9]+)+ +(.*)(<..>)+"
	if {$type == "broadcast"} {
		if {$ip != "default_samba"} {
			set spawn_pid [spawn nmblookup -d 1 -S -M -B [NameSubstitution $ip] [NameSubstitution $workgroup]]
		} else {
			set spawn_pid [spawn nmblookup -d 1 -S -M [NameSubstitution $workgroup]]
		}
	} else {
		set spawn_pid [spawn nmblookup -d 1 -S -U [NameSubstitution $ip] -R "[NameSubstitution $workgroup]#1B"]
	}
	set id $spawn_id
	set timeout $set_timeout
	set chad "no"
	set found "no"
	expect {
		-i $id -indices -re $nmb_pattern {
			if {$type == "broadcast"} {
				set broadcast_master_ip_num $expect_out(1,string)
				set broadcast_master $expect_out(2,string)
			} else {
				set wins_domain_master_ip $expect_out(1,string)
				set wins_domain_master $expect_out(2,string)
			}
			set chad "yes"
			exp_continue
		}
		-i $id -indices -re "\r\n\t(\[^<00>]*)<00> -     " {
			if {$type == "broadcast" & $found == "no"} {
				set broadcast_master [string trim $expect_out(1,string)]
			} elseif {$found == "no"} {
				set wins_domain_master [string trim $expect_out(1,string)]
			}
			set found "yes"
			exp_continue
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	if {$chad != "yes"} {incr checker}
}

proc NmbLookupName {ip_address type} {
	######################################################
	# -> issues "nmblookup" command to find the Netbios
	#    name based on IP
	#
	global computer
	global workgroup
	global spawn_pid
	global wins_domain_master
	global checker
	global set_timeout
	set chad "no"
	set wg ""
	set nmb_pattern "\t+(\[^<]*)<..>(\[^\r\n]*)\r\n"
	set spawn_pid [spawn nmblookup -d 1 -A [NameSubstitution $ip_address]]
	set id $spawn_id
	set timeout $set_timeout
	expect {
		-i $id -indices -re $nmb_pattern {
			if [string match *GROUP* $expect_out(2,string)] {
				if {[string trim $expect_out(1,string)] == "..__MSBROWSE__." | [string trim $expect_out(1,string)] == "INet~Services"} {
					exp_continue
				} else {
					set wg [string trim $expect_out(1,string)]
					if {$chad == "no"} {
						exp_continue
					}
				}
			} else {
				if {$chad == "no"} {
					set ip [string trim $expect_out(1,string)]
					set chad "yes"
				}
				exp_continue
			}
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	if {$chad != "yes"} {
		incr checker
		return
	}
	if {$type != "wins"} {
		set computer $ip
		set workgroup $wg
	} else {
		set wins_domain_master $ip
	}
}

proc NameSubstitution {name} {
	#############################
	set name2 ""
	set m 0
	if {[string index $name 0] == "-"} {
		set name2 "\\-"
		set m 1
	}
	while {$m < [expr [string length $name] - 1]} {
		if [string match *[string index $name $m]* {#$"}] {
			set name2 "$name2\\[string index $name $m]"
		} else {
			set name2 "$name2[string index $name $m]"
		}
		incr m
	}
	if [string match *[string index $name $m]* {#"}] {
		set name2 "$name2\\[string index $name $m]"
	} else {
		set name2 "$name2[string index $name $m]"
	}
	return $name2
}

proc Error {error} {
	###########################################
	if {$error == "ERRaccess"} {
		return "Error: No Access"
	} elseif {$error == "ERRbadaccess"} {
		return "Error: Invalid open mode"
	} elseif {$error == "ERRbadcmd"} {
		return "Error: Unknown command"
	} elseif {$error == "ERRbaddata"} {
		return "Error: Invalid data"
	} elseif {$error == "ERRbaddrive"} {
		return "Error: Invalid drive specified"
	} elseif {$error == "ERRbadenv"} {
		return "Error: Invalid environment"
	} elseif {$error == "ERRbadfid"} {
		return "Error: Bad FID"
	} elseif {$error == "ERRbadfile"} {
		return "Error: Bad File"
	} elseif {$error == "ERRbadformat"} {
		return "Error: Invalid format"
	} elseif {$error == "ERRbadfunc"} {
		return "Error: Bad Function"
	} elseif {$error == "ERRbadmcb"} {
		return "Error: Memory control blocks destroyed"
	} elseif {$error == "ERRbadmedia"} {
		return "Error: Unknown media type"
	} elseif {$error == "ERRbadmem"} {
		return "Error: Invalid memory block address"
	} elseif {$error == "ERRbadpath"} {
		return "Error: Bad Path"
	} elseif {$error == "ERRbadpermits"} {
		return "Error: Bad Permissions"
	} elseif {$error == "ERRbadpipe"} {
		return "Error: Pipe invalid"
	} elseif {$error == "ERRbadpw"} {
		return "Error: Bad Password"
	} elseif {$error == "ERRbadreq"} {
		return "Error: Bad request structure length"
	} elseif {$error == "ERRbadsector"} {
		return "Error: Sector not found"
	} elseif {$error == "ERRbadshare"} {
		return "Error: Bad Share"
	} elseif {$error == "ERRbadtype"} {
		return "Error: Bad Type"
	} elseif {$error == "ERRbaduid"} {
		return "Error: The UID is not known as a valid ID on this session"
	} elseif {$error == "ERRbadunit"} {
		return "Error: Unknown unit"
	} elseif {$error == "ERRcontmpx"} {
		return "Error: Continue in MPX mode"
	} elseif {$error == "ERRdata"} {
		return "Error: Data error (CRC)"
	} elseif {$error == "ERRdiffdevice"} {
		return "Error: Not same device"
	} elseif {$error == "ERRerror"} {
		return "Error: Non-specific error code"
	} elseif {$error == "ERRfilespecs"} {
		return "Error: File Specifications"
	} elseif {$error == "ERRfilexists"} {
		return "Error: File Exists"
	} elseif {$error == "ERRgeneral"} {
		return "Error: General failure"
	} elseif {$error == "ERRinvdevice"} {
		return "Error: Invalid Device"
	} elseif {$error == "ERRinvnetname"} {
		return "Error: Invalid network name in tree connect"
	} elseif {$error == "ERRinvnid"} {
		return "Error: The tree ID (TID) specified in a command was invalid"
	} elseif {$error == "ERRlock"} {
		return "Error: Lock"
	} elseif {$error == "ERRmoredata"} {
		return "Error: There is more data to be returned"
	} elseif {$error == "ERRnoaccess"} {
		return "Error: No Access"
	} elseif {$error == "ERRnofids"} {
		return "Error: No FIDs"
	} elseif {$error == "ERRnofiles"} {
		return "Error: No Files"
	} elseif {$error == "ERRnomem"} {
		return "Error: Insufficient server memory to perform the requested function"
	} elseif {$error == "ERRnoresource"} {
		return "Error: No resources currently available for request"
	} elseif {$error == "ERRnosupport"} {
		return "Error: Function not supported"
	} elseif {$error == "ERRnotconnected"} {
		return "Error: No process on other end of pipe"
	} elseif {$error == "ERRnotready"} {
		return "Error: Drive not ready"
	} elseif {$error == "ERRnowrite"} {
		return "Error: Attempt to write on write-protected diskette"
	} elseif {$error == "ERRpaused"} {
		return "Error: Server is paused"
	} elseif {$error == "ERRpipebusy"} {
		return "Error: All instances of the requested pipe are busy"
	} elseif {$error == "ERRpipeclosing"} {
		return "Error: Pipe close in progress"
	} elseif {$error == "ERRread"} {
		return "Error: Read fault"
	} elseif {$error == "ERRrmuns"} {
		return "Error: Too many remote user names"
	} elseif {$error == "ERRseek"} {
		return "Error: Seek error"
	} elseif {$error == "ERRsetattrmode"} {
		return "Error: The attribute mode in the Set File Attribute request is invalid"
	} elseif {$error == "ERRsharebufexc"} {
		return "Error: Share Buffer"
	} elseif {$error == "ERRsmbcmd"} {
		return "Error: The server did not recognize the command received"
	} elseif {$error == "ERRsrverror"} {
		return "Error: Server Error"
	} elseif {$error == "ERRtimeout"} {
		return "Error: Operation timed out"
	} elseif {$error == "ERRtoomanyuids"} {
		return "Error: Too many UIDs active on this session"
	} elseif {$error == "ERRusempx"} {
		return "Error: Temp unable to support Raw, use MPX mode"
	} elseif {$error == "ERRusestd"} {
		return "Error: Temp unable to support Raw, use standard read/write"
	} elseif {$error == "ERRwrite"} {
		return "Error: Write fault"
	} elseif {$error == "ERRwrongdisk"} {
		return "Error: Wrong Disk"
	} else {
		return "Error: $error"
	}
}

proc SortShares {} {
	################################################
	global shares_m
	if {[info exists shares_m] == 1 && [array size shares_m] > "3"} {
		set i 0
		while {$i < [expr [array size shares_m] / 3]} {
			lappend dummy_list [string toupper $shares_m($i,1)]/$i
			set dummy($i,1) $shares_m($i,1)
			set dummy($i,2) $shares_m($i,2)
			set dummy($i,3) $shares_m($i,3)
			incr i
		}
		set numerated_list [lsort -ascii $dummy_list]
		set i 0
		while {$i < [llength $numerated_list]} {
			regexp {/([0-9]+)$} [lindex $numerated_list $i] stuff alpha_index
			set shares_m($i,1) $dummy($alpha_index,1)
			set shares_m($i,2) $dummy($alpha_index,2)
			set shares_m($i,3) $dummy($alpha_index,3)
			incr i
		}
	}
}


proc SortWorkgroups {} {
	################################################
	global workgroups_m
	if {[info exists workgroups_m] == 1 && [array size workgroups_m] > "2"} {
		set i 0
		while {$i < [expr [array size workgroups_m] / 2]} {
			lappend dummy_list [string toupper $workgroups_m($i,1)]/$i
			set dummy($i,1) $workgroups_m($i,1)
			set dummy($i,2) $workgroups_m($i,2)
			incr i
		}
		set numerated_list [lsort -ascii $dummy_list]
		for {set i 0} {$i < [llength $numerated_list]} {incr i} {
			regexp {/([0-9]+)$} [lindex $numerated_list $i] stuff alpha_index
			set workgroups_m($i,1) $dummy($alpha_index,1)
			set workgroups_m($i,2) $dummy($alpha_index,2)
		}
	}
}


proc ReadSmbConf {} {
	#####################################################
	# As of now, only reads in workgroup and wins server
	#
	global default_samba_workgroup
	global default_samba_wins_server
	global readfmt
	if {[file exists "/etc/smb.conf"] != "0"} {
		puts -nonewline [format "$readfmt" "Reading /etc/smb.conf "]; flush stdout
		set userfile [open "/etc/smb.conf" r]
	} elseif {[file exists "/usr/local/samba/etc/smb.conf"] != "0"} {
		puts -nonewline [format "$readfmt" "Reading /usr/local/samba/etc/smb.conf "]; flush stdout
		set userfile [open "/usr/local/samba/etc/smb.conf" r]
	} elseif {[file exists "/usr/local/samba/smb.conf"] != "0"} {
		puts -nonewline [format "$readfmt" "Reading /usr/local/samba/smb.conf "]; flush stdout
		set userfile [open "/usr/local/samba/smb.conf" r]
	} elseif {[file exists "/etc/samba/smb.conf"] != "0"} {
		puts -nonewline [format "$readfmt" "Reading /etc/samba/smb.conf "]; flush stdout
		set userfile [open "/etc/samba/smb.conf" r]
	} elseif {[file exists "/usr/local/samba/lib/smb.conf"] != "0"} {
		puts -nonewline [format "$readfmt" "Reading /usr/local/samba/lib/smb.conf "]; flush stdout
		set userfile [open "/usr/local/samba/lib/smb.conf" r]
	} else {
		puts "\[failed\]\n\[!\] W: file smb.conf was not found, using default values."
		set default_samba_workgroup "MSHOME"
		set default_samba_wins_server "none"
		return
	}
	set default_samba_workgroup "MSHOME"
	set default_samba_wins_server "none"
	set eof_check 0
	gets $userfile line
	set line [string toupper $line]
	while {[eof $userfile] == 0 & $eof_check != 9999} {
		if [regexp -indices "^(\t| )*WORKGROUP(\t| )*=(\t| )*(.*)" $line m1 m01 m02 m03 m2] {
			set default_samba_workgroup [string range $line [lindex $m2 0] [lindex $m2 1]]
			if {$default_samba_wins_server != "none"} {set eof_check 9998}
		} elseif [regexp -indices "^(\t| )*WINS SERVER(\t| )*=(\t| )*(.*)" $line m1 m01 m02 m03 m2] {
			set default_samba_wins_server [string range $line [lindex $m2 0] [lindex $m2 1]]
			if {$default_samba_workgroup != "UNKNOWN"} {set eof_check 9998}
		}
		gets $userfile line
		set line [string toupper $line]
		incr eof_check
	}
	close $userfile
	puts "\[ok\]\n... $eof_check lines / workgroup: $default_samba_workgroup / WINS server: $default_samba_wins_server"
}


proc ReadUserFile {} {
	#########################################
	global commands_m
	global mount_fav_m
	global networks_m
	global networks_extra
	global favorites_m
	global favorites_extra
	if [info exists commands_m] {unset commands_m}
	if [info exists mount_fav_m] {unset mount_fav_m}
	if [info exists networks_m] {unset networks_m}
	if [info exists networks_extra] {unset networks_extra}
	if [info exists favorites_m] {unset favorites_m}
	if [info exists favorites_extra] {unset favorites_extra}
	ReadUserFileNow Global
	ReadUserFileNow User
}

proc ReadUserFileNow {which_file} {
	#########################################
	global readfmt
	puts -nonewline [format "$readfmt" "Reading $which_file config... "]; flush stdout
	global user_name_default
	global set_timeout
	global mount_version
	global commands_m
	global mount_fav_m
	global cmultiply
	global pixmaps_buttons
	global networks_m
	global networks_extra
	global favorites_m
	global favorites_extra
	global show_next_time
	global history_length
	global image_path
	global file_place
	global default_pixmaps_dir
	global mount_addon
	global smbmount_execute
	global smbmount_tree
	global env_name
	if {$which_file == "Global"} {
		set user_name_default "defaults"
		set set_timeout "35"
		set history_length "20"
		set image_path "$default_pixmaps_dir"
		set cmultiply "6"
		set pixmaps_buttons "yes"
		set show_next_time "yes"
		set mount_addon "yes"
		set mount_version "2"
		set smbmount_execute "xterm -e mc \$MOUNTPOINT"
		set smbmount_tree "\$HOME/mnt"
	}
	set global_exist "no"
	if {$which_file == "Global"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-config" r]
		set global_exist "yes"
		gets $userfile line
	} else {
		if [file exists /etc/xsmbrowser/xsmbrowser-config] {
			set userfile [open "/etc/xsmbrowser/xsmbrowser-config" r]
			set global_exist "yes"
			gets $userfile line
		}
	}
	while {$global_exist == "yes" && $line != "EOF" & [eof $userfile] == "0"} {
		if [regexp -indices "^ *\[t,T]imeout *= *(.*)" $line m1 m2] {
			set set_timeout [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[I,i]mage \[P,p]ath *= *(.*)" $line m1 m2] {
			set image_path [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\Button Pixmaps *= *(.*)" $line m1 m2] {
			set pixmaps_buttons [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[O,o]bject \[S,s]pacing *= *(.*)" $line m1 m2] {
			set cmultiply [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[S,s]how \[L,l]icense *= *(.*)" $line m1 m2] {
			set show_next_time [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[U,u]sername *= *(.*)" $line m1 m2] {
			set user_name_default [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[E,e]xecute *= *(.*)" $line m1 m2] {
			set smbmount_execute [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[M,m]ount \[T,t]ree *= *(.*)" $line m1 m2] {
			set smbmount_tree [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *\[S,s]mbmount *= *(.*)" $line m1 m2] {
			set mount_addon [lindex [string range $line [lindex $m2 0] [lindex $m2 1]] 0]
			set mount_version [lindex [string range $line [lindex $m2 0] [lindex $m2 1]] 1]
		}
		gets $userfile line
	}
	if {$user_name_default == "defaults"} {set user_name_default ""}
	if {$global_exist == "yes"} {
		close $userfile
	}
	if {$which_file == "Global"} {
		set networks_m(1,name) "Default Samba"
		set networks_m(1,net_type) "broadcast"
		set networks_m(1,ip_num) "default_samba"
		set networks_m(1,workgroup) "default_samba"
		set networks_m(1,user_name) "defaults"
		set networks_m(1,password) "defaults"
	}
	set global_exist "no"
	if {$which_file == "User"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-networks" r]
		set global_exist "yes"
		gets $userfile line
		set m $file_place(networks_m)
	} else {
		if [file exists /etc/xsmbrowser/xsmbrowser-networks] {
			set userfile [open "/etc/xsmbrowser/xsmbrowser-networks" r]
			set global_exist "yes"
			gets $userfile line
		}
		set m 0
	}
	while {$global_exist == "yes" && $line != "EOF" & [eof $userfile] == "0"} {
		if [regexp -indices "^:(.*) *" $line m1 m2] {
			incr m
			set networks_m($m,name) [string range $line [lindex $m2 0] [lindex $m2 1]]
			set networks_m($m,net_type) "broadcast"
			set networks_m($m,ip_num) "default_samba"
			set networks_m($m,workgroup) "default_samba"
			set networks_m($m,user_name) "defaults"
			set networks_m($m,password) "defaults"
		} elseif [regexp -indices "^ *\[T,t]ype *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_m($m,net_type) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *IP \[N,n]um *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_m($m,ip_num) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\[W,w]orkgroup *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_m($m,workgroup) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Username *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_m($m,user_name) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Secondary Wins *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_extra($m,sec_wins) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Static Workgroup *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_extra($m,wg_static) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Master *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_extra($m,master) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Master IP *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_extra($m,master_ip) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Password *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set networks_m($m,password) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		}
		gets $userfile line
	}
	if {$global_exist == "yes"} {
		close $userfile
	}
	if {$which_file == "Global"} {
		set file_place(networks_m) $m
		set favorites_m(1,name) "Your Computer"
		set favorites_m(1,net_type) "ip_only"
		set favorites_m(1,ip_num) "127.0.0.1"
		set favorites_m(1,workgroup) ""
		set favorites_m(1,user_name) $env_name
		set favorites_m(1,password) "defaults"
		set favorites_m(1,netbios_des) "defaults"
		set favorites_m(1,share) "defaults"
		set mount_fav_m(1,share) "//SAMPLE/entry"
		set mount_fav_m(1,spot) "default"
		set mount_fav_m(1,uid) ""
		set mount_fav_m(1,gid) ""
		set mount_fav_m(1,file) ""
		set mount_fav_m(1,dir) ""
		set mount_fav_m(1,execute) "yes"
		set mount_fav_m(1,history) "no"
		set mount_fav_m(1,ip) "127.0.0.1"
		set mount_fav_m(1,workgroup) "none"
		set mount_fav_m(1,username) "none"
		set mount_fav_m(1,password) "none"
		set mount_fav_m(1,netbios) "SAMPLE"
		set mount_fav_m(1,sharename) "entry"
	}
	set global_exist "no"
	if {$which_file == "User"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-favorites" r]
		set global_exist "yes"
		gets $userfile line
		set m $file_place(favorites_m)
		set p $file_place(mount_fav_m)
	} else {
		if [file exists /etc/xsmbrowser/xsmbrowser-favorites] {
			set userfile [open "/etc/xsmbrowser/xsmbrowser-favorites" r]
			set global_exist "yes"
			gets $userfile line
		}
		set m 0
		set p 0
	}
	while {$global_exist == "yes" && $line != "EOF" & [eof $userfile] == "0"} {
		if [regexp -indices "^:(.*) *" $line m1 m2] {
			incr m
			set favorites_m($m,name) [string range $line [lindex $m2 0] [lindex $m2 1]]
			set favorites_m($m,net_type) "ip_only"
			set favorites_m($m,ip_num) "127.0.0.1"
			set favorites_m($m,workgroup) ""
			set favorites_m($m,user_name) "defaults"
			set favorites_m($m,password) "defaults"
			set favorites_m($m,netbios_des) "defaults"
			set favorites_m($m,share) "defaults"
		} elseif [regexp -indices "^ *\[T,t]ype *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,net_type) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *IP \[N,n]um *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,ip_num) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\[W,w]orkgroup *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,workgroup) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Username *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,user_name) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Password *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,password) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *Secondary Wins *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_extra($m,sec_wins) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *NetBIOS Name Destination *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set favorites_m($m,netbios_des) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^@(.*) *" $line m1 m2] {
			incr p
			set mount_fav_m($p,share) [string range $line [lindex $m2 0] [lindex $m2 1]]
			set mount_fav_m($p,spot) "default"
			set mount_fav_m($p,uid) ""
			set mount_fav_m($p,gid) ""
			set mount_fav_m($p,file) ""
			set mount_fav_m($p,dir) ""
			set mount_fav_m($p,execute) "yes"
			set mount_fav_m($p,history) "no"
			set mount_fav_m($p,ip) "127.0.0.1"
			set mount_fav_m($p,workgroup) ""
			set mount_fav_m($p,username) ""
			set mount_fav_m($p,password) ""
			set mount_fav_m($p,netbios) ""
			set mount_fav_m($p,sharename) ""
		} elseif [regexp -indices "^ *Mount Point *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,spot) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount UID *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,uid) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount GID *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,gid) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount FMask *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,file) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Execute *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,execute) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount DMask *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,dir) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *History *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,history) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount IP *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,ip) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount NetBios *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,netbios) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount Workgroup *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,workgroup) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount Username *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,username) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount Password *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,password) [string range $line [lindex $m2 0] [lindex $m2 1]]
		} elseif [regexp -indices "^ *Mount Share *= *(.*)" $line m1 m2] {
			set mount_fav_m($p,sharename) [string range $line [lindex $m2 0] [lindex $m2 1]]
		}
		gets $userfile line
	}
	if {$global_exist == "yes"} {
		close $userfile
	}
	if {$which_file == "Global"} {
		set file_place(mount_fav_m) $p
		set file_place(favorites_m) $m
		set commands_m(0,name) "Internal Text Viewer"
		set commands_m(0,types) ""
		set commands_m(0,command) "Internal Text Viewer"
	}
	set global_exist "no"
	if {$which_file == "User"} {
		set userfile [open "~/.xsmbrowser/xsmbrowser-commands" r]
		set global_exist "yes"
		gets $userfile line
		set m $file_place(commands_m)
	} else {
		if [file exists /etc/xsmbrowser/xsmbrowser-commands] {
			set userfile [open "/etc/xsmbrowser/xsmbrowser-commands" r]
			set global_exist "yes"
			gets $userfile line
		}
		set m 0
	}
	while {$global_exist == "yes" && $line != "EOF" & [eof $userfile] == "0"} {
		if [regexp -indices "^:(.*) *" $line m1 m2] {
			incr m
			set commands_m($m,name) [string range $line [lindex $m2 0] [lindex $m2 1]]
			set commands_m($m,types) ""
			set commands_m($m,command) ""
		} elseif [regexp -indices "^ *\[T,t]ypes *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set commands_m($m,types) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\[C,c]ommand *= *(.*)" $line m1 m2] {
			if {$m != "0"} {set commands_m($m,command) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		}
		gets $userfile line
	}
	if {$global_exist == "yes"} {
		close $userfile
	}
	if {$which_file == "Global"} {
		set file_place(commands_m) $m
	}
	puts "\[ok\]"
}


proc WriteUserFile {} {
	###############################################
	global user_name_default
	global file_place
	global set_timeout
	global mount_version
	global mount_fav_m
	global cmultiply
	global networks_m
	global pixmaps_buttons
	global networks_extra
	global favorites_m
	global favorites_extra
	global image_path
	global show_next_time
	global history_length
	global mount_addon
	global smbmount_execute
	global smbmount_tree
	global commands_m
	global env_name
	puts "Writing config (.xsmbrowser-*) ..."
	set userfile [open "~/.xsmbrowser/xsmbrowser-config" w]
	puts $userfile "# Values defined in /etc/xsmbrowser/xsmbrowser-config take first priority."
	puts $userfile "#"
	if {$user_name_default != ""} {
		puts $userfile "Username = $user_name_default"
	}
	puts $userfile "Timeout = $set_timeout"
	puts $userfile "Object Spacing = $cmultiply"
	puts $userfile "Image Path = $image_path"
	puts $userfile "Button Pixmaps = $pixmaps_buttons"
	puts $userfile "Show License = $show_next_time"
	puts $userfile "Smbmount = $mount_addon $mount_version"
	puts $userfile "Execute = $smbmount_execute"
	puts $userfile "Mount Tree = $smbmount_tree"
	puts $userfile ""
	puts $userfile "# File must end with EOF"
	puts $userfile "EOF"
	close $userfile
	set userfile [open "~/.xsmbrowser/xsmbrowser-networks" w]
	puts $userfile "# Networks in /etc/xsmbrowser/xsmbrowser-networks are read first."
	puts $userfile "#"
	if {[array exists networks_m] == 1} {
		set m [expr 1 + $file_place(networks_m)]
		while {$m < [expr 1 + [array size networks_m] / 6]} {
			if {$networks_m($m,name) != "delete_me"} {
				puts $userfile ":$networks_m($m,name)"
				puts $userfile "Type = $networks_m($m,net_type)"
				puts $userfile "IP Num = $networks_m($m,ip_num)"
				puts $userfile "Workgroup = $networks_m($m,workgroup)"
				if {$networks_m($m,user_name) != "defaults"} {
					puts $userfile "Username = $networks_m($m,user_name)"
				}
				if {$networks_m($m,password) != "defaults"} {
					puts $userfile "Password = $networks_m($m,password)"
				}
				if [info exists networks_extra($m,sec_wins)] {
					puts $userfile "Secondary Wins = $networks_extra($m,sec_wins)"
				}
				if [info exists networks_extra($m,wg_static)] {
					puts $userfile "Static Workgroup = no"
				}
				if [info exists networks_extra($m,master)] {
					puts $userfile "Master = $networks_extra($m,master)"
				}
				if [info exists networks_extra($m,master_ip)] {
					puts $userfile "Master IP = $networks_extra($m,master_ip)"
				}
				puts $userfile ""
		      }
		      incr m
		}
	}
	puts $userfile ""
	puts $userfile "# File must end with EOF"
	puts $userfile "EOF"
	close $userfile
	set userfile [open "~/.xsmbrowser/xsmbrowser-favorites" w]
	puts $userfile "# Favorites and mounts in /etc/xsmbrowser/xsmbrowser-favorites are read first."
	puts $userfile "#"
	if {[array exists favorites_m] == 1} {
		set m [expr 1 + $file_place(favorites_m)]
		while {$m < [expr 1 + [array size favorites_m] / 8]} {
			if {$favorites_m($m,name) != "delete_me"} {
				puts $userfile ":$favorites_m($m,name)"
				puts $userfile "Type = $favorites_m($m,net_type)"
				puts $userfile "IP Num = $favorites_m($m,ip_num)"
				puts $userfile "Workgroup = $favorites_m($m,workgroup)"
				if {$favorites_m($m,user_name) != "defaults"} {
					puts $userfile "Username = $favorites_m($m,user_name)"
				}
				if {$favorites_m($m,password) != "defaults"} {
					puts $userfile "Password = $favorites_m($m,password)"
				}
				if {$favorites_m($m,netbios_des) != "defaults"} {
					puts $userfile "NetBIOS Name Destination = $favorites_m($m,netbios_des)"
				}
				if [info exists favorites_extra($m,sec_wins)] {
					puts $userfile "Secondary Wins = $favorites_extra($m,sec_wins)"
				}
				puts $userfile ""
			}
			incr m
		}
	}
	puts $userfile "# Mount Points"
	if [info exists mount_fav_m] {
		set m [expr 1+ $file_place(mount_fav_m)]
		while {$m < [expr 1 + [array size mount_fav_m] / 14]} {
			puts $userfile "@$mount_fav_m($m,share)"
			puts $userfile "Mount Point = $mount_fav_m($m,spot)"
			if {$mount_fav_m($m,uid) != ""} {
				puts $userfile "Mount UID = $mount_fav_m($m,uid)"
			}
			if {$mount_fav_m($m,gid) != ""} {
				puts $userfile "Mount GID = $mount_fav_m($m,gid)"
			}
			if {$mount_fav_m($m,file) != ""} {
				puts $userfile "Mount FMask = $mount_fav_m($m,file)"
			}
			if {$mount_fav_m($m,dir) != ""} {
				puts $userfile "Mount DMask = $mount_fav_m($m,dir)"
			}
			if {$mount_fav_m($m,username) != ""} {
				puts $userfile "Mount Username = $mount_fav_m($m,username)"
			}
			if {$mount_fav_m($m,password) != ""} {
				puts $userfile "Mount Password = $mount_fav_m($m,password)"
			}
			puts $userfile "Execute = $mount_fav_m($m,execute)"
			puts $userfile "Mount NetBios = $mount_fav_m($m,netbios)"
			puts $userfile "Mount Workgroup = $mount_fav_m($m,workgroup)"
			puts $userfile "Mount IP = $mount_fav_m($m,ip)"
			puts $userfile "History = $mount_fav_m($m,history)"
			puts $userfile "Mount Share = $mount_fav_m($m,sharename)"
			puts $userfile ""
			incr m
		}
	}
	puts $userfile ""
	puts $userfile "# File must end with EOF"
	puts $userfile "EOF"
	close $userfile
	set userfile [open "~/.xsmbrowser/xsmbrowser-commands" w]
	puts $userfile "# Commands in /etc/xsmbrowser/xsmbrowser-commands are read first."
	puts $userfile "#"
	if {[array exists commands_m] == 1} {
		set m [expr 1 + $file_place(commands_m)]
		while {$m < [expr [array size commands_m] / 3]} {
			if {$commands_m($m,name) != "delete_me"} {
				puts $userfile ":$commands_m($m,name)"
				puts $userfile "Types = $commands_m($m,types)"
				puts $userfile "Command = $commands_m($m,command)"
				puts $userfile ""
			}
			incr m
		}
	}
	puts $userfile ""
	puts $userfile "# File must end with EOF"
	puts $userfile "EOF"
	close $userfile
	puts "Done writing."
}


proc DisableEnable {a b c d e f g h i j k l} {
	###################################################
	# Disables / Enables Buttons ...
	# a:net b:fav c:wgs d:up e:bk f:for g:sp h:rf i:sv j:tg k:ul l:canv
	#
	global canvason
	global place
	global place_local
	global workgroups_m
	global save_on
	if {$a == 1} {.top.top1.favorites config -state disabled
	} else {.top.top1.favorites config -state normal }
	if {$b == 1} {.top.top1.networks config -state disabled
	} else {.top.top1.networks config -state normal }
	if {$c == 1} {.top.top1.workgroups config -state disabled
	} else {
		if [info exists workgroups_m] {
			.top.top1.workgroups config -state normal
		} else {
			.top.top1.workgroups config -state disabled
		}
	}
	if {$e == 1} {.top.top2.back config -state disabled
	} else {
		if {$place != $place_local(pointer)} {
			.top.top2.back config -state normal
		} else {
			.top.top2.back config -state disabled
		}
	}
	if {$f == 1} {.top.top3.forward config -state disabled
	} else {
		if {$place != [expr $place_local(pointer) + $place_local(length) - 1]} {
			.top.top3.forward config -state normal
		} else {
			.top.top3.forward config -state disabled
		}
	}
	if {$g == 1} {.top.top4.stop config -state disabled
	} else {.top.top4.stop config -state normal }
	if {$h == 1} {.top.top4.refresh config -state disabled
	} else {.top.top4.refresh config -state normal }
	if {$i == 1} {.bottom.saveto config -state disabled
	} else {.bottom.saveto config -state normal }
	if {$k == 1} {.bottom.filequeue config -state disabled
	} else {.bottom.filequeue config -state normal }
	if {$l == 1} {set canvason "off"
	} else {set canvason "on"}
}


proc HistoryAdd {type length folder_length} {
	############################################
	# -> adds an entry to history for the Back
	#    and Forward buttons to operate
	#
	global history_m
	global favorites_m
	global networks_m
	global network_sec_wins
	global network_wg_static
	global network_master
	global network_master_ip
	global workgroups_m
	global computers_m
	global shares_m
	global folders_m
	global files_m
	global workgroup
	global computer_ip_num
	global computer
	global default_password
	global default_user_name
	global share
	global user_name
	global wins_ip_num
	global wins_domain_master
	global wins_domain_master_ip
	global broadcast_subnet
	global password
	global net_type
	global broadcast_master_ip_num
	global directory_a
	global place
	global place_local
	global history_length
	incr place
	if {$place_local(length) == $history_length} {
		if {$place == [expr $history_length + $place_local(pointer)]} {
			incr place_local(pointer)
			HistoryDelLocal [expr $place - $history_length]
		}
	} else {
		if {[expr $place - 1] == $place_local(length)} {
			incr place_local(length)
		}
	}
	if [info exists history_m($place,type)] {
		HistoryDelLocal $place
		if [info exists history_m($place,net_type)] {unset history_m($place,net_type)}
		if [info exists history_m($place,network_sec_wins)] {unset history_m($place,network_sec_wins)}
		if [info exists history_m($place,network_wg_static)] {unset history_m($place,network_wg_static)}
		if [info exists history_m($place,network_master)] {unset history_m($place,network_master)}
		if [info exists history_m($place,network_master_ip)] {unset history_m($place,network_master_ip)}
		if [info exists history_m($place,wins_ip_num)] {unset history_m($place,wins_ip_num)}
		if [info exists history_m($place,wins_domain_master)] {unset history_m($place,wins_domain_master)}
		if [info exists history_m($place,wins_domain_master_ip)] {unset history_m($place,wins_domain_master_ip)}
		if [info exists history_m($place,broadcast_subnet)] {unset history_m($place,broadcast_subnet)}
		if [info exists history_m($place,workgroup)] {unset history_m($place,workgroup)}
		if [info exists history_m($place,password)] {unset history_m($place,password)}
		if [info exists history_m($place,default_password)] {unset history_m($place,default_password)}
		if [info exists history_m($place,user_name)] {unset history_m($place,user_name)}
		if [info exists history_m($place,default_user_name)] {unset history_m($place,default_user_name)}
		if [info exists history_m($place,computer)] {unset history_m($place,computer)}
		if [info exists history_m($place,computer_ip_num)] {unset history_m($place,computer_ip_num)}
		if [info exists history_m($place,share)] {unset history_m($place,share)}
		if [info exists history_m($place,directory)] {unset history_m($place,directory)}
		if [info exists history_m($place,directory_a,length)] {unset history_m($place,directory_a,length)}
	}
	set history_m($place,type) $type
	set history_m($place,length) $length
	set history_m($place,folder_length) $folder_length
	if [info exists net_type] {set history_m($place,net_type) $net_type}
	if [info exists network_sec_wins] {set history_m($place,network_sec_wins) $network_sec_wins}
	if [info exists network_wg_static] {set history_m($place,network_wg_static) $network_wg_static}
	if [info exists network_master] {set history_m($place,network_master) $network_master}
	if [info exists network_master_ip] {set history_m($place,network_master_ip) $network_master_ip}
	if [info exists wins_ip_num] {set history_m($place,wins_ip_num) $wins_ip_num}
	if [info exists wins_domain_master] {set history_m($place,wins_domain_master) $wins_domain_master}
	if [info exists wins_domain_master_ip] {set history_m($place,wins_domain_master_ip) $wins_domain_master_ip}
	if [info exists broadcast_subnet] {set history_m($place,broadcast_subnet) $broadcast_subnet}
	if [info exists workgroup] {set history_m($place,workgroup) $workgroup}
	if [info exists password] {set history_m($place,password) $password}
	if [info exists default_password] {set history_m($place,default_password) $default_password}
	if [info exists user_name] {set history_m($place,user_name) $user_name}
	if [info exists default_user_name] {set history_m($place,default_user_name) $default_user_name}
	if [info exists computer] {set history_m($place,computer) $computer}
	if [info exists computer_ip_num] {set history_m($place,computer_ip_num) $computer_ip_num}
	if [info exists share] {set history_m($place,share) $share}
	set m 0
	if {$type == "workgroups"} {
		while {$m < $length} {
			set history_m($place,$m,1) $workgroups_m($m,1)
			set history_m($place,$m,2) $workgroups_m($m,2)
			incr m
		}
	}
	if {$type == "computers"} {
		for {} {$m < $length} {incr m} {
			set history_m($place,$m,1) $computers_m($m,1)
			set history_m($place,$m,2) $computers_m($m,2)
		}
	}
	if {$type == "shares"} {
		while {$m < $length} {
			set history_m($place,$m,1) $shares_m($m,1)
			set history_m($place,$m,2) $shares_m($m,2)
			set history_m($place,$m,3) $shares_m($m,3)
			incr m
		}
		if [info exists computers_m] {set history_m($place,computers_exists) "yes"}
	}
	if {$type == "files"} {
		for {} {$m < [expr $length - $folder_length]} {incr m} {
			set history_m($place,files,$m,1) $files_m($m,1)
			set history_m($place,files,$m,2) $files_m($m,2)
			set history_m($place,files,$m,3) $files_m($m,3)
		}
		for {set m 0} {$m < $folder_length} {incr m} {
			set history_m($place,folders,$m,1) $folders_m($m,1)
			set history_m($place,folders,$m,2) $folders_m($m,2)
			set history_m($place,folders,$m,3) $folders_m($m,3)
		}
		if [info exists directory_a] {
			set h_directory $directory_a(1)
			for {set m 2} {$m <= [array size directory_a]} {incr m} {
				set h_directory "$h_directory\\$directory_a($m)"
			}
			set history_m($place,directory) $h_directory
			set history_m($place,directory_a,length) [array size directory_a]
			for {set m 1} {$m <= [array size directory_a]} {incr m} {
				set history_m($place,directory_a,$m) $directory_a($m)
			}
		}
	}
}


proc HistoryDelLocal {placed} {
	############################################################
	global history_m
	set m 0
	set type $history_m($placed,type)
	if {$type == "workgroups"} {
		while {$m < $history_m($placed,length)} {
			if [info exists history_m($placed,$m,clicked)] {
				unset history_m($placed,$m,clicked)
			} 
			unset history_m($placed,$m,1)
			unset history_m($placed,$m,2)
			incr m
		}
	}
	if {$type == "computers"} {
		while {$m < $history_m($placed,length)} {
			if [info exists history_m($placed,$m,clicked)] {
				unset history_m($placed,$m,clicked)
			}        
			unset history_m($placed,$m,1)
			unset history_m($placed,$m,2)
			incr m
		}
	}
	if {$type == "shares"} {
		while {$m < $history_m($placed,length)} {
			if [info exists history_m($placed,$m,clicked)] {
				unset history_m($placed,$m,clicked)
			} 
			unset history_m($placed,$m,1)
			unset history_m($placed,$m,2)
			unset history_m($placed,$m,3)
			incr m
		}
	}
	if {$type == "files"} {
		if [info exists history_m($placed,files,0,1)] {
			while {$m < [expr $history_m($placed,length) - $history_m($placed,folder_length)]} {
				if [info exists history_m($placed,files,$m,clicked)] {
					unset history_m($placed,files,$m,clicked)
				} 
				unset history_m($placed,files,$m,1)
				unset history_m($placed,files,$m,2)
				unset history_m($placed,files,$m,3)
				incr m
			}
		}
		set m 0
		if [info exists history_m($placed,folders,0,1)] {
			while {$m < $history_m($placed,folder_length)} {
				if [info exists history_m($placed,folders,$m,clicked)] {
					unset history_m($placed,folders,$m,clicked)
				} 
				unset history_m($placed,folders,$m,1)
				unset history_m($placed,folders,$m,2)
				unset history_m($placed,folders,$m,3)
				incr m
			}
		}
		set m 1
		if [info exists history_m($placed,directory_a,length)] {
			while {$m <= $history_m($placed,directory_a,length)} {
				if [info exists history_m($placed,directory_a,$m)] {unset history_m($placed,directory_a,$m)}
				incr m
			}
		}
	}
}


proc HistoryCall {direction whichkind} {
	##########################################################
	global history_m
	global favorites_m
	global networks_m
	global mount_addon
	global workgroups_m
	global mstatus
	global computers_m
	global shares_m
	global folders_m
	global files_m
	global network_sec_wins
	global network_wg_static
	global network_master
	global network_master_ip
	global selected_file_size
	global files_list
	global folders_list
	global workgroup
	global computer_ip_num
	global computer
	global share
	global user_name
	global wins_ip_num
	global wins_domain_master
	global wins_domain_master_ip
	global broadcast_subnet
	global password
	global default_password
	global default_user_name
	global net_type
	global directory_a
	global place
	global place_local
	set place [expr $place + $direction]
	if {$whichkind == "local"} {
		if [info exists history_m($place,net_type)] {set net_type $history_m($place,net_type)}
		if [info exists history_m($place,network_sec_wins)] {set network_sec_wins $history_m($place,network_sec_wins)}
		if [info exists history_m($place,network_wg_static)] {set network_wg_static $history_m($place,network_wg_static)}
		if [info exists history_m($place,network_master)] {set network_master $history_m($place,network_master)}
		if [info exists history_m($place,network_master_ip)] {set network_master_ip $history_m($place,network_master_ip)}
		if [info exists history_m($place,share)] {set share $history_m($place,share)}
		if [info exists history_m($place,wins_ip_num)] {set wins_ip_num $history_m($place,wins_ip_num)}
		if [info exists history_m($place,wins_domain_master)] {set wins_domain_master $history_m($place,wins_domain_master)}
		if [info exists history_m($place,wins_domain_master_ip)] {set wins_domain_master $history_m($place,wins_domain_master_ip)}
		if [info exists history_m($place,broadcast_subnet)] {set broadcast_subnet $history_m($place,broadcast_subnet)}
		if [info exists history_m($place,workgroup)] {set workgroup $history_m($place,workgroup)}
		if {[info exists history_m($place,password)] == 1 &  $history_m($place,type) != "networks" & $history_m($place,type) != "favorites"} {
			set password $history_m($place,password)
			if {$direction != "0"} {
				.info.info0.stats delete 0 1024
				.info.info0.stats insert 0 $password
			}
		} else {
			.info.info0.stats delete 0 1024
		}
		if [info exists history_m($place,default_password)] {set default_password $history_m($place,default_password)}
		if {[info exists history_m($place,user_name)] == 1 &  $history_m($place,type) != "networks" &  $history_m($place,type) != "favorites"} {
			set user_name $history_m($place,user_name)
			if {$direction != "0"} {
				.info.info0.statU delete 0 1024
				.info.info0.statU insert 0 $user_name
			}
		} else {
			.info.info0.statU delete 0 1024
		}
		if [info exists history_m($place,default_user_name)] {set default_user_name $history_m($place,default_user_name)}
		if [info exists history_m($place,computer)] {set computer $history_m($place,computer)}
		if [info exists history_m($place,computer_ip_num)] {set computer_ip_num $history_m($place,computer_ip_num)}
	}
	set m 0
	set type $history_m($place,type)
	if {$type == "favorites"} {
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		.info.info2.stats config -text ""
		. config -cursor left_ptr
		.status.stats config -text ""
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
		DisplayOnCanvas "favorites" [expr [array size favorites_m] / 8] "" [expr 0 - $direction]
	}
	if {$type == "networks"} {
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		.info.info2.stats config -text ""
		. config -cursor left_ptr
		.status.stats config -text ""
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
		DisplayOnCanvas "networks" [expr [array size networks_m] / 6] "" [expr 0 - $direction]
	}
	if {$type == "workgroups"} {
		while {$m < $history_m($place,length)} {
			set workgroups_m($m,1) $history_m($place,$m,1)
			set workgroups_m($m,2) $history_m($place,$m,2)
			incr m
		}
		DisableEnable 0 0 0 1 0 0 1 1 1 1 0 0
		.info.info2.stats config -text ""
		. config -cursor left_ptr
		.status.stats config -text ""
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
		DisplayOnCanvas "workgroups" [expr [array size workgroups_m] / 2] "" [expr 0 - $direction]
	}
	if {$type == "computers"} {
		set go 1
		if [info exists computers_m] {
			if {$computers_m($m,1) == $history_m($place,$m,1)} {
				set go 0
			} else {
				unset computers_m
				set go 1
			}
		}
		if [info exists shares_m] {unset shares_m}
		if $go {
			for {} {$m < $history_m($place,length)} {incr m} {
				set computers_m($m,1) $history_m($place,$m,1)
				set computers_m($m,2) $history_m($place,$m,2)
			}
		}
		DisplayOnCanvas "computers" $history_m($place,length) "" [expr 0 - $direction]
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		.status.stats config -text " Workgroup: $workgroup"
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
	}
	if {$type == "shares"} {
		if {$whichkind == "local"} {
			if [info exists shares_m] {unset shares_m}
			while {$m < $history_m($place,length)} {
				set shares_m($m,1) $history_m($place,$m,1)
				set shares_m($m,2) $history_m($place,$m,2)
				set shares_m($m,3) $history_m($place,$m,3)
				incr m
			}
			set directory_a(1) "shares"
			DisplayOnCanvas "shares" $history_m($place,length) "" [expr 0 - $direction]
			DisableEnable 0 0 0 0 0 0 1 0 1 1 0 0
			if {[expr [array size shares_m] / 3] != 0} {
				.status.stats config -text " Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
				if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
					.mstatus.buttons.unmount config -state disabled}
				if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
					.mstatus.info2.stats config -text ""}
			}
		}
	}
	if {$type == "files"} {
		if {$whichkind == "local"} {
			if [info exists files_m] {unset files_m}
			if [info exists folders_m] {unset folders_m}
			if [info exists files_list] {unset files_list}
			if [info exists folders_list] {unset folders_list}
			if [info exists directory_a] {unset directory_a}
			set selected_file_size 0
			for {set m 0} {$m < [expr $history_m($place,length) - $history_m($place,folder_length)]} {incr m} {
				set files_m($m,1) $history_m($place,files,$m,1)
				set files_m($m,2) $history_m($place,files,$m,2)
				set files_m($m,3) $history_m($place,files,$m,3)
			}
			for {set m 0} {$m < $history_m($place,folder_length)} {incr m} {
				set folders_m($m,1) $history_m($place,folders,$m,1)
				set folders_m($m,2) $history_m($place,folders,$m,2)
				set folders_m($m,3) $history_m($place,folders,$m,3)
			}
			if [info exists history_m($place,directory)] {
				for {set m 1} {$m <= $history_m($place,directory_a,length)} {incr m} {
					set directory_a($m) $history_m($place,directory_a,$m)
				}
				set directory $history_m($place,directory)
			} else {
				set directory ""
			}
			DisplayOnCanvas "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3] [expr 0 - $direction]
			if {[expr [array size files_m] / 3 + [array size folders_m] / 3] == 0} {
				.info.info2.stats config -text "Directory Is Empty"
				. config -cursor left_ptr
				.info.info1.stats config -text " Total:"
				.cscroll.c delete all
			}
			DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
			.status.stats config -text " Dir: \\$directory  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
			if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
			if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
		}
	}
	if [info exists history_m($place,wheight)] {
		if {$history_m($place,wheight) == [expr [winfo height .cscroll.c] / 20 - 1]} {.cscroll.c xview moveto $history_m($place,wposition)}
	}
}


proc DisplayOnCanvas {c_type length folder_length spot} {
	##############################################
	# -> displays images and text on canvas
	#
	global favorites_m
	global networks_m
	global workgroups_m
	global computers_m
	global save_on
	global favorites_m
	global fav_m
	global net_m
	global box_select
	global shares_m
	global folders_m
	global history_m
	global place
	global image_path
	global files_m
	global total_file_size
	global files_list
	global folders_list
	global selected_file_size
	global directory_a
	global cmultiply
	if {$length == "0"} {
		return
	} else {
		.info.info2.stats config -text ""
		. config -cursor left_ptr
		.info.info1.stats config -text ""
	}
	set num_rows [expr [winfo height .cscroll.c] / 20 - 1]
	if {$num_rows == 0} {set num_rows 1}
	if {[info exists history_m] == 1 & $spot != "*"} {
		set history_m([expr $place + $spot],wheight) $num_rows
		set history_m([expr $place + $spot],wposition) [lindex [.cscroll.xscroll get] 0]
	}
	.cscroll.c delete all
	if {$c_type == "favorites" | $c_type == "networks" | $c_type == "workgroups"} {
		set m 0
		set col 0
		set row 0
		while {$m < $length} {
			if {$c_type == "favorites"} {
				if [info exists fav_m($favorites_m([expr $m + 1],name),clicked)] {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill blue1\
					-text $favorites_m([expr $m + 1],name) -anchor nw -tags "$m text$m favorites computer $m b$m"        
				} else {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill black\
					-text $favorites_m([expr $m + 1],name) -anchor nw -tags "$m text$m favorites computer $m b$m"        
				}
			} elseif {$c_type == "networks"} {
				if {[info exists net_m($networks_m([expr $m + 1],name),clicked)] == 1} {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill blue1\
					-text $networks_m([expr $m + 1],name) -anchor nw -tags "$m text$m networks $m $m b$m"
				} else {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill black\
					-text $networks_m([expr $m + 1],name) -anchor nw -tags "$m text$m networks $m $m b$m"
				}
			} else {
				if {$spot == 0} {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill black\
					-text $workgroups_m($m,1) -anchor nw -tags "$m text$m workgroups $m $m b$m"
				} elseif {[info exists history_m($place,$m,clicked)] == 1} {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill blue1\
					-text $workgroups_m($m,1) -anchor nw -tags "$m text$m workgroups $m $m b$m"
				} else {
					.cscroll.c create text [expr 30 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -width [expr 40 * $cmultiply - 20] -fill black\
					-text $workgroups_m($m,1) -anchor nw -tags "$m text$m workgroups $m $m b$m"
				}
			}
			if {$c_type == "workgroups" | $c_type == "networks"} {
				if {$image_path != "Use Geo"} {
					if {$c_type == "networks"} {
						.cscroll.c create image [expr 10 + $col * 40 * $cmultiply] [expr 13 + 20 * $row] -image networks_i -anchor nw\
						-tags "$m geo$m $c_type $m $m"
					} else {
						.cscroll.c create image [expr 10 + $col * 40 * $cmultiply] [expr 12 + 20 * $row] -image workgroups_i -anchor nw\
						-tags "$m geo$m $c_type $m $m"   
					}
				} else {
					.cscroll.c create line [expr 30 -11 + $col * 40 * $cmultiply] [expr 20 +1 + 20 * $row] [expr 30 -11 + $col * 40 * $cmultiply]\
					[expr 20 -4 + 20 * $row] -tags "$m geo$m $c_type $m $m"
					.cscroll.c create line [expr 30 -11 + $col * 40 * $cmultiply] [expr 20 + 20 * $row] [expr 30 -8 + $col * 40 * $cmultiply]\
					[expr 20 + 20 * $row] -tags "$m geo$m $c_type $m $m $m"
					.cscroll.c create rectangle [expr 30 -14 + $col * 40 * $cmultiply] [expr 20 +4 + 20 * $row] [expr 30 -11 + $col * 40 * $cmultiply]\
					[expr 20 +1 + 20 * $row] -fill blue1 -outline blue1 -tags "$m geo$m $c_type $m $m"
					.cscroll.c create rectangle [expr 30 -13 + $col * 40 * $cmultiply] [expr 20 -3 + 20 * $row] [expr 30 -10 + $col * 40 * $cmultiply]\
					[expr 20 -6 + 20 * $row] -fill blue1 -outline blue1 -tags "$m geo$m $c_type $m $m"
					.cscroll.c create rectangle [expr 30 -8 + $col * 40 * $cmultiply] [expr 20 -3 + 20 * $row] [expr 30 -5 + $col * 40 * $cmultiply]\
					[expr 20 + 20 * $row] -fill blue1 -outline blue1 -tags "$m geo$m $c_type $m $m"
					if {$c_type == "networks"} {.cscroll.c create rectangle [expr 30 -8 + $col * 40 * $cmultiply] [expr 20 -4 + 20 * $row]\
						[expr 30 -4 + $col *40 * $cmultiply] [expr 20 +4 + 20 * $row] -fill grey95 -tags "$m geo$m $c_type $m $m"}
				}
			}
			if {$c_type == "favorites"} {
				if {$image_path != "Use Geo"} {
					.cscroll.c create image [expr 10 + $col * 40 * $cmultiply] [expr 11 + 20 * $row] -image computers_i -anchor nw\
					-tags "$m geo$m favorites computer $m"        
				} else {
					.cscroll.c create rectangle [expr 30 - 14 + $col * 40 *  $cmultiply] [expr 20 - 1 + 20 * $row] [expr 30 - 4 + $col * 40 * $cmultiply]\
					[expr 20 + 4 + 20 * $row] -fill grey95 -tags "$m geo$m favorites computer $m"
					.cscroll.c create rectangle [expr 30 - 12 + $col * 40 * $cmultiply] [expr 20 - 7 + 20 * $row] [expr 30 - 6 + $col * 40 * $cmultiply]\
					[expr 20 - 1 + 20 * $row] -fill DeepSkyblue1 -tags "$m geo$m favorites computer $m"
				}
			}
			set bound_box [.cscroll.c bbox text$m]
			set item_height [expr [lindex $bound_box 3] - [lindex $bound_box 1]]
			if { $item_height > 20 } {
				if { [expr $item_height % 20] == 0 } {
					set row [expr $row + $item_height / 20]
					set stop_loop [expr $item_height / 20]
				} else {
					set row [expr 1 + $row + $item_height / 20]
					set stop_loop [expr 1 + $item_height / 20]
				}
			} else {
				set stop_loop 1
				incr row
			}
			if { $row == $num_rows } {
				set row 0
				incr col
			} elseif { $num_rows > $stop_loop & $row > $num_rows} {
				set row 0
				incr col
				.cscroll.c delete text$m
				.cscroll.c delete geo$m
				set m [expr $m - 1]
			}
			incr m
		}
		if {$row == "0"} {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 40 * $col * $cmultiply] 0"
		} else {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 40 * $cmultiply + 40 * $col * $cmultiply] 0"
		}
		bind .cscroll.c <Button-1> {
			.cscroll.c delete box
			set current_num [lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 0]
			if {$current_num != "" & $current_num != "boxbox"} {
				scrollButton .cscroll.c canvas
			} else {
				if {$canvason != "off"} {
					.cscroll.c delete boxbox
				}
			}
		}
		bind .cscroll.c <B1-Motion> {}
		bind .cscroll.c <Shift-B1-Motion> {}
		bind .cscroll.c <ButtonRelease-1> {}
		bind .cscroll.c <Button-3> "MarkBox .cscroll.c %x %y %W; SecondButton .cscroll.c $c_type"
	}

	if {$c_type == "shares" | $c_type == "computers"} {
		set m 0
		set col 0
		set row 0
		if {$c_type == "shares"} {
			while {$m < $length} {
				if {$spot == 0} {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill black\
					-text $shares_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill black -text $shares_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				} elseif {[info exists history_m($place,$m,clicked)] == 1} {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill blue1\
					-text $shares_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill blue1 -text $shares_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				} else {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill black\
					-text $shares_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill black -text $shares_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				}
				if {$image_path != "Use Geo"} {
					if {$shares_m($m,3) == "Disk"} {
						.cscroll.c create image [expr 10 + $col * 70 * $cmultiply] [expr 11 + 20 * $row] -image share_i -anchor nw\
						-tags "$m geo$m $c_type $m $m"
					} else {
						.cscroll.c create image [expr 10 + $col * 70 * $cmultiply] [expr 11 + 20 * $row] -image printer_c -anchor nw\
						-tags "$m geo$m $c_type $m $m"
					}
				} else {
					.cscroll.c create rectangle [expr 30 - 14 + $col * 70 * $cmultiply] [expr 20 - 4 + 20 * $row] [expr 30 -4 + $col * 70 * $cmultiply]\
					[expr 20 + 4 + 20 * $row] -fill Dodgerblue1 -tags "$m geo$m $c_type $m $m"
					.cscroll.c create rectangle [expr 30 - 14 + $col * 70 * $cmultiply] [expr 20 - 6 + 20 * $row] [expr 30 -9 + $col * 70 * $cmultiply]\
					[expr 20 - 4 + 20 * $row] -fill Dodgerblue1 -tags "$m geo$m $c_type $m $m"
					.cscroll.c create rectangle [expr 30 - 13 + $col * 70 * $cmultiply] [expr 20 + 3 + 20 * $row] [expr 30 -5 + $col * 70 * $cmultiply]\
					[expr 20 - 2 + 20 * $row] -outline Dodgerblue1 -fill Dodgerblue1 -tags "$m geo$m $c_type $m $m"
				}
				set bound_box [.cscroll.c bbox text$m]
				set item_height [expr [lindex $bound_box 3] - [lindex $bound_box 1]]
				if { $item_height > 20 } {
					if { [expr $item_height % 20] == 0 } {
						set row [expr $row + $item_height / 20]
						set stop_loop [expr $item_height / 20]
					} else {
						set row [expr 1 + $row + $item_height / 20]
						set stop_loop [expr 1 + $item_height / 20]
					}
				} else {
					set stop_loop 1
					incr row
				}
				if { $row == $num_rows } {
					set row 0
					incr col
				} elseif { $num_rows > $stop_loop & $row > $num_rows} {
					set row 0
					incr col
					.cscroll.c delete text$m
					.cscroll.c delete geo$m
					set m [expr $m - 1]
				}
				incr m
			}
		} else {
			while {$m < $length} {
				if {$spot == 0} {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill black\
					-text $computers_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill black -text $computers_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				} elseif {[info exists history_m($place,$m,clicked)] == 1} {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill blue1\
					-text $computers_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill blue1 -text $computers_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				} else {
					.cscroll.c create text [expr 200 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -width [expr 70 * $cmultiply - 195] -fill black\
					-text $computers_m($m,2) -anchor nw -tags "$m text$m $c_type $m $m b$m"
					.cscroll.c create text [expr 30 + $col * 70 * $cmultiply] [expr 13 + 20 * $row] -fill black -text $computers_m($m,1) -anchor nw\
					-tags "$m text$m $c_type sec$m $m b$m"
				}
				if {$image_path != "Use Geo"} {
					.cscroll.c create image [expr 10 + $col * 70 * $cmultiply] [expr 11 + 20 * $row] -image computers_i -anchor nw\
					-tags "$m geo$m $c_type $m $m"
				} else {
					.cscroll.c create rectangle [expr 30 - 14 + $col * 70 * $cmultiply] [expr 20 - 1 + 20 * $row] [expr 30 - 4 + $col * 70 * $cmultiply]\
					[expr 20 + 4 + 20 * $row] -fill grey95 -tags "$m geo$m $c_type $m $m"
					.cscroll.c create rectangle [expr 30 - 12 + $col * 70 * $cmultiply] [expr 20 - 7 + 20 * $row] [expr 30 - 6 + $col * 70 * $cmultiply]\
					[expr 20 - 1 + 20 * $row] -fill DeepSkyblue1 -tags "$m geo$m $c_type $m $m"
				}
				if {[string length $computers_m($m,2)] > 18} {
					set bound_box [.cscroll.c bbox text$m]
					set item_height [expr [lindex $bound_box 3] - [lindex $bound_box 1]]
					if { $item_height > 20 } {
						if { [expr $item_height % 20] == 0 } {
							set row [expr $row + $item_height / 20]
							set stop_loop [expr $item_height / 20]
						} else {
							set row [expr 1 + $row + $item_height / 20]
							set stop_loop [expr 1 + $item_height / 20]
						}
					} else {
						set stop_loop 1
						incr row
					}
				} else {
					set stop_loop 1
					incr row
				}
				if { $row == $num_rows } {
					set row 0
					incr col
				} elseif { $num_rows > $stop_loop & $row > $num_rows} {
					set row 0
					incr col
					.cscroll.c delete text$m
					.cscroll.c delete geo$m
					set m [expr $m - 1]
				}
				incr m
			}
		}
		if {$row == "0"} {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 70 * $col * $cmultiply] 0"
		} else {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 70 * $cmultiply + 70 * $col * $cmultiply] 0"
		}
		if {$c_type == "computers"} {
			if {$m == 1} {
				.info.info1.stats config -text " $m Computer"
			} else {
				.info.info1.stats config -text " $m Computers"
			}
		}
		bind .cscroll.c <Button-1> {
			.cscroll.c delete box
			set current_num [lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 0]
			if {$current_num != "" & $current_num != "boxbox"} {
				scrollButton .cscroll.c canvas
			} else {
				if {$canvason != "off"} {
					.cscroll.c delete boxbox
				}
			}
		}
		bind .cscroll.c <B1-Motion> {}
		bind .cscroll.c <Shift-B1-Motion> {}
		bind .cscroll.c <ButtonRelease-1> {}
		bind .cscroll.c <Button-3> "MarkBox .cscroll.c %x %y %W; SecondButton .cscroll.c $c_type"
	}
	if {$c_type == "files"} {
		set total_file_size 0
		set m 0
		set col 0
		set row 0
		while {$m < $length} {
			if {$m < $folder_length} {
				.cscroll.c create text [expr 60 * $cmultiply - 20 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -fill black -text "Directory" -anchor ne\
				-tags "null null$m"
				if {$spot == 0} {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill black\
					-text $folders_m($m,1) -anchor nw -tags "$m text$m files folder $m"
				} elseif {[info exists history_m($place,folders,$m,clicked)] == 1 } {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill blue1\
					-text $folders_m($m,1) -anchor nw -tags "$m text$m files folder $m"
				} else {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill black\
					-text $folders_m($m,1) -anchor nw -tags "$m text$m files folder $m"
				}
				if {$image_path != "Use Geo"} {
					if {[string range $folders_m($m,1) 0 0] == "."} {
						.cscroll.c create image [expr 10 + $col * 60 * $cmultiply] [expr 11 + 20 * $row] -anchor nw -image h_folder_i\
						-tags "d$m geo$m files folder $m"
					} else {
						.cscroll.c create image [expr 10 + $col * 60 * $cmultiply] [expr 11 + 20 * $row] -anchor nw -image folder_i\
						-tags "d$m geo$m files folder $m"
					}
				} else {
					.cscroll.c create rectangle [expr 30 - 14 + $col * 60 * $cmultiply] [expr 20 - 4 + 20 * $row] [expr 30 -4 + $col * 60 * $cmultiply]\
					[expr 20 + 4 + 20 * $row] -fill AntiqueWhite2 -tags "d$m geo$m files folder $m"
					.cscroll.c create rectangle [expr 30 - 13 + $col * 60 * $cmultiply] [expr 20 - 6 + 20 * $row] [expr 30 -9 + $col * 60 * $cmultiply]\
					[expr 20 - 4 + 20 * $row] -fill AntiqueWhite2 -tags "$m geo$m files folder $m"
					.cscroll.c create rectangle [expr 30 - 13 + $col * 60 * $cmultiply] [expr 20 + 3 + 20 * $row] [expr 30 -5 + $col * 60 * $cmultiply]\
					[expr 20 - 1 + 20 * $row] -outline AntiqueWhite2 -fill AntiqueWhite2 -tags "$m geo$m files folder $m"
				}
			} else {
				.cscroll.c create text [expr 60 * $cmultiply - 20 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -fill black\
				-text $files_m([expr $m - $folder_length],3) -anchor ne -tags "null nnull[expr $m - $folder_length]"
				if {$spot == 0} {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill black\
					-text $files_m([expr $m - $folder_length],1) -anchor nw -tags "[expr $m - $folder_length] ttext[expr $m - $folder_length]\
					files file [expr $m - $folder_length]"
				} elseif {[info exists history_m($place,files,[expr $m - $folder_length],clicked)] == 1 } {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill blue1\
					-text $files_m([expr $m - $folder_length],1) -anchor nw -tags "[expr $m - $folder_length] ttext[expr $m - $folder_length]\
					files file [expr $m - $folder_length]"
				} else {
					.cscroll.c create text [expr 30 + $col * 60 * $cmultiply] [expr 13 + 20 * $row] -width [expr 60 * $cmultiply - 125] -fill black\
					-text $files_m([expr $m - $folder_length],1) -anchor nw -tags "[expr $m - $folder_length] ttext[expr $m - $folder_length]\
					files file [expr $m - $folder_length]"
				}
				if {$image_path != "Use Geo"} {
					.cscroll.c create image [expr 10 + $col * 60 * $cmultiply] [expr 11 + 20 * $row] -anchor nw\
					-image [ChooseIcon $files_m([expr $m - $folder_length],1)] -tags "f[expr $m - $folder_length] ggeo[expr $m - $folder_length]\
					files file [expr $m - $folder_length]"
				} else {
					.cscroll.c create rectangle [expr 30 - 12 + $col * 60 * $cmultiply] [expr 20 - 7 + 20 * $row] [expr 30 - 4 + $col * 60 * $cmultiply]\
					[expr 20 + 4 + 20 * $row] -fill white -tags "f[expr $m - $folder_length] ggeo[expr $m - $folder_length] files file\
					[expr $m - $folder_length]"
				}
				set total_file_size [expr $total_file_size + $files_m([expr $m - $folder_length],3)]
			}
			if {$m < $folder_length} {
				set bound_box [.cscroll.c bbox text$m]
			} else {
				set bound_box [.cscroll.c bbox ttext[expr $m - $folder_length]]
			}
			set item_height [expr [lindex $bound_box 3] - [lindex $bound_box 1]]
			if { $item_height > 20 } {
				if { [expr $item_height % 20] == 0 } {
					set row [expr $row + $item_height / 20]
					set stop_loop [expr $item_height / 20]
				} else {
					set row [expr 1 + $row + $item_height / 20]
					set stop_loop [expr 1 + $item_height / 20]
				}
			} else {
				set stop_loop 1
				incr row
			}
			if { $row == $num_rows } {
				set row 0
				incr col
			} elseif { $num_rows > $stop_loop & $row > $num_rows} {
				set row 0
				incr col
				.cscroll.c delete text$m ttext[expr $m - $folder_length]
				.cscroll.c delete sec$m ssec[expr $m - $folder_length]
				.cscroll.c delete geo$m ggeo[expr $m - $folder_length]
				.cscroll.c delete null$m nnull[expr $m - $folder_length]
				set m [expr $m - 1]
			}
			incr m
		}
		if {$row == "0"} {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 60 * $col * $cmultiply] 0"
		} else {
			.cscroll.c config -scrollregion "0 0 [expr 30 + 60 * $cmultiply + 60 * $col * $cmultiply] 0"
		}
		if {$total_file_size < 1024} {
			set total_file_size "$total_file_size"
		} elseif {$total_file_size < 1048576} {
			set total_file_size "[expr $total_file_size / 1024]KB"
		} elseif {$total_file_size < 1073741824} {
			set total_file_size [expr $total_file_size / 1048576.0]
			set total_file_size "[string range $total_file_size 0 [expr 1 + [string last "." $total_file_size]]]MB"
		} else {
			set total_file_size [expr $total_file_size / 1073741824.0]
			set total_file_size "[string range $total_file_size 0 [expr 1 + [string last "." $total_file_size]]]GB"
		}
		.info.info1.stats config -text " Total: $total_file_size"
		.cscroll.c bind $c_type <Button-1> ""
		bind .cscroll.c <Button-3> {
			MarkBox .cscroll.c %x %y %W
			SecondButton .cscroll.c files
		}
		bind .cscroll.c <Button-1> {
			set current_num [lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 4]
			set current_type [lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 3]
			.cscroll.c delete box
			if {$box_sel == "delete"} {
				.cscroll.c delete bb
				.cscroll.c dtag yes yes
				set selected_file_size 0
				.info.info1.stats config -text " Total: $total_file_size"
				if {[info exists files_list] == "1" | [info exists folders_list] == "1"} {
					if {[info exists files_list] == "1"} {unset files_list}
					if {[info exists folders_list] == "1"} {unset folders_list}
					set boxbox_del "no"
				} else {
					set boxbox_del "yes"
				}
				if [info exists folders_list] {
					unset folders_list
				}
			} else {
				set box_sel "delete"
				if {[info exists files_list] == "1" | [info exists folders_list] == "1"} {
					set boxbox_del "no"
				} else {
					set boxbox_del "yes"
				}
			}
			MarkBox .cscroll.c %x %y %W
			if {$current_num != "" & $current_num != "boxbox" & $current_num != "null"} {
				if {$current_type == "folder"} {
					scrollButtonFolder .cscroll.c canvas
				} else {
					scrollButton .cscroll.c canvas
				}
			} else {
				if {$boxbox_del == "yes" & $canvason != "off"} {
					.cscroll.c delete boxbox
				}
			}
		}
		.cscroll.c bind files <Shift-Button-1> {
			set select_list [SelectList [lindex [.cscroll.c find withtag yes] end] [.cscroll.c find withtag current]]
			SelectBox .cscroll.c "shift" $select_list
		}
		.cscroll.c bind files <Control-Button-1> {
			scrollButton .cscroll.c canvas
		}
		bind .cscroll.c <B1-Motion> {
			.cscroll.c delete bb
			.cscroll.c dtag yes yes
			set selected_file_size 0
			.info.info1.stats config -text " Total: $total_file_size"
			if [info exists files_list] {unset files_list}
			if [info exists folders_list] {unset folders_list}
			set box_select "yes-ctrl"
			DrawBox .cscroll.c %x %y %W
		}
		bind .cscroll.c <Shift-Button-1> {
			.cscroll.c delete box
			MarkBox .cscroll.c %x %y %W
		}
		bind .cscroll.c <Control-Button-1> {
			.cscroll.c delete box
			MarkBox .cscroll.c %x %y %W
		}
		bind .cscroll.c <Shift-B1-Motion> {
			set box_select "yes-shift"
			DrawBox .cscroll.c %x %y %W
		}
		bind .cscroll.c <Control-B1-Motion> {
			set box_select "yes-ctrl"
			DrawBox .cscroll.c %x %y %W
		}
		bind .cscroll.c <ButtonRelease-1> {
			if {$box_select == "yes-shift"} {
				SelectBox .cscroll.c shift "none"
			} elseif {$box_select == "yes-ctrl"} {
				SelectBox .cscroll.c ctrl "none"
			}
			set box_select "no"
		}
		.cscroll.c bind file <Double-1> {
			set history_m($place,files,[lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 4],clicked) "yes"
			.cscroll.c itemconfigure ttext[lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 4] -fill blue1
			OpenCommand [lindex [.cscroll.c gettags [.cscroll.c find withtag current]] 4]
		}
	}
	if {$spot == "0"} {.cscroll.c xview moveto 0}
}


proc scrollLeave {canvas} {
	set current_id [$canvas find withtag current]
	if {[lindex [$canvas gettags $current_id] 2] == "second"} {
		$canvas itemconfigure $current_id -fill black
	}
}


proc SecondButton {canvas c_type} {
	###############################################################
	global networks_m
	global favorites_m
	global workgroups_m
	global shares_m
	global explore_type
	global share
	global computer
	global files_m
	global folders_m
	global files_list
	global folders_list
	global selected_file_size
	global total_file_size
	global directory_a
	global checker
	global canvason
	global place
	global net_type
	global history_m
	global current_id_sec
	global fav_index
	global test_s
	global zc_s
	global box_x1
	global box_y1
	focus .
	$canvas delete box
	if {$canvason == "off"} {return}
	set current_id [$canvas find withtag current]
	if {[lindex [$canvas gettags $current_id] 0] == "boxbox" | [lindex [$canvas gettags $current_id] 1] == "bb" | \
		[lindex [$canvas gettags $current_id] 0] == "null"} {set current_id ""}
	set current_id_sec $current_id
	if {$current_id == ""} {
		if {$c_type != "files"} {
			$canvas delete boxbox
		}
	} else {
		set data_type [lindex [$canvas gettags $current_id] 2]
		set data_type_t [lindex [$canvas gettags $current_id] 3]
		set data_type_m [lindex [$canvas gettags $current_id] 4]
		set text_type "text"
		if {$data_type == "files" & $data_type_t == "file"} {set text_type "ttext"}
		if {$data_type == "computers" | $data_type == "shares"} {set text_type "sec"}
		$canvas delete boxbox
		set bb [.cscroll.c bbox $text_type$data_type_m]
		if {$data_type == "files"} {
			$canvas create rectangle [expr [lindex $bb 0] - 3] [expr [lindex $bb 1] - 3] [expr [lindex $bb 2] + 2] [expr [lindex $bb 3] + 2]\
			-width 1 -outline black -tags "boxbox"
		} else {
			$canvas create rectangle [lindex $bb 0] [lindex $bb 1] [lindex $bb 2] [lindex $bb 3] -width 6 -outline grey80 -fill grey80 -tags "boxbox"
			$canvas raise $text_type$data_type_m boxbox
			$canvas raise geo$data_type_m boxbox
			$canvas raise ggeo$data_type_m boxbox
		}
	}
	if {$c_type == "networks"} {set height 126; set width 150}
	if {$c_type == "favorites"} {set height 126; set width 160}
	if {$c_type == "workgroups"} {set height 72; set width 150}
	if {$c_type == "files"} {
		if {[lindex [$canvas gettags $current_id] 3] == "file"} {
			set letter "f"
		} else {
			set letter "d"
		}
		if {[lindex [$canvas gettags $letter[lindex [$canvas gettags $current_id] 4]] 5] != "yes"} {
			.cscroll.c delete bb
			.cscroll.c dtag yes yes
			set selected_file_size 0
			.info.info1.stats config -text " Total: $total_file_size"
			if [info exists files_list] {unset files_list}
			if [info exists folders_list] {unset folders_list}
			scrollButton .cscroll.c $current_id
		}
		set height 162; set width 150
		set file_selec "file"
		if {[lindex [$canvas gettags $current_id] 3] == "folder"} {
			set file_selec "folder"
		}
	}
	if {$c_type == "shares"} {
		if {$current_id_sec != ""} {
			set zc_s [lindex [.cscroll.c gettags $current_id_sec] 4]
			set test_s [UnmountCheck "//$computer/$shares_m($zc_s,1)"]
		}
		set height 108; set width 150
	}
	if {$c_type == "computers"} {set height 72; set width 150}
	set position [winfo height $canvas]
	set position2 [$canvas canvasx [winfo width $canvas]]
	set position3 [$canvas canvasx 0]
	if {$current_id == ""} {
		set x1 $box_x1
		set y1 $box_y1
		set x2 [expr $x1 + $width]
		set y2 [expr $y1 + $height]
	} else {
		set coordinates [$canvas bbox $current_id]
		set x1 [expr [lindex $coordinates 0] + 15]
		set y1 [expr [lindex $coordinates 1] + 2]
		set x2 [expr $x1 + $width]
		set y2 [expr $y1 + $height]
	}
	if {$y2 > $position} {
		set y1 [expr $position - $height - 4]
		set y2 [expr $position - 4]
	}
	if {$x2 > $position2} {
		set x1 [expr $position2 - $width - 3]
		set x2 [expr $position2 - 3]
	}
	if {$x1 < $position3} {
		set x1 [expr $position3 + 3]
		set x2 [expr $position3 + $width + 3]
	}
	$canvas create rectangle $x1 $y1 $x2 $y2 -fill grey80 -outline black -tag box
	if {$c_type == "networks"} {
		$canvas create text [expr $x1+3] [expr $y1+10]\
		-fill black -text "Enter Network               " -anchor w -tags "box enter"
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Edit Network                  " -anchor w -tags "box edit"
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Delete Network             " -anchor w -tags "box delete"
		if {$current_id == ""} {
			$canvas delete boxbox
			$canvas itemconfigure enter -fill grey60
			$canvas itemconfigure edit -fill grey60
			$canvas itemconfigure delete -fill grey60
			$canvas bind enter <Button-1> {}
			$canvas bind edit <Button-1> {}
			$canvas bind delete <Button-1> {}
		} else {
			$canvas bind enter <Button-1> {
				.cscroll.c delete box
				scrollButton .cscroll.c $current_id_sec
			}
			$canvas bind edit <Button-1> {
				AddNetworkDialog [expr [lindex [.cscroll.c gettags $current_id_sec] 4] + 1]
			}
			$canvas bind delete <Button-1> {
				set zc [expr [lindex [.cscroll.c gettags $current_id_sec] 4] + 1]
				set networks_m($zc,name) "delete_me"
				WriteUserFile
				unset networks_m
				.top.top4.refresh invoke
			}
			$canvas addtag second withtag enter
			$canvas addtag second withtag edit
			$canvas addtag second withtag delete
		}
		set bby [lindex [$canvas bbox delete] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Add Network               " -anchor w -tags "box add second"
		$canvas bind add <Button-1> {
			AddNetworkDialog add
		}
		$canvas create text [expr $x1+3] [expr $y1+82]\
		-fill black -text "Resolve IP                " -anchor w -tags "box resolve second"
		$canvas bind resolve <Button-1> {
			.cscroll.c delete box
			set net_type "ip_only"
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+100]\
		-fill black -text "Find Computer             " -anchor w -tags "box find second"
		$canvas bind find <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+118]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
	} elseif {$c_type == "favorites"} {
		$canvas create text [expr $x1+3] [expr $y1+10]\
		-fill black -text "Enter Favorite              " -anchor w -tags "box enter"
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Edit Favorite              " -anchor w -tags "box rename"
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Delete Favorite              " -anchor w -tags "box delete"
		if {$current_id == ""} {
			$canvas delete boxbox
			$canvas itemconfigure enter -fill grey60
			$canvas itemconfigure rename -fill grey60
			$canvas itemconfigure delete -fill grey60
			$canvas bind enter <Button-1> {}
			$canvas bind rename <Button-1> {}
			$canvas bind delete <Button-1> {}
		} else {
			$canvas bind enter <Button-1> {
				.cscroll.c delete box
				scrollButton .cscroll.c $current_id_sec
			}
			$canvas bind rename <Button-1> {
				set zc [expr [lindex [.cscroll.c gettags $current_id_sec] 4] + 1]
				AddFavDialog $zc
			}
			$canvas bind delete <Button-1> {
				set zc [expr [lindex [.cscroll.c gettags $current_id_sec] 4] + 1]
				set favorites_m($zc,name) "delete_me"
				WriteUserFile
				unset favorites_m
				.top.top4.refresh invoke
			}
			$canvas addtag second withtag enter
			$canvas addtag second withtag rename
			$canvas addtag second withtag delete
		}
		set bby [lindex [$canvas bbox delete] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Add Favorite                " -anchor w -tags "box add second"
		$canvas bind add <Button-1> {
			AddFavDialog add
		}
		$canvas create text [expr $x1+3] [expr $y1+82]\
		-fill black -text "Resolve IP                 " -anchor w -tags "box resolve second"
		$canvas bind resolve <Button-1> {
			.cscroll.c delete box
			set net_type "ip_only"
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+100]\
		-fill black -text "Find Computer             " -anchor w -tags "box find second"
		$canvas bind find <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+118]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
	} elseif {$c_type == "workgroups"} {
		$canvas create text [expr $x1+3] [expr $y1+10]\
		-fill black -text "Enter Workgroup            " -anchor w -tags "box enter"
		if {$current_id == ""} {
			$canvas delete boxbox
			$canvas itemconfigure enter -fill grey60
			$canvas bind enter <Button-1> {}
		} else {
			$canvas bind enter <Button-1> {
				.cscroll.c delete box
				scrollButton .cscroll.c $current_id_sec
			}
			$canvas addtag second withtag enter
		}
		set bby [lindex [$canvas bbox enter] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Find Workgroup              " -anchor w -tags "box find second"
		$canvas bind find <Button-1> {
			.cscroll.c delete box
			FindWorkgroup
		}
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Find Computer               " -anchor w -tags "box resolve second"
		$canvas bind resolve <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
	} elseif {$c_type == "computers"} {
		$canvas create text [expr $x1+3] [expr $y1+10]\
		-fill black -text "Enter Computer              " -anchor w -tags "box enter"
		if {$current_id == ""} {
			$canvas delete boxbox
			$canvas itemconfigure enter -fill grey60
			$canvas bind enter <Button-1> {}
		} else {
			$canvas bind enter <Button-1> {
				.cscroll.c delete box
				scrollButton .cscroll.c $current_id_sec
			}
			$canvas addtag second withtag enter
		}
		set bby [lindex [$canvas bbox enter] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Find Computer              " -anchor w -tags "box find second"
		$canvas bind find <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Find Workgroup              " -anchor w -tags "box findw"
		$canvas bind findw <Button-1> {
			.cscroll.c delete box
			FindWorkgroup
		}
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
		if {$net_type == "ip_only"} {
			$canvas itemconfigure findw -fill grey60
			$canvas bind findw <Button-1> {}
		} else {
			$canvas addtag second withtag findw
		}
	} elseif {$c_type == "files"} {
		if {$file_selec != "folder"} {
			$canvas create text [expr $x1+3] [expr $y1+10]\
			-fill black -text "Open File                  " -anchor w -tags "box open"
		} else {
			$canvas create text [expr $x1+3] [expr $y1+10]\
			-fill black -text "Enter Directory                " -anchor w -tags "box open second"
			$canvas bind open <Button-1> {
				.cscroll.c delete box
				scrollButtonFolder .cscroll.c $current_id_sec
			}
		}
		set bby [lindex [$canvas bbox open] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Save Selected               " -anchor w -tags "box save"
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Delete Selected               " -anchor w -tags "box delete"
		set bby [lindex [$canvas bbox delete] 3]
		$canvas create line $x1 $bby $x2 $bby -fill black -tags box
		if {$current_id == ""} {
			$canvas itemconfigure save -fill grey60
			$canvas itemconfigure open -fill grey60
			$canvas itemconfigure delete -fill grey60
			$canvas bind save <Button-1> {}
			$canvas bind open <Button-1> {}
			$canvas bind delete <Button-1> {}
		} else {
			$canvas bind save <Button-1> {
				set box_sel "no"
				SaveSelected
			}
			if {$file_selec != "folder"} {
				$canvas bind open <Button-1> {
					set box_sel "no"
					set zc [lindex [.cscroll.c gettags $current_id_sec] 4]
					set history_m($place,files,$zc,clicked) "yes"
					.cscroll.c itemconfigure ttext$zc -fill blue1
					OpenCommand $zc
				}
			}
			$canvas bind delete <Button-1> {
				set box_sel "no"
				DeleteSelected
			}
			$canvas addtag second withtag save
			$canvas addtag second withtag open
			$canvas addtag second withtag selected
			$canvas addtag second withtag delete
			$canvas addtag second withtag delselected
		}
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Upload File               " -anchor w -tags "box upload second"
		$canvas bind upload <Button-1> {
			set box_sel "no"
			UploadFile
		}
		$canvas create text [expr $x1+3] [expr $y1+82]\
		-fill black -text "Power Transfer              " -anchor w -tags "box power second"
		$canvas bind power <Button-1> {
			set box_sel "no"
			SaveDialog 1
		}
		$canvas create text [expr $x1+3] [expr $y1+100]\
		-fill black -text "Make Directory               " -anchor w -tags "box makedir second"
		$canvas bind makedir <Button-1> {
			set box_sel "no"
			MakeFolder
		}
		$canvas create text [expr $x1+3] [expr $y1+118]\
		-fill black -text "Find File               " -anchor w -tags "box search second"
		$canvas bind search <Button-1> {
			.cscroll.c delete box
			set box_sel "no"
			FindName
		}
		$canvas create text [expr $x1+3] [expr $y1+136]\
		-fill black -text "Find Computer               " -anchor w -tags "box resolve second"
		$canvas bind resolve <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+154]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
	} elseif {$c_type == "shares"} {
		$canvas create text [expr $x1+3] [expr $y1+10]\
		-fill black -text "Enter Share                  " -anchor w -tags "box enter"
		$canvas create text [expr $x1+3] [expr $y1+28]\
		-fill black -text "Explore Share                " -anchor w -tags "box explore"
		$canvas create text [expr $x1+3] [expr $y1+46]\
		-fill black -text "Mount Share                " -anchor w -tags "box mount"
		$canvas create text [expr $x1+3] [expr $y1+64]\
		-fill black -text "Unmount Share               " -anchor w -tags "box unmount"
		if {$current_id == ""} {
			$canvas delete boxbox
			$canvas itemconfigure enter -fill grey60
			$canvas itemconfigure explore -fill grey60
			$canvas itemconfigure mount -fill grey60
			$canvas itemconfigure unmount -fill grey60
			$canvas bind enter <Button-1> {}
			$canvas bind explore <Button-1> {}
			$canvas bind unmount <Button-1> {}
			$canvas bind mount <Button-1> {}
		} else {
			$canvas bind enter <Button-1> {
				.cscroll.c delete box
				scrollButton .cscroll.c $current_id_sec
			}
			$canvas bind explore <Button-1> {
				if {$explore_type == "explore"} {
					ExploreDir $mounted_m($test_s,2) "no"
				} else {
					Explore $shares_m($zc_s,1)
				}
			}
			if {$test_s != "no"} {
				$canvas bind unmount <Button-1> {
					UnMount $mounted_m($test_s,2)
				}
				$canvas addtag second withtag unmount
			} else {
				$canvas itemconfigure unmount -fill grey60
			}
			$canvas bind mount <Button-1> {
				Mount $shares_m($zc_s,1)
			}
			$canvas addtag second withtag enter
			$canvas addtag second withtag explore
			$canvas addtag second withtag mount
		}
		$canvas create text [expr $x1+3] [expr $y1+82]\
		-fill black -text "Find Computer               " -anchor w -tags "box resolve second"
		$canvas bind resolve <Button-1> {
			.cscroll.c delete box
			FindComputer
		}
		$canvas create text [expr $x1+3] [expr $y1+100]\
		-fill black -text "Internet Link              " -anchor w -tags "box internet second"
		$canvas bind internet <Button-1> {
			.cscroll.c delete box
			InternetLink
		}
	}
	$canvas bind second <Any-Enter> {
		set current_id_highlight [.cscroll.c find withtag current]
		if {[lindex [.cscroll.c gettags $current_id_highlight] 2] == "second"} {
			.cscroll.c itemconfigure $current_id_highlight -fill white
		}
	}
	$canvas bind second <Any-Leave> {scrollLeave .cscroll.c }
}


proc SelectList {start finish} {
	############################
	if {$start == ""} {
		return $finish
	} elseif {$start == $finish} {
		return $finish
	} elseif {$start > $finish} {
		set addition "-1"
	} else {
		set addition "1"
	}
	set select_list $start
	set m [expr $start + $addition]
	while {$m != $finish} {
		lappend select_list $m
		set m [expr $m + $addition]
	}
	lappend select_list $finish
	return $select_list
}


proc DrawBox {canvas x2 y2 W} {
	#####################################################
	global box_x2
	global box_y2
	global box_x1
	global box_y1
	set box_x2 [expr [$canvas canvasx 0] + $x2]
	set box_y2 $y2
	$canvas delete drawbox
	$canvas create rectangle $box_x1 $box_y1 $box_x2 $box_y2 -outline black -tags drawbox
}

proc MarkBox {canvas x1 y1 W} {
	#####################################################
	global box_x1
	global box_y1
	set box_x1 [expr [$canvas canvasx 0] + $x1]
	set box_y1 $y1
}

proc SelectBox {canvas holding list_set} {
	#####################################################
	global box_x2
	global box_y2
	global box_x1
	global box_y1
	global files_m
	global folders_m
	global files_list
	global folders_list
	global selected_file_size
	global total_file_size
	global directory_a
	$canvas delete drawbox
	if {$list_set != "none"} {
		set id_list $list_set
	} else {
		set id_list [$canvas find overlapping $box_x1 $box_y1 $box_x2 $box_y2]
	}
	set y 1
	set current_id [lindex $id_list 0]
	while {$current_id != ""} {
		set m [lindex [$canvas gettags $current_id] 4]
		if {[lindex [$canvas gettags $current_id] 2] == "files"} {
			$canvas delete boxybox
			if {[lindex [$canvas gettags $current_id] 3] == "file"} {
				set letter "f"
			} else {
				set letter "d"
			}
			if {[lindex [$canvas gettags $current_id] 2] == "files" & [string range [lindex [$canvas gettags $current_id] 0] 0 0] != $letter} {
				if {[lindex [$canvas gettags $letter[lindex [$canvas gettags $current_id] 4]] 5] == "yes" & $holding == "ctrl"} {
					$canvas dtag $letter[lindex [$canvas gettags $current_id] 4] "yes"
					$canvas delete bb[lindex [$canvas gettags $current_id] 4]
					if {$letter == "f"} {
						set in_point [lsearch -exact $files_list $files_m($m,1)]
						set selected_file_size [expr $selected_file_size - $files_m($m,3)]
						if {$selected_file_size == 0} {
							.info.info1.stats config -text " Total: $total_file_size"
						} elseif {$selected_file_size < 1024} {
							set selec_file_size "$selected_file_size"
						} elseif {$selected_file_size < 1048576} {
							set selec_file_size "[expr $selected_file_size / 1024]KB"
						} elseif {$selected_file_size < 1073741824} {
							set selec_file_size [expr $selected_file_size / 1048576.0]
							set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]MB"
						} else {
							set selec_file_size [expr $selected_file_size / 1073741824.0]
							set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]GB"
						}
						if {$selected_file_size != 0} {.info.info1.stats config -text " Total: $total_file_size Selec: $selec_file_size"}
						if {$in_point == 0} {
							if {[llength $files_list] == 1} {
								unset files_list
							} else {
								set files_list [lrange $files_list 1 [expr [llength $files_list] - 1]]
							}
						} elseif {$in_point == [expr [llength $files_list] - 1]} {
							set files_list [lrange $files_list 0 [expr [llength $files_list] - 2]]
						} else {
							set first_half [lrange $files_list 0 [expr $in_point - 1]]
							set latter_half [lrange $files_list [expr $in_point + 1] [expr [llength $files_list] - 1]]
							set files_list "$first_half $latter_half"
						}
					} else {
						set in_point [lsearch -exact $folders_list $folders_m($m,1)]
						if {$in_point == 0} {
							if {[llength $folders_list] == 1} {
								unset folders_list
							} else {
								set folders_list [lrange $folders_list 1 [expr [llength $folders_list] - 1]]
							}
						} elseif {$in_point == [expr [llength $folders_list] - 1]} {
							set folders_list [lrange $folders_list 0 [expr [llength $folders_list] - 2]]
						} else {
							set first_half [lrange $folders_list 0 [expr $in_point - 1]]
							set latter_half [lrange $folders_list [expr $in_point + 1] [expr [llength $folders_list] - 1]]
							set folders_list "$first_half $latter_half"
						}
					}
				} elseif {[lindex [$canvas gettags $letter[lindex [$canvas gettags $current_id] 4]] 5] == ""} {
					$canvas addtag "yes" withtag $letter[lindex [$canvas gettags $current_id] 4]
					set mmm [lindex [$canvas gettags $current_id] 4]
					if {$letter == "f"} {
						set bb [$canvas bbox ttext$mmm]
					} else {
						set bb [$canvas bbox text$mmm]
					}
					$canvas create rectangle [lindex $bb 0] [lindex $bb 1] [lindex $bb 2] [lindex $bb 3] -width 4 -outline grey80 -fill grey80\
					-tags "$mmm bb bb$mmm $mmm $mmm"
					$canvas raise ttext$mmm bb$mmm
					$canvas raise text$mmm bb$mmm
					if {$letter == "f"} {
						lappend files_list $files_m($m,1)
						set selected_file_size [expr $selected_file_size + $files_m($m,3)]
						if {$selected_file_size < 1024} {
							set selec_file_size "$selected_file_size"
						} elseif {$selected_file_size < 1048576} {
							set selec_file_size "[expr $selected_file_size / 1024]KB"
						} elseif {$selected_file_size < 1073741824} {
							set selec_file_size [expr $selected_file_size / 1048576.0]
							set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]MB"
						} else {
							set selec_file_size [expr $selected_file_size / 1073741824.0]
							set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]GB"
						}
						.info.info1.stats config -text " Total: $total_file_size Selec: $selec_file_size"
					} else {
						lappend folders_list $folders_m($m,1)
					}
				}
			}
		}
		set current_id [lindex $id_list $y]
		incr y
	}
}


proc scrollButton {canvas id} {
	###############################################################
	global networks_m
	global favorites_m
	global networks_extra
	global favorites_extra
	global net_type
	global stop_now
	global wins_ip_num
	global mount_addon
	global position
	global broadcast_subnet
	global workgroup
	global user_name
	global user_name_default
	global wins_domain_master
	global wins_domain_master_ip
	global broadcast_master
	global env
	global broadcast_master_ip_num
	global computers_m
	global workgroups_m
	global shares_m
	global mstatus
	global computer_ip_num
	global share
	global computer
	global files_m
	global folders_m
	global files_list
	global folders_list
	global selected_file_size
	global total_file_size
	global directory_a
	global password
	global default_password
	global fav_m
	global net_m
	global default_samba_workgroup
	global default_samba_wins_server
	global default_user_name
	global checker
	global canvason
	global place
	global history_m
	global network_sec_wins
	global network_wg_static
	global network_master
	global network_master_ip
	focus .
	if {$canvason == "off"} {return}
	if {$id == "canvas"} {
		set current_id [$canvas find withtag current]
	} else {
		set current_id $id
	}
	if {$current_id == ""} {return}
	set data_type [lindex [$canvas gettags $current_id] 2]
	set data_type_t [lindex [$canvas gettags $current_id] 3]
	set data_type_m [lindex [$canvas gettags $current_id] 4]
	set text_type "text"
	if {$data_type == "files" & $data_type_t == "file"} {set text_type "ttext"}
	if {$data_type == "computers" | $data_type == "shares"} {set text_type "sec"}
	$canvas delete boxbox
	set bb [.cscroll.c bbox $text_type$data_type_m]
	if {$data_type == "files"} {
		$canvas create rectangle [expr [lindex $bb 0] - 3] [expr [lindex $bb 1] - 3] [expr [lindex $bb 2] + 2] [expr [lindex $bb 3] + 2] -width 1\
		-outline black -tags "boxbox"
	} else {
		$canvas create rectangle [lindex $bb 0] [lindex $bb 1] [lindex $bb 2] [lindex $bb 3] -width 6 -outline grey80 -fill grey80 -tags "boxbox"
		$canvas raise $text_type$data_type_m boxbox
		$canvas raise geo$data_type_m boxbox
		$canvas raise ggeo$data_type_m boxbox
	}
	if {[lindex [$canvas gettags $current_id] 2] != "files"} {
		.info.info2.stats config -text "Working ..."
		. config -cursor watch
	}
	if {[lindex [$canvas gettags $current_id] 2] == "favorites"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		if [info exists shares_m] {unset shares_m}
		if [info exists network_sec_wins] {unset network_sec_wins}
		if [info exists wins_domain_master] {unset wins_domain_master}
		if [info exists wins_domain_master_ip] {unset wins_domain_master_ip}
		if [info exists broadcast_master] {unset broadcast_master}
		if [info exists computers_m] {unset computers_m}
		set m [expr 1 + [lindex [$canvas gettags $current_id] 4]]
		set fav_m($favorites_m($m,name),clicked) "yes"
		.cscroll.c itemconfigure text[expr $m - 1] -fill blue1
		set net_type $favorites_m($m,net_type)
		if {$net_type == "wins"} {
			set wins_ip_num $favorites_m($m,ip_num)
			if [info exists favorites_extra($m,sec_wins)] {set network_sec_wins $favorites_extra($m,sec_wins)}
		} elseif {$net_type == "broadcast"} {
			set broadcast_subnet $favorites_m($m,ip_num)
		} else {
			set computer_ip_num $favorites_m($m,ip_num)
		}
		if {[.info.info0.statU get] == "" } {
			if {$favorites_m($m,user_name) == "defaults"} {
				set default_user_name ""
			} else {
				set default_user_name $favorites_m($m,user_name)
			}
		} else {
			set default_user_name [.info.info0.statU get]
		}
		set user_name $default_user_name
		if {[.info.info0.stats get] == "" } {
			if {$favorites_m($m,password) == "defaults"} {
				set default_password ""
			} else {
				set default_password $favorites_m($m,password)
			}
		} else {
			set default_password [.info.info0.stats get]
		}
		set password $default_password
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		set check $checker
		if {$net_type == "wins" | $net_type == "broadcast"} {
			set computer $favorites_m($m,netbios_des)
			set workgroup $favorites_m($m,workgroup)
		} else {
			NmbLookupName $computer_ip_num "computer"
			if {$check != $checker} {
				.info.info2.stats config -text "Cannot Find NetBios Name of Computer"
				. config -cursor left_ptr
				DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
				return
			}
			if ![info exists workgroup] {set workgroup ""}
		}
		set check $checker
		set stop_now "then"
		if {$net_type == "wins"} {
			NmbLookup $computer "wins" $wins_ip_num
			if {$check != $checker & $stop_now == "then" & [info exists network_sec_wins] == 1} {
				set check $checker
				set wins_ip_temp $wins_ip_num
				set wins_ip_num $network_sec_wins
				set network_sec_wins $wins_ip_temp
				puts "Trying Secondary Wins Server."
				NmbLookup $computer "wins" $wins_ip_num
			}
		} elseif {$net_type == "broadcast"} {
			NmbLookup $computer "broadcast" $broadcast_subnet
		}
		if {$check != $checker | $stop_now != "then"} {
			.info.info2.stats config -text "Cannot Find NetBios Name of Computer"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
			return
		}
		if {$workgroup == "defaults"} {set workgroup ""}
		if [info exists shares_m] {unset shares_m}
		SmbClientList $computer $computer_ip_num shares_only $workgroup
		DisplayOnCanvas "shares" [expr [array size shares_m] / 3] "" 0
		if {[expr [array size shares_m] / 3] != 0} {
			.status.stats config -text " Computer: $computer  IP: $computer_ip_num"
			if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
				.mstatus.buttons.unmount config -state disabled}
			if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
				.mstatus.info2.stats config -text ""}
			HistoryAdd "shares" [expr [array size shares_m] / 3] ""
		}
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	}
	if {[lindex [$canvas gettags $current_id] 2] == "networks"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set m [expr 1 + [lindex [$canvas gettags $current_id] 4]]
		set net_m($networks_m($m,name),clicked) "yes"
		.cscroll.c itemconfigure text[expr $m - 1] -fill blue1
		set net_type $networks_m($m,net_type)
		if [info exists network_wg_static] {unset network_wg_static}
		if [info exists network_sec_wins] {unset network_sec_wins}
		if [info exists network_master] {unset network_master}
		if [info exists network_master_ip] {unset network_master_ip}
		if [info exists networks_extra($m,wg_static)] {set network_wg_static "no"}
		if [info exists workgroups_m] {unset workgroups_m}
		if [info exists networks_extra($m,sec_wins)] {set network_sec_wins $networks_extra($m,sec_wins)}
		if [info exists networks_extra($m,master)] {set network_master $networks_extra($m,master)}
		if [info exists networks_extra($m,master_ip)] {set network_master_ip $networks_extra($m,master_ip)}
		if {$net_type == "wins"} {
			set wins_ip_num $networks_m($m,ip_num)
			if {$wins_ip_num == "default_samba"} {
				if {$default_samba_wins_server != "none"} {
					set wins_ip_num $default_samba_wins_server
				} else {
					set wins_ip_num "127.0.0.1"
				}
			}
		} else {
			set broadcast_subnet $networks_m($m,ip_num)
		}
		set workgroup $networks_m($m,workgroup)
		if {$workgroup == "default_samba"} {
			if {$default_samba_workgroup != "UNKNOWN"} {
				set workgroup $default_samba_workgroup
			} else {
				set workgroup ""
			}
		}
		if {$networks_m($m,user_name) == "defaults"} {
			set default_user_name ""
		} else {
			set default_user_name $networks_m($m,user_name)
		}
		if {[.info.info0.statU get] != "" } {
			set default_user_name [.info.info0.statU get]
		}
		set user_name $default_user_name
		if {$networks_m($m,password) == "defaults"} {
			set default_password ""
		} else {
			set default_password $networks_m($m,password)
		}
		if {[.info.info0.stats get] != "" } {
			set default_password [.info.info0.stats get]
		}
		set password $default_password
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		if ![info exists network_master] {
			set check $checker
			set stop_now "then"
			if {$net_type == "wins"} {
				NmbLookupMaster $workgroup $wins_ip_num wins
				if {$check != $checker & $stop_now == "then"} {
					if {[info exists network_sec_wins] == "1"} {
						set check $checker
						puts "Trying Secondary Wins Server."
						set wins_ip_temp $wins_ip_num
						set wins_ip_num $network_sec_wins
						set network_sec_wins $wins_ip_temp
						NmbLookupMaster $workgroup $wins_ip_num wins
						if {$check != $checker & $stop_now == "then"} {
							puts "Failed to find domain. Now using wins server as domain master."
							set wins_domain_master $workgroup
							set wins_domain_master_ip $wins_ip_num
							set check $checker
							NmbLookupName $wins_ip_num "wins"
							if {$check != $checker & $stop_now == "then"} {
								puts "Now trying secondary wins server as domain master."
								set wins_domain_master_ip $network_sec_wins
								set wins_ip_temp $wins_ip_num
								set wins_ip_num $network_sec_wins
								set network_sec_wins $wins_ip_temp
								set check $checker
								NmbLookupName $wins_ip_num "wins"
							}
						}
					} else {
						puts "Failed to find domain. Now using wins server as domain master."
						set wins_domain_master $workgroup
						set wins_domain_master_ip $wins_ip_num
						set check $checker
						NmbLookupName $wins_ip_num "wins"
					}
				}
			} elseif {$net_type == "broadcast"} {
				NmbLookupMaster $workgroup $broadcast_subnet broadcast
			}
			if {$check != $checker | $stop_now != "then"} {
				.info.info2.stats config -text "Unable To Find Domain Master"
				. config -cursor left_ptr
				DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
				return
			}
		} else {
			if {$net_type == "wins"} {
				set wins_domain_master $network_master
				set wins_domain_master_ip $network_master_ip
			} elseif {$net_type == "broadcast"} {
				set broadcast_master $network_master
				set broadcast_master_ip_num $network_master_ip
			}
		}
		if [info exists computers_m] {unset computers_m}
		if [info exists shares_m] {unset shares_m}
		if [info exists workgroups_m] {unset workgroups_m}
		if {$net_type == "wins"} {
			SmbClientList $wins_domain_master $wins_domain_master_ip computers_workgroups $workgroup
		} elseif {$net_type == "broadcast"} {
			SmbClientList $broadcast_master $broadcast_master_ip_num computers_workgroups $workgroup
		} else {
			if ![file exists $networks_m($m,ip_num)] {
				.info.info2.stats config -text "File \"$networks_m($m,ip_num)\" Does Not Exist"
				. config -cursor left_ptr
				DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
				return
			}
			set ipfile [open $networks_m($m,ip_num) r]
			gets $ipfile line
			set r 0
			set eof_check 0
			while {$line != "-1" & $eof_check != 5 & [eof $ipfile] == "0"} {
				if [string match *\ * $line] {
					set computers_m($r,1) [string range $line 0 [expr [string first " " $line] - 1]]
					set computers_m($r,2) [string range $line [string first " " $line] [expr [string length $line] - 1]]
				} else {
					set computers_m($r,1) $line
					set computers_m($r,2) " "
					if { $line == "" } { incr eof_check }
				}
				gets $ipfile line
				incr r
			}
			close $ipfile
		}
		DisplayOnCanvas "computers" [expr [array size computers_m] / 2] "" 0
		if {[expr [array size computers_m] / 2] != 0} {
			.status.stats config -text " Workgroup: $workgroup"
			if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
				.mstatus.buttons.unmount config -state disabled}
			if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
				.mstatus.info2.stats config -text ""}
			HistoryAdd "computers" [expr [array size computers_m] / 2] ""
		} else {
			. config -cursor left_ptr
		}
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	}
	if {[lindex [$canvas gettags $current_id] 2] == "workgroups"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set m [expr [lindex [$canvas gettags $current_id] 4]]
		set history_m($place,$m,clicked) "yes"
		.cscroll.c itemconfigure text$m -fill blue1
		if [info exists network_wg_static] {
			set workgroup $workgroups_m($m,1)
		}
		set stop_now "then"
		set check $checker
		if {$net_type == "wins"} {
			NmbLookupMaster $workgroups_m($m,1) $wins_ip_num wins
			if {$check != $checker & $stop_now == "then"} {
				if [info exists network_sec_wins] {
					set check $checker
					puts "Trying Secondary Wins Server."
					set wins_ip_temp $wins_ip_num
					set wins_ip_num $network_sec_wins
					set network_sec_wins $wins_ip_temp
					NmbLookupMaster $workgroups_m($m,1) $wins_ip_num wins
					if {$check != $checker & $stop_now == "then" & $workgroups_m($m,2) != ""} {
						puts "Trying listed domain master instead."
						set wins_domain_master $workgroups_m($m,2)
						set checker [expr $checker - 1]
						NmbLookup $workgroups_m($m,2) "wins" $wins_ip_num
						if {$check != $checker & $stop_now == "then"} {
							set checker [expr $checker - 1]
							puts "Trying Secondary Wins Server."
							set wins_ip_temp $wins_ip_num
							set wins_ip_num $network_sec_wins
							set network_sec_wins $wins_ip_temp
							NmbLookup $workgroups_m($m,2) "wins" $wins_ip_num
						}
						if {$check == $checker} {set wins_domain_master_ip $computer_ip_num}
					}
				} elseif {$workgroups_m($m,2) != ""} {
					puts "Trying listed domain master instead."
					set wins_domain_master $workgroups_m($m,2)
					set checker [expr $checker - 1]
					NmbLookup $workgroups_m($m,2) "wins" $wins_ip_num
					if {$check == $checker} {set wins_domain_master_ip $computer_ip_num}
				}
			}
		} elseif {$net_type == "broadcast"} {
			NmbLookupMaster $workgroups_m($m,1) $broadcast_subnet broadcast
			if {$check != $checker & $stop_now == "then" & $workgroups_m($m,2) != ""} {
				puts "Using listed master instead."
				set broadcast_master $workgroups_m($m,2)
				set checker [expr $checker - 1]
				NmbLookup $broadcast_master "broadcast" $broadcast_subnet
				if {$check == $checker} {set broadcast_master_ip_num $computer_ip_num}
			}
		} else {
			.info.info2.stats config -text "Not Applicable In File Mode"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
			return
		}
		if {$check != $checker} {
			.info.info2.stats config -text "Unable To Find Workgroup"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
			return
		}
		set password [.info.info0.stats get]
		set user_name [.info.info0.statU get]
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		if [info exists computers_m] {unset computers_m}
		if {$net_type == "wins"} {
			SmbClientList $wins_domain_master $wins_domain_master_ip computers_only $workgroup
		} else {
			SmbClientList $broadcast_master $broadcast_master_ip_num computers_only $workgroup
		}
		DisplayOnCanvas "computers" [expr [array size computers_m] / 2] "" 0
		if {[expr [array size computers_m] / 2] != 0} {
			.status.stats config -text " Workgroup: $workgroup"
			if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
				.mstatus.buttons.unmount config -state disabled}
			if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
				.mstatus.info2.stats config -text ""}
			HistoryAdd "computers" [expr [array size computers_m] / 2] ""
		} else {
			. config -cursor left_ptr
		}
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	}
	if {[lindex [$canvas gettags $current_id] 2] == "computers"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set m [expr [lindex [$canvas gettags $current_id] 4]]
		set history_m($place,$m,clicked) "yes"
		.cscroll.c itemconfigure text$m -fill blue1
		set computer $computers_m($m,1)
		if [info exists shares_m] {unset shares_m}
		set check $checker
		set stop_now "then"
		if {$net_type == "wins"} {
			NmbLookup $computer "wins" $wins_ip_num
			if {$check != $checker & [info exists network_sec_wins] == "1" & $stop_now == "then"} {
				set checker [expr $checker - 1]
				puts "Trying Secondary Wins Server."
				set wins_ip_temp $wins_ip_num
				set wins_ip_num $network_sec_wins
				set network_sec_wins $wins_ip_temp
				NmbLookup $computer "wins" $wins_ip_num
			}
		} elseif {$net_type == "broadcast"} {
			NmbLookup $computer "broadcast" $broadcast_subnet
		} else {
			set workgroup ""
			set computer_ip_num $computer
			NmbLookupName $computer "computer"
		}
		if {$check != $checker} {
			.info.info2.stats config -text "Unable To Find Computer"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
			return
		}
		set password [.info.info0.stats get]
		set user_name [.info.info0.statU get]
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		if {$net_type == "wins" | $net_type == "ip_only"} {
			SmbClientList $computer $computer_ip_num shares_only $workgroup
		} else {
			SmbClientList $computer $computer_ip_num shares_checkgroups $workgroup
		}
		DisplayOnCanvas "shares" [expr [array size shares_m] / 3] "" 0
		if {[expr [array size shares_m] / 3] != 0} {
			set directory_a(1) "shares"
			.status.stats config -text " Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
			if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
				.mstatus.buttons.unmount config -state disabled}
			if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
				.mstatus.info2.stats config -text ""}
			HistoryAdd "shares" [expr [array size shares_m] / 3] ""
			DisableEnable 0 0 0 0 0 0 1 0 1 1 0 0
		} else {
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		}
	}
	if {[lindex [$canvas gettags $current_id] 2] == "shares"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set m [expr [lindex [$canvas gettags $current_id] 4]]
		set history_m($place,$m,clicked) "yes"
		.cscroll.c itemconfigure text$m -fill blue1
		set share $shares_m($m,1)
		if [info exists directory_a] {unset directory_a}
		set check $checker
		SmbClientFiles $computer $computer_ip_num $share "" $workgroup
		if {$check != $checker} {
			set directory_a(1) "shares"
			if { [expr $checker - $check] == 2 } {
				DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
			} else {
				DisableEnable 0 0 0 0 0 0 1 0 1 1 1 0
			}
			return
		}
		if [info exists files_list] {unset files_list}
		if [info exists folders_list] {unset folder_list}
		DisplayOnCanvas "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3] 0
		HistoryAdd "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3]
		.status.stats config -text " Dir: \\  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
		if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
		if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
		DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
	}
	if {[lindex [$canvas gettags $current_id] 2] == "files"} {
		set m [expr [lindex [$canvas gettags $current_id] 4]]
		$canvas delete boxybox
		if {[lindex [$canvas gettags $current_id] 3] == "file"} {
			set letter "f"
		} else {
			set letter "d"
		}
		if {[lindex [$canvas gettags $letter[lindex [$canvas gettags $current_id] 4]] 5] == "yes"} {
			$canvas dtag $letter[lindex [$canvas gettags $current_id] 4] "yes"
			$canvas delete bb[lindex [$canvas gettags $current_id] 4]
			if {$letter == "f"} {
				set in_point [lsearch -exact $files_list $files_m($m,1)]
				set selected_file_size [expr $selected_file_size - $files_m($m,3)]
				if {$selected_file_size == 0} {
					.info.info1.stats config -text " Total: $total_file_size"
				} elseif {$selected_file_size < 1024} {
					set selec_file_size "$selected_file_size"
				} elseif {$selected_file_size < 1048576} {
					set selec_file_size "[expr $selected_file_size / 1024]KB"
				} elseif {$selected_file_size < 1073741824} {
					set selec_file_size [expr $selected_file_size / 1048576.0]
					set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]MB"
				} else {
					set selec_file_size [expr $selected_file_size / 1073741824.0]
					set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]GB"
				}
				if {$selected_file_size != 0} {.info.info1.stats config -text " Total: $total_file_size Selec: $selec_file_size"}
				if {$in_point == 0} {
					if {[llength $files_list] == 1} {
						unset files_list
					} else {
						set files_list [lrange $files_list 1 [expr [llength $files_list] - 1]]
					}
				} elseif {$in_point == [expr [llength $files_list] - 1]} {
					set files_list [lrange $files_list 0 [expr [llength $files_list] - 2]]
				} else {
					set first_half [lrange $files_list 0 [expr $in_point - 1]]
					set latter_half [lrange $files_list [expr $in_point + 1] [expr [llength $files_list] - 1]]
					set files_list "$first_half $latter_half"
				}
			} else {
				set in_point [lsearch -exact $folders_list $folders_m($m,1)]
				if {$in_point == 0} {
					if {[llength $folders_list] == 1} {
						unset folders_list
					} else {
						set folders_list [lrange $folders_list 1 [expr [llength $folders_list] - 1]]
					}
				} elseif {$in_point == [expr [llength $folders_list] - 1]} {
					set folders_list [lrange $folders_list 0 [expr [llength $folders_list] - 2]]
				} else {
					set first_half [lrange $folders_list 0 [expr $in_point - 1]]
					set latter_half [lrange $folders_list [expr $in_point + 1] [expr [llength $folders_list] - 1]]
					set folders_list "$first_half $latter_half"
				}
			}
		} else {
			$canvas addtag "yes" withtag $letter[lindex [$canvas gettags $current_id] 4]
			set mmm [lindex [$canvas gettags $current_id] 4]
			if {$letter == "f"} {
				set bb [$canvas bbox ttext$mmm]
			} else {
				set bb [$canvas bbox text$mmm]
			}
			$canvas create rectangle [lindex $bb 0] [lindex $bb 1] [lindex $bb 2] [lindex $bb 3] -width 4 -outline grey80 -fill grey80\
			-tags "$mmm bb bb$mmm $mmm $mmm"
			$canvas raise ttext$mmm bb$mmm
			$canvas raise text$mmm bb$mmm
			if {[lindex [$canvas gettags $current_id] 3] == "file"} {
				lappend files_list $files_m($m,1)
				set selected_file_size [expr $selected_file_size + $files_m($m,3)]
				if {$selected_file_size < 1024} {
					set selec_file_size "$selected_file_size"
				} elseif {$selected_file_size < 1048576} {
					set selec_file_size "[expr $selected_file_size / 1024]KB"
				} elseif {$selected_file_size < 1073741824} {
					set selec_file_size [expr $selected_file_size / 1048576.0]
					set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]MB"
				} else {
					set selec_file_size [expr $selected_file_size / 1073741824.0]
					set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]GB"
				}
				.info.info1.stats config -text " Total: $total_file_size Selec: $selec_file_size"
			} else {
				lappend folders_list $folders_m($m,1)
			}
		}
	}
}

proc scrollButtonFolder {canvas id} {
	###############################################################
	global directory_a
	global canvason
	global folders_m
	global history_m
	global place
	global checker
	global computer
	global computer_ip_num
	global share
	global workgroup
	global files_m
	global mount_addon
	focus .
	if {$canvason == "off"} {return}
	if {$id == "canvas"} {
		set current_id [$canvas find withtag current]
	} else {
		set current_id $id
	}
	if {$current_id == ""} {return}
	$canvas delete boxbox
	set m [lindex [$canvas gettags $current_id] 4]
	set bb [.cscroll.c bbox text$m]
	$canvas create rectangle [expr [lindex $bb 0] - 3] [expr [lindex $bb 1] - 3] [expr [lindex $bb 2] + 2] [expr [lindex $bb 3] + 2] -width 1\
	-outline black -tags "boxbox"
	.info.info2.stats config -text "Working ..."
	. config -cursor watch
	if [info exists directory_a] {
		set directory_a([expr 1 + [array size directory_a]]) $folders_m($m,1)
		set directory $directory_a(1)
		set p 2
		while {$p <= [array size directory_a]} {
			set directory "$directory\\$directory_a($p)"
			incr p
		}
	} else {
		set directory_a(1) $folders_m($m,1)
		set directory $folders_m($m,1)
	}
	DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
	set history_m($place,folders,$m,clicked) "yes"
	.cscroll.c itemconfigure text$m -fill blue1
	set check $checker
	SmbClientFiles $computer $computer_ip_num $share $directory $workgroup
	if {$check != $checker} {
		DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
		return
	}
	DisplayOnCanvas "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3] 0
	.status.stats config -text " Dir: \\$directory  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
	if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
	HistoryAdd "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3]
	if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
	DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
}


proc PasswordPrompt {} {
	#############################################
	global user_name
	global password
	global cancel_password
	global env_name
	set cancel_password "no"
	toplevel .password
	wm title .password "Password"
	frame .password.prompt1 -borderwidth 6
	frame .password.prompt2 -borderwidth 6
	frame .password.prompt1.msg1 -borderwidth 0
	label .password.prompt1.msg1.t -text "Username:"
	pack .password.prompt1.msg1.t -side right
	entry .password.prompt2.entry1 -width 15 -foreground black -background white
	frame .password.prompt1.msg2 -borderwidth 0
	label .password.prompt1.msg2.t -text "Password:"
	pack .password.prompt1.msg2.t -side right
	entry .password.prompt2.entry2 -width 15 -show "*" -foreground black -background white
	frame .password.okay -borderwidth 8
	button .password.okay.okayb -highlightthickness 0 -width 6\
	-text "Okay" -command {
		set user_name [.password.prompt2.entry1 get]
		set password [.password.prompt2.entry2 get]
		set cancel_password "no"
		destroy .password
	}
	button .password.okay.cancelb -highlightthickness 0 -width 6\
	-text "Cancel" -command {
		set cancel_password "yes"
		destroy .password
	}
	pack .password.okay -side bottom -expand yes
	pack .password.prompt1 -side left -fill x
	pack .password.prompt2 -side left -fill x
	pack .password.prompt1.msg1 .password.prompt1.msg2 -side top
	pack .password.prompt2.entry1 .password.prompt2.entry2 -side top
	pack .password.okay.okayb .password.okay.cancelb -side left
	bind .password <KeyPress-Return> {.password.okay.okayb invoke}
	bind .password <KeyPress-Escape> {.password.okay.cancelb invoke}
	.password.prompt2.entry1 insert 0 $user_name
	.password.prompt2.entry2 insert 0 $password
	tkwait visibility .password.prompt2.entry2
	grab .password
	focus .password.prompt2.entry2
	raise .password .
	tkwait window .password
}


proc DirMaker {seperator} {
	###################################
	global directory_a
	if [info exists directory_a(1)] {
		set directory $directory_a(1)
		set m 2
		while {$m <= [array size directory_a]} {
			set directory "$directory$seperator$directory_a($m)"
			incr m
		}
	} else {
		set directory ""
	}
	return $directory
}


proc FindComputer {} {
	###########################################
	global net_type
	toplevel .findcomp
	wm title .findcomp "Find Computer"
	frame .findcomp.f -borderwidth 6
	pack .findcomp.f -side top -fill x
	if {$net_type == "ip_only"} {
		label .findcomp.f.l -text "IP Address:"
	} else {
		label .findcomp.f.l -text "NetBios Name:"
	}
	entry .findcomp.f.e -width 15 -foreground black -background white
	pack .findcomp.f.l -side left
	pack .findcomp.f.e -expand yes -fill x -side left
	frame .findcomp.f2
	pack .findcomp.f2 -side top -fill x
	button .findcomp.f2.b -highlightthickness 0 -width 6 -text "Find"\
	-command {
		set comp [.findcomp.f.e get]
		destroy .findcomp
		FindComputerExecute $comp
	}
	button .findcomp.f2.c -highlightthickness 0 -width 6\
	-text "Cancel" -command {
		destroy .findcomp
	}
	pack .findcomp.f2.c .findcomp.f2.b -side right
	bind .findcomp <KeyPress-Return> {.findcomp.f2.b invoke}
	bind .findcomp <KeyPress-Escape> {.findcomp.f2.c invoke}
	focus .findcomp.f.e
	tkwait visibility .findcomp.f2.b
	grab .findcomp
	raise .findcomp .
	tkwait window .findcomp
}


proc FindComputerExecute {comp} {
	global computer workgroup shares_m
	global checker stop_now net_type mount_addon
	global wins_ip_num network_sec_wins
	global broadcast_subnet computer_ip_num
	global history_m place password user_name
	global default_samba_workgroup
	set computer $comp
	.info.info2.stats config -text "Working ..."
	if ![info exists net_type] {
		set net_type "broadcast"
		if ![info exists workgroup] {
			set workgroup $default_samba_workgroup
		} 
		if ![info exists broadcast_subnet] {
			set broadcast_subnet "default_samba"
		}
	}
	. config -cursor watch
	DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
	if [info exists shares_m] {unset shares_m}
	set check $checker
	set stop_now "then"
	if {$net_type == "wins"} {
		NmbLookup $computer "wins" $wins_ip_num
		if {$check != $checker & [info exists network_sec_wins] == "1" & $stop_now == "then"} {
			set checker [expr $checker - 1]
			puts "Trying Secondary Wins Server."
			set wins_ip_temp $wins_ip_num
			set wins_ip_num $network_sec_wins
			set network_sec_wins $wins_ip_temp
			NmbLookup $computer "wins" $wins_ip_num
		}
	} elseif {$net_type == "broadcast"} {
		NmbLookup $computer "broadcast" $broadcast_subnet
	} else {
		set workgroup ""
		set computer_ip_num $computer
		NmbLookupName $computer "computer"
	}
	if {$check != $checker} {
		.info.info2.stats config -text "Unable To Find Computer"
		. config -cursor left_ptr
		if {$history_m($place,type) == "shares"} {
			set l 0
			while {$l < $history_m($place,length)} {
				set shares_m($l,1) $history_m($place,$l,1)
				set shares_m($l,2) $history_m($place,$l,2)
				set shares_m($l,3) $history_m($place,$l,3)
				incr l
			}
		}
		if [info exists history_m($place,computer)] {
			set computer $history_m($place,computer)
		}
		if [info exists history_m($place,workgroup)] {
			set workgroup $history_m($place,workgroup)
		}
		if [info exists history_m($place,computer_ip_num)] {
			set computer_ip_num $history_m($place,computer_ip_num)
		}
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	} else {
		set password ""
		set user_name [.info.info0.statU get]
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		SmbClientList $computer $computer_ip_num shares_only $workgroup
		if {[expr [array size shares_m] / 3] != 0} {
			DisplayOnCanvas "shares" [expr [array size shares_m] / 3] "" 0
			set directory_a(1) "shares"
			.status.stats config -text " Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
			if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
				.mstatus.buttons.unmount config -state disabled}
			if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
				.mstatus.info2.stats config -text ""}
			HistoryAdd "shares" [expr [array size shares_m] / 3] ""
			DisableEnable 0 0 0 0 0 0 1 0 1 1 0 0
		} else {
			if {$history_m($place,type) == "shares"} {
				set l 0
				while {$l < $history_m($place,length)} {
					set shares_m($l,1) $history_m($place,$l,1)
					set shares_m($l,2) $history_m($place,$l,2)
					set shares_m($l,3) $history_m($place,$l,3)
					incr l
				}
			}
			if [info exists history_m($place,computer)] {
				set computer $history_m($place,computer)
			}
			if [info exists history_m($place,workgroup)] {
				set workgroup $history_m($place,workgroup)
			}
			if [info exists history_m($place,computer_ip_num)] {
				set computer_ip_num $history_m($place,computer_ip_num)
			}
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		}
	}
}


proc InternetLink {} {
	###########################################
	global link_history
	global link_rb_history
	toplevel .link
	wm title .link "Internet Link"
	frame .link.f0 -borderwidth 6
	pack .link.f0 -side top -fill x
	label .link.f0.l1 -text "Link Type:  "
	radiobutton .link.f0.rb1 -text "File" -variable link_rb -relief flat -value "file"
	radiobutton .link.f0.rb2 -text "Folder" -variable link_rb -relief flat -value "folder"
	pack .link.f0.l1 .link.f0.rb1 .link.f0.rb2 -side left
	frame .link.f -borderwidth 1
	pack .link.f -side top -fill x
	label .link.f.l -text "Link:"
	entry .link.f.e -width 30 -foreground black -background white
	pack .link.f.l -side left
	pack .link.f.e -expand yes -fill x -side left
	frame .link.f3 -borderwidth 1
	pack .link.f3 -side top -fill x
	label .link.f3.l1 -text "e.g. file://Computer/Share/Directory/File"
	pack .link.f3.l1 -side top
	frame .link.f2
	pack .link.f2 -side top -fill x
	button .link.f2.b -highlightthickness 0 -width 8 -text "Lookup"\
	-command {
		set link_g [.link.f.e get]
		set link_rb2 $link_rb
		set link_history $link_g
		set link_rb_history $link_rb2
		destroy .link
		InternetLinkExecute $link_g $link_rb2
	}
	button .link.f2.c -highlightthickness 0 -width 8\
	-text "Cancel" -command {
		destroy .link
	}
	pack .link.f2.c .link.f2.b -side right
	bind .link <KeyPress-Return> {.link.f2.b invoke}
	bind .link <KeyPress-Escape> {.link.f2.c invoke}
	focus .link.f.e
	tkwait visibility .link.f2.b
	if [info exists link_history] {
		.link.f.e insert 0 $link_history
		.link.f.e icursor [string length $link_history]
		.link.f.e selection range 0 [string length $link_history]
		if {$link_rb_history == "file"} {
			.link.f0.rb1 select
		} else {
			.link.f0.rb2 select
		}
	} else {
		.link.f0.rb2 select
	}
	grab .link
	raise .link .
	tkwait window .link
}


proc InternetLinkExecute {line preference} {
	###########################################
	global net_type
	global stop_now
	global wins_ip_num
	global mount_addon
	global broadcast_subnet
	global workgroup
	global user_name
	global computer_ip_num
	global share
	global computer
	global directory_a
	global password
	global default_samba_workgroup
	global checker
	global place
	global history_m
	global files_m
	global folders_m
	set m 0
	while {$m < [string length $line]} {
		if {[string index $line $m] == "\\"} {
			set line "[string range $line 0 [expr $m - 1]]/[string range $line [expr $m + 1] [expr [string length $line] - 1]]"
		}
		if {[string index $line $m] == "%"} {
			if {[string range $line $m [expr $m + 2]] == "%20"} {
				set line "[string range $line 0 [expr $m - 1]] [string range $line [expr $m + 3] [expr [string length $line] - 1]]"
			}
		}
		incr m
	}
	set pattern  "file://(\[^/]+)+/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*/*(\[^/]+)*"
	if [regexp -indices $pattern [string tolower $line] m_line m_computer m_share dir(1) dir(2) dir(3) dir(4) dir(5) dir(6) dir(7) dir(8) dir(9) dir(10)] {
		set computer_match [string range $line [lindex $m_computer 0] [lindex $m_computer 1]]
		set share_match [string range $line [lindex $m_share 0] [lindex $m_share 1]]
		if {$computer_match != "" & $share_match == ""} {
			FindComputerExecute $computer_match
		} elseif {$computer_match != "" & $share_match != ""} {
			set m 1
			if {$preference == "folder"} {
				while {[lindex $dir($m) 0] != "-1"} {
					set directory_a($m) [string range $line [lindex $dir($m) 0] [lindex $dir($m) 1]]
					incr m
				}
				set directory [DirMaker \\]
				set computer $computer_match
				set share $share_match
				. config -cursor watch
				.info.info2.stats config -text "Working ..."
			} else {
				set file_name ""
				set directory ""
				while {[lindex $dir($m) 0] != "-1"} {
					set file_name [string range $line [lindex $dir($m) 0] [lindex $dir($m) 1]]
					if {[lindex $dir([expr $m + 1]) 0] != "-1"} {
						set directory "$directory\\[string range $line [lindex $dir($m) 0] [lindex $dir($m) 1]]"
					}
					incr m
				}
				set directory [string range $directory 1 [expr [string length $directory]]]
			}
			if ![info exists net_type] {
				set net_type "broadcast"
				if ![info exists workgroup] {
					set workgroup $default_samba_workgroup
				} 
				if ![info exists broadcast_subnet] {
					set broadcast_subnet "default_samba"
				}
			}
			DisableEnable 1 1 1 1 1 1 0 1 1 1 1 0
			set check $checker
			set stop_now "then"
		if {$net_type == "wins"} {
			NmbLookup $computer_match "wins" $wins_ip_num
			if {$check != $checker & [info exists network_sec_wins] == "1" & $stop_now == "then"} {
				set checker [expr $checker - 1]
				puts "Trying Secondary Wins Server."
				set wins_ip_temp $wins_ip_num
				set wins_ip_num $network_sec_wins
				set network_sec_wins $wins_ip_temp
				NmbLookup $computer_match "wins" $wins_ip_num
			}
			} else {
				NmbLookup $computer_match "broadcast" $broadcast_subnet
			}
			if {$check != $checker} {
				.info.info2.stats config -text "Unable To Find Computer"
				. config -cursor left_ptr
				if [info exists history_m($place,directory)] {
					if {$preference == "folder"} {
						if [info exists directory_a] {unset directory_a}
						set m 1
						while {$m <= $history_m($place,directory_a,length)} {
							set directory_a($m) $history_m($place,directory_a,$m)
							incr m
						}
						if [info exists history_m($place,computer)] {
							set computer $history_m($place,computer)
						}
					}
					set directory $history_m($place,directory)
				} else {
					set directory ""
				}
				if [info exists history_m($place,computer_ip_num)] {
					set computer_ip_num $history_m($place,computer_ip_num)
				}
				if {$history_m($place,type) == "shares"} {
					DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
				} else {
					DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
				}
			} else {
				if {$preference == "folder"} {
					.info.info0.stats delete 0 1024
					set check $checker
					if {$directory == "shares"} {set directory ""; unset directory_a }
					SmbClientFiles $computer $computer_ip_num $share $directory $workgroup
					if {$check != $checker} {
						. config -cursor left_ptr
						.info.info0.stats insert 0 $password
						if [info exists directory_a] {unset directory_a}
						if [info exists history_m($place,directory)] {
							set m 1
							while {$m <= $history_m($place,directory_a,length)} {
								set directory_a($m) $history_m($place,directory_a,$m)
								incr m
							}
							set directory $history_m($place,directory)
						} else {
							set directory ""
						}
						if [info exists history_m($place,computer)] {
							set computer $history_m($place,computer)
						}
						if [info exists history_m($place,computer_ip_num)] {
							set computer_ip_num $history_m($place,computer_ip_num)
						}
						if {$history_m($place,type) == "shares"} {
							DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
						} else {
							DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
						}
					} else {
						DisplayOnCanvas "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3] 0
						.status.stats config -text " Dir: \\$directory  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
						if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
						HistoryAdd "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3]
						if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
						DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
					}
				} else {
					set local_path [FolderDialog ""]
					set password ""
					. config -cursor left_ptr
					if {$history_m($place,type) == "shares"} {
						DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
					} else {
						DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
					}
					if [info exists history_m($place,directory)] {
						set directory $history_m($place,directory)
					}
					if [info exists history_m($place,computer_ip_num)] {
						set computer_ip_num $history_m($place,computer_ip_num)
					}
					set password [.info.info0.stats get]
					if {$local_path != ""} {
						set fq_type "1"
						set command_line "cd \"$directory\";lcd \"$local_path\"; prompt; get \"$file_name\""
						FileQueue "\{\{File $file_name from //$computer_match/$share_match\} \{//$computer_match/$share_match/[DirMaker /]\}\
							\{$local_path\} \{(Unknown)\} $fq_type \{$computer_match\} \{$share_match\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
					}
				}
			}
		} else {
			.info.info2.stats config -text "Link Pattern Mismatch"
		}
	} else {
		.info.info2.stats config -text "Link Pattern Mismatch"
	}
}


proc FindWorkgroup {} {
	###########################################
	global net_type
	toplevel .findwork
	wm title .findwork "Find Workgroup"
	frame .findwork.f -borderwidth 6
	pack .findwork.f -fill x -side top
	label .findwork.f.l -text "Workgroup:"
	pack .findwork.f.l -side left
	entry .findwork.f.e -width 15 -foreground black -background white
	pack .findwork.f.e -expand yes -fill x -side left
	frame .findwork.f2
	pack .findwork.f2 -side top -fill x
	button .findwork.f2.b -highlightthickness 0 -width 6 -text "Find"\
	-command {
		set  workgroup_entry [.findwork.f.e get]
		destroy .findwork
		.info.info2.stats config -text "Working ..."
		. config -cursor watch
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set stop_now "then"
		set check $checker
		if {$net_type == "wins"} {
			NmbLookupMaster $workgroup_entry $wins_ip_num wins
			if {$check != $checker & $stop_now == "then"} {
				if [info exists network_sec_wins] {
					set check $checker
					puts "Trying Secondary Wins Server."
					set wins_ip_temp $wins_ip_num
					set wins_ip_num $network_sec_wins
					set network_sec_wins $wins_ip_temp
					NmbLookupMaster $workgroup_entry $wins_ip_num wins
				}
			}
		} elseif {$net_type == "broadcast"} {
			NmbLookupMaster $workgroup_entry $broadcast_subnet broadcast
		} else {
			.info.info2.stats config -text "Not Applicable In File Mode"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
			incr checker
		}
		if {$check != $checker} {
			.info.info2.stats config -text "Unable To Find Workgroup"
			. config -cursor left_ptr
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		} else {
			if [info exists network_wg_static] {
				set workgroup_use $workgroup_entry
			} else {
				set workgroup_use $workgroup
			}
			set password ""
			set user_name [.info.info0.statU get]
			if [info exists env(USER)] {
				set env(USER) "$user_name%$password"
			} elseif [info exists env(LOGNAME)] {
				set env(LOGNAME) "$user_name%$password"
			} else {
				set env(USER) "$user_name%$password"
			}
			if {$net_type == "wins"} {
				SmbClientList $wins_domain_master $wins_domain_master_ip computers_only $workgroup_use
			} else {
				SmbClientList $broadcast_master $broadcast_master_ip_num computers_only $workgroup_use
			}
			DisplayOnCanvas "computers" [expr [array size computers_m] / 2] "" 0
			if {[expr [array size computers_m] / 2] != 0} {
				if [info exists network_wg_static] {
					set workgroup $workgroup_entry
				}
				.status.stats config -text " Workgroup: $workgroup"
				if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
					.mstatus.buttons.unmount config -state disabled}
				if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
					.mstatus.info2.stats config -text ""}
				HistoryAdd "computers" [expr [array size computers_m] / 2] ""
			} else {
				. config -cursor left_ptr
			}
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		}
	}
	button .findwork.f2.c -highlightthickness 0 -width 6 -text "Cancel"\
	-command {
		destroy .findwork
	}
	pack .findwork.f2.c .findwork.f2.b -side right
	bind .findwork <KeyPress-Return> {.findwork.f2.b invoke}
	bind .findwork <KeyPress-Escape> {.findwork.f2.c invoke}
	focus .findwork.f.e
	tkwait visibility .findwork.f2.b
	grab .findwork
	raise .findwork .
	tkwait window .findwork
}


proc FindName {} {
	###########################################
	global net_type
	global name_index
	global name_index_type
	global f_pattern
	toplevel .namesearch
	wm title .namesearch "Find File"
	frame .namesearch.f -borderwidth 6
	pack .namesearch.f -fill x -side top
	label .namesearch.f.l -text "File *pattern* :"
	pack .namesearch.f.l -side left
	entry .namesearch.f.e -width 20 -foreground black -background white
	pack .namesearch.f.e -expand yes -fill x -side left
	frame .namesearch.f1 -borderwidth 4
	pack .namesearch.f1 -side top -fill x
	label .namesearch.f1.l -text "Case Insensitive  e.g. \"abc*mp3\""
	pack .namesearch.f1.l
	frame .namesearch.f2
	pack .namesearch.f2 -side top -fill x
	button .namesearch.f2.b -highlightthickness 0 -width 10 -text "Find Next"\
	-command {
		FindNameButton
	}
	button .namesearch.f2.c -highlightthickness 0 -width 10 -text "Cancel"\
	-command {
		destroy .namesearch
	}
	pack .namesearch.f2.c .namesearch.f2.b -side right
	bind .namesearch <KeyPress-Return> {.namesearch.f2.b invoke}
	bind .namesearch <KeyPress-Escape> {.namesearch.f2.c invoke}
	bind .namesearch <Destroy> {
		set name_index 0
		set name_index_type "folders"
	}
	focus .namesearch.f.e
	tkwait visibility .namesearch.f2.b
	if [info exists f_pattern] {
		.namesearch.f.e insert 0 $f_pattern
		.namesearch.f.e icursor [string length $f_pattern]
		.namesearch.f.e selection range 0 [string length $f_pattern]
		set f_pattern ""
	}
	grab .namesearch
	raise .namesearch .
	tkwait window .namesearch
}


proc FindNameButton {} {
	global net_type
	global name_index
	global name_index_type
	global f_pattern
	global files_m
	global folders_m
	global files_list
	global folders_list
	global selected_file_size
	if [info exists f_pattern] {
		if {$f_pattern != [.namesearch.f.e get]} {
			set name_index 0
			set name_index_type "folders"
		}
	}
	set f_pattern [.namesearch.f.e get]
	if {$f_pattern == ""} {return }
	if ![info exists name_index] {
		set name_index 0
		set name_index_type "folders"
	}
	if {[info exists folders_m] == "1" && [array size folders_m] > 3 & $name_index_type == "folders"} {
		while {$name_index < [expr [array size folders_m] / 3]} {
			if [string match "*[string tolower $f_pattern]*" [string tolower $folders_m($name_index,1)]] {
				.cscroll.c delete bb
				.cscroll.c dtag yes yes
				set selected_file_size 0
				if [info exists files_list] {unset files_list}
				if [info exists folders_list] {unset folders_list}
				scrollButton .cscroll.c [.cscroll.c find withtag text$name_index]
				.cscroll.c xview moveto [expr [expr [lindex [.cscroll.c coords text$name_index] 0] - [winfo width .cscroll.c] / 2] / [lindex [.cscroll.c bbox all] 2]]
				incr name_index
				return
			}
			incr name_index
		}
	}
	if {$name_index_type != "files"} {
		set name_index 0
		set name_index_type "files"
	}
	if {[info exists files_m] == "1" && [array size files_m] > 3 & $name_index_type == "files"} {
		for {} {$name_index < [expr [array size files_m] / 3]} {incr name_index} {
			if [string match "*[string tolower $f_pattern]*" [string tolower $files_m($name_index,1)]] {
				.cscroll.c delete bb
				.cscroll.c dtag yes yes
				set selected_file_size 0
				if [info exists files_list] {unset files_list}
				if [info exists folders_list] {unset folders_list}
				scrollButton .cscroll.c [.cscroll.c find withtag ttext$name_index]
				.cscroll.c xview moveto [expr [expr [lindex [.cscroll.c coords ttext$name_index] 0] - [winfo width .cscroll.c] / 2] / [lindex [.cscroll.c bbox all] 2]]
				incr name_index
				return
			}
		}
	}
	set name_index 0
	set name_index_type "folders"
}


proc UploadFile {} {
	###############################################################
	global computer
	global workgroup
	global computer_ip_num
	global user_name
	global password
	global share
	.cscroll.c delete box
	set directory [DirMaker \\]
	set file_path [tk_getOpenFile -title "Upload File"]
	if {$file_path == ""} {return}
	set path [string range $file_path 0 [string last "/" $file_path]]
	set p_file [string range $file_path [expr [string last "/" $file_path] + 1] [expr [string length $file_path] - 1]]
	set command_line "cd \"$directory\"; lcd \"$path\"; put \"$p_file\""
	set fq_type 1
	if {$user_name == "" & $password == ""} {set fq_type "0"}
	FileQueue "\{\{Upload file to //$computer/$share\} \{$file_path\} \{//$computer/$share/[DirMaker /]\} \{(Unknown)\} $fq_type \{$computer\}\
		\{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
}


proc SaveSelected {} {
	###############################################################
	global computer
	global workgroup
	global computer_ip_num
	global user_name
	global password
	global share
	global files_m
	global directory_a
	global saveoropen
	global save_file_size
	global selected_file_size
	global files_list
	global folders_list
	.cscroll.c delete box
	if {[info exists files_list] == "0" & [info exists folders_list] == "0"} {return}
	set local_path [FolderDialog ""]
	if {$local_path == ""} {return}
	set directory [DirMaker \\]
	set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt;"
	if {[info exists files_list] == 1 && [llength $files_list] != 0} {
		set m 0
		while {$m != [llength $files_list]} {
			set command_line "$command_line get \"[lindex $files_list $m]\";"
			incr m
		}
	}
	if {[info exists folders_list] == 1 && [llength $folders_list] != 0} {
		set m 0
		set command_line "$command_line recurse;"
		while {$m != [llength $folders_list]} {
			set command_line "$command_line mget \"[lindex $folders_list $m]\";"
			incr m
		}
	}
	set fq_type 1
	if {$user_name == "" & $password == ""} {set fq_type "0"}
	FileQueue "\{\{Selected files from //$computer/$share\} \{//$computer/$share/[DirMaker /]\} \{$local_path\} \{$selected_file_size\}\
		$fq_type \{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
}


proc OpenText {file} {
	##################################################################
	global opentextid
	global save_on
	global win_id
	incr win_id
	.cscroll.c delete box
	set opentextid ".opentext$win_id"
	toplevel $opentextid
	frame $opentextid.text
	pack $opentextid.text -fill both -expand yes -pady 5 -side top
	scrollbar $opentextid.text.yscroll -orient vertical -command "$opentextid.text.area yview"
	pack  $opentextid.text.yscroll -side right -fill y
	text $opentextid.text.area -foreground black -background white -yscrollcommand "$opentextid.text.yscroll set"
	pack $opentextid.text.area -fill both -expand yes -side top
	frame $opentextid.buttons -borderwidth 5
	pack $opentextid.buttons -side bottom -fill x
	button $opentextid.buttons.dismiss -highlightthickness 0 -text Dismiss\
	-command "destroy $opentextid"
	pack $opentextid.buttons.dismiss
	wm title $opentextid "File: $file"
	tkwait visibility $opentextid.buttons.dismiss
	set fid [open $file]
	$opentextid.text.area insert 1.0 [read $fid]
	close $fid
	bind $opentextid <KeyPress-Escape> "destroy $opentextid"
}


proc OpenCommand {globelm} {
	##################################################################
	global commands_m
	global computer
	global canvason
	global share
	global directory_a
	global env
	global computer_ip_num
	global files_m
	global user_name
	global password
	global workgroup
	global save_on
	global command_win
	global save_on
	global file_global
	global file_remote_global
	global kill_id
	global env
	global env_name
	global stopped
	.cscroll.c delete box
	set directory [DirMaker \\]
	set char_index [string last "." $files_m($globelm,1)]
	if {$char_index == "-1" | $char_index == "0"} {
		set end ""
		set very_end ""
	} else {
		set end [string range $files_m($globelm,1) $char_index [expr [string length $files_m($globelm,1)] - 1]]
		set char_index [string last "." $files_m($globelm,1)]
		set very_end [string range $files_m($globelm,1) $char_index [expr [string length $files_m($globelm,1)] - 1]]
	}
	set file_remote $directory\\$files_m($globelm,1)
	set file "$env(HOME)/.xsmbrowser/xsmbrowser-temp/cache[string tolower $end]"
	set file_global $file
	set file_remote_global $files_m($globelm,1)
	if ![winfo exists .command_win] {
		toplevel .command_win
		frame .command_win.f -borderwidth 6
		frame .command_win.f.p
		frame .command_win.f.c
		frame .command_win.f.b  -borderwidth 4
		pack .command_win.f .command_win.f.p .command_win.f.c .command_win.f.b -side top -fill x
		label .command_win.f.p.l -text "Programs: "
		label .command_win.f.c.l -text "Command: "
		pack .command_win.f.p.l .command_win.f.c.l -side left
		menubutton .command_win.f.p.m -indicatoron 1 -relief groove -menu .command_win.f.p.m.m
		menu .command_win.f.p.m.m -tearoff 0
		set m 0
		set type_match "0"
		while {$m < [expr [array size commands_m] / 3]} {
			.command_win.f.p.m.m add radiobutton -label $commands_m($m,name) -command "FileSub $m .command_win; focus .command_win.f.c.e"
			if {$type_match == "0"} {
				if {[lsearch -exact $commands_m($m,types) [string toupper $very_end]] != "-1"} {
					set type_match $m
				}
			}
			incr m
		}
		pack .command_win.f.p.m -side left -fill x -expand yes
		entry .command_win.f.c.e -width 35 -foreground black -background white
		pack .command_win.f.c.e -side left -fill x -expand yes
		set stopped "no"
		button .command_win.f.b.ex -highlightthickness 0 -width 8\
		-text "Execute" -command {CommandExecute .command_win $file_global}
		button .command_win.f.b.sa -highlightthickness 0 -width 8\
		-text "Stop" -command {set stopped yes;catch {eval {exec kill -s SIGTERM} $kill_id}}
		button .command_win.f.b.cn -highlightthickness 0 -width 8\
		-text "Close" -state disabled -command "destroy .command_win"
		pack .command_win.f.b.cn .command_win.f.b.sa .command_win.f.b.ex -side right
		tkwait visibility .command_win.f.b.ex
	} else {
		.command_win.f.b.ex config -command {CommandExecute .command_win $file_global}
		.command_win.f.b.sa config -text "Stop" -command {set stopped yes;catch {eval {exec kill -s SIGTERM} $kill_id}}
		.command_win.f.b.cn config -state disabled
		set m 0
		set type_match "0"
		while {$m < [expr [array size commands_m] / 3]} {
			if {$type_match == "0"} {
				if {[lsearch -exact $commands_m($m,types) [string toupper $very_end]] != "-1"} {
					set type_match $m
				}
			}
			incr m
		}
		raise .command_win .
	}
	wm title .command_win "Loading ... Please Wait."
	.command_win.f.p.m.m invoke $type_match
	focus .command_win.f.c.e
	bind .command_win <KeyPress-Return> ".command_win.f.b.ex invoke"
	grab .command_win
	set canvason "off"
	set command_line "get \"$file_remote\" \"$file\""
	if {$user_name == "" & $password == ""} {
		set kill_id [spawn smbclient \\\\$computer\\$share -I $computer_ip_num -N -W $workgroup -c $command_line]
	} else {
		set kill_id [spawn smbclient \\\\$computer\\$share -U $user_name -I $computer_ip_num -N -W $workgroup -c $command_line]
	}
	set id $spawn_id
	set timeout 360
	expect {
		-i $id -indices -re " - (ERR\[^ ]+)" {
			set error_message [Error $expect_out(1,string)]
			set stopped "yes"
			exp_continue
		}
		-i $id -indices -re "Error code \[0-9]*" {
			set error_message $expect_out(0,string)
			set stopped "yes"
			exp_continue
		}
		-i $id "Error" {
			if [string match *Error* $command_line] {
				exp_continue
			} else {
				set error_message "Unexpected Error"
				set stopped "yes"
				close -i $id
			}
		}
		-i $id "failed" {
			if [string match *failed* $command_line] {
				exp_continue
			} else {
				set error_message "Connection failed"
				set stopped "yes"
				exp_continue
			}
		}
		-i $id "ERRDOS" {
			if [string match *ERRDOS* $command_line] {
				exp_continue
			} else {
				set error_message "Error: ERRDOS"
				set stopped "yes"
				exp_continue
			}
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	set canvason "on"
	grab release .command_win
	.command_win.f.b.sa config -text "Save As" -command {CommandSaveAs .command_win $file_global $file_remote_global}
	.command_win.f.b.cn config -state normal
	.command_win.f.b.sa config -state normal
	if {[file exists $file] == 0 | $stopped == "yes"} {
		if [info exists error_message] {
			wm title .command_win $error_message
			unset error_message
		} else {
			wm title .command_win "File Not Loaded ..."
		}
	}
	wm title .command_win "File: $file"
	focus .command_win.f.c.e
	raise .command_win .
}


proc CommandSaveAs {window file file_remote} {
	set file_place_new [tk_getSaveFile -initialfile $file_remote -title "Save As"]
	if {$file_place_new != ""} {
		destroy $window
		eval "exec cp \"$file\" \"$file_place_new\" &"
	}
}


proc CommandExecute {window file} {
	if {[$window.f.c.e get] == "Internal Text Viewer"} {
		OpenText $file
	} else {
		set fs_execute "exec [$window.f.c.e get] &"
		eval $fs_execute
	}
}


proc FileSub {m window} {
	##########################
	global commands_m
	global file_global
	set first [string first "\$FILE" $commands_m($m,command)]
	if {$first != "-1"} {
		set execute "[string range $commands_m($m,command) 0 [expr $first - 1]]\"$file_global\"[string range $commands_m($m,command)\
		[expr $first + 11] [expr [string length $commands_m($m,command)] - 1]]"
	} else {
		set execute "$commands_m($m,command)"
	}
	$window.f.p.m config -text $commands_m($m,name)
	$window.f.c.e delete 0 1024
	$window.f.c.e insert 0 $execute
}


proc FolderDialog {entryname} {
	#############################
	global last_save_dir
	global env
	if ![info exists last_save_dir] {
		set last_save_dir $env(HOME)
	}
	set file [tk_getSaveFile -title "Choose Directory" -filetypes  {{"No Files" {.none}}} -initialdir $last_save_dir -initialfile "Choose Directory"]
	if {$file == ""} {return ""}
	set spot [string last "/" $file]
	set folder $file
	if {$spot != "-1" & $file != "/"} {
		set folder [string range $file 0 [expr $spot - 1]]
		set last_save_dir $folder
	}
	if {$entryname != ""} {
		$entryname delete 0 1024
		$entryname insert 0 $folder
	}
	return $folder
}


proc MakeFolder {} {
	###########################################
	global net_type
	.cscroll.c delete box
	toplevel .makefol
	wm title .makefol "Make Directory"
	frame .makefol.f -borderwidth 6
	pack .makefol.f -side top -fill x
	label .makefol.f.l -text "Directory:"
	entry .makefol.f.e -width 15 -foreground black -background white
	pack .makefol.f.l -side left
	pack .makefol.f.e -expand yes -fill x -side left
	frame .makefol.f2
	pack .makefol.f2 -side top -fill x
	button .makefol.f2.b -highlightthickness 0 -width 6 -text "Make"\
	-command {
		.info.info2.stats config -text "Working ..."
		. config -cursor watch
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		if {$user_name == "" & $password == ""} {
			set spawn_pid [spawn smbclient \\\\$computer\\$share -I $computer_ip_num -N -W $workgroup -c "cd \"[DirMaker \\]\";\
			mkdir \"[.makefol.f.e get]\""]
		} else {
			set spawn_pid [spawn smbclient \\\\$computer\\$share -U $user_name -I $computer_ip_num -N -W $workgroup\
			-c "cd \"[DirMaker \\]\"; mkdir \"[.makefol.f.e get]\""]
		}
		destroy .makefol
		set id $spawn_id
		set timeout 25
		expect {
			-i $id -indices -re " - (ERR\[^ ]+)" {
				set error_message [Error $expect_out(1,string)]
				exp_continue
			}
			-i $id -indices -re "Error code \[0-9]*" {
				set error_message $expect_out(0,string)
				exp_continue
			}
			-i $id "Error" {
				set error_message "Unexpected Error"
				exp_continue
			}
			-i $id "failed" {
				set error_message "Connection failed"
				exp_continue
			}
			-i $id "ERRDOS" {
				set error_message "Error: ERRDOS"
				exp_continue
			}
			-i $id timeout { close -i $id }
		}
		wait -i $id
		DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
		. config -cursor left_ptr
		.top.top4.refresh invoke
		if [info exists error_message] {
			.info.info2.stats config -text $error_message
			unset error_message
		}
	}
	button .makefol.f2.c -highlightthickness 0 -width 6 -text "Cancel"\
	-command {
		destroy .makefol
	}
	pack .makefol.f2.c .makefol.f2.b -side right
	bind .makefol <KeyPress-Return> {.makefol.f2.b invoke}
	bind .makefol <KeyPress-Escape> {.makefol.f2.c invoke}
	focus .makefol.f.e
	tkwait visibility .makefol.f2.b
	grab .makefol
	raise .makefol .
	tkwait window .makefol
}


proc DeleteSelected {} {
	##################################################################
	global computer
	global canvason
	global share
	global env
	global computer_ip_num
	global spawn_pid
	global files_m
	global files_list
	global folders_list
	global user_name
	global password
	global directory_a
	global workgroup
	global save_on
	global save_on
	global env
	global env_name
	.cscroll.c delete box
	DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
	. config -cursor watch
	set dir [DirMaker \\]
	set command_line "cd \"$dir\"; prompt;"
	if {[info exists files_list] == 1 && [llength $files_list] != 0} {
		set m 0
		while {$m != [llength $files_list]} {
			set command_line "$command_line del \"[lindex $files_list $m]\";"
			incr m
		}
	}
	if {[info exists folders_list] == 1 && [llength $folders_list] != 0} {
		set m 0
		set command_line "$command_line recurse;"
		while {$m != [llength $folders_list]} {
			set command_line "$command_line rmdir \"[lindex $folders_list $m]\";"
			incr m
		}
	}
	if {$user_name == "" & $password == ""} {
		set spawn_pid [spawn smbclient \\\\$computer\\$share -I $computer_ip_num -N -W $workgroup -c $command_line]
	} else {
		set spawn_pid [spawn smbclient \\\\$computer\\$share -U $user_name -I $computer_ip_num -N -W $workgroup -c $command_line]
	}
	set id $spawn_id
	set timeout 25
	expect {
		-i $id -indices -re " - (ERR\[^ ]+)" {
			set error_message [Error $expect_out(1,string)]
			exp_continue
		}
		-i $id -indices -re "Error code \[0-9]*" {
			set error_message $expect_out(0,string)
			exp_continue
		}
		-i $id "Error" {
			if [string match *Error* $command_line] {
				exp_continue
			} else {
				set error_message "Unexpected Error"
				exp_continue
			}
		}
		-i $id "failed" {
			if [string match *failed* $command_line] {
				exp_continue
			} else {
				set error_message "Connection failed"
				exp_continue
			}
		}
		-i $id "ERRDOS" {
			if [string match *ERRDOS* $command_line] {
				exp_continue
			} else {
				set error_message "Error: ERRDOS"
				exp_continue
			}
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
	. config -cursor left_ptr
	.top.top4.refresh invoke
	if [info exists error_message] {
		.info.info2.stats config -text $error_message
	}
}


proc FileQueue {list_addition} {
	#############################################
	global canvason
	global file_queue_list
	global file_queue_stop
	global file_queue_loop
	global file_queue_exist
	global m_working
	if [winfo exists .file] {
		set window_exist "yes"
	} else {
		set window_exist "no"
	}
	if {$window_exist == "no"} {
		toplevel .file
		wm title .file "File Queue"
		frame .file.f1 -borderwidth 0
		frame .file.f2 -borderwidth 10
		pack .file.f1 .file.f2 -side top -fill x
		frame .file.f1.f1 -borderwidth 0
		pack .file.f1.f1 -side left
		frame .file.f1.f2 -borderwidth 0
		pack .file.f1.f2 -side left -fill both -expand yes
		frame .file.f1.f3 -borderwidth 0
		frame .file.f2.f1 -borderwidth 0
		frame .file.f2.f2 -borderwidth 0
		pack .file.f1.f3 .file.f2.f1 .file.f2.f2 -side left
		button .file.f1.f1.b1 -highlightthickness 0 -text "Top" -width 6\
		-command {
			FileQueueMove "top"
		}
		button .file.f1.f1.b2 -highlightthickness 0 -text "Up" -width 6\
		-command {
			FileQueueMove "up"
		}
		button .file.f1.f1.b3 -highlightthickness 0 -text "Down" -width 6\
		-command {
			FileQueueMove "down"
		}
		button .file.f1.f1.b4 -highlightthickness 0 -text "End" -width 6\
		-command {
			FileQueueMove "end"
		}
		button .file.f1.f3.b1 -highlightthickness 0 -text "Start Queue" -width 10
		button .file.f1.f3.b2 -highlightthickness 0 -text "Retry" -width 10
		button .file.f1.f3.b3 -highlightthickness 0 -text "Remove" -width 10\
		-command {
			FileQueueRemove
		}
		button .file.f1.f3.b4 -highlightthickness 0 -text "Close Queue"\
		-width 10 -command {
			catch [destroy .file]
		}
		pack .file.f1.f1.b1 .file.f1.f1.b2 .file.f1.f1.b3 .file.f1.f1.b4 .file.f1.f3.b1 .file.f1.f3.b2 .file.f1.f3.b3 .file.f1.f3.b4 -side top
		listbox .file.f1.f2.lb1 -height 1 -width 54 -takefocus 1 -cursor right_ptr -foreground black -background white\
		-borderwidth 1 -selectmode single -selectborderwidth 0 -yscrollcommand [list .file.f1.f2.sb1 set]
		scrollbar .file.f1.f2.sb1 -borderwidth 2 -orient vertical -command [list .file.f1.f2.lb1 yview]
		pack .file.f1.f2.lb1 -side left -fill both -expand yes
		pack .file.f1.f2.sb1 -side right -fill y
		label .file.f2.f1.l1 -justify right -text "Source:  \nDestination:  \nSize:  "
		pack .file.f2.f1.l1 -side right
		label .file.f2.f2.l1 -justify left -text ""
		pack .file.f2.f2.l1 -side left
		tkwait visibility .file.f2.f2.l1
		FileQueueReadFile  
		set file_queue_loop "loop"
		set file_queue_stop "stopped"
		bind .file.f1.f2.lb1 <ButtonRelease-1> {
			FileQueueFocus
		}
		bind .file <Destroy> {
			set file_queue_loop "end"
			if {$file_queue_stop != "stopped"} {
				set file_queue_stop "stopped"
				catch {eval {exec kill -s SIGTERM} $file_queue_id}
			}
			FileQueueWriteFile
		}
		bind .file <KeyPress-Escape> {.file.f1.f3.b4 invoke}
	}
	if {$list_addition != ""} {
		if [info exists file_queue_list] {
			lappend file_queue_list [lindex $list_addition 0]
		} else {
			set file_queue_list $list_addition
		}
		.file.f1.f2.lb1 insert end " [string range [lindex [lindex $list_addition 0] 0] 0 33] ... Queued"
		FileQueueWriteFile
		if {$window_exist == "yes"} {return}
	} else {
		if [info exists file_queue_list] {
			set file_queue_loop "wait"
		} else {
			set file_queue_loop "emptystart"
		}
	}
	set error_found "no"
	set queue_found "yes"
	while {$queue_found == "yes"} {
		set queue_found "no"
		set m 0
		while {$file_queue_loop == "emptystart"} {
			set m 0
			if {$file_queue_loop == "end"} {
				return
			}
			.file.f1.f3.b1 config -text "Start Queue" -command {
				set file_queue_loop "loop"
			}
			tkwait variable file_queue_loop
		}
		while {[info exists file_queue_list] == "1" && [lindex $file_queue_list $m] != ""} {
			while {$file_queue_loop != "loop"} {
				set m 0
				if {$file_queue_loop == "end"} {
					return
				}
				.file.f1.f3.b1 config -text "Start Queue" -command {
					set file_queue_loop "loop"
				}
				tkwait variable file_queue_loop
			}
			.file.f1.f3.b1 config -text "Stop Queue" -command {
				set file_queue_loop "wait"
				if {$file_queue_stop != "stopped"} {
					set file_queue_stop "stopped"
					catch {eval {exec kill -s SIGTERM} $file_queue_id}
				}
				FileQueueWriteFile
			}
			if {[lindex [lindex $file_queue_list $m] 13] == "Queued"} {
				set queue_found "yes"
				FileQueueStatus $m "Working"
				FileQueueFocus
				set m_working $m
				set status [FileQueueSpawn $m]
				set canvason "on"
				if [winfo exists .file] {
					wm title .file $status
					if {[string range $status 0 4] == "Error"} {set error_found "yes"}
					if {$status == "Done"} {FileQueueUploadCheck $m_working}
					if {[lindex [lindex $file_queue_list $m_working] 13] == "Working"} {
						FileQueueStatus $m_working $status
						if {[.file.f1.f2.lb1 curselection] == $m_working} {FileQueueFocus}
					}
					FileQueueWriteFile
					set m "-1"
				}
			}
			incr m
		}
		if {$queue_found == "no" & $error_found == "yes"} {
			if [winfo exists .file] {
				focus .file
				raise .file .
				set queue_found "yes"
				set error_found "no"
				set file_queue_loop "wait"
			}
		}
	}
	catch [destroy .file]
}


proc FileQueueStatus {m what} {
	##############################
	global file_queue_list
	if {[lindex $file_queue_list $m] != ""} {
		.file.f1.f2.lb1 delete $m
		.file.f1.f2.lb1 insert $m " [string range [lindex [lindex $file_queue_list $m] 0] 0 33] ... $what"
		.file.f1.f2.lb1 selection clear 0 1024
		.file.f1.f2.lb1 selection set $m $m
		.file.f1.f2.lb1 see $m
		set file_queue_list [lreplace $file_queue_list $m $m [lreplace [lindex $file_queue_list $m] 13 13 "$what"]]
	}
}


proc FileQueueUploadCheck {m} {
	##############################
	global file_queue_list
	global computer
	global share
	global directory_a
	if {[string range [lindex [lindex $file_queue_list $m] 0] 0 5] == "Upload"} {
		if {[info exists computer] == 1 & [info exists share] == 1} {
			set directory [DirMaker /]
			if {[lindex [lindex $file_queue_list $m] 2] == "//$computer/$share/$directory"} {
				.top.top4.refresh invoke
			}
		}
	}
}


proc FileQueueWriteFile {} {
	##############################
	global file_queue_list
	global file_queue_write_wait
	if {$file_queue_write_wait != "0"} {
		incr file_queue_write_wait
		tkwait variable file_queue_write_wait
		if {$file_queue_write_wait != "0"} {return}
	}
	incr file_queue_write_wait
	if ![info exists file_queue_list] {
		set file_queue_write_wait 0
		return
	}
	set userfile [open "~/.xsmbrowser/xsmbrowser-queue" w 0600]
	set m 0
	while {[lindex [lindex $file_queue_list $m] 0] != ""} {
		if {[lindex [lindex $file_queue_list $m] 13] != "Done"} {
			puts $userfile ":[lindex [lindex $file_queue_list $m] 0]"
			puts $userfile "Source Info = [lindex [lindex $file_queue_list $m] 1]"
			puts $userfile "Destination Info = [lindex [lindex $file_queue_list $m] 2]"
			puts $userfile "Size Info = [lindex [lindex $file_queue_list $m] 3]"
			puts $userfile "Type = [lindex [lindex $file_queue_list $m] 4]"
			puts $userfile "Computer = [lindex [lindex $file_queue_list $m] 5]"
			puts $userfile "Share = [lindex [lindex $file_queue_list $m] 6]"
			puts $userfile "IP Address = [lindex [lindex $file_queue_list $m] 7]"
			puts $userfile "User Name = [lindex [lindex $file_queue_list $m] 8]"
			puts $userfile "Password = [lindex [lindex $file_queue_list $m] 9]"
			puts $userfile "Directory = [lindex [lindex $file_queue_list $m] 10]"
			puts $userfile "Workgroup = [lindex [lindex $file_queue_list $m] 11]"
			puts $userfile "Command = [lindex [lindex $file_queue_list $m] 12]"
			set status [lindex [lindex $file_queue_list $m] 13]
			if {$status == "Queued" | $status == "Working"} {set status "Canceled"}
			puts $userfile "Status = $status"
			puts $userfile ""
		}
		incr m
	}
	puts $userfile "EOF"
	close $userfile
	set file_queue_write_wait 0
}


proc FileQueueReadFile {} {
	##############################
	global file_queue_list
	if [info exists file_queue_list] {unset file_queue_list}
	set userfile [open "~/.xsmbrowser/xsmbrowser-queue" r]
	set m "-1"
	gets $userfile line
	while {$line != "EOF" & [eof $userfile] == "0"} {
		if [regexp -indices "^:(.*) *" $line m1 m2] {
			incr m
			set list($m,list) [string range $line [lindex $m2 0] [lindex $m2 1]]
			set list($m,source) ""
			set list($m,destination) ""
			set list($m,size) ""
			set list($m,type) ""
			set list($m,computer) ""
			set list($m,share) ""
			set list($m,ip) ""
			set list($m,user) ""
			set list($m,password) ""
			set list($m,directory) ""
			set list($m,workgroup) ""
			set list($m,command) ""
			set list($m,status) ""
		} elseif [regexp -indices "^ *\Source Info *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,source) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Destination Info *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,destination) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Size Info *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,size) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Type *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,type) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Computer *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,computer) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Share *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,share) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\IP Address *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,ip) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\User Name *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,user) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Password *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,password) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Directory *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,directory) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Command *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,command) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Workgroup *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,workgroup) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		} elseif [regexp -indices "^ *\Status *= *(.*)" $line m1 m2] {
			if {$m != "-1"} {set list($m,status) [string range $line [lindex $m2 0] [lindex $m2 1]]}
		}
		gets $userfile line
	}
	close $userfile
	if [info exists list(0,list)] {
		set p 0
		set file_queue_list "\{\{$list($p,list)\} \{$list($p,source)\} \{$list($p,destination)\} \{$list($p,size)\} \{$list($p,type)\} \{$list($p,computer)\}\
			\{$list($p,share)\} \{$list($p,ip)\} \{$list($p,user)\} \{$list($p,password)\} \{$list($p,directory)\} \{$list($p,workgroup)\} \{$list($p,command)\}\
			\{$list($p,status)\}\}"
		.file.f1.f2.lb1 insert end " [string range $list($p,list) 0 33] ... $list($p,status)"
		set p 1
		while {$p <= $m} {
			lappend file_queue_list "\{$list($p,list)\} \{$list($p,source)\} \{$list($p,destination)\} \{$list($p,size)\} \{$list($p,type)\} \{$list($p,computer)\}\
			\{$list($p,share)\} \{$list($p,ip)\} \{$list($p,user)\} \{$list($p,password)\} \{$list($p,directory)\} \{$list($p,workgroup)\} \{$list($p,command)\}\
			\{$list($p,status)\}"
			.file.f1.f2.lb1 insert end " [string range $list($p,list) 0 33] ... $list($p,status)"
			incr p
		}
		.file.f1.f2.lb1 selection clear 0 1024
		.file.f1.f2.lb1 selection set 0 0
		.file.f1.f2.lb1 see 0
		FileQueueFocus
	}
}


proc FileQueueSpawn {m} {
	##############################
	global file_queue_list
	global file_queue_stop
	global file_queue_id
	global env
	global canvason
	wm title .file [string range [lindex [lindex $file_queue_list $m] 1] 0 65]
	set file_queue_stop "active"
	set err "Done"
	while {$canvason == "off"} {
		tkwait variable canvason
	}
	set canvason "off"
	if [info exists env(USER)] {
		set user_bkup $env(USER)
		set env(USER) "[lindex [lindex $file_queue_list $m] 8]%[lindex [lindex $file_queue_list $m] 9]"
	} elseif [info exists env(LOGNAME)] {
		set user_bkup $env(LOGNAME)
		set env(LOGNAME) "[lindex [lindex $file_queue_list $m] 8]%[lindex [lindex $file_queue_list $m] 9]"
	} else {
		set user_bkup "%"
		set env(USER) "[lindex [lindex $file_queue_list $m] 8]%[lindex [lindex $file_queue_list $m] 9]"
	}
	set e [lindex [lindex $file_queue_list $m] 4]
	if {$e == "0"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -N -W [lindex [lindex $file_queue_list $m] 11] -c [lindex [lindex $file_queue_list $m] 12]]
	} elseif {$e == "1"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -U [lindex [lindex $file_queue_list $m] 8] -N -W [lindex [lindex $file_queue_list $m] 11]\
		-c [lindex [lindex $file_queue_list $m] 12]]
	} elseif {$e == "2"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -N -W [lindex [lindex $file_queue_list $m] 11] -D [lindex [lindex $file_queue_list $m] 10]\
		-Tc [lindex [lindex $file_queue_list $m] 12]]
	} elseif {$e == "3"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -U [lindex [lindex $file_queue_list $m] 8] -N -W [lindex [lindex $file_queue_list $m] 11]\
		-D [lindex [lindex $file_queue_list $m] 10] -Tc [lindex [lindex $file_queue_list $m] 12]]
	} elseif {$e == "4"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -N -W [lindex [lindex $file_queue_list $m] 11] -Tc [lindex [lindex $file_queue_list $m] 12]]
	} elseif {$e == "5"} {
		set file_queue_id [spawn smbclient \\\\[lindex [lindex $file_queue_list $m] 5]\\[lindex [lindex $file_queue_list $m] 6]\
		-I [lindex [lindex $file_queue_list $m] 7] -U [lindex [lindex $file_queue_list $m] 8] -N -W [lindex [lindex $file_queue_list $m] 11]\
		-Tc [lindex [lindex $file_queue_list $m] 12]]
	}
	set id $spawn_id
	set timeout 4
	expect {
		-i $id -indices -re " - (ERR\[^ ]+)" {
			set err "Error ([Error $expect_out(1,string)])"
			exp_continue
		}
		-i $id -indices -re "Error code \[0-9]*" {
			set err "Error ($expect_out(0,string))"
			exp_continue
		}
		-i $id "Error" {
			set err "Error"
			exp_continue
		}
		-i $id "failed" {
			set err "Error (Connection failed)"
			exp_continue
		}
		-i $id "Usage: smbclient" {
			set err "Error (Bad Usage, Check Filename)"
			exp_continue
		}
		-i $id "ERRDOS" {
			set err "Error (ERRDOS)"
			exp_continue
		}
		-i $id timeout {
			if {$user_bkup != "Done."} {
				if [info exists env(USER)] {
					set env(USER) $user_bkup
				} elseif [info exists env(LOGNAME)] {
					set env(LOGNAME) $user_bkup
				} else {
					set env(USER) $user_bkup
				}
				set user_bkup "Done."
				set canvason "on"
			}
			exp_continue
		}
	}
	wait -i $id
	if {$user_bkup != "Done."} {
		if [info exists env(USER)] {
			set env(USER) $user_bkup
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) $user_bkup
		} else {
			set env(USER) $user_bkup
		}
		set canvason "on"
	}
	if {$file_queue_stop == "stopped"} {
		return "Canceled"
	} else {
		set file_queue_stop "stopped"
		return $err
	}
}


proc FileQueueFocus {} {
	##############################
	global file_queue_list
	set selected [.file.f1.f2.lb1 curselection]
	if {[llength $selected] == "1"} {
		.file.f2.f2.l1 config -text "[string range [lindex [lindex $file_queue_list $selected] 1] 0 85]\n[string range [lindex [lindex $file_queue_list\
		$selected] 2] 0 85]\n[lindex [lindex $file_queue_list $selected] 3]"
		if {[lindex [lindex $file_queue_list $selected] 13] == "Working"} {
			.file.f1.f3.b2 config -text "Stop" -command {
				if {$file_queue_stop != "stopped"} {
					set file_queue_stop "stopped"
					catch {eval {exec kill -s SIGTERM} $file_queue_id}
				}
			}
			return
		}
	}
	set focus_queued "yes"
	set m 0
	set index [lindex $selected $m]
	while {$index != ""} {
		set status [lindex [lindex $file_queue_list $index] 13]
		if {$status != "Queued"} {set focus_queued "no"}
		incr m
		set index [lindex $selected $m]
	}
	if {$focus_queued == "yes"} {
		.file.f1.f3.b2 config -text "Cancel" -command {
			set selected_retry [.file.f1.f2.lb1 curselection]
			set m_retry 0
			set index_retry [lindex $selected_retry $m_retry]
			while {$index_retry != ""} {
				if {[lindex [lindex $file_queue_list $index_retry] 13] != "Working"} {
					FileQueueStatus $index_retry "Canceled"
				} 
				incr m_retry
				set index_retry [lindex $selected_retry $m_retry]
			}
			FileQueueFocus
		}
		return
	}
	.file.f1.f3.b2 config -text "Retry" -command {
		set selected_retry [.file.f1.f2.lb1 curselection]
		set m_retry 0
		set index_retry [lindex $selected_retry $m_retry]
		while {$index_retry != ""} {
			if {[lindex [lindex $file_queue_list $index_retry] 13] != "Working"} {
				FileQueueStatus $index_retry "Queued"
			}
			incr m_retry
			set index_retry [lindex $selected_retry $m_retry]
		}
		FileQueueFocus
	}
}


proc FileQueueRemove {} {
	##############################
	global file_queue_list
	global file_queue_stop
	global file_queue_wait
	global file_queue_loop
	global file_queue_id
	global m_working
	set loop_return $file_queue_loop
	set file_queue_loop "wait"
	set selected [.file.f1.f2.lb1 curselection]

	set m 0
	set index [lindex $selected $m]
	set first_index $index
	while {$index != ""} {
		set status [lindex [lindex $file_queue_list $first_index] 13]
		if {$status == "Working"} {
			if {$file_queue_stop != "stopped"} {
				set file_queue_stop "stopped"
				catch {eval {exec kill -s SIGTERM} $file_queue_id}
			}
		}
		.file.f1.f2.lb1 delete $first_index
		set file_queue_list "[lrange $file_queue_list 0 [expr $first_index - 1]] [lrange $file_queue_list [expr $first_index + 1] [expr [llength\
		$file_queue_list] - 1]]"
		incr m
		set index [lindex $selected $m]
	}
	if {$m_working > [lindex $selected [expr $m - 1]]} {
		set m_working [expr $m_working - [llength $selected]]
	}
	set file_queue_loop $loop_return
	FileQueueWriteFile
	if {[lindex [lindex $file_queue_list 0] 13] != ""} {
		.file.f1.f2.lb1 selection set 0
		FileQueueFocus
	}
}


proc FileQueueMove {where} {
	##############################
	global file_queue_list
	global m_working
	set selected [.file.f1.f2.lb1 curselection]
	if {$where == "top"} {
		set move_index 0
		set addition "-1"
		set m [expr [llength $selected] - 1]
	} elseif {$where == "end"} {
		set move_index [llength $file_queue_list]
		set addition "1"
		set m 0
	} elseif {$where == "up"} {
		set move_index [expr [lindex $selected 0] - 1]
		set addition "-1"
		set m [expr [llength $selected] - 1]
	} else {
		set move_index [expr [lindex $selected [expr [llength $selected] - 1]] + 1]
		set addition "1"
		set m 0
	}
	set m_working_found "no"
	set index [lindex $selected $m]
	set main_index $index
	.file.f1.f2.lb1 selection clear 0 1024
	while {$index != ""} {
		set status [lindex [lindex $file_queue_list $main_index] 13]
		set list_info [lindex [lindex $file_queue_list $main_index] 0]
		set file_queue_list [linsert "[lrange $file_queue_list 0 [expr $main_index - 1]] [lrange $file_queue_list [expr $main_index + 1]\
		[expr [llength $file_queue_list] - 1]]" $move_index [lindex $file_queue_list $main_index]]
		.file.f1.f2.lb1 delete $main_index
		.file.f1.f2.lb1 insert $move_index " [string range $list_info 0 33] ... $status"
		if {$move_index < "0"} {
			.file.f1.f2.lb1 selection set 0
		} elseif {$move_index > [expr [llength $file_queue_list] - 1]} {
			.file.f1.f2.lb1 selection set [expr [llength $file_queue_list] - 1]
		} else {
			set real_index $move_index
			.file.f1.f2.lb1 selection set $move_index
		}
		set m [expr $m + $addition]
		set index [lindex $selected $m]
	}
	set m 0
	set status [lindex [lindex $file_queue_list $m] 13]
	while {$status != ""} {
		if {$status == "Working"} {
			set m_working $m
		}
		incr m
		set status [lindex [lindex $file_queue_list $m] 13]
	}
}


proc SaveDialog {where} {
	################################################
	global files_list
	global folders_list
	global directory_a
	global selected_file_size
	global env
	global checker
	global last_save_dir
	global selec_stat
	global where_global
	if [info exists selected_file_size] {
		if {$selected_file_size < 1024} {
			set selec_file_size "$selected_file_size"
		} elseif {$selected_file_size < 1048576} {
			set selec_file_size "[expr $selected_file_size / 1024]KB"
		} elseif {$selected_file_size < 1073741824} {
			set selec_file_size [expr $selected_file_size / 1048576.0]
			set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]MB"
		} else {
			set selec_file_size [expr $selected_file_size / 1073741824.0]
			set selec_file_size "[string range $selec_file_size 0 [expr 1 + [string last "." $selec_file_size]]]GB"
		}
	}
	if [info exists files_list] {
		set selec_stat "[llength $files_list] Files Selected ($selec_file_size)"
	} else {
		set selec_stat "None (drag box; shift-button)"
	}
	set where_global $where
	toplevel .save
	wm title .save "Power Transfer"
	frame .save.a -borderwidth 8
	frame .save.b -borderwidth 1 -relief sunken
	frame .save.c -borderwidth 6
	pack .save.a .save.b .save.c -side top -fill x
	frame .save.a.a
	pack .save.a.a -side top
	radiobutton .save.a.a.rb1 -text "Save" -relief flat -value save -variable transfer_sel -command {
		destroy .save.c
		frame .save.c -borderwidth 6
		pack .save.c -side top -fill x
		frame .save.c.a -borderwidth 1
		frame .save.c.b -borderwidth 1
		frame .save.c.c -borderwidth 1
		frame .save.c.d -borderwidth 1
		frame .save.c.e -borderwidth 1
		frame .save.c.f -borderwidth 1
		frame .save.c.g -borderwidth 1
		frame .save.c.h -borderwidth 1
		frame .save.c.i -borderwidth 6
		pack .save.c.a .save.c.b .save.c.c .save.c.d .save.c.e .save.c.f .save.c.g .save.c.h .save.c.i -side top -fill x
		entry .save.c.a.e1 -foreground black -background white
		pack .save.c.a.e1 -side left -expand yes -fill x
		button .save.c.a.b1 -highlightthickness 0 -text "Browse" -width 8\
		-command {
			FolderDialog .save.c.a.e1
		}
		pack .save.c.a.b1 -side left
		radiobutton .save.c.b.rb1 -text "Selected Files" -variable transfer_sel2 -relief flat -value 1 -command {
			.save.c.e.cb1 config -state disabled
			.save.c.g.e1 config -state disabled -background grey70
			.save.c.h.cb1 config -state disabled
		}
		pack .save.c.b.rb1 -side left
		label .save.c.c.spacer -text "      "
		label .save.c.c.l1 -text $selec_stat
		pack .save.c.c.spacer .save.c.c.l1 -side left
		radiobutton .save.c.d.rb1 -text "All Files in Current Directory" -variable transfer_sel2 -relief flat -value 2 -command {
			.save.c.e.cb1 config -state normal
			.save.c.g.e1 config -state disabled -background grey70
			.save.c.h.cb1 config -state disabled
		}
		pack .save.c.d.rb1 -side left
		label .save.c.e.spacer -text "      "
		checkbutton .save.c.e.cb1 -onvalue "yes" -offvalue "no" -variable recursion_sel -text "Recurse into Subdirectories"
		pack .save.c.e.spacer .save.c.e.cb1 -side left
		radiobutton .save.c.f.rb1 -text "Pattern for Files in Current Directory" -variable transfer_sel2 -relief flat -value 3 -command {
			.save.c.e.cb1 config -state disabled
			.save.c.g.e1 config -state normal -background white
			.save.c.h.cb1 config -state normal
			focus .save.c.g.e1
		}
		pack .save.c.f.rb1 -side left
		label .save.c.g.spacer -text "      "
		entry .save.c.g.e1 -width 15 -foreground black -background white
		label .save.c.h.spacer -text "      "
		checkbutton .save.c.h.cb1 -onvalue "yes" -offvalue "no" -variable recursion_sel2 -text "Recursion"
		pack .save.c.g.spacer .save.c.g.e1 -side left
		pack .save.c.h.spacer .save.c.h.cb1 -side left
		frame .save.c.i.b
		pack .save.c.i.b -side top
		button .save.c.i.b.b1 -highlightthickness 0 -text "Save" -width 8\
		-command {
			set directory [DirMaker \\]
			if {$transfer_sel2 == "1"} {
				if {[info exists files_list] == "0" & [info exists folders_list] == "0"} {return}
				set local_path [MakeDir [.save.c.a.e1 get] "check" ""]
				if {$local_path == "get_thee_to_a_nunnery"} {return}
				set last_save_dir $local_path
				set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt;"
				if {[info exists files_list] == 1 && [llength $files_list] != 0} {
					set m 0
					while {$m != [llength $files_list]} {
						set command_line "$command_line get \"[lindex $files_list $m]\";"
						incr m
					}
				}
				if {[info exists folders_list] == 1 && [llength $folders_list] != 0} {
					set m 0
					set command_line "$command_line recurse;"
					while {$m != [llength $folders_list]} {
						set command_line "$command_line mget \"[lindex $folders_list $m]\";"
						incr m
					}
				}
				destroy .save
				set fq_type 1
				if {$user_name == "" & $password == ""} {set fq_type "0"}
				FileQueue "\{\{Selected files from //$computer/$share\} \{//$computer/$share/[DirMaker /]\} \{$local_path\} \{$selected_file_size\}\
					$fq_type \{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			} elseif {$transfer_sel2 == "2"} {
				set local_path [MakeDir [.save.c.a.e1 get] "check" ""]
				if {$local_path == "get_thee_to_a_nunnery"} {return}
				set last_save_dir $local_path
				if {$recursion_sel == "no"} {
					set command_line "cd \"$directory\";lcd \"$local_path\";prompt;mget *"
				} else {
					set command_line "cd \"$directory\";lcd \"$local_path\";prompt;recurse;mget *"
				}
				destroy .save
				set fq_type 1
				if {$user_name == "" & $password == ""} {set fq_type "0"}
				FileQueue "\{\{All files from //$computer/$share\} \{//$computer/$share/[DirMaker /]\} \{$local_path\} \{(Unknown)\} $fq_type\
					\{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			} else {
				if {[.save.c.g.e1 get] == ""} {return}
				set local_path [MakeDir [.save.c.a.e1 get] "check" ""]
				if {$local_path == "get_thee_to_a_nunnery"} {return}
				set last_save_dir $local_path
				if {$recursion_sel2 == "yes"} {
					set command_line "cd \"$directory\";lcd \"$local_path\";prompt;recurse;mget [.save.c.g.e1 get]"
				} else {
					set command_line "cd \"$directory\";lcd \"$local_path\";prompt; mget [.save.c.g.e1 get]"
				}
				destroy .save
				set fq_type 1
				if {$user_name == "" & $password == ""} {set fq_type "0"}
				FileQueue "\{\{Matching files from //$computer/$share\} \{//$computer/$share/[DirMaker /]\} \{$local_path\} \{(Unknown)\}\
					$fq_type \{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			}
		}
		button .save.c.i.b.b2 -highlightthickness 0 -text "Cancel" -width 8\
		-command {
			destroy .save
		}
		pack .save.c.i.b.b1 .save.c.i.b.b2 -side left
		tkwait visibility .save.c.i.b.b2
		if {$where_global == "2"} {
			.save.c.d.rb1 invoke
		} elseif {$where_global == "3"} {
			.save.c.f.rb1 invoke
		} else {
			.save.c.b.rb1 invoke
		}
		if [info exists last_save_dir] {
			set save_to_dir $last_save_dir
		} elseif [info exists env(HOME)] {
			set save_to_dir $env(HOME)
		} else {
			set save_to_dir "/"
		}
		.save.c.a.e1 insert 0 $save_to_dir
		focus .save.c.a.e1
		bind .save <KeyPress-Return> {.save.c.i.b.b1 invoke}
		bind .save <KeyPress-Escape> {.save.c.i.b.b2 invoke}
	}
	radiobutton .save.a.a.rb2 -text "Tar" -relief flat -value tar -variable transfer_sel -command {
		destroy .save.c
		frame .save.c -borderwidth 6
		pack .save.c -side top -fill x
		frame .save.c.a -borderwidth 1
		frame .save.c.b -borderwidth 1
		frame .save.c.c -borderwidth 6
		pack .save.c.a .save.c.b .save.c.c -side top -fill x
		label .save.c.a.l1 -text "Tar File:"
		pack .save.c.a.l1 -side left
		entry .save.c.a.e1 -foreground black -background white
		pack .save.c.a.e1 -side left -expand yes -fill x
		button .save.c.a.b1 -highlightthickness 0 -text "Browse" -width 8\
		-command {
			set picked_tar_file [tk_getSaveFile -title "Save Tar File"]
			if {$picked_tar_file != ""} {
				.save.c.a.e1 delete 0 100
				.save.c.a.e1 insert 0 $picked_tar_file
			}
		}
		pack .save.c.a.b1 -side left
		label .save.c.b.l1 -justify left -text "Tars all files in current directory and recurses\ninto subdirectories."
		pack .save.c.b.l1 -side left
		frame .save.c.c.b
		pack .save.c.c.b -side top
		button .save.c.c.b.b1 -highlightthickness 0 -text "Tar" -width 8\
		-command {
			set directory [DirMaker \\]
			set pathname [.save.c.a.e1 get]
			if {$pathname == ""} {return}
			destroy .save
			if {$directory == "" & $user_name == "" & $password == ""} {
				set fq_type "4"
			} elseif {$directory != "" & $user_name == "" & $password == ""} {
				set fq_type "2"
			} elseif {$directory == ""} {
				set fq_type "5"
			} else {
				set fq_type "3"
			}
			FileQueue "\{\{Tar files from //$computer/$share\} \{//$computer/$share/[DirMaker /]\} \{$pathname\} \{(Unknown)\} $fq_type \{$computer\}\
				\{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{$directory\} \{$workgroup\} \{$pathname\} Queued\}"
		}
		button .save.c.c.b.b2 -highlightthickness 0 -text "Cancel" -width 8\
		-command {
			destroy .save
		}
		pack .save.c.c.b.b1 .save.c.c.b.b2 -side left
		tkwait visibility .save.c.c.b.b2
		if [info exists last_save_dir] {
			set save_to_dir $last_save_dir
		} elseif [info exists env(HOME)] {
			set save_to_dir $env(HOME)
		} else {
			set save_to_dir "/"
		}
		.save.c.a.e1 insert 0 "$save_to_dir/foo.tar"
		focus .save.c.a.e1
		bind .save <KeyPress-Return> {.save.c.c.b.b1 invoke}
		bind .save <KeyPress-Escape> {.save.c.c.b.b2 invoke}
	}
	radiobutton .save.a.a.rb3 -text "Upload" -variable transfer_sel -relief flat -value upload -command {
		destroy .save.c
		frame .save.c -borderwidth 6
		pack .save.c -side top -fill x
		frame .save.c.a -borderwidth 1
		frame .save.c.b -borderwidth 1
		frame .save.c.c -borderwidth 1
		frame .save.c.d -borderwidth 1
		frame .save.c.e -borderwidth 1
		frame .save.c.f -borderwidth 1
		frame .save.c.g -borderwidth 1
		frame .save.c.g2 -borderwidth 1
		frame .save.c.h -borderwidth 1
		frame .save.c.i -borderwidth 6
		frame .save.c.b.a -borderwidth 1
		frame .save.c.d.a -borderwidth 1
		frame .save.c.e.a -borderwidth 1
		frame .save.c.g.a -borderwidth 1
		frame .save.c.h.a -borderwidth 1
		frame .save.c.i.a -borderwidth 1
		pack .save.c.a .save.c.b .save.c.c .save.c.d .save.c.e .save.c.f .save.c.g .save.c.g2 .save.c.h .save.c.i -side top -fill x
		pack .save.c.b.a .save.c.d.a .save.c.e.a .save.c.g.a .save.c.h.a -side top -fill x
		pack .save.c.i.a -side top
		radiobutton .save.c.a.rb1 -text "Individual File" -variable transfer_sel2 -relief flat -value 5 -command {
			.save.c.g.a.e1 config -state disabled -background grey70
			.save.c.g.a.b1 config -state disabled
			.save.c.g2.e1 config -background grey70 -state disabled
			.save.c.h.a.cb1 config -state disabled
			.save.c.b.a.b1 config -state normal
			.save.c.b.a.e1 config -state normal -background white
			.save.c.d.a.e1 config -state disabled -background grey70
			.save.c.d.a.b1 config -state disabled
			.save.c.e.a.cb1 config -state disabled
			focus .save.c.b.a.e1
		}
		label .save.c.b.a.spacer -text "      "
		entry .save.c.b.a.e1 -foreground black -background white
		button .save.c.b.a.b1 -highlightthickness 0 -text "Browse" -width 8\
		-command {
			set picked_tar_file [tk_getOpenFile -title "Upload File"]
			if {$picked_tar_file != ""} {
				.save.c.b.a.e1 delete 0 100
				.save.c.b.a.e1 insert 0 $picked_tar_file
			}
		}
		pack .save.c.a.rb1 .save.c.b.a.spacer -side left
		pack .save.c.b.a.e1 -side left -expand yes -fill x -side left
		pack .save.c.b.a.b1 -side left
		radiobutton .save.c.c.rb1 -text "All Files from Directory" -variable transfer_sel2 -relief flat -value 6 -command {
			.save.c.b.a.b1 config -state disabled
			.save.c.b.a.e1 config -state disabled -background grey70
			.save.c.d.a.e1 config -state normal -background white
			.save.c.d.a.b1 config -state normal
			.save.c.e.a.cb1 config -state normal
			.save.c.g.a.e1 config -background grey70 -state disabled
			.save.c.g.a.b1 config -state disabled
			.save.c.g2.e1 config -background grey70 -state disabled
			.save.c.h.a.cb1 config -state disabled
			if {[.save.c.d.a.e1 get] == ""} {
				.save.c.d.a.e1 insert 0 $save_to_dir
			}
			focus .save.c.d.a.e1
		}
		label .save.c.d.a.spacer -text "      "
		entry .save.c.d.a.e1 -foreground black -background white
		button .save.c.d.a.b1 -highlightthickness 0 -text "Browse" -width 8\
		-command {
			FolderDialog .save.c.d.a.e1
		}
		pack .save.c.c.rb1 .save.c.d.a.spacer -side left
		pack .save.c.d.a.e1 -side left -fill x -expand yes
		pack .save.c.d.a.b1 -side left
		label .save.c.e.a.spacer -text "      "
		checkbutton .save.c.e.a.cb1 -onvalue "yes" -offvalue "no" -variable recursion_sel -text "Recurse into Subdirectories"
		pack .save.c.e.a.spacer .save.c.e.a.cb1 -side left
		radiobutton .save.c.f.rb1 -text "Pattern for Files from Directory" -variable transfer_sel2 -relief flat -value 7 -command {
			.save.c.b.a.b1 config -state disabled
			.save.c.b.a.e1 config -state disabled -background grey70
			.save.c.d.a.e1 config -state disabled -background grey70
			.save.c.d.a.b1 config -state disabled
			.save.c.e.a.cb1 config -state disabled
			.save.c.g.a.e1 config -background white -state normal
			.save.c.g.a.b1 config -state normal
			.save.c.g2.e1 config -background white -state normal
			.save.c.h.a.cb1 config -state normal
			if {[.save.c.g.a.e1 get] == ""} {
				.save.c.g.a.e1 insert 0 $save_to_dir
			}
			focus .save.c.g.a.e1
		}
		label .save.c.g.a.spacer -text "      "
		entry .save.c.g.a.e1 -foreground black -background white
		button .save.c.g.a.b1 -highlightthickness 0 -text "Browse" -width 8\
		-command {
			FolderDialog .save.c.g.a.e1
		}
		pack .save.c.f.rb1 .save.c.g.a.spacer -side left
		pack .save.c.g.a.e1 -side left -fill x -expand yes
		pack .save.c.g.a.b1 -side left
		label .save.c.g2.spacer -text "        Pattern:"
		entry .save.c.g2.e1 -foreground black -background white -width 15
		pack .save.c.g2.spacer .save.c.g2.e1 -side left
		label .save.c.h.a.spacer -text "      "
		checkbutton .save.c.h.a.cb1 -onvalue "yes" -offvalue "no" -variable recursion_sel2 -text "Recursion"
		pack .save.c.h.a.spacer .save.c.h.a.cb1 -side left
		button .save.c.i.a.b1 -highlightthickness 0 -text "Upload" -width 8\
		-command {
			set directory [DirMaker \\]
			if {$transfer_sel2 == "5"} {
				set file_path [.save.c.b.a.e1 get]
				if {$file_path == ""} {return}
				set path [string range $file_path 0 [string last "/" $file_path]]
				set p_file [string range $file_path [expr [string last "/" $file_path] + 1] [expr [string length $file_path] - 1]]
				set command_line "cd \"$directory\"; lcd \"$path\"; put \"$p_file\""
				destroy .save
				set fq_type 1
				if {$user_name == "" & $password == ""} {set fq_type "0"}
				FileQueue "\{\{Upload file to //$computer/$share\} \{$file_path\} \{//$computer/$share/[DirMaker /]\} \{(Unknown)\} $fq_type \{$computer\}\
					\{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			} elseif {$transfer_sel2 == "6"} {
				set local_path [.save.c.d.a.e1 get]
				if {$recursion_sel == "no"} {
					set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt; mput *"
				} else {
					set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt; recurse; mput *"
				}
				destroy .save
				set fq_type 1
				if {$user_name == "" & $password == ""} {set fq_type "0"}
				FileQueue "\{\{Upload all to //$computer/$share\} \{$local_path\} \{//$computer/$share/[DirMaker /]\} \{(Unknown)\} $fq_type\
					\{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			} elseif {$transfer_sel2 == "7"} {
				set local_path [.save.c.g.a.e1 get]
				if {[.save.c.g2.e1 get] == ""} {return}
				if {$recursion_sel2 == "no"} {
					set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt; mput [.save.c.g2.e1 get]"
			} else {
				set command_line "cd \"$directory\"; lcd \"$local_path\"; prompt; recurse; mput [.save.c.g2.e1 get]"
			}
			destroy .save
			set fq_type 1
			if {$user_name == "" & $password == ""} {set fq_type "0"}
			FileQueue "\{\{Upload matching to //$computer/$share\} \{$local_path\} \{//$computer/$share/[DirMaker /]\} \{(Unknown)\} $fq_type\
				\{$computer\} \{$share\} \{$computer_ip_num\} \{$user_name\} \{$password\} \{\} \{$workgroup\} \{$command_line\} Queued\}"
			}
		}
		button .save.c.i.a.b2 -highlightthickness 0 -text "Cancel" -width 8\
		-command {
			destroy .save
		}
		pack .save.c.i.a.b1 .save.c.i.a.b2 -side left
		tkwait visibility .save.c.i.a.b2
		if {$where_global == "6"} {
			.save.c.c.rb1 invoke
		} else {
			.save.c.a.rb1 invoke
		}
		if [info exists env(HOME)] {
			set save_to_dir $env(HOME)
		} else {
			set save_to_dir "/"
		}
		bind .save <KeyPress-Return> {.save.c.i.a.b1 invoke}
		bind .save <KeyPress-Escape> {.save.c.i.a.b2 invoke}
	}
	pack .save.a.a.rb1 .save.a.a.rb2 .save.a.a.rb3 -side left
	label .save.b.l1 -anchor w -width 45 -text "Options:"
	pack .save.b.l1 -side left -fill x
	tkwait visibility .save.b.l1
	grab .save
	raise .save .
	if {$where < "4"} {
		.save.a.a.rb1 invoke
	} elseif {$where == "4"} {
		.save.a.a.rb2 invoke
	} else {
		.save.a.a.rb3 invoke
	}
}


proc MakeDir {pathname checkme ask} {
	#######################################################
	global env
	global send_thee
	if {$checkme == "check" & [string range $pathname 0 0] == "~"} {
		set pathname "$env(HOME)[string range $pathname 1 [expr [string length $pathname] - 1]]"
	}
	if {$checkme == "check" & [string range $pathname 0 0] != "/"} {
		set pathname "$env(HOME)/$pathname"
	}
	if {$checkme == "check" & [string range $pathname [expr [string length $pathname] - 1] [expr [string length $pathname] - 1]] == "/"} {
		set pathname [string range $pathname 0 [expr [string length $pathname] - 2]]
	}
	if {[file isdirectory $pathname]} {
		return $pathname
	} elseif {[file exists $pathname]} {
		toplevel .makedir
		wm title .makedir "Non-Directory"
		frame .makedir.label1 -borderwidth 1 -relief sunken
		label .makedir.label1.saveto -text "Error:                       "
		frame .makedir.entry1 -borderwidth 10
		label .makedir.entry1.eg1 -text "Non-directory already exists"
		pack .makedir.label1 -fill x -side top
		pack .makedir.label1.saveto -side left
		pack .makedir.entry1 -side top
		pack .makedir.entry1.eg1 -side top
		frame .makedir.button -borderwidth 10
		button .makedir.button.okay -highlightthickness 0 -text Okay -width 8\
		-command {destroy .makedir}
		pack .makedir.button -side top
		pack .makedir.button.okay -side top
		tkwait visibility .makedir.button.okay
		grab .makedir
		raise .makedir .
		return "get_thee_to_a_nunnery"
	} else {
		set send_thee "go"
		if {$checkme == "check"} {
			if {$ask != "pass"} {
				toplevel .makedir
				wm title .makedir "Directory Does Not Exist"
				frame .makedir.label1 -borderwidth 1 -relief sunken
				label .makedir.label1.saveto -text "Directory Does Not Exist"
				frame .makedir.entry1 -borderwidth 10
				label .makedir.entry1.eg1 -text "Create Directory?"
				pack .makedir.label1 -fill x -side top
				pack .makedir.label1.saveto -side left
				pack .makedir.entry1 -side top
				pack .makedir.entry1.eg1 -side top
				frame .makedir.button -borderwidth 10
				button .makedir.button.yes -highlightthickness 0 -text Yes -width 5\
				-command {destroy .makedir}
				button .makedir.button.no -highlightthickness 0 -text No -width 5\
				-command {set send_thee "exit";destroy .makedir}
				bind .makedir <KeyPress-Return> {.makedir.button.yes invoke}
				bind .makedir <KeyPress-Escape> {.makedir.button.no invoke}
				pack .makedir.button -side top
				pack .makedir.button.yes .makedir.button.no -side left
				tkwait visibility .makedir.button.no
				grab .makedir
				raise .makedir .
				tkwait window .makedir
			}
		}
		if {$send_thee == "exit"} {return "get_thee_to_a_nunnery"}
		MakeDir [file dirname $pathname] "nocheck" ""
		catch [exec mkdir $pathname]
		return $pathname
	}
}


proc AddNetworkDialog {n_index} {
	#####################################################
	global networks_m
	global networks_extra
	global net_index
	set net_index $n_index
	toplevel .addnetworkdialog
	.bottom.network config -state disabled
	if {$n_index == "add"} {
		wm title .addnetworkdialog "Add Network"
	} else {
		wm title .addnetworkdialog "Edit $networks_m($n_index,name)"
	}
	frame .addnetworkdialog.title -borderwidth 1 -relief sunken
	pack .addnetworkdialog.title -fill x -side top
	label .addnetworkdialog.title.words -text "Network Information:"
	pack .addnetworkdialog.title.words -side left
	frame .addnetworkdialog.required -borderwidth 5
	pack .addnetworkdialog.required -side top
	frame .addnetworkdialog.required.op -borderwidth 1
	frame .addnetworkdialog.required.en -borderwidth 1
	pack .addnetworkdialog.required.op .addnetworkdialog.required.en -side left
	frame .addnetworkdialog.required.op.o1 -borderwidth 2
	pack .addnetworkdialog.required.op.o1 -side top -fill x
	label .addnetworkdialog.required.op.o1.n -text "Name:"
	frame .addnetworkdialog.required.en.o1 -borderwidth 2
	pack .addnetworkdialog.required.en.o1 -side top -fill x
	entry .addnetworkdialog.required.en.o1.n -width 20 -foreground black -background white
	pack .addnetworkdialog.required.op.o1.n -side right
	pack .addnetworkdialog.required.en.o1.n -side left
	frame .addnetworkdialog.required.op.o2 -borderwidth 2
	pack .addnetworkdialog.required.op.o2 -side top -fill x
	label .addnetworkdialog.required.op.o2.t -text "Type:"
	frame .addnetworkdialog.required.en.o2 -borderwidth 2
	pack .addnetworkdialog.required.en.o2 -side top -fill x
	radiobutton .addnetworkdialog.required.en.o2.b -text "Broadcast" -variable network_type -relief flat -value broadcast -command {
		NetworkBind "1"
	}
	radiobutton .addnetworkdialog.required.en.o2.w -text "Wins" -variable network_type -relief flat -value wins -command {
		NetworkBind "2"
	}
	radiobutton .addnetworkdialog.required.en.o2.f -text "File Name" -variable network_type -relief flat -value ip_only -command {
		NetworkBind "3"
	}
	pack .addnetworkdialog.required.op.o2.t -side right
	pack .addnetworkdialog.required.en.o2.b .addnetworkdialog.required.en.o2.w .addnetworkdialog.required.en.o2.f -side left
	frame .addnetworkdialog.required.op.o3 -borderwidth 2
	pack .addnetworkdialog.required.op.o3 -side top -fill x
	label .addnetworkdialog.required.op.o3.f -text "Subnet IP:"
	frame .addnetworkdialog.required.en.o3 -borderwidth 2
	pack .addnetworkdialog.required.en.o3 -side top -fill x
	entry .addnetworkdialog.required.en.o3.f -width 15 -foreground black -background white
	button .addnetworkdialog.required.en.o3.b -highlightthickness 0 -width 6\
	-text "Browse" -command {
		set b_choice [tk_getOpenFile -title "Choose File"]
		if {$b_choice != ""} {
			.addnetworkdialog.required.en.o3.f delete 0 1024
			.addnetworkdialog.required.en.o3.f insert 0 $b_choice
		}
	}
	pack .addnetworkdialog.required.op.o3.f -side right
	pack .addnetworkdialog.required.en.o3.f .addnetworkdialog.required.en.o3.b -side left
	frame .addnetworkdialog.required.op.oSW -borderwidth 2
	pack .addnetworkdialog.required.op.oSW -side top -fill x
	label .addnetworkdialog.required.op.oSW.f -text "Secondary Wins:"
	frame .addnetworkdialog.required.en.oSW -borderwidth 2
	pack .addnetworkdialog.required.en.oSW -side top -fill x
	entry .addnetworkdialog.required.en.oSW.f -width 15 -foreground black -background white
	pack .addnetworkdialog.required.op.oSW.f -side right
	pack .addnetworkdialog.required.en.oSW.f -side left
	frame .addnetworkdialog.required.op.o4 -borderwidth 2
	pack .addnetworkdialog.required.op.o4 -side top -fill x
	label .addnetworkdialog.required.op.o4.w -text "         Workgroup:"
	frame .addnetworkdialog.required.en.o4 -borderwidth 2
	pack .addnetworkdialog.required.en.o4 -side top -fill x
	entry .addnetworkdialog.required.en.o4.w -width 15 -foreground black -background white
	pack .addnetworkdialog.required.op.o4.w -side right
	pack .addnetworkdialog.required.en.o4.w -side left
	frame .addnetworkdialog.v -borderwidth 5
	pack .addnetworkdialog.v -fill x -side top
	button .addnetworkdialog.v.b -highlightthickness 0 -width 20\
	-text "Advanced Options" -command {
		AddNetworkAdvanced $net_index
	}
	pack .addnetworkdialog.v.b -side top
	frame .addnetworkdialog.d -borderwidth 5
	pack .addnetworkdialog.d -fill x -side top
	frame .addnetworkdialog.d.w1 -borderwidth 0
	pack .addnetworkdialog.d.w1 -fill x -side top
	label .addnetworkdialog.d.w1.t -borderwidth 0 -text "  In a Broadcast network, computers find the IP of"
	pack .addnetworkdialog.d.w1.t -side left
	frame .addnetworkdialog.d.w2 -borderwidth 0
	pack .addnetworkdialog.d.w2 -fill x -side top
	label .addnetworkdialog.d.w2.t -borderwidth 0 -text "  other computers by sending out a broadcast message."
	pack .addnetworkdialog.d.w2.t -side left
	frame .addnetworkdialog.d.w3 -borderwidth 0
	pack .addnetworkdialog.d.w3 -fill x -side top
	label .addnetworkdialog.d.w3.t -borderwidth 0 -text "  Entering a subnet IP, such as 192.168.0.255 if your"
	pack .addnetworkdialog.d.w3.t -side left
	frame .addnetworkdialog.d.w4 -borderwidth 0
	pack .addnetworkdialog.d.w4 -fill x -side top
	label .addnetworkdialog.d.w4.t -borderwidth 0 -text "  IP was 192.168.0.5, gives access to the computers."
	pack .addnetworkdialog.d.w4.t -side left
	frame .addnetworkdialog.d.w5 -borderwidth 0
	pack .addnetworkdialog.d.w5 -fill x -side top
	label .addnetworkdialog.d.w5.t -borderwidth 0 -text "See the Help Button for further information."
	pack .addnetworkdialog.d.w5.t -side top -fill x
	if {$n_index != "add"} {
		.addnetworkdialog.required.en.o1.n insert 0 $networks_m($n_index,name)
		.addnetworkdialog.required.en.o4.w insert 0 $networks_m($n_index,workgroup)
		if {$networks_m($n_index,net_type) == "broadcast"} {
			.addnetworkdialog.required.en.o2.b invoke
		} elseif {$networks_m($n_index,net_type) == "wins"} {
			.addnetworkdialog.required.en.o2.w invoke
			if [info exists networks_extra($n_index,sec_wins)] {
				.addnetworkdialog.required.en.oSW.f insert 0 $networks_extra($n_index,sec_wins)
			}
		} else {
			.addnetworkdialog.required.en.o2.f invoke
		}
		.addnetworkdialog.required.en.o3.f insert 0 $networks_m($n_index,ip_num)
	} else {
		.addnetworkdialog.required.en.o2.b invoke
	}
	frame .addnetworkdialog.buttons -borderwidth 5
	pack .addnetworkdialog.buttons -side top
	button .addnetworkdialog.buttons.okay -highlightthickness 0 -text Okay -width 8\
	-command {
		if {[.addnetworkdialog.required.en.o1.n get] == ""} {return}
		if {$net_index == "add"} {
			set p [expr 1 + [array size networks_m] / 6]
		} else {
			set p $net_index
		}
		set networks_m($p,name) [.addnetworkdialog.required.en.o1.n get]
		set networks_m($p,workgroup) [.addnetworkdialog.required.en.o4.w get]
		if {$networks_m($p,workgroup) == "" & $network_type != "ip_only"} {
			set networks_m($p,workgroup) "default_samba"
		}
		set networks_m($p,net_type) $network_type
		set networks_m($p,ip_num) [.addnetworkdialog.required.en.o3.f get]
		if {$networks_m($p,ip_num) == "" & $network_type != "ip_only"} {
			set networks_m($p,ip_num) "default_samba"
		}
		if {$network_type == "wins"} {
			if {[.addnetworkdialog.required.en.oSW.f get] != ""} {
				set networks_extra($p,sec_wins) [.addnetworkdialog.required.en.oSW.f get]
			}
		}
		if ![info exists net_advanced_pw] {
			set networks_m($p,password) "defaults"
		} else {
			set networks_m($p,password) $net_advanced_pw
		}
		if ![info exists net_advanced_un] {
			set networks_m($p,user_name) "defaults"
		} else {
			set networks_m($p,user_name) $net_advanced_un
		}
		if [info exists net_advanced_ms] {
			set networks_extra($p,master) $net_advanced_ms
		} else {
			if [info exists networks_extra($p,master)] {unset networks_extra($p,master)}
		}
		if [info exists net_advanced_msip] {
			set networks_extra($p,master_ip) $net_advanced_msip
		} else {
			if [info exists networks_extra($p,master_ip)] {unset networks_extra($p,master_ip)}
		}
		if [info exists net_advanced_wg] {
			set networks_extra($p,wg_static) "no"
		} else {
			if [info exists networks_extra($p,wg_static)] {unset networks_extra($p,wg_static)}
		}
		WriteUserFile
		destroy .addnetworkdialog
		.top.top1.networks invoke
	}
	button .addnetworkdialog.buttons.cancel -highlightthickness 0 -text Cancel -width 8\
	-command {destroy .addnetworkdialog}
	pack .addnetworkdialog.buttons.okay .addnetworkdialog.buttons.cancel -side left
	tkwait visibility .addnetworkdialog
	bind .addnetworkdialog <Destroy> {.bottom.network config -state normal}
	bind .addnetworkdialog <KeyPress-Return> {.addnetworkdialog.buttons.okay invoke}
	bind .addnetworkdialog <KeyPress-Escape> {.addnetworkdialog.buttons.cancel invoke}
}


proc NetworkBind {what} {
	if {$what == "1"} {
		.addnetworkdialog.required.en.o4.w config -state normal -background white
		.addnetworkdialog.required.en.oSW.f config -state disabled -background grey70
		.addnetworkdialog.required.en.o3.b config -state disabled
		.addnetworkdialog.v.b config -state normal
		.addnetworkdialog.required.op.o3.f config -text "Subnet IP:"
		.addnetworkdialog.d.w1.t config -text "  In a Broadcast network, computers find the IP of"
		.addnetworkdialog.d.w2.t config -text "  other computers by sending out a broadcast message."
		.addnetworkdialog.d.w3.t config -text "  Entering a subnet IP, such as 192.168.0.255 if your"
		.addnetworkdialog.d.w4.t config -text "  IP was 192.168.0.5, gives access to the computers."
	} elseif {$what == "2"} {
		.addnetworkdialog.required.en.o4.w config -state normal -background white
		.addnetworkdialog.required.en.oSW.f config -state normal -background white
		.addnetworkdialog.v.b config -state normal
		.addnetworkdialog.required.en.o3.b config -state disabled
		.addnetworkdialog.required.op.o3.f config -text "Primary Wins:"
		.addnetworkdialog.d.w1.t config -text "  A Wins Network consists of computers that query a"
		.addnetworkdialog.d.w2.t config -text "  central Wins Server for the name and IP Address of"
		.addnetworkdialog.d.w3.t config -text "  other computers on the network. By entering the IP"
		.addnetworkdialog.d.w4.t config -text "  of the Wins Server, you can access these computers."
	} else {
		.addnetworkdialog.required.en.o4.w config -state disabled -background grey70
		.addnetworkdialog.required.en.oSW.f config -state disabled -background grey70
		.addnetworkdialog.v.b config -state disabled
		.addnetworkdialog.required.en.o3.b config -state normal
		.addnetworkdialog.required.op.o3.f config -text "File Name:"
		.addnetworkdialog.d.w1.t config -text "  This acts much like an lmhosts file. The file name"
		.addnetworkdialog.d.w2.t config -text "  specified will consist of an IP Address followed"
		.addnetworkdialog.d.w3.t config -text "  by a name (if desired) on each line. The last line"
		.addnetworkdialog.d.w4.t config -text "  of the file must be -1."
	}
}


proc AddNetworkAdvanced {n_index} {
	#####################################################
	global networks_m
	global networks_extra
	global net_index
	global wg_static_sel
	global net_advanced_un
	global net_advanced_pw
	global net_advanced_ms
	global net_advanced_msip
	global net_advanced_wg
	if [info exists netadvanced_un] {
		unset net_advanced_un
	}
	if [info exists netadvanced_pw] {
		unset net_advanced_pw
	}
	if [info exists netadvanced_ms] {
		unset net_advanced_ms
	}
	if [info exists netadvanced_msip] {
		unset net_advanced_msip
	}
	if [info exists netadvanced_wg] {
		unset net_advanced_wg
	}
	set net_index $n_index
	toplevel .addnetadvanced
	.bottom.network config -state disabled
	wm title .addnetadvanced "Advanced Options"
	frame .addnetadvanced.e -borderwidth 1
	pack .addnetadvanced.e -fill x -side top
	frame .addnetadvanced.e.title -borderwidth 1 -relief sunken
	pack .addnetadvanced.e.title -fill x -side top
	label .addnetadvanced.e.title.words -text "Username and Password:"
	pack .addnetadvanced.e.title.words -side left
	frame .addnetadvanced.f -borderwidth 0
	pack .addnetadvanced.f -fill x -side top
	label .addnetadvanced.f.words -borderwidth 0 -text "  The following pair will be used throughout the network."
	frame .addnetadvanced.f2 -borderwidth 0
	pack .addnetadvanced.f2 -fill x -side top
	label .addnetadvanced.f2.words -borderwidth 0 -text "  It is usually best to keep both of these blank."
	pack .addnetadvanced.f.words .addnetadvanced.f2.words -side left
	frame .addnetadvanced.extra -borderwidth 5
	pack .addnetadvanced.extra -side top
	frame .addnetadvanced.extra.op -borderwidth 1
	frame .addnetadvanced.extra.en -borderwidth 1
	pack .addnetadvanced.extra.op .addnetadvanced.extra.en -side left
	frame .addnetadvanced.extra.op.o1 -borderwidth 2
	pack .addnetadvanced.extra.op.o1 -side top -fill x
	label .addnetadvanced.extra.op.o1.un -text "Default Username:"
	frame .addnetadvanced.extra.en.o1 -borderwidth 2
	pack .addnetadvanced.extra.en.o1 -side top -fill x
	entry .addnetadvanced.extra.en.o1.un -width 15 -foreground black -background white
	pack .addnetadvanced.extra.op.o1.un -side right
	pack .addnetadvanced.extra.en.o1.un -side left
	frame .addnetadvanced.extra.op.o2 -borderwidth 2
	pack .addnetadvanced.extra.op.o2 -side top -fill x
	label .addnetadvanced.extra.op.o2.pw -text "Default Password:"
	frame .addnetadvanced.extra.en.o2 -borderwidth 2
	pack .addnetadvanced.extra.en.o2 -side top -fill x
	entry .addnetadvanced.extra.en.o2.pw -show "*" -width 15 -foreground black -background white
	pack .addnetadvanced.extra.op.o2.pw -side right
	pack .addnetadvanced.extra.en.o2.pw -side left
	frame .addnetadvanced.c -borderwidth 1
	pack .addnetadvanced.c -fill x -side top
	frame .addnetadvanced.c.title -borderwidth 1 -relief sunken
	pack .addnetadvanced.c.title -fill x -side top
	label .addnetadvanced.c.title.words -text "Computer List:"
	pack .addnetadvanced.c.title.words -side left
	frame .addnetadvanced.g -borderwidth 0
	pack .addnetadvanced.g -fill x -side top
	label .addnetadvanced.g.words -borderwidth 0 -text "  Specify the name and IP of a computer that has the list "
	frame .addnetadvanced.g2 -borderwidth 0
	pack .addnetadvanced.g2 -fill x -side top
	label .addnetadvanced.g2.words -borderwidth 0 -text "  of the networked computers and workgroups."
	pack .addnetadvanced.g.words .addnetadvanced.g2.words -side left
	frame .addnetadvanced.extrac -borderwidth 5
	pack .addnetadvanced.extrac -side top
	frame .addnetadvanced.extrac.op -borderwidth 1
	frame .addnetadvanced.extrac.en -borderwidth 1
	pack .addnetadvanced.extrac.op .addnetadvanced.extrac.en -side left
	frame .addnetadvanced.extrac.op.o1 -borderwidth 2
	pack .addnetadvanced.extrac.op.o1 -side top -fill x
	label .addnetadvanced.extrac.op.o1.un -text "NetBios Name:"
	frame .addnetadvanced.extrac.en.o1 -borderwidth 2
	pack .addnetadvanced.extrac.en.o1 -side top -fill x
	entry .addnetadvanced.extrac.en.o1.un -width 15 -foreground black -background white
	pack .addnetadvanced.extrac.op.o1.un -side right
	pack .addnetadvanced.extrac.en.o1.un -side left
	frame .addnetadvanced.extrac.op.o2 -borderwidth 2
	pack .addnetadvanced.extrac.op.o2 -side top -fill x
	label .addnetadvanced.extrac.op.o2.pw -text "IP Address:"
	frame .addnetadvanced.extrac.en.o2 -borderwidth 2
	pack .addnetadvanced.extrac.en.o2 -side top -fill x
	entry .addnetadvanced.extrac.en.o2.pw -width 15 -foreground black -background white
	pack .addnetadvanced.extrac.op.o2.pw -side right
	pack .addnetadvanced.extrac.en.o2.pw -side left
	frame .addnetadvanced.wg -borderwidth 1
	pack .addnetadvanced.wg -fill x -side top
	frame .addnetadvanced.wg.title -borderwidth 1 -relief sunken
	pack .addnetadvanced.wg.title -fill x -side top
	label .addnetadvanced.wg.title.words -text "Workgroup Behavior:"
	pack .addnetadvanced.wg.title.words -side left
	frame .addnetadvanced.wg2 -borderwidth 0
	pack .addnetadvanced.wg2 -fill x -side top
	label .addnetadvanced.wg2.words -borderwidth 0 -text "  This option allows for your workgroup to change as "
	frame .addnetadvanced.wg3 -borderwidth 0
	pack .addnetadvanced.wg3 -fill x -side top
	label .addnetadvanced.wg3.words -borderwidth 0 -text "  you enter another. Default is to keep it the same."
	pack .addnetadvanced.wg2.words .addnetadvanced.wg3.words -side left
	frame .addnetadvanced.wg4 -borderwidth 5
	checkbutton .addnetadvanced.wg4.c -onvalue "static" -offvalue "not" -variable wg_static_sel -text "Static Workgroup"
	pack .addnetadvanced.wg4 .addnetadvanced.wg4.c -side top
	frame .addnetadvanced.buttons -borderwidth 5
	pack .addnetadvanced.buttons -side top
	button .addnetadvanced.buttons.okay -highlightthickness 0 -text Okay -width 8\
	-command {
		if {[.addnetadvanced.extra.en.o1.un get] != ""} {
			set net_advanced_un [.addnetadvanced.extra.en.o1.un get]
		}
		if {[.addnetadvanced.extra.en.o2.pw get] != ""} {
			set net_advanced_pw [.addnetadvanced.extra.en.o2.pw get]
		}
		if {[.addnetadvanced.extrac.en.o1.un get] != ""} {
			set net_advanced_ms [.addnetadvanced.extrac.en.o1.un get]
		}
		if {[.addnetadvanced.extrac.en.o2.pw get] != ""} {
			set net_advanced_msip [.addnetadvanced.extrac.en.o2.pw get]
		}
		if {$wg_static_sel == "not"} {
			set net_advanced_wg "no"
		}
		destroy .addnetadvanced
	}
	button .addnetadvanced.buttons.cancel -highlightthickness 0 -text Cancel -width 8\
	-command {destroy .addnetadvanced}
	pack .addnetadvanced.buttons.okay .addnetadvanced.buttons.cancel -side left
	tkwait visibility .addnetadvanced.buttons.cancel
	grab .addnetadvanced
	if {$n_index != "add"} {
		if {$networks_m($n_index,password) != "defaults"} {
			.addnetadvanced.extra.en.o2.pw insert 0 $networks_m($n_index,password)
		}
		if {$networks_m($n_index,user_name) != "defaults"} {
			.addnetadvanced.extra.en.o1.un insert 0 $networks_m($n_index,user_name)
		}
		if [info exists networks_extra($n_index,master)] {
			.addnetadvanced.extrac.en.o1.un insert 0 $networks_extra($n_index,master)
		}
		if [info exists networks_extra($n_index,master_ip)] {
			.addnetadvanced.extrac.en.o2.pw insert 0 $networks_extra($n_index,master_ip)
		}
		if [info exists networks_extra($n_index,wg_static)] {
			.addnetadvanced.wg4.c deselect
		} else {
			.addnetadvanced.wg4.c select
		}
	} else {
		.addnetadvanced.wg4.c select
	}
	bind .addnetadvanced <KeyPress-Return> {.addnetadvanced.buttons.okay invoke}
	bind .addnetadvanced <KeyPress-Escape> {.addnetadvanced.buttons.cancel invoke}
}


proc AddFavDialog {n_index} {
	#####################################################
	global favorites_m
	global favorites_extra
	global wins_ip_num
	global broadcast_subnet
	global fav_index
	global computer
	global workgroup
	global net_type
	global computer_ip_num
	global workgroup
	global user_name
	global password
	set fav_index $n_index
	toplevel .addfavdialog
	.bottom.favorite config -state disabled
	if {$n_index == "add"} {
		wm title .addfavdialog "Add Favorite"
	} else {
		wm title .addfavdialog "Edit $favorites_m($n_index,name)"
	}
	frame .addfavdialog.title -borderwidth 1 -relief sunken
	pack .addfavdialog.title -fill x -side top
	label .addfavdialog.title.words -text "Computer Information:"
	pack .addfavdialog.title.words -side left
	frame .addfavdialog.required -borderwidth 5
	pack .addfavdialog.required -side top
	frame .addfavdialog.required.op -borderwidth 1
	frame .addfavdialog.required.en -borderwidth 1
	pack .addfavdialog.required.op .addfavdialog.required.en -side left
	frame .addfavdialog.required.op.o1 -borderwidth 2
	pack .addfavdialog.required.op.o1 -side top -fill x
	label .addfavdialog.required.op.o1.n -text "Favorite Name:"
	frame .addfavdialog.required.en.o1 -borderwidth 2
	pack .addfavdialog.required.en.o1 -side top -fill x
	entry .addfavdialog.required.en.o1.n -width 20 -foreground black -background white
	pack .addfavdialog.required.op.o1.n -side right
	pack .addfavdialog.required.en.o1.n -side left
	frame .addfavdialog.required.op.o2 -borderwidth 2
	pack .addfavdialog.required.op.o2 -side top -fill x
	label .addfavdialog.required.op.o2.t -text "Type:"
	frame .addfavdialog.required.en.o2 -borderwidth 2
	pack .addfavdialog.required.en.o2 -side top -fill x
	radiobutton .addfavdialog.required.en.o2.b -text "Broadcast" -variable fav_type -relief flat -value broadcast -command {
		FavoriteBind "1"
	}
	radiobutton .addfavdialog.required.en.o2.w -text "Wins" -variable fav_type -relief flat -value wins -command {
		FavoriteBind "2"
	}
	radiobutton .addfavdialog.required.en.o2.f -text "IP Only" -variable fav_type -relief flat -value ip_only -command {
		FavoriteBind "3"
	}
	pack .addfavdialog.required.op.o2.t -side right
	pack .addfavdialog.required.en.o2.b .addfavdialog.required.en.o2.w .addfavdialog.required.en.o2.f -side left
	frame .addfavdialog.required.op.o45 -borderwidth 2
	pack .addfavdialog.required.op.o45 -side top -fill x
	label .addfavdialog.required.op.o45.n -text "NetBios Name:"
	frame .addfavdialog.required.en.o45 -borderwidth 2
	pack .addfavdialog.required.en.o45 -side top -fill x
	entry .addfavdialog.required.en.o45.n -width 20 -foreground black -background white
	pack .addfavdialog.required.op.o45.n -side right
	pack .addfavdialog.required.en.o45.n -side left
	frame .addfavdialog.required.op.o3 -borderwidth 2
	pack .addfavdialog.required.op.o3 -side top -fill x
	label .addfavdialog.required.op.o3.f -text "Subnet IP:"
	frame .addfavdialog.required.en.o3 -borderwidth 2
	pack .addfavdialog.required.en.o3 -side top -fill x
	entry .addfavdialog.required.en.o3.f -width 15 -foreground black -background white
	pack .addfavdialog.required.op.o3.f -side right
	pack .addfavdialog.required.en.o3.f -side left
	frame .addfavdialog.required.op.oSW -borderwidth 2
	pack .addfavdialog.required.op.oSW -side top -fill x
	label .addfavdialog.required.op.oSW.f -text "Secondary Wins:"
	frame .addfavdialog.required.en.oSW -borderwidth 2
	pack .addfavdialog.required.en.oSW -side top -fill x
	entry .addfavdialog.required.en.oSW.f -width 15 -foreground black -background white
	pack .addfavdialog.required.op.oSW.f -side right
	pack .addfavdialog.required.en.oSW.f -side left
	frame .addfavdialog.required.op.o4 -borderwidth 2
	pack .addfavdialog.required.op.o4 -side top -fill x
	label .addfavdialog.required.op.o4.w -text "Workgroup:"
	frame .addfavdialog.required.en.o4 -borderwidth 2
	pack .addfavdialog.required.en.o4 -side top -fill x
	entry .addfavdialog.required.en.o4.w -width 15 -foreground black -background white
	pack .addfavdialog.required.op.o4.w -side right
	pack .addfavdialog.required.en.o4.w -side left
	frame .addfavdialog.required.op.o46 -borderwidth 2
	pack .addfavdialog.required.op.o46 -side top -fill x
	label .addfavdialog.required.op.o46.w -text "Username:"
	frame .addfavdialog.required.en.o46 -borderwidth 2
	pack .addfavdialog.required.en.o46 -side top -fill x
	entry .addfavdialog.required.en.o46.w -width 15 -foreground black -background white
	pack .addfavdialog.required.op.o46.w -side right
	pack .addfavdialog.required.en.o46.w -side left
	frame .addfavdialog.required.op.o47 -borderwidth 2
	pack .addfavdialog.required.op.o47 -side top -fill x
	label .addfavdialog.required.op.o47.w -text "Password:"
	frame .addfavdialog.required.en.o47 -borderwidth 2
	pack .addfavdialog.required.en.o47 -side top -fill x
	entry .addfavdialog.required.en.o47.w -show "*" -width 15 -foreground black -background white
	pack .addfavdialog.required.op.o47.w -side right
	pack .addfavdialog.required.en.o47.w -side left
	if {$n_index != "add"} {
		.addfavdialog.required.en.o1.n insert 0 $favorites_m($n_index,name)
		.addfavdialog.required.en.o3.f insert 0 $favorites_m($n_index,ip_num)
		if {$favorites_m($n_index,net_type) == "broadcast"} {
			.addfavdialog.required.en.o2.b invoke
			.addfavdialog.required.en.o45.n insert 0 $favorites_m($n_index,netbios_des)
			.addfavdialog.required.en.o4.w insert 0 $favorites_m($n_index,workgroup)
		} elseif {$favorites_m($n_index,net_type) == "wins"} {
			.addfavdialog.required.en.o2.w invoke
			.addfavdialog.required.en.o45.n insert 0 $favorites_m($n_index,netbios_des)
			.addfavdialog.required.en.o4.w insert 0 $favorites_m($n_index,workgroup)
			if [info exists favorites_extra($n_index,sec_wins)] {
				.addfavdialog.required.en.oSW.f insert 0 $favorites_extra($n_index,sec_wins)
			}
		} else {
			.addfavdialog.required.en.o2.f invoke
		}
		if {$favorites_m($n_index,user_name) != "defaults"} {
			.addfavdialog.required.en.o46.w insert 0 $favorites_m($n_index,user_name)
		}
		if {$favorites_m($n_index,password) != "defaults"} {
			.addfavdialog.required.en.o47.w insert 0 $favorites_m($n_index,password)
		}
	} else {
		if ![info exists net_type] {
			.addfavdialog.required.en.o2.f invoke
		} else {
			if [info exists computer] {
				.addfavdialog.required.en.o1.n insert 0 $computer
				.addfavdialog.required.en.o45.n insert 0 $computer
			}
			if [info exists workgroup] {
				.addfavdialog.required.en.o4.w insert 0 $workgroup
			}
			if [info exists user_name] {
				.addfavdialog.required.en.o46.w insert 0 $user_name
			}
			if [info exists password] {
				.addfavdialog.required.en.o47.w insert 0 $password
			}
			if {$net_type == "broadcast"} {
				.addfavdialog.required.en.o2.b invoke
			} elseif {$net_type == "wins"} {
				.addfavdialog.required.en.o2.w invoke
			} else {
				.addfavdialog.required.en.o2.f invoke
			}
		}
	}
	frame .addfavdialog.buttons -borderwidth 5
	pack .addfavdialog.buttons -side top
	button .addfavdialog.buttons.okay -highlightthickness 0 -text Okay -width 8\
	-command {
		if {[.addfavdialog.required.en.o1.n get] == ""} {return}
		if {$fav_index == "add"} {
			set p [expr 1 + [array size favorites_m] / 8]
		} else {
			set p $fav_index
		}
		if {$fav_type != "ip_only"} {
			set favorites_m($p,netbios_des) [.addfavdialog.required.en.o45.n get]
			set favorites_m($p,workgroup) [.addfavdialog.required.en.o4.w get]
			if {$fav_type == "wins"} {
				if {[.addfavdialog.required.en.oSW.f get] != ""} {
					set favorites_extra($p,sec_wins) [.addfavdialog.required.en.oSW.f get]
				}
			}
		} else {
			set favorites_m($p,netbios_des) "defaults"
			set favorites_m($p,workgroup) ""
		}
		set favorites_m($p,net_type) $fav_type
		set favorites_m($p,share) "defaults"
		set favorites_m($p,user_name) [.addfavdialog.required.en.o46.w get]
		set favorites_m($p,password) [.addfavdialog.required.en.o47.w get]
		set favorites_m($p,name) [.addfavdialog.required.en.o1.n get]
		set favorites_m($p,ip_num) [.addfavdialog.required.en.o3.f get]
		WriteUserFile
		destroy .addfavdialog
		if {$history_m($place,type) == "favorites"} {HistoryCall 0 local}
	}
	button .addfavdialog.buttons.cancel -highlightthickness 0 -text Cancel -width 8\
	-command {destroy .addfavdialog}
	pack .addfavdialog.buttons.okay .addfavdialog.buttons.cancel -side left
	tkwait visibility .addfavdialog
	bind .addfavdialog <Destroy> {.bottom.favorite config -state normal}
	bind .addfavdialog <KeyPress-Return> {.addfavdialog.buttons.okay invoke}
	bind .addfavdialog <KeyPress-Escape> {.addfavdialog.buttons.cancel invoke}
}


proc FavoriteBind {what} {
	global fav_index
	global broadcast_subnet
	global wins_ip_num
	global computer_ip_num
	global network_sec_wins
	if {$what == "1"} {
		.addfavdialog.required.en.o45.n config -state normal -background white
		.addfavdialog.required.en.o4.w config -state normal -background white
		.addfavdialog.required.en.oSW.f config -state disabled -background grey70
		.addfavdialog.required.op.o3.f config -text "Subnet IP:"
		if {$fav_index == "add"} {
			if [info exists broadcast_subnet] {
				.addfavdialog.required.en.o3.f delete 0 1024
				.addfavdialog.required.en.o3.f insert 0 $broadcast_subnet
			}
		}
	} elseif {$what == "2"} {
		.addfavdialog.required.en.o45.n config -state normal -background white
		.addfavdialog.required.en.o4.w config -state normal -background white
		.addfavdialog.required.en.oSW.f config -state normal -background white
		.addfavdialog.required.op.o3.f config -text "Primary Wins:"
		if {$fav_index == "add"} {
			if [info exists wins_ip_num] {
				.addfavdialog.required.en.o3.f delete 0 1024
				.addfavdialog.required.en.o3.f insert 0 $wins_ip_num
			}
			if [info exists network_sec_wins)] {
				.addfavdialog.required.en.oSW.f delete 0 1024
				.addfavdialog.required.en.oSW.f insert 0 $network_sec_wins
			}
		}
	} else {
		.addfavdialog.required.en.o45.n config -state disabled -background grey70
		.addfavdialog.required.en.o4.w config -state disabled -background grey70
		.addfavdialog.required.en.oSW.f config -state disabled -background grey70
		.addfavdialog.required.op.o3.f config -text "Computer IP:"
		if {$fav_index == "add"} {
			if [info exists computer_ip_num] {
				.addfavdialog.required.en.o3.f delete 0 1024
				.addfavdialog.required.en.o3.f insert 0 $computer_ip_num
			}
		}
	}
}


proc HelpDialog {} {
	#####################################################
	global helpincr
	incr helpincr
	global helpwindow
	set helpwindow ".code$helpincr"
	toplevel $helpwindow
	frame $helpwindow.buttons -borderwidth 2
	pack $helpwindow.buttons -side top -fill x
	button $helpwindow.buttons.ex -highlightthickness 0 -width 11 -text Browsing\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "The following information was found at \n"
		$helpwindow.text.area insert end "http://www.cisco.com/warp/public/473/winnt_dg.htm, so I \n"
		$helpwindow.text.area insert end "didnt' write this stuff. Any comments I make are \n"
		$helpwindow.text.area insert end "denoted by \"**\". This document is meant to give an\n"
		$helpwindow.text.area insert end "overview of how xSMBrowser works so you can better\n"
		$helpwindow.text.area insert end "diagnose any problem encountered.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Introduction\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "The term \"networking\" covers a broad range of \n"
		$helpwindow.text.area insert end "technologies, which, combined together, allow \n"
		$helpwindow.text.area insert end "computers to share information. Networking components \n"
		$helpwindow.text.area insert end "can be segmented into end-system applications, network \n"
		$helpwindow.text.area insert end "operating systems, and networking equipment.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "A network operating system is software run on all \n"
		$helpwindow.text.area insert end "interconnected systems. Examples include Novell \n"
		$helpwindow.text.area insert end "NetWare, Sun's NFS (Network File System), AppleShare, \n"
		$helpwindow.text.area insert end "and Microsoft's implementation of a network operating \n"
		$helpwindow.text.area insert end "system commonly called Windows Networking. Windows \n"
		$helpwindow.text.area insert end "Networking is now extensively deployed with millions \n"
		$helpwindow.text.area insert end "of nodes.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "This design guide explains the basic concepts of \n"
		$helpwindow.text.area insert end "Windows Networking and provides insight on how to \n"
		$helpwindow.text.area insert end "design networks (LANs and WANs) to best utilize this \n"
		$helpwindow.text.area insert end "operating system. The guide also explains protocols, \n"
		$helpwindow.text.area insert end "naming, and scaling issues associated with Windows \n"
		$helpwindow.text.area insert end "Networking.\n"
		$helpwindow.text.area insert end "** Most \"design\" aspects have been deleted from this \n"
		$helpwindow.text.area insert end "document\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Domains versus Workgroups\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Windows Networking has three concepts of a group of \n"
		$helpwindow.text.area insert end "related computers- workgroups, domains and a domain \n"
		$helpwindow.text.area insert end "hierarchy. Workgroups can be any logical collection of \n"
		$helpwindow.text.area insert end "computers; any computer on the network can join an \n"
		$helpwindow.text.area insert end "existing workgroup or create a new one. More formal \n"
		$helpwindow.text.area insert end "entities, domains are created and managed by a primary \n"
		$helpwindow.text.area insert end "domain controller (PDC) process that runs on a Windows \n"
		$helpwindow.text.area insert end "NT or Windows 2000 server. A domain has security and \n"
		$helpwindow.text.area insert end "administrative properties that a workgroup does not. \n"
		$helpwindow.text.area insert end "Each domain must have at least one NT or 2000 server, \n"
		$helpwindow.text.area insert end "which is responsible for the PDC process, user account \n"
		$helpwindow.text.area insert end "information in the domain, and security within the \n"
		$helpwindow.text.area insert end "domain. Windows Networking domains are not the same as \n"
		$helpwindow.text.area insert end "Internet domain names as used by the Domain Name \n"
		$helpwindow.text.area insert end "System (DNS).\n"
		$helpwindow.text.area insert end "** For future reference, this document leaves Samba \n"
		$helpwindow.text.area insert end "out in the cold, even though it can do most of these \n"
		$helpwindow.text.area insert end "tasks.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Name Resolution\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Name resolution is the process of associating a \n"
		$helpwindow.text.area insert end "convenient name, such as FRED or fred.domain.com, with \n"
		$helpwindow.text.area insert end "a network address (often an IP address). For present \n"
		$helpwindow.text.area insert end "purposes, this discussion applies to the way that \n"
		$helpwindow.text.area insert end "Windows Networking resolves a NetBIOS unique \n"
		$helpwindow.text.area insert end "workstation name to an IP address. This process should \n"
		$helpwindow.text.area insert end "not be confused with the related but different process \n"
		$helpwindow.text.area insert end "of browsing (which uses other types of NetBIOS names). \n"
		$helpwindow.text.area insert end "Windows Networking clients can use the following \n"
		$helpwindow.text.area insert end "methods of name resolution:\n"
		$helpwindow.text.area insert end " IP Subnet Broadcasts \n"
		$helpwindow.text.area insert end " LMHOSTS \n"
		$helpwindow.text.area insert end " WINS \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "IP Subnet Broadcasts\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "IP subnet broadcasts can be used for name resolution. \n"
		$helpwindow.text.area insert end "Broadcasts are received by all computers on a subnet, \n"
		$helpwindow.text.area insert end "requiring processing time at each computer. Windows \n"
		$helpwindow.text.area insert end "Networking also maintains a designated browse master \n"
		$helpwindow.text.area insert end "that maintains a list of all resources available on a \n"
		$helpwindow.text.area insert end "subnet. An election process that uses broadcasts \n"
		$helpwindow.text.area insert end "determines this browse master because registrations, \n"
		$helpwindow.text.area insert end "browser elections, and name queries could all generate \n"
		$helpwindow.text.area insert end "broadcasts, use of the broadcast name resolution \n"
		$helpwindow.text.area insert end "method is not recommended. \n"
		$helpwindow.text.area insert end "** Don't worry, broadcast is just fine for small \n"
		$helpwindow.text.area insert end "networks\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "LMHOSTS\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Windows Networking can consult a static table in a \n"
		$helpwindow.text.area insert end "file called LMHOSTS. To use this method, the PDC \n"
		$helpwindow.text.area insert end "should maintain at the least a static list of all \n"
		$helpwindow.text.area insert end "computers and their IP addresses in that domain and \n"
		$helpwindow.text.area insert end "the names and addresses of the PDCs for all other \n"
		$helpwindow.text.area insert end "domains in the network. All clients must then have an \n"
		$helpwindow.text.area insert end "LMHOSTS file with the IP address of their PDC and the \n"
		$helpwindow.text.area insert end "path to the master LMHOSTS file on the PDC.\n"
		$helpwindow.text.area insert end "** Samba's lmhost file is usually at /etc/lmhosts\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Windows Internet Name Service\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "WINS was created to allow clients on different IP \n"
		$helpwindow.text.area insert end "subnets to dynamically resolve addresses, register \n"
		$helpwindow.text.area insert end "themselves, and browse the network without sending \n"
		$helpwindow.text.area insert end "broadcasts. Clients send unicast packets to the WINS \n"
		$helpwindow.text.area insert end "server at a well-known address. For compatibility with \n"
		$helpwindow.text.area insert end "older Microsoft Networking clients, however, broadcast \n"
		$helpwindow.text.area insert end "name resolution is still turned on by default, even \n"
		$helpwindow.text.area insert end "when WINS is also configured.\n"
		$helpwindow.text.area insert end "** Which can make broadcast a good choice for small or \n"
		$helpwindow.text.area insert end "home networks\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "To repeat what was stated above, it is highly \n"
		$helpwindow.text.area insert end "recommended for optimum network performance to use \n"
		$helpwindow.text.area insert end "WINS. Again, there is a direct correlation between the \n"
		$helpwindow.text.area insert end "number of broadcasts in a network and network \n"
		$helpwindow.text.area insert end "performance; broadcasts are necessary for a network to \n"
		$helpwindow.text.area insert end "function, but minimizing them can be critical. \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Name Lookup Order\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Windows networking components sends name resolution \n"
		$helpwindow.text.area insert end "queries in a different order, depending on the NetBIOS \n"
		$helpwindow.text.area insert end "node type. If the system is Windows NT 4.0 and the \n"
		$helpwindow.text.area insert end "name is longer than 15 characters, then Windows NT \n"
		$helpwindow.text.area insert end "sends only a DNS query. Other networking components \n"
		$helpwindow.text.area insert end "and services may also use a different order depending \n"
		$helpwindow.text.area insert end "upon the API called to perform name resolution. \n"
		$helpwindow.text.area insert end "Otherwise name lookup is performed in the following \n"
		$helpwindow.text.area insert end "order:\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end " Check the NetBIOS name cache. \n"
		$helpwindow.text.area insert end " Send a broadcast query or a WINS query name, \n"
		$helpwindow.text.area insert end "  depending on the current NetBIOS node type. \n"
		$helpwindow.text.area insert end " Check the LMHOSTS file. \n"
		$helpwindow.text.area insert end " Check the HOSTS file (if \"resolve using DNS\" is \n"
		$helpwindow.text.area insert end "  checked). \n"
		$helpwindow.text.area insert end " Send an Internet DNS query (if resolve using DNS is \n"
		$helpwindow.text.area insert end "  checked). \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "** Samba can also follow a name lookup order that can \n"
		$helpwindow.text.area insert end "be specified in its config. xSMBrowser supports \n"
		$helpwindow.text.area insert end "sending broadcast or WINS queries directly instead of \n"
		$helpwindow.text.area insert end "having an implied order. This speeds things up and \n"
		$helpwindow.text.area insert end "allows for easier debugging of network troubles.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "NetBIOS Names\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "NetBIOS names are 15-character, uppercase names that \n"
		$helpwindow.text.area insert end "have a special identifier added to the 16th byte. As \n"
		$helpwindow.text.area insert end "well, NetBIOS names can apply to a single IP address \n"
		$helpwindow.text.area insert end "(unique), or to more than one (group). Some name types \n"
		$helpwindow.text.area insert end "can be either unique or group names. Some of the most \n"
		$helpwindow.text.area insert end "common of these last characters are listed as follows \n"
		$helpwindow.text.area insert end "(all values are in hexadecimal): \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "\<COMPUTER>\<00> This is the computer name registered \n"
		$helpwindow.text.area insert end "for workstation services by a WINS client. \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "\<DOMAIN>\<1b> Used to identify the domain master \n"
		$helpwindow.text.area insert end "browser name, which is a unique name that only the \n"
		$helpwindow.text.area insert end "primary domain controller (PDC) can add. The PDC \n"
		$helpwindow.text.area insert end "processes GetBrowserServerList requests on this name. \n"
		$helpwindow.text.area insert end "WINS assumes that the computer that registers a domain \n"
		$helpwindow.text.area insert end "name with the \<1b> character is the PDC.\n"
		$helpwindow.text.area insert end "** xSMBrowser uses \"smbclient -R -U \<ip of WINS> \n"
		$helpwindow.text.area insert end "DOMAIN#1B\" to find the PDC in WINS networks.  \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "\<DOMAIN>\<1d> Used to identify a master browser (not a \n"
		$helpwindow.text.area insert end "domain master browser). The master browser adds this \n"
		$helpwindow.text.area insert end "name as a unique NetBIOS name when it starts. \n"
		$helpwindow.text.area insert end "Workstations announce their presence to this name so \n"
		$helpwindow.text.area insert end "that master browsers can build their browse list. For \n"
		$helpwindow.text.area insert end "workgroups, this name has the form \<WORKGROUP>\<1d>.\n"
		$helpwindow.text.area insert end "** These are sort of like PDCs for broadcast networks. \n"
		$helpwindow.text.area insert end "xSMBrowser uses \"smbclient -M WORKGROUP\" to find these \n"
		$helpwindow.text.area insert end "in broadcast networks.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Viewing the Network Neighborhood\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When a user opens the network neighborhood to request \n"
		$helpwindow.text.area insert end "a list of domains, the system will attempt to get a \n"
		$helpwindow.text.area insert end "list of backup browsers, either through broadcasting \n"
		$helpwindow.text.area insert end "to the master browser name, or directly connecting to \n"
		$helpwindow.text.area insert end "the domain master browser (or both). Once a list of \n"
		$helpwindow.text.area insert end "backup browsers is retrieved, the system will choose a \n"
		$helpwindow.text.area insert end "backup browser, connect to that system and retrieve \n"
		$helpwindow.text.area insert end "the list of domains. Subsequent requests for servers \n"
		$helpwindow.text.area insert end "within a domain are forwarded to the same backup \n"
		$helpwindow.text.area insert end "browser.\n"
		$helpwindow.text.area insert end "** Unlike Network Neighborhood, xSMBrowser doesn't do \n"
		$helpwindow.text.area insert end "anything when it first starts. Instead, xSMBrowser \n"
		$helpwindow.text.area insert end "waits for the user to click on one of the defined \n"
		$helpwindow.text.area insert end "networks. It then finds the PDC (WINS) or Master \n"
		$helpwindow.text.area insert end "Browser (broadcast) and retrieves the list of \n"
		$helpwindow.text.area insert end "computers.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Subnet Browsing\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "In the 1980s, most networks were \"flat,\" or had only a \n"
		$helpwindow.text.area insert end "few subnets. NetBEUI and NWLink use this model, and IP \n"
		$helpwindow.text.area insert end "broadcasts can be bridged or helped across a small \n"
		$helpwindow.text.area insert end "number of subnets. The following discussion assumes \n"
		$helpwindow.text.area insert end "the case of a flat network.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Each subnet has a subnet master browser per domain or \n"
		$helpwindow.text.area insert end "workgroup and may have some subnet backup browsers \n"
		$helpwindow.text.area insert end "(also per domain or workgroup). After bootup, backup \n"
		$helpwindow.text.area insert end "browsers and nonbrowsers send broadcast announcements \n"
		$helpwindow.text.area insert end "at increasing intervals of 1, 2, 4, and 8 minutes; \n"
		$helpwindow.text.area insert end "they eventually broadcast announcements only every 12 \n"
		$helpwindow.text.area insert end "minutes. Subnet master browsers listen to these \n"
		$helpwindow.text.area insert end "announcements to build a browse list. \n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Subnet master browsers and backup browsers are \n"
		$helpwindow.text.area insert end "responsible for answering browse queries from other \n"
		$helpwindow.text.area insert end "computers. Master browsers can answer these requests \n"
		$helpwindow.text.area insert end "directly from the browse list. Backup browsers also \n"
		$helpwindow.text.area insert end "keep a browse list, which they request from the subnet \n"
		$helpwindow.text.area insert end "master browser every 15 minutes.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Broadcast Browsing across Subnets\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "In reality, most networks today have several subnets. \n"
		$helpwindow.text.area insert end "Domains often span subnets and subnets sometimes \n"
		$helpwindow.text.area insert end "contain systems in more than one domain. The browser \n"
		$helpwindow.text.area insert end "software on some systems can communicate with a domain \n"
		$helpwindow.text.area insert end "master browser (usually the PDC) to exchange browse \n"
		$helpwindow.text.area insert end "lists from many subnets, but it needs to know the \n"
		$helpwindow.text.area insert end "unicast address of the domain master browser. A subnet \n"
		$helpwindow.text.area insert end "master browser can get the unicast address of the PDC \n"
		$helpwindow.text.area insert end "from an LMHOSTS file (for a detailed description, see \n"
		$helpwindow.text.area insert end "the Name Resolution section) or from WINS (see next \n"
		$helpwindow.text.area insert end "section).\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Important note: Because of a bug in some versions of \n"
		$helpwindow.text.area insert end "Windows for Workgroups 3.11 and Windows 95, these \n"
		$helpwindow.text.area insert end "systems cannot function as a subnet master browser or \n"
		$helpwindow.text.area insert end "backup browser. The bug prevents the subnet browser \n"
		$helpwindow.text.area insert end "from contacting the domain master browser. This bug \n"
		$helpwindow.text.area insert end "has been fixed in Windows 95 OSR (OEM Service Release) \n"
		$helpwindow.text.area insert end "2. As a result, browsing on the subnet fails if there \n"
		$helpwindow.text.area insert end "are Win31 or Win95 master or backup browsers on the \n"
		$helpwindow.text.area insert end "subnet.\n"
		$helpwindow.text.area insert end "** This affects Samba too! If you have 95 clients in \n"
		$helpwindow.text.area insert end "your network, either upgrade or make sure Samba \n"
		$helpwindow.text.area insert end "becomes the master browser.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Browsing Any Domain with WINS\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "In an organization with several domains, it is not \n"
		$helpwindow.text.area insert end "reasonable to architect a network based on the \n"
		$helpwindow.text.area insert end "restrictions outlined in the previous section. When \n"
		$helpwindow.text.area insert end "WINS is running, the subnet browser can be a WINS \n"
		$helpwindow.text.area insert end "client and can get the unicast IP address of the \n"
		$helpwindow.text.area insert end "domain master browser (the PDC) for any domain. \n"
		$helpwindow.text.area insert end "However, broadcasts are still sent frequently and \n"
		$helpwindow.text.area insert end "repeatedly by default (see table describing WINS node \n"
		$helpwindow.text.area insert end "types in the following section) on the chance that \n"
		$helpwindow.text.area insert end "there may be some non-WINS clients on the subnet. The \n"
		$helpwindow.text.area insert end "best solution in most networks is to turn off \n"
		$helpwindow.text.area insert end "broadcast browsing.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Copyright 1992--2001 Cisco Systems Inc.\n"
	}
	button $helpwindow.buttons.o -highlightthickness 0 -width 11 -text FAQ\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "Frequently Asked Questions\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "NOTE: I will not address networking problems with Samba! DO NOT send me\n"
		$helpwindow.text.area insert end "an email saying \"My network is not working\" or \"Program reports that it\n"
		$helpwindow.text.area insert end "can't find the Master Browser\". These are generally Samba or network problems,\n"
		$helpwindow.text.area insert end "and you should fix them on your own by consulting the Samba documentation.\n"
		$helpwindow.text.area insert end "Sorry, but problems associated with setting up a network are too numerous,\n"
		$helpwindow.text.area insert end "and I do not have time to answer every email.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "chadspen@iastate.edu\n"
		$helpwindow.text.area insert end "http://www.public.iastate.edu/~chadspen\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "What is xSMBrowser?\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "xSMBrowser is the Linux equivalent of Windows' Network Neighborhood.\n"
		$helpwindow.text.area insert end "That is, its used to browse the shares and files of computers using the SMB or\n"
		$helpwindow.text.area insert end "CIFS protocols. xSMBrowser does this by placing a GUI over Samba's smbclient\n"
		$helpwindow.text.area insert end "and nmblookup commands.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "What is \"Samba Config\" network ... never saw this in Neighborhood?\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Most users of xSMBrowser expect to see workgroups or computers when they\n"
		$helpwindow.text.area insert end "first start. xSMBrowser is different because it allows users to define their\n"
		$helpwindow.text.area insert end "own networks that need not correspond to Samba defaults. If your Samba\n"
		$helpwindow.text.area insert end "is correctly set up, clicking on \"Samba Config\" will retrieve the list of\n"
		$helpwindow.text.area insert end "computers in your workgroup or domain.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Why is defining alternate networks useful? Personally, I find it useful because\n"
		$helpwindow.text.area insert end "I can define my home (2 computers, broadcast) and my school's (1000+ computers,\n"
		$helpwindow.text.area insert end "WINS) separately. I can even define different workgroups for both and have\n"
		$helpwindow.text.area insert end "different user names. I am not saying such a task is impossible in Windows, but\n"
		$helpwindow.text.area insert end "it certainly is not straightforward.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "How do I see my simple home network?\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Okay, so you want your Unix machine to communicate in your home network\n"
		$helpwindow.text.area insert end "with some Windows machines that have \"Client of Microsoft Networks\"\n"
		$helpwindow.text.area insert end "enabled. You know your Unix can talk to the other computers because you\n"
		$helpwindow.text.area insert end "have tested it with ping. All of your computers in your network have similar\n"
		$helpwindow.text.area insert end "IP numbers (e.g. 192.168.0.xxx). And you know what the name of your common\n"
		$helpwindow.text.area insert end "workgroup should be (e.g. MYGROUP). Perhaps you even tested and were\n"
		$helpwindow.text.area insert end "successful with using the smbclient or nmblookup commands.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "However, you clicked on \"Samba Config\" and nothing happened. So, what\n"
		$helpwindow.text.area insert end "is xSMBrowser trying to do, and why is it failing?\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "As mentioned before, it is trying to retrieve the list of computers from your\n"
		$helpwindow.text.area insert end "workgroup or domian. To find this list, it must be able to find the computer\n"
		$helpwindow.text.area insert end "with the list, called the Master Browser (assuming simple broadcast network).\n"
		$helpwindow.text.area insert end "When it is unable to do so, two things should be double-checked:\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "1. Set up Samba\n"
		$helpwindow.text.area insert end "First, is Samba running (check that smbd and nmbd are running)? Second,\n"
		$helpwindow.text.area insert end "are there any special settings used by the other computers in the network that\n"
		$helpwindow.text.area insert end "Samba should follow? Using a Samba configuration package, such as SWAT,\n"
		$helpwindow.text.area insert end "should make setting up Samba easier.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "2. Use \"+ Network\" button\n"
		$helpwindow.text.area insert end "Once Samba is working 100%, using the \"+ Network\" button will add the\n"
		$helpwindow.text.area insert end "settings that xSMBrowser needs to know in order to browse your network.\n"
		$helpwindow.text.area insert end "All options are explained in the \"+ Network\" portion of Help.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Reports \"spawn nmblookup\", smbmount, or smbclient commands not found\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "These commands must be in your \"PATH\" variable. To see the value of your\n"
		$helpwindow.text.area insert end "current PATH, issue:\n"
		$helpwindow.text.area insert end "> echo \$PATH\n"
		$helpwindow.text.area insert end "If the path of smbmount is /usr/local/samba/sbin, you can add it to your\n"
		$helpwindow.text.area insert end "path with either:\n"
		$helpwindow.text.area insert end "> PATH=\$PATH:/usr/local/samba/sbin             (modern linux)\n"
		$helpwindow.text.area insert end "> export PATH\n"
		$helpwindow.text.area insert end " or\n"
		$helpwindow.text.area insert end "> setenv PATH \$PATH:/usr/local/samba/sbin      (old way)\n"
		$helpwindow.text.area insert end "Consider adding these commands to your startup script, such as\n"
		$helpwindow.text.area insert end "\"~/.bash_profile\" or \"~/.login\".\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Reports smbmount access right error\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "For non-root users, smbmount should be given the \"+s\" bit to function.\n"
		$helpwindow.text.area insert end "Issuing the command \"chmod +s /usr/sbin/smbmount\" as root should fix\n"
		$helpwindow.text.area insert end "the problem.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "What happened to the pictures and icons?\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "All of the bitmaps are stored in a seperate directory. For instance,\n"
		$helpwindow.text.area insert end "if you downloaded the RPM, they should be in /usr/share/pixmaps/xsmbrowser.\n"
		$helpwindow.text.area insert end "Go into xSMBrowser's setup and specify the \"Image Path\".\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Has \"tk_getOpenFile\" or other tk_** error.\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Some distributions of Tcl/Tk don't offer certain features. You should try\n"
		$helpwindow.text.area insert end "upgrading to a more recent version. Also, be sure that expectk is\n"
		$helpwindow.text.area insert end "compiled correctly so to incorporate all of the latest tk features.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Can browse everything, but mounting doesn't work.\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Go into setup, and be sure you have the correct smbmount version. This\n"
		$helpwindow.text.area insert end "should fix the problem.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Computer with name \"-XXXX-\" doesn't resolve right.\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Currently, computer netbios names that begin with a dash do not resolve\n"
		$helpwindow.text.area insert end "correctly (putting a \\ in front of character fails also). Other names with\n"
		$helpwindow.text.area insert end "weird characters have problems as well.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Deleting Folders\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Even with recurse turned on, it seems to be impossible to delete non-empty\n"
		$helpwindow.text.area insert end "folders with smbclient. If you need to delete a lot of data, you should try\n"
		$helpwindow.text.area insert end "mounting the share instead.\n"
	}
	button $helpwindow.buttons.gen -highlightthickness 0 -width 11 -text Features\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "Features\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "   I.  Introduction\n"
		$helpwindow.text.area insert end "  II.  Favorites\n"
		$helpwindow.text.area insert end " III.  Mount History\n"
		$helpwindow.text.area insert end "  IV.  File Queue\n"
		$helpwindow.text.area insert end "   V.  Adding Commands\n"
		$helpwindow.text.area insert end "  VI.  Power Transfers\n"
		$helpwindow.text.area insert end " VII.  Explore Button\n"
		$helpwindow.text.area insert end "VIII.  Internet Links\n"
		$helpwindow.text.area insert end "  IX.  Find File\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "I. Introduction\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "The following explains the uses of xSMBrowser's various features. Most of\n"
		$helpwindow.text.area insert end "which you will learn simply by using xSMBrowser enough, but are mentioned\n"
		$helpwindow.text.area insert end "here to give a head start.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "II. Favorites\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "The most common way to add a favorite is to simply visit the computer and\n"
		$helpwindow.text.area insert end "press the \"+ Favorite\" button. The values used to access the computer\n"
		$helpwindow.text.area insert end "should already be pre-entered. Favorites can also be added manually if\n"
		$helpwindow.text.area insert end "you know enough information about the computer, such as netbios name,\n"
		$helpwindow.text.area insert end "workgroup, and ip address. Existing favorites can be edited by\n"
		$helpwindow.text.area insert end "right-clicking them.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "III. Mount History\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When a mount is made, it is automatically added to the \"mount\n"
		$helpwindow.text.area insert end "history\". Items recorded in the mount history can be remounted at any\n"
		$helpwindow.text.area insert end "time. This becomes useful when you have a common set of computers that\n"
		$helpwindow.text.area insert end "you often mount. Then, the \"Mount All\" button can be used to remount\n"
		$helpwindow.text.area insert end "all of your network drives.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "IV. File Queue\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When saving or uploading files, the operation is \"queued\" in the File\n"
		$helpwindow.text.area insert end "Queue dialog. For etherneted computers, this probably just flashes by\n"
		$helpwindow.text.area insert end "since downloads take seconds, but users with slower connections may find\n"
		$helpwindow.text.area insert end "this useful. The operation of the File Queue is pretty\n"
		$helpwindow.text.area insert end "self-explanatory. Any transfers in which errors occur are recorded and\n"
		$helpwindow.text.area insert end "can be \"requeued\". Also, if you exit the program with items still in the\n"
		$helpwindow.text.area insert end "queue, they will be remembered next time you start xSMBrowser.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "V. Adding Commands\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When viewing files, double-clicking the files quickly downloads them to a\n"
		$helpwindow.text.area insert end "temporary directory (~/.xsmbrowser/xsmbrowser-temp), then prompts for a command to\n"
		$helpwindow.text.area insert end "which the file can be opened (such as Gimp). By pressing the Commands\n"
		$helpwindow.text.area insert end "button in Setup, you can add preset commands to certain file types. For\n"
		$helpwindow.text.area insert end "example, I could setup Gimp to open \".JPG .GIF .BMP\" files.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Just remember, when xSMBrowser matches a command to a file-type, it\n"
		$helpwindow.text.area insert end "chooses the first entry, so file-type order is important.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "VI. Power Transfers\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When you usually transfer files to and from shares, the operation is\n"
		$helpwindow.text.area insert end "quite simple. For instance, you might upload an individual file or\n"
		$helpwindow.text.area insert end "download some selected files (files can be selected by drawing boxes or\n"
		$helpwindow.text.area insert end "using the shift and ctrl keys). Sometimes, however, more advanced\n"
		$helpwindow.text.area insert end "transfers, such as file patters (*.gif), full directory uploads, or\n"
		$helpwindow.text.area insert end "directory tars may be desired. For these, you can use the power transfer\n"
		$helpwindow.text.area insert end "button.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "VII. Explore Button\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "The explore button is simply a fast and easy way to mount and explore\n"
		$helpwindow.text.area insert end "shares. The default \"mount point\", samba version, and explore command can\n"
		$helpwindow.text.area insert end "be set in setup. For instance, lets say that I'm viewing the files in a\n"
		$helpwindow.text.area insert end "share called \"DOE\" on a computer called \"JOHN\". Lets also say that I set\n"
		$helpwindow.text.area insert end "my default mount point to \"\$HOME/mnt\" and my explore command to\n"
		$helpwindow.text.area insert end "\"kfmclient folder \$MOUNTPOINT\" (KDE application). If I press the explore\n"
		$helpwindow.text.area insert end "button, it would mount DOE to /home/chadspen/mnt/JOHN/DOE and execute the\n"
		$helpwindow.text.area insert end "command \"kfmclient folder /home/chadspen/mnt/JOHN/DOE\". Note also that if\n"
		$helpwindow.text.area insert end "I use the explore button with a share that is already mounted, it will\n"
		$helpwindow.text.area insert end "not attempt to remount, but simply execute the explore command.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "VIII. Internet Links\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "In Windows, Internet Explorer 5.0 can access links of the form\n"
		$helpwindow.text.area insert end "\"file:\\\\COMPUTER\\SHARE\\FOLDERFILE\\\". Netscape currently has no support\n"
		$helpwindow.text.area insert end "for this, and more and more people use this to provide links to\n"
		$helpwindow.text.area insert end "computers.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "xSMBrowser allows users to use these links. This feature can be seen \n"
		$helpwindow.text.area insert end "by right clicking the main window and choosing \"Internet Link\". Users can\n"
		$helpwindow.text.area insert end "use the \"Copy Link Location\" option from Netscape, and then paste that\n"
		$helpwindow.text.area insert end "link into the \"Internet Link\" dialog of xSMBrowser.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "IX. Find File\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When viewing hundreds of files, you often want to search for one matching\n"
		$helpwindow.text.area insert end "some pattern. This right-click menu feature allows you to search for\n"
		$helpwindow.text.area insert end "files and folders matching your pattern in the current directory.\n"
	}
	button $helpwindow.buttons.ad -highlightthickness 0 -width 11 -text Admin\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "Admin Guide\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "  I.  Introduction\n"
		$helpwindow.text.area insert end " II.  Global Files\n"
		$helpwindow.text.area insert end "      a) Config\n"
		$helpwindow.text.area insert end "      b) Networks\n"
		$helpwindow.text.area insert end "      c) Favorites\n"
		$helpwindow.text.area insert end "      d) Commands\n"
		$helpwindow.text.area insert end "III.  Networking Ideas\n"
		$helpwindow.text.area insert end "      a) Using Favorites\n"
		$helpwindow.text.area insert end "      b) Master Browsers\n"
		$helpwindow.text.area insert end "      c) Multiple Networks\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "I. Introduction\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "The purpose of this document is to give system administrators an idea of\n"
		$helpwindow.text.area insert end "how to integrate xSMBrowser into an environment with multiple users.\n"
		$helpwindow.text.area insert end "Also, ideas are given about how to make your network more robust.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "II. Global Files\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When xSMBrowser is first started, it creates four important files in the\n"
		$helpwindow.text.area insert end "home directory: \".xsmbrowser-config\", \".xsmbrowser-networks\",\n"
		$helpwindow.text.area insert end "\".xsmbrowser-favorites\", and \".xsmbrowser-commands\". These files can be\n"
		$helpwindow.text.area insert end "made global to all users by placing them in the /etc directory (minus the\n"
		$helpwindow.text.area insert end "period, e.g. \"~/.xsmbrowser/xsmbrowser-config\" --> \"/etc/xsmbrowser/xsmbrowser-config\"). When\n"
		$helpwindow.text.area insert end "xSMBrowser starts, it will read both files in /etc and ~, but definitions\n"
		$helpwindow.text.area insert end "in /etc take precedence. To get the most flexibility from this, the\n"
		$helpwindow.text.area insert end "following should be carefully read.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "a) Config\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "The .xsmbrowser-config file contains various setup settings. Looking at\n"
		$helpwindow.text.area insert end "this file, the most important settings are as follows.\n"
		$helpwindow.text.area insert end " Image Path = /usr/share/pixmaps/xsmbrowser\n"
		$helpwindow.text.area insert end " Smbmount = yes 1\n"
		$helpwindow.text.area insert end " Execute = kfmclient folder \$MOUNTPOINT\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "The other values in .xsmbrowser-config can be customized by the user. You\n"
		$helpwindow.text.area insert end "might even allow users to customize Execute.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "b) Networks\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "This is the config file that usually gets the most attention. Networks\n"
		$helpwindow.text.area insert end "defined in /etc will appear before user-defined networks in xSMBrowser's\n"
		$helpwindow.text.area insert end "main screen. Networks can generally be transfered strait over to /etc,\n"
		$helpwindow.text.area insert end "just make sure to rid of any passwords.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "c) Favorites\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Favorites can also be defined globally. One could put commonly accessed\n"
		$helpwindow.text.area insert end "computers here. Again, make sure there are not any passwords still\n"
		$helpwindow.text.area insert end "present in /etc/xsmbrowser/xsmbrowser-favorites after copying it over.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "d) Commands\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Instead of making users scour for programs, one could enter some of the\n"
		$helpwindow.text.area insert end "more common programs in the /etc/xsmbrowser/xsmbrowser-commands file.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "III. Networking Ideas\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Netbios networks are well-known for their inconsistencies. Ideally, they\n"
		$helpwindow.text.area insert end "would work quite smoothly, with their backup masters and other features,\n"
		$helpwindow.text.area insert end "but nothing is ideal. Users are often left stranded--not being able to\n"
		$helpwindow.text.area insert end "connect to the network.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "To combat this, administrators should first try to tweak settings in\n"
		$helpwindow.text.area insert end "Samba and Windows to maximize their network's robustness. The following\n"
		$helpwindow.text.area insert end "are some ideas about how xSMBrowser can help alleviate some of the\n"
		$helpwindow.text.area insert end "hassle.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "a) Using Favorites\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "When a favorite is added after visiting a computer, it probably still\n"
		$helpwindow.text.area insert end "depends on name resolution (wins or broadcast) to resolve its ip. If name\n"
		$helpwindow.text.area insert end "resolution is not working, however, then using favorites as backups does\n"
		$helpwindow.text.area insert end "not do much good. If favorites are to be used as a backup, then the \"ip\n"
		$helpwindow.text.area insert end "only\" type of favorite should be probably be used. So, when adding a\n"
		$helpwindow.text.area insert end "favorite, be sure to check the \"ip only\" type in the \"+ Favorite\" dialog.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "b) Master Browsers\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "In the \"Advanced Options\" of the \"+ Network\" dialog, one can specify to\n"
		$helpwindow.text.area insert end "use a particular \"master browser\" from which to get the list of\n"
		$helpwindow.text.area insert end "computers. Since most networks have backup browsers, one could use these\n"
		$helpwindow.text.area insert end "computers as a backup way to still use the network.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "c) Multiple Networks\n"
		$helpwindow.text.area insert end "-------------------------------\n"
		$helpwindow.text.area insert end "Using the above ideas, you could create two or three networks to place in\n"
		$helpwindow.text.area insert end "/etc/xsmbrowser/xsmbrowser-networks. The resulting names might look like the\n"
		$helpwindow.text.area insert end "following.\n"
		$helpwindow.text.area insert end " * CAS Main Network\n"
		$helpwindow.text.area insert end " * CAS Network Backup (1)   \<--- uses known master browser\n"
		$helpwindow.text.area insert end " * CAS Network Backup (2)   \<--- tries possible master browser\n"
		$helpwindow.text.area insert end " * CAS Network Backup (3)   \<--- filename with ips of important computers\n"
	}
	button $helpwindow.buttons.n -highlightthickness 0 -width 11 -text "+ Network"\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "Network Help\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "  I.  Adding Networks\n"
		$helpwindow.text.area insert end " II.  Broadcast Network\n"
		$helpwindow.text.area insert end "III.  WINS Network\n"
		$helpwindow.text.area insert end " IV.  File Name\n"
		$helpwindow.text.area insert end "  V.  Workgroup/Domain\n"
		$helpwindow.text.area insert end " VI.  Advanced Options\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "I. Adding Networks\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "One thing users immediately notice different about xSMBrowser is it takes\n"
		$helpwindow.text.area insert end "a \"multiple networks\" approach. That is, more than one network can be\n"
		$helpwindow.text.area insert end "defined or initiated at any time. Each network defined can have its own\n"
		$helpwindow.text.area insert end "workgroup name, network type (wins or broadcast), and ip address. New\n"
		$helpwindow.text.area insert end "networks can be added with the \"+ Network\" button. Existing networks\n"
		$helpwindow.text.area insert end "can be edited by right clicking them.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "II. Broadcast Network\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "When setting up a broadcast network, there are two important things to\n"
		$helpwindow.text.area insert end "remember. Each computer must be on the same subnet (e.g. 192.168.0.255)\n"
		$helpwindow.text.area insert end "and each computer must have the same workgroup name. Enter these values\n"
		$helpwindow.text.area insert end "into the \"+ Network\" dialog and you should see your network.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Note: Specifying a broadcast of \"default_samba\" will use the default\n"
		$helpwindow.text.area insert end "defined in smb.conf.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "III. Wins Network\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "A Wins Network consists of computers that query a Wins Server for the\n"
		$helpwindow.text.area insert end "name and ip address of the other computers on the network. Wins networks\n"
		$helpwindow.text.area insert end "are commonly found at Universities and other large scale networks. By\n"
		$helpwindow.text.area insert end "entering the ip address of the Wins Server, you can access the computers\n"
		$helpwindow.text.area insert end "in this type of network.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "If your network is set up to use a DHCP server, and you want to find the\n"
		$helpwindow.text.area insert end "IP of the Wins Server, you can run the program winipcfg from Windows\n"
		$helpwindow.text.area insert end "(C:WINDOWS directory). If you use a Wins server, its ip should be\n"
		$helpwindow.text.area insert end "listed.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Note: Specifying a Wins Server of \"default_samba\" will use the Wins\n"
		$helpwindow.text.area insert end "Server defined in smb.conf.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "IV. File Name\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "This acts much like an lmhosts file. The file name specified will consist\n"
		$helpwindow.text.area insert end "of an IP address followed by a name (if desired) on each line. The last\n"
		$helpwindow.text.area insert end "line of the file must be -1.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "Example File:\n"
		$helpwindow.text.area insert end "  192.1.2.3 CHAD\n"
		$helpwindow.text.area insert end "  143.1.2.3 ERIK\n"
		$helpwindow.text.area insert end "  143.1.2.5 JOSH HASSLER\n"
		$helpwindow.text.area insert end "  129.2.3.4\n"
		$helpwindow.text.area insert end "  -1\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "V. Workgroup/Domain\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "This is the workgroup or domain that will be used for the network. If you\n"
		$helpwindow.text.area insert end "specify a file name, a workgroup is not required since the program will take\n"
		$helpwindow.text.area insert end "on the workgroup of each computer it accesses. Specifying a workgroup of\n"
		$helpwindow.text.area insert end "\"default_samba\" will use the workgroup defined in smb.conf.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "VI. Advanced Options\n"
		$helpwindow.text.area insert end "===============================\n"
		$helpwindow.text.area insert end "Specifying a Username and Password here will cause the program to use\n"
		$helpwindow.text.area insert end "that username and password pair every time it accesses a computer. This\n"
		$helpwindow.text.area insert end "feature is commonly used in corporate settings. It is highly recommended\n"
		$helpwindow.text.area insert end "that both are left blank if you don't feel you need them.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "In the Computer List option, you can specify the NetBios name and IP of\n"
		$helpwindow.text.area insert end "the computer from which to get the \"list\" of computers. This option is\n"
		$helpwindow.text.area insert end "only provided for network-debugging reasons.\n"
		$helpwindow.text.area insert end "\n"
		$helpwindow.text.area insert end "If the Workgroup is left \"Static\", your Workgroup name will stay the same\n"
		$helpwindow.text.area insert end "for each Workgroup you enter. If the Workgroup is not \"Static\", your\n"
		$helpwindow.text.area insert end "Workgroup will update each time you enter a new Workgroup.\n"
	}
	button $helpwindow.buttons.s -highlightthickness 0 -width 11 -text Setup\
	-command {
		$helpwindow.text.area delete 0.0 end
		$helpwindow.text.area insert end "Setup Help\n"
		$helpwindow.text.area insert end "================================\n"
		$helpwindow.text.area insert end "  I.  General Options\n"
		$helpwindow.text.area insert end "       a) Image Path\n"
		$helpwindow.text.area insert end "       b) Query Timeout\n"
		$helpwindow.text.area insert end "       c) Cache Size\n"
		$helpwindow.text.area insert end "       d) Object Spacing\n"
		$helpwindow.text.area insert end "       e) Button Pixmaps\n"
		$helpwindow.text.area insert end " II.  Mounting Options\n"
		$helpwindow.text.area insert end "       a) Show Mount Window\n"
		$helpwindow.text.area insert end "       b) Smbmount Version\n"
		$helpwindow.text.area insert end "       c) Post Execute\n"
		$helpwindow.text.area insert end "       d) Mount Tree\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end "I. General Options\n"
		$helpwindow.text.area insert end "================================\n"
		$helpwindow.text.area insert end " a) Image Path\n"
		$helpwindow.text.area insert end "     xSMBrowser now uses pictures and icons throughout the program. For\n"
		$helpwindow.text.area insert end "     it to use the pictures, however, it must know where they are being\n"
		$helpwindow.text.area insert end "     stored. By default, they are put into /usr/share/pixmaps/xsmbrowser,\n"
		$helpwindow.text.area insert end "     so try that first if it says Use Geo (use internal geometry).\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " b) Query Timeout\n"
		$helpwindow.text.area insert end "     An operation, such as a NetBIOS lookup or a file listing, will be\n"
		$helpwindow.text.area insert end "     canceled if it exceeds this time in seconds.\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " c) Cache Size\n"
		$helpwindow.text.area insert end "     Data stored after each completed operation is stored in the Back and \n"
		$helpwindow.text.area insert end "     Forward buttons. Cache Size determines how many operations will be\n"
		$helpwindow.text.area insert end "     stored before they are deleted from memory. 8 is practical.\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " d) Object Spacing\n"
		$helpwindow.text.area insert end "     Different versions of Tcl/Tk and different OS's employ different\n"
		$helpwindow.text.area insert end "     default font sizes. If the text on the screen is piling over top the\n"
		$helpwindow.text.area insert end "     next, select setting 3.\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " e) Button Pixmaps\n"
		$helpwindow.text.area insert end "     On some systems, the buttons with pictures (Back, Forward) may \n"
		$helpwindow.text.area insert end "     appear a little weird-looking. This option lets you use just text\n"
		$helpwindow.text.area insert end "     instead.\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end "II. Mounting Options\n"
		$helpwindow.text.area insert end "================================\n"
		$helpwindow.text.area insert end " a) Show mount window\n"
		$helpwindow.text.area insert end "     The dialog on the bottom of the main window can be rid of if the user\n"
		$helpwindow.text.area insert end "     so wishes. (for Unix users that can't mount shares anyway)\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " b) Smbmount Version\n"
		$helpwindow.text.area insert end "     Sets version of your smbmount program.\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " c) Post Execute\n"
		$helpwindow.text.area insert end "     After using the Mount or Explore button, the command specified will\n"
		$helpwindow.text.area insert end "     execute. Here are some examples:\n"
		$helpwindow.text.area insert end "       Midnight Commander: xterm -e mc \$MOUNTPOINT\n"
		$helpwindow.text.area insert end "       Gnome: gmc \$MOUNTPOINT (doesn't work, but I wish it did)\n"
		$helpwindow.text.area insert end "       KDE: kfmclient folder \$MOUNTPOINT\n"
		$helpwindow.text.area insert end "       Terminal: xterm -e cd \$MOUNTPOINT\n"
		$helpwindow.text.area insert end " \n"
		$helpwindow.text.area insert end " d) Mount Tree\n"
		$helpwindow.text.area insert end "     Specifies directory which to mount shares using the format of:\n"
		$helpwindow.text.area insert end "       \<Mount Tree>/\<netbios name>/\<share name>\n"
		$helpwindow.text.area insert end "     For example, by setting this value to \"\$HOME/mnt\", a computer named\n"
		$helpwindow.text.area insert end "     CHAD and a share named PUBLIC would mount by default to:\n"
		$helpwindow.text.area insert end "       /home/chadspen/mnt/CHAD/PUBLIC\n"
	}
	pack $helpwindow.buttons.o  $helpwindow.buttons.ex $helpwindow.buttons.gen $helpwindow.buttons.ad $helpwindow.buttons.n $helpwindow.buttons.s -side left
	frame $helpwindow.text -borderwidth 0
	pack $helpwindow.text -fill both -expand yes -side top
	scrollbar $helpwindow.text.yscroll -orient vertical -command "$helpwindow.text.area yview"
	pack  $helpwindow.text.yscroll -side right -fill y
	text $helpwindow.text.area -width 1 -foreground black -background white -wrap none -yscrollcommand "$helpwindow.text.yscroll set"
	pack $helpwindow.text.area -side top -fill both -expand yes
	wm title $helpwindow "Help"
	$helpwindow.buttons.o invoke
	bind $helpwindow <KeyPress-Escape> "destroy $helpwindow"
}


proc GPLDialog {} {
	#####################################################
	global show_next_time
	toplevel .code
	frame .code.text
	pack .code.text -fill both -expand yes -pady 5 -side top
	scrollbar .code.text.yscroll -orient vertical -command ".code.text.area yview"
	pack  .code.text.yscroll -side right -fill y
	text .code.text.area -wrap none -width 80 -height 20 -foreground black -background white -yscrollcommand ".code.text.yscroll set"
	pack .code.text.area -fill both -expand yes -side top -expand yes
	frame .code.buttons -borderwidth 5
	pack .code.buttons -side bottom -fill x
	if {$show_next_time == "no"} {
		set show_next_time "show"
	}
	checkbutton .code.buttons.check -onvalue "show" -offvalue "full" -variable show_next_time -text "Show license next time"
	button .code.buttons.dismiss -highlightthickness 0 -text Agree -command {
		if {$show_next_time == "full"} {
			WriteUserFile
		}
		destroy .code
	}
	bind .code <KeyPress-Escape> "destroy .code"
	pack .code.buttons.check
	pack .code.buttons.dismiss
	wm title .code "GNU Public License"
	.code.text.area insert end " xSMBrowser - Samba GUI that emulates Network Neighborhood\n"
	.code.text.area insert end " Copyright (C) 2000 Chad Spencer\n"
	.code.text.area insert end " \n"
	.code.text.area insert end " This program is free software; you can redistribute it and/or modify\n"
	.code.text.area insert end " it under the terms of the GNU General Public License as published by\n"
	.code.text.area insert end " the Free Software Foundation; either version 2 of the License, or\n"
	.code.text.area insert end " (at your option) any later version.\n"
	.code.text.area insert end " \n"
	.code.text.area insert end " This program is distributed in the hope that it will be useful,\n"
	.code.text.area insert end " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
	.code.text.area insert end " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
	.code.text.area insert end " GNU General Public License for more details.\n"
	.code.text.area insert end " \n"
	.code.text.area insert end " You should have received a copy of the GNU General Public License\n"
	.code.text.area insert end " along with this program; if not, write to the Free Software\n"
	.code.text.area insert end " Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\n"
	tkwait visibility .code.buttons.dismiss
	grab .code
	raise .code .
}


proc SetupDialog {} {
	#######################################################
	global user_name_default
	global set_timeout
	global history_length
	global cmultiply
	global history_m
	global image_path
	global pixmaps_buttons
	global place
	.bottom.setup config -state disabled
	toplevel .setupdialog
	wm title .setupdialog "Setup"
	frame .setupdialog.title2 -borderwidth 1 -relief sunken
	pack .setupdialog.title2 -fill x -side top
	label .setupdialog.title2.info -text "General Options:"
	pack .setupdialog.title2.info -fill x -side left
	frame .setupdialog.options -borderwidth 1
	frame .setupdialog.options.op -borderwidth 0
	frame .setupdialog.options.en -borderwidth 0
	pack .setupdialog.options -side top -fill x -expand yes
	pack .setupdialog.options.op -side left
	pack .setupdialog.options.en -side left -fill x -expand yes
	frame .setupdialog.options.op.o1 -borderwidth 2
	pack .setupdialog.options.op.o1 -side top -fill x
	label .setupdialog.options.op.o1.dnl -text "Image Path:"
	frame .setupdialog.options.en.o1 -borderwidth 2
	pack .setupdialog.options.en.o1 -side top -fill x -expand yes
	entry .setupdialog.options.en.o1.dn -width 15 -foreground black -background white
	button .setupdialog.options.en.o1.b -highlightthickness 0 -width 6\
	-text "Browse" -command {
		FolderDialog .setupdialog.options.en.o1.dn
	}
	.setupdialog.options.en.o1.dn insert 0 $image_path
	pack .setupdialog.options.op.o1.dnl -side right
	pack .setupdialog.options.en.o1.dn -side left -fill x -expand yes
	pack .setupdialog.options.en.o1.b -side left
	frame .setupdialog.options.op.o3 -borderwidth 2
	pack .setupdialog.options.op.o3 -side top -fill x
	label .setupdialog.options.op.o3.tl -text "Query timeout:"
	frame .setupdialog.options.en.o3 -borderwidth 2
	pack .setupdialog.options.en.o3 -side top -fill x
	entry .setupdialog.options.en.o3.t -width 3 -foreground black -background white
	.setupdialog.options.en.o3.t insert 0 $set_timeout
	pack .setupdialog.options.op.o3.tl -side right
	pack .setupdialog.options.en.o3.t -side left
	frame .setupdialog.options.op.o4 -borderwidth 2
	pack .setupdialog.options.op.o4 -side top -fill x
	label .setupdialog.options.op.o4.spl -text "Object Spacing:"
	pack .setupdialog.options.op.o4.spl -side right
	frame .setupdialog.options.en.o4 -borderwidth 2
	pack .setupdialog.options.en.o4 -side top -fill x
	radiobutton .setupdialog.options.en.o4.sp1 -text "1" -variable spacing -relief flat -value 5
	radiobutton .setupdialog.options.en.o4.sp2 -text "2" -variable spacing -relief flat -value 6
	radiobutton .setupdialog.options.en.o4.sp3 -text "3" -variable spacing -relief flat -value 7
	if {$cmultiply == 5} {
		.setupdialog.options.en.o4.sp1 select
	} elseif {$cmultiply == 6} {
		.setupdialog.options.en.o4.sp2 select
	} else {
		.setupdialog.options.en.o4.sp3 select
	}
	pack .setupdialog.options.en.o4.sp1 .setupdialog.options.en.o4.sp2 .setupdialog.options.en.o4.sp3 -side left
	frame .setupdialog.pixbut -borderwidth 0
	pack .setupdialog.pixbut -side top -fill x
	checkbutton .setupdialog.pixbut.cb -onvalue "yes" -offvalue "no" -variable pix_but -text "Button Pixmaps (restart)"
	if {$pixmaps_buttons == "yes"} {
		.setupdialog.pixbut.cb select
	} else {
		.setupdialog.pixbut.cb deselect
	}
	pack .setupdialog.pixbut.cb -side top
	frame .setupdialog.buttons2 -borderwidth 1
	button .setupdialog.buttons2.mount -highlightthickness 0 -width 16\
	-text "Mount Options" -command {
		SetupDialogMount
	}
	button .setupdialog.buttons2.open -highlightthickness 0 -width 16\
	-text "Commands" -command {
		CommandsSetup
	}
	label .setupdialog.buttons2.label -borderwidth 4 -text "See Help Button for descriptions."
	pack .setupdialog.buttons2 -side top
	pack .setupdialog.buttons2.label .setupdialog.buttons2.mount .setupdialog.buttons2.open -side top
	frame .setupdialog.buttons1 -borderwidth 10
	button .setupdialog.buttons1.o -highlightthickness 0 -width 7\
	-text "Okay" -command {
		if ![string match {[0-9][0-9][0-9]} [.setupdialog.options.en.o3.t get]] {
			if ![string match {[0-9][0-9]} [.setupdialog.options.en.o3.t get]] {
				if ![string match {[0-9]} [.setupdialog.options.en.o3.t get]] {return}
			}
		}
		set user_name_default ""
		set set_timeout [.setupdialog.options.en.o3.t get]
		set spacing_check $cmultiply
		set cmultiply $spacing
		if {[.setupdialog.options.en.o1.dn get] != $image_path} {
			set image_path [.setupdialog.options.en.o1.dn get]
			set spacing_check 989
			ReadImages
		}
		set pixmaps_buttons $pix_but
		WriteUserFile
		destroy .setupdialog
		if {$spacing_check != $cmultiply} {HistoryCall 0 local}
	}
	button .setupdialog.buttons1.c -highlightthickness 0 -width 7\
	-text "Cancel" -command {destroy .setupdialog}
	pack .setupdialog.buttons1 -side top
	pack .setupdialog.buttons1.o .setupdialog.buttons1.c -side left
	tkwait visibility .setupdialog
	bind .setupdialog <KeyPress-Return> {.setupdialog.buttons1.o invoke}
	bind .setupdialog <KeyPress-Escape> {.setupdialog.buttons1.c invoke}
	bind .setupdialog <Destroy> {
		.bottom.setup config -state normal
	}
}


proc SetupDialogMount {} {
	#######################################################
	global mount_version
	global mount_addon
	global mounting
	global smbmount_tree
	global smbmount_execute
	global history_m
	global place
	toplevel .setupdialogm
	wm title .setupdialogm "Mount Setup"
	frame .setupdialogm.title2 -borderwidth 1 -relief sunken
	pack .setupdialogm.title2 -fill x -side top
	label .setupdialogm.title2.info -text "Mount Options:"
	pack .setupdialogm.title2.info -fill x -side left
	frame .setupdialogm.buttons1 -borderwidth 5
	button .setupdialogm.buttons1.o -highlightthickness 0 -width 8\
	-text "Okay" -command {
		if {$mount_addon != $mounting} {
			if {$mounting == "yes"} {
			} else {
				destroy .title
				destroy .mounted
				destroy .mstatus
			}
		}
		set mount_version $version
		set mount_addon $mounting
		set smbmount_tree [.setupdialogm.options4.m.r.e2 get]
		set smbmount_execute [.setupdialogm.options4.m.r.e1 get]
		WriteUserFile
		destroy .setupdialogm
	}
	button .setupdialogm.buttons1.c -highlightthickness 0\
	-width 8 -text "Cancel" -command {destroy .setupdialogm}
	frame .setupdialogm.options4 -borderwidth 5
	pack .setupdialogm.options4 -fill x -side top
	frame .setupdialogm.options4.o7 -borderwidth 2
	pack .setupdialogm.options4.o7 -fill x -side top
	frame .setupdialogm.options4.o7.mount -borderwidth 0
	pack .setupdialogm.options4.o7.mount -fill x
	frame .setupdialogm.options4.o7.title -borderwidth 1
	pack .setupdialogm.options4.o7.title -fill x
	checkbutton .setupdialogm.options4.o7.mount.v -onvalue "yes" -offvalue "no" -variable mounting\
	-text "Show bottom mount window" -command {
		if {$mounting != "yes"} {
			.setupdialogm.options4.o7.mount.v config -text "Show bottom mount window"
			.setupdialogm.options4.o7.version0.o config -state disabled
			.setupdialogm.options4.o7.version1.o config -state disabled
			.setupdialogm.options4.o7.version2.o config -state disabled
			.setupdialogm.options4.o7.version3.o config -state disabled
			.setupdialogm.options4.o7.version4.o config -state disabled
		} else {
			if {$mount_addon == "no"} {
				.setupdialogm.options4.o7.mount.v config -text "Show mount window (program restart required)"
			}
			.setupdialogm.options4.o7.version0.o config -state normal
			.setupdialogm.options4.o7.version1.o config -state normal
			.setupdialogm.options4.o7.version2.o config -state normal
			.setupdialogm.options4.o7.version3.o config -state normal
			.setupdialogm.options4.o7.version4.o config -state normal
		}
	}
	if {$mount_addon == "yes"} {
		.setupdialogm.options4.o7.mount.v select
	}
	pack .setupdialogm.options4.o7.mount.v -side left
	label .setupdialogm.options4.o7.title.o -text "Smbmount Version:"
	pack .setupdialogm.options4.o7.title.o -side left
	frame .setupdialogm.options4.o7.version0 -borderwidth 0
	pack .setupdialogm.options4.o7.version0 -fill x
	radiobutton .setupdialogm.options4.o7.version0.o -text "Version >= 2.0.7" -variable version -relief flat -value 0
	pack .setupdialogm.options4.o7.version0.o -side left
	frame .setupdialogm.options4.o7.version1 -borderwidth 0
	pack .setupdialogm.options4.o7.version1 -fill x
	radiobutton .setupdialogm.options4.o7.version1.o -text "Version == 2.0.6" -variable version -relief flat -value 1
	pack .setupdialogm.options4.o7.version1.o -side left
	frame .setupdialogm.options4.o7.version2 -borderwidth 0
	pack .setupdialogm.options4.o7.version2 -fill x
	radiobutton .setupdialogm.options4.o7.version2.o -text "Version == 2.0.5" -variable version -relief flat -value 2
	pack .setupdialogm.options4.o7.version2.o -side left
	frame .setupdialogm.options4.o7.version3 -borderwidth 0
	pack .setupdialogm.options4.o7.version3 -fill x
	radiobutton .setupdialogm.options4.o7.version3.o -text "Ver. \< 2.0.5 ; Ker. >= 2.2" -variable version -relief flat -value 3
	pack .setupdialogm.options4.o7.version3.o -side left
	frame .setupdialogm.options4.o7.version4 -borderwidth 0
	pack .setupdialogm.options4.o7.version4 -fill x
	radiobutton .setupdialogm.options4.o7.version4.o -text "Ver. \< 2.0.5 ; Ker. \< 2.2" -variable version -relief flat -value 4
	pack .setupdialogm.options4.o7.version4.o -side left
	frame .setupdialogm.options4.o7.version5 -borderwidth 0
	pack .setupdialogm.options4.o7.version5 -fill x
	radiobutton .setupdialogm.options4.o7.version5.o -text "mount_smbfs" -variable version -relief flat -value 5
	pack .setupdialogm.options4.o7.version5.o -side left
	if {$mount_version == 0} {
		.setupdialogm.options4.o7.version0.o select
	} elseif {$mount_version == 1} {
		.setupdialogm.options4.o7.version1.o select
	} elseif {$mount_version == 2} {
		.setupdialogm.options4.o7.version2.o select
	} elseif {$mount_version == 3} {
		.setupdialogm.options4.o7.version3.o select
	} elseif {$mount_version == 4} {
		.setupdialogm.options4.o7.version4.o select
	} elseif {$mount_version == 5} {
		.setupdialogm.options4.o7.version5.o select
	}
	pack .setupdialogm.buttons1
	pack .setupdialogm.buttons1.o .setupdialogm.buttons1.c -side left
	tkwait visibility .setupdialogm
	grab .setupdialogm
	if {$mounting != "yes"} {
		.setupdialogm.options4.o7.version0.o config -state disabled
		.setupdialogm.options4.o7.version1.o config -state disabled
		.setupdialogm.options4.o7.version2.o config -state disabled
		.setupdialogm.options4.o7.version3.o config -state disabled
		.setupdialogm.options4.o7.version4.o config -state disabled
	}
	frame .setupdialogm.options4.m -borderwidth 3
	label .setupdialogm.options4.m.t -anchor w -borderwidth 0 -text "Use \$MOUNTPOINT for mount path"
	label .setupdialogm.options4.m.t2 -anchor w -borderwidth 0 -text "and \$HOME for home directory. See"
	label .setupdialogm.options4.m.t3 -anchor w -borderwidth 0 -text "Help for examples."
	pack .setupdialogm.options4.m.t .setupdialogm.options4.m.t2 .setupdialogm.options4.m.t3 -fill x -side top
	pack .setupdialogm.options4.m -side top -fill x -expand yes
	frame .setupdialogm.options4.m.l
	pack .setupdialogm.options4.m.l -side left
	frame .setupdialogm.options4.m.r
	pack .setupdialogm.options4.m.r -side left -fill x -expand yes
	label .setupdialogm.options4.m.l.t1 -anchor e -text "Post Execute:"
	entry .setupdialogm.options4.m.r.e1 -width 20 -foreground black -background white
	label .setupdialogm.options4.m.l.t2 -anchor e -text "Mount Tree:"
	entry .setupdialogm.options4.m.r.e2 -width 17 -foreground black -background white
	pack .setupdialogm.options4.m.l.t1 .setupdialogm.options4.m.l.t2 -side top -fill x
	pack .setupdialogm.options4.m.r.e1 .setupdialogm.options4.m.r.e2 -side top -fill x -expand yes
	.setupdialogm.options4.m.r.e1 insert 0 $smbmount_execute
	.setupdialogm.options4.m.r.e2 insert 0 $smbmount_tree
	bind .setupdialogm <KeyPress-Return> {.setupdialogm.buttons1.o invoke}
	bind .setupdialogm <KeyPress-Escape> {.setupdialogm.buttons1.c invoke}
}


proc CommandsSetup {} {
	#######################################################
	global commands_m
	global commands_sel
	toplevel .commands
	wm title .commands "Commands Setup"
	frame .commands.f -borderwidth 6
	frame .commands.f.a -borderwidth 4
	frame .commands.f.b
	frame .commands.f.c -borderwidth 4
	frame .commands.f.d
	frame .commands.f.e -borderwidth 4
	frame .commands.f.f
	frame .commands.f.g -borderwidth 6
	pack .commands.f .commands.f.a .commands.f.b .commands.f.c .commands.f.d .commands.f.e .commands.f.f -side top -fill x
	pack .commands.f.g -side top
	menubutton .commands.f.a.s1 -indicatoron 1 -relief groove -menu .commands.f.a.s1.m
	menu .commands.f.a.s1.m -tearoff 0
	set commands_sel 0
	.commands.f.a.s1.m add radiobutton -label "Add New" -command ".commands.f.a.s1 config -text \"Add New\";\
	set commands_sel 0; .commands.f.b.e1 delete 0 1024; .commands.f.d.e1 delete 0 1024; .commands.f.f.e1 delete 0 1024;\
	.commands.f.g.b2 config -state disabled"
	set m 1
	while {$m < [expr [array size commands_m] / 3]} {
		.commands.f.a.s1.m add radiobutton -label $commands_m($m,name) -command ".commands.f.a.s1 config -text\
		\{$commands_m($m,name)\}; set commands_sel $m; .commands.f.b.e1 delete 0 1024; .commands.f.b.e1 insert 0\
		\{$commands_m($m,name)\}; .commands.f.d.e1 delete 0 1024; .commands.f.d.e1 insert 0 \{$commands_m($m,types)\};\
		.commands.f.f.e1 delete 0 1024; .commands.f.f.e1 insert 0 \{$commands_m($m,command)\}; .commands.f.g.b2 config -state normal"
		incr m
	}
	pack .commands.f.a.s1 -side left -fill x -expand yes
	label .commands.f.b.l1 -text "Name:"
	pack .commands.f.b.l1 -side left
	entry .commands.f.b.e1 -foreground black -background white
	pack .commands.f.b.e1 -side left -fill x -expand yes
	label .commands.f.c.l1 -justify left -text "List the file types--seperating each by\none space \(Case Insensitive).\nEg.  .GIF .JPG .BMP"
	pack .commands.f.c.l1 -side left
	entry .commands.f.d.e1 -foreground black -background white
	pack .commands.f.d.e1 -side left -expand yes -fill x
	label .commands.f.e.l1 -justify left -text "Use \$FILE for the file name in the\nfollowing command line.\nEg.  gimp \$FILE"
	pack .commands.f.e.l1 -side left
	entry .commands.f.f.e1 -foreground black -background white
	pack .commands.f.f.e1 -side left -expand yes -fill x
	button .commands.f.g.b2 -highlightthickness 0 -width 7\
	-text "Delete" -command {
		set commands_m($commands_sel,name) "delete_me"
		destroy .commands.f.a.s1
		CommandsSetupRepack
		tkwait visibility .commands.f.a.s1
		.commands.f.a.s1.m invoke 0
	}
	button .commands.f.g.b1 -highlightthickness 0 -width 7\
	-text "Update" -command {
		if {[.commands.f.b.e1 get] == ""} {return}
		if {$commands_sel == "0"} {
			set commands_sel [expr [array size commands_m] / 3]
		}
		set commands_m($commands_sel,name) [.commands.f.b.e1 get]
		set commands_m($commands_sel,types) [string toupper [.commands.f.d.e1 get]]
		set commands_m($commands_sel,command) [.commands.f.f.e1 get]
		destroy .commands.f.a.s1
		CommandsSetupRepack
		tkwait visibility .commands.f.a.s1
		.commands.f.a.s1.m invoke 0
	}
	button .commands.f.g.b3 -highlightthickness 0 -width 7\
	-text "Dismiss" -command {
		destroy .commands
	}
	pack .commands.f.g.b1 .commands.f.g.b2 .commands.f.g.b3 -side left
	tkwait visibility .commands.f.f.e1
	.commands.f.a.s1.m invoke 0
	bind .commands <KeyPress-Return> {.commands.f.g.b1 invoke}
	bind .commands <KeyPress-Escape> {.commands.f.g.b3 invoke}
}


proc CommandsSetupRepack {} {
	global commands_m
	global commands_sel
	WriteUserFile
	ReadUserFile
	set commands_sel 0
	menubutton .commands.f.a.s1 -indicatoron 1 -relief groove -menu .commands.f.a.s1.m
	menu .commands.f.a.s1.m -tearoff 0
	.commands.f.a.s1.m add radiobutton -label "Add New" -command ".commands.f.a.s1 config -text \"Add New\";\
	set commands_sel 0; .commands.f.b.e1 delete 0 1024; .commands.f.d.e1 delete 0 1024; .commands.f.f.e1 delete 0 1024;\
	.commands.f.g.b2 config -state disabled"
	set m 1
	while {$m < [expr [array size commands_m] / 3]} {
		.commands.f.a.s1.m add radiobutton -label $commands_m($m,name) -command ".commands.f.a.s1 config -text\
		\{$commands_m($m,name)\}; set commands_sel $m; .commands.f.b.e1 delete 0 1024; .commands.f.b.e1 insert 0\
		\{$commands_m($m,name)\}; .commands.f.d.e1 delete 0 1024; .commands.f.d.e1 insert 0 \{$commands_m($m,types)\};\
		.commands.f.f.e1 delete 0 1024; .commands.f.f.e1 insert 0 \{$commands_m($m,command)\}; .commands.f.g.b2 config -state normal"
		incr m
	}
	pack .commands.f.a.s1 -side left -fill x -expand yes
}


proc CheckMTAB {} {
	##########################################
	global readfmt
	global mounted_m
	global mount_fav_m
	global user_name_default set_timeout cmultiply
	if ![file exists /etc/mtab] {
		puts "\[!\] File \"/etc/mtab\" missing. You may experience unmounting problems."
		return
	}
	if [info exists mounted_m] {unset mounted_m}
	.mounted.list delete 0 1024
	.mounted.list2 delete 0 1024
	puts -nonewline [format "$readfmt" "Reading /etc/mtab"]; flush stdout
	set mtab [open "/etc/mtab" r]
	gets $mtab line
	set m 0
	set eof_check 0
	while {[eof $mtab] == 0 & $eof_check != "15"} {
		gets $mtab line
		if {$line == ""} {incr eof_check}
		if {[string range $line 0 1] == "//"} {
			if [info exists m1] {unset m1}
			if [info exists m2] {unset m2}
			if [info exists m3] {unset m3}
			if [info exists m4] {unset m4}
			if [info exists m5] {unset m5}
			regexp -indices "(//(\[^/]*)/(\[^/]*)).*(smbfs *\[0-9]* *\[0-9]*)" $line m1 m2 m3 m4 m5
			if [info exists m1] {
				set mounted_m($m,1) [string trim [string range $line [lindex $m2 0] [lindex $m2 1]]]
				set mounted_m($m,2) [string trim [string range $line [expr [lindex $m2 1] + 1] [expr [lindex $m5 0] - 1]]]
				set mounted_m($m,3) [string trim [string range $line [lindex $m5 0] [lindex $m5 1]]]
				incr m
			}
		}
	}
	close $mtab
	puts "\[ok\]"
	if [info exists mounted_m] {
		set l 0
		while {$l < $m} {
			.mounted.list insert $l " $mounted_m($l,1)"
			.mounted.list2 insert $l " $mounted_m($l,2)"
			incr l
		}
	}
}


proc MountedBoxClick {index} {
	###########################################
	global mounted_m
	global computer
	global explore_type
	global share
	global history_m
	global place
	global mstatus
	if ![info exists mounted_m] {return}
	set comp_name [.mounted.list get $index]
	set mstatus $comp_name
	.mstatus.info2.stats config -text [.mounted.list2 get $index]
	.mounted.list selection set $index $index
	.mounted.list see $index
	.mounted.list2 see $index
	.mstatus.buttons.unmount config -state normal
	set explore_type "explore"
	if {$history_m($place,type) == "files"} {
		if {$comp_name == " //$computer/$share"} {
			.mstatus.buttons.mount config -state normal
			.mstatus.buttons.explore config -state normal
		} else {
			.mstatus.buttons.mount config -state disabled
			.mstatus.buttons.explore config -state normal
		}
	} else {
		.mstatus.buttons.explore config -state normal
	}
}


proc ComputerShareClick {comp_share} {
	####################################################
	global mounted_m
	global mstatus
	global history_m
	global explore_type
	global place
	global computer
	global share
	set tester "no"
	set m 0
	if [info exists mounted_m] {
		while {$m < [expr [array size mounted_m] / 3]} {
			set mount_match $mounted_m($m,1)
			set i 0
			while {$i < [string length $mount_match]} {
				if {[string match {[0-9a-zA-Z]} [string index $mount_match $i]] == "0"} {
					set mount_match "[string range $mount_match 0 [expr $i - 1]]?[string range $mount_match [expr $i + 1] [expr [string length\
					$mount_match] - 1]]"
				}
				incr i
			}
			if {[string match [string toupper $mount_match] [string toupper $comp_share]] == "1"} {
				set tester $m
				set explore_type "explore"
			}
			incr m
		}
	}
	if {$tester == "no"} {
		set explore_type "mount"
		if {$history_m($place,type) == "files"} {
			set mstatus " //$computer/$share"
			.mstatus.info2.stats config -text " Not Mounted"
			.mstatus.buttons.mount config -state normal
			.mstatus.buttons.explore config -state normal
			.mstatus.buttons.unmount config -state disabled
		} else {
			.mstatus.buttons.mount config -state disabled
			.mstatus.buttons.explore config -state disabled
			.mstatus.buttons.unmount config -state disabled
		}
	} else {
		MountedBoxClick $tester
	}
}


proc UnmountCheck {comp_share} {
	####################################################
	global explore_type
	global mounted_m
	set tester "no"
	set m 0
	set explore_type "mount"
	if [info exists mounted_m] {
		while {$m < [expr [array size mounted_m] / 3]} {
			set mount_match $mounted_m($m,1)
			set i 0
			while {$i < [string length $mount_match]} {
				if {[string match {[0-9a-zA-Z]} [string index $mount_match $i]] == "0"} {
					set mount_match "[string range $mount_match 0 [expr $i - 1]]?[string range $mount_match [expr $i + 1] [expr [string length\
					$mount_match] - 1]]"
				}
				incr i
			}
			if {[string match [string toupper $mount_match] [string toupper $comp_share]] == "1"} {
				set tester $m
				set explore_type "explore"
			}
			incr m
		}
	}
	return $tester
}


proc UnMount {mount_dir} {
	#######################################
	global mount_dir_retad
	global computer
	global mount_refresh
	global share
	global place
	global mstatus
	global history_m
	set mount_dir_retad $mount_dir
	# first I try smbumount, if fail, I then try plain-old umount
	if [catch [exec smbumount $mount_dir_retad]] {
		exec umount $mount_dir_retad
	}
	CheckMTAB
	set mount_refresh "refresh"
	if {$history_m($place,type) == "files"} {
		ComputerShareClick "//$computer/$share"
	} else {
		.mstatus.buttons.unmount config -state disabled
		.mstatus.buttons.explore config -state disabled
		set mstatus ""
		.mstatus.info2.stats config -text ""
	}
}


proc Mount {share} {
	#######################################
	global computer
	global computer_ip_num
	global workgroup
	global mount_version_tmp
	global mount_fav_m
	global env
	global mount_refresh
	global mount_version
	global env_name
	global global_topbox
	global password
	global user_name
	global share_m
	global smbmount_tree
	global smbmount_execute
	set share_m $share
	global override_mount
	global canvason
	if {$canvason == "off"} {return}
	toplevel .mountit
	wm title .mountit "Mount"
	frame .mountit.title -borderwidth 1 -relief sunken
	pack .mountit.title -fill x -side top
	label .mountit.title.t -text "Specify Mount Point:"
	pack .mountit.title.t -fill x -side left
	frame .mountit.topbox -borderwidth 3
	pack .mountit.topbox -side top -fill x -expand yes
	frame .mountit.topbox.left -borderwidth 1
	frame .mountit.topbox.right -borderwidth 1
	pack .mountit.topbox.left -side left
	pack .mountit.topbox.right -side left -fill x -expand yes
	frame .mountit.topbox.left.s -borderwidth 0
	frame .mountit.topbox.left.m -borderwidth 0
	pack .mountit.topbox.left.s .mountit.topbox.left.m -side top -fill x
	frame .mountit.topbox.right.s -borderwidth 0
	frame .mountit.topbox.right.m -borderwidth 0
	pack .mountit.topbox.right.s -side top -fill x
	pack .mountit.topbox.right.m -side top -fill x -expand yes
	label .mountit.topbox.left.s.t -text "Service:"
	label .mountit.topbox.left.m.t -text "Mount Point:"
	label .mountit.topbox.right.s.t -text "\\\\$computer\\$share_m"
	entry .mountit.topbox.right.m.e -foreground black -background white -width 17 -state normal
	button .mountit.topbox.right.m.b -highlightthickness 0 -width 6\
	-text "Make Dir" -command {
		MakeDir [.mountit.topbox.right.m.e get] "check" "pass"
	}
	pack .mountit.topbox.left.s.t .mountit.topbox.left.m.t -side right
	pack .mountit.topbox.right.s.t -side left
	pack .mountit.topbox.right.m.e -side left -fill x -expand yes
	pack .mountit.topbox.right.m.b -side left
	frame .mountit.midbox -borderwidth 3
	pack .mountit.midbox -side top -fill x
	set override_mount "no"
	checkbutton .mountit.midbox.c -onvalue "yes" -offvalue "no" -variable override_mount -text "Override Defaults" -command {
		if {$override_mount == "yes"} {
			.mountit.botbox.two.u.e config -state normal -background white
			.mountit.botbox.two.g.e config -state normal -background white
			.mountit.botbox.four.f.e config -state normal -background white
			.mountit.botbox.four.d.e config -state normal -background white
			.mountit.botbox.two.u.e insert 0 $env_name
			.mountit.botbox.two.g.e insert 0 $env_name
			.mountit.botbox.four.f.e insert 0 644
			.mountit.botbox.four.d.e insert 0 755
		} else {
			.mountit.botbox.two.u.e delete 0 999
			.mountit.botbox.two.g.e delete 0 999
			.mountit.botbox.four.f.e delete 0 999
			.mountit.botbox.four.d.e delete 0 999
			.mountit.botbox.two.u.e config -state disabled -background grey70
			.mountit.botbox.two.g.e config -state disabled -background grey70
			.mountit.botbox.four.f.e config -state disabled -background grey70
			.mountit.botbox.four.d.e config -state disabled -background grey70
		}
	}
	menubutton .mountit.midbox.box -indicatoron 1 -relief groove -menu .mountit.midbox.box.m
	menu .mountit.midbox.box.m -tearoff 0
	.mountit.midbox.box.m add command -label "Set default in Setup."
	.mountit.midbox.box.m add radiobutton -label "Version >= 2.0.7" -command {
		.mountit.midbox.box config -text "Version >= 2.0.7"
		set mount_version_tmp 0
	}
	.mountit.midbox.box.m add radiobutton -label "Version == 2.0.6" -command {
		.mountit.midbox.box config -text "Version == 2.0.6"
		set mount_version_tmp 1
	}
	.mountit.midbox.box.m add radiobutton -label "Version == 2.0.5" -command {
		.mountit.midbox.box config -text "Version == 2.0.5"
		set mount_version_tmp 2
	}
	.mountit.midbox.box.m add radiobutton -label "Ver. \< 2.0.5 \; Ker. >= 2.2" -command {
		.mountit.midbox.box config -text "Ver. \< 2.0.5 \; Ker. >= 2.2"
		set mount_version_tmp 3
	}
	.mountit.midbox.box.m add radiobutton -label "Ver. \< 2.0.5 \; Ker. \< 2.2" -command {
		.mountit.midbox.box config -text "Ver. \< 2.0.5 \; Ker. \< 2.2"
		set mount_version_tmp 4
	}
	.mountit.midbox.box.m add radiobutton -label "mount_smbfs" -command {
		.mountit.midbox.box config -text "mount_smbfs"
		set mount_version_tmp 5
	}
	if {$mount_version == "4"} {
		.mountit.midbox.box.m invoke 5
	} elseif {$mount_version == "3"} {
		.mountit.midbox.box.m invoke 4
	} elseif {$mount_version == "5"} {
		.mountit.midbox.box.m invoke 6
	} elseif {$mount_version == "2"} {
		.mountit.midbox.box.m invoke 3
	} elseif {$mount_version == "1"} {
		.mountit.midbox.box.m invoke 2
	} else {
		.mountit.midbox.box.m invoke 1
	}
	pack .mountit.midbox.c .mountit.midbox.box -side left
	frame .mountit.botbox -borderwidth 3
	pack .mountit.botbox -side top -fill x
	frame .mountit.botbox.one -borderwidth 1
	frame .mountit.botbox.two -borderwidth 1
	frame .mountit.botbox.three -borderwidth 1
	frame .mountit.botbox.four -borderwidth 1
	pack .mountit.botbox.one .mountit.botbox.two .mountit.botbox.three -side left
	pack .mountit.botbox.four -side left -fill x
	frame .mountit.botbox.one.u -borderwidth 0
	frame .mountit.botbox.one.g -borderwidth 0
	frame .mountit.botbox.two.u -borderwidth 0
	frame .mountit.botbox.two.g -borderwidth 0
	frame .mountit.botbox.three.f -borderwidth 0
	frame .mountit.botbox.three.d -borderwidth 0
	frame .mountit.botbox.four.f -borderwidth 0
	frame .mountit.botbox.four.d -borderwidth 0
	pack .mountit.botbox.one.u .mountit.botbox.one.g .mountit.botbox.two.u .mountit.botbox.two.g .mountit.botbox.three.f\
	.mountit.botbox.three.d .mountit.botbox.four.f .mountit.botbox.four.d -side top -fill x
	label .mountit.botbox.one.u.t -text "UID:"
	label .mountit.botbox.one.g.t -text "GID:"
	label .mountit.botbox.three.f.t -text "File Mode:"
	label .mountit.botbox.three.d.t -text "Dir Mode:"
	pack .mountit.botbox.one.u.t .mountit.botbox.one.g.t .mountit.botbox.three.f.t .mountit.botbox.three.d.t -side right
	entry .mountit.botbox.two.u.e -width 10 -background grey70 -state disabled
	entry .mountit.botbox.two.g.e -width 10 -background grey70 -state disabled
	entry .mountit.botbox.four.f.e -width 5 -background grey70 -state disabled
	entry .mountit.botbox.four.d.e -width 5 -background grey70 -state disabled
	pack .mountit.botbox.two.u.e .mountit.botbox.two.g.e .mountit.botbox.four.f.e .mountit.botbox.four.d.e -side right
	frame .mountit.ex -borderwidth 4
	frame .mountit.ex.b -borderwidth 0
	pack .mountit.ex -side top -fill x
	pack .mountit.ex.b -fill x -side top
	checkbutton .mountit.ex.b.c -onvalue "yes" -offvalue "no" -variable execute_mount -text "Post Execute:" -command {
		if {$execute_mount == "yes"} {
			.mountit.ex.b.e delete 0 999
			.mountit.ex.b.e config -background white -state normal
			.mountit.ex.b.e insert 0 $smbmount_execute
		} else {
			.mountit.ex.b.e delete 0 999
			.mountit.ex.b.e config -background grey70 -state disabled
		}
	}
	entry .mountit.ex.b.e -foreground black -background white -state normal
	pack .mountit.ex.b.c -side left
	pack .mountit.ex.b.e -expand yes -fill x -side left
	frame .mountit.b -borderwidth 10
	frame .mountit.b.buttons -borderwidth 0
	pack .mountit.b -side top -fill x
	pack .mountit.b.buttons -side top
	button .mountit.b.buttons.mount -highlightthickness 0 -width 8\
	-text "Mount" -command {
		if {[.mountit.topbox.right.m.e get] == ""} {return}
		set mount_path [MakeDir [.mountit.topbox.right.m.e get] "check" ""]
		if {$mount_path == "get_thee_to_a_nunnery"} {return}
		if {$override_mount == "yes"} {
			set mount_uid [.mountit.botbox.two.u.e get]
			set mount_gid [.mountit.botbox.two.g.e get]
			set mount_file [.mountit.botbox.four.f.e get]
			set mount_dir [.mountit.botbox.four.d.e get]
		}
		set canvason "off"
		if {$mount_version_tmp == 0} {
			if {$override_mount == "yes"} {
				spawn mount -t smbfs \
				-o uid=$mount_uid,gid=$mount_gid,fmask=$mount_file,dmask=$mount_dir,ip=$computer_ip_num,workgroup=$workgroup,guest,rw //$computer/$share_m $mount_path
			} else {
				spawn mount -t smbfs -o ip=$computer_ip_num,workgroup=$workgroup,guest,rw //$computer/$share_m $mount_path
			}
		} elseif {$mount_version_tmp == 1} {
			if {$override_mount == "yes"} {
				spawn smbmount \\\\$computer\\$share_m $mount_path \
				-o uid=$mount_uid,gid=$mount_gid,fmask=$mount_file,dmask=$mount_dir,ip=$computer_ip_num,workgroup=$workgroup,guest,rw
			} else {
				spawn smbmount \\\\$computer\\$share_m $mount_path -o ip=$computer_ip_num,workgroup=$workgroup,guest,rw
			}
		} elseif {$mount_version_tmp == 5} {
			if {$override_mount == "yes"} {
				spawn mount_smbfs -I $computer_ip_num -W $workgroup -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir  //$user_name@$computer/$share_m $mount_path
			} else {
				spawn mount_smbfs -I $computer_ip_num -W $workgroup //$user_name@$computer/$share_m $mount_path
			}
		} elseif {$mount_version_tmp == 2} {
			if {$user_name == "" & $password == "" } {
				spawn smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -N -W $workgroup
			} else {
				spawn smbmount \\\\$computer\\$share_m $mount_path -U $user_name -I $computer_ip_num -N -W $workgroup
			}
		} elseif {$mount_version_tmp == 3} {
			if {$override_mount == "yes"} {
				if {$user_name == "" & $password == ""} {
					spawn smbmount \\\\$computer\\$share_m -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\"\
					-u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir"
				} else {
					spawn smbmount \\\\$computer\\$share_m -U $user_name -I $computer_ip_num -N -W $workgroup\
					-c "mount \"$mount_path\" -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir"
				}
			} else {
				if {$user_name == "" & $password == ""} {
					spawn smbmount \\\\$computer\\$share_m -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
				} else {
					spawn smbmount \\\\$computer\\$share_m -U $user_name -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
				}
			}
		} else {
			if {$override_mount == "yes"} {
				if {$user_name == ""} {
					spawn smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup\
					-u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir
				} else {
					spawn smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup\
					-U $user_name -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir
				}
			} else {
				if {$user_name == ""} {
					spawn smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup
				} else {
					spawn smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup -U $user_name
				}
			}
		}
		set id $spawn_id
		set timeout 35
		.mountit.b.buttons.mount config -state disabled
		expect {
			-i $id "Usage: smbmount" {
				set error_message "Bad Usage. Check setup for correct version of smbmount."
				close -i $id
			}
			-i $id "only root can do that" {
				set error_message "Only root can mount. Try setting version to 2.0.6."
				exp_continue
			}
			-i $id "invalid option -- " {
				set error_message "Bad Usage. Check setup for correct version of smbmount."
				exp_continue
			}
			-i $id -indices -re " - (ERR\[^ ]+)" {
				set error_message [Error $expect_out(1,string)]
				exp_continue
			}
			-i $id "Error" {
				if [string match *Error* $mount_path] {
					exp_continue
				} else {
					set error_message "Unexpected Error"
					exp_continue
				}
			}
			-i $id "failed" {
				if [string match *failed* $mount_path] {
					exp_continue
				} else {
					set error_message "Connection failed"
					exp_continue
				}
			}
			-i $id "ERRDOS" {
				if [string match *ERRDOS* $mount_path] {
					exp_continue
				} else {
					set error_message "Error: ERRDOS"
					exp_continue
				}
			}
			-i $id "assword:" {
				exp_send -i $id "$password\r"
				exp_continue
			}
			-i $id timeout { close -i $id }
		}
		wait -i $id
		set canvason "on"
		after 1000 {set after_time 1}
		tkwait variable after_time
		CheckMTAB
		set mount_refresh "refresh"
		ComputerShareClick "//$computer/$share_m"
		.mountit.b.buttons.mount config -state normal
		if [info exists error_message] {
			.mountit.title.t config -text $error_message
			unset error_message
		} else {
			set z 1
			set mount_match "no"
			while {$z < [expr 1 + [array size mount_fav_m] / 14] & $mount_match == "no"} {
				if {$mount_fav_m($z,share) == "//$computer/$share_m"} {
					set mount_match $z
				}
				incr z
			}
			if {$mount_match == "no"} {
				set mount_match [expr 1 + [array size mount_fav_m] / 14]
			}
			set mount_fav_m($mount_match,share) "//$computer/$share_m"
			if {$global_topbox == $mount_path} {
				set mount_fav_m($mount_match,spot) "default"
			} else {
				set mount_fav_m($mount_match,spot) $mount_path
			}
			if {$override_mount == "yes"} {
				set mount_fav_m($mount_match,uid) $mount_uid
				set mount_fav_m($mount_match,gid) $mount_gid
				set mount_fav_m($mount_match,file) $mount_file
				set mount_fav_m($mount_match,dir) $mount_dir
			} else {
				set mount_fav_m($mount_match,uid) ""
				set mount_fav_m($mount_match,gid) ""
				set mount_fav_m($mount_match,file) ""
				set mount_fav_m($mount_match,dir) ""
			}
			set mount_fav_m($mount_match,history) "yes"
			set mount_fav_m($mount_match,ip) "$computer_ip_num"
			set mount_fav_m($mount_match,username) "$user_name"
			set mount_fav_m($mount_match,password) "$password"
			set mount_fav_m($mount_match,netbios) "$computer"
			set mount_fav_m($mount_match,workgroup) "$workgroup"
			set mount_fav_m($mount_match,execute) $execute_mount
			set mount_fav_m($mount_match,sharename) $share_m
			WriteUserFile
			if {$execute_mount == "yes"} {set post_mount [.mountit.ex.b.e get]}
			destroy .mountit
			if {$execute_mount == "yes"} {
				set first [string first "\$MOUNTPOINT" $post_mount]
				if {$first != "-1"} {
					set execute "exec [string range $post_mount 0 [expr $first - 1]]\"$mount_path\"[string range $post_mount [expr $first + 11]\
					[expr [string length $post_mount] - 1]] &"
				} else {
					set execute "exec $post_mount &"
				}
				after 2000 {set after_time 1}
				tkwait variable after_time
				eval $execute
			}
		}
	}
	button .mountit.b.buttons.cancel -highlightthickness 0 -width 8\
	-text "Cancel" -command {destroy .mountit}
	pack .mountit.b.buttons.mount .mountit.b.buttons.cancel -side left
	if {$mount_version == "2"} {
		.mountit.midbox.c config -state disabled
	}
	set found "no"
	set z 1
	set global_topbox "no"
	set found_default "yes"
	if [info exists mount_fav_m] {
		while {$z < [expr 1 + [array size mount_fav_m] / 14]} {
			if {$mount_fav_m($z,share) == "//$computer/$share_m"} {
				if {$mount_fav_m($z,spot) != "default"} {
					set found_default "no"
					.mountit.topbox.right.m.e insert 0 $mount_fav_m($z,spot)
				}
				if {$mount_fav_m($z,execute) == "yes"} {
					.mountit.ex.b.c select
					.mountit.ex.b.e config -background white -state normal
					.mountit.ex.b.e insert 0 $smbmount_execute
				} else {
					.mountit.ex.b.c deselect
					.mountit.ex.b.e config -background grey70 -state disabled
				}
				if {$mount_fav_m($z,uid) != ""} {
					.mountit.midbox.c config -state normal
					.mountit.midbox.c select
					.mountit.botbox.two.u.e config -state normal -background white
					.mountit.botbox.two.g.e config -state normal -background white
					.mountit.botbox.four.f.e config -state normal -background white
					.mountit.botbox.four.d.e config -state normal -background white
					.mountit.botbox.two.u.e insert 0 $mount_fav_m($z,uid)
					.mountit.botbox.two.g.e insert 0 $mount_fav_m($z,gid)
					.mountit.botbox.four.f.e insert 0 $mount_fav_m($z,file)
					.mountit.botbox.four.d.e insert 0 $mount_fav_m($z,dir)
				}
				set found "yes"
				set z 999999
			}
			set z [expr $z + 1]
		}
	}
	if {$found == "no"} {
		.mountit.midbox.c deselect
		.mountit.ex.b.c deselect
		.mountit.ex.b.e config -background grey70 -state disabled
	}
	if {$found_default == "yes"} {
		if [info exists env(HOME)] {
			set mount_to_dir $env(HOME)
		} else {
			set mount_to_dir "/"
		}
		set spot [DefaultSpot $computer $share_m $mount_to_dir]
		.mountit.topbox.right.m.e insert 0 $spot
		set global_topbox $spot
	}
	tkwait visibility .mountit.b.buttons.cancel
	focus .mountit.topbox.right.m.e
	bind .mountit <KeyPress-Return> {
		.mountit.b.buttons.mount invoke
	}
	bind .mountit <KeyPress-Escape> {
		.mountit.b.buttons.cancel invoke
	}
	set password [.info.info0.stats get]
	set user_name [.info.info0.statU get]
	if [info exists env(USER)] {
		set env(USER) "$user_name%$password"
	} elseif [info exists env(LOGNAME)] {
		set env(LOGNAME) "$user_name%$password"
	} else {
		set env(USER) "$user_name%$password"
	}
	grab .mountit
	raise .mountit .
}


proc Explore {share} {
	#######################################
	global smbmount_tree
	global smbmount_execute
	global computer
	global computer_ip_num
	global workgroup
	global mount_fav_m
	global env
	global mount_version
	global env_name
	global password
	global user_name
	global override_mount
	global directory_a
	global history_m
	global place
	global canvason
	global mstatus
	global mount_refresh
	global explore_type
	if {$canvason == "off"} {return}
	.cscroll.c delete box
	DisableEnable 1 1 1 1 1 1 1 1 1 1 1 1
	if {$explore_type == "explore"} {
		set mount_path [string trimleft [.mstatus.info2.stats cget -text]]
		set comp_share [string trimleft $mstatus]
		if {[info exists computer] == 1 & [info exists share] == 1 && $comp_share == "//$computer/$share"} {
			ExploreDir $mount_path yes
		} else {
			ExploreDir $mount_path no
		}
		return
	}
	if [info exists env(HOME)] {
		set mount_to_dir $env(HOME)
	} else {
		set mount_to_dir "/"
	}
	set spot [DefaultSpot $computer $share $mount_to_dir]
	. config -cursor watch
	.info.info2.stats config -text "Mounting ... Please Wait."
	set mount_path [MakeDir "$spot" "check" "pass"]
	if {$mount_path == "get_thee_to_a_nunnery"} {
		.info.info2.stats config -text "Unable to create directory"
		if {$history_m($place,type) == "shares"} {
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		} else {
			DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
		}
		. config -cursor left_ptr
		return
	}
	set password [.info.info0.stats get]
	set user_name [.info.info0.statU get]
	if [info exists env(USER)] {
		set env(USER) "$user_name%$password"
	} elseif [info exists env(LOGNAME)] {
		set env(LOGNAME) "$user_name%$password"
	} else {
		set env(USER) "$user_name%$password"
	}
	if {$mount_version == 0} {
		spawn mount -t smbfs -o ip=$computer_ip_num,workgroup=$workgroup,guest,rw //$computer/$share $mount_path
	} elseif {$mount_version == 1} {
		spawn smbmount \\\\$computer\\$share $mount_path -o ip=$computer_ip_num,workgroup=$workgroup,rw
	} elseif {$mount_version == 2} {
		if {$user_name == "" & $password == "" } {
			spawn smbmount \\\\$computer\\$share $mount_path -I $computer_ip_num -N -W $workgroup
		} else {
			spawn smbmount \\\\$computer\\$share $mount_path -U $user_name -I $computer_ip_num -N -W $workgroup
		}
	} elseif {$mount_version == 5} {
		spawn mount_smbfs -I $computer_ip_num -W $workgroup //$user_name@$computer/$share $mount_path
	} elseif {$mount_version == 3} {
		if {$user_name == "" & $password == ""} {
			spawn smbmount \\\\$computer\\$share -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
		} else {
			spawn smbmount \\\\$computer\\$share -U $user_name -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
		}
	} else {
		if {$user_name == ""} {
			spawn smbmount \\\\$computer\\$share $mount_path -I $computer_ip_num -s $computer -D $workgroup
		} else {
			spawn smbmount \\\\$computer\\$share $mount_path -I $computer_ip_num -s $computer -D $workgroup -U $user_name
		}
	}
	set id $spawn_id
	set timeout 35
	expect {
		-i $id "Usage: smbmount" {
			set error_message "Bad Usage. Check setup for correct version of smbmount."
			close -i $id
		}
		-i $id "only root can do that" {
			set error_message "Only root can mount. Check permisions."
			close -i $id
		}
		-i $id "invalid option -- " {
			set error_message "Bad Usage. Check setup for correct version of smbmount."
			exp_continue
		}
		-i $id -indices -re " - (ERR\[^ ]+)" {
			set error_message [Error $expect_out(1,string)]
			exp_continue
		}
		-i $id "Error" {
			if [string match *Error* $mount_path] {
				exp_continue
			} else {
				set error_message "Unexpected Error"
				exp_continue
			}
		}
		-i $id "failed" {
			if [string match *failed* $mount_path] {
				exp_continue
			} else {
				set error_message "Connection failed"
				exp_continue
			}
		}
		-i $id "ERRDOS" {
			if [string match *ERRDOS* $mount_path] {
				exp_continue
			} else {
				set error_message "Error: ERRDOS"
				exp_continue
			}
		}
		-i $id "assword:" {
			exp_send -i $id "$password\r"
			exp_continue
		}
		-i $id timeout { close -i $id }
	}
	wait -i $id
	if [info exists error_message] {
		.info.info2.stats config -text $error_message
		unset error_message
		CheckMTAB
		set mount_refresh "refresh"
		ComputerShareClick "//$computer/$share"
		if {$history_m($place,type) == "shares"} {
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		} else {
			DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
		}
		. config -cursor left_ptr
		return
	} else {
		set z 1
		set mount_match "no"
		while {$z < [expr 1 + [array size mount_fav_m] / 14] & $mount_match == "no"} {
			if {$mount_fav_m($z,share) == "//$computer/$share"} {
				set mount_match $z
			}
			incr z
		}
		if {$mount_match == "no"} {
			set mount_match [expr 1 + [array size mount_fav_m] / 14]
		}
		set mount_fav_m($mount_match,share) "//$computer/$share"
		set mount_fav_m($mount_match,spot) "default"
		set mount_fav_m($mount_match,uid) ""
		set mount_fav_m($mount_match,gid) ""
		set mount_fav_m($mount_match,file) ""
		set mount_fav_m($mount_match,dir) ""
		set mount_fav_m($mount_match,execute) "yes"
		set mount_fav_m($mount_match,history) "yes"
		set mount_fav_m($mount_match,ip) "$computer_ip_num"
		set mount_fav_m($mount_match,username) "$user_name"
		set mount_fav_m($mount_match,password) "$password"
		set mount_fav_m($mount_match,netbios) "$computer"
		set mount_fav_m($mount_match,workgroup) "$workgroup"
		set mount_fav_m($mount_match,sharename) "$share"
		WriteUserFile
		.info.info2.stats config -text "Waiting 2 sec ..."
		after 2000 {set after_time 1}
		tkwait variable after_time
		.info.info2.stats config -text "Initializing Program ..."
		set directory [DirMaker /]
		if {$directory == "shares"} {set directory ""}
		set first [string first "\$MOUNTPOINT" $smbmount_execute]
		if {$first != "-1"} {
			set execute "exec [string range $smbmount_execute 0 [expr $first - 1]]\"$mount_path/$directory\"[string range $smbmount_execute\
			[expr $first + 11] [expr [string length $smbmount_execute] - 1]] &"
		} else {
			set execute "exec $smbmount_execute &"
		}
		eval $execute
		.info.info2.stats config -text ""
		CheckMTAB
		set mount_refresh "refresh"
		ComputerShareClick "//$computer/$share"
		if {$history_m($place,type) == "shares"} {
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		} else {
			DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
		}
		. config -cursor left_ptr
	}
}


proc ExploreDir {mount_path share_check} {
	###########################################
	global smbmount_tree
	global smbmount_execute
	global directory_a
	global history_m
	global share
	global place
	.info.info2.stats config -text "Initializing Program ..."
	if {$share_check == "yes"} {
		set directory [DirMaker /]
	} else {
		set directory ""
	}
	if {$directory == "shares"} {set directory ""}
	set first [string first "\$MOUNTPOINT" $smbmount_execute]
	if {$first != "-1"} {
		set execute "exec [string range $smbmount_execute 0 [expr $first - 1]]\"$mount_path/$directory\"[string range\
		$smbmount_execute [expr $first + 11] [expr [string length $smbmount_execute] - 1]] &"
	} else {
		set execute "exec $smbmount_execute &"
	}
	eval $execute
	.info.info2.stats config -text ""
	if {$history_m($place,type) == "shares"} {
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	} else {
		DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
	}
	. config -cursor left_ptr
}


proc DefaultSpot {computer share mount_to_dir} {
	#################################
	global smbmount_tree
	set first [string first "\$HOME" $smbmount_tree]
	if {$first != "-1"} {
		set tree "[string range $smbmount_tree 0 [expr $first - 1]]$mount_to_dir[string range $smbmount_tree [expr $first + 5]\
		[expr [string length $smbmount_tree] - 1]]"
	} else {
		set tree $smbmount_tree
	}
	set comp_share "$computer/$share"
	if {[string first " " $comp_share] != "-1"} {
		set length [string length $comp_share]
		set cs 0
		while {$cs < $length} {
			if {[string index $comp_share $cs] == " "} {
				set comp_share "[string range $comp_share 0 [expr $cs - 1]]_[string range $comp_share [expr $cs + 1] [expr $length - 1]]"
			}
			incr cs
		}
	}
	return "$tree/$comp_share"
}


proc MountHistory {} {
	#############################################
	global canvason
	global mount_fav_m
	global mount_refresh
	toplevel .mhist
	wm title .mhist "Mount History"
	frame .mhist.f1 -borderwidth 0
	pack .mhist.f1 -side top -fill both -expand yes
	frame .mhist.f1.f2 -borderwidth 0
	pack .mhist.f1.f2 -side left -fill both -expand yes
	frame .mhist.f1.f2.f2 -borderwidth 0
	pack .mhist.f1.f2.f2 -side top -fill x
	frame .mhist.f1.f2.f1 -borderwidth 0
	pack .mhist.f1.f2.f1 -side top -fill both -expand yes
	frame .mhist.f1.f3 -borderwidth 0
	pack .mhist.f1.f3 -side top
	button .mhist.f1.f3.b1 -highlightthickness 0 -text "Mount All" -width 10\
	-command {
		if [info exists mount_fav_reference] {
			MountHistoryDisable disable
			if [info exists env(USER)] {
				set user_temp $env(USER)
			} elseif [info exists env(LOGNAME)] {
				set user_temp $env(LOGNAME)
			} else {
				set user_temp $env(USER)
			}
			set mount_history_item 0
			while {$mount_history_item < [array size mount_fav_reference]} {
				if {[.mhist.f1.f2.f1.lb5 get $mount_history_item $mount_history_item] != "\{ Yes\}"} {
					if [info exists env(USER)] {
						set env(USER) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
					} elseif [info exists env(LOGNAME)] {
						set env(LOGNAME) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
					} else {
						set env(USER) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
					}
					catch [MountHistoryMount $mount_history_item [string trimleft [lindex [.mhist.f1.f2.f1.lb1 get $mount_history_item $mount_history_item] 0]]]
				}
				incr mount_history_item
			}
			set mount_refresh "refreshAll"
			if [info exists env(USER)] {
				set env(USER) $user_temp
			} elseif [info exists env(LOGNAME)] {
				set env(LOGNAME) $user_temp
			} else {
				set env(USER) $user_temp
			}
			MountHistoryDisable normal
		}
	}
	button .mhist.f1.f3.b9 -highlightthickness 0 -text "Unmount All" -width 10\
	-command {
		if [info exists mount_fav_reference] {
			MountHistoryDisable disable
			set mount_history_item 0
			while {$mount_history_item < [array size mount_fav_reference]} {
				if {[.mhist.f1.f2.f1.lb5 get $mount_history_item $mount_history_item] == "\{ Yes\}"} {
					catch [MountHistoryUnmount [string trimleft [lindex [.mhist.f1.f2.f1.lb1 get $mount_history_item $mount_history_item] 0]]]
				}
				incr mount_history_item
			}
			set mount_refresh "refreshAll"
			MountHistoryDisable normal
		}
	}
	button .mhist.f1.f3.b3 -highlightthickness 0 -text "Remove" -width 10\
	-command {
		set mount_history_item [.mhist.f1.f2.f1.lb0 curselection]
		if {$mount_history_item != ""} {
			set mount_fav_m($mount_fav_reference($mount_history_item),history) "no"
			WriteUserFile
			set mount_refresh "refresh"
		}
	}
	button .mhist.f1.f3.b4 -highlightthickness 0 -text "Mount"\
	-width 10 -command {
		set mount_history_item [.mhist.f1.f2.f1.lb0 curselection]
		if {$mount_history_item != ""} {
			MountHistoryDisable disable
			if [info exists env(USER)] {
				set user_temp $env(USER)
				set env(USER) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
			} elseif [info exists env(LOGNAME)] {
				set user_temp $env(LOGNAME)
				set env(LOGNAME) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
			} else {
				set user_temp $env(USER)
				set env(USER) "$mount_fav_m($mount_fav_reference($mount_history_item),username)%$mount_fav_m($mount_fav_reference($mount_history_item),password)"
			}
			MountHistoryMount $mount_history_item [string trimleft [lindex [.mhist.f1.f2.f1.lb1 get $mount_history_item $mount_history_item] 0]]
			set mount_refresh "refreshAll"
			if [info exists env(USER)] {
				set env(USER) $user_temp
			} elseif [info exists env(LOGNAME)] {
				set env(LOGNAME) $user_temp
			} else {
				set env(USER) $user_temp
			}
			MountHistoryDisable normal
		}
	}
	button .mhist.f1.f3.b5 -highlightthickness 0 -text "Unmount" -width 10\
	-command {
		set mount_history_item [.mhist.f1.f2.f1.lb0 curselection]
		if {$mount_history_item != ""} {
			MountHistoryDisable disable
			MountHistoryUnmount [string trimleft [lindex [.mhist.f1.f2.f1.lb1 get $mount_history_item $mount_history_item] 0]]
			set mount_refresh "refreshAll"
		}
	}
	button .mhist.f1.f3.b7 -highlightthickness 0 -text "Close" -width 10\
	-command {
		destroy .mhist
	}
	button .mhist.f1.f3.b8 -highlightthickness 0 -text "Refresh" -width 10\
	-command {
		set mount_refresh "refreshAll"
	}
	pack .mhist.f1.f3.b1 .mhist.f1.f3.b9 .mhist.f1.f3.b4 .mhist.f1.f3.b5 .mhist.f1.f3.b3 .mhist.f1.f3.b8 .mhist.f1.f3.b7 -side top
	label .mhist.f1.f2.f2.l1 -borderwidth 0 -padx 2 -width 30 -anchor w -text " Share Source"
	label .mhist.f1.f2.f2.l3 -borderwidth 0 -padx 2 -width 30 -anchor w -text " Mount Point"
	label .mhist.f1.f2.f2.l2 -borderwidth 0 -padx 2 -width 10 -anchor w -text " Mounted"
	pack .mhist.f1.f2.f2.l1 .mhist.f1.f2.f2.l2 -side left
	pack .mhist.f1.f2.f2.l3 -side left -fill x -expand yes
	listbox .mhist.f1.f2.f1.lb0 -height 1 -width 30 -takefocus 1 -cursor right_ptr -foreground black -background white\
	-borderwidth 1 -selectmode single -selectborderwidth 0
	listbox .mhist.f1.f2.f1.lb5 -height 1 -width 10 -takefocus 1 -cursor right_ptr -selectbackground white -foreground black -background white\
	-borderwidth 1 -selectmode single -selectborderwidth 0
	listbox .mhist.f1.f2.f1.lb1 -height 1 -takefocus 1 -width 30 -cursor right_ptr -selectbackground white -foreground black -background white\
	-borderwidth 1 -selectmode single -selectborderwidth 0 -yscrollcommand [list .mhist.f1.f2.f1.sb1 set]
	scrollbar .mhist.f1.f2.f1.sb1 -borderwidth 2 -orient vertical -command [list .mhist.f1.f2.f1.lb1 yview]
	pack  .mhist.f1.f2.f1.lb0 .mhist.f1.f2.f1.lb5 -side left -fill both
	pack  .mhist.f1.f2.f1.lb1 -side left -fill both -expand yes
	pack .mhist.f1.f2.f1.sb1 -side right -fill y
	tkwait visibility .mhist.f1.f2.f1.sb1
	bind .mhist.f1.f2.f1.sb1 <ButtonRelease-1> {.mhist.f1.f2.f1.lb0 yview moveto [lindex [.mhist.f1.f2.f1.sb1 get] 0];.mhist.f1.f2.f1.lb1 yview moveto\
		[lindex [.mhist.f1.f2.f1.sb1 get] 0];.mhist.f1.f2.f1.lb5 yview moveto [lindex [.mhist.f1.f2.f1.sb1 get] 0]}
	bind .mhist.f1.f2.f1.lb0 <ButtonRelease-1> {MountHistoryButtons 0 [.mhist.f1.f2.f1.lb0 curselection]}
	bind .mhist.f1.f2.f1.lb1 <ButtonRelease-1> {MountHistoryButtons 1 [.mhist.f1.f2.f1.lb1 curselection]}
	bind .mhist.f1.f2.f1.lb5 <ButtonRelease-1> {MountHistoryButtons 5 [.mhist.f1.f2.f1.lb5 curselection]}
	.mstatus.buttons.history config -state disabled
	bind .mhist <Destroy> { .mstatus.buttons.history config -state normal; set mount_refresh "stop"}
	bind .mhist <KeyPress-Escape> {destroy .mhist}
	MountHistoryRefresh
	set mount_refresh "refresh"
	while {$mount_refresh != "stop"} {
		tkwait variable mount_refresh
		if {$mount_refresh == "refreshAll"} {
			ReadUserFile
			CheckMTAB
			MountHistoryRefresh
		} elseif {$mount_refresh == "refresh"} {
			MountHistoryRefresh
		}
	}
}


proc MountHistoryDisable {state} {
	############################
	if {$state == "disabled"} {
		.mhist.f1.f3.b1 config -state disabled
		.mhist.f1.f3.b4 config -state disabled
		.mhist.f1.f3.b5 config -state disabled
		.mhist.f1.f3.b3 config -state disabled
		.mhist.f1.f3.b8 config -state disabled
		.mhist.f1.f3.b7 config -state disabled
	} else {
		.mhist.f1.f3.b1 config -state normal
		.mhist.f1.f3.b4 config -state normal
		.mhist.f1.f3.b5 config -state normal
		.mhist.f1.f3.b3 config -state normal
		.mhist.f1.f3.b8 config -state normal
		.mhist.f1.f3.b7 config -state normal
	}
}


proc MountHistoryRefresh {} {
	##########################
	global mount_fav_m
	global mount_fav_reference
	global env
	if ![winfo exists .mhist] {return}
	if [info exists env(HOME)] {
		set mount_to_dir $env(HOME)
	} else {
		set mount_to_dir "/"
	}
	.mhist.f1.f2.f1.lb0 delete 0 end
	.mhist.f1.f2.f1.lb1 delete 0 end
	.mhist.f1.f2.f1.lb5 delete 0 end
	set m 1
	set reference 0
	if [info exists mount_fav_reference] {
		unset mount_fav_reference
	}
	while {$m < [expr [array size mount_fav_m] / 14 + 1]} {
		if {$mount_fav_m($m,history) == "yes"} {
			.mhist.f1.f2.f1.lb0 insert [expr $m - 1] " $mount_fav_m($m,share)"
			if {$mount_fav_m($m,spot) == "default"} {
				.mhist.f1.f2.f1.lb1 insert [expr $m - 1] " [DefaultSpot $mount_fav_m($m,netbios) $mount_fav_m($m,sharename) $mount_to_dir]"
			} else {
				.mhist.f1.f2.f1.lb1 insert [expr $m - 1] " $mount_fav_m($m,spot)"
			}
			if {[UnmountCheck "$mount_fav_m($m,share)"] == "no"} {
				.mhist.f1.f2.f1.lb5 insert [expr $m - 1] " No"
			} else {
				.mhist.f1.f2.f1.lb5 insert [expr $m - 1] " Yes"
			}
			set mount_fav_reference($reference) $m
			incr reference
		}
		incr m
	}
	if {$reference > 0} {
		MountHistoryButtons 1 0
	}
}


proc MountHistoryButtons {list listnum} {
	#################################
	if {$list != "0"} {
		.mhist.f1.f2.f1.lb0 selection set $listnum $listnum
	}
	set status [.mhist.f1.f2.f1.lb5 get $listnum $listnum]
	if {$status == "\{ Yes\}"} {
		.mhist.f1.f3.b4 config -state disabled
		.mhist.f1.f3.b5 config -state normal
	} else {
		.mhist.f1.f3.b4 config -state normal
		.mhist.f1.f3.b5 config -state disabled
	}
}


proc MountHistoryUnmount {mount_dir} {
	#######################################
	# first I try smbumount, if fail, I then try plain-old umount
	if [catch [exec smbumount $mount_dir]] {
		exec umount $mount_dir
	}
}


proc MountHistoryMount {item mount_path} {
	########################
	global mount_fav_reference
	global mount_fav_m
	global mount_version
	set user_name $mount_fav_m($mount_fav_reference($item),username)
	set mount_uid $mount_fav_m($mount_fav_reference($item),uid)
	set mount_gid $mount_fav_m($mount_fav_reference($item),gid)
	set mount_file $mount_fav_m($mount_fav_reference($item),file)
	set mount_dir $mount_fav_m($mount_fav_reference($item),dir)
	set computer_ip_num $mount_fav_m($mount_fav_reference($item),ip)
	set workgroup $mount_fav_m($mount_fav_reference($item),workgroup)
	set computer $mount_fav_m($mount_fav_reference($item),netbios)
	set share_m $mount_fav_m($mount_fav_reference($item),sharename)
	set password $mount_fav_m($mount_fav_reference($item),password)
	if {$mount_uid == ""} {
		set override_mount "no"
	} else {
		set override_mount "yes"
	}
	if {$mount_version == 0} {
		if {$override_mount == "yes"} {
			exec mount -t smbfs \
			-o uid=$mount_uid,gid=$mount_gid,fmask=$mount_file,dmask=$mount_dir,ip=$computer_ip_num,workgroup=$workgroup,guest,rw //$computer/$share_m $mount_path
		} else {
			exec mount -t smbfs -o ip=$computer_ip_num,workgroup=$workgroup,guest,rw //$computer/$share_m $mount_path
		}
	} elseif {$mount_version == 1} {
		if {$override_mount == "yes"} {
			exec smbmount \\\\$computer\\$share_m $mount_path \
			-o uid=$mount_uid,gid=$mount_gid,fmask=$mount_file,dmask=$mount_dir,ip=$computer_ip_num,workgroup=$workgroup,guest,rw
		} else {
			exec smbmount \\\\$computer\\$share_m $mount_path -o ip=$computer_ip_num,workgroup=$workgroup,guest,rw
		}
	} elseif {$mount_version == 5} {
		if {$override_mount == "yes"} {
			exec mount_smbfs -I $computer_ip_num -W $workgroup -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir  //$user_name@$computer/$share_m $mount_path
		} else {
			exec mount_smbfs -I $computer_ip_num -W $workgroup //$user_name@$computer/$share_m $mount_path
		}
	} elseif {$mount_version == 2} {
		if {$user_name == "" & $password == "" } {
			exec smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -N -W $workgroup
		} else {
			exec smbmount \\\\$computer\\$share_m $mount_path -U $user_name -I $computer_ip_num -N -W $workgroup
		}
	} elseif {$mount_version == 3} {
		if {$override_mount == "yes"} {
			if {$user_name == "" & $password == ""} {
				exec smbmount \\\\$computer\\$share_m -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\"\
				-u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir"
			} else {
				exec smbmount \\\\$computer\\$share_m -U $user_name -I $computer_ip_num -N -W $workgroup\
				-c "mount \"$mount_path\" -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir"
			}
		} else {
			if {$user_name == "" & $password == ""} {
				exec smbmount \\\\$computer\\$share_m -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
			} else {
				exec smbmount \\\\$computer\\$share_m -U $user_name -I $computer_ip_num -N -W $workgroup -c "mount \"$mount_path\""
			}
		}
	} else {
		if {$override_mount == "yes"} {
			if {$user_name == ""} {
				exec smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup\
				-u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir
			} else {
				exec smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup\
				-U $user_name -u $mount_uid -g $mount_gid -f $mount_file -d $mount_dir
			}
		} else {
			if {$user_name == ""} {
				exec smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup
			} else {
				exec smbmount \\\\$computer\\$share_m $mount_path -I $computer_ip_num -s $computer -D $workgroup -U $user_name
			}
		}
	}
}


##
# This is where execution first begins (the above is all procedures)

if [info exists env(USER)] {
	set env_name $env(USER)
} elseif [info exists env(LOGNAME)] {
	set env_name $env(LOGNAME)
} else {
	set env_name "GUEST"
}

set readfmt "\[+\] %-62s"
ReadSmbConf
UserFileExist
ReadUserFile
if {$image_path != "Use Geo"} {
	ReadImages
}
set password ""
set m_working 0
set user_name ""
set box_select "no"
set box_sel "delete"
set explore_type "mount"
set file_queue_write_wait 0
set place 0
set place_local(pointer) 1
set place_local(length) 0
set checker 0
set helpincr 1
set upload_incr 1
set tar_incr 1
set saver_incr 1
set canvason "on"
set fav_edit "off"
set net_edit "off"
set save_on "yes"
set win_id 0
wm title . "xSMBrowser 3.4.0"
frame .top -borderwidth 0
frame .top.top1 -borderwidth 0
frame .top.top2 -borderwidth 0
frame .top.top3 -borderwidth 0
frame .top.top4 -borderwidth 0
button .top.top1.favorites -highlightthickness 0 -relief groove -command {
	.info.info2.stats config -text ""
	. config -cursor left_ptr
	.status.stats config -text ""
	if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;.mstatus.buttons.unmount\
		config -state disabled}
	if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;.mstatus.info2.stats\
		config -text ""}
	.info.info0.stats delete 0 1024
	.info.info0.statU delete 0 1024
	DisplayOnCanvas "favorites" [expr [array size favorites_m] / 8] "" 0
	if [info exists favorites_m] {HistoryAdd "favorites" "" ""}
	DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
}
button .top.top1.networks -highlightthickness 0 -relief groove -command {
	.info.info2.stats config -text ""
	. config -cursor left_ptr
	.status.stats config -text ""
	if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;.mstatus.buttons.unmount\
		config -state disabled}
	if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;.mstatus.info2.stats config\
		-text ""}
	.info.info0.stats delete 0 1024
	.info.info0.statU delete 0 1024
	DisplayOnCanvas "networks" [expr [array size networks_m] / 6] "" 0
	if [info exists networks_m] {HistoryAdd "networks" "" ""}
	DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
}
button .top.top1.workgroups -highlightthickness 0 -relief groove -command {
	.info.info2.stats config -text ""
	. config -cursor left_ptr
	.status.stats config -text ""
	if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;.mstatus.buttons.unmount\
		config -state disabled}
	if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;.mstatus.info2.stats\
		config -text ""}
	.info.info0.stats delete 0 1024
	.info.info0.stats insert 0 $default_password
	.info.info0.statU delete 0 1024
	.info.info0.statU insert 0 $default_user_name
	DisplayOnCanvas "workgroups" [expr [array size workgroups_m] / 2] "" 0
	HistoryAdd "workgroups" [expr [array size workgroups_m] / 2] ""
	DisableEnable 0 0 0 1 0 0 1 1 1 1 0 0
}
button .top.top2.back -highlightthickness 0 -relief groove -command {HistoryCall -1 local}
button .top.top3.forward -highlightthickness 0 -relief groove -command {HistoryCall 1 local}
button .top.top4.stop -highlightthickness 0 -relief groove -command {
	if [catch {eval {exec kill -s SIGTERM} $spawn_pid}] {
		. config -cursor left_ptr
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
	}
	set stop_now "now"
}
button .top.top4.refresh -highlightthickness 0 -relief groove -command {
	.info.info2.stats config -text "Working ..."
	. config -cursor watch
	if {$history_m($place,type) == "shares"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set password [.info.info0.stats get]
		set user_name [.info.info0.statU get]
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		if [array exists shares_m] {unset shares_m}
		SmbClientList $computer $computer_ip_num shares_only $workgroup
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
		if {[expr [array size shares_m] / 3] != 0} {
			.status.stats config -text " Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
			set place [expr $place - 1]
			HistoryAdd "shares" [expr [array size shares_m] / 3] ""
			DisplayOnCanvas "shares" [expr [array size shares_m] / 3] "" 0
			DisableEnable 0 0 0 0 0 0 1 0 1 1 0 0
		} else {
			set l 0
			while {$l < $history_m($place,length)} {
				set shares_m($l,1) $history_m($place,$l,1)
				set shares_m($l,2) $history_m($place,$l,2)
				set shares_m($l,3) $history_m($place,$l,3)
				incr l
			}
			DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		}
	} elseif {$history_m($place,type) == "computers"} {
		if [info exists computers_m] {unset computers_m}
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set password [.info.info0.stats get]
		set user_name [.info.info0.statU get]
		if [info exists env(USER)] {
			set env(USER) "$user_name%$password"
		} elseif [info exists env(LOGNAME)] {
			set env(LOGNAME) "$user_name%$password"
		} else {
			set env(USER) "$user_name%$password"
		}
		if {$net_type == "wins"} {
			SmbClientList $wins_domain_master $wins_domain_master_ip computers_only $workgroup
		} elseif {$net_type == "broadcast"} {
			SmbClientList $broadcast_master $broadcast_master_ip_num computers_only $workgroup
		} else {
			if ![file exists $history_m($place,broadcast_subnet)] {
				.info.info2.stats config -text "File \"$history_m($place,broadcast_subnet)\" Does Not Exist"
				. config -cursor left_ptr
				DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
				return
			}
			set ipfile [open $history_m($place,broadcast_subnet) r]
			gets $ipfile line
			set r 0
			set eof_check 0
			while {$line != "-1" & $eof_check != 5 & [eof $ipfile] == "0"} {
				if [string match *\ * $line] {
				      set computers_m($r,1) [string range $line 0 [expr [string first " " $line] - 1]]
				      set computers_m($r,2) [string range $line [string first " " $line] [expr [string length $line] - 1]]
				} else {
					set computers_m($r,1) $line
					set computers_m($r,2) " "
					if { $line == "" } { incr eof_check }
				}
				gets $ipfile line
				incr r
			}
			close $ipfile
		}
		if {$mount_addon == "yes"} {set mstatus "";.mstatus.buttons.mount config -state disabled;\
			.mstatus.buttons.unmount config -state disabled}
		if {$mount_addon == "yes"} {.mstatus.buttons.explore config -state disabled;.mounted.list selection clear 0 999;\
			.mstatus.info2.stats config -text ""}
		if {[expr [array size computers_m] / 2] != 0} {
			.status.stats config -text " Workgroup: $workgroup"
			set place [expr $place - 1]
			HistoryAdd "computers" [expr [array size computers_m] / 2] ""
			DisplayOnCanvas "computers" [expr [array size computers_m] / 2] "" 0
		} else {
			set l 0
			while {$l < $history_m($place,length)} {
				set computers_m($l,1) $history_m($place,$l,1)
				set computers_m($l,2) $history_m($place,$l,2)
				incr l
			}
			. config -cursor left_ptr
		}
		DisableEnable 0 0 0 1 0 0 1 0 1 1 0 0
		if [info exists directory_a(1)] {unset directory_a(1) }
	} elseif {$history_m($place,type) == "files"} {
		DisableEnable 1 1 1 1 1 1 0 1 1 1 1 1
		set check $checker
		if [info exists history_m($place,directory)] {
			set dir_f $history_m($place,directory)
			SmbClientFiles $computer $computer_ip_num $share $history_m($place,directory) $workgroup
		} else {
			set dir_f ""
			SmbClientFiles $computer $computer_ip_num $share "" $workgroup
		}
		if {$check != $checker} {
			if {[expr $checker - $check] == "2"} {
				set place [expr $place - 1]
				DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
				return
			}
			if ![info exists directory_a(1)] {
				set directory_a(1) $history_m($place,directory_a,1)
			} elseif {$directory_a(1) == "shares"} {
				unset directory_a
			} else {
				set directory_a($history_m($place,directory_a,length)) $history_m($place,directory_a,$history_m($place,directory_a,length))
			}
			DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
			return
		}
		.status.stats config -text " Dir: \\$dir_f  Share: $share  Computer: $computer  Workgroup: $workgroup  IP: $computer_ip_num"
		if {$mount_addon == "yes"} {set mstatus " //$computer/$share"}
		if {$mount_addon == "yes"} {.mounted.list selection clear 0 999;ComputerShareClick "//$computer/$share"}
		set place [expr $place - 1]
		HistoryAdd "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3]
		DisplayOnCanvas "files" [expr [array size files_m] / 3 + [array size folders_m] / 3] [expr [array size folders_m] / 3] 0
		DisableEnable 0 0 0 0 0 0 1 0 0 0 0 0
	} else {
		if {$history_m($place,type) != "workgroups"} {
			UserFileExist
			ReadUserFile
		}
		HistoryCall 0 local
	}
	if {$mount_addon == "yes"} {
		CheckMTAB
		set mount_refresh "refresh"
	}
}
pack .top -side top -fill x
pack .top.top2 .top.top3 .top.top4 .top.top1 -side left -fill x
frame .mstatus -borderwidth 0
if {$mount_addon == "yes"} {pack .mstatus -side bottom -fill x}
frame .mstatus.buttons -borderwidth 0
frame .mstatus.info1 -borderwidth 0
frame .mstatus.info2 -borderwidth 0
if {$mount_addon == "yes"} {pack .mstatus.info1 -fill both -side left}
if {$mount_addon == "yes"} {pack .mstatus.buttons -fill x -side left}
if {$mount_addon == "yes"} {pack .mstatus.info2 -fill both -expand yes -side left}
button .mstatus.buttons.explore -highlightthickness 0 -relief groove -command {
	if [info exists share] {
		Explore $share
	} else {
		Explore sdf
	}
}
button .mstatus.buttons.mount -highlightthickness 0 -relief groove -command {Mount $share}
button .mstatus.buttons.unmount -highlightthickness 0 -relief groove -command {UnMount [string trimleft [.mstatus.info2.stats cget -text]]}
button .mstatus.buttons.history -highlightthickness 0 -relief groove -command {
	MountHistory
}
label .mstatus.info2.stats -borderwidth 1 -pady 3 -width 1 -anchor w -relief sunken -text ""
if {$mount_addon == "yes"} {
	pack .mstatus.info2.stats -fill both -expand yes -side left
	pack .mstatus.buttons.history .mstatus.buttons.explore .mstatus.buttons.mount .mstatus.buttons.unmount -side left
}
frame .status -borderwidth 0
pack .status -side top -fill x
label .status.stats -borderwidth 1 -anchor w -width 10 -relief sunken -text ""
pack .status.stats -side left -fill x -expand yes
frame .mounted -borderwidth 0
listbox .mounted.list -width 30 -height 3 -foreground black -takefocus 1 -background white -borderwidth 1 -selectmode single\
-selectborderwidth 0
listbox .mounted.list2 -width 30 -height 3 -selectbackground white -foreground black -background white -borderwidth 1 -selectmode single\
-selectborderwidth 0 -yscrollcommand [list .mounted.yscroll set]
scrollbar .mounted.yscroll -borderwidth 2 -orient vertical -command [list .mounted.list2 yview]
bind .mounted.yscroll <ButtonRelease-1> {.mounted.list yview moveto [lindex [.mounted.yscroll get] 0];.mounted.list2 yview moveto\
	[lindex [.mounted.yscroll get] 0]}
if {$mount_addon == "yes"} {pack .mounted.yscroll -side right -fill y}
if {$mount_addon == "yes"} {pack .mounted.list -side left -fill both}
if {$mount_addon == "yes"} {pack .mounted.list2 -side left -fill both -expand yes}
if {$mount_addon == "yes"} {pack .mounted -side bottom -fill both}
bind .mounted.list <ButtonRelease-1> {MountedBoxClick [.mounted.list curselection]}
bind .mounted.list2 <ButtonRelease-1> {MountedBoxClick [.mounted.list2 curselection]}
.mounted.list config -cursor right_ptr
.mounted.list2 config -cursor right_ptr
frame .cscroll -borderwidth 0
canvas .cscroll.c -width 1 -height 180 -xscrollincrement 50 -background white -scrollregion {0 0 1000 0} -xscrollcommand\
[list .cscroll.xscroll set]
scrollbar .cscroll.xscroll -borderwidth 2 -orient horizontal -command [list .cscroll.c xview]
pack .cscroll.xscroll -side bottom -fill x
pack .cscroll.c -side left -fill both -expand yes
pack .cscroll -side top -fill both -expand yes
bind .cscroll.xscroll <Button-1> {.cscroll.c delete box}
frame .title -borderwidth 0
if {$mount_addon == "yes"} {pack .title -side bottom -fill x}
label .title.stat1 -borderwidth 0 -padx 2 -width 30 -anchor w -text " Share Source"
label .title.stat2 -borderwidth 0 -padx 2 -width 30 -anchor w -text " Mount Point"
if {$mount_addon == "yes"} {pack .title.stat1 -side left -fill x}
if {$mount_addon == "yes"} {pack .title.stat2 -side left -fill x -expand yes}
frame .bottom -borderwidth 0
pack .bottom -side bottom -fill x
button .bottom.saveto -highlightthickness 0 -relief groove -command {SaveDialog 0}
button .bottom.favorite -highlightthickness 0 -relief groove -command {AddFavDialog add}
button .bottom.network -highlightthickness 0 -relief groove -command {AddNetworkDialog add}
button .bottom.filequeue -highlightthickness 0 -relief groove -command {
	if [winfo exists .file] {
		focus .file
		raise .file .
	} else {
		FileQueue ""
	}
}
button .bottom.setup -highlightthickness 0 -relief groove -command {SetupDialog}
button .bottom.help -highlightthickness 0 -relief groove -command {HelpDialog}
button .bottom.exit -highlightthickness 0 -relief groove -command exit
frame .info -borderwidth 0
frame .info.info0 -borderwidth 0
frame .info.info1 -borderwidth 0
frame .info.info2 -borderwidth 0
pack .info -side bottom -fill x
pack .info.info0 .info.info1 -fill x -side left
pack .info.info2 -fill x -expand yes -side left
label .info.info0.t -borderwidth 1 -anchor e -relief sunken -width 10 -text "User/Pass:"
entry .info.info0.statU -borderwidth 1 -relief sunken -width 8
entry .info.info0.stats -borderwidth 1 -relief sunken -width 8 -show "*"
label .info.info1.stats -borderwidth 1 -anchor w -relief sunken -width 26 -text ""
label .info.info2.stats -borderwidth 1 -anchor center -relief sunken -width 1 -text ""
pack .info.info0.t .info.info0.statU .info.info0.stats .info.info1.stats -fill x -side left
pack .info.info2.stats -fill x -expand yes -side left
if {$image_path != "Use Geo" & $pixmaps_buttons == "yes"} {
	.top.top1.favorites config -relief flat -image favorites_c
	.top.top1.networks config -relief flat -image networks_c
	.top.top1.workgroups config -relief flat -image workgroups_c
	.top.top2.back config -relief flat -image back_c
	.top.top3.forward config -relief flat -image forward_c
	.top.top4.stop config -relief flat -image stop_c
	.top.top4.refresh config -relief flat -image refresh_c
	.bottom.saveto config -relief flat -image transfer_c
	.bottom.favorite config -relief flat -image favorite_c
	.bottom.network config -relief flat -image network_c
	.bottom.filequeue config -relief flat -image queue_c
	.bottom.setup config -relief flat -image setup_c
	.bottom.help config -relief flat -image help_c
	.bottom.exit config -relief flat -image exit_c
	.bottom config -relief flat -borderwidth 0
	.mstatus.buttons.explore config -relief flat -image explore_c
	.mstatus.buttons.mount config -relief flat -image mount_c
	.mstatus.buttons.unmount config -relief flat -image unmount_c
	.mstatus.buttons.history config -relief flat -image history_c
	.mstatus.buttons config -relief flat -borderwidth 0
} else {
	.top.top1.favorites config -width 8 -pady 4 -height 3 -text Favorites
	.top.top1.networks config -width 8 -pady 4 -height 3 -text Networks
	.top.top1.workgroups config -width 8 -pady 4 -height 3 -text Workgroups
	.top.top2.back config -width 8 -pady 4 -height 3 -text Back
	.top.top3.forward config -width 8 -pady 4 -height 3 -text Forward
	.top.top4.stop config -width 8 -pady 4 -height 3 -text Stop
	.top.top4.refresh config -width 8 -pady 4 -height 3 -text Refresh
	.bottom.saveto config -width 8 -text Transfer
	.bottom.favorite config -width 8 -text "+ Favorite"
	.bottom.network config -width 8 -text "+ Network"
	.bottom.filequeue config -width 8 -text "File Queue"
	.bottom.setup config -width 8 -text Setup
	.bottom.help config -width 8 -text Help
	.bottom.exit config -width 8 -text Exit
	.mstatus.buttons.explore config -width 8 -text Explore
	.mstatus.buttons.mount config -width 8 -text Mount
	.mstatus.buttons.unmount config -width 8 -text Unmount
	.mstatus.buttons.history config -width 8 -text History
}
pack .top.top1.workgroups .top.top1.networks .top.top1.favorites -side left
pack .top.top2.back -side top
pack .top.top3.forward -side top
pack .top.top4.stop .top.top4.refresh -side left
pack .bottom.saveto .bottom.favorite .bottom.network .bottom.filequeue .bottom.setup .bottom.help .bottom.exit -side left
tkwait visibility .info.info2.stats
.top.top1.networks invoke
.mstatus.buttons.explore config -state disabled
.mstatus.buttons.mount config -state disabled
.mstatus.buttons.unmount config -state disabled
DisableEnable 0 0 0 1 1 1 1 0 1 1 0 0
if {$show_next_time != "full"} {
	GPLDialog
}
if {$mount_addon == "yes"} {CheckMTAB}
bind . <KeyPress-Left> {.cscroll.c xview scroll -1 pages}
bind . <KeyPress-Right> {.cscroll.c xview scroll +1 pages}
set resize_on "no"
bind . <Configure> {
	if { $resize_on == "no" } {
		set resize_on "yes"
		set resize_rows [expr [winfo height .cscroll.c] / 20 - 1]
		after 1000 {set after_time 1}
		tkwait variable after_time
		if {$canvason == "on" & [expr [winfo height .cscroll.c] / 20 - 1] != $resize_rows} {
			HistoryCall 0 local
		}
		set resize_on "no"
	}
}
