var KEYWORDS_BLANKSTR="keyword, restaurant, etc.";

var ID_DEFAULT='all';

var tab_closeDlg=null;

var isAllRestSearch=false;

var choice_cuisine={id:'',name:'',isBigCatalog:false};
var choice_location={id:'',name:'',isBigCatalog:false,locationType:"district"};
var choice_price={id:'',name:'',isBigCatalog:false};

function redirectMethod(flag){
	if(flag == "usercenter"){
		location.href = '/html/UserCenter/mainpage?userId='+login_user_id
	}else if(flag == "usercenterreview"){
		$.fn.colorbox.close();
		$("#seeAllReviews").trigger("click")
	}else if(flag == 'blog'){
		location.href = 'http://www.diningsecretary.com/blog'
	}else if(flag == 'topn'){
		location.href = '/shanghai/restaurant-all/search/all,all,all,all,all,all,all,1,25,1,1.shtml?type=deals'	
	}else if(flag == 'usercenterfavorite'){
		$.fn.colorbox.close();
		location.href = '/html/UserCenter/mainpage?userId='+login_user_id
		$("#seeAllFavorite").trigger("click")
	}else {
		location.href='/';
	}
}
//验证是否符合手机格式
function isMobile(value) {
	var length = value.length;
	return (length == 11 && /^([1][3,5,8]\d{9})|(^021\d{8}$)$/.test(value));
}
//验证是否符合邮箱格式
function isEmail(str) {
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return reg.test(str);
}

var confirmflag = false;

// 用户中心处已取消，现在只剩 layout页面右下角
function shareToFriend(id){
	var emailAddress = $("#"+id).val();
	if (emailAddress == "") {
		alertMsg("The email address you have entered is not valid.")
		return
	}
	if (!isEmail(emailAddress)) {
		alertMsg("Please enter a valid email address.")
		return
	}
	// 验证格式
	function callback(json) {
		if (!json.success) {
			alert("Fail[L001]:" + json.resultMsg);
			return;
		}
		var result = json.gsonMap.result
		if(result == 1){
			alertMsg("Thanks for signing up, but this email address is already in our system.");
		}
		if(result == 3){
			alertMsg("Thanks! You've successfully subscribed to our mailing list.")
		}
		$("#"+id).val("Email address")
	};
	// ------------- 放置到邮件队列
	$.getJSON("/ajax/UserCenter.shareToFriend", {"emailAddress":emailAddress},callback);
}
//-------------------------------------------------
$(document).ready(function(){
	$("#newsletter").focus(function (){
		if($("#newsletter").val() == "Email address"){
			$("#newsletter").val("")
		}
	});
	$("#newsletter").blur(function (){
		if($("#newsletter").val() == ""){
			$("#newsletter").val("Email address")
		}
	});
	
	chkIsLogin();
	initMaintab();
	mainTabSelect();
	
	initSearchInput();
	searchParams_getLast();//必须在initSearchInput之后执行。
	
	function initCtrls(){
		function postInit(tabIndex){
			if(tabIndex == 2){
				new Subway().initSubwayDrag("001",5);
			}
		}
		initOpCard(postInit);
		initSearchBtn();
	}
	loadDlgData(initCtrls);
	
	$("#subwayZoom").click(function(e){
		subwaySel($(this),e);
	});

	 
	$("#cancleConfirmBtn").click(function (){confirmflag=false;$.fn.colorbox.close();});
	$("#submitConfirmBtn").click(function (){confirmflag=true; $.fn.colorbox.close();});
	
	showKeywordSuggestion();
});

function showKeywordSuggestion(){
	if(typeof keywordSuggestion != "string"){
		return;
	}
	var index=keywordSuggestion.indexOf("=");
	if(index < 0){
		return;
	}
	var key=keywordSuggestion.substring(0,index);
	var val=keywordSuggestion.substring(index+1);
	$("#keywordSug").attr("name",key);
	$("#keywordSug").text(val);
	$("#keywordSugDiv").show();
}

function alertMsg(content,title){
	$("#noticeContent").html(content)
	if(title != undefined){
		$("#alertTitle").html(title)
	}
	$.fn.colorbox({
		opacity:"0.3",
		speed:0,
		width:"350px",
		height:"180px",
		inline:true,
		href:"#alertNotice"
	});
}
function confirmMsg(content,callback){
	confirmflag = false;
	$("#confirmContent").html(content);
	$.fn.colorbox({
		opacity:"0.3",
		speed:0,
		width:"350px",
		height:"180px",
		inline:true,
		href:"#confirmNotice",
		onClosed:callback
	});
}

function getInputName(type){
	var lastParams=$("#json_searchParams").html();
	if(lastParams == null){
		return;
	}
	lastParams=$.parseJSON(lastParams);
	return lastParams[type];
}
function searchParams_getLast(){
	var lastParams=$("#json_searchParams").html();
	if(lastParams == null){
		return;
	}
	
	lastParams=$.parseJSON(lastParams);
	//处理keywords
	var val=lastParams["input_keywords"];
	var obj=$("#input_keywords");
	obj.val(val);
	obj.focus();//触发背景图片的变化
	obj.blur();//触发背景图片的变化
	
	
	val=lastParams["input_price"];
	var obj=$(".searchPriceBtn");
	obj.val(val);
	
	//处理cuisine
	val=lastParams["input_cuisine"];
	choice_cuisine.name=val;
	$(".searchTypeBtn > b").text(trim25c(val));
	
	val=lastParams["cuisinebig_id"];
	if(notAll(val)){
		choice_cuisine.id=val;
		choice_cuisine.isBigCatalog=true;
	}
	val=lastParams["cuisinesmall_id"];
	if(notAll(val)){
		choice_cuisine.id=val;
		choice_cuisine.isBigCatalog=false;
	}
	
	//处理location
	val=lastParams["input_location"];
	choice_location.name=val
	$(".searchNearBtn > b").text(trim25c(val));
	
	val=lastParams["district_id"];
	if(notAll(val)){
		choice_location.id=val;
		choice_location.isBigCatalog=true;
		choice_location.locationType="district";
	}
	
	val=lastParams["subdistrict_id"];
	if(notAll(val)){
		choice_location.id=val;
		choice_location.isBigCatalog=false;
		choice_location.locationType="district";
	}
	
	val=lastParams["populararea_id"];
	if(notAll(val)){
		choice_location.id=val;
		choice_location.isBigCatalog=false;
		choice_location.locationType="populararea";
	}
	
	val=lastParams["subway_id"];
	if(notAll(val)){
		choice_location.id=val;
		choice_location.isBigCatalog=false;
		choice_location.locationType="subway";
	}
	
	
	//处理price
	val=lastParams["input_price"];
	choice_price.name=val
	$(".searchPriceBtn > b").text(trim25c(val));
	
	val=lastParams["percapita_id"];
	if(notAll(val)){
		choice_price.id=val;
		choice_price.isBigCatalog=false;
	}	
	
	//非空则弹出clear按钮。
	if(notAll(choice_cuisine.id)){
		$(".searchType .clearKeywords").show();
	}
	if(notAll(choice_location.id)){
		$(".searchNear .clearKeywords").show();
	}
	if(notAll(choice_price.id)){
		$(".searchPrice .clearKeywords").show();
	}
}
function notAll(val){
	return (val != "all")&&($.trim(val) != "");
}
function trim25c(str){
	if(str.length > 25){
		str=str.substring(0,25)+"...";
	}
	return str;
}

function loadDlgData(initMethod){
	var callback = function(json){
		if(!json.success){
			alert("Fail[L002]:"+json.resultMsg);
			return;
		}
		
		var cuisineType=json.gsonMap.cuisine_type;
		if(cuisineType != null){
			initCuisineDlg(cuisineType,json.gsonMap.cuisine_content);
		}
		
		var districtType=json.gsonMap.district_type;
		if(districtType != null){
			initDistrictDlg(districtType,json.gsonMap.district_content);
		}
		
		var popularareaType=json.gsonMap.populararea_type;
		if(popularareaType != null){
			initPopularareaDlg(popularareaType);
		}
		
		
		//
		initMapHotarea(json);

		
		var priceType=json.gsonMap.price_type;
		if(priceType != null){
			initPriceDlg(priceType);
		}
		
		//-----数据加载完成，开始初始化界面逻辑-------------------------
		initMethod();
	}	
	$.getJSON("/ajax/SearchParam.getDlgData",{},callback);
}

function initMapHotarea(json){
	var mapHotarea=json.gsonMap.maphotarea;
	if(mapHotarea == null){
		mapHotarea={};
	}
	var district=json.gsonMap.district_type;
	var subDistrict=json.gsonMap.district_content;
	
	$("#hotArea > a").each(function(index){
		var aName=$(this).text();
		aName=$.trim(aName);
		var finded=false;
		var districtType=$(this).attr("district");
		if(districtType == "1"){
			for(var i=0;i<district.length;i++){
				var item=district[i];
				if(aName == item.name){
					$(this).attr({"sname":item.name,"sid":item.id,href:'#'});
					finded=true;
					break;
				}
			}
		}else if(districtType == "2"){
			for(var id in subDistrict){
				var l2=subDistrict[id];
				for(var x=0;x<l2.length;x++){
					var item=l2[x];
					if(aName == item.name){
						$(this).attr({"sname":item.name,"sid":item.id,href:'#'});
						finded=true;
						break;
					}
				}
				if(finded){
					break;
				}
			}
		}else{			
			for(var i=0;i<mapHotarea.length;i++){
				var item=mapHotarea[i];
				if($.trim(item.name) == $.trim(aName)){
					$(this).attr({"sname":item.name,"sid":item.id,href:'#'});
					finded=true;
					break;
				}
			}			
		}
		if(!finded){
			$(this).css({'text-decoration':'line-through'});
		}
	});
	
//	$("#hotArea > a").click(function(){
//		alert("sid="+$(this).attr("sid")+",sname="+ $(this).attr("sname"));
//	});
}

function initPriceDlg(type){
	var pb=$("#priceBody");
	pb.html("");
	for(var i=0;i<type.length;i++){
		var item=type[i];
		var a=$("<a></a>").attr({"sname":item.name,"sid":item.id,href:'#'}).text(item.name);
		pb.append(a);
	}
}

function initPopularareaDlg(type){
	var tbl=$("#popularAreasTable");
	tbl.html("");
	for(var i=0;i<type.length;i+=3){
		var tr=$("<tr></tr>");
		for(var x=0;x<3;x++){
			index=i+x;
			var td=$("<td></td>");
			if(index < type.length){
				var item=type[index];
				var a=$("<a></a>").attr({"sname":item.name,"sid":item.id,href:'#'}).text(item.name);
				td.append(a);
			}			
			tr.append(td);
		}
		tbl.append(tr);
	}
}

function initCuisineDlg(type,content){
	for(var i=0;i<type.length;i++){
		var h3=$("#cuisineBody").children("h3").eq(i*1);
		var div=$("#cuisineBody").children("div").eq(i*2);
		h3.html("");
		div.html("");
		
		var bigCata=type[i];
		
		var a=$("<a></a>").attr({"sname":bigCata.name,"sid":bigCata.id,href:'#',"isBigCatalog":true}).text(bigCata.name);
		h3.html(a);
		
		var l2=content[bigCata.id];
		for(var x=0;x<l2.length;x++){
			var item=l2[x];
			
			//直接拼html会有[']和["]的转义问题，所以用jquery拼。
			var a=$("<a></a>").attr({"sname":item.name,"sid":item.id,href:'#'}).text(item.name);
			div.append(a);
		}
	}
}

function initDistrictDlg(type,content){
	var menu=$("#districtTabMenu");
	var dtb=$("#districtTabBody");
	menu.html("");
	dtb.html("");
	
	for(var i=0;i<type.length;i++){
		var bigCata=type[i];
		menu.append("<li>"+bigCata.name+"</li>");
		
		var ul=$("<ul></ul>");
		var l2=content[bigCata.id];
		for(var x=0;x<l2.length;x++){
			var item=l2[x];
			
			//直接拼html会有[']和["]的转义问题，所以用jquery拼。
			var a=$("<a></a>").attr({"sname":item.name,sid:item.id,href:'#'}).text(item.name);
			var li=$("<li></li>").append(a);
			ul.append(li);
		}
		
		dtb.append(ul);
	}
	//隐藏所有，除了第一个
	dtb.children("ul").each(function(i){
		if(i >= 1){
			$(this).hide();
		}
		var a=$(this).children("li").eq(0).children("a");
		//alert("len="+a.length+",txt="+ a.text());
		a.attr({"isBigCatalog":'true'});
		a.css({"font-weight":"bold"});
	});
}

function finishSelect(aNode){
	var sname=aNode.attr("sname");
	var sid=aNode.attr("sid");
	var isBig=(aNode.attr("isBigCatalog") == 'true');
	var item={id:sid,name:sname,isBigCatalog:isBig};
	
	var clz=aNode.parents(".enPop1").parent().attr('class');
	if(clz == "searchType"){
		choice_cuisine=item;
	}else if(clz == "searchNear"){
		choice_location=item;
		if(aNode.parents("[id='districtTabBody']").length == 1){
			//alert("district");
			item.locationType="district";
		}else if((aNode.parents("[id='popularAreasTable']").length == 1)){
			//alert("popularArea");
			item.locationType="populararea";
		}else if((aNode.parents("[id='hotArea']").length == 1)){
			var tmp=aNode.attr("district");
			if((tmp == "1")||(tmp == "2")){
				item.isBigCatalog=(tmp == "1");
				item.locationType="district";				
			}else{
				item.locationType="populararea";
			}
		}
	}else if(clz == "searchPrice"){
		choice_price=item;
		return;
	}
	
	aNode.parents(".enPop1").siblings("span").children("b").attr("title",sname);
}

function ifNull(val){
	if($.trim(val) == ""){
		return ID_DEFAULT;
	}else{
		return val;
	}
}
//location
function getDistrictId(big){
	if(choice_location.locationType != "district"){
		return ifNull(null);
	}
	if(choice_location.isBigCatalog == big){
		return ifNull(choice_location.id);
	}else{
		return ifNull(null);
	}
}
function getPopularId(){
	if(choice_location.locationType != "populararea"){
		return ifNull(null);
	}
	return ifNull(choice_location.id);
}
function getSubwayId(){
	if(choice_location.locationType != "subway"){
		return ifNull(null);
	}
	return ifNull(choice_location.id);
}
//cuisine
function getCuisineId(big){
	if(choice_cuisine.isBigCatalog == big){
		return ifNull(choice_cuisine.id);
	}else{
		return ifNull(null);
	}
}
//price
function getPriceId(){
	return ifNull(choice_price.id);
}

var isGotoRest=false;
//-------------------------------------------
function initSearchInput(){
	//keywords
    var kw=$("#input_keywords");
	//active(kw);
	kw.focus(function (){
		if($(this).val() == KEYWORDS_BLANKSTR){
			$(this).val("");
		}
	});
	kw.blur(function (){
		if($.trim($(this).val()) == ""){
			$(this).val(KEYWORDS_BLANKSTR);
		}
	});
	kw.keydown(function(e){
		if(e.which != 13){
			isGotoRest=false;
			return;
		}
		function clbk(){
			/*
			 * 如果是选中autocomplete弹出的下拉选项，不需要触发mainform,
			 * 因为autucomplete中已经出发了，重复触发会有问题。
			 */
			if(isGotoRest){
				return;
			}
			$("#type").val("");
			$("#mainform").submit();
		}
		/*
		 * Layout.html相关代码，执行顺序冲突
		 * $("#input_keywords").result(function(){
		 *     ....
		 *     $("#mainform").submit()
		 * }
		 * 需要让此处的clbk方法晚些时候执行（相比Layout.html中的代码）。
		 */
		setTimeout(clbk,100);
	});
	

	$("#mainform").submit(function(){		
		var tgt=$(this).attr("target")
		if(tgt == "hidden_frame"){
			alert("action is="+ $(this).attr("action"));
			return;
		}
		
		//var viewWithPhoto=$("#checkbox_photo").attr("checked");
		//var viewOnMap=$("#checkbox_map").attr("checked");
		var activeTab=$("#viewTab .current").parent().prevAll().length;
		var type = $("#type").val()
		
		var contextS="/shanghai/restaurant-s";
		var contextAll="/shanghai/restaurant-all";
		var ctx=isAllRestSearch?contextAll:contextS;
		
		var keystr=$("#input_keywords").val();
		if(keystr == KEYWORDS_BLANKSTR){
			keystr="";
		}
		keystr=replaceEnSpecialChar(keystr);
		
		//如果用户输入了关键词，不能排序，因为关键词可能是要寻找餐馆名称
        //如果排序，则命中的餐馆名称不在考前的位置。
		var sort=0;
//		if($.trim(keystr).length >= 1){
//			sort=0;
//		}
		
		var newAct=ctx+"/search/"+
				getDistrictId(true)+','+
				getDistrictId(false)+','+
				getPopularId()+','+
				getSubwayId()+','+
				getCuisineId(true)+','+
				getCuisineId(false)+','+
				getPriceId()+','+
				        "1,"+
				        "10,"+sort+",1.shtml?keyword="+keystr+"&activeTab="+activeTab+"&type="+type;
		newAct=encodeURI(newAct);//中文需要编码，否则ie8下会导致乱码。
		$(this).attr("action",newAct);
		//alert("newAction="+newAct);
		return true;
	});
	
	$("#searchBtn").click(function (){
		$("#type").val("");
		$("#mainform").submit();
	});
}

function aa(){
	if(typeof isRestListPage != "undefined"){
		$("#panel_map").css("top",0);
	}
}
function bb(){
	if(typeof isRestListPage != "undefined"){
		$("#panel_map").css("top",360);//解决搜索弹出对话框被地图(flash)遮盖的问题。
	}
}

function initSearchBtn(){
	// type pop
	function searchAllClear(){
		$(".searchTypeBox").css("display","none");
		$(".searchNearBox").css("display","none");
		$(".searchPriceBox").css("display","none");
		$(".searchTypeBtn").children("i").removeClass("current");
		$(".searchNearBtn").children("i").removeClass("current");
		$(".searchPriceBtn").children("i").removeClass("current");
		$(".searchTypeMask").css("display","none");
		$(".searchNearMask").css("display","none");
		$(".searchPriceMask").css("display","none");
	}
	
	tab_closeDlg=searchAllClear;

	$(".searchTypeBtn").click(function(){
	      if($(".searchTypeBox").css("display")=="block"){
	    	   aa();
		       $(".searchTypeBox").css("display","none");
			   $(".searchTypeBtn").children("i").removeClass("current");
			   $(".searchTypeMask,.searchNearMask,.searchPriceMask").css("display","none");
		  }
		  else{
			  bb();
		       searchAllClear();
		       $(".searchTypeBox").css("display","block");
			   $(".searchTypeBtn").children("i").addClass("current");
		       $(".searchTypeMask").css("display","block");
		  }
	})
	// near pop
	$(".searchNearBtn").click(function(){
	      if($(".searchNearBox").css("display")=="block"){
	    	   aa();
		       $(".searchNearBox").css("display","none");
			   $(".searchNearBtn").children("i").removeClass("current");
			   $(".searchTypeMask,.searchNearMask,.searchPriceMask").css("display","none");
		  }
		  else{
			  bb();
		       searchAllClear();
		       $(".searchNearBox").css("display","block");
			   $(".searchNearBtn").children("i").addClass("current");
			   $(".searchNearMask").css("display","block");
		  }
	})
	// Price pop
	$(".searchPriceBtn").click(function(){
		aa();
	      if($(".searchPriceBox").css("display")=="block"){
		       $(".searchPriceBox").css("display","none");
			   $(".searchPriceBtn").children("i").removeClass("current");
			   $(".searchTypeMask,.searchNearMask,.searchPriceMask").css("display","none");
		  }
		  else{
		       searchAllClear();
			   $(".searchPriceBox").css("display","block");
			   $(".searchPriceBtn").children("i").addClass("current");
			   $(".searchPriceMask").css("display","block");
		  }
	})
	//关闭按钮事件
	$(".enPop1Close").click(function(){
	   $(this).parents(".enPop1").css("display","none");
	   $(this).parents(".enPop1").siblings("span").children("i").removeClass("current");
	   $(".searchTypeMask,.searchNearMask,.searchPriceMask").css("display","none");
	})

	//关闭按钮事件
	$(".enPop1List1 a,.popularAreasTable a,.districtTabBody a,.popularAreasList a,#cuisineBody>h3>a").click(function(){
	    $(this).parents(".enPop1").css("display","none");
		$(this).parents(".enPop1").siblings("span").children("i").removeClass("current");
		var keyWords=$(this).text();
		if(keyWords.length>25){
		    objString = keyWords.substring(0,25) + "..."; 
		}
		else{
		   objString=keyWords;
		}
		$(this).parents(".enPop1").siblings("span").children("b").text(objString);
		$(this).parents(".enPop1").siblings("p.notes").children(".clearKeywords").show();
		$(".searchTypeMask,.searchNearMask,.searchPriceMask").css("display","none");
		
		//###########################################
		finishSelect($(this));
	})
	//清楚选择条件
	$(".searchType .clearKeywords").click(function(){
	   $(this).hide();
	   $(".searchTypeBtn").children("b").text("Cuisines");
	   choice_cuisine.id=null;
	})
	$(".searchNear .clearKeywords").click(function(){
	   $(this).hide();
	   $(".searchNearBtn").children("b").text("Locations");
	   choice_location.id=null;
	})
	$(".searchPrice .clearKeywords").click(function(){
	   $(this).hide();
	   $(".searchPriceBtn").children("b").text("any $");
	   choice_price.id=null;
	})
	//
	$(".searchInput1").focus(function(){
	   searchAllClear();
	})
}


function initOpCard(tabPostInit){
	/*FG.YTabs({
		tabs: FG.get('spotlightSmall').getElementsByTagName('li'),
		contents: FG.getByClassName('spotlightBigList', 'div', 'spotlightBig'),
		defaultIndex: 1,
		fadeUp: true,
		auto:true
	});*/
//	var top10Tab = new opCard();
//	top10Tab.bind = ["top10TabMenu","li","top10TabBody","div"];
//	top10Tab.style = ["","current","current"];
//	top10Tab.auto = false;
//	top10Tab.overStyle = false;
//	top10Tab.overChange = false;
//	top10Tab.creat();
//	top10Tab = null;
//	var enpopTab1 = new opCard();
//	enpopTab1.bind = ["enpopTab1Menu","li","enpopTab1Body","div"];
//	enpopTab1.nesting = [false,true,"",""]
//	enpopTab1.style = ["","current","current"];
//	enpopTab1.auto = false;
//	enpopTab1.overStyle = false;
//	enpopTab1.overChange = false;
//	enpopTab1.creat();
//	enpopTab1 = null;
	
	var myPopTabMenu=$("#enpopTab1Menu>li");
    myPopTabMenu.eq(0).addClass("current");
    myPopTabMenu.click(function(){
       $(this).addClass("current").siblings().removeClass("current");
	   var myTabIndex=myPopTabMenu.index(this);
	   $("#enpopTab1Body>div").eq(myTabIndex).show().siblings().hide();
	   if(typeof tabPostInit == 'function'){
		   tabPostInit(myTabIndex);
	   }
    })


	var districtTab = new opCard();
	districtTab.bind = ["districtTabMenu","li","districtTabBody","ul"];
	districtTab.nesting = [false,true,"",""]
	districtTab.style = ["","current","current"];
	districtTab.auto = false;
	districtTab.overStyle = false;
	districtTab.overChange = false;
	districtTab.creat();
	districtTab = null;
}
//##############################################################################



function subwaySel(obj,e){
	var pos = getObjectPosition(obj,e);
	pos.left=pos.left-200;
	$.fn.colorbox({
		title:"Subway station selecting",
		opacity:"0.3",
		speed:0,
		width:"865px",
		height:"670px",
		inline:true,
		href:"#subwaySelDlg_002"
	});
	$("#colorbox").css({"z-index":10000});
	new Subway().initSubwayDrag("002");
}

//------------------------------------------------
function searchParams_reset(){
	choice_cuisine.id=null;
	choice_location.id=null;
	choice_price.id=null;
}


//------------------------------------------------
function initMaintab(){
	$("#mainTab > li > a").click(function(){
		searchParams_reset();
	});
}
//-------------------------------------------------
function mainTabSelect(){
    var url=window.location.href;
    var reg=/^[^\/]+\/\/[^\/]+\/[^\/]+\/([^\/]+)\/.*/;
	var arr=url.match(reg);
	var currTab=-1;
	if(arr != null){
		var rest=RegExp.$1;
		if(rest.indexOf("restaurant-all") == 0){
			currTab=1;
		}
		var q=url;
		if((q != null) && ((q.indexOf("type=partner") >= 0) || (q.indexOf("type=deals") >= 0))){
			currTab=-1;
		}
		if((q != null) && (q.indexOf("type=nightlife") >= 0)){
			currTab=2;
		}
	}else if(url.indexOf("/IntegralChange/giftIndex") >= 0){
		currTab=3;
	}else{
		var homeReg=/^[^\/]+\/\/[^\/]+\/#?$/;
		if(url.match(homeReg)){
			currTab=0;
		}
	}
	if(currTab <= 0){
		searchParams_reset();
	}

	$("#mainTab > li").each(function(){
		$("a",$(this)).removeClass();
	});
	if(currTab >= 0){
		if(currTab != 3){
			$("#mainTab > li").eq(currTab).children("a").addClass("current");
		}else{
			$("#rewards").addClass("current");	
		}
	}
}

function toggleSelectCuisine(id,isBig){
	if(choice_cuisine.id == id){
		choice_cuisine.id=ID_DEFAULT;
	}else{
		choice_cuisine.id=id;
	}
	choice_cuisine.isBigCatalog=(isBig == true);
}
function toggleSelectLocation(id,locType,isBig){
	if(choice_location.id == id){
		choice_location.id=ID_DEFAULT;
	}else{
		choice_location.id=id;
	}
	choice_location.locationType=locType;
	choice_location.isBigCatalog=(isBig == true);
}
function toggleSelectPrice(id){
	if(choice_price.id == id){
		choice_price.id=ID_DEFAULT;
	}else{
		choice_price.id=id;
	}
}

function getObjectPosition(obj,e){
	dX=e.pageX-e.clientX;
	dY=e.pageY-e.clientY;
	
	obj=$.ensure(obj);
	var p=obj.offset();
    var left = p.left-dX;
    var top = p.top+obj.outerHeight()+2-dY;
    return {left:left,top:top};
}

function subwayStationSel(id,name,suffix){
	choice_location.id=id;
	choice_location.name=name;
	choice_location.locationType="subway";
	
	$(".searchNearBtn > b").text(trim25c(name));
	$(".searchNear .clearKeywords").show();
	
	if(suffix == "002"){
		$.fn.colorbox.close();
		tab_closeDlg();
	}else if(suffix == "001"){
		tab_closeDlg();
	}
}






