﻿function _$(id){return document.getElementById(id);}
function getPosition(obj){
var top=0;var left=0;var width=obj.offsetWidth;var height=obj.offsetHeight;while(obj.offsetParent){
top+=obj.offsetTop;left+=obj.offsetLeft;obj=obj.offsetParent;}
return{"top":top,"left":left,"width":width,"height":height};}
         
var verifyCounter=[];var isUpdate=false;function VerifyImage(eleID,x,y){
var c=verifyCounter.length;this.timeout=null;this.ipt=null;var seed=null;if(!eleID)
this.eleID=eleID="verifyIMG_"+c;this.od=document.createElement("div");with(this.od){
style.position = "absolute"; style.zIndex = 10; style.backgroundColor = "#FFFFFF"; style.border = "solid 1px #64a9d9"; style.padding = "3px"; id = eleID + "_anchor";
}
this.templete = ('<img id="' + eleID + '" onclick="getVerify(\'' + eleID + '\',' + c + ')" style="cursor:pointer;margin-bottom:5px" src="/Security/InputValidCheck.aspx?w=100&h=53&bc=d5d7d7&{{_random_}}" alt="获取中..." title="点击更换" width="100" height="53" /><br /><span onclick="getVerify(\'' + eleID + '\',' + c + ')" style="color:black;cursor:pointer">看不清楚?换一个</span>'); this.seed = Math.random(); this.appended = false; verifyCounter[c] = this;
}
VerifyImage.prototype.showMe = function(x, y, d) {
    with (this.od) {
        switch (d) {
            case "right":
                y = y + 3;
                x = x + 100;
                break;
            case "bottom":
                y = y + 20;
                x = x + 1;
                break;
        }
        style.top = y + "px"; style.left = x + "px";
    }
    if (!this.appended) {
        document.body.appendChild(this.od); this.od.innerHTML = this.templete.replace(/\{\{_random_\}\}/g, this.seed); this.appended = true;
    }
    this.od.style.display = "";
}
VerifyImage.prototype.killMe=function(){
this.od.style.display="none";}
VerifyImage.prototype.change=function(){
var o=_$(this.eleID); this.seed=Math.random();o.src="/Security/InputValidCheck.aspx?w=100&h=53&bc=e4e8f3&"+this.seed;}
function getVerify(s,n){
clearTimeout(verifyCounter[n].timeout);verifyCounter[n].change();if(verifyCounter[n].ipt){
verifyCounter[n].ipt.value="";verifyCounter[n].ipt.focus();}}
function changeVerify(){
getVerify("verifyIMG_0",0);}

function focusGetVerify(o,d) {
var pos=getPosition(o);var e=(verifyCounter.length>0)?(verifyCounter[0]):(new VerifyImage());e.ipt=o;e.showMe(pos.left,pos.top,d);o.value="";if(isUpdate){changeVerify();isUpdate=false;}}

function hiddenVerify(isImme){
if(!verifyCounter[0])
return;if(!isImme){verifyCounter[0].timeout=setTimeout(function(){verifyCounter[0].killMe()},500);}
else{verifyCounter[0].killMe();isUpdate=true;}}