﻿// JScript 文件

// JScript 文件
    function isObject(obj){
        if (obj != null && typeof(obj) != "undefined")
            return true;
          else
            return false;
     }
     
     function focusFirstElement(formName){
         var form = document.forms[formName];
         if (!isObject(form) || form.tagName != "FORM")
             return;
             
         var elements = form.elements;
         for (var i = 0; i < elements.length; i++) {
             if (elements[i].type == 'text' && !elements[i].disabled) {
                 elements[i].focus();
                 break;
             }
         }
     }
     
     function fillNumbericOptions(start, end, val){
         var str = "";
         for (var i=start; i<=end; i++){
             str += "<option value='" + i + "'" ;
             if (i == val)
                 str += " selected";
             str += " >" + i + "</option>";
         }

         document.write (str);
     }
     
     function fillOptions(data, val){
         var str = "";
         for (var i=0; i<data.length; i++){
            
             str += "<option value='" + data[i][0] + "'" ;
             if (data[i][0] == val)
                 str += " selected";
             str += " >" + data[i][1] + "</option>";
             
         }
         
         document.write (str);
     }
     
     function fillQuestionOptions(val){
        fillOptions(hintQuestionList, val);
     }
     
     function fillIDTypeOptions(val){
        fillOptions(IDCardTypeList, val);
     }
     
     function fillSecureOptions(val){
         
        fillOptions(updateSecureList, val);
     }
     
    function getHintQuestion(val){
         if (val == "")
             return val;
             
         for (var i=0; i<hintQuestionList.length; i++){
             if (hintQuestionList[i][0] != "" && hintQuestionList[i][0] == val)
                 return hintQuestionList[i][1];
         }
     }
     
     function getUpdateSecure(val){
         if (val == "")
             return val;
            
         for (var i=0; i<updateSecureList.length; i++){
             if (updateSecureList[i][0] != "" && updateSecureList[i][0] == val)
                 return updateSecureList[i][1];
         }
     }
     
     function getIDCardType(val){
         if (val == "")
             return val;
             
         for (var i=0; i<IDCardTypeList.length; i++){
             if (IDCardTypeList[i][0] != "" && IDCardTypeList[i][0] == val)
                 return IDCardTypeList[i][1];
         }
     }
     
     function getCountry(val){
         if (val == "")
             return val;
         
        for (var i=0; i<countryList.length; i++){
            if (countryList[i][0] != "" && countryList[i][0] == val)
                return countryList[i][1];
        }
    }
    
    function hideSelectForm(){
        var opts = document.getElementsByTagName("SELECT");
        if (opts == null || typeof(opts) == "undefined")
            return ;
            
        for (var i=0; i<opts.length; i++){
            opts[i].style.visibility = "hidden";
        }
    }
    
    function showSelectForm(){
        var opts = document.getElementsByTagName("SELECT");
        if (opts == null || typeof(opts) == "undefined")
            return ;
            
        for (var i=0; i<opts.length; i++){
            
            opts[i].style.visibility = "visible";
        }
    }
    
    function createBgDiv(id){
        if (!isObject(id))
            id = "backgroundDiv";
           
        offHeight = window.screen.height;
        var div = document.createElement("DIV");
        div.id = id;
        div.style.left = 0;
       div.style.top = 0;
        div.style.width=document.body.scrollWidth;
        div.style.height = document.body.scrollHeight;
        div.style.position = "absolute";
        div.style.display = "";
        div.style.zIndex = "999";
        div.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
        div.style.backgroundColor="#efefef";
        document.body.appendChild(div);
        hideSelectForm();
        
        fadeBg(50, id);
        
        return div;
    }
    
    function fadeBg(index, str){
        var obj = document.getElementById(str);
       obj.style.filter = "alpha(Opacity=" + index + ")";
        
        if (index < 50)
            window.setTimeout("fadeBg(" + (index+5) + ", '" + str + "')", 10);
        
    }
