﻿$(document).ready(function() {
	$('#province').change(function() {
		if($(this).attr("value") == "") {
			alert("请选择省份！");
		}
	});
	
	$('#city').change(function() {
		if($(this).attr("value") == "") {
			alert("请选择城市！");
		}
	}); 
});

//弹出选择医院窗口
function hospital() {
	if ($('#province').attr("value") == "") {
		alert("请选择省份！");
		$('#province').focus();
		return false;
	}
	if ($('#city').attr("value") == "") {
		alert("请选择城市！");
		$('#city').focus();
		return false;
	}
	var province = encodeURIComponent($("#province").val());
	var city = encodeURIComponent($("#city").val());
	var area = encodeURIComponent($("#area").val());
	
	$.get("ajax.php?action=gethospital&province="+province+"&city="+city+"&area="+area, function(data){
		//$("#hid").html(data);
		dialogShow(data);
	});
}

function G(id) {
	return document.getElementById(id);
}

function GC(t) {
	return document.createElement(t);
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, '');
}

function isIE() {
	return (document.all && window.ActiveXObject && !window.opera)?true:false;
}

function popCoverDiv() {
	if (G("cover_div")) {
		G("cover_div").style.display = '';
	} else {
		var coverDiv = GC('div');
		document.body.appendChild(coverDiv);
		coverDiv.id = 'cover_div';
		with (coverDiv.style) {
			position = 'absolute';
			background = '#EFEFEF';
			left = '0px';
			top = '0px';
			var bodySize = getBodySize();
			width = bodySize[0] + 'px'
			height = bodySize[1] + 'px';
			zIndex = 98;
			if (isIE()) {
				filter = "Alpha(Opacity=60)";
			} else {
				opacity = 0.6;
			}
		}
	}
}

function getBodySize() {
	var bodySize = [];
	with (document.documentElement) {
		bodySize[0] = (scrollWidth>clientWidth)?scrollWidth:clientWidth;
		bodySize[1] = (scrollHeight>clientHeight)?scrollHeight:clientHeight;
	}
	return bodySize;
} 

function dialogShow(htmlcode) {
	var DivWidth=500;
	popCoverDiv();
	if (G("dialog_div")) {
		G("dialog_div").style.display = '';
	} else {
		var signDiv = GC('div');
		document.body.appendChild(signDiv);
		signDiv.id = 'dialog_div';
		with (signDiv.style) {
			position = 'absolute';
			left = (document.documentElement.clientWidth - DivWidth)/2 +'px';
			top = (document.documentElement.clientHeight - 300)/2 + 'px';
			width = DivWidth + 'px';
			zIndex = 99;
		}
	}
	G("dialog_div").innerHTML = htmlcode;
}

function dialogHide() {
	G("dialog_div").style.display = 'none';
	G("cover_div").style.display = 'none';
	//$("#dialog_div").fadeOut("slow");
	//$("#cover_div").fadeOut("slow");
	
	document.body.style.overflow = '';
}

/*function putStr(hid, lname){
	if(G('hospitalname')) G('hospitalname').value = lname;
	if(G('hid')) G('hid').value = hid;
}*/
