var x=-1;
var j=0;
var z= 0;
var move;
var text1 = "<table><tr><td align=center><font size='5' color='#0000cc'><b>Lost child<\/b><\/font><tr><td><font face =arial size =2>Mary is eight years old. She has brown hair which she wears in pigtails.When last seen, she had an orange top and was wearing a light-coloured skirt. She went to play in the street, and her mother is getting very worried.<\/font><\/table>";
var text2 = "<table><tr><td align=center><font size=5 color='#0000cc'><b>Burglar Bill<\/b><\/font><tr><td><font face =arial size =2>Bill is aged about 28 years old. He has light brown hair and does not have a beard or moustache. But a lot of people know him, so he tries to hide his face if he can. He often pretends to be a postman or delivery man.<\/font><\/table>";
var text3 = "<table><tr><td align=center><font size=5 color='#0000cc'><b>Con-man Willie<\/b><\/font><tr><td><font face =arial size =2>Willie is described as being quite old. He looks respectable and often wears a suit. He is going bald and has grey hair. He is tall and rather fat.<\/font><\/table>";
var text4 = "<table><tr><td align=center><font size=5 color='#0000cc'><b>Desperate Sarah<\/b><\/font><tr><td><font face =arial size =2>She escaped from jail a month ago. She is aged 25 and has light-coloured hair. It used to be long, but police think she has cut it. She may have got a job in the catering trade.<\/font><\/table>";
var text5 = "<table><tr><td align=center><font size=5 color='#0000cc'><b>Shoplifting Sam<\/b><\/font><tr><td><font face =arial size =2>Sam is a young troublemaker. He likes sports and often goes barefoot.  He has brown hair, and likes to wear demin jeans. He does not get on with his father and they have many arguements. He might be with his friend Joey, who is from South Africa.<\/font><\/table>";
var text6 = "<table><tr><td align=center><font size=5 color='#0000cc'><b>The smuggler<\/b><\/font><tr><td>He is a young man, but he is already bald. He is medium height, but rather fat and short-sighted. He will probably try to disguise himself as someone else, but he cannot hide these things. He sometimes travels with his dog, Rupert.<\/font><\/table>"; 
var text7 = "THE END";
var txt = new Array(text1, text2, text3, text4, text5, text6, text7);
var pics = new Array("pic1", "pic2", "pic3", "pic4", "pic5");
var newsclip = new Array();
var badclip = new Array();
function createXMLHttpRequest() {                       
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {                   
        xmlHttp = new XMLHttpRequest();
    }
}
		
function startRequest()
{
 createXMLHttpRequest();           
    xmlHttp.onreadystatechange = handleStateChange; 
    xmlHttp.open("GET", "xml/findperson.xml", true);  
    xmlHttp.send(null); 
}

function handleStateChange() {
    if(xmlHttp.readyState == 4) {                  
        if(xmlHttp.status == 200) {               
       		  parseResults();     
			
        }
    }
}

function parseResults()
{
var contents = null;
var name="";
var badnews = "";
var results = xmlHttp.responseXML;
var cont = results.getElementsByTagName("news");
for(var i=0; i<cont.length; i++)
{
contents = cont[i];
name = contents.getElementsByTagName("para")[0].firstChild.nodeValue;
newsclip.push(name);
badnews = contents.getElementsByTagName("parabad")[0].firstChild.nodeValue;
badclip.push(badnews); 
}

}
function hideIt(){
document.getElementById("textRes").style.display = "none";
}
function stopShow(){
document.getElementById("textRes").style.display= "";
window.clearInterval(move);
}
function runIt()
{
document.getElementById("but2").style.display = "none";
x=x+1;
if(x==6){
finishGame();
}
showtext();
startPicshow();
}
function showtext(){
document.getElementById("desc").innerHTML = txt[x];
}
function hideText(){
document.getElementById("desc").innerHTML = "";
}
function startPicshow(){
if(document.getElementById("pic5").style.display == ""){
window.clearInterval(move);
}
else{
move = window.setInterval("Picshow()", 6000);
}
}
function Picshow(){
for(i=0; i<4; i++){
document.getElementById(pics[i]).style.display = 'none';
}
document.getElementById(pics[j]).style.display = "";
j++
if(j==4){
j=0;
}
}
function Resscore(val){
if(val ==x){
z=z+1;
}
else{
z=0;
}
stopShow();
}

function CheckRes(){
window.clearInterval(move);
for(i=0; i<4; i++){
document.getElementById(pics[i]).style.display = 'none';
}
document.getElementById("pic5").style.display = "";
if(z==1){
document.getElementById("pic5").style.background= "url(graphics/papergood.gif)";
document.getElementById("comt").innerHTML = newsclip[x];
document.getElementById("but1").style.display = "";
document.myform.mybut.value = "New Investigation";
}
else{
document.getElementById("pic5").style.background= "url(graphics/paperbad.gif)";
document.getElementById("comt").innerHTML = badclip[x];
document.getElementById("but1").style.display = "";
document.myform.mybut.value = "Restart Investigation";
}
z=0;
}

function resumegame(){
document.getElementById("pic5").style.display = "none";
if(document.myform.mybut.value=="New Investigation"){
document.getElementById("but1").style.display = "none";
runIt();
}
if(document.myform.mybut.value == "Restart Investigation"){
document.getElementById("but1").style.display = "none";
showtext();
startPicshow();
}}
function finishGame(){
document.getElementById("desc").innerHTML = "";
document.getElementById("pic5").style.display = "";
document.getElementById("pic5").style.background= "url(graphics/papergood.gif)";
document.getElementById("comt").innerHTML = "Well done to our Police force for solving all recent cases";
window.clearInterval(move);
for(y=0; y<4; y++){
document.getElementById(pics[i]).style.display = 'none';
}
}
