/* ThinkQuest International 2006/2007
   TQ Toolkit - A web building guide for ThinkQuesters (C)
   Your TQ Guides (R)
   Visit http://library.thinkquest.org/06aug/02048/

*/

// ---------- sites ----------

var s = new Array();

s[0] = "2008, Year of Sanitation^2008.html^Year 2008 is the International Year of Sanitation.^2008,iys,international,year,sanitation";
s[1] = "About Site^aboutsite.html^Summary of this site and its development process.^about,site,development,technology";
s[2] = "About Team^aboutteam.html^About the team, our collaboration, and our diversity^team,member,collaboration,diversity,about";
s[3] = "Acknowledgments^acknowledgments.html^Credits, references, and permissions.^credits,references,permission,citation,link,source";
s[4] = "Educational Presentation^ajaxs.html^AJAX powered web presentation for educators.^present,show,teach,spread,educate";
s[5] = "Big Business!^big.html^Saniation system, diseases, and ecological sanitation^,closing,loop,eco,sanitation,eco,sanitation,disease,economy,death,nutrients,reuse,recycle,circle";
s[6] = "BlissfuLoo Project^blissfuloo.html^Everything that is important to a toilet's design^creativity,design,guidelines,idea,team,toilet";
s[7] = "Conclusion^conclusion.html^Concluding statements on breaking the taboo^avoid,break,taboo,conclude,overview";
s[8] = "The Dark Side^darkness.html^Most dirtiest place of an entire toilet, all listed out^flash,video,flv,experiment,analysis,dirty,dirtiest,handle,bowl,seat,urinal,tap,sink";
s[9] = "Disclaimer^disclaimer.html^Disclaimer";
s[10] = "Download^download.html^Download entire site in zip format.^download,zip,entire,site";
s[11] = "Etiquette & Culture^etiquette.html^General toilet etiquette for both genders, and common myths demystified.^myths,truth,lift,lower,squat,sit,wash,wipe,close,open,male,female";
s[12] = "Imagine This...^flushstory.html^Introduction to Flush section - all about meeting the goals.^meet,goals,flush,imagine";
s[13] = "Global Outlook^global.html^International organizations, services, and information.^global,world,near,association,organization,distribution";
s[14] = "Help^help.html^All questions addressed in help!^help,problem,faq";
s[15] = "Up the Hygiene^hygiene.html^Learn the proper toilet procedures and have a test of your knowledge!^golden,rules,toilet,hygiene,test,7,reason,game,flash";
s[16] = "International Efforts^international.html^International organizations taht are trying to better the situation^WTO,WTA,Sulabh,Sanicon,WSP,UNICEF,world,toilet,association,connection,united,nation,children,fund";
s[17] = "Introduction^introduction.html^The introduction to the entire site^intro,tour,objectives,scope,audience,who";
s[18] = "Choose Your Path...^introstory.html^Decide on Pee or Poo.^decide,pee,poo,path";
s[19] = "All about Loos^loos.html^The history of toilet and sanitation.^history,sanitation,toilet,story,past,time";
s[20] = "Millennium Development Goals^mdg.html^United Nation's Millennium Development Goals^mdg,millennium,development,goals";
s[21] = "Home^home.html^Home page of Pee or Poo: Break the Taboo!^trailer,tour";
s[22] = "Orientation^orientation.html^Structured path, or the open path.^path,structured,open,storyline,choice";
s[23] = "Imagine This...^peestory.html^Introduction to Pee^intro,pee,overview";
s[24] = "Imagine This...^poostory.html^Introduction to Poo^intro,poo,overview";
s[25] = "Preferences^preferences.html^Style switching.^preferences,style,switch,look";
s[26] = "Little Secrets^secrets.html^Secrets and unknowns of the toilet^slideshow,spot,contamination,game,flash,frog,in,well,facts";
s[27] = "Toilet Proficiency Test^tpt.html^Final quiz to see if you have truly learnt anything^proficiency,test,flash,game,knowledge,learnt,learned";
s[28] = "It Used to Be^usedtobe.html^How mankind has dealt with sanitation in the past^scavengers,pathak,recycle,gold,farmer,agricultural,what,population,boom";
s[29] = "Our Voices^voices.html^Podcasts to spread the cause.^podcast,mp3,download,stream,archery,queue,language,where,maintenance,specialist,restroom,diarrhea,alert";
s[30] = "World Toilet Day^wtday.html^What is this day about, and how long more from now!^toilet,day,countdown,when,significance";
s[31] = "Glossary^glossary.html^Glossary";

// ---------- end of sites ----------
var d = "";
var od = "";
var m = 0;
var r = new Array();
var co = 0;
var pat = "";
var hitnum = new Array();

function search_form() {
	//Initialise again
	d = "";
	od = "";
	m = 0;
	r = new Array();
	co = 0;
	pat = "";
	hitnum = new Array();
	//End of init
	if (document.getElementById) {
		var keyword = document.getElementById("searchtxt");
		if (keyword.value.length > 0) 
			d = keyword.value;

od = d;

if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
	m = 1;
}

if (m == 0) {
	var woin = new Array();
	var w = d.split(" ");
	for (var a = 0; a < w.length; a++) {
		woin[a] = 0;
		if (w[a].charAt(0) == '-') {
			woin[a] = 1;
		}
	}
	for (var a = 0; a < w.length; a++) {
		w[a] = w[a].replace(/^\-|^\+/gi, "");
	}
	a = 0;
	for (var c = 0; c < s.length; c++) {
		pa = 0;
		nh = 0;
		for (var i = 0; i < woin.length; i++) {
			if (woin[i] == 0) {
				nh++;
				pat = new RegExp(w[i], "i");
				var rn = s[c].search(pat);
				if (rn >= 0) {
					pa++;
				} else {
					pa = 0;
				}
			}
			if (woin[i] == 1) {
				pat = new RegExp(w[i], "i");
				var rn = s[c].search(pat);
				if (rn >= 0) {
					pa = 0;
				}
			}
		}
		if (pa == nh) {
			r[a] = s[c];
			hitnum[a] = c;
			a++;
		}
	}
	co = a;
}

if (m == 1) {
	d = d.replace(/"/gi, "");
	var a = 0;
	pat = new RegExp(d, "i");
	for (var c = 0; c < s.length; c++) {
		var rn = s[c].search(pat);
		if (rn >= 0) {
			r[a] = s[c];
			hitnum[a] = c;
			a++;
		}
	}
	co = a;
}
}
}

function getpage() {
	var memory = s[this.lastChild.getAttribute("id")].split("^");
	if (memory[1] == "skinchooser.html")
		loadobjs('scripts/skin.js');
	ajaxpage(memory[1], "contentpage");
}

function num_jse() {
	if (document.createTextNode)
	{
		var text = document.getElementById("pagefound");
		var num = document.createTextNode(co);
		var extra = document.createTextNode(" page(s) found");
		while (text.firstChild)
			text.removeChild(text.firstChild);
		text.appendChild(num);
		text.appendChild(extra);
	}
}

function out_jse() {
	if (document.createTextNode && document.createElement) {
	var textarea = document.getElementById("result");
	while (textarea.firstChild)
		textarea.removeChild(textarea.firstChild);
	if (co == 0) {
		var nomatch = document.createTextNode("Your search did not match any documents.");	
		var makesure = document.createTextNode("Make sure all keywords are spelt correctly.");
		var diff = document.createTextNode("Try different or more general keywords.");
		textarea.appendChild(nomatch);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(makesure);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(diff);
	}
	else {
	var first = new Array();
	var second = new Array();
	var third = new Array();
	var bolded = new Array();
	var fourth = new Array();
	var hyplink = new Array();
	var hidden = new Array();
	for (var a = 1; a < r.length+1; a++) {
		var os = r[a-1].split("^");
		//os[1] is now the href, os[2] the description, d is the keyword, pat is /d/i
		//if (m == 1) {
		os[2] = os[2].replace(pat, d);
		if (os[2].indexOf(d) != -1) {
			var beg = os[2].substr(0, os[2].indexOf(d));
			var end = os[2].substr(os[2].indexOf(d)+d.length); }
		else {
			var beg = os[2];
			var end = "";
		}
		first[a-1] = document.createTextNode(a+". ");
		textarea.appendChild(first[a-1]);
		hyplink[a-1] = document.createElement("a");
		hyplink[a-1].setAttribute("href", "#contentarea");
		hyplink[a-1].setAttribute("class", "external");
		hyplink[a-1].setAttribute("className", "external");
		second[a-1] = document.createTextNode(os[0]);
		hyplink[a-1].appendChild(second[a-1]);
		hidden[a-1] = document.createElement("span");
		hidden[a-1].appendChild(document.createTextNode(os[1]));
		hidden[a-1].setAttribute("id", hitnum[a-1]);
		hidden[a-1].style.display = "none";
		hyplink[a-1].appendChild(hidden[a-1]);
		textarea.appendChild(hyplink[a-1]);
		textarea.appendChild(document.createElement("br"));
		third[a-1] = document.createTextNode(beg);
		textarea.appendChild(third[a-1]);
		if (os[2].indexOf(d) != -1) {
		bolded[a-1] = document.createElement("b");
		bolded[a-1].appendChild(document.createTextNode(d)); 
		textarea.appendChild(bolded[a-1]);}
		fourth[a-1] = document.createTextNode(end);
		textarea.appendChild(fourth[a-1]);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(document.createElement("br"));
		hyplink[a-1].onclick = getpage;
	}
	}
	}
	return;
}
 {
		var nomatch = document.createTextNode("Your search did not match any documents.");	
		var makesure = document.createTextNode("Make sure all keywords are spelt correctly.");
		var diff = document.createTextNode("Try different or more general keywords.");
		textarea.appendChild(nomatch);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(makesure);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(diff);
	}
	else {
	var first = new Array();
	var second = new Array();
	var third = new Array();
	var bolded = new Array();
	var fourth = new Array();
	var hyplink = new Array();
	var hidden = new Array();
	for (var a = 1; a < r.length+1; a++) {
		var os = r[a-1].split("^");
		//os[1] is now the href, os[2] the description, d is the keyword, pat is /d/i
		//if (m == 1) {
		os[2] = os[2].replace(pat, d);
		if (os[2].indexOf(d) != -1) {
			var beg = os[2].substr(0, os[2].indexOf(d));
			var end = os[2].substr(os[2].indexOf(d)+d.length); }
		else {
			var beg = os[2];
			var end = "";
		}
		first[a-1] = document.createTextNode(a+". ");
		textarea.appendChild(first[a-1]);
		hyplink[a-1] = document.createElement("a");
		hyplink[a-1].setAttribute("href", "#contentarea");
		hyplink[a-1].setAttribute("class", "external");
		hyplink[a-1].setAttribute("className", "external");
		second[a-1] = document.createTextNode(os[0]);
		hyplink[a-1].appendChild(second[a-1]);
		hidden[a-1] = document.createElement("span");
		hidden[a-1].appendChild(document.createTextNode(os[1]));
		hidden[a-1].setAttribute("id", hitnum[a-1]);
		hidden[a-1].style.display = "none";
		hyplink[a-1].appendChild(hidden[a-1]);
		textarea.appendChild(hyplink[a-1]);
		textarea.appendChild(document.createElement("br"));
		third[a-1] = document.createTextNode(beg);
		textarea.appendChild(third[a-1]);
		if (os[2].indexOf(d) != -1) {
		bolded[a-1] = document.createElement("b");
		bolded[a-1].appendChild(document.createTextNode(d)); 
		textarea.appendChild(bolded[a-1]);}
		fourth[a-1] = document.createTextNode(end);
		textarea.appendChild(fourth[a-1]);
		textarea.appendChild(document.createElement("br"));
		textarea.appendChild(document.createElement("br"));
		hyplink[a-1].onclick = getpage;
	}
	}
	}
	return;
}
