function closeSearch(){
document.getElementById("searchPop").style.display = 'none';
}
function displaySearch(pageID) {
var searchMessage;
searchMessage = pageID;
  document.getElementById("searchMessage").innerHTML = searchMessage;
  if (document.getElementById("searchPop").style.display = 'none' )
  {
    document.getElementById("searchPop").style.display = 'block';
  }
  var searchElement = document.getElementById("searchPop");
  //eval("searchElement.style.left ="+window.event.x+"+"+document.body.scrollLeft+"");
  //eval("searchElement.style.top ="+window.event.y+"+"+document.body.scrollTop+"");
  searchElement.style.left = window.event.x + document.body.scrollLeft;
  //searchElement.style.top = window.event.y + document.body.scrollTop;
}

function searchPop(){
document.write("<DIV class=searchPop name=searchPop ID=searchPop ALIGN=center>");
document.write("<fieldset>");
document.write("<legend class=greenSmall><b>Search Results</b></legend>");
document.write("<table>");
document.write("<tr><td id=searchMessage name=searchMessage></td></tr>");
document.write("<tr><td>");
document.write("<a href=javascript:closeSearch();>");
document.write("<img src=images/buttons/close.gif border=0 alt='close'></a>");
document.write("</td></tr>");
document.write("</table>");
document.write("</fieldset>");
document.write("</DIV>");
}
searchPop();
var item = new Array();
//NOTES FOR VITAL VEG - SEARCH MODULE.
//To edit a page search ONLY edit the text within the double quotes between brackets.
//example ("index.htm","","Home page","home,address,main,front","")
//"index.htm" = is the linked paged returned in a search result.
//"Home page" = is the name of the link that appears in the search.
//"home,address,main,front" = are keywords used for this result.

c=0; item[c]=new Array("index.htm","","Home page","home,address,main,front","");
c++; item[c]=new Array("about.htm","","About Us","organic,deliveries,delivery,midmar,pesticides","");
c++; item[c]=new Array("advice.htm","","Garden Design","rotation,sowing,advice,soil,plot","");
c++; item[c]=new Array("contact.htm","","Contact Us","contact,telephone,email","");
c++; item[c]=new Array("deliverymap.htm","","Delivery Map","deliver to,location,map,area,when","");
c++; item[c]=new Array("environment.htm","","Environment","environment,more,where,similar,friends","");
c++; item[c]=new Array("faq.htm","","Frequently Asked Questions","questions,help,what,where,when,why,how","");
c++; item[c]=new Array("jobs.htm","","Jobs at Vital Veg","jobs,careers,temp,permanent,job,career","");
c++; item[c]=new Array("news.htm","","Vital Veg News","news,newsletter,events","");
c++; item[c]=new Array("newsarchive.htm","","News Archives","archives,old news,past","");
c++; item[c]=new Array("plants.htm","","Starter Plants","plants,planting,starter","");
c++; item[c]=new Array("placeorder.htm","","Place an Order","order,sign,register,logon,login,shop,store","");
c++; item[c]=new Array("recipes.htm","","Featured Recipes","recipes,soup,cake,kitchen","");
c++; item[c]=new Array("seminars.htm","","Vital Veg Seminars","seminars,businesses,education,higher,school,organisations","");
c++; item[c]=new Array("tips.htm","","Hints and Tips","tips,hints,advice","");

function search() {
page="";
page="<table border=0 cellspacing=1 width=100%>";

txt0 = document.getElementById("q").value;
txt1 = txt0.toLowerCase();
//txt = document.getElementById("q").value.split(" ");
txt = txt1.split(" ");

fnd = new Array(); total=0;
for (i = 0; i < item.length; i++) {
fnd[i] = 0; order = new Array(0, 4, 2, 3);
for (j = 0; j < order.length; j++)
for (k = 0; k < txt.length; k++)
if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
fnd[i] += (j+1);
}
for (i = 0; i < fnd.length; i++) {
n = 0; w = -1;
for (j = 0;j < fnd.length; j++)
if (fnd[j] > n) { n = fnd[j]; w = j; };
if (w > -1) total += show(w, n);
fnd[w] = 0;
}
page = page + "</table><table><tr><td class=greenSmall>Total found: "+total+"</td><tr></table>";
displaySearch(page)
}
function show(which,num) {
link = item[which][1] + item[which][0]; 
page = page + "<tr><td class=greenSmall><a href='"+link+"'>"+item[which][2]+"</a> Score: "+num+" ";
page += item[which][4] + " "+link+"</td></tr>";
return 1;
}

var itemAd = new Array();
//NOTES FOR VITAL VEG - ADVERTISING MODULE.
//To edit the advertsing module. ONLY edit the text within the double quotes between brackets.
//example ("about","DeltaStudios in Aberdeenshire","Specialists in online software solutions...")
//"about is" = the page where the advert appears.
//"DeltaStudios in Aberdeenshire" = is the title of the advert.
//"Specialists in online software solutions..." = is the main text/link in advert.

c=0; itemAd[c]=new Array("about","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("whatsinbox","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("placeorder","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("deliverymap","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("logon","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("forgotten","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("myvitalveg","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("mydetails","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("newcustomer","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("newcustomernodelivery","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("search","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("secure","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("advice","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("contact","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("news","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("deliverymap","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("news","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("environment","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("faq","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("farmcam","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("jobs","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("plants","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("privacy","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("recipes","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("seminars","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("terms","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("testimonials","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("tips","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");
c++; itemAd[c]=new Array("viewmyorder","Sponsor a Page","Advertise your site with Vital Veg","http://www.vitalveg.co.uk/contact.asp");

function showAds(pageName){
	for (i = 0; i < itemAd.length; i++) {
		if(itemAd[i][0] == pageName){
			document.getElementById("adHead").innerHTML = "<a class=adLink href='"+itemAd[i][3]+"' target=_blank>"+ itemAd[i][1] +"</a>";
			document.getElementById("adHead").href = itemAd[i][3];
			document.getElementById("adBody").innerHTML = itemAd[i][2];
		}
	}
}
