﻿
String.prototype.Trim = function() {
  var m = this.match(/^\s*(\S+(\s+\S+)*)\s*$/);
  return (m == null) ? "" : m[1];
}
String.prototype.isMobile = function() {
  return (/^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(this.Trim()));
}

 String.prototype.Trim1 = function() {
     return this.replace(/(^\s*)|(\s*$)/g, "");
    }
//去左空格;
function ltrim(s){
return s.replace( /^\s*/, "");
}
//去右空格;
function rtrim(s){
return s.replace( /\s*$/, "");
}
//左右空格;
function trim(s){
return rtrim(ltrim(s));
}

function chkMobile(mobile) {
  if (!mobile.isMobile())  {
  	alert("请输入正确的手机号码!");
  	return false;
  }
  return true;

}
function chkName(name) {
	if(trim(name).length<1||trim(name).length>20){
     alert("用户名:1-20位字母或数字");
     return false;
  }
    return true;
}

function chkPwd(pwd,pwd1) {
	if(pwd!=pwd1){
	alert('两次密码输入不一致');
	return false;
	}else if(trim(pwd).length<6||trim(pwd).length>15){
	alert('密码：6-15位数字.');
	return false;
	}
	  return true;
}

  function submitChk(){	
	var uname=document.getElementById("name");

	var pwd=document.getElementById("password");

    	
	if(uname.value==""||trim(uname.value)==""){
		alert("请输入用户名。");
		uname.value="";
		pwd.value="";
		uname.focus();
		return false;
	}
	var expname=new RegExp("^[A-Za-z0-9]+$");
	var trimname=trim(uname.value);
	if (trimname.length > 20||!expname.test(trimname)) {
		alert("请输入正确的用户名。");
		uname.value="";
		pwd.value="";
		uname.focus();
		return false;
	}
		
		
	if(pwd.value==""||trim(pwd.value)==""){
		alert("请输入密码。");
		uname.value="";
		pwd.value="";
		uname.focus();
		return false;
	}
	if(trim(pwd.value).length<6||trim(pwd.value).length>15||isNaN(pwd.value)){
		alert("请输入正确的密码。");
		uname.value="";
		pwd.value="";
		uname.focus();
		return false;
	}
	     
	return true;
    }

function Check(version){
var mobile=document.getElementById("mobile").value;
 if(!chkMobile(mobile)){return false}

 var X=new ActiveXObject("Msxml2.XMLHTTP");
 if(X){
  X.onreadystatechange=function(){
   if(X.readyState==4){
    if(X.status==200){
   	alert(X.responseText);
   	document.getElementById("mobile").value="请输入手机号码";
    }
    else{
    	alert(X.statusText);
    	}
    	
   }
   else{document.getElementById("mobile").value="正在发送短信..."}
  };
   var SendData ="sendMsg.do?version="+version + "&mobile="+mobile;
  X.open('POST',SendData,true);
  X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

 
  X.send();
 }
 else{
 alert('你的浏览器不支持XMLHttpRequest');
 }
}


var  req  ;
function selectMobile(){
	var mobile=document.getElementById("mobilep");
	document.getElementById("mobileName").value=mobile.options[mobile.selectedIndex].text;
	if(window.XMLHttpRequest){
      req=new XMLHttpRequest();
    }else if(window.ActiveXObject){
      req=new ActiveXObject("Microsoft.XMLHTTP");
    }
   var  url  = 'mobileAction.do?method=getMobileTypeList&mobile='+mobile.value;
   if(req){
        req.open("GET",url, true);
        req.onreadystatechange  =  callback;
        req.send(null);
   }

}

function  callback(){
  if  (req.readyState  ==  4)  {
  	if  (req.status  ==  200)  {
	        var  mobileType  =  req.responseXML.getElementsByTagName("mobileType");
	       	var  str  =  new  Array();
	        for(var  i  =  0;  i  <  mobileType.length;  i++){
	          str[i]=mobileType[i].firstChild.data;
	        }
	    	 buildSelect(str,document.getElementById("mobileType"));
   		}
  	}
}
function  buildSelect(str,sel)  {
	sel.options.length  =  1;
	var start;
	var tvalue;
	var tname;
	sel.options[0]=new  Option("请选择手机型号","0");
	for(var  i  =  0;  i<str.length;  i++)  {
		start= str[i].indexOf("_");
		tvalue =str[i].slice(0, start);
		sel.options[sel.options.length]=new  Option(tvalue,str[i]);
	}
	sel.options[sel.options.length]=new  Option("其他","其他_J2ME");
}
function chkGetDown(){
if(document.getElementById("mobilep").value=="0"){
alert("请选择手机品牌");
return false;
}

if(document.getElementById("mobileType").value=="0"){
alert("请选择手机型号");
return false;
}

}

var  req  ;
function selectProv(){		
	var province=document.getElementById("province");
	document.getElementById("addrprov").value=province.options[province.selectedIndex].text;
	if(window.XMLHttpRequest){
      req=new XMLHttpRequest();
    }else if(window.ActiveXObject){
      req=new ActiveXObject("Microsoft.XMLHTTP");
    }
   var  url  = 'addressAction.do?method=getCityList&provinceID='+province.value;
   if(req){	   
        req.open("GET",url, true);
        req.onreadystatechange  =  callback1;
        req.send(null);
   }

}

function  callback1(){
  if  (req.readyState  ==  4)  {
  	if  (req.status  ==  200)  {
	        var  city  =  req.responseXML.getElementsByTagName("city");
	       	var  str  =  new  Array();
	        for(var  i  =  0;  i  <  city.length;  i++){
	          str[i]=city[i].firstChild.data;
	        }			
	    	buildSelect1(str,document.getElementById("city"));
			selectCity();
   		}
  	}
}
function  buildSelect1(str,sel)  {
	sel.options.length  =  1;
	var start;
	var tvalue;
	var tname;
	if(document.getElementById("addrprov").value=="请选择"){
		sel.options[0]=new  Option("","0");
	}else{
		sel.options.length  = 0;
	}		
	for(var  i  =  0;  i<str.length;  i++)  {	
		start= str[i].indexOf("_");
		tvalue =str[i].slice(0, start);
		sel.options[sel.options.length]=new  Option(tvalue,str[i].substr(start+1));
	}	
}

var  req  ;
function selectCity(){	
	var city=document.getElementById("city");	
	document.getElementById("addrcity").value=city.options[city.selectedIndex].text;
	if(window.XMLHttpRequest){
      req=new XMLHttpRequest();
    }else if(window.ActiveXObject){
      req=new ActiveXObject("Microsoft.XMLHTTP");
    }
	//var ind= city.value.indexOf("_");		
  // var  url  = 'addressAction.do?method=getDistrictList&cityID='+city.value.substr(ind+1);
  var  url  = 'addressAction.do?method=getDistrictList&cityID='+city.value;
   if(req){		  
        req.open("GET",url, true);
        req.onreadystatechange  =  callback2;
        req.send(null);
   }

}

function  callback2(){
  if  (req.readyState  ==  4)  {
  	if  (req.status  ==  200)  {
	        var  district=  req.responseXML.getElementsByTagName("district");
	       	var  str  =  new  Array();			
	        for(var  i  =  0;  i  <  district.length;  i++){
	          str[i]=district[i].firstChild.data;
	        }
	    	 buildSelect2(str,document.getElementById("district"));
   		}
  	}
}
function  buildSelect2(str,sel)  {
	sel.options.length  =  1;
	var start;
	var tvalue;
	var tname;	
	if(document.getElementById("addrcity").value==""){
		sel.options[0]=new  Option("","0");
	}else{
		sel.options.length  =  0;
	}	
	for(var  i  =  0;  i<str.length;  i++)  {
		start= str[i].indexOf("_");
		tvalue =str[i].slice(0, start);
		sel.options[sel.options.length]=new  Option(tvalue,str[i].substr(start+1));
	}
}