var citylist={};
citylist.hot_city=['北京','上海','广州','深圳','天津'];
citylist.city={
	first_A:['安庆','鞍山','安阳','安康','安顺','阿坝藏族羌族自治州'],
	first_B:['北京','保定','宝鸡','本溪','包头','蚌埠','北海','亳州','巴中','毕节地区','滨州','白城','白山','白银','博尔塔拉蒙古自治州'],
	first_C:['成都','重庆','长春','长沙','巢湖','潮州','常德','承德','常州','池州','滁州','郴州','赤峰','长治','沧州','朝阳','崇左','楚雄彝族自治州','昌吉回族自治州'],
	first_D:['大连','东莞','大庆','丹东','德州','德阳','东营','大同','大庆','定西','达州','大兴安岭地区','大理白族自治州'],
	first_E:['鄂尔多斯','鄂州','恩施土家族苗族自治州'],
	first_F:['福州','佛山','抚顺','凤凰','防城港','阜阳','阜新'],
	first_G:['广州','贵阳','桂林','赣州','贵港','广安','广元','甘孜藏族自治州'],
	first_H:['衡阳','黄山','合肥','邯郸','惠州','杭州','海口','湖州','黄石','葫芦岛','哈尔滨','呼和浩特','淮北','淮南','淮安','河源','河池','贺州','黑河','黄冈','鹤壁','衡水','菏泽','怀化','鹤岗','呼伦贝尔','汉中','海东地区','海北藏族自治州','海南藏族自治州','红河哈尼族彝族自治州'],
	first_I:[],
	first_J:['焦作','荆州','荆门','吉林','江门','揭阳','金华','金昌','嘉兴','九江','锦州','济南','九华山','佳木斯','景德镇','济宁','济源','吉安','晋城','晋中','酒泉','鸡西'],
	first_K:['昆明','克拉玛依','开封'],
	first_L:['廊坊','乐山','柳州','洛阳','泸州','辽阳','辽源','陇南','连云港','聊城','临汾','临沂','丽水','六安','兰州','吕梁','娄底','拉萨','来宾','漯河','莱芜','龙岩','临夏回族自治州','凉山彝族自治州'],
	first_M:['茂名','梅州','眉山','绵阳','马鞍山','牡丹江'],
	first_N:['南京','南通','宁德','宁波','南宁','南昌','内江','南充','南宁','南平','南阳'],
	first_O:[],
	first_P:['莆田','盘锦','平顶山','平凉','濮阳','攀枝花','萍乡'],
	first_Q:['青岛','泉州','秦皇岛','齐齐哈尔','七台河','庆阳','曲靖','清远','潜江','钦州','黔东南苗族侗族自治州','黔南布依族苗族自治州'],
	first_R:['日照','日喀则地区'],
	first_S:['上海','韶关','汕头','汕尾','深圳','三亚','四平','苏州','十堰','沈阳','绍兴','邵阳','石家庄','绥化','随州','三明','三门峡','上饶','双鸭山','商丘','商洛','宿州','宿迁','山南地区','朔州','松原','石嘴山','石河子','遂宁','神农架林区'],
	first_T:['天津','太原','唐山','台州','泰州','泰安','吐鲁番地区','塔城地区','天水','天门','铁岭','通化','通辽','铜仁地区','铜陵','铜川'],
	first_U:[],
	first_V:[],
	first_W:['芜湖','无锡','温州','武汉','潍坊','威海','乌兰察布','乌海','吴忠','梧州','乌鲁木齐','武威','渭南'],
	first_X:['厦门','咸阳','西安','湘潭','襄樊','许昌','新乡','徐州','仙桃','信阳','孝感','忻州','新余','西宁','咸宁','宣城','邢台','兴安盟','西双版纳傣族自治州','湘西土家族苗族自治州'],
	first_Y:['宜宾','营口','阳江','延安','岳阳','玉溪','延吉','宜昌','盐城','烟台','扬州','伊春','榆林','玉林','益阳','云浮','运城','宜春','鹰潭','永州','银川','阳泉','雅安','伊犁哈萨克自治州','延边朝鲜族自治州'],
	first_Z:['漳州','珠海','湛江','肇庆','中山','株洲','郑州','舟山','镇江','自贡','淄博','资阳','张家界','张家口','遵义','驻马店','中卫','周口','张掖','昭通','枣庄']
	};
var isIe=(document.all)?true:false;
function setSelectState(state){
	var objl=document.getElementsByTagName('select');
	for(var i=0;i<objl.length;i++){
		objl[i].style.visibility=state;
	}
}
function setCurrentCity(o,type,pic_id){
	try{
		document.getElementById('inhdlistpage').value=1;
		document.getElementById('labsetresideplace').style.display='';
		document.getElementById('labsetasresidereturn').innerHTML='您可以将这里保存为你的居住地';
	}catch(e){}
	try{
		document.getElementById('incpalbum').value=1;
		document.getElementById('resideprovince').value=o;
		var checkbox=document.forms['hold'].elements['box[]'];
		var allcheckpicsids=GetCheckboxValue(checkbox);
		if(allcheckpicsids==''){
			alert('请先选择图片!');
		}else{
			sp_hd_hold_drawpoint();
		}
	}catch(e){}
	try{
		if(type=='drive_end_city'){
			document.getElementById('drive_end_city').value=o;
		}else{
		document.getElementById('city').value=o;
		}
		try{
			document.getElementById('inplaceindex').value=1;
			setcity();
			}catch(e){}
	}catch(e){
		if(type=='reside'){
			document.getElementById('city_reside').value=o;
		}else if(type=='birth'){
			document.getElementById('city_birth').value=o;
		}else if(type=='resideprovince'){
			document.getElementById('resideprovince').value=o;
		}
	}
	var c=search_type(o);
	if(type=='drive_end_city'){
		document.getElementById('searchdrive_endcity').value=(c.split(','))[1];
	}else if(type=='resideprovince'){
		try{
			document.getElementById('inalbumpic').value=1;
			try{
				document.getElementById('ismulti').value=1;
				sp_hd_hold_drawpoint(pic_id);
			}catch(e){
				SetDragablePoint((c.split(','))[2],(c.split(','))[3]);
				if(pic_id>0){
					document.getElementById('currenteditpicid').value=pic_id;
					var thispicCityid='city_'+pic_id.toString();
					document.getElementById(thispicCityid).value=o;
					if(document.getElementById(thispicCityid).value){
						document.getElementById('actionpanel').style.display='';
						if(document.getElementById('modifiedpicids').value==''){
							document.getElementById('modifiedpicids').value=pic_id;
						}else{
							document.getElementById('modifiedpicids').value=document.getElementById('modifiedpicids').value+','+pic_id;
						}
						var thisPicCity='city_'+pic_id;
						document.getElementById(thisPicCity).value=o;
						document.getElementById('initcity').innerHTML=o;
						var x='x_'+pic_id.toString();
						var y='y_'+pic_id.toString();
						document.getElementById(x).value=(c.split(','))[2];
						document.getElementById(y).value=(c.split(','))[3];
					}else{
						if(document.getElementById('resideprovince').value==''){
							alert('请先选择省份!');
							return false;
						}
					}
				}
			}
		}catch(e){}
	}
	try{
		document.getElementById('citycode').value=(c.split(','))[1];
		if(type!='birth')
		movetocity((c.split(','))[2],(c.split(','))[3]);
		if(type!='drive_end_city'){
			try{
				setAllCode4MapSearch((c.split(','))[1]);
			}catch(e){}
		}
	}catch(e){}
	try{
		document.getElementById('resideprovince').value=document.getElementById('city').value;
		var province=document.getElementById('resideprovince').value;
		changesearchbar('eventlist',province);
	}catch(e){}
	try{
		document.getElementById('hit').value=o;
		province_escape=escape(o);
		var url_hd='do.php?ac=ajax&op=mainpagehd&city='+province_escape+'&viewnum=5&ajaxdiv=newesthd';
		var url_place='do.php?ac=ajax&op=mainpageplace&city='+province_escape+'&viewnum=5&ajaxdiv=newestplace';
		ajaxget(url_hd,'newesthd');
		ajaxget(url_place,'newestplace');
	}catch(e){}
	try{
		document.getElementById('inmappage').value='1';
		getWeatherInfo(unescape(o));
		if(type!='drive_end_city')
		document.getElementById('temp_drive_start').value=o;
	}catch(e){}
	try{
		document.getElementById('inmapdiypage').value=1;
		SetObjValue('diycitycode',(c.split(','))[1]);
		movetocity((c.split(','))[2],(c.split(','))[3]);
	}catch(e){}
	closeWindow();
}
function showMessageBox(wTitle,content,pos,wWidth,type){
	closeWindow();
	var bWidth=parseInt(document.documentElement.scrollWidth);
	var bHeight=parseInt(document.documentElement.clientHeight)>parseInt(document.documentElement.scrollHeight)?parseInt(document.documentElement.clientHeight):parseInt(document.documentElement.scrollHeight);
	if(isIe){setSelectState('hidden');}
	if(document.getElementById('back')==null){
		var back=document.createElement('div');
		back.id='back';
		var styleStr='top:0px;left:0px;position:absolute;background:#666;width:'+bWidth+'px;height:'+bHeight+'px;z-index:999;';
		styleStr+=(isIe)?'filter:alpha(opacity=40);':'opacity:0.40;';
		back.style.cssText=styleStr;
		document.body.appendChild(back);
	}else{document.getElementById('back').style.visibility='visible';}
	if(type=='birth'){
		if(document.getElementById('birthmesWindow')==null){
			var mesW=document.createElement('div');
			mesW.id='birthmesWindow';
			mesW.className='mesWindow';
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			try{
				document.getElementById('inCpProfile').value=1;
				styleStr="left:"+((bWidth-wWidth)/2)+"px;top:560"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			}catch(e){
				try{
					document.getElementById('inFriendFinder').value=1;
					styleStr="left:"+((bWidth-wWidth)/2)+"px;top:330"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
				}catch(e){}
			}
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}else{document.getElementById('birthmesWindow').style.visibility='visible';}
	}else if(type=='reside'){
		if(document.getElementById('residemesWindow')==null){
			var mesW=document.createElement('div');
			mesW.id="residemesWindow";
			mesW.className="mesWindow";
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			try{
				document.getElementById('inCpProfile').value=1;
				styleStr="left:"+((bWidth-wWidth)/2)+"px;top:560"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			}catch(e){
				try{
					document.getElementById('inFriendFinder').value=1;
					styleStr="left:"+((bWidth-wWidth)/2)+"px;top:330"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
				}catch(e){}
			}
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}else{document.getElementById('residemesWindow').style.visibility='visible';}
	}else if(type=='resideprovince'){
		if(document.getElementById('resideprovincemesWindow')==null){
			var mesW=document.createElement('div');
			mesW.id="resideprovincemesWindow";
			mesW.className="mesWindow";
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			try{
				document.getElementById('ctrlCityBoxTop').value=1;
				styleStr="left:"+((bWidth-wWidth)/2)+"px;top:58"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			}catch(e){}
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}else{
			document.getElementById('resideprovincemesWindow').outerHTML='';
			var mesW=document.createElement('div');
			mesW.id="resideprovincemesWindow";
			mesW.className="mesWindow";
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			try{
				document.getElementById('ctrlCityBoxTop').value=1;
				styleStr="left:"+((bWidth-wWidth)/2)+"px;top:58"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			}catch(e){}
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}
	}else if(type=='drive_end_city'){
		if(document.getElementById('drive_end_citymesWindow')==null){
			var mesW=document.createElement('div');
			mesW.id="drive_end_citymesWindow";
			mesW.className="mesWindow";
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}else{document.getElementById('drive_end_citymesWindow').style.visibility='visible';}
	}else{
		if(document.getElementById('mesWindow')==null){
			var mesW=document.createElement('div');
			mesW.id="mesWindow";
			mesW.className="mesWindow";
			mesW.innerHTML="<div class='mesWindowTop'>"+wTitle+"<div class='close'><a href=\"javascript:closeWindow();\"></a></div></div><div class='mesWindowContent' id='mesWindowContent'>"+content+"</div><div class='mesWindowBottom'></div>";
			styleStr="left:"+((bWidth-wWidth)/2)+"px;top:158"+"px;position:absolute;width:"+wWidth+"px;z-index:1000;";
			mesW.style.cssText=styleStr;
			document.body.appendChild(mesW);
		}else{document.getElementById('mesWindow').style.visibility='visible';}
	}
}
function showBackground(obj,endInt){
	obj.filters.alpha.opacity+=5;
	if(obj.filters.alpha.opacity<endInt){
		setTimeout(function(){showBackground(obj,endInt)},8);
	}
}
function closeWindow(){
	if(document.getElementById('back')!=null){
		document.getElementById('back').style.visibility='hidden';
	}
	try{
		if(document.getElementById('mesWindow')!=null){
			document.getElementById('mesWindow').style.visibility='hidden';
		}
	}catch(e){}
	try{
		if(document.getElementById('birthmesWindow')!=null){
			document.getElementById('birthmesWindow').style.visibility='hidden';
		}
	}catch(e){}
	try{
		if(document.getElementById('residemesWindow')!=null){
			document.getElementById('residemesWindow').style.visibility='hidden';
		}
	}catch(e){}
	try{
		if(document.getElementById('drive_end_citymesWindow')!=null){
			document.getElementById('drive_end_citymesWindow').style.visibility='hidden';
		}
	}catch(e){}
	try{
		if(document.getElementById('resideprovincemesWindow')!=null){
			document.getElementById('resideprovincemesWindow').style.visibility='hidden';
		}
	}catch(e){}
	if(isIe){setSelectState('');}
}
function citylistBox(type,picid){
	var messContent="<div><ul class=\"red\">";
	for(var h=0;h<citylist.hot_city.length;++h){
		if(type=='birth'){
			messContent+="<li><a href=\"javascript:setCurrentCity('" +citylist.hot_city[h]+"','birth')\">"+citylist.hot_city[h]+"</a></li>";
		}else if(type=='reside'){
			messContent+="<li><a href=\"javascript:setCurrentCity('"+citylist.hot_city[h]+"','reside')\">"+citylist.hot_city[h]+"</a></li>";
		}else if(type=='resideprovince'){
			messContent+="<li><a href=\"javascript:setCurrentCity('"+citylist.hot_city[h]+"','resideprovince','"+picid+"')\">"+citylist.hot_city[h]+"</a></li>";
		}else if(type=='drive_end_city'){
			messContent+="<li><a href=\"javascript:setCurrentCity('"+citylist.hot_city[h]+"','drive_end_city')\">"+citylist.hot_city[h]+"</a></li>";
		}else{
			messContent+="<li><a href=\"javascript:setCurrentCity('"+citylist.hot_city[h]+"')\">"+citylist.hot_city[h]+"</a></li>";
		}
	}
	messContent+='</ul><div class=hackbox></div>';
	cities=citylist.city;
	for(var t in cities){
		if(cities[t].length>0){
			messContent+="<ul><li class=\"import F14\"><strong>"+(t.split('_'))[1]+"</strong> </li>";
			for(var i=0;i<cities[t].length;++i){
				if(type=='birth'){
					messContent+="<li><a href=\"javascript:setCurrentCity('"+cities[t][i]+"','birth')\">"+cities[t][i]+"</a></li>";
				}else if(type=='reside'){
					messContent+="<li><a href=\"javascript:setCurrentCity('"+cities[t][i]+"','reside')\">"+cities[t][i]+"</a></li>";
				}else if(type=='resideprovince'){
					messContent+="<li><a href=\"javascript:setCurrentCity('"+cities[t][i]+"','resideprovince','"+picid+"')\">"+cities[t][i]+"</a></li>";
				}else if(type=='drive_end_city'){
					messContent+="<li><a href=\"javascript:setCurrentCity('"+cities[t][i]+"','drive_end_city')\">"+cities[t][i]+"</a></li>";
				}else{
					messContent+="<li><a href=\"javascript:setCurrentCity('"+cities[t][i]+"')\">"+cities[t][i]+"</a></li>";
				}
			}
			messContent+='</ul><div class=hackbox></div>';
		}
	}
	messContent+='</div>';
	showMessageBox('选择城市',messContent,0,700,type);
}
function search_type(value){
	var arrcities=(document.getElementById('hiddencitydata').innerHTML.split(','));
	var arr=arrcities.length;
	for(var i=0;i<arr;i++){
		if(value==arrcities[i]){	
			return arrcities[i]+','+arrcities[i+1]+','+arrcities[i+2]+','+arrcities[i+3];
		}else{
			var tempstr=null;
			tempstr=value.split(arrcities[i]);
			if(tempstr.length>1){
				return arrcities[i]+','+arrcities[i+1]+','+arrcities[i+2]+','+arrcities[i+3]+','+tempstr[1];
			}
		}
		i=i+4;
	}
	return '未知城市！';
}
//添加一个自动完成的模糊搜索
function autoCompleteCity(){
	var o=$('resideprovince').value;
	if(o==''){
		return false;
	}
	var allreturn='';
	var arrcities=(document.getElementById('hiddencitydata').innerHTML.split(','));
	var arr=arrcities.length;
	var existedcity='';
	for(var i=0;i<arr;i++){
		if(arrcities[i].indexOf(o)!=-1){
			if(existedcity.indexOf(arrcities[i])==-1){
				existedcity+=(arrcities[i]+' ');
				allreturn+=("<a href=\"javascript:;\" onclick=\"document.getElementById('resideprovince').value='"+arrcities[i]+"';\">"+arrcities[i]+'</a> ');
			}
		}
		i=i+4;
	}
	$('resideprovincetip').innerHTML=allreturn;
}
function getcitycodethroughcityname(cityname){
	var c=search_type(cityname);
	var citycode=(c.split(','))[1];
	return citycode;
}
function GetCitynameThroughCitycode(value){
	var arrcities=(document.getElementById('hiddencitydata').innerHTML.split(','));
	var arr=arrcities.length;
	for(var i=0;i<arr;i++){
		if(value==arrcities[i+1]){	
			return arrcities[i];
		}else{
			var tempstr=null;
			tempstr=value.split(arrcities[i+1]);
			if(tempstr.length>1){
				return arrcities[i];
			}
		}
		i=i+4;
	}
} 
