﻿//set cookie
function setCookie(key,value){
	var never = new Date();
	never.setTime(never.getTime()+1*365*24*60*60*1000);
	var expString = "expires="+never.toGMTString()+";";
	document.cookie=key+"="+escape(value)+" ;"+expString;
}
//get cookie by name
function getCookie(key){
	var aCookie = document.cookie.split("; ");
	for(var i=0;i<aCookie.length;i++){
		var aCrumb = aCookie[i].split("=");
		  if(key == aCrumb[0])
		     return unescape(aCrumb[1]);
	}
	return "";
}  
//open window
//
function openWindowNoAll(url,width,height){
  var left = (window.screen.width-width)/2;
  var top = (window.screen.height-height)/2;
  window.open(url, "", "width="+width+"px,height="+height+"px,left="+left+",top="+top+
	  ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no maximum=no");
}
//
function openWindowScrollbars(url,width,height){
  var left = (window.screen.width-width)/2;
  var top = (window.screen.height-height)/2;
  window.open(url, "", "width="+width+"px,height="+height+"px,left="+left+",top="+top+
	  ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no maximum=no");
}
//检查密码安全性
        var PasswordStrength ={
            Level : ["差","中","强"],
            LevelValue : [0,20,30],//强度值
            Factor : [1,2,5],//字符加数,分别为字母，数字，其它
            KindFactor : [0,0,10,20],//密码含几种组成的加数 
            Regex : [/[a-zA-Z]/g,/\d/g,/[^a-zA-Z0-9]/g], //字符正则数字正则其它正则
			Color : ["#FF4545","#FFD35E","#95EB81"]
            }
		PasswordStrength.init = function(pwd){
			var div = "";
            for(var i = 0 ; i < this.LevelValue.length ; i ++){
			     div +="<div id='"+i+"' style='position:absolute;display:none;width:4px;height:2px;border:1px solid #0000;background:#BEBEBE;' title='密码安全性'></div>";
			}
		    document.write(div);
		}
        PasswordStrength.StrengthValue = function(pwd){
            var strengthValue = 0;
            var ComposedKind = 0;
            for(var i = 0 ; i < this.Regex.length;i++)
            {
                var chars = pwd.match(this.Regex[i]);
                if(chars != null)
                {
                    strengthValue += chars.length * this.Factor[i];
                    ComposedKind ++;
                }
            }
            strengthValue += this.KindFactor[ComposedKind];
            return strengthValue;
        } 
        PasswordStrength.StrengthLevel = function(event){
			var ev = event||window.event;
			var obj = ev.target||ev.srcElement;
			//alert(this);
			//alert(this.StrengthValue(obj.value));
            var value = this.StrengthValue(obj.value);
            for(var i = 0 ; i < this.LevelValue.length ; i ++)
            {
                if(value >= this.LevelValue[i] )
					this.showStrength(obj,this.Level[i],i);
            }
        }
		PasswordStrength.showStrength = function(obj,label,level){
           for(var i = 0 ; i < this.LevelValue.length ; i ++){
		      var el = document.getElementById(""+i);
			  el.style.display = "none";
		   }
		   //
		   var el = null;
		   var pwd = obj.getBoundingClientRect(); 
		   var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);         
		   var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); 
		   var divTop = pwd.top + scrollTop;
		   var divLeft = pwd.left + scrollLeft + obj.offsetWidth;//
		   for(var i=0;i<=level;i++){
				el = document.getElementById(""+i);
				el.title = "密码安全性";
				el.style.top = divTop-1;
				el.style.left = divLeft+i*6;
				el.style.height = 4;
				el.style.background = this.Color[level];
				el.title=el.title+":"+label;
				el.style.display = "block"; 
		   }
        }
//大写锁定键检查
        var CapsLockDetect ={
            }
		CapsLockDetect.detectCapsLock = function(event){
				var e = event||window.event;
				var o = e.target||e.srcElement;
				var oTip =  document.getElementById("tip");
				oTip.innerHTML='&nbsp;<img src="/images/question.gif">&nbsp;<b>大写锁定打开！</b><br>&nbsp;保持大写锁定打开可能会使您错误输入密码。<br>&nbsp;在输入密码前，您应该按"Caps Lock"键来将其<br>&nbsp;关闭。';
				var keyCode  =  e.keyCode||e.which; // 获取按键的keyCode
				var isShift  =  e.shiftKey ||(keyCode  ==   16 ) || false ; // 判断shift键是否按住
				if (((keyCode >=   65   &&  keyCode  <=   90 )  &&   !isShift)|| ((keyCode >=   97   &&  keyCode  <=   122 )  &&  isShift)){
					var box = o.getBoundingClientRect(); 
					var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);         
					var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);  
					oTip.style.top = box.top + scrollTop - 2;
					oTip.style.left = box.left + scrollLeft + o.offsetWidth;
					oTip.style.display = 'block';
				}
				else{
					oTip.style.display  =  'none';
				}
			}
		CapsLockDetect.init = function(event){
			var div = "<div id='tip' style='position:absolute;display:none;background:#F0F7EF;width:255px;border:1px solid #000;color:#ffff;text-align:left;font-size:12;' onclick=\"javascript:this.style.display = 'none'\";></div>";
		    document.write(div);
		}
		CapsLockDetect.closeMsg = function(event){
			var oTip =  document.getElementById("tip");
			oTip.style.display  =  'none';
		}
