
function g$(fctId){	return document.getElementById(fctId);}
function n$(fctId){	return document.getElementsByName(fctId);}
function c$(fctId,fctClassName){
	var varTempDivObj=g$(fctId);
	if(!varTempDivObj){
		GetPyzyIframe("ifm"+fctId);
		varTempDivObj=document.createElement("div");
		varTempDivObj.id=fctId;
		if(fctClassName && fctClassName!="")varTempDivObj.className=fctClassName;
		document.body.appendChild(varTempDivObj);
	}
	return varTempDivObj;
}

//取得某ID的iframe对象，若不存在该ID的对象则自动创建
function GetPyzyIframe(fctIfmId,fctVisibility,fctTop,fctLeft,fctWidth,fctHeight){
	var varTempIfmObj=g$(fctIfmId);
	if(!varTempIfmObj){
		varTempIfmObj=document.createElement("iframe");
		varTempIfmObj.id=fctIfmId;
		varTempIfmObj.style.position="absolute";
		varTempIfmObj.style.zIndex="1";
		varTempIfmObj.style.visibility="hidden";
		document.body.appendChild(varTempIfmObj);
	}
	if(fctTop)varTempIfmObj.style.top=fctTop+"px";
	if(fctLeft)varTempIfmObj.style.left=fctLeft+"px";
	if(fctWidth)varTempIfmObj.style.width=fctWidth+"px";
	if(fctHeight)varTempIfmObj.style.height=fctHeight+"px";
	if(fctVisibility)varTempIfmObj.style.visibility=(document.all?fctVisibility:"hidden	");
	return varTempIfmObj;
}

//取得某对象的坐标位置、宽、高
function getPosition(obj){
	var top=0;
	var left=0;
	var width=obj.offsetWidth;
	var height=obj.offsetHeight;
	while(obj.offsetParent){
		top+=obj.offsetTop;
		left+=obj.offsetLeft;
		obj=obj.offsetParent;
	}
	return{"top":top,"left":left,"width":width,"height":height};
}

//取得编码存储框对象
function GetValueToInputObj(fctThisObj){
	if(!fctThisObj)return null;
	var varThisObjAutoInput=(fctThisObj.getAttributeNode("value_to_input")?fctThisObj.getAttributeNode("value_to_input").value:"");
	if(varThisObjAutoInput=="")return null;
	return g$(varThisObjAutoInput);
}

//自动触发下一个对象的Act事件
function AutoNextInputAct(fctThisObj,fctAct){
	var varNextInput=fctThisObj.getAttributeNode("nextinput");
	if(varNextInput && varNextInput!=""){
		if(document.all){
			eval("g$('"+varNextInput.value+"')."+fctAct+"()");
		}else{
			var evt = document.createEvent("MouseEvents");
			evt.initEvent(fctAct,true,true);
			g$(varNextInput.value).dispatchEvent(evt);
		}
		g$(varNextInput.value).focus();
	}
}

//给某对象的某事件增加处理函数AddFunToObj(document,"onclick","alert('1');")
function AddFunToObj(fctObj,fctAct,fctFunction){
	if(fctObj.addEventListener){ //!IE
		fctObj.addEventListener(fctAct.replace("on",""),function(e){
			e.cancelBubble=!eval(fctFunction);
		},false);
	}else if(fctObj.attachEvent){ //IE
		fctObj.attachEvent(fctAct,function(){
			return eval(fctFunction);
		});
	}
}

function matchCityItems(cityDataSplitI, objValue) {
    var cityArr = cityDataSplitI.split("|"); 
    for (var i = 0; i < cityArr.length; i++) {       
        if (cityArr[i].toUpperCase().substr(0, objValue.length) == objValue.toUpperCase())
            return true;
    }
    return false;
}
var varPageId=0;
//生成并显示出城市下拉菜单
function GetWebCityList(fctThisObj,pos,even){
/*
fctThisObj 自动完成对象；
pos 指定定位方式，默认与表单对象左侧对齐，若为'R'则基于表单对象右侧对齐
even 指定触发方式，若为'click'，则清空input值

modifyed by youhua@staff Tel:5947 @ 090707
**/

	var varData='';
	var varMenuObj=c$("divAddressMenu");
	var varThisObj=fctThisObj;
	var EventType = even;
	if(varThisObj.id=="menuPageS"||varThisObj.id=="menuPageE"){
		varThisObj=varMenuObj.obj;
	}else{
		varPageId=0;
	}
	//清除已选城市Value
	var varThisObjAutoInput=GetValueToInputObj(varThisObj); //取得城市编码值存储对象
	if(EventType=='click'){varThisObjAutoInput.value="";varThisObj.value=""};//清除输入框值by youhuata 090629
	//取得城市数据并拆解为数组
	var varObjValue=varThisObj.value;
	var varThisObjAdd=(varThisObj.getAttributeNode("mod_address_suggest")?varThisObj.getAttributeNode("mod_address_suggest").value:"");
	   varData=(varObjValue==""?(varThisObjAdd==""?webAddress:varThisObjAdd):webAddress);
	var varHtmlStr="",varCityDataSplit=varData.split("@"),varCityDataSplitI,varCityDataSplitIu,varNextPageStr="";
	//存储当前操作对象
	varMenuObj.obj=varThisObj;
	var varPageRCount=(varThisObj.getAttributeNode("pagecount")?parseInt(varThisObj.getAttributeNode("pagecount").value,10):18);
	var varThisPageI = 0; 
	for(var i=1;i<varCityDataSplit.length-1;i++){
	    varCityDataSplitI = varCityDataSplit[i];
	    
		if (matchCityItems(varCityDataSplitI, varObjValue) || varObjValue == "" || i == varObjValue) { // || varCityDataSplitI.toLowerCase().indexOf(varObjValue.toLowerCase())>=0
			varThisPageI+=1;
			if(varThisPageI>varPageId*varPageRCount && varThisPageI<=(varPageId+1)*varPageRCount){
				varCityDataSplitISplit=varCityDataSplitI.split("|");
            		varHtmlStr+="<a href='javascript:;' onclick='WriteCity("+varThisPageI+")' id='menuA"+varThisPageI+"' title='"+varCityDataSplitI+"'><span>"+varCityDataSplitISplit[1]+"("+varCityDataSplitISplit[2]+")</span><em>"+varCityDataSplitISplit[0]+"</em></a>";
			}
		}
	}
	if(varThisPageI>varPageRCount){
		varNextPageStr="&nbsp;<b id=menuPageS style="+(varPageId>0?"cursor:pointer;":"color:#666666;")+">&lt;&lt;&lt;&nbsp;上一页</b>　"
		varNextPageStr+="<b id=menuPageE style="+(varThisPageI>(varPageId+1)*varPageRCount?"cursor:pointer;":"color:#666666;")+">下一页&nbsp;&gt;&gt;&gt;</b>";
	}
	var varThisObjPosition=getPosition(varThisObj); //取得事件发生处控件坐标
	with(varMenuObj){
		style.top=varThisObjPosition.top+varThisObjPosition.height+"px";
		style.left=varThisObjPosition.left+"px";
		style.visibility="hidden";
		innerHTML="<div><h4>可输拼音/汉字/首字母</h4>"+(varHtmlStr==""?"<nobr>没有找到您查的城市‘"+varObjValue+"’。</nobr>":varHtmlStr+varNextPageStr)+"</div>";
	}
	var MenuWidth = getPosition(varMenuObj).width;
	var MenuL = varThisObjPosition.left;
	if(pos=='R'){
			varMenuObj.style.left=varThisObjPosition.left-(MenuWidth-varThisObjPosition.width)+'px';
			MenuL = varThisObjPosition.left-(MenuWidth-varThisObjPosition.width);
		}
	varMenuObj.style.visibility="visible";	
	GetPyzyIframe("ifm"+varMenuObj.id,"visible",(varThisObjPosition.top+varThisObjPosition.height),MenuL,varMenuObj.offsetWidth,varMenuObj.offsetHeight); //取Iframe
	return false;
}
//选择某城市
function WriteCity(fctI){
	var varMenuObj=c$("divAddressMenu");
	var varThisObj=varMenuObj.obj;
	var varMenuValue=g$("menuA"+fctI).title;
	varMenuValue=varMenuValue.split("|");
	varThisObj.value=varMenuValue[1];
	
	var varThisObjAutoInput=GetValueToInputObj(varThisObj); //取得城市编码值存储对象
	if(!varThisObjAutoInput)varThisObjAutoInput=varThisObj;
	varThisObjAutoInput.value=varMenuValue[0];
	
	if(typeof(fctI)=="number")AutoNextInputAct(varThisObj,"click");
	//_Hidden("1");
}
//隐藏城市列表
function _Hidden(e){
	e=e?e:event;
	var varMenuObj=c$("divAddressMenu");
	var varThisObj=varMenuObj.obj;
	if(varMenuObj.style.visibility!="hidden"){
		if(e){
			var EventOBJ=(e.srcElement?e.srcElement:e.target);
			if(EventOBJ.id=="menuPageS" && EventOBJ.style.color==""){ //如果点的是“上一页”则向上翻页
				varPageId=varPageId-1;
				GetWebCityList(EventOBJ);
			}
			if(EventOBJ.id=="menuPageE" && EventOBJ.style.color==""){ //如果点的是“下一页”则向下翻页
				varPageId=varPageId+1;
				GetWebCityList(EventOBJ);
			}
			if(varThisObj==EventOBJ || EventOBJ.id.indexOf("menuPage")==0 || EventOBJ.id.indexOf("divAddressMenu")==0) return false;
		}
		
		var varThisObjAutoInput=GetValueToInputObj(varThisObj); //取得城市编码值存储对象
		if(g$("menuA1")){ //如果下拉菜单中存在第一个城市
			if(!varThisObjAutoInput)varThisObjAutoInput=varThisObj;
			if(varThisObjAutoInput.value=="" || varThisObjAutoInput==varThisObj){ //编码框中无值
				WriteCity("1");
			}
		}else if(EventOBJ.id.indexOf("menuA")<0){ //如果下拉菜单中不存在满足条件的城市
			if(varThisObj)varThisObj.value="";
		}
		varMenuObj.style.visibility="hidden";
		GetPyzyIframe("ifm"+varMenuObj.id,"hidden","400","100");
	}
}
 

AddFunToObj(window,"onload","AddFunToObj(document,'onclick','_Hidden("+(document.all?"":"e")+");HiddenDateBox();');");

function postcity()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/";
	window.open(pageURL)
}

function postcityline()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/lines/";
	window.open(pageURL)
}
function postcityspot()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/spots/";
	window.open(pageURL)
}
function postcityhotel()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/hotels/";
	window.open(pageURL)
}
function postcityfang()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/dingfangs/";
	window.open(pageURL)
}
function postcitypiao()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/dingpiaos/";
	window.open(pageURL)
}
function postcityyou()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/daoyous/";
	window.open(pageURL)
}
function postcityche()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/zuches/";
	window.open(pageURL)
}
function postcityyi()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/huiyis/";
	window.open(pageURL)
}
function postcityzheng()
{
	var obj = document.getElementById('SCityCode');
	var pageURL="http://"+obj.value+".xxjq.com/qianzhengs/";
	window.open(pageURL)
}

