set numberOfContacts to #numberOfContacts#
set firstNamesList to #firstNamesList#
set lastNamesList to #lastNamesList#
set streetsList to #streetsList#
set citiesList to #citiesList#
set statesList to #statesList#
set countriesList to #countriesList#
set zipsList to #zipsList#
set callsignsList to #callsignsList#
set emailsList to #emailsList#

tell application "Address Book"
	if not (exists group "Aether Contacts") then
		make new group with properties {name:"Aether Contacts"}
	end if
	set theGroup to (group "Aether Contacts")
	
	repeat with i from 1 to numberOfContacts
		set theLastName to item i of the lastNamesList
		set theFirstName to item i of the firstNamesList
		set theStreet to item i of the streetsList
		set theCity to item i of the citiesList
		set theState to item i of the statesList
		set theCountry to item i of the countriesList
		set theZip to item i of the zipsList
		set theCallsign to item i of the callsignsList
		set theEmail to item i of the emailsList
		
		--Based on whether or not the last name is filled in (first name is always filled in), create a new person
		--with the correct properties
		if (theLastName) is not equal to "N/A" then
			set thePerson to (make new person with properties {first name:theFirstName, last name:theLastName})
		else
			set thePerson to (make new person with properties {first name:theFirstName})
		end if
		
		if theCallsign is not equal to "N/A" then
			tell thePerson to make new related name with properties {label:"Callsign", value:theCallsign}
		end if
		
		if theEmail is not equal to "N/A" then
			tell thePerson to make new email with properties {label:"Home", value:theEmail}
		end if
		
		
		--As long as one of the address fields is filled in, add the address
		if (theStreet is not equal to "N/A") or (theCity is not equal to "N/A") or (theState is not equal to "N/A") or (theCountry is not equal to "N/A") or (theZip is not equal to "N/A") then
			tell thePerson
				set existingAddresss to (every address)
				if (existingAddresss is equal to {}) then
					make new address at end of addresses with properties {label:"Home"}
					set existingAddresss to (every address)
				end if
				set currentAddress to item 1 of existingAddresss
				if (theStreet is not equal to "N/A") then set street of currentAddress to theStreet
				if (theCity is not equal to "N/A") then set the city of currentAddress to theCity
				if (theState is not equal to "N/A") then set the state of currentAddress to theState
				if (theCountry is not equal to "N/A") then set the country of currentAddress to theCountry
				if (theZip is not equal to "N/A") then set the zip of currentAddress to theZip
			end tell
		end if
		add thePerson to theGroup
		
	end repeat
	
	save addressbook
	activate
end tell