/**
 * 国家省份和城市的三级联动选择，本脚本中显示文本和value都是一样的值
 * 使用方法：
 * 1.用于新建页面
 * <body onload="init(n_id,p_id,c_id)"> 其中，n_id是中国或洲select元素的id的值，p_id是中国省份或外国城市select元素的id的值，c_id是城市select元素的id值
 * <select id="province" onchange="selectn_id(this,p_id,c_id)">
 * <select id="nation" onchange="selectp_id(this,c_id)">
 * 2.用于修改页面
 * <body onload="initEdit(n_id,p_id,c_id,n_value,p_value,c_value)"> 其中，n_id是国家select元素的id的值，p_id是省份select元素的id的值，c_id是城市select元素的id值,n_value是省的值,p_value是省的值,c_value是城市的值
 * <select id="province" onchange="selectn_id(this,p_id,c_id)">
 * <select id="nation" onchange="selectp_id(this,c_id)">
**/
var where = new Array(100); 
function comefrom(loca,locacity) { this.loca = loca; this.locacity = locacity; }  
/*1到34 是中国的城市*/
where[0]= new comefrom("请选择","请选择"); 
where[1] = new comefrom("北京","请选择|北京"); 
where[2] = new comefrom("上海","请选择|上海"); 
where[3] = new comefrom("天津","请选择|天津"); 
where[4] = new comefrom("重庆","请选择|重庆"); 
where[5] = new comefrom("河北","请选择|石家庄|邯郸|邢台|保定|张家口|承德|廊坊|唐山|秦皇岛|沧州|衡水|迁安|任丘"); 
where[6] = new comefrom("山西","请选择|太原|大同|阳泉|长治|晋城|朔州|吕梁|忻州|晋中|临汾|运城|介休|平遥|永济"); 
where[7] = new comefrom("内蒙古","请选择|呼和浩特|包头|巴彦淖尔|乌海|赤峰|通辽|呼伦贝尔|阿拉善盟|鄂尔多斯|兴安盟|乌兰察布|锡林郭勒盟|锡林浩特|满洲里"); 
where[8] = new comefrom("辽宁","请选择|沈阳|大连|鞍山|抚顺|本溪|丹东|锦州|营口|阜新|辽阳|盘锦|铁岭|朝阳|葫芦岛|兴城"); 
where[9] = new comefrom("吉林","请选择|长春|吉林|四平|辽源|通化|白山|松原|白城|延边|珲春"); 
where[10] = new comefrom("黑龙江","请选择|哈尔滨|齐齐哈尔|牡丹江|佳木斯|大庆|绥化|鹤岗|鸡西|黑河|双鸭山|伊春|七台河|大兴安岭|绥芬河"); 
where[11] = new comefrom("江苏","请选择|南京|镇江|苏州|南通|扬州|盐城|徐州|连云港|常州|无锡|宿迁|泰州|淮安|常熟|丹阳|东台|高邮|海安|海门|江都|江阴|姜堰|金坛|靖江|昆山|溧阳|启东|如皋|泗阳县|太仓|泰兴|同里|吴江|新沂|盱眙|扬中|宜兴|张家港|周庄"); 
where[12] = new comefrom("浙江","请选择|杭州|宁波|温州|嘉兴|湖州|绍兴|金华|衢州|舟山|台州|丽水|桐乡|慈溪|奉化|富阳|海宁|东阳|嘉善|建德|兰溪|乐清|临安|临海|平湖|千岛湖|瑞安|上虞|义乌|永康|余姚"); 
where[13] = new comefrom("安徽","请选择|合肥|芜湖|蚌埠|马鞍山|淮北|铜陵|安庆|黄山|滁州|宿州|池州|淮南|巢湖|阜阳|六安|宣城|亳州|宁国|天柱山|桐城"); 
where[14] = new comefrom("福建","请选择|福州|厦门|莆田|三明|泉州|漳州|南平|龙岩|宁德|福鼎|福清|晋江|连城|石狮"); 
where[15] = new comefrom("江西","请选择|南昌市|景德镇|九江|鹰潭|萍乡|新余|赣州|吉安|宜春|抚州|上饶|井岗山|德兴|庐山|婺源"); 
where[16] = new comefrom("山东","请选择|济南|青岛|淄博|枣庄|东营|烟台|潍坊|济宁|泰安|威海|日照|莱芜|临沂|德州|聊城|滨州|菏泽|肥城|海阳|即墨|胶南|胶州|莱西|龙口|蓬莱|青州|曲阜|荣成|寿光|文登|兖州"); 
where[17] = new comefrom("河南","请选择|郑州|开封|洛阳|平顶山|安阳|鹤壁|新乡|焦作|濮阳|许昌|漯河|三门峡|南阳|商丘|信阳|周口|驻马店|济源|登封|林州|新密"); 
where[18] = new comefrom("湖北","请选择|武汉|宜昌|荆州|襄樊|黄石|荆门|黄冈|十堰|恩施|潜江|天门|仙桃|随州|咸宁|孝感|鄂州|神农架|应城|赤壁|大冶|钟祥"); 
where[19] = new comefrom("湖南","请选择|长沙|常德|株洲|湘潭|衡阳|岳阳|邵阳|益阳|娄底|怀化|郴州|永州|湘西|张家界|凤凰县|吉首|浏阳|韶山"); 
where[20] = new comefrom("广东","请选择|广州|深圳|珠海|汕头|东莞|中山|佛山|韶关|江门|湛江|茂名|肇庆|惠州|梅州|汕尾|河源|阳江|清远|潮州|揭阳|云浮|开平|汕尾|台山"); 
where[21] = new comefrom("广西","请选择|南宁|柳州|桂林|梧州|北海|防城港|钦州|贵港|玉林|贺州|百色|河池|龙胜|兴安|阳朔"); 
where[22] = new comefrom("海南","请选择|海口|三亚|琼海|万宁|文昌|五指山|东方|临高|陵水|儋州|昌江|乐东|保亭|安定县|博鳌"); 
where[23] = new comefrom("四川","请选择|成都|绵阳|德阳|自贡|攀枝花|广元|内江|乐山|南充|宜宾|广安|达州|雅安|眉山|甘孜|凉山|泸州|阿坝藏族羌族自治州|遂宁|巴中|资阳|都江堰|峨眉山|江油|阆中|邛崃|西昌"); 
where[24] = new comefrom("贵州","请选择|贵阳|六盘水|遵义|安顺|铜仁|黔西南|毕节|黔东南|黔南|都匀|凯里|荔波|兴义"); 
where[25] = new comefrom("云南","请选择|昆明|大理|曲靖|玉溪|昭通|楚雄|红河|文山|普洱|西双版纳|保山|德宏|丽江|怒江|迪庆|临沧"); 
where[26] = new comefrom("西藏","请选择|拉萨|日喀则|山南|林芝|昌都|阿里|那曲"); 
where[27] = new comefrom("陕西","请选择|西安|宝鸡|咸阳|铜川|渭南|延安|榆林|汉中|安康|商洛|华阴"); 
where[28] = new comefrom("甘肃","请选择|兰州|嘉峪关|金昌|白银|天水|酒泉|张掖|武威|定西|陇南|平凉|庆阳|临夏|甘南|敦煌"); 
where[29] = new comefrom("宁夏","请选择|银川|石嘴山|吴忠|固原|中卫"); 
where[30] = new comefrom("青海","请选择|西宁|海东|海南|海北|黄南|玉树|果洛|海西"); 
where[31] = new comefrom("新疆","请选择|乌鲁木齐|石河子|克拉玛依|伊犁|巴音郭勒|昌吉|克孜勒苏柯尔克孜|博尔塔拉|吐鲁番|哈密|喀什|和田|阿克苏|阿勒泰|塔城|库尔勒"); 
where[32] = new comefrom("香港","请选择|香港"); 
where[33] = new comefrom("澳门","请选择|澳门"); 
where[34] = new comefrom("台湾","请选择|台北|高雄|台中|台南|屏东|南投|云林|新竹|彰化|苗栗|嘉义|花莲|桃园|宜兰|基隆|台东|金门|马祖|澎湖"); 

where[35] = new comefrom("爱尔兰","请选择|都柏林"); 
where[36] = new comefrom("奥地利","请选择|维也纳|格拉茨|茵斯布鲁克|萨尔茨堡|哈尔施塔特"); 
where[37] = new comefrom("比利时","请选择|布鲁塞尔|安特卫普"); 
where[38] = new comefrom("冰岛","请选择|雷克亚未克"); 
where[39] = new comefrom("丹麦","请选择|哥本哈根"); 
where[40] = new comefrom("德国","请选择|柏林|法兰克福|慕尼黑|汉堡|科隆"); 
where[41] = new comefrom("法国","请选择|巴黎|马赛|戛纳|波尔多|普罗旺斯埃克斯|里昂|卡尔卡松|尼斯"); 
where[42] = new comefrom("梵蒂冈","请选择|梵蒂冈"); 
where[43] = new comefrom("芬兰","请选择|赫尔辛基|罗凡涅米"); 
where[44] = new comefrom("荷兰","请选择|阿姆斯特丹|鹿特丹|海牙|乌特勒支|马斯特里赫特"); 
where[45] = new comefrom("捷克","请选择|布拉格"); 
where[46] = new comefrom("马耳他","请选择|瓦莱塔"); 
where[47] = new comefrom("挪威","请选择|奥斯陆|卑尔根"); 
where[48] = new comefrom("俄罗斯","请选择|莫斯科|圣彼得堡|弗拉基米尔|苏兹达里"); 
where[49] = new comefrom("瑞典","请选择|斯德哥尔摩"); 
where[50] = new comefrom("瑞士","请选择|伯尔尼|苏黎世|日内瓦|洛桑|采尔马特|蒙特勒|因特拉肯|卢塞恩|沙芙豪森"); 
where[51] = new comefrom("土耳其","请选择|安卡拉|安塔利亚|伊斯坦布尔|伊兹密尔"); 
where[52] = new comefrom("西班牙","请选择|马德里|巴塞罗那|巴斯克|科尔多瓦|塞维利亚|格拉纳达"); 
where[53] = new comefrom("希腊","请选择|雅典|奥林匹亚|米科诺斯岛|圣托里尼岛 ");
where[54] = new comefrom("意大利","请选择|罗马|威尼斯|佛罗伦萨|米兰|庞贝|那不勒斯|维罗纳");
where[55] = new comefrom("英国","请选择|伦敦|牛津|剑桥|曼彻斯特|巴斯|爱丁堡|约克|贝尔法斯特|格拉斯哥");

where[56] = new comefrom("阿联酋","请选择|迪拜");
where[57] = new comefrom("朝鲜","请选择|平壤");
where[58] = new comefrom("菲律宾","请选择|马尼拉|长滩岛|佬沃|宿雾|巴拉望");
where[59] = new comefrom("韩国","请选择|首尔|庆州|釜山|光州|济州岛");
where[60] = new comefrom("柬埔寨","请选择|金边|西哈努克|暹粒-吴哥窟");
where[61] = new comefrom("马来西亚","请选择|吉隆坡| 槟城|兰卡威|马六甲|热浪岛|沙巴|沙捞越|停泊岛");
where[62] = new comefrom("马尔代夫","请选择|马累");
where[63] = new comefrom("缅甸","请选择|仰光|曼德勒|蒲甘|茵莱湖");
where[64] = new comefrom("尼泊尔","请选择|博卡拉|加德满都|奇旺");
where[65] = new comefrom("日本","请选择|东京|大阪|冲绳|长崎|京都|名古屋|神户|札幌");
where[66] = new comefrom("斯里兰卡","请选择|科伦坡");
where[67] = new comefrom("泰国","请选择|曼谷|芭堤雅|华欣七岩|甲米|皮皮岛|普吉岛|清莱|清迈|苏梅岛");
where[68] = new comefrom("汶莱","请选择|斯里巴加湾市");
where[69] = new comefrom("新加坡","请选择|新加坡|圣淘沙");
where[70] = new comefrom("印度","请选择|新德里|阿格拉|瓜里尔|克久拉霍|孟买|斋普尔");
where[71] = new comefrom("越南","请选择|胡志明市|河内|海防|顺化|会安|芽庄");
where[72] = new comefrom("印度尼西亚","请选择|雅加达|龙目岛|民丹岛|日惹|巴厘岛");
where[73] = new comefrom("以色列","请选择|特拉维夫|耶路撒冷");
where[74] = new comefrom("约旦","请选择|伊尔比德|安曼|亚喀巴");

where[75] = new comefrom("加拿大","请选择|渥太华|温哥华|维多利亚|多伦多|蒙特利尔");
where[76] = new comefrom("美国","请选择|旧金山|芝加哥|迈阿密|奥兰多|洛杉矶|纽约|拉斯维加斯|北马里亚纳群岛|塞班岛|波士顿|天宁岛");

where[77] = new comefrom("澳大利亚","请选择|凯恩斯|布里斯班|黄金海岸|悉尼|堪培拉|墨尔本阿德莱德 |弗里曼特尔|珀斯");
where[78] = new comefrom("斐济","请选择|苏瓦|南迪");
where[79] = new comefrom("新西兰","请选择|惠灵顿|奥克兰|罗托鲁瓦|基督城|皇后镇|但尼丁");

where[80] = new comefrom("埃及","请选择|开罗|阿斯旺|卢克索|孟菲斯");
where[81] = new comefrom("埃塞俄比亚","请选择|埃塞俄比亚");
where[82] = new comefrom("刚果民主共和国","请选择|刚果民主共和国");
where[83] = new comefrom("肯尼亚","请选择|内罗毕|马塞马拉|纳库鲁");
where[84] = new comefrom("毛里求斯","请选择|毛里求斯");
where[85] = new comefrom("南非","请选择|开普敦|约翰内斯堡");
where[86] = new comefrom("塞舌尔","请选择|塞舌尔");
where[87] = new comefrom("坦桑尼亚","请选择|坦桑尼亚");
where[88] = new comefrom("突尼斯","请选择|突尼斯");
where[89] = new comefrom("津巴布韦","请选择|哈拉雷");
where[90] = new comefrom("摩洛哥","请选择|摩洛哥");
where[91] = new comefrom("赞比亚","请选择|赞比亚");

where[92] = new comefrom("阿根廷","请选择|布宜诺斯艾利斯");
where[93] = new comefrom("巴西","请选择|圣保罗|里约热内卢|依瓜苏");
where[94] = new comefrom("古巴","请选择|哈瓦那");
where[95] = new comefrom("加拿大","请选择|温哥华|多伦多|尼亚加拉大瀑布|渥太华|蒙特利尔");
where[96] = new comefrom("秘鲁","请选择|秘鲁");
where[97] = new comefrom("墨西哥","请选择|墨西哥城");
where[98] = new comefrom("委内瑞拉","请选择|委内瑞拉");
where[99] = new comefrom("智利","请选择|智利");

var where1 = new Array(7); 
function comefrom(loca,locacity) { this.loca = loca; this.locacity = locacity; }  
where1[0]= new comefrom("请选择","请选择"); 
where1[1] = new comefrom("中国","请选择|北京|上海|天津|重庆|河北|山西|内蒙古|辽宁|吉林|黑龙江|江苏|浙江|安徽|福建|江西|山东|河南|湖北|湖南|广东|广西|海南|四川|贵州|云南|西藏|陕西|甘肃|宁夏|青海|新疆|香港|澳门|台湾");  
where1[2] = new comefrom("欧洲","请选择|爱尔兰|奥地利|比利时|冰岛|丹麦|德国|法国|梵蒂冈|芬兰|荷兰|捷克|马耳他|挪威|俄罗斯|瑞典|瑞士|土耳其|西班牙|希腊|意大利|英国"); 
where1[3] = new comefrom("亚洲","请选择|阿联酋|朝鲜|菲律宾|韩国|柬埔寨|马来西亚|马尔代夫|缅甸|尼泊尔|日本|斯里兰卡|泰国|汶莱|新加坡|印度|越南|印度尼西亚|以色列|约旦");
where1[4] = new comefrom("大洋洲","请选择|澳大利亚|斐济|新西兰");
where1[5] = new comefrom("美洲","请选择|加拿大|美国|阿根廷|巴西|古巴|加拿大|秘鲁|墨西哥|委内瑞拉|智利");
where1[6] = new comefrom("非洲","请选择|埃及|埃塞俄比亚|刚果民主共和国|肯尼亚|毛里求斯|南非|塞舌尔|坦桑尼亚|突尼斯|津巴布韦|摩洛哥|赞比亚");

  
function selectn_id(obj,p_id,c_id) { 
    var n_value = obj.value;    
    var province = document.getElementById(p_id); 
	
    for(i = 0;i < where1.length;i ++) 
	{ 
        if (where1[i].loca == n_value) { 
            provinces = (where1[i].locacity).split("|");             
            for(j = 0;j < provinces.length;j++) {
             province.options.length = provinces.length; 
             province.options[j].text = provinces[j]; 
             province.options[j].value = provinces[j];
            }
        }         
    }
	province.options[0].selected = true;
	
	var city = document.getElementById(c_id);
	var len = city.options.length;  
	for(var c = len;c > 0;c--) 
	{ 
        city.remove(c);
    } 
	
}
function selectp_id(obj,c_id) { 
    var p_value = obj.value;    
    var city = document.getElementById(c_id); 
    city.options.selectedIndex = 0;
    for(var i = 0;i < where.length;i ++) { 
        if (where[i].loca == p_value) { 
            cities = (where[i].locacity).split("|");             
            for(j = 0;j < cities.length;j++) {
             city.options.length = cities.length; 
             city.options[j].text = cities[j]; 
             city.options[j].value = cities[j];
            }
        }         
    }
    city.options[0].selected = true;    
} 
function init(n_id,p_id,c_id) { 
    var nation = document.getElementById(n_id); 
    var province = document.getElementById(p_id); 
	var city = document.getElementById(c_id);     
    with(nation) { 
        length = where1.length; 
        for(k=0;k<where1.length;k++) { 
        	options[k].text = where1[k].loca; 
        	options[k].value = where1[k].loca; 
        } 
        options.selectedIndex=0;        
    } 
    with(province) { 
        cities = (where1[0].locacity).split("|"); 
        length = cities.length; 
        for(l=0;l<length;l++) { 
        	options[l].text = cities[l]; 
        	options[l].value = cities[l]; 
        } 
        options.selectedIndex = 0;
    }
	 with(city) { 
        cities = (where1[0].locacity).split("|"); 
        length = cities.length; 
        for(l=0;l<length;l++) { 
        	options[l].text = cities[l]; 
        	options[l].value = cities[l]; 
        } 
        options.selectedIndex = 0; 
    }
} 
function initEdit(n_id,p_id,c_id,n_value,p_value,c_value) {
	var nation = document.getElementById(n_id);
    var province = document.getElementById(p_id); 
    var city = document.getElementById(c_id);
    var selected=0;
	with(nation) { 
        length = where1.length; 
        for(k=0;k<where1.length;k++) { 
         options[k].text = where1[k].loca; 
         options[k].value = where1[k].loca; 
         if(n_value==where1[k].loca){
          options[k].selected=true;
          selected=k;
         }
        }       
    } 
    with(province) 
	{ 
 
		
		for(i = 0;i < where1.length;i ++) 
		{ 
			if (where1[i].loca == n_value) 
			{ 
				cities = (where1[i].locacity).split("|");             
				for(j = 0;j < cities.length;j++) 
				{
				 province.options.length = cities.length; 
				 province.options[j].text = cities[j]; 
				 province.options[j].value = cities[j];
				  if(p_value==cities[j])
				  {
					options[j].selected=true;
					selected=j;
				   }
				}
			}        
    	} 
		for(k=0;k<where.length;k++) 
		{ 

			 if(p_value==where[k].loca){
			 selected=k;}
		 }          
    }
	
	 
    with(city) { 
        cities = (where[selected].locacity).split("|"); 
        length = cities.length; 
        for(l=0;l<length;l++) { 
         options[l].text = cities[l]; 
         options[l].value = cities[l]; 
         if(c_value==cities[l]){
          options[l].selected=true;
         }
        } 
        //options[selectedIndex].text = cities[0]; options[selectedIndex].value = cities[0]; 
       
    }
} 


function initEditcity(n_id,p_id,c_id,n_value,p_value,c_value) {
    var nation = document.getElementById(n_id);
    var province = document.getElementById(p_id); 
    var city = document.getElementById(c_id);
    var selected=0;
    alert(where1.length);
	with(nation) { 
		alert(where1.length);
        for(k=0;k<where1.length;k++) { 
         options[k].text = where1[k].loca; 
         options[k].value = where1[k].loca; 
         if(n_value==where1[k].loca){
          options[k].selected=true;
          selected=k;
         }
       }       
    } 
    with(province) 
	{ 	
		for(i = 0;i < where1.length;i ++) 
		{ 
			if (where1[i].loca == n_value) 
			{ 
				cities = (where1[i].locacity).split("|");             
				for(j = 0;j < cities.length;j++) 
				{
				 province.options.length = cities.length; 
				 province.options[j].text = cities[j]; 
				 province.options[j].value = cities[j];
				  if(p_value==cities[j])
				  {
					options[j].selected=true;
					selected=j;
				   }
				}
			}        
    	} 
		for(k=0;k<where.length;k++) 
		{ 
			 if(p_value==where[k].loca){
			 selected=k;}
		 }          
    }
    with(city) { 
        cities = (where[selected].locacity).split("|"); 
        length = cities.length; 
        for(l=0;l<length;l++) { 
         options[l].text = cities[l]; 
         options[l].value = cities[l]; 
         if(c_value==cities[l]){
          options[l].selected=true;
         }
         else{
         	 options[selectedIndex].text = c_value;
         	 options[selectedIndex].value = c_value
         }
       } 
    }
    
} 


function initProvince(p_id,selected) { 
    var province = document.getElementById(p_id);     
    with(province) { 
        length = where.length; 
        for(k=0;k<where.length;k++) { 
         options[k].text = where[k].loca; 
         options[k].value = where[k].loca; 
         if(selected.length>0){
          if(selected==where[k].loca){
           options[k].selected=true;
          }
         }
        } 
        options[selectedIndex].text = where[0].loca; 
        options[selectedIndex].value = where[0].loca; 
    }     
} 
