﻿//var resultspage="http://" + location.host + "/ontolica/Pages/DefaultResults.aspx?scrptng=true&s=intranet&kw=";
var resultspage= parent.location.protocol + "//" + location.host + "/search/Pages/Results.aspx?kw=";


//default search functions

function DoSearchHLF()
{

				var keywords=document.getElementById('searchtext').value;
				if ((keywords == "Enter Search") || (keywords == ""))
				{
				document.getElementById('searchtext').focus();
				document.getElementById('searchtext').value = "Enter Search";
				document.getElementById('searchtext').select();
				}
				else
				{
				window.location = resultspage + keywords;
				
				}
				return false;
}
function ClearSearchHLF()
{
				var keywords=document.getElementById('searchtext').value;
				if (keywords == "Enter Search")
				{
				document.getElementById('searchtext').value = "";
				}
}


function SearchKeyDownHLF(event1)
{
				var kCode = String.fromCharCode(event1.keyCode);
				if(kCode == "\n" || kCode == "\r")
				{   
					DoSearchHLF(); 
					return false;
				}
}

//our project specific functions
var projectsresultspage = parent.location.protocol + "//" + location.host + "/search/Pages/results.aspx?kw=";
function DoSearchProjectHLF()
{
		var keywords=document.getElementById('projectsearchtext').value;
		if(keywords.toLowerCase()!="search by keyword"){
			var filter = "";
			var url = document.location.toString().toLowerCase();
			if(keywords.length<900){
				var intIndexOfMatch = url.indexOf( "%22" );		
				while (intIndexOfMatch != -1){
					url = url .replace( "%22", "\"" )
					intIndexOfMatch = url.indexOf( "%22" );
				}
				intIndexOfMatch = url.indexOf( "%3a" );
				while (intIndexOfMatch != -1){
					url = url.replace( "%3a", ":" )
					intIndexOfMatch = url.indexOf( "%3a" );
				}
				intIndexOfMatch = url.indexOf( " " );
					while (intIndexOfMatch != -1){
					url = url.replace( " ", "+" )
					intIndexOfMatch = url.indexOf( " " );
				}					
				if (url.indexOf("hlftype:\"project\"")>-1)
				{
				filter+= "+hlftype:\"project\"";
				}									
				if (url.indexOf("hlftype:\"case+study\"")>-1)
				
				{filter+= "+hlftype:\"case+study\"";
				}							
				if (url.indexOf("hlftype:\"article\"")>-1)
				
				{filter+= "+hlftype:\"article\"";
				}
				if (url.indexOf("hlftype:\"publication\"")>-1)
				
				{filter+= "+hlftype:\"publication\"";
				}
				if (url.indexOf("hlfsector:\"buildings+and+monuments\"")>-1)
				
				{filter+= "+hlfsector:\"buildings+and+monuments\"";
				}
				if (url.indexOf("hlfsector:\"industry,+maritime+and+transport\"")>-1)
				
				{filter+= "+hlfsector:\"industry,+maritime+and+transport\"";
				}							
				if (url.indexOf("hlfsector:\"culture+and+memories\"")>-1)
				
				{filter+= "+hlfsector:\"culture+and+memories\"";
				}
				if (url.indexOf("hlfsector:\"land+and+biodiversity\"")>-1)
				
				{filter+= "+hlfsector:\"land+and+biodiversity\"";
				}
				if (url.indexOf("hlfsector:\"collections\"")>-1)
				
				{filter+= "+hlfsector:\"collections\"";
				}
				if (url.indexOf("hlfprogramme:\"your+heritage\"")>-1)
				
				{filter+= "+hlfprogramme:\"your+heritage\"";
				}
				if (url.indexOf("hlfprogramme:\"heritage+grants\"")>-1)
				
				{filter+= "+hlfprogramme:\"heritage+grants\"";
				}
				if (url.indexOf("hlfprogramme:\"repair+grants+for+places+of+worship\"")>-1)
				
				{filter+= "+hlfprogramme:\"repair+grants+for+places+of+worship\"";
				}
				if (url.indexOf("hlfprogramme:\"townscape+heritage+initiative\"")>-1)
				
				{filter+= "+hlfprogramme:\"townscape+heritage+initiative\"";
				}
				if (url.indexOf("hlfprogramme:\"parks+for+people\"")>-1)
				
				{filter+= "+hlfprogramme:\"parks+for+people\"";
				}
				if (url.indexOf("hlfprogramme:\"landscape+partnerships\"")>-1)
				
				{filter+= "+hlfprogramme:\"landscape+partnerships\"";
				}
				if (url.indexOf("hlfprogramme:\"young+roots\"")>-1)
				
				{filter+= "+hlfprogramme:\"young+roots\"";
				}
				if (url.indexOf("hlfactivity:\"conservation\"")>-1)
				
				{filter+= "+hlfactivity:\"conservation\"";
				}
				if (url.indexOf("hlfactivity:\"participation\"")>-1)
				
				{filter+= "+hlfactivity:\"participation\"";
				}
				if (url.indexOf("hlfactivity:\"learning\"")>-1)
				
				{filter+= "+hlfactivity:\"learning\"";
				}
				if (url.indexOf("hlfregion:\"east+of+england\"")>-1)
				
				{filter+= "+hlfregion:\"east+of+england\"";
				}
				if (url.indexOf("hlfregion:\"east+midlands\"")>-1)
				
				{filter+= "+hlfregion:\"east+midlands\"";
				}
				if (url.indexOf("hlfregion:\"london\"")>-1)
				
				{filter+= "+hlfregion:\"london\"";
				}
				if (url.indexOf("hlfregion:\"north+east\"")>-1)
				
				{filter+= "+hlfregion:\"north+east\"";
				}
				if (url.indexOf("hlfregion:\"north+west\"")>-1)
				
				{filter+= "+hlfregion:\"north+West\"";
				}
				if (url.indexOf("hlfregion:\"northern+ireland\"")>-1)
				
				{filter+= "+hlfregion:\"northern+ireland\"";
				}
				if (url.indexOf("hlfregion:\"scotland\"")>-1)
				
				{filter+= "+hlfregion:\"scotland\"";
				}
				if (url.indexOf("hlfregion:\"south+east+england\"")>-1)
				
				{filter+= "+hlfregion:\"south+east+england\"";
				}
				if (url.indexOf("hlfregion:\"south+west\"")>-1)
				
				{filter+= "+hlfregion:\"south+west\"";
				}
				if (url.indexOf("hlfregion:\"wales\"")>-1)
				
				{filter+= "+hlfregion:\"wales\"";
				}
				if (url.indexOf("hlfregion:\"west+midlands\"")>-1)
				
				{filter+= "+hlfregion:\"west+midlands\"";
				}
				if (url.indexOf("hlfregion:\"yorkshire+and+the+humber\"")>-1)
				
				{filter+= "+hlfregion:\"yorkshire+and+the+humber\"";
				}
				if (url.indexOf("hlfregion:\"national\"")>-1)
				
				{filter+= "+hlfregion:\"national\"";
				}		
				window.location = projectsresultspage + keywords + filter;
				return false;

				}else{
					alert('Please limit the keyword length to less than 900 characters.');
				}
			}
		
		else{
		alert('Please enter a valid search term');
		}
}
function DoSearchOurProjectsHLF()
{

				//var keywords=document.getElementById('projectssearchtext').value;
				var filter = "";
				var scopeFilter ="";
				var url = document.location.toString().toLowerCase();
					if (url.indexOf("projectsbysector/buildingsandmonuments/")>-1)
					{
						filter = "+hlfsector:\"buildings and monuments\"";
					}

					if (url.indexOf("projectsbysector/industry/")>-1)
					{
						filter = "+hlfsector:\"industry, maritime and transport\"";
					}
					if (url.indexOf("projectsbysector/cultureandmemories/")>-1)
					{
						scopeFilter = "&s=isf";
					}
					if (url.indexOf("projectsbysector/landandbiodiversity/")>-1)
					{
						filter = "+hlfsector:\"land and biodiversity\"";
					}
					if (url.indexOf("projectsbysector/collections/")>-1)
					{
						filter = "+hlfsector:\"collections\"";
					}
					if (url.indexOf("projectsbyactivity/conservation/")>-1)
					{
						filter = "+hlfactivity:\"conservation\"";
					}
					if (url.indexOf("projectsbyactivity/participation/")>-1)
					{
						scopeFilter = "&s=psf";
					}
					if (url.indexOf("projectsbyactivity/learning/")>-1)
					{
						filter = "+hlfactivity:\"learning\"";
					}								
				window.location = projectsresultspage+filter + "+HLFType:\"Case Study\"+HLFType:\"Project\""+ scopeFilter;
				return false;
}


function ClearSearchProjectHLF()
{
				var keywords=document.getElementById('projectsearchtext').value;
				if (keywords == "Enter Search")
				{
				document.getElementById('projectsearchtext').value = "";
				}
}


function SearchKeyDownProjectHLF(event1)
{
				var kCode = String.fromCharCode(event1.keyCode);
				if(kCode == "\n" || kCode == "\r")
				{   
					DoSearchProjectHLF(); 
					return false;
				}
}


