Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

Search = function(){
	this.sForm = "frmOneField-Popup";
	this.sField = "ofs-ofq";
	this.sQueryPlaceholder = "ofs-ofq-ph";
	
	this.sQuery = "";
	
	this.sHyloHistory = new Array();
	
	//Placeholders
	this.sPlaceholder = "ofs-placeholder";
	this.sTabsPlaceholder = "ofs-tabs";
	this.sSidebarPlaceholder = "ofs-sidebar";
	
	this.arrPostalCode = new Array();
	this.arrTrackTrace = new Array();
	this.arrAddress = new Array();
	this.arrCity = new Array();
	this.arrHousenumber = new Array();
	this.arrProduct = new Array();
	this.arrTab = new Array();
	this.arrStreetname = new Array();
	
	this.sUrl = window.location;
	this.bZakelijk = true;
	
	this.sSidebarID = "341289";

	this.sHyloID = "337678";
	this.sTrackTraceID = "337682";
	this.sPostalcodeID = "337655";
	this.sOfficeID = "337686";
	this.sHelpID = "337684";
	this.sPriceWatchID = "340080";

	this.sHyloSidebarID = "341434";
	this.sTrackTraceSidebarID = "341437";
	this.sPostalcodeSidebarID = "341435";
	this.sHelpSidebarID = "341439";
	this.sOfficeSidebarID = "341436";
	this.sPriceWatchSidebarID = "341438";
	
	this.sHyloTCMUri = "";
	this.sTrackTraceTCMUri = "";
	this.sPostalCodeTCMUri = "";
	this.sOfficeTCMUri = "";
	this.sHelpTCMUri = "";
	this.sPriceWatchTCMUri = "";

	this.sHyloSidebarTCMUri = "";
	this.sTrackTraceSidebarTCMUri = "";
	this.sPostalCodeSidebarTCMUri = "";
	this.sOfficeSidebarTCMUri = "";
	this.sHelpSidebarTCMUri = "";
	this.sPriceWatchSidebarTCMUri = "";
	
	this.sZakelijkUri = "tcm:42-";
	this.sVoorthuisUri = "tcm:44-"
	this.sTargetUri = this.sZakelijkUri;
	
	this.init();
}

Search.prototype.init = function(){
	var oForm = document.getElementById(this.sForm);
	var oQuery = document.getElementById(this.sField);
	var oPlaceholder = document.getElementById(this.sPlaceholder);
	var self = this;

	new OFAutoSuggest(this.sField, {className:"autosuggest popup"});


	if(window.location.href.match("zakelijk")){
		this.bZakelijk = true;
		this.sTargetUri = this.sZakelijkUri;
	}else{
		this.bZakelijk = false;
		this.sTargetUri = this.sVoorthuisUri;
	}
	
	this.sHyloTCMUri = this.sTargetUri + this.sHyloID;
	this.sHyloSidebarTCMUri = this.sTargetUri + this.sHyloSidebarID;

	this.sTrackTraceTCMUri = this.sTargetUri + this.sTrackTraceID;
	this.sTrackTraceSidebarTCMUri = this.sTargetUri + this.sTrackTraceSidebarID;

	this.sPostalCodeTCMUri = this.sTargetUri + this.sPostalcodeID;
	this.sPostalCodeSidebarTCMUri = this.sTargetUri + this.sPostalcodeSidebarID;

	this.sOfficeTCMUri = this.sTargetUri + this.sOfficeID;
	this.sOfficeSidebarTCMUri = this.sTargetUri + this.sOfficeSidebarID;

	this.sHelpTCMUri = this.sTargetUri + this.sHelpID;
	this.sHelpSidebarTCMUri = this.sTargetUri + this.sHelpSidebarID;

	this.sPriceWatchTCMUri = this.sTargetUri + this.sPriceWatchID;
	this.sPriceWatchSidebarTCMUri = this.sTargetUri + this.sPriceWatchSidebarID;

	oPlaceholder.handler = this;
	if(oForm){
		if(oQuery){
			oForm.onsubmit = function(){
				self.query(oQuery.value);
				return false;
			}
			this.query(oQuery.value);
		}
	}
}

Search.prototype.initTabs = function(){
	var self = this;
	var oTabsPlaceholder = document.getElementById(this.sTabsPlaceholder);
	var arrTabs = oTabsPlaceholder.getElementsByTagName("li");
	var bPostalcode = false;
	var bTrackTrace = false;
	var bOffice = false;
	var bPrice = false;
	
	if(this.arrTrackTrace.length > 0 || this.arrTab.inArray("tracktrace")){
		bTrackTrace = true;
	}else if((this.arrAddress.length > 0 && this.sQuery.split(" ").length <= 3) || (this.arrPostalCode.length > 0 && this.arrHousenumber.length > 0) || (this.arrCity.length > 0 && this.sQuery.split(" ").length <= 3) || this.arrCity.length > 0 || this.arrTab.inArray("postcode")){
		bPostalcode = true;
	}else if(this.arrPostalCode.length > 0 || this.arrTab.inArray("locatiewijzer")){
		bOffice = true;
	}else if(this.arrTab.inArray("tarievenwijzer")){
		bPrice = true;
	}

	for(i = 0; i < arrTabs.length;i++){
		oTab = arrTabs[i];
		oTab.parent = oTabsPlaceholder;
		
		oTab.onclick = function(){
			arrTabs = this.parent.getElementsByTagName("li");
			for(i = 0; i < arrTabs.length;i++){
				removeClass(arrTabs[i], "current");
			}
			addClass(this, "current");
		}
		
		arrLinks = oTab.getElementsByTagName("a");
		arrLinks[0].onclick = function(){
			if(this.href.match("#hylo")){
				self.stats(this.sQuery, "Hylo");
				self.getHyloResult();
			}
			else if(this.href.match("#postalcode")){
				self.stats(this.sQuery, "Postcode zoeken");
				self.getPostalCodeResult();
			}
			else if(this.href.match("#office")){
				self.stats(this.sQuery, "Locatiewijzer");
				self.getOfficeResult();
			}
			else if(this.href.match("#tracktrace")){
				self.stats(this.sQuery, "Track & Trace");
				self.getTrackTraceResult();
			}
			else if(this.href.match("#price")){
				self.stats(this.sQuery, "Tarievenwijzer");
				self.getPriceResult();
			}
			else if(this.href.match("#help")){
				self.stats(this.sQuery, "Help");
				self.getHelpResult();
			}
		}
		

		if(arrLinks[0].href.match("#postalcode") && bPostalcode){
			addClass(oTab, "current");
		}else if(arrLinks[0].href.match("#office") && bOffice){
			addClass(oTab, "current");
		}else if(arrLinks[0].href.match("#tracktrace") && bTrackTrace){
			addClass(oTab, "current");
		}else if(arrLinks[0].href.match("#price") && bPrice){
			addClass(oTab, "current");
		}else if(arrLinks[0].href.match("#hylo") && !bPostalcode && !bOffice && !bTrackTrace && !bPrice){
			addClass(oTab, "current");
		}else{
			removeClass(oTab, "current");
		}
	}
}

Search.prototype.openTab = function(sLink){
	var self = this;
	var oTabsPlaceholder = document.getElementById(this.sTabsPlaceholder);
	var arrTabs = oTabsPlaceholder.getElementsByTagName("li");
	for(i = 0; i < arrTabs.length;i++){
		oTab = arrTabs[i];
		oTab.parent = oTabsPlaceholder;
		
		arrLinks = oTab.getElementsByTagName("a");
		
		if(arrLinks[0].href.match(sLink)){
			addClass(oTab, "current");
		}else{
			removeClass(oTab, "current");
		}
		
			if(sLink.match("#hylo")){
				self.stats(this.sQuery, "Hylo");
				self.getHyloResult();
			}
			else if(sLink.match("#postalcode")){
				self.stats(this.sQuery, "Postcode zoeken");
				self.getPostalCodeResult();
			}
			else if(sLink.match("#office")){
				self.stats(this.sQuery, "Locatiewijzer");
				self.getOfficeResult();
			}
			else if(sLink.match("#tracktrace")){
				self.stats(this.sQuery, "Track & Trace");
				self.getTrackTraceResult();
			}
			else if(sLink.match("#price")){
				self.stats(this.sQuery, "Tarievenwijzer");
				self.getPriceResult();
			}
			else if(sLink.match("#help")){
				self.stats(this.sQuery, "Help");
				self.getHelpResult();
			}
	}
}

Search.prototype.initSidebar = function(sSidebarTCMUri){
	var self = this;
	var oSidebar = document.getElementById(this.sSidebarPlaceholder);
	oSidebar.handler = self;
	this.showLoading(oSidebar.id);
	if(this.arrProduct.length > 0){
		var product = this.arrProduct[0];
		if(product.uri != ""){
			AJAXHandler.RenderComponent(product.uri, this.sSidebarPlaceholder, this.sSidebarPlaceholder, self.SidebarCallBack);
		}else{
			AJAXHandler.RenderComponent(sSidebarTCMUri, this.sSidebarPlaceholder, this.sSidebarPlaceholder, self.SidebarCallBack);
		}
	}else{
		AJAXHandler.RenderComponent(sSidebarTCMUri, this.sSidebarPlaceholder, this.sSidebarPlaceholder, self.SidebarCallBack);
	}
}

Search.prototype.initHylo = function(){
	var oPlaceholder = document.getElementById("ofs-placeholder");
	var self = oPlaceholder.handler;
	var oHyloLinksPlaceholder = document.getElementById("ofs-hyloresult");
	var oHyloLinksAltPlaceholder = document.getElementById("ofs-hyloresult-more");
	self.initHyloLinks(oHyloLinksPlaceholder, self);
	self.initHyloLinks(oHyloLinksAltPlaceholder, self);
}

Search.prototype.initHyloLinks = function(oHyloLinksPlaceholder, handler){
	var self = handler;
	oPlaceholder = document.getElementById(self.sPlaceholder);
	if(oHyloLinksPlaceholder != null){
		var arrLinks = oHyloLinksPlaceholder.getElementsByTagName("a");

		for(i = 0; i < arrLinks.length;i++){
			oLink = arrLinks[i];
			oLink.onclick = function(){
				var url = this.href;
				var vars = new Array();
				var querystring = "";
				var res = null;
				
				querystring = self.getQueryStringFromUrl(url);
				vars = self.getVarsFromQueryString(querystring);
				
				if(this.id.match("hylo_yes")){
					placeholder = document.getElementById("pulldown_" + vars["obj_id"]);
					if(!placeholder){
						placeholder = document.getElementById(self.sPlaceholder);
					}
					res = AJAXHandler.getHyloResult(self.sHyloTCMUri, placeholder.id, placeholder.id, querystring);
					self.goToPreviousQuestions(self);
				}else if(this.id.match("hylo_no")){
					placeholder = document.getElementById("pulldown_" + vars["obj_id"]);
					if(!placeholder){
						placeholder = document.getElementById(self.sPlaceholder);
					}
					res = AJAXHandler.getHyloResult(self.sHyloTCMUri, placeholder.id, placeholder.id, querystring);
					self.goToPreviousQuestions(self);
				}else if(!url.match("hylo")){
					window.location = url;
				}else if(querystring.match("obj_id")){
					placeholder = document.getElementById("pulldown_" + vars["obj_id"]);
					loader = document.getElementById("pulldown_" + vars["obj_id"]);
					if(placeholder.style.display == "none"){
						placeholder.handler = self;
						placeholder.style.display = "block";
						addClass(placeholder, "answer");
						this.fontWeight = "bold";
						self.showSmallLoading(loader.id);
					}else{
						this.fontWeight = "normal";
						placeholder.style.display = "none";
						removeClass(placeholder, "answer");
					}
					AJAXHandler.getHyloResult(self.sHyloTCMUri, placeholder.id, placeholder.id, querystring, self.HyloCallback);
				}else{
					placeholder = oPlaceholder;
					loader = oPlaceholder;
					self.showLoading(loader.id);
					AJAXHandler.getHyloResult(self.sHyloTCMUri, placeholder.id, placeholder.id, querystring, self.HyloCallback);
				}
				return false;
			}
		}
	}
}

Search.prototype.goBack = function(self, steps){
	for(i = 0; i < steps;i++){
		self.sHyloHistory.pop();
	}
	var oHyloResult = self.sHyloHistory[self.sHyloHistory.length - 1];
	var myPlaceHolder = document.getElementById(oHyloResult.HTML_ID);
	var myLoaderPlaceHolder = document.getElementById(oHyloResult.Loader_ID);
	if(oHyloResult.HTML.match("<redirect>")){
		window.location = oHyloResult.HTML.replace("<redirect>", "").replace("</redirect>", "")
	}else if(oHyloResult.HTML.match("ofs-hyloresultlinks")){
		myPlaceHolder = document.getElementById("ofs-placeholder");
		myPlaceHolder.innerHTML = oHyloResult.HTML;
	}else{
		myPlaceHolder.innerHTML = oHyloResult.HTML;
	}
	self.initHylo();
}

Search.prototype.goToPreviousQuestions = function(self){
	self.sHyloHistory.pop();
	oHyloResult = self.sHyloHistory[self.sHyloHistory.length - 1];
	var oHyloResult
	while(oHyloResult.HTML_ID != self.sPlaceholder && self.sHyloHistory.length > 0){
		self.sHyloHistory.pop();
		oHyloResult = self.sHyloHistory[self.sHyloHistory.length - 1];
	}
	var myPlaceHolder = document.getElementById(oHyloResult.HTML_ID);
	var myLoaderPlaceHolder = document.getElementById(oHyloResult.Loader_ID);
	if(oHyloResult.HTML.match("<redirect>")){
		window.location = oHyloResult.HTML.replace("<redirect>", "").replace("</redirect>", "")
	}else if(oHyloResult.HTML.match("ofs-hyloresultlinks")){
		myPlaceHolder = document.getElementById("ofs-placeholder");
		myPlaceHolder.innerHTML = oHyloResult.HTML;
	}else{
		myPlaceHolder.innerHTML = oHyloResult.HTML;
	}
	self.initHylo();
}

Search.prototype.getQueryStringFromUrl = function(sUrl){
	var arrUrl = sUrl.split("?");
	if(arrUrl.length > 1){
		return arrUrl[1];
	}else{
		return "";
	}
}

Search.prototype.getVarsFromQueryString = function(sQueryString){
	var vars = new Array();
	var tmp = sQueryString.split("&");
	for(i = 0;i < tmp.length;i++){
		myVar = tmp[i].split("=");
		vars[myVar[0]] = myVar[1];
	}
	return vars;
}

Search.prototype.initResultForm = function(){
	var self = this;
	var oPlaceholder = document.getElementById(this.sPlaceholder);
	var oForm = document.getElementById("onefieldResultFrm");
	if(oPlaceholder){
	    var arrLinks = oPlaceholder.getElementsByTagName("a");
		for(i = 0; i< arrLinks.length; i++){
			oLink = arrLinks[i];
			if(oLink.href.indexOf("#") > 0 && oLink.href.indexOf("#") < oLink.href.length){
			    oLink.onclick = function(){
			        self.openTab(this.href);
			    }
			}
		}
	}
	if(oForm){
		oForm.onsubmit = function(){
			var arrInputFields = this.getElementsByTagName("input");
			var arrSelectFields = this.getElementsByTagName("select");
			
			var query = "";
			for(i = 0; i< arrInputFields.length; i++){
				oField = arrInputFields[i];
				if(oField.type == "text" && oField.value != ""){
					if(oField.id != "")
					    query = query + oField.id + ":" + oField.value + ", ";
					else
					    query = query + oField.value + ", ";
				}
			}
			for(i = 0; i< arrSelectFields.length; i++){
				oField = arrSelectFields[i];
				query = query + oField.value + " "
			}
			oQField = document.getElementById(self.sField);
			oQField.value = query;
			self.query(query);
			return false;
		}
	}
}

Search.prototype.Callback = function(res){
	if(res.error){
    myPlaceHolder = document.getElementById("ofs-placeholder");
    var self = myPlaceHolder.handler;
    self.hideLoading(result.Loader_ID);
		myPlaceHolder.innerHTML = "Er is een fout opgetreden. Probeer het nog eens.";
	}else{
    var result = res.value;
    var myPlaceHolder = document.getElementById(result.HTML_ID);
    var self = myPlaceHolder.handler;
    self.hideLoading(result.Loader_ID);
		myPlaceHolder.innerHTML = result.HTML;
		self.initResultForm();
	}
}

Search.prototype.PostalCodeCallback = function(res){
	if(res.error){
        myPlaceHolder = document.getElementById("ofs-placeholder");
        var self = myPlaceHolder.handler;
        self.hideLoading(myPlaceHolder.id);
		myPlaceHolder.innerHTML = "Er is een fout opgetreden. Probeer het nog eens.";
	}else{
        var result = res.value;
        var myPlaceHolder = document.getElementById(result.HTML_ID);
        var self = myPlaceHolder.handler;
        if(result.parameters.length > 0){
            var postalcode = result.parameters[0][1];
            self.arrPostalCode.push(postalcode);
        }
        self.hideLoading(result.Loader_ID);
		myPlaceHolder.innerHTML = result.HTML;
		self.initResultForm();
	}
}

Search.prototype.HyloCallback = function(res){
	var oHyloResult = res.value;
	var myPlaceHolder = document.getElementById(oHyloResult.HTML_ID);
	var myLoaderPlaceHolder = document.getElementById(oHyloResult.Loader_ID);
	var self = myPlaceHolder.handler;
	self.sHyloHistory.push(oHyloResult);
	self.hideLoading(myLoaderPlaceHolder.id);
	if(res.error){
		myPlaceHolder.innerHTML = "Er is een fout opgetreden. Probeer het nog eens.";
	}else{
		if(oHyloResult.HTML.match("<redirect>")){
			window.location = oHyloResult.HTML.replace("<redirect>", "").replace("</redirect>", "")
		}else if(oHyloResult.HTML.match("ofs-hyloresultlinks")){
			myPlaceHolder = document.getElementById("ofs-placeholder");
			myPlaceHolder.innerHTML = oHyloResult.HTML;
		}else{
			myPlaceHolder.innerHTML = oHyloResult.HTML;
		}
		self.initHylo();
	}
}

Search.prototype.SidebarCallBack = function(res){
	if(res.error){
    myPlaceHolder = document.getElementById("ofs-sidebar");
    var self = myPlaceHolder.handler;
    self.hideLoading(result.Loader_ID);
		myPlaceHolder.innerHTML = "Er is een fout opgetreden. Probeer het nog eens.";
	}else{
    var result = res.value;
    var myPlaceHolder = document.getElementById(result.HTML_ID);
    var self = myPlaceHolder.handler;
    self.hideLoading(result.Loader_ID);
		myPlaceHolder.innerHTML = result.HTML;
		self.initResultForm();
	}
}


Search.prototype.showLoading = function(){
	if(!this.showLoading.arguments[0] || this.showLoading.arguments[0] == ""){
		id = this.sPlaceholder;
	}else{
		id = this.showLoading.arguments[0];
	}
	var myPlaceHolder = document.getElementById(id);
	myPlaceHolder.innerHTML = "Een moment geduld alstublieft. Uw gegevens worden opgehaald...";
	addClass(myPlaceHolder, "loader");
}

Search.prototype.showSmallLoading = function(){
	if(!this.showSmallLoading.arguments[0] || this.showSmallLoading.arguments[0] == ""){
		id = this.sPlaceholder;
	}else{
		id = this.showSmallLoading.arguments[0];
	}
	var myPlaceHolder = document.getElementById(id);
	addClass(myPlaceHolder, "loader");
	myPlaceHolder.innerHTML = "&nbsp;<br>";
}

Search.prototype.hideLoading = function(){
	if(!this.hideLoading.arguments[0] || this.hideLoading.arguments[0] == ""){
		id = this.sPlaceholder;
	}else{
		id = this.hideLoading.arguments[0];
	}
	var myPlaceHolder = document.getElementById(id);
	myPlaceHolder.innerHTML = "";
	removeClass(myPlaceHolder, "loader");
}

Search.prototype.getHyloResult = function(){
	var self = this;
	var sQuestion = this.sQuery;
	this.showLoading();
	AJAXHandler.RenderHyloResult(this.sHyloTCMUri, self.sPlaceholder, self.sPlaceholder, sQuestion, self.HyloCallback);
	this.initSidebar(this.sHyloSidebarTCMUri);
}

Search.prototype.getPostalCodeResult = function(){
  var self = this;
	var sPostalcode = "";
	var sStreet = "";
	var sNumber = ""
	var sCity = "";
	var address = null;
	var oAction = document.getElementById('action');
	var sAction = "";
	if(oAction)
	    sAction = oAction.value;
    if(sAction == "postalcode" || sAction == ""){
	    if(this.arrAddress.length > 0){
            address = this.arrAddress[0];
            sStreet = address.streetname;
            sNumber = address.housenumber;
	    }
	    if(this.arrStreetname.length > 0 && sStreet == ""){
		    sStreet = this.arrStreetname[0];
	    }
	    if(this.arrCity.length > 0){
		    sCity = this.arrCity[0];
	    }
	    if(this.arrHousenumber.length > 0 && sNumber == ""){
		    sNumber = this.arrHousenumber[0];
	    }
	}
	if(sAction == "address" || sAction == ""){
	    if(this.arrPostalCode.length > 0){
		    sPostalcode = this.arrPostalCode[0];
	    }
	    if(this.arrHousenumber.length > 0 && sNumber == ""){
		    sNumber = this.arrHousenumber[this.arrHousenumber.length - 1];
	    }
	}
	this.showLoading();
	AJAXHandler.RenderPostalCode(this.sPostalCodeTCMUri, sPostalcode, sStreet, sNumber, sCity, this.sPlaceholder, this.sPlaceholder, self.PostalCodeCallback);
	this.initSidebar(this.sPostalCodeSidebarTCMUri);
}
	
Search.prototype.getOfficeResult = function(){
	var self = this;
	var sPostalCode = "";
	if(this.arrPostalCode.length > 0){
        sPostalCode = this.arrPostalCode[0];
	}
	this.showLoading();
	AJAXHandler.RenderOffice(this.sOfficeTCMUri, sPostalCode, this.sPlaceholder, this.sPlaceholder, self.Callback);
	this.initSidebar(this.sOfficeSidebarTCMUri);
}
	
Search.prototype.getTrackTraceResult = function(){
	var self = this;
	var sTrackTraceCode = "";
	var sPostalcode = "";
	if(this.arrTrackTrace.length > 0){
    sTrackTraceCode = this.arrTrackTrace[0];
	}
	if(this.arrPostalCode.length > 0){
    sPostalcode = this.arrPostalCode[0];
	}
	this.showLoading();
	AJAXHandler.RenderTrackTrace(this.sTrackTraceTCMUri, sTrackTraceCode, sPostalcode, this.sPlaceholder, this.sPlaceholder, self.Callback);
	this.initSidebar(this.sTrackTraceSidebarTCMUri);
}
	
Search.prototype.getHelpResult = function(){
	var self = this;
	this.showLoading();
	AJAXHandler.RenderComponent(this.sHelpTCMUri, this.sPlaceholder, this.sPlaceholder, self.Callback);
	this.initSidebar(this.sHelpSidebarTCMUri);
}

Search.prototype.getPriceResult = function(){
	var self = this;
	this.showLoading();
	AJAXHandler.RenderPriceWatch(this.sPriceWatchTCMUri, this.sQuery, this.sPlaceholder, this.sPlaceholder, self.Callback);
	this.initSidebar(this.sPriceWatchSidebarTCMUri);
}

Search.prototype.filter = function(sQuery){
	var res = SearchHandler.Search(sQuery);
	var arrFilterResult = res.value;
	
	this.arrTrackTrace = new Array();
	this.arrPostalCode = new Array();
	this.arrAddress = new Array();
	
	//Arrange FilterResults
	for(i = 0; i < arrFilterResult.length; i++){
		for(j = 0; j < arrFilterResult[i][1].length; j++){
			if(arrFilterResult[i][0] == "TrackTraceFilter"){
				this.arrTrackTrace.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "PostalCodeFilter"){
				this.arrPostalCode.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "AddressFilter"){
				this.arrAddress.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "HousenumberFilter"){
				this.arrHousenumber.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "StreetnameFilter"){
				this.arrStreetname.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "CityFilter"){
				this.arrCity.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "CityCompare"){
				this.arrCity.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "TabCompare"){
				this.arrTab.push(arrFilterResult[i][1][j]);
			}else if(arrFilterResult[i][0] == "ProductCompare"){
				product = arrFilterResult[i][1][j];
				if(!this.bZakelijk && product.portal_id == 1){
					this.arrProduct.push(product);
				}else if(this.bZakelijk && product.portal_id == 2){
					this.arrProduct.push(product);
				}
			}
		}
	}
}

Search.prototype.stats = function(sQuery, sApplication){
       if (typeof(s) != "undefined" || typeof(s_account) != "undefined"){ // Omniture present?
             var s = s_gi(s_account);
             s.linkTrackVars = "prop1,eVar1";
             s.linkTrackEvents = "None";
             s.prop1 = s.eVar1 = sQuery;
             s.tl(true,"o","One Field Search : " + sApplication);
       }
}

Search.prototype.query = function(sInput){
	this.sQuery = this.clean(sInput);
	var oQueryPlaceholder = document.getElementById(this.sQueryPlaceholder);
	
	oQueryPlaceholder.innerHTML = sInput;
	
	//Run Filter
	
	this.arrPostalCode = new Array();
	this.arrTrackTrace = new Array();
	this.arrAddress = new Array();
	this.arrCity = new Array();
	this.arrHousenumber = new Array();
	this.arrProduct = new Array();
	this.arrTab = new Array();
	this.arrStreetname = new Array();

	this.filter(sInput);
	
	this.initTabs();
	
	//Run Template
	if(this.arrTrackTrace.length > 0 || this.arrTab.inArray("tracktrace")){
		this.stats(this.sQuery, "Track & Trace");
		this.getTrackTraceResult();
	}else if((this.arrAddress.length > 0 && this.sQuery.split(" ").length <= 3) || (this.arrPostalCode.length > 0 && this.arrHousenumber.length > 0) || (this.arrStreetname.length > 0 && this.arrHousenumber.length > 0) || (this.arrCity.length > 0 && this.sQuery.split(" ").length <= 3) || this.arrCity.length > 0 || this.arrTab.inArray("postcode")){
		this.stats(this.sQuery, "Postcode zoeken");
		this.getPostalCodeResult();
	}else if(this.arrPostalCode.length > 0 || this.arrTab.inArray("locatiewijzer")){
		this.stats(this.sQuery, "Locatiewijzer");
		this.getOfficeResult();
	}else if(this.arrTab.inArray("tarievenwijzer")){
		this.stats(this.sQuery, "Tarievenwijzer");
		this.getPriceResult();
	}else if(this.arrTab.inArray("help")){
		this.stats(this.sQuery, "Help");
		this.getHelpResult();
	}else{
		this.stats(this.sQuery, "Hylo");
		this.getHyloResult();
	}
	
	return false;
}

Search.prototype.clean = function(sQuery){
	sQuery = sQuery.replace("<", "");
	sQuery = sQuery.replace(">", "");
	sQuery = sQuery.replace("?", "");
	sQuery = sQuery.replace("&", "");
	return sQuery;
}
