 
 var oAutoRunChk=0;
 var ocreateLnkCkb=0;
 var oaccleratorKeyIpt;
 var oaccleraEnableChk;
 var oaccleraGroup;
 var octrlChk;
 var oaltChk;
 var oshtChk;
 var owinChk;
 
var g_bCtrl  = false;
var g_bAlt   = false;
var g_bShift = false;
var g_bWin = false;
var otips; 



function mapKeyPressToActualCharacter(characterCode)
{
    var ch= -1; 
    switch(characterCode) 
    {
    case 9:
       ch='Tab';
       break;
    case 19: 
        ch='Pause Break';
    	break; 
    case 38: //up arrow 
        ch='↑';
    	break; 
    case 40: //down arrow 
        ch='↓';
    	break;
    case 33: //page up 
    	ch='Pup';
    	break;
    case 34: //page down 
    	ch='Pdn';
    	break;
    case 36:
    	ch='Home';
    	break;
    case 35: //end   
    	ch='End';
    	break;
    case 37: //left arrow 
        ch='←';
    	break;
    case 39: //right arrow 
        ch='→';
    	break;
    case 32:
        ch ='空格';
    	break;
 
    case 112: 
        ch ='F1';
    	break;
    case 113: 
        ch ='F2';
    	break;
    case 114:  
        ch ='F3';
    	break;
    case 115: 
        ch ='F4';
    	break;
    case 116: 
        ch ='F5';
    	break;
    case 117:  
        ch ='F6';
    	break;
    case 118: 
        ch ='F7';
    	break;
    case 119: 
        ch ='F8';
    	break;
    case 120:  
        ch ='F9';
    	break;
    case 121: 
        ch ='F10';
    	break;
    case 122: 
        ch ='F11';
    	break;
    case 123:  
        ch ='F12';
    	break;
    case 13: //enter 
    case 9:  //tab 
    case 27: //esc 
    case 16: //shift 
    case 17: //ctrl 
    case 18: //alt 
    case 20: //caps lock
    case 8:  //backspace 
    case 46: //delete 
        ch='';
    	break;
    default:
    
    } 
    return ch;
}
 
// Comm.addEvent(document, 'keydown',function (e) 
// {
//    e = e||window.event;
//    alert(2);
//    Comm.cancelEvent(e);
// });
 
function BtnOkTrigger() 
{
    Comm.$('setting').click();
} 

function KeyDownHandler(e) 
{
    if (oaccleraGroup.disabled) 
    {
        return;
    }
    
    e = e||window.event; 
    if (e.keyCode == 13) 
    {
        Comm.$('setting').click();
        //alert('回车');
        return;
    }
        

    
    g_bCtrl = e.ctrlKey;
    g_bAlt  = e.altKey;
    g_bShift = e.shiftKey;
    g_bWin   = ( ( e.keyCode == 91 )|| ( e.keyCode == 92 ) ); 
    
    oaccleratorKeyIpt.value='';
    oaccleratorKeyIpt.keyCode =-1;

    var sVal='';
 
    var ch = mapKeyPressToActualCharacter(e.keyCode);//String.fromCharCode(e.keyCode);
    if (ch!=-1) 
    {
        //按键值需要被处理
        oaccleratorKeyIpt.value=ch;
    }else
    {  
        ;//oaccleratorKeyIpt.value.toUpperCase();//
    }
      
    oaccleratorKeyIpt.keyCode = e.keyCode;
    //otips.innerHTML =String.fromCharCode(e.keyCode) +', '+ e.keyCode;

    g_bCtrl  = false;
    g_bAlt   = false;
    g_bShift = false;
    g_bWin   = false;  
    
    Comm.cancelEvent(e); 
};
 
 Comm.ReadyDoc(function () 
 {
    oAutoRunChk = Comm.$('AutoRunChk');
    ocreateLnkCkb= Comm.$('createLnkCkb');
    oaccleratorKeyIpt = Comm.$('accleratorKeyIpt');
    oaccleraEnableChk   = Comm.$('accleraEnableChk');
    oaccleraGroup   = Comm.$('accleraGroup');
    octrlChk = Comm.$('ctrlChk');
    oaltChk = Comm.$('altChk');
    oshtChk = Comm.$('shtChk');
    owinChk = Comm.$('winChk');
    otips = Comm.$('tips');
 
 
    Comm.addEvent(oaccleraEnableChk,'click',function () 
    {
        if (oaccleraEnableChk.checked ==true) 
        {
            oaccleraGroup.disabled = false;
            oaccleraEnableChk.checked=true;
        }else
        {
            oaccleraGroup.disabled = true;
            oaccleraEnableChk.checked=false;
        }
    })
    
    //KeyDownHandler
    Comm.addEvent(oaccleratorKeyIpt,'keydown', function (e) 
    {  
        KeyDownHandler(e);
    });
//    Comm.addEvent(oaccleratorKeyIpt,'keypress',function (e) 
//    {
//        oaccleratorKeyIpt.value = oaccleratorKeyIpt.value.toUpperCase();
//        alert(oaccleratorKeyIpt.value);
//    });
    
    Comm.addEvent(Comm.$('setting'),'click',function () 
    {
        var sAutoRun = '0',sCreateLnk='0', sAcclerateKeys='';
        if (oAutoRunChk.checked) 
        {
            sAutoRun = '1';
        }
        
        if (ocreateLnkCkb.checked) 
        {
            sCreateLnk = '1';
        }     
        
        if (oaccleraEnableChk.checked ==true) 
        {
            if (!/\S{1}/gi.test(oaccleratorKeyIpt.value)) 
            {
                alert('请至少指定一个字符键');
                return;
            }
        }
        
        if (oaccleraEnableChk.checked ==true) 
        {
            sAcclerateKeys +='1,';
        }else
        {
            sAcclerateKeys +='0,';
        }
        
        if (octrlChk.checked ==true) 
        {
            sAcclerateKeys +='1,';
        }else
        {
            sAcclerateKeys +='0,';
        }
        
        if (oaltChk.checked ==true) 
        {
            sAcclerateKeys +='1,';
        }else
        {
            sAcclerateKeys +='0,';
        }
        
        if (oshtChk.checked ==true) 
        {
            sAcclerateKeys +='1,';
        }else
        {
            sAcclerateKeys +='0,';
        }
        
        if (owinChk.checked ==true) 
        {
            sAcclerateKeys +='1,';
        }else
        {
            sAcclerateKeys +='0,';
        }
        
        sAcclerateKeys += oaccleratorKeyIpt.keyCode+',';//oaccleratorKeyIpt.value.toUpperCase();
        
        if (oaccleratorKeyIpt.value ==',') 
        {
            sAcclerateKeys += 'MLGB';
        }else
        sAcclerateKeys += oaccleratorKeyIpt.value.toUpperCase();
             
        window.external.saveXmlCfg(sAutoRun, sCreateLnk, sAcclerateKeys);

        //window.external.CB_Close();
    });
    
    var oRadios = document.getElementsByTagName('input');
    for(var i=0;i<oRadios.length;i++)
    {
        var oRadio = oRadios[i];
        if (oRadio.type != 'checkbox') 
        {
            continue; 
        }
        
        //取得单选按钮的前一个元素
        var oNext  = oRadio.nextSibling;//previousSibling;
        if (oNext && oNext.tagName && oNext.tagName.toLowerCase()=='span') 
        {
            oNext.className += ' radioNxt';
    
            Comm.addEvent(oNext,'click',function () 
            {
                if (this.previousSibling) 
                {
                    this.previousSibling.click();
                }
            }) ;

            var oChildsIpt = oNext.getElementsByTagName('input');
            for(var j=0;j< oChildsIpt.length;j++)
            {
                Comm.addEvent(oChildsIpt[j],'focus',function () 
                {
                    if (this.parentNode.previousSibling) 
                    {
                        this.parentNode.previousSibling.click();
                    }
                }); 
            }        
        }//if oNext
        
    }//for
 });
 
 function closeDlg() 
 {
    window.external.CB_Close();
 }
 
 function faildTips(s) 
 {
    alert(s);
 }
 
 function Init( s) 
 {
    xmlDoc = new OHSXml();  
    xmlDoc.loadXML('<customer>'+s+'</customer>');
    //alert(xmlDoc.xmlDoc.xml);

    var autoRunNd = xmlDoc.selectSingleNode( "//AppAutoRun" );
    if (!autoRunNd) 
    {
        return;
    }
    var sVal = autoRunNd.text
  
    if (sVal == '1') 
    {
        oAutoRunChk.checked= true;
    }else 
    {
        oAutoRunChk.checked= false;    
    }
    
    var DesktopLnkNd = xmlDoc.selectSingleNode( "//DesktopLnkExists" );
    if (!DesktopLnkNd) 
    {
        return;
    }
    var sVal = DesktopLnkNd.text
  
    if (sVal == '1') 
    {
        ocreateLnkCkb.checked= true;
    }else 
    {
        ocreateLnkCkb.checked= false;  
    }
    
    //<AcceleraKey><![CDATA[1,0,1,0,0,190,Z]]></AcceleraKey>
    var AcceleraKeyNd = xmlDoc.selectSingleNode( "//AcceleraKey" );
    if (!AcceleraKeyNd) 
    {
        return;
    }
    var sVal = AcceleraKeyNd.text
    sVal = sVal.split(',');
    if (sVal.length < 7) 
    {
        //format is invalid!
        return;
    }
    
    //ctrl key
    if (sVal[1]=='1') 
    {
        
        octrlChk.checked = true;
    }else
    {
        octrlChk.checked = false;    
    }
    
    //alt key
    if (sVal[2]=='1') 
    {
        
        oaltChk.checked = true;
    }else
    {
        oaltChk.checked = false;    
    }    
    
    //alt key
    if (sVal[3]=='1') 
    {
        
        oshtChk.checked = true;
    }else
    {
        oshtChk.checked = false;    
    }  
    
    //win key
    if (sVal[4]=='1') 
    {
        
        owinChk.checked = true;
    }else
    {
        owinChk.checked = false;    
    } 
    oaccleratorKeyIpt.keyCode = parseInt(sVal[5],10);

    if (sVal[6]=='MLGB') 
    {
        sVal[6] =',';
    }
    oaccleratorKeyIpt.value = sVal[6]; 
 
    //enabled?
    if (sVal[0]=='1') 
    {
        oaccleraEnableChk.checked = true;
    }else
    {
        oaccleraEnableChk.click();  
        oaccleraEnableChk.checked = false;  

    }
}