﻿        var strArray;
        var headText="_pd_js_rt_";//应用验证的页面id前缀
        
        //获取对应的警告框，错误框，成功框，提示框，提示文字
        var warm = "";
        var error = "";
        var Sucess = "";
        var Remark = "";
        var font = "";
    
    
    
    
    
        //——
        //count:生成层组数
        //bg1:警告框及文字颜色
        //bg2:错误框及文字颜色
        //bg3:成功框及文字颜色
        //bg4:提示框及文字颜色
        //bg5:提示文字颜色（默认黑）
        //imgWarm:警告图片
        //imgError:错误图片
        //imgSucess:成功图片
        //imgExplain:提示图片
        //warmContent 警告窗提示內容 默认（系統未檢測到您的輸入）
        //SucessContent 成功框提示內容 默认（內容符合規範，可以使用）
    function _window(count,bg1,bg2,bg3,bg4,bg5,imgWarm,imgError,imgSucess,imgExplain,warmContent,SucessContent){
        strArray = new Array(count); //用于保存所有验证是否成功

        if(bg1=="")content="#000000";
        if(bg2=="")content="#000000";
        if(bg3=="")content="#000000";
        if(bg4=="")content="#000000";
        if(bg5=="")content="#000000";

        if(warmContent=="_M")warmContent="系統未檢測到您的輸入";
        if(SucessContent=="_M")SucessContent="內容符合規範，可以使用";

        for(i=0;i<count;i++){
        
            strArray[i]=false;
            
            var body=document.getElementById(headText+i);
            if(body==null) {
//                alert("未找到指定的标签！");
                return;
            }
//警告        
            body.innerHTML+="<div id='_000_000_div_panda_"+i+"' style='position:absolute; display:none'><table style='border:solid 1px "+bg1+" '><tr><td width='22px'><img alt='' src='"+imgWarm+"' /></td><td id='_000_000_td_panda_"+i+"' style='color:"+bg1+"; font-size:12px' valign='bottom'>"+warmContent+"</td></tr></table></div>";
//错误
            body.innerHTML+="<div id='_000_111_div_panda_"+i+"' style='position:absolute; display:none '><table style='border:solid 1px "+bg2+" '><tr><td width='22px'><img alt='' src='"+imgError+"' /></td><td id='_000_111_td_panda_"+i+"' style='color:"+bg2+"; font-size:12px' valign='bottom'></td></tr></table></div>";
//成功
            body.innerHTML+="<div id='_000_222_div_panda_"+i+"' style='position:absolute; display:none '><table style='border:solid 1px "+bg3+" '><tr><td width='22px'><img alt='' src='"+imgSucess+"' /></td><td id='_000_222_td_panda_"+i+"' style='color:"+bg3+"; font-size:12px' valign='bottom'>"+SucessContent+"</td></tr></table></div>";
//提示框
            body.innerHTML+="<div id='_000_333_div_panda_"+i+"' style='position:absolute; display:none '><table style='border:solid 1px "+bg4+" '><tr><td width='22px'><img alt='' src='"+imgExplain+"' /></td><td id='_000_333_td_panda_"+i+"' style='color:"+bg4+"; font-size:12px' valign='bottom'></td></tr></table></div>";
//提示文字
            body.innerHTML+="<div id='_000_444_div_panda_"+i+"' style='position:absolute; display:block '><table><tr><td id='_000_444_td_panda_"+i+"' style='color:"+bg5+";font-size:12px' valign='bottom'></td></tr></table></div>";

        }
    }
    
    
    
    
    
    //——
    //count:生成层组数 絕對定位
    //bg1:警告框及文字颜色
    //bg2:错误框及文字颜色
    //bg3:成功框及文字颜色
    //bg4:提示框及文字颜色
    //bg5:提示文字颜色（默认黑）
    //imgWarm:警告图片
    //imgError:错误图片
    //imgSucess:成功图片
    //imgExplain:提示图片
    //warmContent 警告窗提示內容 默认（系統未檢測到您的輸入）
    //SucessContent 成功框提示內容 默认（內容符合規範，可以使用）
    function _windowABS(count,bg1,bg2,bg3,bg4,bg5,imgWarm,imgError,imgSucess,imgExplain,warmContent,SucessContent){
        strArray = new Array(count); //用于保存所有验证是否成功
        if(bg1=="")content="#000000";
        if(bg2=="")content="#000000";
        if(bg3=="")content="#000000";
        if(bg4=="")content="#000000";
        if(bg5=="")content="#000000";

        if(warmContent=="_M")warmContent="系統未檢測到您的輸入";
        if(SucessContent=="_M")SucessContent="內容符合規範，可以使用";

        for(i=0;i<count;i++){
        
            strArray[i]=false;
            
            var body=document.getElementById(headText+i);
            if(body==null) {
//                alert("未找到指定的标签！");
                return;
            }
//警告        
            body.innerHTML+="<div id='_000_000_div_panda_"+i+"' style='display:none'><table style='border:solid 1px "+bg1+" '><tr><td width='22px'><img alt='' src='"+imgWarm+"' /></td><td id='_000_000_td_panda_"+i+"' style='color:"+bg1+"; font-size:12px' valign='bottom'>"+warmContent+"</td></tr></table></div>";
//错误
            body.innerHTML+="<div id='_000_111_div_panda_"+i+"' style='display:none '><table style='border:solid 1px "+bg2+" '><tr><td width='22px'><img alt='' src='"+imgError+"' /></td><td id='_000_111_td_panda_"+i+"' style='color:"+bg2+"; font-size:12px' valign='bottom'></td></tr></table></div>";
//成功
            body.innerHTML+="<div id='_000_222_div_panda_"+i+"' style='display:none '><table style='border:solid 1px "+bg3+" '><tr><td width='22px'><img alt='' src='"+imgSucess+"' /></td><td id='_000_222_td_panda_"+i+"' style='color:"+bg3+"; font-size:12px' valign='bottom'>"+SucessContent+"</td></tr></table></div>";
//提示框
            body.innerHTML+="<div id='_000_333_div_panda_"+i+"' style='display:none '><table style='border:solid 1px "+bg4+" '><tr><td width='22px'><img alt='' src='"+imgExplain+"' /></td><td id='_000_333_td_panda_"+i+"' style='color:"+bg4+"; font-size:12px' valign='bottom'></td></tr></table></div>";
//提示文字
            body.innerHTML+="<div id='_000_444_div_panda_"+i+"' style='display:block '><table><tr><td id='_000_444_td_panda_"+i+"' style='color:"+bg5+";font-size:12px' valign='bottom'></td></tr></table></div>";

        }
    }
    
    
    
    
    
    
    
    
    //——
    //判断层组是否生成
    //——
    function _IsNull(count){
        warm = document.getElementById("_000_000_div_panda_"+count);
        error = document.getElementById("_000_111_div_panda_"+count);
        Sucess = document.getElementById("_000_222_div_panda_"+count);
        Remark = document.getElementById("_000_333_div_panda_"+count);
        font = document.getElementById("_000_444_div_panda_"+count);
     
        if(warm==null || error==null || Sucess==null || Remark==null || font==null){
//            alert("未找到所需的提示框！");
 strArray[count]=false;  
            return false;
        }else{
            return true;
        }
    }
    
    
    
    
    
    //——
    //提示文字框
    //——
    //count 对应的层组的索引0开始
    //content 提示文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    //isNull 是否允许为空（必填） N不允许 Y允许 不允许其他值
    function _windowLoadFontBox(count,content,topSize,leftSize,leng,isNull){
        var text="";
        if(isNull=="N"){
            text="<span style='color:Red'>*</span>";
        }else if(isNull=="Y"){
            text="&nbsp;&nbsp;"
        }else return;
        var fontBox = document.getElementById("_000_444_td_panda_"+count);//内容框
        if(fontBox!=null){
            fontBox.innerHTML=text+content;
            fontBox.style.width=leng+"px";
        }
        var _div = document.getElementById("_000_444_div_panda_"+count);//提示框
        if(_div!=null){
            _div.style.marginLeft=leftSize+"px";
            _div.style.marginTop=topSize+"px";
            _div.style.display="block";
        }
    }
   




    //——
    //验证框,验证信息不能为空的
    //——
    //count 对应的层组的索引0开始
    //control this
    //expression 正则表达式
    //content 验证失败是现实的文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    function _windowCheckBox(count,control,expression,content,topSize,leftSize,leng){
        
        if(!(_IsNull(count))) return;//验证
        
       Vs_False();//隐藏层组
        
        //如果没有值则显示警告框
        if(control.value==""){
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
            
            //获取对应的警告框
            var fontBoxValue = document.getElementById("_000_000_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.weidth=leng+"px";
            }
 strArray[count]=false;
            return;
        }
        
        //如果有输入数据则进入已下代码
        _eques(count,control,expression,content,topSize,leftSize,leng);
    }
    
    
    
    
    
    
    //——
    //验证信息可以为空，但输入时却要有一定的格式
    //——
    //count 对应的层组的索引0开始
    //control this
    //expression 正则表达式
    //content 验证失败是现实的文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
     function _windowIsNullNotCheck(count,control,expression,content,topSize,leftSize,leng){
        
        if(!(_IsNull(count))) return;//验证
        
        Vs_False();//隐藏层组
        
        //如果没有值则通过验证
        if(control.value==""){
 strArray[count]=true;
            return;
        }
        
        //如果有输入数据则进入一下代码
        _eques(count,control,expression,content,topSize,leftSize,leng);
    }
    
    
    
    
    //——
    //提取重复代码
    //——
    function _eques(count,control,expression,content,topSize,leftSize,leng){
        var result = control.value.match(expression);
        //验证失败
        if(result==null){
            Sucess.style.display="none";
            
            error.style.display="block";
            error.style.marginLeft=leftSize+"px";
            error.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_111_td_panda_"+count);
            if(fontBoxValue!=null){
                
                fontBoxValue.innerText=content;
                fontBoxValue.style.width=leng+"px";
            }
 strArray[count]=false;
        }
        else{ 
            error.style.display="none";
            
            Sucess.style.display="block";
            Sucess.style.marginLeft=leftSize+"px";
            Sucess.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_222_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
                }
 strArray[count]=true;
        }
    }
    
    
    
    
    //——
    //验证确认密码框
    //——
    //count 对应的层组的索引0开始
    //control this
    //pwdControlID 密码框ID
    //content 验证失败是现实的文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
     function _windowPwdOkBox(count,control,pwdControlID,content,topSize,leftSize,leng){
      
       if(!(_IsNull(count))) return;//验证
        
        //获取密码框
        var pwdControl=document.getElementById(pwdControlID);
        if(pwdControl==null){
            alert("未找到所需的密码框！")
            strArray[count]=false;  
            return;
        }
        
        Vs_False();//隐藏层组
        
        //不允许有空值
        if(control.value==""){
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
 strArray[count]=true;
            return;
        }
        
        //两次密码一样
        if(control.value==pwdControl.value){
            Sucess.style.display="block";
            Sucess.style.marginLeft=leftSize+"px";
            Sucess.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_222_td_panda_"+count);
            if(fontBoxValue!=null){
                
                fontBoxValue.style.width=leng+"px";
            }
 strArray[count]=true;
            return;
        }
        else{
            error.style.display="block";
            error.style.marginLeft=leftSize+"px";
            error.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_111_td_panda_"+count);
            if(fontBoxValue!=null){
                
                fontBoxValue.innerText=content;
                fontBoxValue.style.width=leng+"px";
            }
 strArray[count]=false;
        }
    }
    
    
    
    
    
    //——
    //密码框 得到焦點調用
    //——
    //count 密碼框对应的层组的索引0开始
    //countOK 密码确认框对应的层组索引
    //control this
    //pwdControlID 密码確認框ID
    //content 提示內容
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
     function _windowPwdCheck(count,countOK,control,pwdControlID,content,topSize,leftSize,leng){
      
        if(!(_IsNull(countOK))) return;//验证
        Vs_False();//隐藏层组
        strArray[count]=false;
        strArray[countOK]=false;
      
        
        //获取密码確認框
        var pwdControl=document.getElementById(pwdControlID);
        if(pwdControl==null){
            alert("未找到所需的密码確認框！")
            return;
        }else{
            pwdControl.value="";
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_000_td_panda_"+countOK);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
                }
        }
        
        if(!(_IsNull(count))) return;//验证
        Vs_False();//隐藏层组
        
        if(control.value!=""){
            Remark.style.display="block";
            Remark.style.marginLeft=leftSize+"px";
            Remark.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_333_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.innerText=content;
                fontBoxValue.style.width=leng+"px";
                }
        }else{
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_000_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
            }
        }
    }
    
    
    
    
    
    //——
    //提示框
    //——
    //count 对应的层组的索引0开始
    //control this
    //content 提示文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    function _windowRemarkBox(count,control,content,topSize,leftSize,leng){
        
        if(!(_IsNull(count))) return;//验证
        
        Vs_False();//隐藏层组

        if(control.value!=""){
            Remark.style.display="block";
            Remark.style.marginLeft=leftSize+"px";
            Remark.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_333_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.innerText=content;
                fontBoxValue.style.width=leng+"px";
                }
        }else{
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_000_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
            }
        }
    }
    
    
    
    
    //——
    //验证函数
    //——
    //count 对应的层组的索引0开始
    //control this
    //content 提示文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    function submint(content){
        if(strArray==null)return false;
        for(i=0;i<strArray.length;i++){
            if(!strArray[i]){
                alert(content);
                return false;
            }
        }
        return true;
    }
    
    
    
    
    //——
    //隐藏层组
    //——
    function Vs_False(){
        error.style.display="none";
        Sucess.style.display="none";
        font.style.display="none";
        warm.style.display="none";
        Remark.style.display="none";
    }
    
    
    
    
    
    
    //--
    //自定义(提示成功或者错误)
    //bl 是否通過驗證
    //count 对应的层组的索引0开始
    //content 提示文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    function Custom_Function(bl,count,content,topSize,leftSize,leng){
        if(!(_IsNull(count))) return;//验证
        
        Vs_False();//隐藏层组
        
        //成功
        if(bl){
            strArray[count]=true;
            
            Sucess.style.display="block";
            Sucess.style.marginLeft=leftSize+"px";
            Sucess.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_222_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
            }
        }else{
            strArray[count]=false;
            
            error.style.display="block";
            error.style.marginLeft=leftSize+"px";
            error.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_111_td_panda_"+count);
            if(fontBoxValue!=null){
                
                fontBoxValue.innerText=content;
                fontBoxValue.style.width=leng+"px";
            }
        }
    }
    
    
    
    
    
    
     //--
    //自定义(提示警告)
    //count 对应的层组的索引0开始
    //content 提示文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    function Custom_Function_Warm(count,topSize,leftSize,leng){
        if(!(_IsNull(count))) return;//验证
        
        Vs_False();//隐藏层组

        strArray[count]=false;
            
        warm.style.display="block";
        warm.style.marginLeft=leftSize+"px";
        warm.style.marginTop=topSize+"px";
            
        var fontBoxValue = document.getElementById("_000_000_td_panda_"+count);
        if(fontBoxValue!=null){
            fontBoxValue.style.width=leng+"px";
        }
    }
    
    
    
    //——
    //验证非空
    //——
    //count 对应的层组的索引0开始
    //control this
    //content 验证失败是现实的文字
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
     function _windowNotNull(count,control,content,topSize,leftSize,leng){
        
        if(!(_IsNull(count))) return;//验证
        
        Vs_False();//隐藏层组
        
        //如果没有值则不通过验证
        if(control.value==""){
            warm.style.display="block";
            warm.style.marginLeft=leftSize+"px";
            warm.style.marginTop=topSize+"px";
            strArray[count]=false;
        }else{
            Sucess.style.display="block";
            Sucess.style.marginLeft=leftSize+"px";
            Sucess.style.marginTop=topSize+"px";
            
            var fontBoxValue = document.getElementById("_000_222_td_panda_"+count);
            if(fontBoxValue!=null){
                fontBoxValue.style.width=leng+"px";
                }
 strArray[count]=true;
        }
        
    }
    
    
    
    //--
    //身份证帐号
    //count 对应的层组的索引0开始
    //IDCard this
    //topSize 验证层距离上一标签的上方距离
    //leftSize 验证层距离上一标签的左方距离
    //leng 层内容框的长度
    //--
   function CheckIDCard(count,IDCard,topSize,leftSize,leng){
    
    var  fstr = 0;
    if(IDCard.value==""){
     Custom_Function_Warm(count,topSize,leftSize,leng);
              return;
    }
    switch(IDCard.value.substr(0,1)){          
         case "A":
           fstr = 10
           break;
         case "B":
           fstr = 11
           break;
         case "C":
           fstr = 12
           break;
         case "D":
           fstr = 13
           break;
         case "E":
           fstr = 14
           break;
         case "F":
           fstr = 15
           break;
         case "G":
           fstr = 16
           break;
         case "H":
           fstr = 17
           break;
         case "I":
           fstr = 34
           break;
         case "J":
           fstr = 18
           break;
         case "K":
           fstr = 19
           break;
         case "L":
           fstr = 20
           break;
         case "M":
           fstr = 21
           break;
         case "N":
           fstr = 22
           break;
         case "O":
           fstr = 35
           break;
         case "P":
           fstr = 23
           break;
         case "Q":
           fstr = 24
           break;
         case "R":
           fstr = 25
           break;
         case "S":
           fstr = 26
           break;
         case "T":
           fstr = 27
           break;
         case "U":
           fstr = 28
           break;
         case "V":
           fstr = 29
           break;
         case "W":
           fstr = 32
           break;
         case "X":
           fstr = 30
           break;
         case "Y":
           fstr = 31
           break;
         case "Z":
           fstr = 33
           break;
         default:
           break;                   
      }
          
   switch(IDCard.value.length){   
      case 10:
       ereg=/^[A-Z ][1-2][0-9]{8}$/;
       if(ereg.test(IDCard.value)){
     var lstr = parseInt((fstr.toString()).substr(0,1));
     var rstr = parseInt((fstr.toString()).substr(1,1));
     var str = parseInt(lstr) + parseInt(rstr)*9 + parseInt(IDCard.value.substr(1,1))*8 + parseInt(IDCard.value.substr(2,1))*7 + parseInt(IDCard.value.substr(3,1))*6
            + parseInt(IDCard.value.substr(4,1))*5 + parseInt(IDCard.value.substr(5,1))*4 + parseInt(IDCard.value.substr(6,1))*3
            + parseInt(IDCard.value.substr(7,1))*2 + parseInt(IDCard.value.substr(8,1))*1;
     var cc = (str.toString()).substr((str.toString()).length-1,1);
     var dd = parseInt(cc);
     if((10-dd)==parseInt(IDCard.value.substr(9,1))){
              
               Custom_Function(true,count,"",topSize,leftSize,leng);
               return;
     }else{
                Custom_Function(false,count,"身份證字碼無效",topSize,leftSize,leng);
                return;
     }   
  }else{
              Custom_Function(false,count,"身份證字碼無效"+IDCard.value.substr(9,1),topSize,leftSize,leng);
              return;
       }
       break;
       default:
           Custom_Function(false,count,"身份證字碼無效",topSize,leftSize,leng);
           return ;
  }
 } 
    
    


