﻿var searchClient = function (settings) {
	this.advancedSearchUrl = settings.advancedSearchUrl;
	this.cQS_SearchText = "SearchText";
	this.cQS_SearchType = "SearchType";
	this.cQS_SectionIDs = "SectionIDs";

	this.cSearchTypeMatchAny = 0x0001;
	this.cSearchTypeMatchAll = 0x0002;

	this.bindEvents();
};

searchClient.prototype = {
	bindEvents: function () {
		var env = this;
		$(document).ready(function (e) {
			$(".btnSearch2").click($.proxy(env.performSearch, env));
			$(".txtSearchValue2").keyup(function (event) {
				if (event.keyCode == 13) {
					event.preventDefault();
					$(".btnSearch2").click();
					return false;
				}
			});

		});
	},

	performSearch: function (e) {
		e.preventDefault();

		var text = $(".txtSearchValue2").val();
		text = text.replace(/(^\s+)|(\s+$)/g, "");
		text = text.replace(/(^\xA0+)|(\xA0+$)/g, ""); // remove &nbsp; (char 160)

		if (text.length != 0) {
			this.advancedSearchUrl += "&" + Search.cQS_SearchText + "=" + escape(text);
			this.advancedSearchUrl += "&" + Search.cQS_SearchType + "=" + Search.cSearchTypeMatchAny;
			window.document.location.href = this.advancedSearchUrl;
		}
	}
}
