var hash_url_delimiter = "/";var hasType = false;var multi_search_del = "+";var page_type = "";var keyword_idx = false;var may_load = false;var currentAnchor = "";var may_regen_sidebar = false;var key = "";$(document).ready(function() {	$('.sidebarAjaxSearchLink').live("click", function() {		callLoadingSearch();		var element = $(this);		var href    = element.attr('href');		$.get(href, function(data) {			$('#goormeLoadingGridBox').parent().parent().addClass("isHidden");			$('#goormeMainSidebar').after(data);		});		return false;	});	$('.remove_logs').live("click", function() {		var search_params = document.location.hash.substring(2).split(multi_search_del);		var rel = $(this).attr('rel');		var idx = $("#" + rel).val();		var is_keyword = false;		var check = rel.split("-");		if(check[0] == 'keyword')			is_keyword = true;		$("#" + rel).remove();		search_params.splice(idx,1);		var params_length = search_params.length;		var length = $("#hidden_nav").children().length;		callLoadingSearch();		if(is_keyword === false)		{			$(this).addClass('links');			$(this).removeClass('remove_logs');		}		if(length == 0 || params_length == 0)		{			document.location.hash = "";			currentAnchor = document.location.hash;			hasType = false;			hideFilter();			regenerate_sidebar(page_type, "");			$.get("/search/hashsearch", "type=" + page_type, function(data) {				afterPaging(data);			});		}		else		{			document.location.hash = "!" + search_params.join(multi_search_del);				var is_type_exist = urlHasType();				if(is_type_exist == false)				{					document.location.hash = "!" + search_params.join(multi_search_del) + "type=" + page_type;				}				currentAnchor = document.location.hash;				dohashsearch();		}		$(this).parent('li').removeClass('isSelected');		if(is_keyword === false)			$(this).children().remove();		return false;	});	if ("onhashchange" in window) {		window.onhashchange = checkAnchor;		setTimeout("checkAnchor()", 300);	}	else		setInterval("checkAnchor()", 300);});//Function which chek if there are anchor changes, if there are, sends the ajax petitionfunction checkAnchor(){	var isForm = false;	var cur_url_has_type = false;	if(currentAnchor != document.location.hash && may_load === true)	{		if(currentAnchor != null)		{			// check if there's exclamation mark in anchor			// if it's not exist, skip the process			var excluded = document.location.hash.substring(2,3) == '&';			var hasExMark = document.location.hash.substring(1,2) == '!';			if (excluded == true || hasExMark == false) {				return false;			}			callLoadingSearch();			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2			//http://sitoesmarket.localhost/dishes#!beef/cuisine=indonesian/tag=food			var splits = document.location.hash.substring(2).split(hash_url_delimiter);			//Get the section			var keyword = splits[0];			delete splits[0];			if (keyword == "nearme")			{				var params = splits.join("");				$.get("/search/ajax_from/popular", params, function(data) {					afterPaging(data);				});			} else if (keyword == "recommendation"){				for(var j = 0; j < splits.length ; j ++)				{					if(splits[j] == undefined || splits[j] == "")					{						splits.splice(j,1);					}				}				var params = splits.join("&");				$.get("/search/recommend_item/", params, function(data) {					afterPaging(data);					if($("#filterContainer").length > 0)						$("#filterContainer").removeClass("isHidden");				});				$.get("/search/fill_filter_number/", params, function(data) {					$("#filterContainer").html(data);				});			} else if (keyword == "editorial") {				var params = splits.join("");				$.get("/search/ajax_editorial", params, function(data) {					afterPaging(data);				});			} else if (keyword == "dislikedtc") {				var params = splits.join("&");				params = params;				var query = "";				if (keyword != "")					query = "type=" + keyword + params;				else					query = params.substring(1);				$.get("/search/fill_filter_number/", query, function(data) {					$("#filterContainer").html(data);						$('#goormeLoadingGridBoxContainer').addClass("isHidden");					if($("#filterContainer").length > 0)						$("#filterContainer").removeClass("isHidden");				});			} else if (keyword == "loved" || keyword == "submitted" || keyword == "reviewed" || keyword == "commented"					|| keyword == "user_default" || keyword == 'tried' || keyword == 'follower' || keyword == 'following'					|| keyword == 'bookmarked' || keyword == 'disliked' || keyword == 'rated' || keyword == "tipped" || keyword == "friend")			{				var params = splits.join("&");				params = params;				var query = "";				if (keyword != "")					query = "type=" + keyword + params;				else					query = params.substring(1);				$.get("/search/fill_filter_number/", query, function(data) {					$("#filterContainer").html(data);				});				$.get("/search/hashsearch", query, function(data) {					afterPaging(data);					if($("#filterContainer").length > 0)						$("#filterContainer").removeClass("isHidden");				});			} else if (keyword == "myhistory") {				$.get("/activities/ajax_recent_history/", function(data) {						$('#goormeLoadingGridBoxContainer').addClass("isHidden");						$('#goormeMainSidebar').append(data);				});			} else if (keyword == "profile") {			} else {				currentAnchor = currentAnchor.substring(2);				var prevUrl = document.location.hash.substring(2);				var arr = prevUrl.split(multi_search_del);				var keep_key = '';				var get_url = document.location.hash;				var get_pass = get_url.split(hash_url_delimiter);				for(var i = 0 ; i < get_pass.length ; i++){					var get_param = get_pass[i].split("=");					if(get_param[0] == 'keyword'){						keep_key = get_param[1];					}				}				if(hasType == false)				{					var has_keyword = false;					key = splits[1].split("=")[1];					for(var p = 0 ; p < arr.length ; p++)					{						var par = arr[p];						var arrPar = par.split(hash_url_delimiter);						for(var r = arrPar.length-1 ; r >= 0 ; r--)						{							if(arrPar[r] != "")							{								var type_temp = arrPar[r].split("=")[0];								var type_value = arrPar[r].split("=")[1];								if(type_temp == 'type')								{									hasType = true;									page_type = arrPar[r].split("=")[1];									if(type_value == 'menus' || type_value == 'recipes'){										if(type_value == 'menus'){											type_value = 'menu';										} else if(type_value == 'recipes'){											type_value = 'recipe';										}										document.location.hash = '!/keyword=' + keep_key + '/type=' + type_value;									}									break;								} else if(type_temp == 'keyword') {									var current_page = arrPar[r].split("=")[1];									var arrBefore = currentAnchor.split(hash_url_delimiter);									for(var p = 0 ; p < arrBefore.length ; p++)									{										if(arrBefore[p] != '')										{											var typeBefore = arrBefore[p].split("=")[0];											var last_keyword = arrBefore[p].split("=")[1];											if(typeBefore == "keyword")											{												arrBefore[p] = "keyword=" + current_page;												if(current_page != last_keyword){													may_regen_sidebar = true;												}												currentAnchor = arrBefore.join(hash_url_delimiter);												arrPar.splice(r,1);												has_keyword = true;												break;											}										}									}								} else if(type_temp == 'page') {									var current_page = arrPar[r].split("=")[1];									var arrBefore = currentAnchor.split(hash_url_delimiter);									for(var p = 0 ; p < arrBefore.length ; p++)									{										if(arrBefore[p] != '')										{											var typeBefore = arrBefore[p].split("=")[0];											if(typeBefore == "page")											{												arrBefore[p] = "page=" + current_page;												currentAnchor = arrBefore.join(hash_url_delimiter);												arrPar.splice(r,1);												has_keyword = true;												break;											}										}									}								}							} else if(arrPar[r] == "") {								arrPar.splice(r,1);							}						}						if(hasType == true)						{							break;						}					}				} else {					var arrAnchor =	document.location.hash.substring(2).split(hash_url_delimiter);					for(var q = arrAnchor.length-1 ; q >= 0 ; q--)					{						if(arrAnchor[q] == "")						{							arrAnchor.splice(q,1);						}						else						{							var type_temp = arrAnchor[q].split("=")[0];							if(type_temp == 'type')							{								arrAnchor.splice(q,1);								cur_url_has_type = true;							}							else if(type_temp == 'page')							{								var current_page = arrAnchor[q].split("=")[1];								var arrBefore = currentAnchor.split(hash_url_delimiter);								for(var p = 0 ; p < arrBefore.length ; p++)								{									if(arrBefore[p] != '')									{										var typeBefore = arrBefore[p].split("=")[0];										if(typeBefore == "page")										{											arrBefore[p] = "page=" + current_page;											currentAnchor = arrBefore.join(hash_url_delimiter);											arrAnchor.splice(q,1);											break;										}									}								}							} else {								if(may_regen_sidebar === false)								{									arrAnchor.splice(q,1);								}							}						}					}					// # Paging					// Current					var paging = new Boolean();					paging = false;					var current_keyword = '';					var past_keyword = '';					var set_keyword = '';					var current = document.location.hash;					var get_by_current = current.split(hash_url_delimiter);					// Check for paging					for(var i = 0 ; i < get_by_current.length ; i++){						var current_param = get_by_current[i].split("=");						if(current_param[0] == 'page'){							paging = true;						}						if(current_param[0] == 'keyword'){							current_keyword = current_param[1];						}					}					//--					// Past					var paging_past = new Boolean();					paging_past = false;					var past = currentAnchor;					var get_by_pass = past.split(hash_url_delimiter);					// Check for paging					for(var i = 0 ; i < get_by_pass.length ; i++){						var past_param = get_by_pass[i].split("=");						if(past_param[0] == 'page'){							paging_past = true;						}						if(past_param[0] == 'keyword'){							past_keyword = past_param[1];							key = past_keyword;						}					}					//--					if(current_keyword != past_keyword && current_keyword != ''){							key = current_keyword;						document.location.hash = '!/keyword=' + current_keyword + '/';					} else {						if(paging == false){							var type = '';							var past_category = '';							var current_category = '';							var past_param = '';							var current_param = '';							// Past category							if(paging_past == true){							for(var i = 0 ; i < get_by_pass.length ; i++){								past_param = get_by_pass[i].split("=");									if(past_param[0] == 'ingredient[]' || past_param[0] == 'tag[]' || past_param[0] == 'cuisine[]' || past_param[0] == 'price[]'										|| past_param[0] == 'venuetype[]' || past_param[0] == 'category[]' || past_param[0] == 'cat[]' || past_param[0] == 'userarticle'										|| past_param[0] == 'editorial' || past_param[0] == 'halal' || past_param[0] == 'spicy' || past_param[0] == 'vegetarian' || past_param[0] == 'city'){										past_category += '/' + past_param[0] + '=' + past_param[1] + '/+';									}								}							}							// Current category							for(var i = 0 ; i < get_by_current.length ; i++){								current_param = get_by_current[i].split("=");								if(current_param[0] == 'ingredient[]' || current_param[0] == 'tag[]' || current_param[0] == 'cuisine[]' || current_param[0] == 'price[]'									|| current_param[0] == 'venuetype[]' || current_param[0] == 'category[]' || current_param[0] == 'cat[]' || current_param[0] == 'userarticle'									|| current_param[0] == 'editorial' || current_param[0] == 'halal' || current_param[0] == 'spicy' || current_param[0] == 'vegetarian' || current_param[0] == 'city'){									current_category += current_param[0] + '=' + current_param[1];								}							}							if(current_param[0] == 'halal' || current_param[0] == 'spicy' || current_param[0] == 'vegetarian'){								may_regen_sidebar = true;							}							if(past_category != ''){								document.location.hash = '!/' + current_category + '/' + multi_search_del + past_category + '/';							} else {								document.location.hash = '!/' + current_category + '/' + multi_search_del + past;							}						} else {							document.location.hash = current;						}					}					// #--				}				var check_key = checkTypeAvailable(document.location.hash.substring(2), 'keyword');				if(check_key !== false)				{					$(".keyword_class").removeClass("gm_Watermark");					var arrKeyword = check_key.split("@");					$(".keyword_class").val(arrKeyword[0]);					if(arrKeyword.length > 1)					{						var keyword_search = arrKeyword[0];						var keyword_location = arrKeyword[1];						var container = '<a class = "remove_search_location" href="#!' + keyword_search + '">' + keyword_location + '</a>';						$("#search_location").html(container);						$("#search_location").removeClass("isHidden");					}				}				var check_editorial 	= checkTypeAvailable(document.location.hash.substring(2), 'editorial');				var check_userarticle 	= checkTypeAvailable(document.location.hash.substring(2), 'userarticle');				var check_spicy 		= checkTypeAvailable(document.location.hash.substring(2), 'spicy');				var check_vegetarian 	= checkTypeAvailable(document.location.hash.substring(2), 'vegetarian');				var check_halal 		= checkTypeAvailable(document.location.hash.substring(2), 'halal');				var check_creditcard 	= checkTypeAvailable(document.location.hash.substring(2), 'creditcard');				var check_type = checkTypeAvailable(document.location.hash.substring(2), 'type');				if(check_type === false && cur_url_has_type === true)				{					document.location.hash += "type=" + page_type;				}				currentAnchor = document.location.hash;				dohashsearch();			}		}		currentAnchor = document.location.hash;	}}function afterPaging(data){	$('#goormeLoadingGridBoxContainer').addClass("isHidden");	$("#goormePagination").removeClass('isHidden');	$('#goormeMainSidebar').append(data);}function dohashsearch(){			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2			//http://sitoesmarket.localhost/dishes#!beef/cuisine=indonesian/tag=food			var splits = currentAnchor.substring(2).split(hash_url_delimiter);			//Get the section			var keyword = splits[0];			delete splits[0];				document.title = "Hasil Pencarian " + keyword + " | Goorme";				if (splits.length == 3) {					var params1 = splits[1].split('=');					var params2 = splits[2].split('=');					if (params1[0] == 'type' && params2[0] == 'page') {						switch(params1[1]) {							case 'dish':								document.title = 'Indonesia Online Menu, Dish Directory, Food Guide and Reviews - page '+ params2[1] +' | Goorme';								break;							case 'businesses':								document.title = 'Indonesia Dining Guide, Restaurant Directory and Reviews - page '+ params2[1] +' | Goorme ';								break;							case 'articles':								document.title = 'Food and Culinary Articles - page '+ params2[1] +' | Goorme';								break;							case 'roll':								document.title = 'Food and Culinary Rolls - page '+ params2[1] +' | Goorme';								break;							case 'promotions':								document.title = 'Indonesia Restaurant Promos, Food Discounts, Credit Card Deals, and Privilege - page '+ params2[1] +' | Goorme';								break;							case 'recipe':								document.title = 'Indonesia Online Recipes Sharing - page '+ params2[1] +' | Goorme';								break;						}					}				}				var valid_alltypes = "";				var current_type = "";				for(var i = splits.length-1 ; i > 0  ; i--)				{					if(splits[i] == '+')					{						splits.splice(i,1);					}					else					{						if(splits[i].split("=").length > 1)						{							var type_param = splits[i].split("=")[0];							if(type_param.length > 0)							{								if(type_param == "type")								{									var typename = splits[i].split("=")[1];									current_type = typename;									if (typename == 'index')									{										valid_alltypes = "&type=dish/venue/article/promotion/recipe";										splits.splice(i, 1);									}								} else if(type_param == "bank") {									var bankname = splits[i].split("=")[1];									document.title = bankname + " Promos, Food Discounts, Credit Cards Deal, and Privilege " + keyword + " - Goorme.com";								} else if(type_param == "keyword") {									var word = splits[i].split("=")[1];									splits[i] = type_param + "=" + escape(word);								}							}						} else {							if(splits[i].split("=")[0] != '')								splits[i] = "keyword" + "=" + escape(splits[i].split("=")[0]);						}					}				}				var params = splits.join("&");				params = params + valid_alltypes;				keyword = escape(keyword);				var query = "";				if (keyword != "")					query = "keyword=" + keyword + params;				else					query = params.substring(1);				$.get("/search/hashsearch", query, function(data) {					afterPaging(data);				});				if(may_regen_sidebar == true)					regenerate_sidebar(current_type, query);		//set the search logs		$("#search_logs").html("");		$("#filteron").addClass("isHidden");		$("#filteroff").removeClass("isHidden");		if(currentAnchor != null && currentAnchor != "")		{			var search_params = currentAnchor.substring(2).split(multi_search_del);			$("#hidden_nav").html("");			for(var t = 0 ; t < search_params.length ; t++)			{				var filter = search_params[t].split(hash_url_delimiter);				var display_text = "";				for(var w = 0 ; w < filter.length ; w++)				{					if(filter[w] != "")					{						if(filter[w].split("=").length > 1)						{							var type_param = filter[w].split("=")[0];							var param_val = filter[w].split("=")[1];						} else {							var type_param = "keyword";							var param_val = filter[w].split("=")[0];							keyword_idx = t;						}						if(type_param != "")						{							type_param = type_param.replace("[]", "");						}						if(type_param != "type" && type_param != "page")						{							if(type_param == "keyword")							{								keyword_idx = t;								$("#keyword_bread").text(param_val);							}							else if(type_param == "userarticle")								keyword_idx = t;							else if(type_param == "editorial")								keyword_idx = t;							else if(type_param == "spicy")								keyword_idx = t;							else if(type_param == "vegetarian")								keyword_idx = t;							else if(type_param == "halal")								keyword_idx = t;							else if(type_param == "creditcard")								keyword_idx = t;							if(w > 0 && display_text != "")							{								display_text += ", ";							}							display_text += type_param + " : " + param_val;							var container = '<input value="' + t + '" type = "hidden" id="' + type_param + '-' + param_val + '"' + '</a>';							$("#hidden_nav").append(container);						}					}				}				if(display_text != '')				{					var container = '<li>' +'<a class = "remove_logs" content="' + display_text + '" rel = "' + t + '"> ' + display_text + ' </a></li>';					$("#search_logs").append(container);					showFilter();				}			}		}}function urlHasType(){	var prevUrl = document.location.hash;	var arr = prevUrl.split(multi_search_del);	var type_exist = false;	for(var p = 0 ; p < arr.length ; p++)	{		var par = arr[p];		var arrPar = par.split(hash_url_delimiter);		for(var r = 0 ; r < arrPar.length ; r++)		{			var type_temp = arrPar[r].split("=")[0];			if(type_temp == 'type')			{				return true;//				page_type = arrPar[r].split("=")[1];			}		}	}	return type_exist;}function clearHashUrl(){	$("#search_logs").html("");	document.location.hash = "";	currentAnchor = document.location.hash;	hasType = false;	callLoadingSearch();	hideFilter();	alert('anjar');	$.get("/search/hashsearch", "type=" + page_type, function(data) {		afterPaging(data);	});}function callLoadingSearch(){	$('html, body').animate({scrollTop:100}, 'fast');	$("#goormePagination").addClass('isHidden');	//$('#goormeMainSidebar').nextUntil('#goormeLoadingGridBoxContainer').remove();	//$('#goormeMainSidebar').children().remove();	$('#goormeLoadingGridBoxContainer').nextAll().remove();	$('#goormeLoadingGridBoxContainer').removeClass("isHidden");	if($("#dislikeTagCloud").length > 0)	{		$("#dislikeTagCloud").siblings().addClass("isBottom");		$("#dislikeTagCloud").remove();	}}function showFilter(){	$("#filteron").removeClass("isHidden");	$("#filteroff").addClass("isHidden");}function hideFilter(){	$("#filteroff").removeClass("isHidden");	$("#filteron").addClass("isHidden");}function checkTypeAvailable(str, check_type){	var check_keyword = false;	var arrAnchor =	str.split(hash_url_delimiter);	if(check_type == 'keyword')	{		for(var q = arrAnchor.length-1 ; q >= 0 ; q--)		{			if(arrAnchor[q] != "" && arrAnchor[q] != "+")			{				//console.log(arrAnchor[q]);				var arr_check = arrAnchor[q].split("=");				if(arr_check.length == 1)				{					check_keyword = arr_check[0];					break;				}				else if(arr_check.length > 1)				{					var type_temp = arr_check[0];					if(type_temp == 'keyword')					{						check_keyword = arr_check[1];						break;					}				}			}		}	}	else	{		for(var q = arrAnchor.length-1 ; q >= 0 ; q--)		{			if(arrAnchor[q] != "" && arrAnchor[q] != "+")			{				//console.log(arrAnchor[q]);				var arr_check = arrAnchor[q].split("=");				if(arr_check.length > 1)				{					var type_temp = arr_check[0];					if(type_temp == check_type)					{						check_keyword = true;						break;					}				}			}		}	}	return check_keyword;}function regenerate_sidebar(current_type, query){	$('#loading_sidebar').removeClass("isHidden");	$('#sidebar_container').addClass("isHidden");	if(current_type == "dish" || current_type == "menu" || current_type == "menus")	{		$.get("/menus/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else if(current_type == "venue" || current_type == "businesses"  || current_type == "business") {		$.get("/businesses/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else if(current_type == "recipe") {		$.get("/recipes/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else if(current_type == "article") {		$.get("/articles/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else if(current_type == "roll") {		$.get("/feeds/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else if(current_type == "promotion") {		$.get("/promotions/regenerate_sidebar", query, function(data) {			after_regenerate(data);		});	} else {		$.get("/search/regenerate_sidebar", query, function(data) {			var temp = jQuery.parseJSON(data);			var business = parseInt(temp.venue);			var dish = parseInt(temp.dish);			var promotion = parseInt(temp.promotion);			var recipe = parseInt(temp.recipe);			var roll = parseInt(temp.roll);			var article = parseInt(temp.article);			if(business == "")				business = 0;			else if(article == "")				article = 0;			else if(promotion == "")				promotion = 0;			else if(recipe == "")				recipe = 0;			else if(roll == "")				roll = 0;			else if(dish == "")				dish = 0;			$("#idxBusiness").html(business);			$("#idxArticle").html(article);			$("#idxRecipe").html(recipe);			$("#idxRoll").html(roll);			$("#idxPromotion").html(promotion);			$("#idxDish").html(dish);			var total = parseInt(business + dish + promotion + recipe + roll + article);			$("#idxCounter").html(total);			after_regenerate();		});	}}function after_regenerate(data){	$("#detilKeyword").text(key);	$("#filterContainer").html(data);	$('#loading_sidebar').addClass("isHidden");	$('#sidebar_container').removeClass("isHidden");}
