function funLoadPlace(evt,name,type) {
	if(evt.keyCode==38 || evt.keyCode==40){return false;}
	curCursor = 0;
	if(name!=""){document.getElementById("hotCity").style.display='none';}
	var showDiv = document.getElementById("cityList");
	showDiv.style.display='block';
	var url = "/placeFront.do";
	if(type=="en") url+="?method=loadCityByEname&enName="+name;
	if(type=="cn") url+="?method=loadCityByCname&cnName="+name;
	//window.status = url+"  "+name;
	new Ajax.Updater("cityList",encodeURI(url), {asynchronous:true, evalScripts:true});
}
	function ajustPlaceDiv(evnt){
		//var showDiv = document.getElementById("placeWin");	//cityList
		var showDiv = document.getElementById(placeWin);
		var scrollTop;
		var scrollLeft;
		if (window.pageYOffset){scrollTop = window.pageYOffset;} 
		else if(document.documentElement && document.documentElement.scrollTop){scrollTop = document.documentElement.scrollTop; } 
		else if(document.body){scrollTop = document.body.scrollTop; } 
		if(window.pageXOffset){ scrollLeft=window.pageXOffset;} 
		else if(document.documentElement && document.documentElement.scrollLeft){scrollLeft=document.documentElement.scrollLeft;} 
		else if(document.body){scrollLeft=document.body.scrollLeft;}
		var x = evnt.clientX + scrollLeft;	//document.body.scrollLeft;
		var y = evnt.clientY + scrollTop;  //document.body.scrollTop;
		//showDiv.style.left = (x - 50) + "px";
		//showDiv.style.top = (y + 10) + "px";
		//$("#cityList").css({top:'644px'})
//		alert(showDiv+"\n\n"+showDiv.style.top);
	}
//这是以前的版本的
	function showHotCity(evnt, contientCode){
		document.getElementById("cityList").style.display='none';
		var showHotCity = document.getElementById("hotCity");
		try{
			if(ScriptHelperV2!=null && ScriptHelperV2!=undefined){
			 var src=Object(evnt.srcElement ? evnt.srcElement : evnt.target);
				ScriptHelperV2.showDivCommon(src,'hotCity', 0, +100); 
			}
		}catch(e){
			showHotCity.style.display='block';ajustHCityDiv(evnt,showHotCity);
		}
		//var url = "/placeFront.do?method=hotCity";
		//if(getCookie("contientCode")!="")contientCode=getCookie("contientCode");
		var url = "/city.php?method=loadHotCity&cCode="+contientCode+"&chooseCityID="+getCookie("chooseCityID");
		//alert (contientCode);
		try{
			new Ajax.Updater("hotCity",url, {asynchronous:true, evalScripts:true});
		}catch(e){
			$("#hotCity").load(url);
			//alert(url);
		}

	}
	
//这是新改的版本2010-1-4
//function showHotCity(evnt, contientCode){
//	document.getElementById("cityList").style.display='none';
//	var showHotCity = document.getElementById("hotCity");
//	//showHotCity.style.display='block';ajustHCityDiv(evnt,showHotCity);
//	//这是新改的 ,如果要改为来，则上一句要去掉注释
//   var src=Object(evnt.srcElement ? evnt.srcElement : evnt.target);
//	ScriptHelperV2.showDivCommon(src,'hotCity', 0, -20);  
//	//var url = "/placeFront.do?method=hotCity";
//	if(getCookie("contientCode")!="")contientCode=getCookie("contientCode");
//	var url = "/city.php?method=loadHotCity&cCode="+contientCode+"&chooseCityID="+getCookie("chooseCityID");
//	try{
//		new Ajax.Updater("hotCity",url, {asynchronous:true, evalScripts:true});
//	}catch(e){
//		$("#hotCity").load(url);
//	}
//
//}


function showHotCity2(contientCode){
	setCookie("contientCode",contientCode,365);
	//document.getElementById("cityList").style.display='none';
	//var showHotCity = document.getElementById("hotCity");
	//showHotCity.style.display='block';
	//var url = "/placeFront.do?method=hotCity";
	var url = "/city.php?method=loadHotCity&cCode="+contientCode;
	$("#hotCity").load(url);
	/*try{
		new Ajax.Updater("hotCity",url, {asynchronous:true, evalScripts:true});
	}catch(e){
		$("#hotCity").load(url);
	}*/
}
	function ajustHCityDiv(evnt,showDiv){
		var scrollTop;
		var scrollLeft;
		if (window.pageYOffset){scrollTop = window.pageYOffset;} 
		else if(document.documentElement && document.documentElement.scrollTop){scrollTop = document.documentElement.scrollTop; } 
		else if(document.body){scrollTop = document.body.scrollTop; } 
		if(window.pageXOffset){ scrollLeft=window.pageXOffset;} 
		else if(document.documentElement && document.documentElement.scrollLeft){scrollLeft=document.documentElement.scrollLeft;} 
		else if(document.body){scrollLeft=document.body.scrollLeft;}
		var x = evnt.clientX + scrollLeft;	//document.body.scrollLeft;
		var y = evnt.clientY + scrollTop;  //document.body.scrollTop;
		showDiv.style.left = x - 180 + "px";
		showDiv.style.top = y + 20 + "px";
	}
	
var _tagCnID; var _tagID;
function funChoosedCity(cnName,id){
	setCookie("chooseCityID",id,365);
	document.getElementById(_tagCnID).value = cnName;
	document.getElementById(_tagID).value = id;
	funCloseAllPlacePanel();
}
	//当有同一个Page需要调用2个以上的地区录入时使用
	function initVariable(field){
		_tagCnID = "show"+field;
		_tagID = field;
	}

function funCloseAllPlacePanel(){
	try{
		document.getElementById('cityList').style.display='none';
		document.getElementById('hotCity').style.display='none';
		
		if(ScriptHelperV2!=null && ScriptHelperV2!=undefined){
		//这是新加的，可以进行删除的****************
			ScriptHelperV2.closeDivCommon('hotCity'); 
		}
		//var p1 = document.getElementById("cityList").style.display;
		//var p2 = document.getElementById("hotCity").style.display;
		//if(p1!="none")p1="none";
		//if(p2!="none")p2="none";
	}catch(e){}
}

function fixFill(){
	var allCity = document.getElementById("_bgAllCity").value;
	var tag = document.getElementById(_tagCnID);
	var tagID = document.getElementById(_tagID);
	if(allCity.Trim()!=""){
		var allCitys = allCity.split(",");
		var firstCity = allCitys[0];
		var firstCityName = firstCity.split("|")[0];
		var firstCityID = firstCity.split("|")[1];
		
		if(tagID==""){
			tag.value = firstCityName;
			tagID = firstCityID;
		}else{
			var isValid = false;
			for(var i=0;i<allCitys.length;i++){
				var cityName = allCitys[0].split("|")[0];
				var cityID = allCitys[0].split("|")[1];
				if(cityName.Trim()==tag.value.Trim() && cityID.Trim()==tagID.value.Trim()){
					isValid = true;break;
				}
			}
			if(!isValid){
				tag.value = firstCityName;
				tagID.value = firstCityID;
			}
		}
	}else{
		tag.value = "";
		tagID.value = "";
	}
	funCloseAllPlacePanel();
}

var curCursor = 0;
function rollPlaceSelect(evt){
	if(evt.keyCode==38 || evt.keyCode==40 || evt.keyCode==13){
	//try{
		var allCity = document.getElementById("_bgAllCity").value;
		if(allCity.Trim()!=""){
			var allCitys = allCity.split(",");
//			window.status = evt.keyCode+"  curCursor:"+curCursor;
			if(allCitys.length<1)funCloseAllPlacePanel();
			var cityNums = allCitys.length;
			var focusLine;
			var tag = document.getElementById(_tagCnID);
			var tagID = document.getElementById(_tagID);
			if(evt.keyCode==40){
				if(curCursor<allCitys.length){
					if(curCursor>0){
						focusLine = document.getElementById(curCursor);
						//focusLine.style.backgroundColor="#FFFFFF";
						focusLine.style.backgroundColor="";
					}
					curCursor++;
					focusLine = document.getElementById(curCursor);
					focusLine.style.backgroundColor="#00B8EE";
					tag.value = focusLine.title;
					tagID.value = focusLine.name;
				}
			}else if(evt.keyCode==38){
				if(curCursor>1){
					focusLine = document.getElementById(curCursor);
//					focusLine.style.backgroundColor="#FFFFFF";
					focusLine.style.backgroundColor="";	//"transparent";
					curCursor--;
					focusLine = document.getElementById(curCursor);
					focusLine.style.backgroundColor="#00B8EE";
					tag.value = focusLine.title;
					tagID.value = focusLine.name;
				}
			}
			
//			if(evt.keyCode==13){funCloseAllPlacePanel();}
			
//			var focusLine = document.getElementById("1");
//			alert(focusLine.style.backgroundColor);
//			focusLine.style.backgroundColor="#00B8EE";
//			window.status = "  curCursor:"+curCursor+"  "+document.getElementById(curCursor).title;
			
		//	window.status=evt.keyCode
		}
//	}catch(e){}
	}
}
//从common转移过来的函数
function getCookie(NameOfCookie){
		if(document.cookie.length>0){
			var begin = document.cookie.indexOf(NameOfCookie+"=");
			if (begin!=-1){
				begin += NameOfCookie.length+1;
				var end = document.cookie.indexOf(";",begin);
				if (end==-1) end=document.cookie.length;
				return replaceAll(decodeURI(unescape(document.cookie.substring(begin,end)))," ","+");
			}return '';
		}return '';
	}
	function setCookie(NameOfCookie,value,expiredays){
		var ExpireDate = new Date();
		ExpireDate.setTime(ExpireDate.getTime()+(expiredays*24*3600*1000));
		document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays==null)?"":";expires="+ExpireDate.toGMTString()+";path=/");
	}
	function delCookie(NameOfCookie){
		var exp = new Date();
		exp.setTime(exp.getTime()-1);
		if(getCookie(NameOfCookie)!=null){document.cookie = NameOfCookie + "=" + ";expires="+exp.toGMTString();}
	}

//将悬浮层的位置定位在屏幕中央
function setDivLocation(objdiv,obj){
	Position.clone(obj.id, objdiv.id);
	var top = objdiv.style.top;
	objdiv.style.top = getPositionNum(top) -200 + obj.offsetHeight + 2 + "px";	
	objdiv.style.left = "350px";
}

/*
	@function - 循环替换字串字符
	@param cSrc - 源字符串
	@param cFind - 需要被替换的字符串
	@param cReplace - 将要被替换成的字符串
	@return - 返回替换成功的字符串
*/
function replaceAll(cSrc,cFind,cReplace){
	try{
		while (cSrc.indexOf(cFind)!=-1){
			cSrc = cSrc.replace(cFind,cReplace);
		}
		return cSrc;
	}catch(e){}
}
