def onDropOnItem( book, item ):
	if not isrunebook( book ):
		return False
	if not isrune( item ):
		return False
	if( item.hastag( "marked" ) != 1 ):
		return False

	# initialize rune serials to -1 if there's no rune
	# should not occur - will be removed later
	for i in range( 0, 16 ):
		if not book.hastag( "rune %i" % i ):
			book.settag( "rune %i" % i, -1 )

	# rune serials
	runes = [ -1 ] * 16
	for i in range( 0, 16 ):
		runes[ i ] = int( book.gettag( "rune %i" % i ) )
	i = 0
	while( runes[ i ] > -1 and i < 16 ):
		i = i + 1
	# runebook is full
	if( i > 15 ):
		# can we access the char.socket ?
		# "This runebook is full."
		#char.socket.clilocmessage( 502401 )
		return False
	book.settag( "rune %i" % i, int( item.serial ) )
	# insert rune - is runebook a container ?
	if book.type == 1:
		wolfpack.utilities.tocontainer( item, book )
		item.update()
	return True
def sendGump( char, item ):
	char.socket.closegump( 0x87654322 )
	char.soundeffect( 0x55 )

	runebook = cGump( 0, 0, 0, 100, 120 )

	runebook.startPage( 0 )
	runebook.addGump( 100, 10, 2200 )

	# decoration bar
	n = 125
	m = 0
	for i in range( 0, 16 ):
		if( i == 8 ):
			n = 170
		if( i % 8 == 0 ):
			m = 57
		elif( i % 8 == 7 ):
			m = 59
		else:
			m = 58
		runebook.addGump( n + i * 15, 50, m )

	# page number button at the bottom of the book
	for i in range( 0, 8 ):
		j = i / 4
		runebook.addPageButton( 130 + i * 35 + j * 30, 187, i + 2225, i + 2225, i + 2 )

	# charge / max charge
	if not item.hastag( "charges" ):
		item.settag( "charges", 0 )
	charges = item.gettag( "charges" )
	if not item.hastag( "maxcharges" ):
		item.settag( "maxcharges", 5 )
	maxcharges = item.gettag( "maxcharges" )
	runebook.addText( 160, 40, "Charges: %i" % charges )
	runebook.addText( 300, 40, "Max Charges: %i" % maxcharges )

	runebook.startPage( 1 )

	# rename button return code = 1000
	runebook.addButton( 130, 20, 2472, 2473, 1000 )
	runebook.addText( 158, 22, "Rename Book" )

	# next page - top right corner
	runebook.addPageButton( 393, 14, 2206, 2206, 2 )

	# get rune serials and names
	runes = [ -1 ] * 16
	for i in range( 0, 16 ):
		if not item.hastag( "rune %i" % i ):
			item.settag( "rune %i" % i, int( runes[ i ] ) )
		else:
			runes[ i ] = int( item.gettag( "rune %i" % i ) )
	runenum = 0
	while( runes[ runenum ] > -1 ):
		runenum = runenum + 1
	runenames = [ "Empty" ] * 16
	for i in range( 0, runenum ):
		rune = wolfpack.finditem( int( runes[ i ] ) )
		if rune and isrune( rune ):
			runenames[ i ] = rune.name

	# blue button and rune name
	for i in range( 0, 16 ):
		if( i < 8 ):
			x = 130
		else:
			x = 290
		y = 60 + ( i % 8 ) * 15
		# blue button return code = rune number + 1
		# tramel color : 115, feluca color : ???
		namecolor = 115
		runebook.addButton( x, y + 5, 2103, 2104, i + 1 )
		if i < runenum:
			runebook.addText( x + 15, y, "%s" % runenames[ i ], namecolor )
		else:
			# no color - black
			runebook.addText( x + 15, y, "Empty" )

	if item.hastag( "default" ):
		default = item.gettag( "default" )
	else:
		item.settag( "default", 0 )
		default = 0

	# page 2 - 9
	for i in range( 2, 10 ):
		runebook.startPage( i )
		# next page - top right corner
		if( i < 9 ):
			runebook.addPageButton( 393, 14, 2206, 2206, i + 1 )
		# previous page - top left corner
		runebook.addPageButton( 125, 14, 2205, 2205, i - 1 )

		# for each sub-page
		for j in range( 0, 2 ):
			# rune number
			k = ( i - 2 ) * 2 + j
			# blue button return code = 1 + rune number
			runebook.addButton( 130 + j * 160, 65, 2103, 2104, 1 + k )
			# recall button return code = 301 + rune number
			runebook.addButton( 135 + j * 160, 140, 2271, 2271, 301 + k )
			# gate button return code = 401 + rune number
			runebook.addButton( 205 + j * 160, 140, 2291, 2291, 401 + k )
			# there's a recall rune
			# tramel color : 115, feluca : ???
			namecolor = 115
			if( k < runenum ):
				runebook.addText( 145 + j * 160, 60, runenames[ k ], namecolor )
				# set default button return code = 101 + rune number
				if( k == default ):
					runebook.addButton( 160 + j * 135, 20, 2360, 2360, 101 + k )
				else:
					runebook.addButton( 160 + j * 135, 20, 2360, 2361, 101 + k )
				runebook.addText( 175 + j * 135, 15, "Set default" )
				# drop button return code = 201 + rune number
				runebook.addButton( 135 + j * 160, 115, 2437, 2438, 201 + k )
				runebook.addText( 150 + j * 160, 115, "Drop rune" )
			# empty - no color : black
			else:
				runebook.addText( 145 + j * 160, 60, runenames[ k ] )

	runebook.setArgs( [ item ] )
	runebook.setType( 0x87654322 )
	runebook.setCallback( "magic.runebook.callback" )

	# send it
	runebook.send( char )