﻿var oPopup = window.createPopup();

var tr01_01 = "#E7E3E7"; //第一行背景颜色
var tr01_02 = "#D6D3D6"; //第二行背景颜色
var tr01_03 = "#FFFFFF";
var tab01 = "#6595D6";  //边框颜色
var kongj;
var hidObj;
var style1 = 'style="font-weight: bold;color: #FFFFFF;background-image: url(/common/images/CityListTop.gif);height: 25px;font-size: 9pt;"';
var style2 = 'style="BACKGROUND-IMAGE: url(/common/images/bg2.GIF); BACKGROUND-COLOR: #F3F6FA; color: #333333;background-repeat:repeat-x; background-position:bottom; font-size: 9pt;"';
var style3 = 'style="position: relative; left: 0px; top: 0px; width: 100%;overflow:hidden; text-overflow:ellipsis;"';

//北京|PEK|B  城市|三字代码|拼音首字母
var HotCity,AllCity
var xmlDoc=new ActiveXObject("Msxml2.FreeThreadedDOMDocument");   
    xmlDoc.async=false;   
    xmlDoc.resolveExternals=false;   
    xmlDoc.load("../common/js/DCityInfo.xml");
    HotCity=xmlDoc.selectSingleNode("//DCityInfo//CityList//HotCity").text;   
    AllCity=xmlDoc.selectSingleNode("//DCityInfo//CityList//AllCity").text;
    Char26="A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,S,T,W,X,Y,Z"
var shcs = HotCity.split(',');
var qtcs = AllCity.split(',');
var ywzm = Char26.split(',');

var popup_gd=25;  //数据显示高度
var popup_i; 
var popup_int0=0;
var popup_int1=0;
var popup_int2=0;
var popup_int3=0;


function Split(popup_str,popup_n,popup_s){ //字符串,取第几个数据,分割字符
	var popup_split;
	 popup_split=popup_str.split(popup_s);
	return popup_split[popup_n];
}

function popUp(tbObjId,hidObjId){
if(typeof(tbObjId)=='string')
	kongj=document.all(tbObjId);
else
	kongj=tbObjId;
if(typeof(hidObjId)=='string')
    hidObj=document.all(hidObjId)
else
    hidObj=hidObjId;

var posLib = {
    getClientLeft:function (el) {
     var r = el.getBoundingClientRect();
     return r.left- this.getBorderLeftWidth(this.getCanvasElement(el));
    },

    getClientTop:    function (el) {
     var r = el.getBoundingClientRect();
      return r.top - this.getBorderTopWidth(this.getCanvasElement(el));
    },

    getLeft:    function (el) {
      return this.getClientLeft(el) + this.getCanvasElement(el).scrollLeft;
    },

    getTop:    function (el) {
      return this.getClientTop(el) + this.getCanvasElement(el).scrollTop;
    },

    getInnerLeft:    function (el) {
      return this.getLeft(el) + this.getBorderLeftWidth(el);
    },

    getInnerTop:    function (el) {
      return this.getTop(el) + this.getBorderTopWidth(el);
    },

    getWidth:    function (el) {
      return el.offsetWidth;
    },

    getHeight:    function (el) {
      return el.offsetHeight;
    },

    getCanvasElement:    function (el) {
      var doc = el.ownerDocument || el.document;    // IE55 bug
      if (doc.compatMode == "CSS1Compat")
        return doc.documentElement;
      else
        return doc.body;
    },

    getBorderLeftWidth:    function (el) {
      return el.clientLeft;
    },

    getBorderTopWidth:    function (el) {
      return el.clientTop;
    },

    getScreenLeft:    function (el) {
      var doc = el.ownerDocument || el.document;    // IE55 bug
      var w = doc.parentWindow;
      return w.screenLeft + this.getBorderLeftWidth(this.getCanvasElement(el)) + this.getClientLeft(el);
    },

    getScreenTop:    function (el) {
      var doc = el.ownerDocument || el.document;    // IE55 bug
      var w = doc.parentWindow;
      return w.screenTop  + this.getClientTop(el);//+ this.getBorderTopWidth(this.getCanvasElement(el))
    }
  }

popup_int0=0;
popup_int1=0;
popup_int2=0;
popup_int3=0;
var tab;
tab = '<table width="350" border="0" cellpadding="0" cellspacing="2" bgcolor="' +tab01+ '">';
tab+= '<tr>';
tab+= '<td>';
tab+= '<table width="100%" border="0" cellpadding="0" cellspacing="0" style="background-color:' +tr01_02+ ';">';
tab+= '  <tr align="center">';
tab+= '    <td height="23"'+style1+'>请选择您要的城市</td>';
tab+= '  </tr>';
tab+= '  <tr align="center">';
tab+= '    <td height="23"'+style2+'>';
tab+= '      <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" style="font-size: 9pt"><tr><td width="100">拼音首字母：</td><td><table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size: 10pt"><tr align="center">';
for(var ywzm_i=0;ywzm_i<26;ywzm_i++){
	if(!ywzm[ywzm_i])break;
	tab+= '<td id="H_'+ywzm[ywzm_i]+'"><label id="'+ywzm[ywzm_i]+'" style="color:#0000FF; cursor:hand" title="点击查看城市首字母为 '+ywzm[ywzm_i]+' 的城市">'+ywzm[ywzm_i]+'</label></td>';
}
tab+= '        <td id="H_SH"><label id="SH" style="color:#FF0000; cursor:hand" title="点击查看省会城市">HOT</label></td>';
tab+= '      </tr></table></td></tr></table>';
tab+= '    </td>';
tab+= '  </tr>';
tab+= '  <tr align="center">';
tab+= '   <td id="Popup_Tab">';
tab+= '    <table width="100%" border="0" cellspacing="1" cellpadding="0" style="font-size: 9pt">';

for(popup_i=0;popup_i<36;popup_i++){
	if(popup_i==0 || popup_i % 6 ==0){
		tab+= '  <tr align="center" style="background-color:' +tr01_03+ ';">';
	}
	if(shcs[popup_i]){
		tab+= '    <td height="'+popup_gd+'" width="14.3%" ID="popup_td_cszm_'+popup_int0+'" title="'+Split(shcs[popup_i],0,"|")+'" style="font-size: 9pt"><NOBR '+style3+' ID="popup_NOBR_cszm_'+Split(shcs[popup_i],1,"|")+'_'+popup_int0+'">'+Split(shcs[popup_i],0,"|")+'</NOBR></td>';
		popup_int0++;
	}else{
		tab+= '    <td height="'+popup_gd+'" width="14.3%">&nbsp;</td>';
	}
	popup_int3 = popup_i+1;
	if(popup_int3 % 6 ==0){
		tab+= '  </tr>';
	}
}

tab+= '    </table>';
tab+= '   </td>';
tab+= '  </tr>';
tab+= '</table>';
tab+= '</td>';
tab+= '</tr>';
tab+= '</table>';
var newX =posLib.getLeft(kongj);
var newY =posLib.getTop(kongj)+20;
oPopup.document.body.innerHTML = tab;
oPopup.document.body.onclick = Htc_OnClick;
oPopup.document.body.onmousemove = Htc_onmousemove;
oPopup.show(newX,newY,350,209,document.body);

}

function Htc_OnClick(){  //鼠标点击事件
var Htc_str;
var obj=this.document.parentWindow;
var e = obj.event.srcElement;
//alert("obj="+obj+",e="+e+",e.tagName="+e.tagName+",e.id="+e.id);
  if (e.tagName == "LABEL")  {
	  if(e.id!=""){
		  yc_dt(e.id);
	  }
  }
  if (e.tagName == "NOBR")  {
	 f_z(e.innerHTML,Split(e.id,3,"_"));
	  oPopup.hide(); 
  }
  
  if (e.tagName == "TD"){
	  if(e.id!=""){
		  yc_dt(Split(e.id,1,"_"));
	  }
  }
}

var ll="popup_td_cszm_0";

function Htc_onmousemove(){   //鼠标移动事件
var obj=this.document.parentWindow;
var e = obj.event.srcElement;
  if (e.tagName == "TD")  {
	  if(e.id!=""){turnrowcolor(e.id,ll);}
  }
  if (e.tagName == "NOBR")  {
	  if(e.id!=""){turnrowcolor("popup_td_cszm_"+Split(e.id,4,"_"),ll);}
  }
}

function turnrowcolor(ss,ls){   //鼠标移动TD背景颜色
 var bc="#FFD373";
 if(oPopup.document.all(ls))oPopup.document.all(ls).style.backgroundColor="";
 if(oPopup.document.all(ss))oPopup.document.all(ss).style.backgroundColor=bc;
 if(oPopup.document.all(ss))oPopup.document.all(ss).style.cursor="hand";
 ll=ss;	
}

var yc_dt_cs="SH";
function yc_dt(sint){
    if(sint=="td")
        return false;
	if(sint!=yc_dt_cs){	    
		oPopup.document.all(yc_dt_cs).style.color="#0000FF";
	    oPopup.document.all(sint).style.color="#FF0000";
		yc_dt_cs=sint;
		if(sint!="SH"){
			Popup_tab(sint,0);
		}else{
			Popup_tab(sint,1);
		}
	}
}

function Popup_tab(str,lx){ //生成数据
	var Popup_dat_i=0;
	var Popup_dat_n;
	var Popup_dat_tab="";
	var Popup_dat =new Array()
	if(lx==0){
		for(Popup_dat_n=0;Popup_dat_n<qtcs.length;Popup_dat_n++){
			if(Split(qtcs[Popup_dat_n],2,"|")==str){
				Popup_dat[Popup_dat_i++]=qtcs[Popup_dat_n];
			}
		}
	}else{
		Popup_dat=shcs;
	}
	popup_int0=0;
	
	Popup_dat_tab+= '<table width="100%" border="0" cellspacing="1" cellpadding="0" style="font-size: 9pt">';
	for(Popup_dat_n=0;Popup_dat_n<36;Popup_dat_n++){
		if(Popup_dat_n==0 || Popup_dat_n % 6 ==0){
			Popup_dat_tab+= '  <tr align="center" style="background-color:' +tr01_03+ ';">';
		}
		if(Popup_dat[Popup_dat_n]){
			Popup_dat_tab+= '    <td height="'+popup_gd+'" width="14.3%" ID="popup_td_cszm_'+popup_int0+'" title="'+Split(Popup_dat[Popup_dat_n],0,"|")+'" style="font-size: 9pt"><NOBR '+style3+' ID="popup_NOBR_cszm_'+Split(Popup_dat[Popup_dat_n],1,"|")+'_'+popup_int0+'">'+Split(Popup_dat[Popup_dat_n],0,"|")+'</NOBR></td>';
			popup_int0++;
		}else{
			Popup_dat_tab+= '    <td height="'+popup_gd+'" width="14.3%">&nbsp;</td>';
		}
		popup_int3 = Popup_dat_n+1;
		if(popup_int3 % 6 ==0){
			Popup_dat_tab+= '  </tr>';
		}
	}
	Popup_dat_tab+= '    </table>';
	oPopup.document.all("Popup_Tab").innerHTML=Popup_dat_tab;
}

function f_z(CityName,CityCode){    //赋值给控件
  kongj.value=CityName;
  if(hidObj!=null)
    hidObj.value=CityCode;
    if(CityCode!="")
    {
        kongj=null;
        hidObj=null;
    };
}

function SetCityName(tbObjId,hidObjId)
{
    if(typeof(tbObjId)=='string')
	    kongj=document.all(tbObjId);
    else
	    kongj=tbObjId;
	
    if(typeof(hidObjId)=='string')
        hidObj=document.all(hidObjId)
    else
        hidObj=hidObjId;
        
    if(kongj.value=="")
    {
        f_z('','');
        return;
    }
    
    var KeyCode=parseInt(event.keyCode);
    if(KeyCode==9 || KeyCode==13)
        return;
   kongj.value=kongj.value.replace(" ","");
   kongj.value=kongj.value.replace("　","");
   
    //初始化
    f_z(kongj.value.toUpperCase(),'')
   
    if(kongj.value.length>=2)
    {
        var temp;
        var finded=false;        
        for(i=0;i<qtcs.length;i++)
        {            
            temp=qtcs[i].split('|');
            if(temp[1].toUpperCase()==kongj.value || temp[0]==kongj.value)
            {
               f_z(temp[0],temp[1]);
               finded=true;
               break;
            };
        };
        //if(!finded)
            //f_z('','');
    } 
};