Changing terrain texture at runtime

I need to change my terrain’s texture during runtime, specifically when the user loads the game it asks them which image to select. The images will be the same size (512x512) so size differences won’t be an issue, I just don’t know how to tell the terrain to load a different texture at run time.

Any help is appreciated.
Thank you.

var texturesIn: Texture2D =new Texture2D [15];
var textureInSplats:SplatPrototype =new SplatPrototype[1];

function changeTexture(inTexture:int)
	textureInSplats[0] = new SplatPrototype();
	textureInSplats[0].texture=texturesIn[inTexture]; // texture here
	textureInSplats[0].tileSize= new Vector2(50,50); //tiling size
	terrainGameObject.GetComponent(Terrain).terrainData.splatPrototypes = textureInSplats;

Your welcome.