﻿
var area_1 = new Array();
area_1.push(["全国",["北京","上海","天津","广东","浙江","江苏","山东","四川","重庆","福建","湖北","湖南","江西","河南","河北","辽宁","安徽","广西","陕西","云南","黑龙江","山西","吉林","贵州","甘肃","内蒙古","西藏","宁夏","青海","新疆","海南","香港","澳门","台湾","其他"]]);

var area_2 = new Array();

	area_2.push(["广东",["广州","深圳","珠海","汕头","惠州","东莞","中山","佛山","湛江","云浮","从化","揭阳","梅州","肇庆","汕尾","韶关","番禺","茂名","潮阳","江门","三水","河源","高明","清远","潮州","增城","阳江","南海"]]);
	area_2.push(["浙江",["杭州","宁波","嘉兴","湖州","绍兴","金华","衢州","舟山","温州","台州","嵊州","丽水"]]);
	area_2.push(["江苏",["南京","徐州","连云港","淮安","宿迁","盐城","扬州","南通","镇江","常州","无锡","苏州","常熟","准阴","淮阴","泰州","张家港"]]);
	area_2.push(["山东",["济南","青岛","淄博","潍坊","烟台","威海","日照","德州","滨州","泰安","东营","济宁","聊城","莱芜","枣庄","临沂","菏泽"]]);
	area_2.push(["四川",["成都","攀枝花","德阳","绵阳","自贡","内江","乐山","泸州","宜宾","雅安","甘孜","阿坝","康定","马尔康","涪陵","达州","西昌","遂宁","资阳","凉山","广安","广元","达川","眉山","巴中","南充"]]);
	area_2.push(["重庆",["黔江","重庆","万州","涪陵"]]);
	area_2.push(["福建",["福州","厦门","三明","莆田","泉州","漳州","南平","宁德","龙岩"]]);
	area_2.push(["湖北",["武汉","襄樊","十堰","宜昌","荆门","孝感","黄岗","恩施","江汉","咸宁","天门","江陵","荆州","黄石","鄂州","随州"]]);
	area_2.push(["湖南",["长沙","湘潭","衡阳","岳阳","常德","郴州","益阳","怀化","张家界","邵阳","吉首","娄底","安阳","永州","自治州","株洲"]]);
	area_2.push(["江西",["南昌","景德镇","新余","九江","鹰潭","上饶","宜春","吉安","赣州","抚州","萍乡"]]);
	area_2.push(["河南",["郑州","开封","洛阳","新乡","濮阳","商丘","南阳","周口","鹤壁","安阳","焦作","潢川","信阳","驻马店","三门峡","许昌","漯河","平顶山","巩义"]]);
	area_2.push(["河北",["石家庄","邯郸","邢台","保定","张家口","承德","唐山","秦皇岛","沧州","廊坊","衡水"]]);
	area_2.push(["辽宁",["沈阳","大连","鞍山","抚顺","本溪","丹东","锦州","营口","阜新","辽阳","铁岭","盘锦","葫芦岛","朝阳","锦西"]]);
	area_2.push(["安徽",["合肥","蚌埠","马鞍山","安庆","黄山","宿州","巢湖","阜阳","毫州","铜陵","宣城","宿县","芜湖","六安","滁州","淮北","池州","淮南"]]);
	area_2.push(["广西",["南宁","柳州","桂林","北海","梧州","钦州","防城港","玉林","河池","防城","贵港","百色","贺州"]]);
	area_2.push(["陕西",["西安","铜川","宝鸡","渭南","商州","商洛","延安","榆林","汉中","咸阳","安康"]]);
	area_2.push(["云南",["昆明","昭通","曲靖","思茅","丽江","楚雄","德宏","玉溪","版纳","红河","景洪","六库","文山","香格里拉","大理","保山","中甸","迪庆","潞西","个旧","迪庆州","临沧","怒江"]]);
	area_2.push(["黑龙江",["哈尔滨","齐齐哈尔","大庆","伊春","牡丹江","佳木斯","绥化","黑河","鸡西","七台河","双鸭山","鹤岗","大兴安岭"]]);
	area_2.push(["山西",["太原","大同","阳泉","长治","朔州","榆次","临汾","运城","离石","晋中","忻州","晋城","吕梁"]]);
	area_2.push(["吉林",["长春","吉林","四平","辽源","通化","延吉","珲春","梅河口","白城","白山","松源","延边","松原"]]);
	area_2.push(["贵州",["贵阳","遵义","安顺","六盘水","铜仁","黔东南","兴义","凯里","毕节","黔南","都匀","黔西南"]]);
	area_2.push(["甘肃",["兰州","金昌","天水","平凉","临夏","白银","陇南","定西","张掖","嘉峪关","酒泉","武威","庆阳","甘南州"]]);
	area_2.push(["内蒙古",["呼和浩特","包头","通辽","乌兰浩特","临河","海拉尔","阿拉善左","乌海","集宁","赤峰","鄂尔多斯","锡林浩特","东胜","科尔沁翼中旗","巴彦浩特","阿拉善左旗"]]);
	area_2.push(["西藏",["拉萨","日喀则","阿里","那曲","山南","林芝","泽当","噶尔","昌都"]]);
	area_2.push(["宁夏",["银川","石嘴山","银北","石咀山","银南","吴忠","固原"]]);
	area_2.push(["青海",["西宁","平安","格尔木","玛沁","海东","玉树","共和","海南","黄南","海北","德令哈","海西","果洛","同仁","门源","海晏"]]);
	area_2.push(["新疆",["乌鲁木齐","克拉玛依","吐鲁番","喀什","阿图什","库尔勒","伊犁","和田","奎屯","哈密","博乐","塔城","博州","阿克苏","阿勒泰","昌吉","伊宁","石河子","克州","咯会"]]);
	area_2.push(["海南",["海口","三亚","儋州","海南"]]);
	area_2.push(["香港",["香港"]]);
	area_2.push(["澳门",["澳门"]]);
	area_2.push(["台湾",["台北"]]);
	area_2.push(["其他",["其他"]]);


$.plug.city = new $.create();
$.plug.city.prototype = {
	init:function(){
		this.childs = [];
		this.values = [];
		this.num = 0;
		this.showType = "undefined";
	},
	showMethod:function(){
		var frame = document.getElementById("_iframe_bg");
		if((navigator.appVersion.indexOf('MSIE') != -1) && (parseFloat(navigator.appVersion.substr(navigator.appVersion.indexOf('MSIE')+5,3))) <= 6 && frame){
			var dis = frame.style.display;
				dis = dis != "none" ? "none" : "block";
				frame.style.display = dis;
		}
		this.showFn(this.showType || "");
		this.showType = "undefined";
	},
	addShowFn:function(fn){
		this.showFn = fn;
	},
	setChild:function(id,datas,fns){
		var len = this.childs.length;
		this.childs.push(new $.plug.city.child(id,datas,len,this,fns));
		this.num++;
	},
	getPre:function(n){
		var m = (n - 1)>=0 ? n - 1 : null;
		return this.childs[m];
	},
	getNext:function(n){
		return this.childs[n+1] || null;
	},
	getValues:function(){
		return this.values;
	}
};
$.plug.city.child = new $.create();
$.plug.city.child.prototype = {
	init:function(id,datas,level,obj,fns){
		this.objCity = obj;
		this.level = level;
		this.dom = typeof id == "string" ? document.getElementById(id) : id ;
		this.data = datas;
		this.value = "";
		for(var p in fns){
			this[p] = fns[p];
		}
	},
	hasValue:function(value){
		for(var i=0;i<this.data.length;i++){
			if(this.data[i][0] == value){
				return true;
			}
		}
		return false;
	},
	upData:function(value,datas){
		this.data.push([value,datas]);
	},
	getValue:function(){
		return this.dom.value;
	},
	setValue:function(){
		this.objCity.values[this.level] = this.dom.value;
	},
	fire:function(value){
		var obj = this.objCity,next = obj.getNext(this.level),i = this.level+1,len = obj.values.length;
			obj.values[this.level] = value;
			this.dom.value = value;
			for(i;i<len;i++){
				obj.values[i] = "";
			}
		if(next != null){
			next.create(value);
		}
		this.showValues();
	},
	create:function(key){
		var i,len = this.data.length;
		var next = this.objCity.getNext(this.level);
		if(!this.hasValue(key)){
			this._remove();
			return;
		}
		for(i=0;i<len;i++){
			if(this.data[i][0] == key){
				this._remove();
				this.objCity.values[this.level-1] = key;
				this._template(this.data[i][1]);
				break;
			}
		}
		if(next != null){
			next.create(this.getValue());
		}else{
			this.setValue();
		}
	},
	_template:function(citys){
		this.template(citys);
	},
	template:function(citys){
		var dom = this.dom,o=this,len=citys.length;
		dom.style.display = "";
		for(var i= 0;i<len;i++){
			dom.options[i] = new Option(citys[i],citys[i]);
		}
		this.setValue();
		dom.onchange = function(){
			o.fire(this.value);
		};
	},
	_remove:function(){
		var next = this.objCity.getNext(this.level);
		this.remove();
		if(next != null){
			next._remove();
		}
	},
	remove:function(){
		this.dom.innerHTML = "";
		if(this.dom.tagName.toLowerCase() == "input"){
			this.dom.disabled = "disabled";
		}else{
			this.dom.style.display = "none";
		}
		
	}
};
//供头部使用，也可插入其他页使用
function initCitys(){
	var conf = {
		template:function(citys){
			var o=this,dom = o.dom;
			dom.style.display = "";
			for(var i= 0;i<citys.length;i++){
				var el = document.createElement("A");
					el.innerHTML = citys[i];
					el.className = "city1";
					el.href = "javascript:void(0)";
					el.onfocus = function(){this.blur()};
					el.onclick = function(){
						o.fire(this.innerHTML);
					};
					dom.appendChild(el);
					el = null;
			}
			var clear = document.createElement("DIV");
				clear.className = "clear";
				dom.appendChild(clear);
				clear = null;
		},
		getValue:function(){
			return this.value;
		},
		setValue:function(){
			this.objCity.values[this.level] = this.value;
		},
		remove:function(){
			this.dom.innerHTML = "";
			this.dom.style.display = "none";
		},
		showValues:function(){
			var sel = myCity.tempSelect,allCity = myCity.allCity,dis;
				myCity.domValues.innerHTML = myCity.getValues().join("--");
				if(this.level == 1){
					
					myCity.showMethod();
					return false;
				}
				dis = sel.style.display == "block" ? "none" : "block";
				allCity.style.display = dis == "none" ? "block" : "none";
				sel.style.display = dis;
		}
	};
	
	//实现多种呈现方式的函数
	function showCityPlanel(type){
		var el = getDom("cityBox");
		var dis = el.style.display;
			el.style.display = dis == "block" ? "none" : "block";

			
		var sheng = myCity.getValues()[0];
		var shi = myCity.getValues()[1] || sheng;
		
		switch (type || ""){
			case "":
				break;
			case "citySearch_1" :
						getDom("Province").value = sheng;
						getDom("City").value = shi;
						getDom("searchHosp").submit();
				break;
			case "regCity" :
					getDom("regCity").value = myCity.getValues().join("-");
					getDom("regProvince").value = sheng;
					getDom("regCity").value = myCity.getValues()[1] || sheng;
				break;
			case "miniHeader":
					getDom("mini_ProvinceValue").value = sheng;
					getDom("mini_CityValue").value = myCity.getValues()[1] || sheng;
					getDom("miniHospSearch").submit();
					
				break;
			case "regBlog":
					getDom("province").value = sheng;
					getDom("city").value = myCity.getValues()[1] || sheng;
					var shi = myCity.getValues()[1] || sheng;
					getHosps(sheng,shi);
					
				break;
				case "reg":{
					getDom("ProvinceValue").value = sheng;
					getDom("CityValue").value = myCity.getValues()[1] || sheng;
					geitip();
					setTab('tab',2,2);
					check("province");
					if(typeof otherSetValue != "undefined"){
						otherSetValue(sheng,myCity.getValues()[1] || sheng);
					}
				 break;
				}
			default :
				break;
			
		}
	
	}
	
	
	myCity = new $.plug.city();
	myCity.setChild("div_2",[],conf);//数据由页面自定义了
	myCity.setChild("div_3",area_2,conf);
	myCity.addShowFn(showCityPlanel);
	myCity.allCity = getDom("allCity");
	myCity.tempSelect = getDom("tempSelect");
	myCity.domValues = getDom("domValues");
	
	
	
			var i,c = myCity.allCity.getElementsByTagName("A"),len = c.length;
			var mainCitys = getDom("mainCity").getElementsByTagName("A");
			var len2 = mainCitys.length,j;
			
			for(i=0;i<len;i++){
				c[i].onclick = function(){
					myCity.childs[0].fire(this.innerHTML);
				};
			}
			for(j=0;j<len2;j++){
				mainCitys[j].onclick = function(){
					var sheng = this.getAttribute("p");
					var shi = this.innerHTML;
					if(sheng){
						myCity.childs[0].fire("");
						myCity.values = [sheng,shi];
						
					}else{
						myCity.childs[0].fire(sheng);
						myCity.values = [shi];					
					}
					var sel = myCity.tempSelect,allCity = myCity.allCity,dis;
						dis = sel.style.display == "block" ? "none" : "block";
						allCity.style.display = dis == "none" ? "block" : "none";
						sel.style.display = dis;
						myCity.showMethod();

				};
			}

			//重新选择省份
			getDom("toSelect").onclick = function(){
				myCity.childs[0].fire();
			};
			//关闭
			getDom("cityBoxClose").onclick = function(){
				myCity.showType = "";
				myCity.showMethod();
			};
			

			//不同页面使用需要在外部覆盖initThisPageEvent函数，以绑定不同的文档dom
			initThisPageEvent();


}


//默认为首页头部使用
function initThisPageEvent(){
	//主医院搜索打开按钮
	/**
	getDom("selButton").onclick = function(){
		myCity.showMethod();
		myCity.showType = "citySearch_1";
		changePos(getDom("cityBox"),300,100);
	};
	**/
}

function setPageBg(){
	var div = document.getElementById("_iframe_bg"),dis = div.style.display;
	if(dis == "none"){
		var w = Math.max(document.documentElement.scrollWidth,document.documentElement.clientWidth)+"px";
		var h = Math.max(document.documentElement.scrollHeight,document.documentElement.clientHeight)-100+"px";
		div.style.width = w;
		div.style.height = h;
		div.style.display = "";
	}else{
		div.style.display = "none";
	}
}

function initRegCity(){
	//找医院
	getDom("selButton_2").onclick = function(){
		myCity.showMethod();
		myCity.showType = "citySearch_1";
		changePos(getDom("cityBox"),240,440);
	};
	//注册选择城市
	getDom("regProvince").onclick = function(){
		myCity.showMethod();getDom("regProvince").blur();
		myCity.showType = "regCity";
		changePos(getDom("cityBox"),240,260);
	};
	getDom("regCity").onclick = function(){
		myCity.showMethod();getDom("regCity").blur();
		myCity.showType = "regCity";
		changePos(getDom("cityBox"),240,260);
	};
}

function getDom(id){
	return document.getElementById(id);
}
function changePos(el,x,y){
	el.style.left = x +"px";
	el.style.top = y + "px";
}

function check_reg(o){
	var myForm = o || document.forms["reg"];
	var name = myForm.UserName,phone = myForm.Mobile,province = myForm.Province,city = myForm.City;
	if(name.value == ""){
		alert("请填写您的姓名！");
		name.focus();
		return false;
	}
	
	if(phone.value == ""){
		alert("请您填写您的手机号码！");
		phone.focus();
		return false;
	}else if(phone.value.length != 11 ){
		alert("手机号码的位数不正确！");
		phone.focus();
		return false;
	}else if(!isNum(phone.value)){
		alert("手机号码必须全部是数字！");
		phone.focus();
		return false;
	}
	
	if(province.value == ""){
		alert("请选择省份和城市！");
		return false;
	}
	if(city.value ==""){
		alert("请选择省份和城市！");
		return false;
	}
	
	return true;
}

function isNum(num){
	var i,s,num = num.toString();
	s="0123456789";
	if(num.length == 0){
		return false;
	}
	for (i=0;i<num.length;i++){
		if(s.indexOf(num.charAt(i)) == -1){
			return false;
		}
 	}
	return true;
}














