on openTerminal(location, remoteHost, serverPort, u, pass)
	
	tell application "Terminal"
		activate
		
		set targetTab to ""
		set sshCommand to ""

		if ((count of remoteHost) is greater than 0) then
			set cdCommand to " 'cd \"" & location & "\"; eval \"$SHELL -il\"'"
			set sshCommand to "ssh -t " & "'"

			if ((count of u) is greater than 0) then
				set sshCommand to sshCommand & u & "@" & remoteHost
			else
				set sshCommand to sshCommand & remoteHost
			end if

			set sshCommand to sshCommand & "'"
		else
			set cdCommand to "cd \"" & location & "\""
		end if

		if (serverPort is greater than 0) then
			set sshCommand to sshCommand & " -p " & serverPort
		end if

		if ((count of location) is greater than 0) then
			set sshCommand to sshCommand & cdCommand
		end if

		if ((count of sshCommand) is greater than 0) then
			set targetTab to do script sshCommand
		end if
		
	end tell
	
end openTerminal
