Question: In what century was this castle erected that was destroyed and replaced several times and whose name is derived from the common Scottish surname Douglas?

Context paragraphs:
MacDougall: MacDougall or MacDougal (see also McDougall) is a common Scottish surname that can refer to a number of individuals, or localities or things named for individuals with this surname.  The name is an Anglicisation of the Scottish Gaelic "Mac Dhùgaill", meaning "Son of Dougal".

Douglas Castle: Douglas Castle was a stronghold of the Douglas family from medieval times to the 20th century.  The first castle, erected in the 13th century, was destroyed and replaced several times until the 18th century when a large mansion house was built in its place.  This too was demolished in 1938, and today only a single corner tower of the 17th-century castle remains.  The castle was the former family seat of the Prime Minister, Sir Alec Douglas-Home.  The castle was located around 1 km north-east of the village of Douglas, South Lanarkshire, in south-west Scotland.  The remains are protected as a category C listed building.

MacGregor (surname): MacGregor, also spelt Macgregor, is a Scottish surname.  The name is Anglicised form of the Scottish Gaelic MacGriogair.  The Gaelic name was originally a patronym, and means "son of "Griogar"".  The Gaelic personal name "Griogar" is a Gaelicised form of the name "Gregory".  The surname is used by members of the Scottish clan Clan Gregor, also known as Clan MacGregor.  The surname was banned in Scotland several times prior to the 18th century, in an effort to clamp down on the unruly clan.  Notable people with the surname include:

Douglas (surname): Douglas (occasionally spelled "Douglass") is a common surname of Scottish origin, thought to derive from the Gaelic "dubh glas", meaning "black stream".  There are numerous places in Scotland from which the surname is derived.  The surname has developed into the given name "Douglas".  "Douglas" is a habitational name, which could be derived from any of the many places so-named.  While there are numerous places with this name in Scotland, it is thought, in most cases, to refer to Douglas, South Lanarkshire, the location of Douglas Castle, the chief stronghold of the Lords of Douglas.  The Scottish Gaelic form of the given name is "Dùbhghlas"; the Irish language form it is "Dúghlas", and "Dubhghlas", which are pronounced ] .  According to George Fraser Black, in southern Argyllshire the surname is an Anglicised form of the surnames "MacLucas", "MacLugash" (which are derived from the Gaelic "Mac Lùcais").

McDougall: McDougall or McDougal (see also MacDougall) is a common Scottish surname that can refer to a number of individuals, or localities or things named for individuals with this surname.

Maxwell (surname): Maxwell is a Jewish, Irish, and Scottish surname.  The Scottish name is a habitational name, derived from a location near Melrose, in Roxburghshire, Scotland.  This name was first recorded in 1144, as "Mackeswell", meaning "Mack's spring (or stream)" (from the Old English "well[a]").  The surname "Maxwell" is also common in Ulster; where it has, in some cases, been adopted as alternate form of the surname "Miskell".  The surname "Maxwell" is also used as a Jewish surname, either as an adoption of the Scottish name, or as an Americanization of one of several like-sounding Jewish surnames.  The surname "Maxwell" is represented in Scottish Gaelic as "MacSual".

McGregor (surname): McGregor, also spelled MacGregor, is a Scottish Surname.  The name is an Anglicised form of the Scottish Gaelic MacGriogair.  The Gaelic name was originally a patronym, and means "son of "Griogar"".  The Gaelic personal name "Griogar" is a Gaelicised form of the name "Gregory".  The surname is used by members of the Scottish clan Clan Gregor, also known as Clan MacGregor.  The surname was banned in Scotland several times prior to the 18th century, in an effort to clamp down on the unruly clan.  Notable people with the surname include:

Henderson (surname): Henderson is a common Scottish surname.  The name is derived from patronymic form of the name "Hendry", which is a Scottish form of "Henry".  Some Hendersons also derive their name from "Henryson".

Douglas (given name): Douglas ( ) is a Scottish masculine given name which originated from the surname "Douglas".  Although today the name is almost exclusively given to boys, it was used as girls name in the 17th and 18th centuries, in the north of England.  The Scottish surname "Douglas" was borne by one of the most powerful families of the Kingdom of Scotland (the Earls of Douglas, Angus, Morton, Dukes of Hamilton and others).  It has sometimes been stated that the given name is connected with the given name "Dougal", although it is more likely derived from the surname already mentioned.

Morrison (surname): Morrison is an English-language surname.  The name is derived from a patronymic form of the English "Morris".  The personal name "Morris" sometimes is a variant of "Maurice", and was quite popular in the Middle Ages.  In Scotland the surname is sometimes also an Anglicised form of the Scottish Gaelic "MacGilleMhuire", a surname meaning "son of the servant of (the Virgin) Mary".  The Scottish surname "Morrison" is also sometimes an Anglicised form of the Irish "O'Muirghesasain", meaning "descendant of "Muirgheas"".  In Ireland the surname is sometimes an Anglicised form of the Irish "Mac Muiris", a surname derived from the patronymic form of "Muiris".  The Irish personal name "Muiris" derives from the Gaelic adjective Mor or the Gaelic word Muir.

Supporting paragraphs: Douglas (surname) Douglas Castle
Answer: 13th century