﻿// JScript 文件

//***************************验证码*********************************//

var code ; //在全局 定义验证码
function createCode(acode)
{ 
    code = "";
    var codeLength = 4;//验证码的长度
    var ccode = document.getElementById(acode);
    ccode.value = "";

    var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
    
    for(var i=0;i<codeLength;i++) 
    {
       var charIndex = Math.floor(Math.random()*62);
       code +=selectChar[charIndex];
    }
    if(code.length != codeLength)
    {
       createCode(acode);
    }
   ccode.value = code;
}

function validateCode (acode,bcode) 
{
    var inputCode = document.getElementById(bcode).value.toUpperCase();

    if(inputCode.length <=0) 
    {
         alert("请输入验证码！");
         return false;
    }
    else if(inputCode != code.toUpperCase() )
    {
         alert("验证码输入错误！");
         createCode(acode);
         return false;
    }
    else 
    {
       return true;
    }
}
