//哈尔滨伟成科技有限公司 www.yidacms.com


//判断排序是否为数字！
function numericCheck(){
nr1=document.form1.sort.value; //判断排序是否为数字！
flg=0;
str="";
spc=""
arw="";
for (var i=0;i<nr1.length;i++){
cmp="0123456789"
tst=nr1.substring(i,i+1)
if (cmp.indexOf(tst)<0){
flg++;
str+=" "+tst;
spc+=tst;
arw+="^";
}
else{arw+="_";}
}
if (flg!=0){
if (spc.indexOf(" ")>-1) {
str+="和空格";
}
alert("这里只接受数字，发现"
+flg+"个不可接受的字符:\n"+str);
return false;
}
}


// --- 获取ClassName
document.getElementsByClassName = function(cl) {
var retnode = [];
var myclass = new RegExp('\\b'+cl+'\\b');
var elem = this.getElementsByTagName('*');
for (var j = 0; j < elem.length; j++) {
var classes = elem[j].className;
if (myclass.test(classes)) retnode.push(elem[j]);
}
return retnode;
}


 // --- 隐藏所有
function HideAll() {
var items = document.getElementsByClassName("optiton");
for (var j=0; j<items.length; j++) {
items[j].style.display = "none";
}
}
 

// --- 设置cookie
function setCookie(sName,sValue,expireHours) {
var cookieString = sName + "=" + escape(sValue);
//;判断是否设置过期时间
if (expireHours>0) {
var date = new Date();
date.setTime(date.getTime + expireHours * 3600 * 1000);
cookieString = cookieString + "; expire=" + date.toGMTString();
}
document.cookie = cookieString;
}
 

//--- 获取cookie
function getCookie(sName) {
var aCookie = document.cookie.split("; ");
for (var j=0; j < aCookie.length; j++){
var aCrumb = aCookie[j].split("=");
if (escape(sName) == aCrumb[0])
return unescape(aCrumb[1]);
}
return null;
}

window.onload = function() {
var show_item = "opt_1";
if (getCookie("show_item") != null) {
show_item= "opt_" + getCookie("show_item");
}
document.getElementById(show_item).style.display = "block";
var items = document.getElementsByClassName("title");
for (var j=0; j<items.length; j++) {
items[j].onclick = function() {
var o = document.getElementById("opt_" + this.name);
if (o.style.display != "block") {
 HideAll();
 o.style.display = "block";
 setCookie("show_item",this.name);
}
else {
 o.style.display = "none";
}
}
}
}


//密码强度检测
 function chkpwd(obj){
  var t=obj.value;
  var id=getResult(t);

  //定义对应的消息提示
  var msg=new Array(4);
  msg[0]="密码过短。";
  msg[1]="密码强度差。";
  msg[2]="密码强度良好。";
  msg[3]="密码强度高。";
  
  var sty=new Array(4);
  sty[0]=-45;
  sty[1]=-30;
  sty[2]=-15;
  sty[3]=0;
  
  var col = new Array(4);
  col[0] = "gray";
  col[1] = "#50AEDD";
  col[2] = "#FF8213";
  col[3] = "green";


  //设置显示效果
  var bImg="images/pwdlen_dSIPeEGQWxfO.gif" //一张显示用的图片
  var sWidth=300;
  var sHeight=15;
  var Bobj=document.getElementById("chkResult");

  Bobj.style.fontSize="12px";
  Bobj.style.color=col[id];
  Bobj.style.width=sWidth + "px";
  Bobj.style.height=sHeight + "px";
  Bobj.style.lineHeight=sHeight + "px";
  Bobj.style.background="url(" + bImg + ") no-repeat left " + sty[id] + "px";
  Bobj.style.textIndent="20px";
  Bobj.innerHTML="检测提示：" + msg[id];
 }
 

 //定义检测函数,返回0/1/2/3分别代表无效/差/一般/强
 function getResult(s){
  if(s.length < 4){
   return 0;
  }
  var ls = 0;
  if (s.match(/[a-z]/ig)){
   ls++;
  }
  if (s.match(/[0-9]/ig)){
   ls++;
  }
   if (s.match(/(.[^a-z0-9])/ig)){
   ls++;
  }
  if (s.length < 6 && ls > 0){
   ls--;
  }
  return ls
}