var CityInfos = [
	{"id":"0","name":"全国站","url":"http://www.eastpiao.com"},		 
	{"id":"1","name":"广州","url":"http://gz.eastpiao.com"},		 
	{"id":"2","name":"中山","url":"http://zs.eastpiao.com"},		 
	{"id":"3","name":"佛山","url":"http://fs.eastpiao.com"},		 
	{"id":"4","name":"香港","url":"http://hk.eastpiao.com"},		 
	{"id":"5","name":"澳门","url":"http://mo.eastpiao.com"},		 
];

function getCityInfo () {
	var domain = location.host;
	//alert("开始获取城市信息："+domain);
	var cityId = 1;
	if(domain.indexOf("www.eastpiao.com") != -1){
		cityId = 1;
	}else if (domain.indexOf("zs.eastpiao.com") != -1) {
		cityId = 2;
	}else if (domain.indexOf("zs.eastpiao.com") != -1) {
		cityId = 3;
	}else if (domain.indexOf("fs.eastpiao.com") != -1) {
		cityId = 4;
	}else if (domain.indexOf("hk.eastpiao.com") != -1) {
		cityId = 5;
	}else if (domain.indexOf("mo.eastpiao.com") != -1) {
		cityId = 6;
	}
	else{
		cityId = getCookie("city");
		//alert("Cookie ID："+ cityId);
		if(cityId <= 1){
			if(typeof(Account) != 'undefined' && Account.cityId > 0){
				cityId = Account.cityId;
			}
			//如果没获取到城市ID,则再主动向服务器请求一次
			else{
				var act = doGet("/userCityInfo.asp?"+Math.random());
				//alert("ajax返回信息："+act);
				eval(act);
				//如果服务器返回的信息中包含了城市ID,则取该城市ID
				if(typeof(Account) != 'undefined' && Account.cityId > 0){
					cityId = Account.cityId;
				}
			}
		}
	}
	//如果城市ID还未取到,则默认为广州
	if(cityId <= 1)
		cityId = 1;
	//alert("最后的城市ID:"+cityId);
	return cityId;
}


function getCookie(Name){
	var search = Name + "=";
	if(document.cookie.length > 0){
		offset = document.cookie.indexOf(search);
		//alert("第二次访问开始检测城市city的Cookie。\n search="+search);
		//alert("cookie中的内容："+document.cookie);
		//alert("是否存在city的cookie："+offset);
		if(offset != -1){
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if(end == -1) 
				end = document.cookie.length;
			//alert("城市的Cookie："+unescape(document.cookie.substring(offset, end)));
			return unescape(document.cookie.substring(offset, end));
		}
		else return ""
	}
}

/**
 * 写入cookie
 */
function rememberCity () {
	var domain = location.host;
	var cityId = 1;
	if(domain.indexOf("www.eastpiao.com") != -1){
		cityId = 1;
	}else if(domain.indexOf("gz.eastpiao.com") != -1){
		cityId = 2;
	}else if (domain.indexOf("zs.eastpiao.com") != -1) {
		cityId = 3;
	}else if (domain.indexOf("fs.eastpiao.com") != -1) {
		cityId = 4;
	}else if (domain.indexOf("hk.eastpiao.com") != -1) {
		cityId = 5;
	}else if (domain.indexOf("mo.eastpiao.com") != -1) {
		cityId = 6;
	}
	if(cityId >= 1){
		expire = "";
		expire = new Date(new Date().getTime() + 30*24*60*60*1000);
		expire = "; expires=" + expire.toGMTString();
		//alert("过期时间："+(expire));
		document.cookie = "city="+cityId+ expire+"; domain=.eastpiao.com; ";
		//alert("写入citycookie："+document.cookie);
	}
}

function switchSite (){
	var city = getCityInfo();
	var domain = location.host; 
	if(domain.indexOf("www.eastpiao.com") == -1 && domain.indexOf("gz.eastpiao.com") == -1 && domain.indexOf("zs.eastpiao.com") == -1 && domain.indexOf("fs.eastpiao.com") == -1 && domain.indexOf("hk.eastpiao.com") == -1 && domain.indexOf("mo.eastpiao.com") == -1) {
	if(city == 1){
		document.location = "http://www.eastpiao.com";
	}else if(city == 2){
		document.location = "http://gz.eastpiao.com";
	}else if (city == 3){
		document.location = "http://zs.eastpiao.com";
	}else if (city == 4){
		document.location = "http://fs.eastpiao.com";
	}else if (city == 5){
		document.location = "http://hk.eastpiao.com";
	}else if (city == 6){
		document.location = "http://mo.eastpiao.com";
	}
	}
}

function showCityInfo(id){
	//alert("显示分站点城市列表");
	var CityAreas = [];
	var index = 0;
	for(var i=0 ; i < CityInfos.length; i++){
		CityAreas[index] = CityInfos[i];	
		index++;
	}
	//alert("显示分站点城市列表:测试一");

	var x = {"CityAreas":CityAreas};
	$("top_city_box").innerHTML = TrimPath.processDOMTemplate("tpltCityInfo", x);
}

