    // Create the XMLHttpRequest 
	
	var loadQueue = new Array();
	
    var xHRObject = false;
	var subjectxHRObject = false;
	var searchSelected = '';
  
    function getData()
    {
        //Check to see if the XMlHttpRequest object is ready and whether it has  
        //returned a legitmate response
        if (xHRObject.readyState == 4 && xHRObject.status == 200)
        {           
            var xmlDoc = xHRObject.responseXML;
            if (window.ActiveXObject)
            { 
                //Load XSL
				/*
                var xsl = new ActiveXObject("Microsoft.XMLDOM");
                xsl.async = false;
                xsl.load("fake.xsl");
       
                //Transform
                var transform = xmlDoc.transformNode(xsl);
                var spanb = document.getElementById("menuhere");
				*/
				document.getElementById("menuhere").innerHTML = "";

            }
            
            else
            {
              /*var xsltProcessor = new XSLTProcessor();
              
              //Load XSL
              XObject = new XMLHttpRequest();
              XObject.open("GET", "fake.xsl", false);
              XObject.send(null);
              
              xslStylesheet = XObject.responseXML;
              xsltProcessor.importStylesheet(xslStylesheet);
              
              //Transform
             // var fragment = xsltProcessor.transformToFragment(xmlDoc, document);
*/
              document.getElementById("menuhere").innerHTML = "";
              //document.getElementById("menuhere").appendChild(fragment);   
           
           
            }

                //Display results of transform
               /* if (spanb != null)
                {
                    //spanb.innerHTML = transform; 
                }*/
				showBox(xmlDoc);

                //Clear the object and call the getDocument function in 10 seconds
                //
                //setTimeout("getDocument()", 10000);     
            }  
    }
	
	function getSubjectData()
    {
        //Check to see if the XMlHttpRequest object is ready and whether it has  
        //returned a legitmate response
        if (subjectxHRObject.readyState == 4 && subjectxHRObject.status == 200)
        {           
            var subjectxmlDoc = subjectxHRObject.responseXML;
            document.getElementById(searchSelected).innerHTML = "";
			printSubject(subjectxmlDoc);
        }  
    }
	
	function printSubject(xmlDoc) {
		var posts = xmlDoc.getElementsByTagName('Subject');
		var subjectDiv='';
		subjectDiv+='<select id="sub_subject" multiple="multiple" name="subjectBody[]" size="7" class="advancedSearch_multipleField">';
		for(var i=0; i<posts.length; i++) {
			//subjectDiv+=posts[i].childNodes[0].nodeValue;
			subjectDiv+='<option value="'+posts[i].childNodes[0].firstChild.nodeValue+'">'+posts[i].childNodes[1].firstChild.nodeValue+'</option>';
		}
		subjectDiv+='</select>';
		document.getElementById(searchSelected).innerHTML=subjectDiv;
	}
	
	function addToQueue(str) {
		 loadQueue.push(str);
		 if(loadQueue.length==1) {
			 getDocument();
		 }
	}
	
	function setSearchQueue(str) {
		document.getElementById('searchField').value=str;
	}
    
    function getDocument()
    {
     //Reset the function
		 if(loadQueue[0].length>2) {
			 if (window.XMLHttpRequest)
			{	
				xHRObject = new XMLHttpRequest();
			}
			else if (window.ActiveXObject)
			{
				xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
			}
			if(xHRObject.overrideMimeType) {
				xHRObject.overrideMimeType("text/xml");
			}
			 
			 //xHRObject.abort();
			 xHRObject.onreadystatechange = getData;
			 
			 //IE will cache the GET request the only way around this is to append a   
			 //different querystring. We add a new date and append it as a querystring
		
			 xHRObject.open("GET", "/ajax.php?str="+ loadQueue[0] +"&section=all&id=" + Number(new Date), true);
			 
			 xHRObject.send(null);
		 } else {
			 //xHRObject.abort();
			 document.getElementById("menuhere").innerHTML = "";
			 //IE will cache the GET request the only way around this is to append a   
			 //different querystring. We add a new date and append it as a querystring
			 //xHRObject.send(null);
			 loadQueue.shift();
			 if(loadQueue.length>0) {
			 	getDocument();
		 	 }
		 }
     }
	 
	 function clearSearch() {
		 document.getElementById("menuhere").innerHTML = "";
		 loadQueue.shift();
		 if(loadQueue.length>0) {
			getDocument();
		 }
	 }

function getSubjects(id, selSearch) {
	searchSelected=selSearch;
	 if (window.XMLHttpRequest)
	{	
		subjectxHRObject = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		subjectxHRObject = new ActiveXObject("Microsoft.XMLHTTP");
	}
	 subjectxHRObject.onreadystatechange = getSubjectData;
	 subjectxHRObject.open("GET", "/getSubjects.php?code="+ id +"&id=" + Number(new Date), true);
	 subjectxHRObject.send(null);
}
	 
	 function showBox(xmlDoc)
	 {
		 
var searchStr = xmlDoc.getElementsByTagName('SearchStr');
searchStr = searchStr[0];
searchStr = searchStr.firstChild.nodeValue;

var loggedIn = xmlDoc.getElementsByTagName('LoggedIn');
loggedIn = loggedIn[0];
loggedIn = loggedIn.firstChild.nodeValue;

var showOfResSkola = xmlDoc.getElementsByTagName('ShowOfResSkola');
showOfResSkola = showOfResSkola[0];
showOfResSkola = showOfResSkola.firstChild.nodeValue;

var listAllSkola = xmlDoc.getElementsByTagName('ListAllSkola');
listAllSkola = listAllSkola[0];
listAllSkola = listAllSkola.firstChild.nodeValue;

var showOfResProgram = xmlDoc.getElementsByTagName('ShowOfResProgram');
showOfResProgram = showOfResProgram[0];
showOfResProgram = showOfResProgram.firstChild.nodeValue;

var listAllProgram = xmlDoc.getElementsByTagName('ListAllProgram');
listAllProgram = listAllProgram[0];
listAllProgram = listAllProgram.firstChild.nodeValue;

var showOfResKurs = xmlDoc.getElementsByTagName('ShowOfResKurs');
showOfResKurs = showOfResKurs[0];
showOfResKurs = showOfResKurs.firstChild.nodeValue;

var listAllKurs = xmlDoc.getElementsByTagName('ListAllKurs');
listAllKurs = listAllKurs[0];
listAllKurs = listAllKurs.firstChild.nodeValue;

var showOfResForelasare = xmlDoc.getElementsByTagName('ShowOfResForelasare');
showOfResForelasare = showOfResForelasare[0];
showOfResForelasare = showOfResForelasare.firstChild.nodeValue;

var listAllForelasare = xmlDoc.getElementsByTagName('ListAllForelasare');
listAllForelasare = listAllForelasare[0];
listAllForelasare = listAllForelasare.firstChild.nodeValue;

var posts = xmlDoc.getElementsByTagName('Suite');

var searchDiv ='<div class="search_top_space"></div>';
searchDiv+='<div class="box_top_left"></div>';
searchDiv+='<div class="search_box_top"></div>';
searchDiv+='<div class="box_top_right"></div>';
    
searchDiv+='<div class="search_box_content">';
    
searchDiv+='	<div class="search_box_double_column">';
searchDiv+='		<span class="align_left">';
searchDiv+='			<h3>Sökresultat för "'+searchStr+'"</h3>';
searchDiv+='		</span>';
searchDiv+='		<span class="align_right">';
searchDiv+='			<a href="/advanced_search.php" class="spacer">Avancerad sökning</a>';
if(loggedIn=='true') {
	searchDiv+='    <a href="/add_lecturer.php" class="spacer">Lägg till ny föreläsare</a>';
} else {
	searchDiv+='    <a href="javascript:popupLoginBox(\'Du måste logga in för att lägga till föreläsare\', \'add_lecturer.php\')" class="spacer">Lägg till ny föreläsare</a>';
}
searchDiv+='			<a href="/faq.php#noSearchResult" class="spacer">Hittar du inte vad du söker?</a>'; 
searchDiv+='			<a href="javascript:clearSearch()">Stäng</a>';
searchDiv+='		</span>'; 
searchDiv+='	</div>';
  
searchDiv+='  <div id="search_box_column_wrapper">';
  
searchDiv+='  <div class="search_box_left_column"> ';
searchDiv+='    <div id="skolor" class="search_box_left_content">';
if(showOfResSkola==0) {
	searchDiv+='        <a href="/skolor/" class="searchHeading" >Skolor</a> Inga träffar för "'+searchStr+'"';

}
else if(showOfResSkola<10) {
	searchDiv+='        <a href="/skolor/" class="searchHeading" >Skolor</a> Visar samtliga '+showOfResSkola+' träffar';
}
else {
	searchDiv+='        <a href="/skolor/" class="searchHeading" >Skolor</a> Visar de första 10 träffarna';
}
searchDiv+='        <div class="search_box_space"></div>';

for(var i=0; i<posts.length; i++) {
	var at=posts[i].attributes;
	var id = at.getNamedItem('ProductID');
	if(posts[i].childNodes[1].firstChild.nodeValue==1001) {
		if(posts[i].childNodes[0].firstChild.nodeValue==0) {
			searchDiv+='	                <div class="oddRow">';
		} else {
			searchDiv+='	                <div class="evenRow">';
		}
		searchDiv+='                    	<span class="hit_highlight">';
		searchDiv+='                            <a href="/'+posts[i].childNodes[4].firstChild.nodeValue+'">'+posts[i].childNodes[2].firstChild.nodeValue+'</a></span>';
		searchDiv+='                	</div>';
	}
}
//searchDiv+='        <xsl:if test="//ShowOfResSkola!=0">
if(showOfResSkola>0) {
	searchDiv+='            <span class="see_all_hits">';
	searchDiv+='            <a href="/'+listAllSkola+'">';
	searchDiv+='                Visa alla träffar på skolor på egen sida';
	searchDiv+='            </a></span>';
}
//searchDiv+='        </xsl:if>
searchDiv+='    </div><!-- /search_box_left_content> -->';
searchDiv+='    <div class="search_box_divider"></div>';
searchDiv+='        ';
searchDiv+='        ';
searchDiv+='    <div id="kurser" class="search_box_left_content">';
if(showOfResKurs==0) {
	searchDiv+='        <a href="/kurser/" class="searchHeading" >Kurser</a> Inga träffar för "'+searchStr+'"';

}
else if(showOfResKurs<10) {
	searchDiv+='        <a href="/kurser/" class="searchHeading" >Kurser</a> Visar samtliga '+showOfResKurs+' träffar';
}
else {
	searchDiv+='        <a href="/kurser/" class="searchHeading" >Kurser</a> Visar de första 10 träffarna';
}
searchDiv+='            <div class="search_box_space"></div>';

for(var i=0; i<posts.length; i++) {
	var at=posts[i].attributes;
	var id = at.getNamedItem('ProductID');
	if(posts[i].childNodes[1].firstChild.nodeValue==1002) {
		if(posts[i].childNodes[0].firstChild.nodeValue==0) {
			searchDiv+='	                <div class="oddRow">';
		} else {
			searchDiv+='	                <div class="evenRow">';
		}
		searchDiv+='                    	<span class="hit_highlight">';
		searchDiv+='                            <a href="/'+posts[i].childNodes[5].firstChild.nodeValue+'">'+posts[i].childNodes[2].firstChild.nodeValue+'</a></span>, ';
		searchDiv+='                            <a href="/'+posts[i].childNodes[4].firstChild.nodeValue+'">'+posts[i].childNodes[3].firstChild.nodeValue+'</a>';
		searchDiv+='                	</div>';
	}
}

if(showOfResKurs>0) {
	searchDiv+='            <span class="see_all_hits">';
	searchDiv+='            <a href="/'+listAllKurs+'">';
	searchDiv+='                    Visa alla träffar på kurser på egen sida';
	searchDiv+='            </a></span>';
}
searchDiv+='        </div><!-- /search_box_left_content -->';
searchDiv+='  </div><!-- /search_box_left_column -->';

searchDiv+='  <div id="program" class="search_box_right_column">';
searchDiv+='        <div class="search_box_right_content">';
if(showOfResProgram==0) {
	searchDiv+='        <a href="/program/" class="searchHeading" >Program</a> Inga träffar för "'+searchStr+'"';

}
else if(showOfResProgram<10) {
	searchDiv+='        <a href="/program/" class="searchHeading" >Program</a> Visar samtliga '+showOfResProgram+' träffar';
}
else {
	searchDiv+='        <a href="/program/" class="searchHeading" >Program</a> Visar de första 10 träffarna';
}
searchDiv+='            <div class="search_box_space"></div>';

for(var i=0; i<posts.length; i++) {
	var at=posts[i].attributes;
	var id = at.getNamedItem('ProductID');
	if(posts[i].childNodes[1].firstChild.nodeValue==1003) {
		if(posts[i].childNodes[0].firstChild.nodeValue==0) {
			searchDiv+='	                <div class="oddRow">';
		} else {
			searchDiv+='	                <div class="evenRow">';
		}
		searchDiv+='                    	<span class="hit_highlight">';
		searchDiv+='                            <a href="/'+posts[i].childNodes[5].firstChild.nodeValue+'">'+posts[i].childNodes[2].firstChild.nodeValue+'</a></span>, ';
		searchDiv+='                            <a href="/'+posts[i].childNodes[4].firstChild.nodeValue+'">'+posts[i].childNodes[3].firstChild.nodeValue+'</a>';
		searchDiv+='                	</div>';
	}
}

if(showOfResProgram>0) {
	searchDiv+='            <span class="see_all_hits">';
	searchDiv+='            <a href="/'+listAllProgram+'">';
	searchDiv+='                    Visa alla träffar på program på egen sida';
	searchDiv+='            </a></span>';
}

searchDiv+='        </div><!-- /search_box_right_content> -->';
searchDiv+='        <div class="search_box_divider"></div>';
searchDiv+='        ';
searchDiv+='        <div id="forelasare" class="search_box_right_content">';
if(showOfResForelasare==0) {
	searchDiv+='        <a href="/forelasare/" class="searchHeading" >Föreläsare</a> Inga träffar för "'+searchStr+'"';

}
else if(showOfResForelasare<10) {
	searchDiv+='        <a href="/forelasare/" class="searchHeading" >Föreläsare</a> Visar samtliga '+showOfResForelasare+' träffar';
}
else {
	searchDiv+='        <a href="/forelasare/" class="searchHeading" >Föreläsare</a> Visar de första 10 träffarna';
}
searchDiv+='            <div class="search_box_space"></div>';

for(var i=0; i<posts.length; i++) {
	var at=posts[i].attributes;
	var id = at.getNamedItem('ProductID');
	if(posts[i].childNodes[1].firstChild.nodeValue==1004) {
		if(posts[i].childNodes[0].firstChild.nodeValue==0) {
			searchDiv+='	                <div class="oddRow">';
		} else {
			searchDiv+='	                <div class="evenRow">';
		}
		searchDiv+='                    	<span class="hit_highlight">';
		searchDiv+='                            <a href="/'+posts[i].childNodes[5].firstChild.nodeValue+'">'+posts[i].childNodes[2].firstChild.nodeValue+'</a></span>, ';
		searchDiv+='                            <a href="/'+posts[i].childNodes[4].firstChild.nodeValue+'">'+posts[i].childNodes[3].firstChild.nodeValue+'</a>';
		searchDiv+='                	</div>';
	}
}

if(showOfResForelasare>0) {
	searchDiv+='            <span class="see_all_hits">';
	searchDiv+='            <a href="/'+listAllForelasare+'">';
	searchDiv+='                    Visa alla träffar på föreläsare på egen sida';
	searchDiv+='            </a></span>';
}

searchDiv+='        </div><!-- /search_box_right_content -->';
searchDiv+='    </div><!-- search_box_right_column -->';
searchDiv+='    </div><!-- search_box_column_wrapper -->';
searchDiv+='    </div><!-- /search_box_content -->';
searchDiv+='    ';
searchDiv+='    <div class="box_bottom_left"></div>';
searchDiv+='    <div class="search_box_bottom"></div>';
searchDiv+='    <div class="box_bottom_right"></div>';
	     var o = testForObject('theSearchBox');
    if(o) {
   		var registrationBox = document.getElementById('menuhere');
		var oldRegistrationBox = document.getElementById('theSearchBox');
		registrationBox.removeChild(oldRegistrationBox);
    } else {    
        var registrationBox = document.getElementById('menuhere');
        var newRegistrationBox = document.createElement('div');
        var divIdName = 'theSearchBox';
        newRegistrationBox.setAttribute('id',divIdName);
        newRegistrationBox.innerHTML = searchDiv;
        registrationBox.appendChild(newRegistrationBox);
    }
				window.location.replace("#searchStr="+loadQueue[0]);
				loadQueue.shift();
				if(loadQueue.length>0) {
					getDocument();
		 		}
}

function testForObject(Id, Tag)
{
  var o = document.getElementById(Id);
  if (o)
  {
    if (Tag)
    {
      if (o.tagName.toLowerCase() == Tag.toLowerCase())
      {
        return o;
      }
    }
    else
    {
      return o;
    }
  }
  return null;
}