function ajaxDiv(url, id) {
	var req=false;
	try{  
		req = new XMLHttpRequest();  
	}catch(e){  
   		try{
       		req = new ActiveXObject("Msxml2.XMLHTTP.5.0");  
  			}catch(e){
       		try{
          			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");  
       		}catch(e){
				try{
					req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
				}catch(e){
       				try{  
           				req = new ActiveXObject("Msxml2.XMLHTTP");
       				}catch(e){
           				try{req = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){alert("error: no ajax!");}  
       				}
				}
       		}
   		}
	}
	req.onreadystatechange = function processAjaxResponse() {
		  if (req.readyState == 4) {
		    if (req.status == 200) {
		      //alert(req.responseText);
		      document.getElementById(id).innerHTML = req.responseText;
		    } else {
		      alert("There was a problem retrieving the XML data:\n" +req.statusText);
		    }
		  }
		} 
		req.open("GET", url, true);
    //req.setrequestheader("contentType","text/html;charset=gb2312");
    //req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); postÓÃ·¨
    //req.setRequestHeader("Content-Type","text/html;charset=gb2312"); 
    req.send(null);
}

function ajaxValue(url, obj) {
	var req=false;
	try{  
		req = new XMLHttpRequest();  
	}catch(e){  
   		try{
       		req = new ActiveXObject("Msxml2.XMLHTTP.5.0");  
  			}catch(e){
       		try{
          			req = new ActiveXObject("Msxml2.XMLHTTP.4.0");  
       		}catch(e){
				try{
					req = new ActiveXObject("Msxml2.XMLHTTP.3.0");
				}catch(e){
       				try{  
           				req = new ActiveXObject("Msxml2.XMLHTTP");
       				}catch(e){
           				try{req = new ActiveXObject("Microsoft.XMLHTTP");}catch(e){alert("error: no ajax!");}  
       				}
				}
       		}
   		}
	}
	req.onreadystatechange = function processAjaxResponse() {
		  if (req.readyState == 4) {
		    if (req.status == 200) {
		      //alert(req.responseText);
		      obj.value = req.responseText;
		    } else {
		      alert("There was a problem retrieving the XML data:\n" +req.statusText);
		    }
		  }
		} 
		req.open("GET", url, true);
    //req.setrequestheader("contentType","text/html;charset=gb2312");
    //req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); postÓÃ·¨
    //req.setRequestHeader("Content-Type","text/html;charset=gb2312"); 
    req.send(null);
}
	
function getParameter2(paramName){
	var paramValue = null;
	var url = window.location.href;
	if(url.indexOf(paramName+"=")!=-1){
		paramValue = "";
		var url2 = url.substring(url.indexOf(paramName+"=") + paramName.length + 1);
		if(url2.indexOf("&")>=0){
			paramValue = url2.substring(0,url2.indexOf("&"));
		}else if(url2.indexOf("#")>=0){
			paramValue = url2.substring(0,url2.indexOf("#"));
		}else if(url2.indexOf("?")>=0){
			paramValue = url2.substring(0,url2.indexOf("?"));
		}else{
			paramValue = url2;
		}
	}
	return paramValue;
}

function getParameter(paramName){
	var paramValue = null;
	var url = window.location.href;
	if(url.indexOf(paramName+"-")!=-1){
		paramValue = "";
		var url2 = url.substring(url.indexOf(paramName+"-") + paramName.length + 1);
		if(url2.indexOf("--")>=0){
			paramValue = url2.substring(0,url2.indexOf("--"));
		}else if(url2.indexOf(".")>=0){
			paramValue = url2.substring(0,url2.indexOf("."));
		}else{
			paramValue = url2;
		}
	}
	//alert(paramName + ":" + paramValue);
	return paramValue;
}

function toGo(obj){
	//alert(obj.alt);
	var jsObj = document.getElementById(obj.alt);
	jsObj.src = obj.id + "";
	//alert(jsObj.src);
}

function changeArea(obj){
	var provinceObj = document.getElementById("province");
	var cityObj = document.getElementById("city");
	var areaObj = document.getElementById("area");
	var ruralObj = null;
	var villageObj = null;
	var provinceCode = provinceObj.options[provinceObj.selectedIndex].value;
	var cityCode = cityObj.options[cityObj.selectedIndex].value;
	var areaCode = areaObj.options[areaObj.selectedIndex].value;
	var ruralCode = "";
	var villageCode = "";
	if(document.getElementById("showRural").value == "true"){
		ruralObj = document.getElementById("rural");
		ruralCode = ruralObj.options[ruralObj.selectedIndex].value;
	}
	if(document.getElementById("showVillage").value == "true"){
			villageObj = document.getElementById("village");
			villageCode = villageObj.options[villageObj.selectedIndex].value;
	}
	if(obj.name=="province"){
		cityCode = "";
		areaCode = "";
		ruralCode = "";
		villageCode = "";
	}
	if(obj.name=="city"){
		areaCode = "";
		ruralCode = "";
		villageCode = "";
	}
	if(obj.name=="area"){
		ruralCode = "";
		villageCode = "";
	}
	
	var url = "/online_doctor/online/initarea.jsp?showRural=" + document.getElementById("showRural").value;
	url += "&showVillage=" + document.getElementById("showVillage").value;
	url += "&province="  + provinceCode;
	url += "&city="  + cityCode;
	url += "&area="  + areaCode;
	if(ruralObj!=null){
		url += "&rural="  + ruralCode;
	}
	if(villageObj!=null){
		url += "&village="  + villageCode;
	}
	ajaxDiv(url,"initArea");
}

function getAreaCode(){
	var provinceObj = document.getElementById("province");
	var cityObj = document.getElementById("city");
	var areaObj = document.getElementById("area");
	var ruralObj = null;
	var villageObj = null;
	var provinceCode = provinceObj.options[provinceObj.selectedIndex].value;
	var cityCode = cityObj.options[cityObj.selectedIndex].value;
	var areaCode = areaObj.options[areaObj.selectedIndex].value;
	var ruralCode = "";
	var villageCode = "";
	if(document.getElementById("showRural").value == "true"){
		ruralObj = document.getElementById("rural");
		ruralCode = ruralObj.options[ruralObj.selectedIndex].value;
	}
	if(document.getElementById("showVillage").value == "true"){
			villageObj = document.getElementById("village");
			villageCode = villageObj.options[villageObj.selectedIndex].value;
	}
	var code = "";
	if(provinceCode!=""){
		code = provinceCode.substring(0,2);
	}
	if(cityCode!=""){
		code = cityCode.substring(0,4);
	}
	if(areaCode!=""){
		code = areaCode.substring(0,6);
	}
	if(ruralCode!=""){
		code = ruralCode.substring(0,8);
	}
	if(villageCode!=""){
		code = villageCode.substring(0,10);
	}
	return code;
}

function checkChin(str){
	var allStr="abcdefghijklmnopqrstuvwxyz_ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
	for(var i=0;i<str.length;i++){
	   if(allStr.indexOf(str.charAt(i))==-1){
	   	return false;
	   }
	}
	return true;
}

function checkPhone(str){
	var allStr="-1234567890";
	for(var i=0;i<str.length;i++){
	   if(allStr.indexOf(str.charAt(i))==-1){
	   	return false;
	   }
	}
	return true;
}

function checkAge(str){
	var allStr="1234567890";
	for(var i=0;i<str.length;i++){
	   if(allStr.indexOf(str.charAt(i))==-1){
	   	return false;
	   }
	}
	return true;
}

function checkPWD(sh) {
		if("hidden"==sh){
			window.parent.document.getElementById("pwdDiv").style.visibility=sh;
		}else{
			document.getElementById("pwdDiv").style.visibility=sh;
		}
}

function getURL_Province_City_Area_Rural_Village(){
	var str = "";
	var province = getParameter("province");
	var city = getParameter("city");
	var area = getParameter("area");
	var rural = getParameter("rural");
	var village = getParameter("village");
	if(province!=null&&province!=""){
		str += "&province=" + province;
	}
	if(city!=null&&city!=""){
		str += "&city=" + city;
	}
	if(area!=null&&area!=""){
		str += "&area=" + area;
	}
	if(rural!=null&&rural!=""){
		str += "&rural=" + rural;
	}
	if(village!=null&&village!=""){
		str += "&village=" + village;
	}
	return str;
}

//function getStr_Province_City_Area_Rural_Village(){
//	var str = "";
//	var provinceObj = document.getElementById("province");
//	var cityObj = document.getElementById("city");
//	var areaObj = document.getElementById("area");
//	var ruralObj = null;
//	var villageObj = null;
//	var provinceCode = provinceObj.options[provinceObj.selectedIndex].value;
//	var cityCode = cityObj.options[cityObj.selectedIndex].value;
//	var areaCode = areaObj.options[areaObj.selectedIndex].value;
//	var ruralCode = "";
//	var villageCode = "";
//	if(document.getElementById("showRural").value == "true"){
//		ruralObj = document.getElementById("rural");
//		ruralCode = ruralObj.options[ruralObj.selectedIndex].value;
//	}
//	if(document.getElementById("showVillage").value == "true"){
//			villageObj = document.getElementById("village");
//			villageCode = villageObj.options[villageObj.selectedIndex].value;
//	}
//	str += "&province="+provinceCode+"&city="+cityCode+"&area="+areaCode+"&rural="+ruralCode+"&village="+villageCode;
//	return str;
//}

//function getURL_Province_City_Area_Rural_Village(){
//        var str = "";
//        var province = getParameter("province");
//        var city = getParameter("city");
//        var area = getParameter("area");
//        var rural = getParameter("rural");
//        var village = getParameter("village");
//        if(province!=null&&province!=""){
//               str += "&province=" + province;
//        }
//        if(city!=null&&city!=""){
//                str += "--city-" + city;
//        }
//        if(area!=null&&area!=""){
//                str += "--area-" + area;
//       }
//        if(rural!=null&&rural!=""){
//                str += "--rural-" + rural;
//        }
//        if(village!=null&&village!=""){
//                str += "--village-" + village;
//        }
//        return str;
//}

function getStr_Province_City_Area_Rural_Village(){
        var str = "";
        var provinceObj = document.getElementById("province");
        var cityObj = document.getElementById("city");
        var areaObj = document.getElementById("area");
        var ruralObj = null;
        var villageObj = null;
        var provinceCode = provinceObj.options[provinceObj.selectedIndex].value;
        var cityCode = cityObj.options[cityObj.selectedIndex].value;
        var areaCode = areaObj.options[areaObj.selectedIndex].value;
        var ruralCode = "";
        var villageCode = "";
        if(document.getElementById("showRural").value == "true"){
                ruralObj = document.getElementById("rural");
                ruralCode = ruralObj.options[ruralObj.selectedIndex].value;
        }
        if(document.getElementById("showVillage").value == "true"){
                        villageObj = document.getElementById("village");
                        villageCode = villageObj.options[villageObj.selectedIndex].value;
        }
        str += "--province-"+provinceCode+"--city-"+cityCode+"--area-"+areaCode+"--rural-"+ruralCode+"--village-"+villageCode;
        return str;
}

function auto_key(obj){
	var _key;
	document.onkeydown = function(e){
		if (e == null) { // ie
			_key = event.keyCode;
		} else { // firefox
			_key = e.which;
		}
		if(_key == 13){
			if(obj.name=="password"){
				ajaxDiv('/online_doctor/login.do?formAction=login&userName='+document.getElementById('userName').value+'&password='+document.getElementById('password').value,'initLoginOut');
				window.location.reload();
				document.initLogin.submit();
			}
			if(obj.name=="strContent"){
				var newWin = window.open('../CL0027/?hrefId=index&askTitle=' + obj.value);
			}
			if(obj.name=="askTitle"){
				checkForm();
			}
			if(obj.name=="suffererAge"){
				checkForm();
			}
			if(obj.name=="restExplain"){
                                checkForm();
                        }
		}
	};
}

function ask_auto_submit(){
        var _key;
        document.onkeydown = function(e){
          if (e == null) { // ie
                _key = event.keyCode;
          } else { // firefox
                _key = e.which;
          }
          if(_key == 13){
                document.loginForm.submit();
          }
        };
}

