A teenager who threatened to set fire to Attleborough High to exact revenge on pupils and staff had been in contact with a German student who shot dead 15 people in a school massacre just five days earlier.

Norwich Crown Court yesterday heard that, had the police not been tipped off following a series of disturbing internet posts, the schoolboy would almost certainly have carried out his threat.

He intended to set fire to the school's English and Maths blocks and admitted to the police that he wanted to hurt people at the school, saying that they had destroyed his self-confidence.

Judge Philip Curl said that Joseph Williams, from the West Country, should be given a �500 reward for alerting the police. He said: 'Had that call been an hour later, this could have been very different.'

Prosecutor Malcolm Robins said that in the months leading up to the failed attack on March 17, 2009, the 17-year-old from Norfolk, who cannot be named for legal reasons, had been in regular contact with Tim Kretschmer.

Just five days before the incident at Attleborough High, Kretschmer, 17, killed nine pupils, three teachers and three passers-by at his school in Winnenden, Germany, before turning the gun on himself.

The boy admitted threatening to destroy property, being in possession of items with intent to destroy property and being in possession of an offensive weapon on school property.

Judge Philip Curl ordered that he be detained indefinitely under the mental health act for the public's protection. Judge Curl said: 'It is my view that you pose a significant danger.'

Like Kretschmer, the boy from Norfolk, who was 16 at the time, had posted warnings on the internet. It also emerged that the boy had attempted to obtain an airgun over the internet in the build-up to the attack.

He planned to use this if anybody tried to stop him but it was not delivered in time so he instead armed himself with a kitchen knife.

On the day of the attempt he had written a series of messages online, including: 'Today at 11.30am I will attack my school with violence and arson.' His online profile made reference to 1999 Columbine school massacre in which 13 people died.

Before launching his attack, Kretschmer had written on a similar forum: 'I am scared, I have weapons here, and I will go to my former school tomorrow and then I will really do a grilling.'

The Attleborough attack was averted when quick-thinking internet users contacted Norfolk police about the comments. When the boy arrived at the school's reception, he was intercepted by teachers who found petrol, accelerants, matches and a knife in his school bag.

Mr Robins said: 'The deputy headteacher had been made aware of the threats and found the boy calmly waiting in the reception area. He managed to separate him from his rucksack.

'The boy talked calmly about his plans and when asked if he intended to hurt people, he said: 'Yes'. He said he felt neglected by staff and peers and had lost all self-esteem because of his experiences at the school.

'When the police arrived they interviewed him immediately to establish whether anybody else was involved and if there was any other threat they needed to be aware of.'

Police searched the home he shared with his parents and found drawings and notes expressing violent feelings and his hatred of the establishment. The links to Kretschmer were discovered when officers examined his computer.

In interview he said he had targeted the English block because there was a large number of books which would fuel the flames. He hoped that he could cause an explosion in the maths block by setting fire to the electrical circuits.

Forensic psychologist Andrew Clarke said that despite making progress since being detained at a secure hospital in Manchester, the boy continued to pose a 'significant risk to the public'.

Michael Clarie, in mitigation, said his client had since be diagnosed with Asperger's Syndrome.

Judge Curl said: 'You are dangerous unless you are in a secure hospital and receiving expert treatment. You will not be released without careful consideration by the secretary of state or a mental health tribunal.'