function UpadteCurrentAdvancedSetting(curkey)
{
    var doc = currentPrefItemDoc;
    var root = DomHelper.getChildNode(doc);
    var node = DomHelper.getChildNode(root);
    while(node)
    {
        try
        {
            UpdateMccoreValue(mccoreDoc, node.getAttribute("key"), DomHelper.getNodeValue(node));
        }
        catch(e)
        {
           dumpErr(e);
        }
        node = DomHelper.getNextNode(node);
    }
    var data = filterMcXml(mccoreDoc);
    var subDoc = data["doc"];
    transformXMLId(subDoc, xslPrefsdoc, "adv_pref");
    ShowValue(curkey, true);
}

function UpdateCurrentCoderSetting()
{
    var doc = currentPrefItemDoc;
    var root = DomHelper.getChildNode(doc);
    var node = DomHelper.getChildNode(root);
    while(node)
    {
        try
        {
            UpdateMccoreValue(mccoreDoc, node.getAttribute("key"), DomHelper.getNodeValue(node));
        }
        catch(e)
        {
           dumpErr(e);
        }
        node = DomHelper.getNextNode(node);
    }
    var data = filterMcXml(mccoreDoc);
    var subDoc = data["doc"];
    if(currentPrefType == PREFVIDEOCODEC)
    {				
        var coder = data["coder"];
        if(coder == "x264")
        {
            var xslX264doc = LoadPrefDocByPath("xslt/deck_video/deck_h264.xsl");
            transformXMLId(subDoc, xslX264doc, "adv_coder_mode");
        }
        else if(coder == "xvid")
        {
             var xslXvidDoc = LoadPrefDocByPath("xslt/deck_video/deck_xvid.xsl");
            transformXMLId(subDoc, xslXvidDoc, "adv_coder_mode");
        }
        else if(coder == "cuda264")
        {
             var xslDoc = LoadPrefDocByPath("xslt/deck_video/deck_cuda264.xsl");
            transformXMLId(subDoc, xslDoc, "adv_coder_mode");
        }
    }
    else if(currentPrefType == PREFAUDIOCODEC)
    {
        var coder = data["coder"];
        if(coder == 'lame')
        {
            var xslDoc = LoadPrefDocByPath("xslt/deck_audio/deck_mp3lame.xsl");
            transformXMLId(subDoc, xslDoc, "adv_coder_mode");
        }
        else if(coder == 'faac')
        {
            var xslDoc = LoadPrefDocByPath("xslt/deck_audio/deck_faac.xsl");
            transformXMLId(subDoc, xslDoc, "adv_coder_mode");
        }
         else if(coder == 'nero')
        {
            var xslDoc = LoadPrefDocByPath("xslt/deck_audio/deck_nero.xsl");
            transformXMLId(subDoc, xslDoc, "adv_coder_mode");
        }
    }
}

function OnTextboxChange2(e, key, byNum)
{
    var val = e.value;
    if(byNum)
    {
        val = parseInt(e.value)*byNum;
    }
    chagneCurDoc(key, val);
    UpadteCurrentAdvancedSetting(key);
}
function OnMenuChange2(e, key)
{
   var val = e.value;
   if(!val)
   {
    val = e.getAttribute("label");
   }
    chagneCurDoc(key, val);
    UpadteCurrentAdvancedSetting(key);
}

function OnCheckboxChange2(e, key)
{
    chagneCurDoc(key, e.checked);
    UpadteCurrentAdvancedSetting(key);
}

function OnOpenAdvancedSplitter(id)
{
    var e = $e(id);
    var state = e.getAttribute("state");
    if(state == "open")
    {
        e.setAttribute("state","collapsed");
    }
    else
    {
        e.setAttribute("state","open");
    }
}

function OnEnableChange(e, ids)
{
    var index = e.selectedIndex;
    for(var i= 0;i<ids.length;++i)
    {
        $e(ids[i]).setAttribute("disabled","true");
    }
    $e(ids[index]).removeAttribute("disabled");
}