//配置初始化
var $ChoiceSign = {
	fdarea : "洪山区",
	fdsx : "",
	mainpanelid : "choicesigndiv"
};
// 唯一入口
function choicesign_click(){
	$ChoiceSign.init();
	$ChoiceSign.reset();
	showSignListLayer();
	searchDB();
	$("#querytxt").focus();
}
$ChoiceSign.init = function() {
	$ChoiceSign.mainpanel = $("#"+$ChoiceSign.mainpanelid);
	// 拼音鼠标事件
	$(".fd_choice_area_2 >li").hover(function(){
		$(this).addClass("letter_over");
	},function(){
		$(this).removeClass("letter_over");
	});
}
$ChoiceSign.reset=function(){
	$ChoiceSign.fdarea="";
	$ChoiceSign.fdsx="";
}
function showSignListLayer() {
	var mainpanel = document.getElementById($ChoiceSign.mainpanelid);
	mainpanel.style.display='block';
	centerLayer($ChoiceSign.mainpanelid);
	$(".pym_area_choiced > li",$ChoiceSign.mainpanel).addClass("pym_no_choiced");
}
/*
 * 关闭写字楼层
 */
$ChoiceSign.closediv_click = function(){
	$G($ChoiceSign.mainpanelid).style.display='none';
	$(".area_choiced > li",$ChoiceSign.mainpanel).addClass("no_choiced");
}
centerLayer = function(layerId) {
	var layer = document.getElementById(layerId);
	var lw = layer.offsetWidth;
	var lh = layer.offsetHeight;
	var cw = document.documentElement.clientWidth == 0 ? document.body.clientWidth : document.documentElement.clientWidth;
	var ch = document.documentElement.clientHeight == 0 ? document.body.clientHeight : document.documentElement.clientHeight;
	var scrollTop=document.documentElement.scrollTop ==0?document.body.scrollTop : document.documentElement.scrollTop;
	var ll = ((cw/2) - (lw/2))+"px";
	var lt = (scrollTop+(ch/2) - (lh/2)) +"px";
	with(layer.style) {
		position = "absolute";
		left = ll;
		top = lt;
	}
	window.onresize = function() {
		centerLayer(layerId);
	}
}
/**
 * 获得页面上的元素
 */
$G = function(id) {
	return document.getElementById(id);
}

$(document).ready(function(){
 
  $("#querytxt").focus(function() {
	  var txt = $(this).val();
	  if(txt == "搜索楼宇/路口/小区:名称") {
		  $(this).val("");
	  }
   });

  $("#querytxt").blur(function() {
	  var txt = $(this).val();
	   if(txt == "") {
		   $(this).val("搜索楼宇/路口/小区:名称");
	  }
   });
	$("#topPageNo").click(function () {
		perpage(1); 
	});
	$("#previousPageNo").click(function () {
		perpage($("#_previousPageNo").val());
	});
	$("#nextPageNo").click(function () { 
		perpage($("#_nextPageNo").val());
	});
	$("#bottomPageNo").click(function () {
		perpage($("#_bottomPageNo").val());
	});
}); 

function getByC(value) {
	$("#content_list").hide();
	$("#fdloading").show();
	var strhtml = '';
	var temp='';
	if(value != null){
		$.getJSON("json/searchArea.do?letter=" + value, function (data) {

			if (data.totalRecords == 0) {
				$("#sign_choice").hide();
				$("#fd_no_search_result").show();
				$("#fd_no_search").html("<center>请点击上面的字母选择您所在位置 或者您可以拨打我们客服电话进行咨询:4006-977-517</center><br><br><br><br>");
				$("#signPerPage").hide();
				
			} else {
				$("#sign_choice").show();
				$("#fd_no_search_result").hide();
				
				$.each(data.areaLis, function (i, value) {
					temp ="<DIV class='fd_sigin_list'><TABLE height=20 cellSpacing=0 cellPadding=0 width=184 border=0><TBODY><TR><TD align=left width='69%'>"
						+"<SPAN id=boxBuildingname><SPAN style='CURSOR: pointer' onclick=toshowarea('"+value.place+"','"+value.id+"');>"+value.place+"</SPAN></SPAN></TD><TD align=right width='31%'>"
						+"<SPAN id=boxCGSL style='COLOR: #747474'>"+value.storesum+"家餐厅</SPAN><SPAN id=wz style='COLOR: #747474'></SPAN></TD></TR></TBODY></TABLE></DIV>";
					strhtml+=temp;
				});
				 
				$("#content_list").html(strhtml);
				 
		 		$("#_previousPageNo")[0].value=data.previousPageNo;
				$("#_nextPageNo")[0].value=data.nextPageNo;
				$("#_bottomPageNo")[0].value=data.bottomPageNo;
				$("#_pageNo").text(data.pageNo);
				$("#_totalPages").text(data.totalPages);
				$("#signPerPage").show();
			// $("#content_list").show();
			}
		});
	}
	$("#fdloading").hide();
	$("#content_list").show();
	$("#szm_selected")[0].value=value;
	$("#curpages")[0].value=1; 
	letterclassreset();
	$("#area_"+value).removeClass("fd_no_choice_1").addClass("fd_choice_3"); 
	// alert( $("#szm_selected").val())
}
function toshowarea(area,id) {
	 var timstamp = (new Date()).valueOf();  
	var url ="webpages/ByAreaGetStoreList.do?area='"+encodeURI(area,'utf-8')+"'&areamessage_id="+id+"&time="+timstamp;
	window.location.href = url;
 }
function perpage(pageNo){
	$("#content_list").hide();
	$("#fdloading").show();
	var strhtml = '';
	var temp='';
	var letter = $("#szm_selected").val();
	var parmas="?letter=" + letter+"&pageNo="+pageNo;
	if(letter==0){
		var place = $("#querytxt").val();
		  if(place == "搜索楼宇/路口/小区:名称") {
			  place = '';
		  }
		parmas+="&place=" + place;
	}
// alert(parmas);
    $.getJSON("json/searchArea.do" + parmas, function (data) {
			
			if (data.totalRecords == 0) {
				$("#sign_choice").hide();
				$("#fd_no_search_result").show();
				$("#fd_no_search").html("<center>请点击上面的字母选择您所在位置 或者您可以拨打我们客服电话进行咨询:4006-977-517</center><br><br><br><br>");
				$("#signPerPage").hide();
			} else {
				$("#sign_choice").show();
				$("#fd_no_search_result").hide();
				// alert(data.areaLis)
				$.each(data.areaLis, function (i, value) {
					temp ="<DIV class='fd_sigin_list'><TABLE height=20 cellSpacing=0 cellPadding=0 width=184 border=0><TBODY><TR><TD align=left width='69%'>"
						+"<SPAN id=boxBuildingname><SPAN style='CURSOR: pointer' onclick=toshowarea('"+value.place+"','"+value.id+"');>"+value.place+"</SPAN></SPAN></TD><TD align=right width='31%'>"
						+"<SPAN id=boxCGSL style='COLOR: #747474'>"+value.storesum+"家餐厅</SPAN><SPAN id=wz style='COLOR: #747474'></SPAN></TD></TR></TBODY></TABLE></DIV>";
					strhtml+=temp;
				});
				 
				$("#content_list").html(strhtml);
			 
		 		$("#_previousPageNo")[0].value=data.previousPageNo;
				$("#_nextPageNo")[0].value=data.nextPageNo;
				$("#_bottomPageNo")[0].value=data.bottomPageNo;
				$("#_pageNo").text(data.pageNo);
				$("#_totalPages").text(data.totalPages);
				$("#signPerPage").show();
			// $("#content_list").show();
			}
		});
	 
	$("#fdloading").hide();
	$("#content_list").show();
	$("#szm_selected")[0].value=letter;
	$("#curpages")[0].value=pageNo;
// alert( $("#szm_selected").val()+'---'+$("#curpages").val())
}
function searchDB(){
	$("#content_list").hide();
	$("#fdloading").show();
	var strhtml = '';
	var temp='';
	var place = $("#querytxt").val();
	  if(place == "搜索楼宇/路口/小区:名称") {
		  place = '';
	  }
	var parmas="?place=" + place;
	// alert(parmas);
    $.getJSON("json/searchArea.do" + parmas, function (data) {

			if (data.totalRecords == 0) {
				$("#sign_choice").hide();
				$("#fd_no_search_result").show();
				$("#fd_no_search").html("<center>请点击上面的字母选择您所在位置 或者您可以拨打我们客服电话进行咨询:4006-977-517</center><br><br><br><br>");
				$("#signPerPage").hide();
			} else {
				$("#sign_choice").show();
				$("#fd_no_search_result").hide();
				$.each(data.areaLis, function (i, value) {
					temp ="<DIV class='fd_sigin_list'><TABLE height=20 cellSpacing=0 cellPadding=0 width=184 border=0><TBODY><TR><TD align=left width='69%'>"
						+"<SPAN id=boxBuildingname><SPAN style='CURSOR: pointer' onclick=toshowarea('"+value.place+"','"+value.id+"');>"+value.place+"</SPAN></SPAN></TD><TD align=right width='31%'>"
						+"<SPAN id=boxCGSL style='COLOR: #747474'>"+value.storesum+"家餐厅</SPAN><SPAN id=wz style='COLOR: #747474'></SPAN></TD></TR></TBODY></TABLE></DIV>";
					strhtml+=temp;
				});
				 
				$("#content_list").html(strhtml);
				
		 		$("#_previousPageNo")[0].value=data.previousPageNo;
				$("#_nextPageNo")[0].value=data.nextPageNo;
				$("#_bottomPageNo")[0].value=data.bottomPageNo;
				$("#_pageNo").text(data.pageNo);
				$("#_totalPages").text(data.totalPages);
				$("#signPerPage").show();	
			// $("#content_list").show();
			}
		});
	 
	$("#fdloading").hide();
	$("#content_list").show();
	$("#szm_selected")[0].value='0';
	// $("#querytxt")[0].value=place;
	$("#curpages")[0].value=1;
	letterclassreset();
// alert( $("#szm_selected").val()+'---'+$("#curpages").val())
}
function letterclassreset(){
	$("#_szm_choice > li").removeClass("fd_choice_3").addClass("fd_no_choice_1"); 	 
}
