﻿// JScript 文件

//全局城市 编号
var m_city;
//全局行政区 商圈 编号
var m_regionlandmark;

function txtFCityFocus()
{
    var txtvalue =document.getElementById("Citys_txtFCity").value;

    if(txtvalue=="中文/拼音")// && IsLoadFocus =="False")
    {//alert(txtvalue)
         document.getElementById('Citys_txtFCity').value ="";
    }
    else
    {
       //document.getElementById('Citys_txtFCity').value = "中文/拼音"; 
    }
}      

var strDiv = "";

//是否正确城市信息
var flgData = "False";


//****
//功能:根据城市名称获得城市代码
//****
    function GetCityCode(sCityName)
    { 
        //alert("sCityName=" + sCityName)
        document.getElementById("keywordcity").innerHTML = "";
        strDiv = "";
        document.getElementById("Citys_txtFCity").value = sCityName;
        document.getElementById('txtCY').value = sCityName; 
        
        //------------------login pic---------------------
        
        strDiv = " <table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding:0px;margin:0px;\"><tr><td valign=\"top\"><h1>城市商圈</h1><ul>";
        strDiv +=  "<li><img src=\"../images/index/indicator.gif\" /></li>";
        strDiv += "</ul></td></tr>";
        strDiv += " <tr><td valign=\"top\" align=\"left\"><h2>行政区域</h2><ul style=\"list-style:none;margin:0px;width:160px;padding-left:10px;\">";
        strDiv +=  "<li><img src=\"../images/index/indicator.gif\" /></li>";
        strDiv += "</ul></td></tr></table>";
       

        //------------------login pic---------------------
        
        if(sCityName!="" && sCityName!="中文/拼音")
        {        
            //document.getElementById("keywordcity").innerHTML = strDiv;
             
            //获取行政区
            //var Data2 = Ascx_Citys.GetRegion(sCityName);
            //SetBRegion(Data2);
            GegRegion(sCityName);
            //获取商圈
            //var Data1 =Ascx_Citys.GetLandMark(sCityName); 
            //SetBLandMark(Data1);
            GetLandMark(sCityName);
            //setTimeout(index.GetRegion(sCityName,SetBRegion),200);
            $('#keywordcity').get(0).style.visibility='';
        } 
        else
        {
             $('#city_error').get(0).style.display="block";        
             $('#city_error_text').get(0).innerHTML = "请选城市!"
        }
    }
    
    function GegRegion(sCityName)
    {
        //判断HashTable中是否存在数据
        if(ht.Contains("Region_" + sCityName))
        {
            var dataRegion = ht.GetValue("Region_" + sCityName);
            SetBRegion(dataRegion);
            return;
        }
        
        var sKey=sCityName;   
         $.ajax({
            type: "POST",
            url: "../WebService/RegionandLandMark.asmx/GetRegion",
            data: "{\"sCityName\":\"" + sKey + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {   
                if(msg != "")
                {          
                    var dataRegion = eval("(" + msg + ")");
                    ht.Add("Region_" + sCityName,dataRegion);
                    SetBRegion(dataRegion);
                }
                else
                {
                    ht.Add("Region_" + sCityName,msg);
                    SetBRegion(msg);
                }
            },
            error: function(msg) {
            }
        });
    }
    
    function GetLandMark(sCityName)
    {
        //判断HashTable中是否存在数据
        if(ht.Contains("LandMark_" + sCityName))
        {
            var dataLandMark = ht.GetValue("LandMark_" + sCityName);
            SetBLandMark(dataLandMark);
            return;
        }
        
        var sKey=sCityName;   
         $.ajax({
            type: "POST",
            url: "../WebService/RegionandLandMark.asmx/GetLandMark",
            data: "{\"sCityName\":\"" + sKey + "\"}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(msg) {   
                if(msg != "")
                {          
                    var dataLandMark = eval("(" + msg + ")");
                    ht.Add("LandMark_" + sCityName,dataLandMark);
                    SetBLandMark(dataLandMark);
                }
                else
                {
                    ht.Add("LandMark_" + sCityName,msg);
                    SetBLandMark(msg);
                }
            },
            error: function(msg) {
            }
        });
    }


    function SetBLandMark(response) 
    { 
        var result = response;

        if(response=="")
        {
            result = "该城市未添加商圈信息";
            return;
        }
    
        //var result = response.value;
        strDiv += " <table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" style=\"padding:0px;margin:0px;\"><tr><td valign=\"top\"><h1>城市商圈</h1><ul>";
        
        var sAllLi ="";
        
        if(result =="该城市未添加商圈信息!")
        {
            strDiv +=  "<li>" + result + "</li>";
               
            strDiv += "</ul></td></tr>";
        }
        else if(result != "")   
        {   
            //全部
            sAllLi ="<li><a style=\"cursor:pointer\" onclick=\"GetValue('','') \">全部</a></li>";
            strDiv +=sAllLi;
            var strArray = result;   
            for(var i=0;i<strArray.length;i++)   
            {   
               //var arrayCity = strArray[i].toString().split("|");
               strDiv +=  "<li><a style=\"cursor:pointer\" onclick=\"GetValue('" + strArray[i].LandMarkDesp+ "','" +strArray[i].LandMarkCd + "');\">" + strArray[i].LandMarkDesp + "(" + strArray[i].LandMarkCount + ")" + "</a></li>";
               
            }   
            strDiv += "</ul></td></tr>";
        }
        //document.getElementById("keywordcity").innerHTML = strDiv;
        document.getElementById("keywordcity").innerHTML = strDiv;
    }
    
    
    function SetBRegion(response) 
    {
        var result = response;

        if(response=="")
        {
            result = "该城市未添加行政区信息";
            return;
        }
        
        //var result = response.value;
        strDiv = "<tr><td valign=\"top\" align=\"left\" style=\"border-top:1px dashed #7f9db9;\"><h2>行政区域</h2><ul style=\"list-style:none;margin:0px;width:480px;padding-left:10px;\">";
        
        var sAllLi ="";
        
        if(result == "该城市未添加行政区信息!")
        {
           
            //var arrayCity = strArray[i].toString().split("|");
            strDiv +=  "<li style=\"padding:0px 0px 3px 0px;line-height:15px;width:90px;\">" + result + "</li>";
                
            strDiv += "</ul></td></tr></table>";
            
            //document.getElementById("keywordcity").innerHTML = strDiv;
        }
        else if(result != "")   
        {   
            //全部
            sAllLi ="<li style=\"padding:0px 0px 3px 0px;line-height:15px;width:90px;\"><a style=\"cursor:pointer\" onclick=\"GetRegion('','') \">全部</a></li>";
            strDiv +=sAllLi;
            var strArray = result;    
            for(var i=0;i<strArray.length;i++)   
            {   
               //var arrayCity = strArray[i].toString().split("|");
               strDiv +=  "<li style=\"padding:0px 0px 3px 0px;line-height:15px;width:90px;\"><a style=\"cursor:pointer\" onclick=\"GetRegion('" + strArray[i].Reg_desc + "','" +strArray[i].Reg_cd + "');\">" + strArray[i].Reg_desc + "(" + strArray[i].Reg_Count + ")" +  "</a></li>";
               
            }   
            strDiv += "</ul></td></tr></table>";
            
        }
    }   
                                               
    function GetValue(sLandMarkNm,sLandMarkCd)
    {
        if(sLandMarkCd == "") 
        {
            document.getElementById("keyword").value="全部";
            $('#keywordcity').get(0).innerHTML = "";
            document.getElementById("keywordcity").style.visibility = "hidden";
            return;
        }
        
        document.getElementById("keyword").value = sLandMarkNm;
        $('#keywordcity').get(0).innerHTML = "";
        document.getElementById("keywordcity").style.visibility = "hidden";
        m_regionlandmark =sLandMarkCd;
        document.getElementById("txtTp").value = "LM";
    }
    
    function GetRegion(sRegion,sRegionCd)
    {
        if(sRegionCd == "")
        {
            document.getElementById("keyword").value = "全部";
            $('#keywordcity').get(0).innerHTML = "";
            document.getElementById("keywordcity").style.visibility = "hidden";
            return;
        }
        
        document.getElementById("keyword").value = sRegion;
        $('#keywordcity').get(0).innerHTML = "";
        document.getElementById("keywordcity").style.visibility = "hidden";
        m_regionlandmark =sRegionCd;
        document.getElementById("txtTp").value = "RG";
    }
    
    //光标左右移动
    function changeFocus(name ,n) 
    {     
        var txt =document.getElementById(name); 
         
        if(isNaN(n))     
            return;     
             
        var rng = txt.createTextRange(); 
        	     
        rng.moveStart("character",n);     
             
        rng.collapse(true);	     
             
        rng.select();     
            
        //document.getElementById("Citys_txtFCity").focus();    
   
     } 
     
    function CityKeydown(event)
    {
        /*if(window.event.keyCode == 9) //Tab
        {
            //alert("def")
            //hideDiv();
            document.getElementById("keyword").focus();
            //alert("abc")
        }*/
        /*
        return   (event.keyCode!=13);
        //回车
        if(event.keyCode==13)
        {   
            alert("aaa")
            return false;
        }
        else if(event.keyCode==37)
        {
            if(document.getElementById('popup').style.display =='' || document.getElementById('popup').style.display =='block')
            {
                return true;
            }
        }
        else if(event.keyCode==38)
        {
            if(document.getElementById('popup').style.display =='' || document.getElementById('popup').style.display =='block')
            {
                return true;
            }
        }
        
        return  false;*/
    }
     
    function CityKeyup(event)
    {     
        //修改过 正确的城市信息
        flgData = "False";
		var obj;// =event.target;			
        if(!isIE())
        {
            obj =event.target;	
        }
        else
        {
            obj =event.srcElement; 	
        }		
         //var e = event.srcElement; 
        //alert(window.event.keyCode)
        switch(event.keyCode){  
            case 37 ://左
                 //changeFocus("txtFCity",1);
                 //document.getElementById("Citys_txtFCity").focus(); 
                break;
            case 39 ://右
                //changeFocus("txtFCity",-1);
                //document.getElementById("Citys_txtFCity").focus(); 
                break;    
            case 38 :  
                break;
            case 40 :
                break;
            case 32 :
                break;
            case 13 :
                break;        
            default:
                $('#keywordcity').get(0).innerHTML = "";
                $('#keywordcity').get(0).style.visibility='hidden';
                XmlPost_ZDWC(obj.value);
                /*var page = 0;
                if(nowPage !=0)
                {
                   page = nowPage*8;
                }
                
                var obj =document.getElementById("cityRow" + page);
                if (obj !="undefined" && obj != null)
                {
                    obj.className="mouseOver";    
                }*/
                break;
                }
       
        switch(event.keyCode){  
            case 37 ://左
                var page = nowPage-1;
                if(page<0)
                {
                    break;
                }
                upPage(page);
                FoucstxtCityhead();
                break;
            case 39 ://右
                var page = nowPage+1;
                if(page>=PagesLen)
                {
                    break;
                }
                //alert("nowPage1=" + nowPage)
                //alert("page=" + page)
                upPage(page);
                FoucstxtCityhead();
                //alert("nowPage2=" + nowPage)
                break;   
            case 38 :  
                //上
                //document.getElementById("cityRow1").className="mouseOver";
                 SearchDataCity(-1);
                break;
            case 40 :
                //下
                //alert(document.getElementById("cityRow0").className)
                SearchDataCity(1);
                //document.getElementById("cityRow7").className="mouseOver";
                //alert("2")
                //mouseOut
                break;
            case 13 :
                
                if(document.getElementById('popup').style.display =='' || document.getElementById('popup').style.display =='block')
                {  
                    //alert("Enter") 
                    EnterDataCity()
                }
                break;
                 }
                 
                 //document.getElementById("Citys_txtFCity").focus(); 
                var r;// = document.getElementById("Citys_txtFCity").createTextRange(); 
                
                if(document.createRange){
                    r = document.createRange();
                }else{
                    r = document.body.createTextRange();
                }
                r.collapse(false); 
                //r.select(); 

    }
    
    function EnterDataCity()
    {
        var beg =0;
        var end =8;
        //本页的行号
        if(nowPage !=0)
        {
            //alert("nowPage=" + nowPage)
            beg =nowPage*8;
            end = beg +8;
        }
        for(var i=beg;i<end;i++)
        {
           var rowNum;
           var obj =document.getElementById("cityRow"+ i);
           
           if(obj=="undefined" || obj == null)
           {
              continue;
           }
           if(obj.className == "mouseOver")
           {
                //alert("obj.firstChild.nodeValue=" + obj.firstChild.nodeValue)
                oInputField.value =obj.firstChild.lastChild.innerText;
                hideDiv();
			    //根据选择的城市将相关的城市代码放入hidFCity中
			    var cityId=$('#' + obj.id+" .liCity2").get(0).id.replace('city','');
			    m_city =cityId;
    			
			    //GetCityCode(oInputField.value);
			    //赋 正确的城市信息
				flgData = "True"
           }
        }
        
    }
    
    function SearchDataCity(step)
    {
        var beg =0;
        var end =8;
        //本页的行号
        if(nowPage !=0)
        {
            //alert("nowPage=" + nowPage)
            beg =nowPage*8;
            end = beg +8;
        }
    
        //alert("SearchDataCity")
         for(var i=beg;i<end;i++)
         {
               var rowNum;
               var obj =document.getElementById("cityRow"+ i);
               
               if(obj=="undefined" || obj == null)
               {
                  continue;
               }
               //alert("obj.className=" + obj.className)
               if(obj.className == "mouseOut" || obj.className == "")
               {
                  continue;
               }
               if(obj.className == "mouseOver")
               {
                    rowNum = i + step;
                    
                    var modNum =(rowNum ) % 8; 
                    //alert("i=" + i )
                    //alert("modNum=" + modNum )
                    //fadsf==1;
                    if(step <0 &&  ( rowNum==-1 ||  rowNum == -2))
                    {
                        rowNum = i + 7;
                    }
                    else if(step >0 &&  modNum == 0)
                    {
                        rowNum =  nowPage*8;
                    }
                    //alert("rowNum=" + rowNum +",beg=" + beg)
                    if(rowNum <beg)
                    {
                        chkcityRow(beg,end);
                        return;
                    }
                    
                    var objclass =document.getElementById("cityRow"+ rowNum);
               
                    if(objclass!="undefined" && objclass != null)
                    {
                        document.getElementById("cityRow" + rowNum).className="mouseOver";
                        mouseover_fun(document.getElementById("cityRow" + rowNum));
                        document.getElementById("cityRow" +i).className="mouseOut";
                        mouseout_fun(document.getElementById("cityRow" +i));
                    }
                    else if(step >0)
                    {
                        document.getElementById("cityRow" +i).className="mouseOut";
                        mouseout_fun(document.getElementById("cityRow" +i));
                        document.getElementById("cityRow" + (nowPage*8)).className="mouseOver";   
                        mouseover_fun(document.getElementById("cityRow" + (nowPage*8)));
                    }
                    else if(step <0)
                    {
                        //alert(step)
                        chkcityRow(beg,end);
                        return;
                    }
                    
                    return;
               }
         }
         
        FoucstxtCityhead();
         
         return;
    }
    
    function chkcityRow(beg,end)
    {
        for(var i=end-1;i>=beg;i--)
        {
            var obj=document.getElementById("cityRow"+ i);
            if(obj!="undefined" && obj != null)
            {
                 document.getElementById("cityRow" + (nowPage*8)).className="mouseOut"; 
                 mouseout_fun(document.getElementById("cityRow" + (nowPage*8)));
                 document.getElementById("cityRow" +i).className="mouseOver";
                 mouseover_fun(document.getElementById("cityRow" +i));
                 return;
            }
        }
    }
    
    function FoucstxtCityhead()
    {
        var beg =0;
        var end =8;
        //本页的行号
        if(nowPage !=0)
        {
            //alert("nowPage=" + nowPage)
            beg =nowPage*8;
            end = beg +8;
        }
        for(var i=beg;i<end;i++)
        {
//           if(nowPage !=0)
//           {
//               //alert("nowPage=" + nowPage)
//               i = nowPage*8;
//           }
        
           var obj =document.getElementById("cityRow"+ i);
           if(obj!="undefined" && obj != null)
           {
                obj.className = "mouseOut"; 
                mouseout_fun(obj);
                
           }
           
        }
        var foucsNum=0;
        if(nowPage !=0)
        {
           foucsNum = nowPage*8;
        }
        var obj =document.getElementById("cityRow" + foucsNum);
        if (obj !="undefined" && obj != null)
        {
            if(obj.firstChild.lastChild.innerText !="没有找到匹配的城市!")
            {
                obj.className="mouseOver";
                mouseover_fun(obj);
            }
           
        }
    }
    
    //定义HashTable
    var ht = new HashTable();
    
//以JSON获取自动完成搜索   
//获取城市
  function XmlPost_ZDWC(obj)   
  {     
    /*var svalue = obj;
    var webFileUrl = "../Index/ajaxselect_ZDWC.aspx?k=" + escape(svalue);   
    var result = "";   
    //xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
    if   (window.XMLHttpRequest)   {   //   Mozilla,   Safari,   ...   
            xmlHttp   =   new   XMLHttpRequest();   
    }     
    else   if   (window.ActiveXObject)   {   //   IE   
            xmlHttp   =   new   ActiveXObject("Microsoft.XMLHTTP");   
    }　
    xmlHttp.open("POST", webFileUrl, false); 
    xmlHttp.setRequestHeader("Content-Type","text/xml");
    xmlHttp.setRequestHeader("charset","utf-8");
    xmlHttp.send(null);  

    result = unescape(xmlHttp.responseText);   

    if(result != "")   
    {   
       aColors = result.split(",");
 
       findColors();
    } */  
    
    
    //判断HashTable中是否存在数据
    if(ht.Contains(obj))
    {
        aColors = ht.GetValue(obj);
        findColors();
        return;
    }
    
    var sKey=obj;   
     $.ajax({
        type: "POST",
        url: "../WebService/City.asmx/GetCitys",
        data: "{\"sKey\":\"" + sKey + "\"}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {   
            if(msg != "")
            {          
                var dataCity = eval("(" + msg + ")");
                aColors =dataCity;
                ht.Add(obj,dataCity);
                findColors();
                
            }
//            else
//            {
//                ShowNoRecorder("#GuestCoupon");
//            }
        },
        error: function(msg) {
        }
    });

  }

//----------------保存弹出框城市数组-----------------------------
var saveResult = new Array();
//---------------------------------------------------------------

function findColors()
{
       oInputField=document.getElementById("Citys_txtFCity");
       oPopDiv=document.getElementById("popup");
       oColorsUl=document.getElementById("colors_ul");
       
//	if(oInputField.value.length>0)
//	{
	    document.getElementById("txtCY").value = "";
	    document.getElementById('keyword').value = "点击选择商圈或行政区";
	    document.getElementById('txtTp').value = "";
	    
		showDiv();//显示弹出层
		var aResult=new Array();//用于存放匹配结果
		
		aResult = aColors;
		
		//---保存
		saveResult =aResult;
		//-------
		
		if(aResult.length>0)
		{
		//如果有匹配的地址则显示出来
			setColors(aResult);
			//alert(aResult);
			paging();
		}
			
//	}
//	else
//	{
//		clearColors();//无输入时清除提示框（例如用户按del键）
//		hideDiv();
//	}
}


function clearColors()
{
       //清除提示内容
       for(var i=oColorsUl.childNodes.length-1;i>=0;i--)
       oColorsUl.removeChild(oColorsUl.childNodes[i]);
       oPopDiv.className="hide";
}

function setColors(the_colors)
{
       //显示提示框,传入的参数即为匹配出来的结果组成的数组
       clearColors();//每输入一个字母就先清除原来的提示,再继续
       oPopDiv.className="show";
       var oLi;
       //alert(the_colors.length);
       
       
       var tdcity= document.getElementById("citysearch");
       tdcity.style.borderBottom="1px #0055aa dashed";
       //fasdfa==1;
       tdcity.innerText=document.getElementById("Citys_txtFCity").value +",按拼音查询 或↑↓→←选择";
       
       
       /*oLihead=document.createElement("<li style=\"padding-left:5px;padding-right:5px;color:#0055aa; border-bottom:#7f9db9 1px dotted;\">");
       var tmp = document.getElementById("Citys_txtFCity").value +",按拼音查询";
       oLihead.appendChild(document.createTextNode(tmp));
		   oColorsUl.appendChild(oLihead);*/
       for(var i=0;i<the_colors.length;i++)
       {
           //将匹配的提示结果逐一显示给用户
           //<li><ul><li style="float:left;">shanghai</li><li style="float:right;">上海</li></ul></li>
           //var j = the_colors[i].indexOf("/");   
		   var py = the_colors[i].CityHYPY;//the_colors[i].substring(0,j); 
		   //var name = the_colors[i].substring(j+1);
		   
		  // var arrtmp =the_colors[i].substring(j+1).split("_");
		   var name = the_colors[i].Descript;//arrtmp[0];
		   var code = the_colors[i].CD;//arrtmp[1];
		   
           if(name =="没有找到匹配的城市!")
           {    
                oLi=document.createElement("li");
		       oColorsUl.appendChild(oLi);
		       oLi.setAttribute("id","cityRow" + i);
		       //oLi.setAttribute("name","city" + i);
		       oLi.setAttribute("name","city" + code);
    		   
		        var oUl = CreateUl();//document.createElement("<ul style=padding:0px;margin:0px;float:left;>");
	            oLi.appendChild(oUl);
	            
    	        
	            var oLLi = CreateLi();//document.createElement("<li style=padding-left:5px;float:left;>");
	            oLLi.className="liCity1";
	            oUl.appendChild(oLLi);
    	         
	            var oRLi = CreateLi();//document.createElement("<li style=padding-right:10px;float:right;>");
	            oRLi.className="liCity2";
	            oUl.appendChild(oRLi);
	            oRLi.setAttribute("id","city" + i);
    	        
	            oLLi.appendChild(document.createTextNode(py));
	            oRLi.appendChild(document.createTextNode(name));
                continue;
           }
           oLi=document.createElement("li");
		   oColorsUl.appendChild(oLi);
		   oLi.setAttribute("id","cityRow" + i);
		   //oLi.setAttribute("name","city" + i);
		   oLi.setAttribute("name","city" + code);
		   
		    var oUl = CreateUl();//document.createElement("<ul style=padding:0px;margin:0px;float:left;WIDTH:200px;>");
		    oUl.className="ulCity";
	        oLi.appendChild(oUl);
	        
	        var oLLi = CreateLi();//document.createElement("<li style=padding-left:5px;float:left;>");
	        oLLi.className="liCity1";
	        oUl.appendChild(oLLi);
	         
	        var oRLi =CreateLi();// document.createElement("<li style=padding-right:10px;float:right;>");
	        oRLi.className="liCity2";
	        oUl.appendChild(oRLi);
	        //oRLi.setAttribute("id","city" + i);
	        oRLi.setAttribute("id","city" + code);
	        
	        
	        oLLi.appendChild(document.createTextNode(py));
	        oRLi.appendChild(document.createTextNode(name));
           
           oLi.style.cursor="pointer";
   		   oLi.onmouseover=function(){
   		        clearCitySearch(the_colors.length);
	            this.className="mouseOver";//鼠标指针经过时      
	                          
	            this.style.backgroundColor="#e7f1fd";
	            this.style.borderBottom="1px solid #7f9db9";
                this.style.borderTop="1px solid #7f9db9";
                this.style.color="#0055aa";
	            }
		   oLi.onmouseout=function(){
		   		this.className="mouseOut";//鼠标指针离开时
		   		this.style.backgroundColor="#FFFFFF";
		   		this.style.borderBottom="1px solid #ffffff";
                this.style.borderTop="1px solid #ffffff";
                this.style.color="#898989";
				}
		   oLi.onclick=function(){
		        //用户单机选择某个选项后触发的事件
		   		//用户单击某个匹配项时，设置输入框为该项的值
				//oInputField.value=this.firstChild.nodeValue;
				//oInputField.value=dealString(this.childNodes[1].nodeValue);
				oInputField.value= $('#'+this.id + ' .liCity2').get(0).innerText;//document.getElementById(this.id).firstChild.nodeValue;
				//同时清除提示框
				//clearColors();
				hideDiv();
				//根据选择的城市将相关的城市代码放入hidFCity中
				var cityId=$('#'+this.id + ' .liCity2').get(0).id.replace('city','');
			    m_city =cityId;
				
				//GetCityCode(oInputField.value);
				//选择某个城市后页面其他控件的联动
				//unSelected();
				
				//赋 正确的城市信息
				flgData = "True"
				
		   		}
		}
}

function clearCitySearch(num)
{
    //alert("clearCitySearch")
    var page = 0;
    if(nowPage !=0)
    {
       page = nowPage*8;
    }
    
    var obj =document.getElementById("cityRow" + page);
    if (obj !="undefined" && obj != null)
    {
        document.getElementById("cityRow" +page).className="mouseOut";
    }
    
    
    for(var i=0;i<num;i++)
    {
        document.getElementById("cityRow" +i).className="mouseOut";
        mouseout_fun(document.getElementById("cityRow" +i));
    }
}
   

var page=0;
var nowPage=0;//当前页
var listNum=24;//每页显示<ul>数3的倍数
var PagesLen;//总页数
var PageNum=3;//分页链接接数(PageNum+1个)

function paging()
{//调用数组内容
    obj=document.getElementById("colors_ul").getElementsByTagName("li");
    j=obj.length;       
    
    PagesLen=Math.ceil(j/listNum);//alert("pagelen"+PagesLen);alert("j:"+j);  
    upPage(0);
}
function upPage(p)
{
    nowPage=p;//drtgyh==1;
    //内容变换
    for (var i=0;i<j;i++)
    {
        obj[i].style.display="none";   
    }
    
    for (var i=p*listNum;i<(p+1)*listNum;i++)
    {
        if(obj[i])
           obj[i].style.display="block";
    }
    
    //分页链接变换
    strS='<a href="###" style="font-size:12px;color:#898989;text-decoration:none;" onclick="upPage(0)">&lt;&minus;</a>&nbsp;&nbsp;'
    var PageNum_2=PageNum%2==0?Math.ceil(PageNum/2)+1:Math.ceil(PageNum/2)
    var PageNum_3=PageNum%2==0?Math.ceil(PageNum/2):Math.ceil(PageNum/2)+1
    var strC="",startPage,endPage;
    
    if (PageNum>=PagesLen)
    {
        startPage=0;
        endPage=PagesLen-1
    }
    else if (nowPage<PageNum_2)
    {
        startPage=0;endPage=PagesLen-1>PageNum?PageNum:PagesLen-1
    }//首页
    else 
    {
        startPage=nowPage+PageNum_3>=PagesLen?PagesLen-PageNum-1: nowPage-PageNum_2+1;
        var t=startPage+PageNum;endPage=t>PagesLen?PagesLen-1:t
    }
    for (var i=startPage;i<=endPage;i++)
    {
    if (i==nowPage)
        strC+='<a href="###" style="color:red;font-weight:700;font-size:14px;text-decoration:none;" onclick="upPage('+i+')">'+(i+1)+'</a>&nbsp;'
    else 
        strC+='<a href="###" style="font-size:14px;color:#898989;" onclick="upPage('+i+')">'+(i+1)+'</a>&nbsp;'
    }
    strE='&nbsp;<a href="###" style="font-size:12px;color:#898989;text-decoration:none;" onclick="upPage('+(PagesLen-1)+')">&minus;&gt;</a>&nbsp;&nbsp;'
    document.getElementById("changpage").innerHTML=strS+strC+strE
}

function showDiv(){
    //显示提示框
    document.getElementById("popup").style.display = "block";
}

function hideDiv(){
    //隐藏提示框
    document.getElementById("popup").style.display = "none";
} 

$(document).ready(function() {
 	      //document.getElementById('Citys_txtFCity').value = "中文/拼音";
            $("div#popup").mouseup(function() {
                return false
            });
            $("div#keywordcity").mouseup(function() {
                return false
            });
            $(document).mouseup(function(e) {
     
            //alert($(e.target).parent("a.search_n").length)
                if($(e.target)[0].id =="Citys_txtFCity" ) 
                {
                    $('#keywordcity').get(0).innerHTML = "";
                    $('#keywordcity').get(0).style.visibility='hidden';
	                document.getElementById('keyword').title = "点击选择商圈或行政区";
	                document.getElementById('txtTp').value = "";	
	                if($(e.target)[0].value =="")    
	                {
                        XmlPost_ZDWC("");
                    }
                    else
                    {
                        XmlPost_ZDWC($(e.target)[0].value);
                    }
                } 
                else if($(e.target)[0].id =="keyword")
                {
                    document.getElementById('keyword').title = "点击选择商圈或行政区";
                     document.getElementById('txtTp').value = "";
                }
                else{
	                document.getElementById('popup').style.display='none';
	                $('#keywordcity').get(0).innerHTML = "";
	                $('#keywordcity').get(0).style.visibility='hidden'

                }
                if( $(e.target)[0].id !="Citys_txtFCity")
                {
                    var txtvalue =document.getElementById("Citys_txtFCity").value;
                    if(txtvalue=="")
                    {
                       document.getElementById('Citys_txtFCity').value ="中文/拼音"; 
                       document.getElementById('txtCY').value =""; 
                    }
                    else
                    {
                        //是否 正确的城市信息
                        if(flgData == "False" && txtvalue != "中文/拼音")
                        {
                            document.getElementById('Citys_txtFCity').value =getFirstRowData();
                        }
                    }
                }
                if($(e.target)[0].id !="keyword" &&  $(e.target)[0].id !="Citys_txtFCity") {

	                //document.getElementById('keywordcity').style.display='none';
	                $('#keywordcity').get(0).innerHTML = "";
	                $('#keywordcity').get(0).style.visibility='hidden';

                }
            });			
			
        });
        
        
        //查询城市信息框第1行数据
        function getFirstRowData()
        {
            try
            {
                if(document.getElementById('cityRow0').firstChild.lastChild.innerText==null || document.getElementById('cityRow0').firstChild.lastChild.innerText  =="undefined")
                {
                    return "上海";
                }
                else
                {
                    return document.getElementById('cityRow0').firstChild.lastChild.innerText;
                }
            }
            catch(ex)
            {
                return "中文/拼音";
            }
        }

//刷新页面
function myrefresh() 
{
    //alert("Ajax超时刷新")
    window.location.reload(); 
} 

function mouseover_fun(obj)
{
    obj.style.backgroundColor="#e7f1fd";
    obj.style.borderBottom="1px solid #7f9db9";
    obj.style.borderTop="1px solid #7f9db9";
    obj.style.color="#0055aa";
}

function mouseout_fun(obj)
{
    obj.style.backgroundColor="#FFFFFF";
	obj.style.borderBottom="1px solid #ffffff";
    obj.style.borderTop="1px solid #ffffff";
    obj.style.color="#898989";
}
        
//酒店查询搜索                                   
function ToResvPage()
{
//    document.getElementById("txtTp").value = "LM";
//    document.getElementById("txtTp").value = "RG";
    if(typeof(m_city) == "undefined" || m_city=="" || $('#Citys_txtFCity')[0].innerText=="中文/拼音")
    {
        $('#city_error').get(0).style.display="block";        
        $('#city_error_text').get(0).innerHTML = "请选城市!"
        return;
    }
    
    if(!CheckDate())
    {
        return;
    }

    if($('#txtTp').get(0).value =="LM")
    {
        aboutLandMark();
    }
    else if($('#txtTp').get(0).value =="RG")
    {
        aboutRegion();
    }
    else
    {
        aboutCity();
    }
}

//日期CHECK
function CheckDate()
{
    var dt1 =new Date($('#date1').get(0).value.replace('-','/').replace('-','/'));
    var dt2 =new Date($('#date2').get(0).value.replace('-','/').replace('-','/'));
    
    //如果结束日期大于今天 90天就报错
    var sDays1 = 90;
    var now = new Date();
    if(Date.parse(dt2) - now >86400000 * sDays1)
    {
//        //错误控件
//        var oerror =$('#errorSpan').get(0);
//        inputchange();
//        oerror.innerText="如果结束日期大于今天 90天!";
//        $('.form_important').get(0).style.display ="block";
        alert("结束日期大于今天 90天!");
        return false;
    }
    
    //如果结束日期大于开始日期 30天就报错
    var sDays1 = 30;
    if(Date.parse(dt2) - Date.parse(dt1) >86400000 * sDays1)
    {
//        //错误控件
//        var oerror =$('#errorSpan').get(0);
//        inputchange();
//        oerror.innerText="结束日期不能大于开始日期30天!";
//        $('.form_important').get(0).style.display ="block";
        alert("结束日期不能大于开始日期30天!");
        return false;
    }
    return true;
}

//城市
function aboutCity()
{
    location="../Resv/hotel.aspx?CityCd=" + m_city +  "&StartDate=" + $('#date1').get(0).value
                                                     + "&EndDate=" + $('#date2').get(0).value +"";
}

//酒店相关行政区
function aboutRegion()
{
    location="../Resv/hotel.aspx?CityCd=" + m_city + "&StartDate=" + $('#date1').get(0).value
                                                     + "&EndDate=" + $('#date2').get(0).value
                                                     + "&Region=" + m_regionlandmark +"";
}

//酒店相关商圈
function aboutLandMark()
{
    location="../Resv/hotel.aspx?CityCd=" + m_city + "&StartDate=" + $('#date1').get(0).value
                                                     + "&EndDate=" + $('#date2').get(0).value
                                                     + "&LandMark=" + m_regionlandmark +"";
}

// js哈希表
function HashTable() {

    this.ObjArr = {};

    this.Count = 0;

    //添加
    this.Add = function(key, value) {
        if (this.ObjArr.hasOwnProperty(key)) {
            return false; //如果键已经存在，不添加
        }
        else {
            this.ObjArr[key] = value;
            this.Count++;
            return true;
        }
    }

    //是否包含某项
    this.Contains = function(key) {
        return this.ObjArr.hasOwnProperty(key);
    }

    //取某一项 其实等价于this.ObjArr[key]
    this.GetValue = function(key) {
        if (this.Contains(key)) {
            return this.ObjArr[key];
        }
        else {
            throw Error("Hashtable not cotains the key: " + String(key)); //脚本错误
            //return;
        }
    }

    //移除
    this.Remove = function(key) {
        if (this.Contains(key)) {
            delete this.ObjArr[key];
            this.Count--;
        }
    }

    //清空
    this.Clear = function() {
        this.ObjArr = {}; this.Count = 0;
    }
}
