// ---------- script properties ----------


var results_location = "search.php";


// ---------- end of script properties ----------


function search_form(jse_Form) {
	if (jse_Form.d.value.length > 0) {
		document.cookie = "dt=" + escape(jse_Form.d.value);
		window.location = results_location;
	}
}

// ---------- script properties ----------

var include_num = 1;
var bold = 1;
var d = ''; 
// ---------- sites ----------


var s = new Array();

s[0] = "DUCK & HiPPO^index.php^We offer unique things to do in Singapore - enjoy a amphibious DUCKtours with us, take a ride on our city sightseeing HiPPO buses or cruise along Singapore River on the HiPPO river cruise.^experience, tours, promotions, programs, book now, city charm, cultural experience, must-see sights, city sightseeing, chinese culture, amphibious fun, river cruise, island getaway, garden & nature, chinese culture, indian insights, arab adventure, themed attractions";

s[1] = "Tours^tours.php^Select from the various tour packages that we offer^tour, tours, singapore pass, singapore sightseeing pass";

s[2] = "Promotions^promo.php^Children ride FREE with every adult this school holiday!^promotions, super duckies, charter, party hopper";

s[3] = "Programs^programs.php^Singapore History Edu-tour just for Primary school children!^programs, school edu-tour, corporate & group, club & association";

s[4] = "Singapore Pass^sp.php^This all-in-1 touring pass is ideal for you if you like to experience the city charm at your own pace and leisure.^singapore pass, city charm, all-in-1, hop-on, hop-off, attractions, tours";

s[5] = "Singapore Sightseeing Pass^ssp.php^This full day touring pass is perfect if you are looking for unlimited hop-on and hop-off rides on land and water!^singapore sightseeing pass, city sightseeing, multi-modal, hop-on, hop-off, night shopping, Moonlight Adventure";

s[6] = "DUCK^duck.php^Ride the Wacky DUCK and have a splashing fun time!^DUCK, DUCKtours, amphibious, war craft, land and sea adventure, wacky, Moonlight Adventure";

s[7] = "DUCK with Flyer^duckflyer.php^Ride the Wacky DUCK and view the World's Largest Observation Wheel^DUCK, DUCKtours, amphibious, war craft, land and sea adventure, wacky, Singapore Flyer";
//s[7] = "";

s[8] = "City Sightseeing Singapore^hippo.php^This full day touring pass allows you unlimited hop-on and hop-off rides along the City and Heritage routes!^HiPPO, City HiPPO, open-top touring system, hop-on, hop-off, transportation system, Heritage";

s[9] = "HiPPO River Tour^hipporiverbasic.php^For those on a tight schedule, this 30 minutes river tour is the best way to experience the Singapore River.^HiPPO River Tour, Singapore River, river experience, cruising, hop-on, hop-off, transportation system, Clarke Quay, Boat Quay";

s[10] = "Flyer with 2-way transfer^flyer.php^At 165 meters above ground, the world's tallest observation wheel has the best view of Singapore.^Singapore Flyer, observation wheel, magnificent cityscape, glittering night views, 360 degree, unobstructed view";

s[11] = "Night Safari Free & Easy with 2-way transfer^nightsafari.php^This free and easy package is ideal for you if you want to experience a nocturnal wildlife adventure with transportation all arranged!^Night Safari, night activities, wildlife night park, nocturnal animals, Creatures of the Night, interlinked walking trails";

s[12] = "Sentosa Transfer Shuttle^sentosa.php^Tour the popular island resort at your own pace. Hourly connections between Sentosa and the City are available on the Sentosa Rhino feeder.^Sentosa, Transfer Shuttle, free and easy, Underwater World, Sentosa Luge, Images of Singapore, Songs of the Sea, Palawan Beach, Silosa Beach";

s[13] = "Sentosa Scenic & Relax^sentosa_fun.php^This special combo package is great for you to experience some of the best scenic highlights of Sentosa in a day!^Sentosa, Island Getaway, Tiger Sky Tower, Images of Singapore, The Merlion";

s[14] = "Sentosa Wildfire^sentosa_wild.php^Keen to explore the beauty of Mother Nature? This tour is just designed for you!^Sentosa, Island Getaway, Butterfly Park, Insect Kingdom, Underwater World, Dolphin Lagoon";

s[15] = "Sentosa Adventure^sentosa_adventure.php^This package offers the perfect combo if you wish to excite your senses in all aspects!^Sentosa, Island Getaway, 4D Magix, Luge & Skyrides, Jungle Trail";

//s[16] = "Moonlight Adventure^moonlight.php^The Moonlight Adventure tour is ideal for you if you like to experience night life in the City!^night of feasting, shopping, Songs of the Sea, Bugis Village, Orchard Road, night life, Sentosa";
s[16] = "";

s[17] = "Super DUCKies Club^promo_superduckie.php^A loyalty programme for the young and inquisitive and most importantly, love for FUN. This program is tailored exclusively for kids between the ages of 3 to 12 years old.^kids, unlimited FREE rides, unlimited entries, loyalty programme, tailored exclusively, membership";

s[18] = "Flyer & HiPPO City^flyerhippo.php^This package allows you a full day access to unlimited hop-on and hop-off HiPPO buses along the City and Heritage routes, plus a ride on the magnificent Singapore Flyer!^open-top, hop-on, hop-off, Singapore Flyer, tallest observation wheel";

s[19] = "About Us^about.php^DUCK & HiPPO is a group of crazy (in a good way) people; committed to bringing a smile to every guest we serve.^fun, loving, crazy, committed, home-grown, wacky, enjoyable";

s[20] = "Charter Special^promo_charter.php^Fancy a private tour? Charters are available for the wacky DUCK, HiPPO topless bus and the HiPPO river cruise!^special charter, rates, private tour, customized tour, unique tour experience, wacky DUCK, HiPPO topless bus, HiPPO river cruise, routes";

s[21] = "Party Hopper^promo_party.php^For a unique private party, corporate event and media launch, check out the HiPPO Party Hopper!^unique private party, corporate event, media launch, no built-in seats, one-of-a-kind, unobstructed open space, mingle, chill, DJ, mobile clubbing experience, fabulous birthday party";

s[22] = "Corporate &amp; Group^programs_corp.php^Want a special program for a product launch, media conference or hospitality event? Let us propose an itinerary for you!^special program, product launch, propose an itinerary, museum tour incorporated, outdoor picnic planned, playground, special, customised package, signature tours, interesting stories, fun";

s[23] = "Club &amp; Association^programs_club.php^Want a special program for a product launch, media conference or hospitality event? Let us propose an itinerary for you!^special program, product launch, propose an itinerary, museum tour incorporated, outdoor picnic planned, playground, special, customised package, signature tours, interesting stories, fun";

s[24] = "Birthday Parties^promo_bd.php^Looking for a unique and fun way to celebrate your child's birthday?^birthday, party, guest, attractive prizes, party host, entertain, live commentary";

s[25] = "The Original Tour^ot.php^This full day touring pass allows you unlimited hop-on and hop-off rides along the Original Tour route!^Original Tour, hop-on, hop-off, full day, unlimited";

s[26] = "Trolley Day Tour^trolleyday.php^Get onto this classic Trolley and let our guide show you the sights and sounds that are uniquely Singapore.^Trolley, day tour, Civic District, Kampong Glam, Chinatown";

s[27] = "Red Lantern Night Trolley Tour^trolleynight.php^When the sun is down, come see the other side of Singapore. Visit the places off the beaten track!^Trolley, Red Lantern, night, red light district, katong, marine parade, geylang";

s[28] = "Trolley &amp; Boat^trolleyboat.php^Get entertained aboard our Trolley and experience Singapore by land and water from a whole new angle!^Trolley, HiPPO River Pass, boat, hop-on, hop-off";
// ---------- end of script properties and sites ----------

var cookies = document.cookie;
var p = cookies.indexOf("dt=");


if (p != -1) {
	var st = p + 3;
	var en = cookies.indexOf(";", st);
	if (en == -1) {
		en = cookies.length;
	}
	var d = cookies.substring(st, en);
	d = unescape(d);
}
var od = d;
var m = 0;
if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
	m = 1;
}

var r = new Array();
var co = 0;

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++;
				var pat = new RegExp(w[i], "i");
				var rn = s[c].search(pat);
				if (rn >= 0) {
					pa++;
				} else {
					pa = 0;
				}
			}
			if (woin[i] == 1) {
				var pat = new RegExp(w[i], "i");
				var rn = s[c].search(pat);
				if (rn >= 0) {
					pa = 0;
				}
			}
		}
		if (pa == nh) {
			r[a] = s[c];
			a++;
		}
	}
	co = a;
}

if (m == 1) {
	d = d.replace(/"/gi, "");
	var a = 0;
	var 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];
			a++;
		}
	}
	co = a;

}


function return_query() {
	document.jse_Form.d.value = od;
}

function num_jse() {
	var page_plural = "";
	if (co > 1) //add s to page if more than 1 page.
	{
		page_plural = "s";
	}
	document.write('[' + co + ' article' + page_plural + ' found]');
}

function out_jse() {
	document.jse_Form.elements["d"].value = od; //Write search query to search input box

	var no_articles = 7; //View no of articles in 1 page. Set to a higher/lower number accordingly.
	if (co == 0) {
		document.write('Your search for <b>"' + d + '"</b> did not match any documents. Make sure all keywords are spelt correctly. Try a different or more general keyword.');
		return;
	}

	document.write('<div id="slider1" class="sliderwrapper" style="width:480px;">'); //START content slider

	for (var a = 0; a < r.length; a++) {
		var os = r[a].split("^");
		//if (bold == 1 && m == 1) {
		if (bold == 1) {
			//var boldtext = new RegExp(d, "gi");
			//var br = "<b style='color: white; background: #CC0000;'>" + d + "</b>";
			//os[2] = os[2].replace(pat/gi, br);
			//os[2] = os[2].replace(boldtext, br);
			titletext = doHighlight(os[0], d, "", "");
			bodytext = doHighlight(os[2], d, "", "");
		}
		if (include_num == 1) {

			if (a == 0 || a % no_articles == 0) {
				//document.write ('START');
				document.write ('<div class="contentdiv" style="width:480px;">');
			}

			document.write('<p style="margin-bottom: 15px;"><b>', a + 1, '.</b> <a href="', os[1], '" style="font-weight: bold;">', titletext, '</a><br>', bodytext, '</p>');

			if (a + 1 == r.length || (a + 1)%no_articles == 0) {
				//document.write ('END');
				document.write ('</div>');
			}

		} else {
			document.write('<p style="margin-bottom: 15px;"><a href="', os[1], '" style="font-weight: bold;">', os[0], '</a><br>', os[2], '</p>');
		}

	} //END for loop
	document.write('</div>'); //END content slider

}

function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<b style='color: white; background: #CC0000;'>";
    highlightEndTag = "</b>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = searchTerm.toLowerCase();
  var lcBodyText = bodyText.toLowerCase();
    
  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = bodyText.toLowerCase();
          i = -1;
        }
      }
    }
  }
  
  return newText;
}

