function newXMLHttpRequest() {
var http_request = false;
　//开始初始化XMLHttpRequest对象
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {//设置MiME类别
				http_request.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) { // 异常，创建对象实例失败
			window.alert("Examples can create XMLHttpRequest object.");
			return false;
		}
　return http_request;
}

function send_reqssss(url,obj)
{　
        var http_request = newXMLHttpRequest();
       //http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		
		//loadingdStr(obj);
		http_request.onreadystatechange = processRequest;		
		http_request.open("GET", url, true);
		http_request.send(null);		
		
// 处理返回信息的函数
    function processRequest() {
        if (http_request.readyState == 4) { // 判断对象状态		
            if (http_request.status == 200) { // 信息已经成功返回，开始处理信息  
		       document.getElementById(obj).innerHTML=http_request.responseText;
            } else { //页面不正常
                alert("Do you have an unusual request pages。");
            } 
		}
    }

}




function send_url(url,obj)
{　
        var http_request = newXMLHttpRequest();
       //http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");		
		loadingdStr(obj);
		http_request.onreadystatechange = processRequest;		
		http_request.open("GET", url, true);
		http_request.send(null);		
		
// 处理返回信息的函数
    function processRequest() {
        if (http_request.readyState == 4) { // 判断对象状态		
            if (http_request.status == 200) { // 信息已经成功返回，开始处理信息  
		       document.getElementById(obj).innerHTML=http_request.responseText;
            } else { //页面不正常
                alert("Do you have an unusual request pages。");
            } 
		}
    }

}

function chkpassword(ms,ojb){
 if (ms.length>18 || ms.length<6 || !ifstrE(ms)){
 document.getElementById(ojb).innerHTML="<font color='red'>Passwords errors</font>";
 }else{
 document.getElementById(ojb).innerHTML="";
 }
}

function VerifyData(form)
	{
		var valid = 1;		
		
		document.getElementById("login_error").innerHTML="";	
		document.getElementById("nick_name_error").innerHTML="";
		document.getElementById("real_name_error").innerHTML="";
		document.getElementById("password_error").innerHTML="";
		document.getElementById("surePassword_error").innerHTML="";		
		document.getElementById("email_error").innerHTML="";		
		document.getElementById("country_error").innerHTML="";		
		document.getElementById("Birthdate_error").innerHTML="";		
		document.getElementById("occupation_error").innerHTML="";		
	
		if (form.login.value.length <6 || form.login.value.length >18)
		{
			document.getElementById("login_error").innerHTML="<font color='red'>Username to 6-18 spaces character</font>";
			form.login.focus();
			valid = 0;
		}else{
			if (!ifstrE(form.login.value))
			{
			document.getElementById("login_error").innerHTML="<font color='red'>Username is Letters or Number</font>";
			form.login.focus();
			valid = 0;
		  }
		}
		
		if (form.nick_name.value.length <2)
		{
			document.getElementById("nick_name_error").innerHTML="<font color='red'>Please enter 3-18 characters and/or numbers</font>";
			form.nick_name.focus();
			valid = 0;
		}
		
       if (form.real_name.value.length <2)
		{
			document.getElementById("real_name_error").innerHTML="<font color='red'>Please enter your real name</font>";
			form.real_name.focus();
			valid = 0;
		}
		
		if (form.password.value.length <6 || form.password.value.length >18)
		{
			document.getElementById("password_error").innerHTML="<font color='red'>Password should be 6-18 characters and/or numbers</font>";
			form.password.focus();
			valid = 0;
		}else{
			if (!ifstrE(form.password.value))
			{
			document.getElementById("password_error").innerHTML="<font color='red'>Passwords is Letters or Number</font>"
			form.password.focus();
			valid = 0;
		  }
		}

		if (form.surePassword.value!=form.password.value)
		{
			document.getElementById("surePassword_error").innerHTML="<font color='red'>Please confirm with the same password you just entered</font>";
			form.surePassword.focus();
			valid = 0;
		}		

		if (form.country.value=="" || form.province.value=="" || form.city.value=="")
		{
			document.getElementById("country_error").innerHTML="<font color='red'>Please choose your location</font>";
			form.surePassword.focus();
			valid = 0;
		}		

				
		if (checkbd(form.year.value,form.month.value,form.day.value)==false){
			document.getElementById("Birthdate_error").innerHTML="<font color='red'>Please choose your birthday</font>";	
			valid = 0;
			}
			
		if (checkEmail(form.email.value)==false){
			document.getElementById("email_error").innerHTML="<font color='red'>Please correct input Email</font>";
			form.email.focus();			
			valid = 0;
			}
		
			
		if (form.occupation.value=='0'){
			document.getElementById("occupation_error").innerHTML="<font color='red'>Please choose your occupation</font>";
			valid = 0;
			}
		
		if (valid==0)
			return false;	
	}
	
//检测字符串为空
function check_null(string) 
{ 
   var i=string.length;
var j = 0; 
var k = 0; 
var flag = true;
while (k<i)
{ 
if (string.charAt(k)!= " ") 
j = j+1; 
k = k+1; 
} 
if (j==0) 
{ 
flag = false;
} 
return flag; 
}

//判断数字	
function is_number(str){
  exp=/[^0-9]/g;
  if(str.search(exp)!=-1){
    return false;
  }else{
    return true;
  }
}
  //判断无效字符	
function ifstr(str){
  exp=/[^\u4E00-\u9FA5a-zA-Z]/g;
  if(str.search(exp)!=-1){
    return false;
  }else{
    return true;
  }
} 


  //判断无效字符，只能出现数字或字母
function ifstrE(str){
  var re=/^[0-9a-z][\w-.]*[0-9a-z]$/i;
	if(re.test(str))
		return true;
	else
		return false;
} 

  //判断无效字符，只能出现汉字或字母
function Enstr(str){
  var re=/[^\u4E00-\u9FA5a-zA-Z]/g;
	if(re.test(str))
		return true;
	else
		return false;
} 


function checkbd(byear,bmon,bday){		
           var Digital=new Date();
		   var yes=Digital.getFullYear();
			if (byear==""||bmon==""||bday==""
				||byear <=0 || bday<=0
			){
				return false;
			}
			switch(bmon){
				case '1':
				case '3':	
				case '5':	
				case '7':	
				case '8':	
				case '10':	
				case '12':	
					if (bday>31){
						return false;
					}
					break;
				case '4':	
				case '6':	
				case '9':	
				case '11':	
					if (bday>30){
						return false;
					}
					break;
				case '2':
					var mday=28;
					var yy = Math.floor(byear/4);
					if (yy*4 == byear){
						mday=29
						if (Math.floor(byear/100)*100 == byear){
							mday = 28;
						}
						if (Math.floor(byear/400)*400 == byear){
							mday = 29;
						}
					}
					if (bday>mday){
						return false;
					}
			}
			if (yes-byear<18 || yes-byear>70){
			return false;
			}
			return true;
		}

function checkEmail(emailStr) {  
			   if (emailStr.length == 0) {                  
                   return false;
               }   
               var emailPat=/^(.+)@(.+)$/;
               var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
               var validChars="\[^\\s" + specialChars + "\]";
               var quotedUser="(\"[^\"]*\")";
               var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
               var atom=validChars + '+';
               var word="(" + atom + "|" + quotedUser + ")";
               var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
               var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
               var matchArray=emailStr.match(emailPat);
               if (matchArray == null) {                   
                   return false;
               }
               var user=matchArray[1];
               var domain=matchArray[2];
               if (user.match(userPat) == null) {                  
                  return false;
               }
               var IPArray = domain.match(ipDomainPat);
               if (IPArray != null) {
                   for (var i = 1; i <= 4; i++) {
                      if (IPArray[i] > 255) {                        
                         return false;
                      }
                   }
                   return true;
               }
               var domainArray=domain.match(domainPat);
               if (domainArray == null) {
                     return false;
               }
               var atomPat=new RegExp(atom,"g");
               var domArr=domain.match(atomPat);
               var len=domArr.length;
               if ((domArr[domArr.length-1].length < 2) ||
                   (domArr[domArr.length-1].length > 3)) {                  
                   return false;
               }
               if (len < 2) {                  
                  return false;
               }
               return true;
            }


function loadingdStr(obj){
document.getElementById(obj).innerHTML="<center><img src='/js/indicator.gif' width='16' height='16'></center>";
} 


function GetResult(str,classid)
{
/*
*--------------- GetResult(str,classid) -----------------
* GetResult(str) 
* 功能:通过XMLHTTP发送请求,返回结果.
* 参数:str,字符串,发送条件;classid,数字,菜单级别
* 实例:GetResult(document.all.userid.value,1);
*--------------- GetResult(str,classid) -----------------
*/
//定义菜单级数，菜单ID数组，菜单对应字段数组




if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
}


var linkurl="/inc/city.php?classid="+classid+"&sel="+str;
http_request.open("GET",linkurl,false);
http_request.send(null);

//服务器端处理返回的是经过escape编码的字符串.
//在页面显示服务器查询结果

var returntxt=unescape(http_request.responseText)


var kkk
for(kkk=classid+2;kkk<=MenuClass;kkk++)
	{		
	submenu=document.getElementById(MenuIdArr[kkk]);
	//submenu.options[0].selected=true;
	submenu.options.length=0;
	submenu.options.add(new Option("select","99999")); 
	}

BuildSel(returntxt,document.getElementById(MenuIdArr[classid+1]))

//============更改下下级以下菜单为空==============

}
function GetResult1(str,classid)
{
/*
*--------------- GetResult(str,classid) -----------------
* GetResult(str) 
* 功能:通过XMLHTTP发送请求,返回结果.
* 参数:str,字符串,发送条件;classid,数字,菜单级别
* 实例:GetResult(document.all.userid.value,1);
*--------------- GetResult(str,classid) -----------------
*/

if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
}


var linkurl="/inc/city.php?classid="+classid+"&sel="+str;
http_request.open("GET",linkurl,false);
http_request.send(null);

//服务器端处理返回的是经过escape编码的字符串.
//在页面显示服务器查询结果

var returntxt=unescape(http_request.responseText)

var kkk
for(kkk=classid+2;kkk<=MenuClass;kkk++)
	{	

	submenu=document.getElementById(MenuIdArr1[kkk]);

	//submenu.options[0].selected=true;
	submenu.options.length=0;

	submenu.options.add(new Option("select","")); 
	}


BuildSel(returntxt,document.getElementById(MenuIdArr1[classid+1]))

//============更改下下级以下菜单为空==============

}
function BuildSel(str,sel)
{
/*
*--------------- BuildSel(str,sel) -----------------
* BuildSel(str,sel) 
* 功能:通过str构建Select.
* 参数:str,字符串,由服务端返回的.有特定结构"字符串1|,字符串2,字符串3"
*          也可为"字符串1序号|字符串1文本,字符串2序号|字符串2文本,字符串3序号|字符串3文本",如本例
* 参数:sel,要构建的Select
* 实例:BuildSel(unescape(oBao.responseText),document.all.sel2)
*--------------- BuildSel(str,sel) -----------------
*/
//先清空原来的数据.
sel.options.length=0;
var arrstr = new Array();
arrstr = str.split(",");
//开始构建新的Select.
sel.options.add(new Option( "+select","99999"));  
if(str.length>0)   
{
for(var i=0;i<arrstr.length-1;i++)
{
//分割字符串
var subarrstr=new Array
subarrstr=arrstr[i].split("|")
//生成下级菜单
sel.options.add(new Option(subarrstr[1],subarrstr[0])); 
}
sel.options[0].selected=true
}

}


function VerifyChangData(form)
	{
		var valid = 1;				

		document.getElementById("nick_name_error").innerHTML="";
		document.getElementById("country_error").innerHTML="";		
		document.getElementById("Birthdate_error").innerHTML="";		
		document.getElementById("occupation_error").innerHTML="";		
	
		if (form.nick_name.value.length <2)
		{
			document.getElementById("nick_name_error").innerHTML="<font color='red'>Please enter 3-18 characters and/or numbers</font>";
			form.nick_name.focus();
			valid = 0;
		}

		if (form.country.value=="" || form.province.value=="" || form.city.value=="")
		{
			document.getElementById("country_error").innerHTML="<font color='red'>Please choose your location</font>";
			form.surePassword.focus();
			valid = 0;
		}		

				
		if (checkbd(form.year.value,form.month.value,form.day.value)==false){
			document.getElementById("Birthdate_error").innerHTML="<font color='red'>Please choose your birthday</font>";	
			valid = 0;
			}
		
			
		if (form.occupation.value=='0'){
			document.getElementById("occupation_error").innerHTML="<font color='red'>Please choose your occupation</font>";
			valid = 0;
			}
		
		if (valid==0)
			return false;	
	}
	
function checkbox_selectAll(idname){
	var f=document.getElementsByName(idname);
for(i=0;i<f.length;i++){
if(f(i).type=="checkbox" && f(i)!=event.srcElement){
f(i).checked=event.srcElement.checked;
		}
	}
}