﻿var oPopup = window.createPopup();
var tr01_01 = "#b8def1"; //第一行背景颜色
var tr01_02 = "#b8def1"; //第二行背景颜色
var tr01_03 = "#FFFFFF";
var tab01 = "#b8def1";  //边框颜色
var NameObj,CodeObj;
var style1 = 'style="font-weight: bold;color: #000000;BACKGROUND-COLOR: #FFDFFF;height: 25px;font-size: 9pt;"';
var style2 = 'style="BACKGROUND-IMAGE: url(../images/newimg/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 shcs = new Array("北京|PEK|B","上海|SHA|S","天津|TSN|T","重庆|CKG|C","太原|TYN|T","呼和浩特|HET|H","沈阳|SHE|S","长春|CGQ|C","哈尔滨|HRB|H","南京|NKG|N","杭州|HGH|H","合肥|HFE|H","福州|FOC|F","南昌|KHN|N","济南|TNA|J","郑州|CGO|Z","武汉|WUH|W","长沙|CSX|C","广州|CAN|G","南宁|NNG|N","海口|HAK|H","成都|CTU|C","贵阳|KWE|G","昆明|KMG|K","西安|XIY|X","兰州|LHW|L","银川|INC|Y","西宁|XNN|X","乌鲁木齐|URC|W","石家庄|SJW|S","拉萨|LXA|L");
//var qtcs = new Array("阿克苏|AKU|A","阿勒泰|AAT|A","安康|AKA|A","安庆|AQG|A","百色|AEB|A","包头|BAV|B","保山|BSD|B","北海|BHY|B","北京|PEK|B","长春|CGQ|C","长沙|CSX|C","常德|CGD|C","常州|CZX|C","长治|CIH|C","成都|CTU|C","赤峰|CIF|C","重庆|CKG|C","达县|DAX|D","大理|DLU|D","大连|DLC|D","大同|DAT|D","丹东|DDG|D","敦煌|DNH|D","达县|DAX|D","恩施|ENH|E","福州|FOC|F","赣州|KOW|G","广州|CAN|G","贵阳|KWE|G","桂林|KWL|G","哈尔滨|HRB|H","海口|HAK|H","海拉尔|HLD|H","邯郸|HDG|H","汉中|HZG|H","杭州|HGH|H","合肥|HFE|H","呼和浩特|HET|H","黄山|TXN|H","黄岩|HYN|H","吉林|JIL|J","济南|TNA|J","佳木斯|JMU|J","锦州|JNZ|J","晋江|JJN|J","景德镇|JDZ|J","九江|JIU|J","九寨沟|JZH|J","库尔勒|KRL|K","昆明|KMG|K","喀纳斯|KJI|K","喀什|KHG|K","库车|KCA|K","克拉玛依|KRY|K","拉萨|LXA|L","兰州|LHW|L","丽江|LJG|L","连云港|LYG|L","临沧|LNC|L","临沂|LYI|L","柳州|LZH|L","泸州|LZO|L","洛阳|LYA|L","芒市|LUM|M","梅州|MXZ|M","满洲里|NZH|N","绵阳|MIG|M","牡丹江|MDG|M","南昌|KHN|N","南充|NAO|N","南京|NKG|N","南宁|NNG|N","南通|NTG|N","南阳|NNY|N","南苑|NAY|N","宁波|NGB|N","攀枝花|PZI|P","齐齐哈尔|NDG|Q","秦皇岛|SHP|Q","青岛|TAO|Q","衢州|JUZ|Q","三亚|SYX|S","汕头|SWA|S","上海|SHA|S","上海浦东|PVG|S","深圳|SZX|S","沈阳|SHE|S","石家庄|SJW|S","思茅|SYM|S","太原|TYN|T","天津|TSN|T","铜仁|TEN|T","万县|WXN|W","威海|WEH|W","潍坊|WEF|W","文山|WNH|W","温州|WNZ|W","乌鲁木齐|URC|W","无锡|WUX|W","武汉|WUH|W","武夷山|WUS|W","西安|XIY|X","西昌|XIC|X","西宁|XNN|X","西双版纳(景洪)|JHG|X","厦门|XMN|X","香格里拉(中甸)|DIG|X","襄樊|XFN|X","兴义|ACX|X","徐州|XUZ|X","延安|ENY|Y","盐城|YNZ|Y","延吉|YNJ|Y","烟台|YNT|Y","宜宾|YBP|Y","宜昌|YIH|Y","伊宁|YIN|Y","义乌|YIW|Y","银川|INC|Y","运城|YCU|Y","榆林|UYN|Y","湛江|ZHA|Z","张家界|DYG|Z","昭通|ZAT|Z","郑州|CGO|Z","芷江|HJJ|Z","舟山|HSN|Z","珠海|ZUH|Z");
var ywzm = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","S","T","W","X","Y","Z") 
var popup_gd=25;  //数据显示高度

var CityList;
function GetCity() {
        Request.sendPOST("/js/city2/cityList.xml","", SetCity);
}
function GetCity_gj() {
        Request.sendPOST("/js/city2/gjcityList.xml","", SetCity);
}
function SetCity(response) {
    var links = response.responseXML.getElementsByTagName("CityList");
    CityList=links;
    var tab;
    tab = '<table width="450" 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="点击查看省会城市">SH</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">';
    var num=0;
    for(var i=0;i<36;i++){
	    if(i==0 || i % 6 ==0){
		    tab+= '  <tr align="center" style="background-color:' +tr01_03+ ';">';
	    }
	    for(num;num<CityList.length;num++)
	    {
	        if(parseInt(CityList[num].childNodes[3].firstChild.nodeValue)==1) break;
	        //if(parseInt(links[i].Child.firstChild.nodeValue)==1) break;
	    }
	    if(num<CityList.length)
	    {
		    tab+= '    <td height="'+popup_gd+'" width="14.3%" ID="TD_'+CityList[num].childNodes[1].firstChild.nodeValue+'" Code="'+CityList[num].childNodes[1].firstChild.nodeValue+'" title="'+CityList[num].childNodes[0].firstChild.nodeValue+'" style="font-size: 9pt"><NOBR '+style3+' ID="NOBR_'+CityList[num].childNodes[1].firstChild.nodeValue+'">'+CityList[num].childNodes[0].firstChild.nodeValue+'</NOBR></td>';
	        num++;
	    }else{
		    tab+= '    <td height="'+popup_gd+'" width="14.3%">&nbsp;</td>';
	    }
	    if((i+1) % 6 ==0){
		    tab+= '  </tr>';
	    }
    }

    tab+= '    </table>';
    tab+= '   </td>';
    tab+= '  </tr>';
    tab+= '</table>';
    tab+= '</td>';
    tab+= '</tr>';
    tab+= '</table>';
    oPopup.document.body.innerHTML = tab;
}


function CityInput(obj1,obj2){
    NameObj=document.all(obj1);
    CodeObj=document.all(obj2);
    CodeObj.value="";
    if(NameObj.value=="") return;
    if(NameObj.value=="上海")
    {
        CodeObj.value="SHA";
        return;
    }
    for(var i=0;i<CityList.length;i++)
    {
        if (CityList[i].childNodes[0].firstChild.nodeValue==NameObj.value)
        {
            CodeObj.value=CityList[i].childNodes[1].firstChild.nodeValue;
            break;
        }
    }
}

function Split(popup_str,popup_n,popup_s){ //字符串,取第几个数据,分割字符
	var popup_split=popup_str.split(popup_s);
	return popup_split[popup_n];
}

function popUp(obj1,obj2){
    if(typeof(obj1)=='string')
    {
	    NameObj=document.all(obj1);
	    CodeObj=document.all(obj2);
    }
    else
    {
	    NameObj=obj1;
	    CodeObj=obj2;
    }

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))
    }
  }

var newX = posLib.getClientLeft(NameObj) + posLib.getCanvasElement(NameObj).clientLeft;
var newY = posLib.getClientTop(NameObj) + NameObj.offsetHeight + posLib.getCanvasElement(NameObj).clientTop;

oPopup.document.body.onclick = Htc_OnClick;
oPopup.document.body.onmousemove = Htc_onmousemove;
oPopup.show(newX,newY,450,209,document.body);
}

function Htc_OnClick(){  //鼠标点击事件
var Htc_str;
var obj=this.document.parentWindow;
var e = obj.event.srcElement;

  if (e.tagName == "LABEL")  {
	  if(e.id!=""){
		  yc_dt(e.id);
	  }
  }
  if (e.tagName == "NOBR")  {
	 //f_z(oPopup.document.all(e.id).innerHTML);
	 f_z(Split(e.id,1,"_"));
	 document.body.focus();
     oPopup.hide(); 
  }
  
  if (e.tagName == "TD"){//H_
	  if(e.id!=""){
		  var param = Split(e.id,1,"_");
		  var len = param.length;
		  if(param.indexOf('"') > -1)
		    len=len-2;
		  if(len > 1)
		  {
		    f_z(Split(e.id,1,"_"));
		    document.body.focus();
            oPopup.hide(); 
		  }
		  else
		  {
			  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);}
  }
  if (e.tagName == "NOBR")  {
	  if(e.id!=""){turnrowcolor("TD_"+Split(e.id,1,"_"));}
  }
}

function turnrowcolor(ss){   //鼠标移动TD背景颜色
 var bc="#FFD373";
 if(oPopup.document.all(ll))oPopup.document.all(ll).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(i){ 
	if(i!=yc_dt_cs){
		 if(i.indexOf("\"") > -1)
		  {
			 i=i.substring(i.indexOf("\"")+1,2)
		  }
		
		oPopup.document.all(yc_dt_cs).style.color="#0000FF";
		oPopup.document.all(i).style.color="#FF0000";
		yc_dt_cs=i;
		
		Popup_tab(i);
	}else{
			Popup_tab(i);
	}
}

function Popup_tab(str){ //生成数据
	var Popup_dat_tab= '    <table width="100%" border="0" cellspacing="1" cellpadding="0" style="font-size: 9pt">';
    var num=0;
    var ss;

    for(var i=0;i<36;i++){
	    if(i==0 || i % 6 ==0){
		    Popup_dat_tab+= '  <tr align="center" style="background-color:' +tr01_03+ ';">';
	    }
	    for(num;num<CityList.length;num++)
	    {
            if(str!="SH" && CityList[num].childNodes[2].firstChild.nodeValue.substr(0,1)==str) break;
	        if(str=="SH" && parseInt(CityList[num].childNodes[3].firstChild.nodeValue)==1)break;
	    }
	    if(num<CityList.length)
	    {
		    Popup_dat_tab+= '    <td height="'+popup_gd+'" width="14.3%" ID="TD_'+CityList[num].childNodes[1].firstChild.nodeValue+'" Code="'+CityList[num].childNodes[1].firstChild.nodeValue+'" title="'+CityList[num].childNodes[0].firstChild.nodeValue+'" style="font-size: 9pt"><NOBR '+style3+' ID="NOBR_'+CityList[num].childNodes[1].firstChild.nodeValue+'">'+CityList[num].childNodes[0].firstChild.nodeValue+'</NOBR></td>';
	        num++;
	    }else{
		    Popup_dat_tab+= '    <td height="'+popup_gd+'" width="14.3%">&nbsp;</td>';
	    }
	    if((i+1) % 6 ==0){
		    Popup_dat_tab+= '  </tr>';
	    }
    }
    Popup_dat_tab+= '    </table>';
	oPopup.document.all("Popup_Tab").innerHTML=Popup_dat_tab;
}

function f_z(temp){   //赋值给控件
    NameObj.value=oPopup.document.all("NOBR_"+temp).innerHTML;
    CodeObj.value=temp;
}

//function setCodevalue(temp){
//	var length=qtcs.length;
//	for(i=0;i<length;i++){
//		var tempArray=qtcs[i].split("|");
//		if(tempArray[0]==temp){
//			kongj.codevalue=tempArray[1];
//			break;
//		}
//	}
//}
//function getCodevalue(temp)
//{
//	var length=qtcs.length;
//	for(i=0;i<length;i++){
//		var tempArray=qtcs[i].split("|");
//		if(tempArray[1]==temp){
//			return tempArray[0];
//		}
//	}
//}
