var orArrowSpan;
var olArrowSpan;
var onongliFestSel; 
var oyangliFestSel;
var ojieqiFestSel;
var oweekFestSel;
var oactionSel;
var oactCntDiv;
var ochildTskCntDiv;
var oactionAddBtn;

var osongfileIpt;
var oappfileIpt;
var oappParamIpt;   
    
var ogChildTskGroup;
var ogTask;
var oxmlTaskDoc  ;

var ogActionGroup;
var oxmlActionGroupDoc;

var TSKSTATE = {'RUNNING':1
,'STOP':2
,'PAUSE':4
,'FORDELETE':8
,'EXPIRED':16
,'OVERDAY':32
};

var gTskId=0;//任务唯一ID,用于编辑后修改目标任务时进行查找和定位的依据
var gTskState=TSKSTATE.RUNNING;//任务状态，0表示运行，1表示暂停，2表示待删除，3表示过期，具体见\MemMapXml\TskTimer.h  enum TSKSTATE
var otitle_div;
var otskNameIpt;

var oday0;
var ohour0;
var ominute0;
var osecond0;

var ooffsetDayIpt ;
var ooffsetHourIpt ;
var ooffsetMinIpt;
var ooffsetSecIpt ;
var orunTimesIpt ;
var oIntvlMonIpt;
var oIntvlDayIpt ;
var oIntvlHourIpt;    
var oIntvlMinIpt ;
var oIntvlSecIpt ; 
var actionNameAr ;
var oRd02;

var oRd10;
var oRd11;
var oRd12;    
var oRd13; 
	


//显示当前时间
function CurentTime() 
{ 
    var now = new Date(); 
    var y,m,d;
    y = now.getFullYear();
    m = now.getMonth()+1;
    d = now.getDate();
    
    var hh = now.getHours(); 
    var mm = now.getMinutes(); 
    var ss = now.getTime() % 60000; 
    ss = (ss - (ss % 1000)) / 1000; 
    var clock = y+'年 '+m+'月 '+d+'日   '+hh+':'; 
    if (mm < 10) clock += '0'; 
    clock += mm+':'; 
    if (ss < 10) clock += '0'; 
    clock += ss; 
    return(clock); 
}

var ocurrTimeSpan =null;
function refreshCalendarClock() 
{
     ocurrTimeSpan.innerHTML = CurentTime();
}

function GetRadioChecked(oRadios) 
{
    for(var i=0;i<oRadios.length;i++)
    {
        var o = oRadios[i];
        if (o.checked) 
        {
            return o;
        }
    }
}

function EnabledAllChilds(oParent,bEnable) 
{
    var oChilds = oParent.childNodes;//o.firstChild;//

    for(var i=0 ;i<oChilds.length;i++)
    {
        var o = oChilds[i];
        if (o.disabled==null || o.disabled=='undefined') 
        {
           continue;
        }
        o.disabled = !bEnable;
        //o  = o.nextSibling;
        //s+= o.tagName;
    } 
    oParent.disabled = !bEnable;    
    //oactCntDiv.innerHTML = s;    
}

function GetDaysOfCurrMonth(nYear, nMonth)
{
    var bIsLeap = (nYear%400==0) || (nYear%100!=0&& nYear%4==0);
    var nTotalDays = 0;

    switch (nMonth)
    {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            nTotalDays=31;
            break;
        case 2:
            if (bIsLeap)
            {
                nTotalDays = 29;
            }else
            {
                nTotalDays=28;
            }
            break;

        default:
            nTotalDays=30;
            break;
    }
    return nTotalDays;
}//int GetDaysOfCurrMonth(int nMonth, int nYear)

var oyearSel0 = 0;
var omonthSel0 = 0; 
var odaySel0  = 0;

function BuildYSel(curY) 
{
    oyearSel0 = Comm.$('yearSel0');
    
    if (oyearSel0.options.length ==0) 
    {
        for(var i=1901;i<2051;i++)
        { 
            var oP = new Option(i,i);
            if (curY==i) 
            {
                oP.selected=true;
            }
            oyearSel0.options.add(oP);
        }         
    }
    var n= curY-1901;
    oyearSel0.options[n].selected = true;
}

//通过给定的年份，重建月下拉框
function BuildMSel(y, curY,curM) 
{
    omonthSel0 = Comm.$('monthSel0'); 
     
    var nlen = omonthSel0.options.length;
    for(var i= 0;i< nlen;i++)
    {
        omonthSel0.options.remove(i);
    }
//    var nOldSel = 0;
//    if (omonthSel0.options.length>0) 
//    {
//        nOldSel = omonthSel0.selectedIndex +1;
//    }
    omonthSel0.options.length=0;  
    
    var leapMon = 0;
        
 
    //阴历单选钮被选定
    if (oRd02.checked) 
    {
        leapMon = leapMonth(y);
    }
    
    var nTotalM = 12;
//    if (leapMon!=0) 
//    {
//         nTotalM = 13; 
//    }
    
    var i = j = 1; 
    for(i=j=1;i<= nTotalM;i++,j++)
    { 
        var oP = new Option(i,j);
        if (curM==i && curY == y)
        {
            oP.selected=true;
        }
        omonthSel0.options.add(oP);
        if (i == leapMon) 
        {
            //闰几月，就是在该月后加闰
            oP = new Option('闰'+i+'月',j+1);
            omonthSel0.options.add(oP);
            j++;
        }
    }
}//BuildMSel

//通过给定的年份和月份，重建日下拉框 
function BuildDSel(y,m,daysCurMonth, curY,curM,curD) 
{
    odaySel0  = Comm.$('daySel0');
    var nOldSel = 0;
//    if (odaySel0.options.length>0) 
//    {
//        nOldSel = odaySel0.selectedIndex +1 ;
//    }  
    odaySel0.options.length=0;  
    
    if (curY==y && curM==m ) 
    {
        for(var i=1;i<= daysCurMonth;i++)
        {
            var oP = new Option(i,i);
            if (curD==i) 
            {
                oP.selected=true;
            }
            odaySel0.options.add(oP);
        }
    }else
    {
        for(var i=1;i<= daysCurMonth;i++)
        {
            var oP = new Option(i,i);
            
            odaySel0.options.add(oP);
        }    
    }
}//BuildDSel(y,m) 


function CreateActTag(oParent, sCnt, oAction)
{
    var ndId     = oAction.selectSingleNode('Id');
//    var ndType   = oAction.selectSingleNode('Type');
//    var ndParam0 = oAction.selectSingleNode('Param0');
//    var ndParam1 = oAction.selectSingleNode('Param1');
//    var ndParam2 = oAction.selectSingleNode('Param2');
    
    //alert(ndId.text);
    //我先查找oParent中是否存在相同的节点，如果存在，即替换，否则追加
    var oOldSpan=null;
    var i=0;
    for(i=0;i< oParent.childNodes.length;i++)
    {
        if (oParent.childNodes[i].id == ndId.text) 
        {
            oOldSpan = oParent.childNodes[i];
            break;
        }
    }
            
    var oTaskSpan = document.createElement('span');
    oTaskSpan.className = 'actBar';

    var _Id0 = 'dateSelectSpan' + (Math.random() * 1000000).toFixed(0);
    var _Id1 = 'delTblSpan' + (Math.random() * 1000000).toFixed(0);
    oTaskSpan.innerHTML = '<span class="left actTagName" title="'+sCnt+'" id="' + _Id0 + '">' + sCnt + '</span><b class="right actDel" title="删除" id="' + _Id1 + '">&nbsp;</b>';
 
    var omsgTips = Comm.$('msgTips');
    if (oOldSpan) 
    {
        oTaskSpan.id= ndId.text;   
        oParent.replaceChild(oTaskSpan,oOldSpan); 
        //omsgTips.innerHTML ='修改成功';   
    }else
    {
        var _Id3 = 'TskSpan' + (Math.random() * 1000000).toFixed(0); 
        oTaskSpan.id= _Id3;    
        oParent.appendChild(oTaskSpan);
        //omsgTips.innerHTML ='添加成功';  
    }

    Comm.addEvent(Comm.$(_Id0), 'click', function ()
    {
        //编辑，修改
        var i=0;
        for(i=0;i< oParent.childNodes.length;i++)
        {
            if (oParent.childNodes[i].id == this.parentNode.id) 
            {
               break;
            }
        }
        
        if (i == oParent.childNodes.length) 
        {
           return;
        }
        
        var currNode = ogActionGroup.childNodes[i];
        var ndType   = currNode.selectSingleNode('Type');
        var ndParam0 = currNode.selectSingleNode('Param0');
        var ndParam1 = currNode.selectSingleNode('Param1');
        var ndParam2 = currNode.selectSingleNode('Param2');
        
        oactionAddBtn._ActId = ndType.text;//this.parentNode.id;
 
        //现在可以根据currNode各值，更改组件状态
        if (oactionSel.options.selectedIndex != ndType.text) 
        {
            oactionSel.options[ndType.text].selected = true;
            oactionSel.fireEvent('onchange');//fireEvent,IE5.5或以上              
        }else
        {
           //alert(oactionSel.options.selectedIndex +', '+ ndType.text);        
        }

        // "待机","休眠","关机","注销","重启","播放音乐","指定应用"
        switch(ndType.text) 
        {
        case '0':
        	break;
        case '1':
        	break;
        case '2':
        	break;
        case '3':
        	break;
        case '4':
        	break;
        case '5':
            //"播放音乐"
            osongfileIpt.value = ndParam0.text;
        	break;
        case '6':
            //"指定应用"
            oappfileIpt.value  = ndParam0.text; 
            oappParamIpt.value = ndParam1.text;            
        	break; 
        } 
    });
    
    Comm.addEvent(Comm.$(_Id1), 'click', function ()
    {
	    var tipmsg = '确定要删除 '+sCnt+' 吗?';
        if (!confirm(tipmsg)) 
        {
		    return ;
        }
        var i=0;
        for(i=0;i< oParent.childNodes.length;i++)
        {
            if (oParent.childNodes[i].id == this.parentNode.id) 
            {
               break;
            }
        }
 
        var currNode = ogActionGroup.childNodes[i];//selectSingleNode("//Actions/Action["+nLine+"]");
        ogActionGroup.removeChild(currNode);
        
        //删除当前标签
        oTaskSpan.parentNode.removeChild(oTaskSpan);
    });
}

function StopUpdateLeftTimeLoop(bStop, _Id) 
{
    var _Id7 = 'leftTimeSpan_'+ _Id;
    var oLeftTimerTag = Comm.$(_Id7);
    if (!oLeftTimerTag) 
    {
        return;
    } 
    
    oLeftTimerTag.Stop = bStop;       
}

function UpdateLeftTime(nTotalSeconds, loopTimes, nState, y,m,d,h,minu,sec, _Id) 
{
    var _Id7 = 'leftTimeSpan_'+ _Id;
    var oLeftTimerTag = Comm.$(_Id7);
    if (!oLeftTimerTag) 
    {
        return;
    } 
    
    if (oLeftTimerTag.timer) 
    {
        clearTimeout(oLeftTimerTag.timer);oLeftTimerTag.timer=null;
    }
    
    oLeftTimerTag.nTotalSeconds = nTotalSeconds;
    
    var s = '';//'剩余时间： ';
 
    var nTmp = parseInt(nState,10);
    switch(nTmp) 
    {
    case TSKSTATE.RUNNING://正在运行
	    break;
    case TSKSTATE.STOP: //stop
        s = '已停止';
	    break;
    case TSKSTATE.PAUSE: //暂停
        s = '已暂停';
	    break;	    
    case TSKSTATE.FORDELETE: //待删除
        s = '待删除';
	    break;	
    case TSKSTATE.EXPIRED: //过期
        s = '已过期';
	    break;	
    case TSKSTATE.OVERDAY: //过期
        s = '触发时机超过一天';
	    break;	
    default:
	    break;
    } 
          
    if (nTmp&TSKSTATE.OVERDAY) 
    {
        s = '触发时机超过一天';
    }
    
    if ( nState != ''+TSKSTATE.RUNNING ) 
    { 
        oLeftTimerTag.innerHTML = s;
        return;        
    }
    
    if ((y=='0' && m=='0' && d=='0' && h=='0' && minu =='0' && sec =='0') || loopTimes=='0') 
    {
        oLeftTimerTag.innerHTML = '任务结束';
        return;
    }

    var oJson = eval(Comm.GetDateNxtSecs(y,m,d,h,minu,sec,-1));
    nTotalSeconds--;

    y    = oJson[0].y;
    m    = oJson[0].m;
    d    = oJson[0].d;
    h    = oJson[0].h;
    minu = oJson[0].minu;
    sec  = oJson[0].sec;

    s='';
    if (y!=0) 
    {
       s += y+'年 ';
    }else
    {
        if (m!=0) 
        {
           s += m+'月 ';
        }else
        {
            if (d!=0) 
            {
               s += d+'天 ';
            }else
            {
                if (h!=0) 
                {
                   s += h+'小时 ';
                }
                
                if (minu!=0) 
                {
                   s += minu+'分 ';
                } 
                
                if (sec!=0) 
                {
                   s += sec+'秒';
                }             
            }            
        }    
    } 

    if (loopTimes=='-1') 
    {
       s +=',无限次';
    }else
    {
       s +=','+loopTimes+'次';
    } 
 
    if ((y==0 && m==0 && d==0 && h==0 && minu ==0 && sec <=0) || loopTimes=='0') 
    {
        oLeftTimerTag.innerHTML = '任务结束';
        return;
    }else
    {
        oLeftTimerTag.innerHTML = s; 
    }
    
    if (oLeftTimerTag.Stop == '1' ) 
    {
        oLeftTimerTag.timer = Comm.setTimeout(UpdateLeftTime, 1000*24*60*60*1000, nTotalSeconds, loopTimes, nState, y, m, d, h, minu, sec, _Id);    
    }else
    {
        oLeftTimerTag.timer = Comm.setTimeout(UpdateLeftTime, 1000, nTotalSeconds, loopTimes, nState, y, m, d, h, minu, sec, _Id);  
    }
}

function UpdateTskTag(_Id, sKey, sVal) 
{
    var xPath    = '//Task[Id="'+ _Id +'"]';
    var currNode = ogChildTskGroup.xmlDoc.selectSingleNode(xPath);
     
    sKey = sKey.toLowerCase();
    if (sKey == 'updatetimes') 
    {
        currNode = currNode.selectSingleNode('Freq/Times');
        if (currNode) 
        { 
            currNode.text = sVal;
        }
    }
}//UpdateTskTag

function CreatTskTag(oParent,sCnt, _Id, sState) 
{
    var oTaskSpan = document.createElement('span');
    oTaskSpan.className = 'tskBar';

    var _Id0 = 'dateSelectSpan' + (Math.random() * 1000000).toFixed(0);
//    var _Id1 = 'delTblSpan' + (Math.random() * 1000000).toFixed(0);
//    var _Id2 = 'editTblSpan' + (Math.random() * 1000000).toFixed(0);
//    var _Id3 = 'movedownTblSpan_'+ (Math.random() * 1000000).toFixed(0);
//    var _Id4 = 'moveupTblSpan_'+ (Math.random() * 1000000).toFixed(0);
//    
//    var _Id5 = 'pauseTblSpan_'+ (Math.random() * 1000000).toFixed(0);
//    var _Id6 = 'startTblSpan_'+ (Math.random() * 1000000).toFixed(0);
//    var _Id7 = 'leftTimeSpan_'+ (Math.random() * 1000000).toFixed(0);
    
    var _Id1 = 'delTblSpan_'  + _Id;
    var _Id2 = 'editTblSpan_' + _Id;
    var _Id3 = 'movedownTblSpan_'+ _Id; 
    var _Id4 = 'moveupTblSpan_'+ _Id;
    
    var _Id5 = 'pauseTblSpan_'+ _Id;
    var _Id6 = 'startTblSpan_'+ _Id;
    var _Id7 = 'leftTimeSpan_'+ _Id;
    
    oTaskSpan.id= _Id;
 
     oTaskSpan.innerHTML = '<span class="left tskTagName" title="' + sCnt + '" id="' + _Id0 + '">' + sCnt + '</span>' 
    + '<b class="right tskDel"      onmouseover="this.className=\'right tskDelOver\';"     onmouseout="this.className=\'right tskDel\';"      title="删除" id="' + _Id1 + '">&nbsp;</b>'
    + '<b class="right tskEdit"     onmouseover="this.className=\'right tskEditOver\';"    onmouseout="this.className=\'right tskEdit\';"     title="编辑" id="' + _Id2 + '">&nbsp;</b>'
    + '<b class="right tskMoveDn"   onmouseover="this.className=\'right tskMoveDnOver\';"  onmouseout="this.className=\'right tskMoveDn\';"   title="下移" id="' + _Id3 + '">&nbsp;</b>'
    + '<b class="right tskMoveUp"   onmouseover="this.className=\'right tskMoveUpOver\';"  onmouseout="this.className=\'right tskMoveUp\';"   title="上移" id="' + _Id4 + '">&nbsp;</b>';
    
    
    if (parseInt(sState,10) & TSKSTATE.PAUSE) 
    {
        //pause
        oTaskSpan.innerHTML+= '<b class="right tskPause"  onmouseover="this.className=\'right tskPauseOver\';" onmouseout="this.className=\'right tskPause\';"  title="开始" id="' + _Id5 + '">&nbsp;</b>'
        + '<b class="right tskStart"  onmouseover="this.className=\'right tskStartOver\';" onmouseout="this.className=\'right tskStart\';"  title="暂停" id="' + _Id6 + '" style="display:none;">&nbsp;</b>';
        
    }else
    {
        //run
        oTaskSpan.innerHTML+= '<b class="right tskPause"  onmouseover="this.className=\'right tskPauseOver\';" onmouseout="this.className=\'right tskPause\';"  title="开始" id="' + _Id5 + '" style="display:none;">&nbsp;</b>'
        + '<b class="right tskStart"  onmouseover="this.className=\'right tskStartOver\';" onmouseout="this.className=\'right tskStart\';"  title="暂停" id="' + _Id6 + '">&nbsp;</b>';
    }
    // 1 天 2 小时 30 分 40 秒
    oTaskSpan.innerHTML+='<span class="right tskTimeLeftSpan" id="'+_Id7+'"></span>';
    
    Comm.addEvent(oTaskSpan,'mouseover',function () 
    {
        this.className='tskBarhover';
    });
    
    Comm.addEvent(oTaskSpan,'mouseout',function () 
    {
        this.className='tskBar';
    });
    
    //获得第一个子节点，然后调用insertBefore
    var oFirstChild = oParent.firstChild;
    if(oFirstChild)
    {
        oParent.insertBefore( oTaskSpan ,oFirstChild);
    }else
    {
        oParent.appendChild( oTaskSpan );
    }
    
    Comm.addEvent(Comm.$(_Id0), 'click', function ()
    {
         //模拟编辑按钮动作
         Comm.$(_Id2).click();
    });
    
    Comm.addEvent(Comm.$(_Id1), 'click', function ()
    {
	    var tipmsg = '确定要删除 '+sCnt+' 吗?';
        if (!confirm(tipmsg)) 
        {
		    return ;
        }
        
        var i=0;
        for ( i = oParent.childNodes.length-1; i >=0 ; i-- )
        {
            if (oParent.childNodes[i].id == this.parentNode.id) 
            {
               break;
            }
        } 
        var currNode = ogChildTskGroup.xmlDoc.childNodes[oParent.childNodes.length-1-i]; 
        
        //通知C++,删除内存映射XML相关节点
        //window.external.delTaskXml(currNode.xml);
 
        //alert(i+', '+currNode.xml);
        ogChildTskGroup.xmlDoc.removeChild(currNode);
        
        //删除当前标签
        oTaskSpan.parentNode.removeChild(oTaskSpan);
    });
    
    Comm.addEvent(Comm.$(_Id2), 'click', function ()
    {     
        var i=0;
        for ( i = oParent.childNodes.length-1; i >=0 ; i-- )
        {
            if (oParent.childNodes[i].id == this.parentNode.id) 
            {
               break;
            }
        } 
        var currNode = ogChildTskGroup.xmlDoc.childNodes[oParent.childNodes.length-1-i]; 
        
        //需要将currNode对应的xml,发送给子任务对话框。
        //alert(currNode.xml); 
        window.external.showAddChildTaskDlg(currNode.xml);    
    });

    Comm.addEvent(Comm.$(_Id3),'click',function () 
    {
        //下移 
        var oSpan = this.parentNode;
        var oNextSpan = oSpan.nextSibling;
        if(oNextSpan)
        {
            var i = 0;

            for ( i = oParent.childNodes.length-1; i >=0 ; i-- )
            {
                if ( oParent.childNodes[i].id == this.parentNode.id )
                {
                    break;
                }
            }
            
            if(i>=0)
            {
                window.external.swapNode( oParent.childNodes[i+1].id , oParent.childNodes[i].id );
                                    
                Comm.swapNode(oNextSpan,oSpan);
                this.className = 'right tskMoveDn';
                oSpan.className = 'tskBar';
                
                //交换内存DOC中对应的项
                var oNode0 = ogChildTskGroup.xmlDoc.selectSingleNode( "//Id[.='" + oParent.childNodes[i+1].id + "']" );
                var oNode1 = ogChildTskGroup.xmlDoc.selectSingleNode( "//Id[.='" + oParent.childNodes[i].id + "']" );
                if (oNode0 &&  oNode1) 
                {
                    //存在原节点,则直接替换
                    Comm.swapNode(oNode0.parentNode, oNode1.parentNode);
                }
            }
        } 
    });
    
    Comm.addEvent(Comm.$(_Id4),'click',function () 
    {
        //上移
        //alert('上移');
        var oSpan = this.parentNode;
        var oPrevSpan = oSpan.previousSibling;
        if(oPrevSpan)
        {
            var i = 0;
            for ( i = oParent.childNodes.length-1; i >=0 ; i-- )
            {
                if ( oParent.childNodes[i].id == this.parentNode.id )
                {
                    break;
                }
            }
            
            if(i>=0)
            {
                //交换XML文件中对应的项
                window.external.swapNode( oParent.childNodes[i].id,   oParent.childNodes[i-1].id );
                    
                //交换DOM中对应的项
                Comm.swapNode(oPrevSpan,oSpan);
                this.className = 'right tskMoveUp'; 
                oSpan.className = 'tskBar';   
                
                //交换内存DOC中对应的项
                var oNode0 = ogChildTskGroup.xmlDoc.selectSingleNode( "//Id[.='" + oParent.childNodes[i].id + "']" );
                var oNode1 = ogChildTskGroup.xmlDoc.selectSingleNode( "//Id[.='" + oParent.childNodes[i-1].id + "']" );
                if (oNode0 &&  oNode1) 
                {
                    //存在原节点,则直接替换
                    Comm.swapNode(oNode0.parentNode, oNode1.parentNode);
                }
            }
        }
    });
    
    Comm.addEvent( Comm.$( _Id6 ), 'click', function ()
    {
        //暂停任务
        this.style.display='none';
        Comm.$( _Id5 ).style.display='block';
        var bComeFromChild = 1;
        window.external.PauseTsk('0', _Id, TSKSTATE.PAUSE, bComeFromChild);
        
        var xPath = '//Task[Id="'+this.parentNode.id +'"]/State';
        var oState = ogChildTskGroup.xmlDoc.selectSingleNode(xPath);
        if (oState) 
        {
            oState.text = TSKSTATE.PAUSE;
        }  
        var oLeftTimerTag = Comm.$(_Id7);
        if (oLeftTimerTag.timer) 
        {
            clearTimeout(oLeftTimerTag.timer);oLeftTimerTag.timer=null;
        }
    } );   
     
    Comm.addEvent( Comm.$( _Id5 ), 'click', function ()
    {
        //开始任务
        this.style.display='none';
        Comm.$( _Id6 ).style.display='block';
        var bComeFromChild = 1;
        
        var _Id7 = 'leftTimeSpan_'+ _Id;
        var oLeftTimerTag = Comm.$(_Id7);
        
        window.external.PauseTsk(/*oLeftTimerTag.nTotalSeconds*/'0',_Id, TSKSTATE.RUNNING, bComeFromChild);        
        
        var xPath = '//Task[Id="'+this.parentNode.id +'"]/State';
        var oState = ogChildTskGroup.xmlDoc.selectSingleNode(xPath);
        if (oState) 
        {
            oState.text = TSKSTATE.RUNNING;
        } 
    } );  
    
    Comm.addEvent( Comm.$( _Id7 ), 'click', function ()
    {
        //模拟编辑按钮动作
        Comm.$( _Id2 ).click();
    } );
}//CreatTskTag


Comm.ReadyDoc(function () 
{ 
//    oxmlActionGroupDoc = new ActiveXObject("Msxml2.Domdocument");
//    oxmlActionGroupDoc.async=false;
    olArrowSpan = Comm.$('lArrowSpan');
	orArrowSpan  = Comm.$('rArrowSpan');

    oxmlActionGroupDoc = new OHSXml();
    
    ogActionGroup = oxmlActionGroupDoc.xmlDoc.createElement("Actions");
    otitle_div = Comm.$('title_div');
    
//    oxmlTaskDoc = new ActiveXObject("Msxml2.Domdocument");
//    oxmlTaskDoc.async=false;
    oxmlTaskDoc = new OHSXml();
    
    ogTask = oxmlTaskDoc.xmlDoc.createElement("Task");
    
    ogChildTskGroup = new OHSXml();
    ogChildTskGroup.xmlDoc = oxmlTaskDoc.xmlDoc.createElement( "Tasks" );
    
    //ogChildTskGroup = oxmlTaskDoc.xmlDoc.createElement("Tasks");//"Childs"
    
    onongliFestSel = Comm.$('nongliFestSel');
    oyangliFestSel = Comm.$('yangliFestSel');
    ojieqiFestSel  = Comm.$('jieqiFestSel');
    oweekFestSel   = Comm.$('weekFestSel');
    oactionSel     = Comm.$('actionSel');
    oactCntDiv     = Comm.$('actCntDiv');
    ochildTskCntDiv     = Comm.$('childTskCntDiv');
    otskNameIpt    = Comm.$('tskNameIpt');   
    
      
    oyearSel0 = Comm.$('yearSel0');
    omonthSel0 =  Comm.$('monthSel0');
    odaySel0  =  Comm.$('daySel0');

    oday0 = Comm.$('day0');
    ohour0 = Comm.$('hour0');
    ominute0 = Comm.$('minute0');
    osecond0 = Comm.$('second0');
    
    var oRd0  = Comm.$('rd0');
    var oRd00 = Comm.$('rd00');
    var oRd01 = Comm.$('rd01');
    oRd02 = Comm.$('rd02');
    
    var oRd1  = Comm.$('rd1');
        
    oRd10 = Comm.$('rd10');
    oRd11 = Comm.$('rd11');
    oRd12 = Comm.$('rd12');    
    oRd13 = Comm.$('rd13'); 
    
    Comm.addEvent(onongliFestSel,'change',function () 
    {

        oRd10.click();
    });
    Comm.addEvent(oyangliFestSel,'change',function () 
    {
 
        oRd11.click();
    });
    Comm.addEvent(ojieqiFestSel,'change',function () 
    {
 
        oRd12.click();
    });
    Comm.addEvent(oweekFestSel,'change',function () 
    {
 
        oRd13.click();
    });
    
    Comm.addEvent(oRd0,'click',function () 
    {
       if(oRd00.checked)
       {
        //时分秒 灰化
        ohour0.disabled= true;
        ominute0.disabled= true;  
        osecond0.disabled= true;           
       }else{
        //时分秒 取消灰化
        ohour0.disabled= false;
        ominute0.disabled= false;  
        osecond0.disabled= false;           
       }
    }); 
    
    Comm.addEvent(oRd1,'click',function () 
    {
        //时分秒 取消灰化       
        ohour0.disabled= false;
        ominute0.disabled= false;  
        osecond0.disabled= false;    
    });    
    
    Comm.addEvent(oRd10,'click',function () 
    {
        ohour0.value=0;
        ominute0.value=0;
        osecond0.value=0;
        oRd1.click();
    });
    
    Comm.addEvent(oRd11,'click',function () 
    {
        ohour0.value=0;
        ominute0.value=0;
        osecond0.value=0;
        oRd1.click();
    });
    
    Comm.addEvent(oRd12,'click',function () 
    {
        ohour0.value=0;
        ominute0.value=0;
        osecond0.value=0;
        oRd1.click();
    });
    
    Comm.addEvent(oRd13,'click',function () 
    {
        ohour0.value=0;
        ominute0.value=0;
        osecond0.value=0;
        oRd1.click();
    });
     
    var now = new Date();
    var SY = now.getFullYear();
    var SM = now.getMonth()+1;     
    var DD = now.getDate();  
     
    var hh = now.getHours(); 
    var mm = now.getMinutes(); 
    var ss = now.getTime() % 60000; 
    ss = (ss - (ss % 1000)) / 1000; 
    
    ohour0.value = hh;    
    ominute0.value = mm;    
    osecond0.value = ss;   
     
    BuildYSel(SY);
    BuildMSel(SY,SY,SM);
    BuildDSel(SY,SM+1,GetDaysOfCurrMonth(SY,SM+1),SY,SM,SD); 
     
    Comm.addEvent(oyearSel0,'change',function () 
    {   
        var _Y = 1901 + this.selectedIndex; 
 
        BuildMSel(_Y,SY,SM);
    });
    
    Comm.addEvent(omonthSel0,'change',function () 
    {    
        var _Y = 1901 + oyearSel0.selectedIndex; 
        var _M = this.selectedIndex; 
        var _D = odaySel0.selectedIndex +1;
        //alert(GetDaysOfCurrMonth(_Y,_M+1)); 
        
        if (oRd02.checked) 
        {
            //如果选择的是阴历
            var sDObj = new Date(_Y,_M,_D);//new Date();//
            var lDObj = new Lunar(sDObj);
            var nlDaysOnMonth = monthDays(lDObj.year,  lDObj.month);
            
            BuildDSel(_Y,_M+1,nlDaysOnMonth,lDObj.year,lDObj.month,Math.floor(lDObj.day)); 
            
        }else
        {
        
            BuildDSel(_Y,_M+1,GetDaysOfCurrMonth(_Y,_M+1),SY,SM,SD);          
        }

    });
    
    ocurrTimeSpan = Comm.$('currTimeSpan');
   
    var oline0_1s = Comm._getElementsByClassName('line0_1',document,'div');
    var oline0_1  = oline0_1s[oline0_1s.length-1];

    var oIntval=null;
    Comm.addEvent(oRd00,'click',function () 
    {
//       var ospecialDate  = document.getElementsByName('specialDate');
//       var o  =GetRadioChecked(ospecialDate);
 
            oRd0.click();
//        if(ocurrTimeSpan.style.display!='inline')
//        {
            ocurrTimeSpan.innerHTML = CurentTime();
            ocurrTimeSpan.style.display = 'inline'; 
                    
            oIntval= setInterval('refreshCalendarClock()',1000); 
            EnabledAllChilds(oline0_1,false);
            
            //时分秒 灰化
            ohour0.disabled= true;
            ominute0.disabled= true;  
            osecond0.disabled= true;              
                         
//        }else
//        {
//            ocurrTimeSpan.style.display = 'none';
//            clearInterval(oIntval);oIntval=null;  
//            EnabledAllChilds(oline0_1,true);
//        } 
    }); 
    
    
    Comm.addEvent(oRd01,'click',function () 
    {
        
        //时分秒 取消灰化
        ohour0.disabled= false;
        ominute0.disabled= false;  
        osecond0.disabled= false;     
              
        //ocurrTimeSpan.style.display = 'none';
        //clearInterval(oIntval);oIntval=null;  
        EnabledAllChilds(oline0_1,true);
        oRd0.click(); 
                 
        var now = new Date();
        var _Y = now.getFullYear();
        var _M = now.getMonth()+1; 
        var _D = now.getDate(); 
         
        var hh = now.getHours(); 
        var mm = now.getMinutes(); 
        var ss = now.getTime() % 60000; 
        ss = (ss - (ss % 1000)) / 1000; 
    
            
        ohour0.value = hh;       
        ominute0.value = mm;   
        osecond0.value = ss; 
            
        BuildYSel(_Y); 
        BuildMSel(_Y,_Y,_M);
        BuildDSel(_Y,_M, GetDaysOfCurrMonth(_Y,_M ),_Y,_M,_D); 
    });  
    
    Comm.addEvent(oRd02,'click',function () 
    {
        //时分秒 取消灰化
        ohour0.disabled= false;
        ominute0.disabled= false;  
        osecond0.disabled= false;    
        
        EnabledAllChilds(oline0_1,true);
        oRd0.click();         
        //阳历转阴历算法，并重建年月日下拉列表 

        var sDObj = new Date();//new Date(_Y,_M,_D);
        
        var lDObj = new Lunar(sDObj);
        
        var nlDaysOnMonth = monthDays(lDObj.year,  lDObj.month);
 
        BuildYSel(lDObj.year);
        BuildMSel(lDObj.year,lDObj.year,lDObj.month);  
        BuildDSel(lDObj.year,lDObj.month,nlDaysOnMonth,lDObj.year,lDObj.month,Math.floor(lDObj.day)); 
        
        var now = sDObj; 
         
        var hh = now.getHours(); 
        var mm = now.getMinutes(); 
        var ss = now.getTime() % 60000; 
        ss = (ss - (ss % 1000)) / 1000; 
        
        ohour0.value = hh;       
        ominute0.value = mm;   
        osecond0.value = ss; 
//        var  tt  = '本月共计'+nlDaysOnMonth+' 天,'+lDObj.year+'年，'+lDObj.month+'月，'+Math.floor(lDObj.day);//cDay(lDObj.month,lDObj.day);
//        
//        oactCntDiv.innerHTML = tt;
    });  
    
    ocurrTimeSpan.innerHTML = CurentTime();
    ocurrTimeSpan.style.display = 'inline'; 
    oIntval= setInterval('refreshCalendarClock()',1000); 
    EnabledAllChilds(oline0_1,false);   
       
    var val = ["0101 春节",
                "0115 元宵节",
                "0505 端午节",
                "0707 七夕情人节",
                "0715 中元节",
                "0815 中秋节",
                "0909 重阳节",
                "1208 腊八节",
                "1224 小年",
                "0100 除夕"];
                
    for(var i=0;i<val.length;i++)
    {
        var oOption =new Option(val[i],i);
        onongliFestSel.options.add(oOption);
    }
     
val = [
"0101*元旦",
"0214 情人节",
"0303 爱耳日",
"0305 青年志愿者服务日",
"0307 女生节",
"0308 妇女节",
"0312 植树节",
"0314 白色情人节",
"0314 国际警察日",
"0315 消费者权益日",
"0321 世界森林日,睡眠日",
"0322 世界水日",
"0323 世界气象日",
"0324 世界防治结核病日",
"0401 愚人节",
"0404 清明节",
"0407 世界卫生日",
"0422 世界地球日",
"0426 世界知识产权日",
"0501 劳动节",
"0503 世界哮喘日",
"0504 青年节",
"0508 世界红十字日,世界微笑日",//5月8日 世界红十字日 1948 
"0512 护士节",
"0515 国际家庭日",
"0531 世界无烟日",
"0601 儿童节",
"0605 世界环境日",
"0606 全国爱眼日",
"0611 中国人口日", 
"0617 世界防止荒漠化和干旱日", 
"0620 世界难民日",//6月20日 世界难民日 2001 
"0623 国际奥林匹克日",
"0625 全国土地日",
"0626 国际禁毒日",
"0701 建党节 香港回归纪念",
"0707 抗日战争纪念日",
"0711 世界人口日",
"0801 建军节",
"0806 国际电影节",//8月6日 国际电影节 1932 
"0808 中国男子节",//8月8日 中国男子节(爸爸节) 1988 
"0812 国际青年节",
"0815 日本投降日",//8月15日 日本正式宣布无条件投降日 1945 
"0903 中国抗日战争胜利纪念日",//9月3日 中国抗日战争胜利纪念日 1945 
"0908 国际扫盲日",
"0909 毛席逝世纪念",
"0910 教师节",
"0916 中国脑健康日,国际臭氧层保护日",
"0918 九·一八事变纪念日,中国国耻日",// 9月18日 "九·一八"事变纪念日(中国国耻日) 1931 
"0920 全国爱牙日",
"0921 世界停火日",
"0927 世界旅游日",
"0928 孔子诞辰",
"1001*国庆节",
"1006 老人节",
"1016 世界粮食日", 
"1017 国际消除贫困日",
"1024 联合国日",
"1031 万圣节",
"1108 中国记者节",
"1112 孙中山诞辰",
"1201 艾滋病日",
"1203 世界残疾人日",
"1213 南京大屠杀悼念日",
"1220 澳门回归纪念",
"1225 圣诞节",
"1226 毛席诞辰"];

    for(var i=0;i<val.length;i++)
    {
        var oOption =new Option(val[i],i);
        oyangliFestSel.options.add(oOption);
    }    
    
    val = ["立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒"];
    for(var i=0;i<val.length;i++)
    {
        var oOption =new Option(val[i],i);
        ojieqiFestSel.options.add(oOption);
    }        
    
    val = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"];
    for(var i=0;i<val.length;i++)
    {
        var oOption =new Option(val[i],i);
        oweekFestSel.options.add(oOption);
    }   
    actionNameAr = ["待机","休眠","关机","注销","重启","播放音乐","指定应用"];//,"唤醒"
 
    for(var i=0;i<actionNameAr.length;i++)
    {
        var oOption =new Option(actionNameAr[i],i);
        oactionSel.options.add(oOption);
    }     
  
    var osongPlaySettingSpan = Comm.$('songPlaySettingSpan'); 
    var omsgTipsSettingSpan= Comm.$('msgTipsSettingSpan');
    var oappRunSettingSpan= Comm.$('appRunSettingSpan');
    
    oactionAddBtn       = Comm.$('actionAddBtn');
    osongfileIpt        = Comm.$('songfileIpt');
    var omsgIpt         = Comm.$('msgIpt');
    oappfileIpt         = Comm.$('appfileIpt');
    oappParamIpt        = Comm.$('appParamIpt');    
    var oappParamDiv    = Comm.$('appParamDiv');

    ooffsetDayIpt  = Comm.$('offsetDayIpt');
    ooffsetHourIpt  = Comm.$('offsetHourIpt');
    ooffsetMinIpt  = Comm.$('offsetMinIpt');
    ooffsetSecIpt  = Comm.$('offsetSecIpt');
    orunTimesIpt   = Comm.$('runTimesIpt');
    
    oIntvlMonIpt   = Comm.$('IntvlMonIpt');
    oIntvlDayIpt   = Comm.$('IntvlDayIpt');
    oIntvlHourIpt   = Comm.$('IntvlHourIpt');    
    oIntvlMinIpt   = Comm.$('IntvlMinIpt');
    oIntvlSecIpt   = Comm.$('IntvlSecIpt'); 
       

	Comm.addEvent(olArrowSpan,'click',function()
	{
		var n=orunTimesIpt.value;
		if(n>-1) n--;
		orunTimesIpt.value = n;

	});

	Comm.addEvent(orArrowSpan,'click',function()
	{
		var n=orunTimesIpt.value;
		n++;
		orunTimesIpt.value = n;
	});

    Comm.addEvent(Comm.$('addChildTask'),'click',function () 
    { 
        window.external.showAddChildTaskDlg('');
    });
           
    Comm.addEvent(oactionAddBtn,'click',function () 
    {
           //var s=osongfileIpt.value;
//           if ( 0 && s.length>0) 
//           {
//               s=osongfileIpt.value.match(/^(.*)(\.)(.{1,8})$/)[3];
//               s = s.toLowerCase();
//               if(s == 'mp3'
//               || s == 'rm'
//               )
//               {
//                   ;//对于用户乱输入的东西，不做处理，交给音乐播放器自己搞定。
//               }             
//           } 
//            var oTimerTags = Comm.$('tskCntDiv');
//            Comm.removeAllChild(oTimerTags);
            var s='';
            var nIndex = oactionSel.selectedIndex;
            switch(nIndex) 
            {
            case 0:
                //
                s = actionNameAr[nIndex];
                break;
            case 1:
                //
                s = actionNameAr[nIndex];
                break;
            case 2:
                //
                s = actionNameAr[nIndex];
                break;
            case 3:
                //
                s = actionNameAr[nIndex];
                break;
            case 4:
                s = actionNameAr[nIndex];
                break;
            case 5:
                //播放音乐,显示文件选择框 
                s = actionNameAr[nIndex];
                s += ': '+osongfileIpt.value;
        	    break;
//            case 6:
//                //消息提示 
//                s = actionNameAr[nIndex];
//                s += ': '+omsgIpt.value; 
//        	    break;
            case 6:
                //指定应用 
                s = actionNameAr[nIndex];
                s += ': '+oappfileIpt.value;
                s += '   '+oappParamIpt.value;
        	    break;  
            case 7:
                //
                s = actionNameAr[nIndex];
                break;
            default:
            }
            
            var nactionType  = nIndex;
            var sParam =  '';
            var sParam1 ='';

            if (osongPlaySettingSpan.style.display =='inline') 
            {
               sParam = osongfileIpt.value;
            }else if (omsgTipsSettingSpan.style.display =='inline') 
            {
               sParam = omsgIpt.value;        
            }else if (oappRunSettingSpan.style.display =='inline') 
            {
               sParam = oappfileIpt.value;  
               sParam1 = oappParamIpt.value;           
            }
            var sId  = (Math.random() * 1000000).toFixed(0);
//             if (this._ActId != null) 
//             {
//                sId = this._ActId;
//             }
             
            var xmlDoc = oxmlActionGroupDoc.xmlDoc;
            var oAction = xmlDoc.createElement("Action");
                var oActId = xmlDoc.createElement('Id');          oActId.appendChild(xmlDoc.createCDATASection(sId));
                var oActType = xmlDoc.createElement('Type');      oActType.appendChild(xmlDoc.createCDATASection(nactionType));  
                var oActParam0 = xmlDoc.createElement('Param0');  oActParam0.appendChild(xmlDoc.createCDATASection(sParam));  
                var oActParam1 = xmlDoc.createElement('Param1');  oActParam1.appendChild(xmlDoc.createCDATASection(sParam1));  
                var oActParam2 = xmlDoc.createElement('Param2');  oActParam1.appendChild(xmlDoc.createCDATASection(''));  
            oAction.appendChild(oActId);                
            oAction.appendChild(oActType);
            oAction.appendChild(oActParam0);
            oAction.appendChild(oActParam1);
            oAction.appendChild(oActParam2);
          
            ogActionGroup.appendChild(oAction);
          
            CreateActTag(oactCntDiv, s, oAction);
            this._ActId =null; 
    });
    
    Comm.addEvent(oactionSel,'change',function () 
    {
        oactionAddBtn._ActId=null;
        
        osongPlaySettingSpan.style.display='none';
        omsgTipsSettingSpan.style.display='none';
        oappRunSettingSpan.style.display='none';
        oappParamDiv.style.visibility='hidden';  
           
        var nIndex = this.selectedIndex;
        switch(nIndex) 
        {
        case 0:
        case 1:
        case 2:
        case 3:
        case 4:
            break;
        case 5:
            //播放音乐,显示文件选择框
            osongPlaySettingSpan.style.display='inline';
            
        	break;
//        case 6:
//            //消息提示
//            omsgTipsSettingSpan.style.display='inline';
//        	break;
        case 6:
            //指定应用
            oappRunSettingSpan.style.display='inline';
            oappParamDiv.style.visibility='visible';
        	break; 
        case 7:   
            break;     	       	
        default:
        }
    });
     
    var oRadios = document.getElementsByTagName('input');
    for(var i=0;i<oRadios.length;i++)
    {
        var oRadio = oRadios[i];
        if (oRadio.type != 'radio') 
        {
            continue;//s += oRadio.value;
        }
        
        //取得单选按钮的前一个元素
        var oNext  = oRadio.nextSibling;//previousSibling;
        oNext.className += ' radioNxt';
        
        Comm.addEvent(oNext,'click',function () 
        {
            this.previousSibling.click();
        }) ;

        var oChildsIpt = oNext.getElementsByTagName('input');
        for(var j=0;j< oChildsIpt.length;j++)
        {
            Comm.addEvent(oChildsIpt[j],'focus',function () 
            { 
                  this.parentNode.previousSibling.click();
            }); 
        }
    }//for
    
    //增加任务！！！！！！！！！！！！！！！！！ 
    Comm.addEvent(Comm.$('addTask'),'click',function () 
    {
        //判断用户输入是否合法
//        var nCount=oactCntDiv.childNodes.length;
//        if( 0 == nCount )
//        {
//            alert('请添加定时器触发后的执行动作');
//            return;        
//        } 
        //将定时任务写入配置XML文件。
        var xmlDoc = oxmlTaskDoc.xmlDoc;//new ActiveXObject("Msxml2.Domdocument");
        xmlDoc.async=false;
        
//        if (!xmlDoc.load("J:\\11.xml")) 
//        {
//            
//            alert('无法打开xml文件');
//            return;
//        }
        //show.innerHTML=a.documentElement.xml;
        Comm.removeAllChild(ogTask);
        
        var y=0,m=0,d=0,h=0,f=0,s=0;
        //var oTaskGroup = xmlDoc.createElement("Tasks");
        var oTask = ogTask;//xmlDoc.createElement("Task");
        
        var s ='',nTimeType=0,sTimeParam='',sTimeParam1='';
        var oRds = document.getElementsByName('taskStartType');
        for(var i=0;i<oRds.length;i++)
        {
            if (oRds[i].checked) 
            {
                nTimeType = i;
                break;
            }
        }
        
        var nIndex = -1;
        if (nTimeType==0) 
        {
            //具体时间,又分为三种类型
            var specialDateRds = document.getElementsByName('specialDate'),nspecialDateType=-1;
            for(var i=0;i<specialDateRds.length;i++)
            {
                if (specialDateRds[i].checked) 
                {
                    nspecialDateType = i;
                    break;
                }
            }
            
            if (nspecialDateType==0) 
            {
                //即时
            }else if (nspecialDateType==1) 
            {
                //阳历，获取阳历的年月日，时分秒
            }else if (nspecialDateType==2) 
            {
                //阴历，获取阴历的年月日，时分秒
            }else
            {
                alert('请选择具体日期');
                return ;
            }
            
            y  = oyearSel0.selectedIndex + 1901 ;if(!IsValidYear(y)){y=0;};
            m  = omonthSel0.selectedIndex + 1;   if(!IsValidMon(m)){m=0;};
            d  = odaySel0.selectedIndex + 1;     if(!IsValidDay(d)){d=0;};   

            sTimeParam = y +'.'+ m +'.'+ d ;//+'.'+ h +':'+ f +':'+ s;
            
            nIndex = nspecialDateType;
        }else  if (nTimeType==1) 
        {
            //节日
            var oFestivalRds = document.getElementsByName('Festival'),nFestivalType=-1;
            for(var i=0;i<oFestivalRds.length;i++)
            {
                if (oFestivalRds[i].checked) 
                {
                    nFestivalType = i;
                    break;
                }
            } 
 
            if (nFestivalType==0) 
            {
                //农历节日
                nIndex =onongliFestSel.selectedIndex;
                
            }else if (nFestivalType==1) 
            {
                //阳历节日
                nIndex =oyangliFestSel.selectedIndex;
            }else if (nFestivalType==2) 
            {
                //农历节气
                nIndex =ojieqiFestSel.selectedIndex;
            }else if (nFestivalType==3) 
            {
                //星期,复选下拉框，允许多选
                s ='';
                for(var i=0;i<oweekFestSel.options.length;i++)
                {
                    if (oweekFestSel.options[i].selected) 
                    {
                        s += i +',';
                    }
                }
                if (s.length==0) 
                {
                    alert('请选择星期几执行');
                    return;
                }
                nIndex =s;
            }else
            {
                alert('请选择节日或日期');
                return ;
            }
            
            sTimeParam = nFestivalType+'-'+nIndex ; 
            nIndex = nFestivalType;
        } 
        h  = ohour0.value;                   if(!IsValidHour(h)){h=0;};   
        f  = ominute0.value;                 if(!IsValidMin(f)){f=0;};
        s  = osecond0.value;                 if(!IsValidSec(s)){s=0;};
        sTimeParam1 = h +':'+ f +':'+ s;
        
        nTimeType = nTimeType+''+nIndex;
        
        var tskName = otskNameIpt.value;
        if (!tskName) 
        {
            tskName='未命名任务';
        }
        tskName = tskName.substr(0,100);
  
        if (gTskId==0) 
        {
            gTskId= (Math.random() * 1000000).toFixed(0);// 'Tsk' +
        }
          
        var oTskId = xmlDoc.createElement("Id");oTskId.appendChild(xmlDoc.createCDATASection(gTskId));
        oTask.appendChild(oTskId);
             
        oTskId = xmlDoc.createElement("State");oTskId.appendChild(xmlDoc.createCDATASection(gTskState));
        oTask.appendChild(oTskId); 
        
        var oTimerName = xmlDoc.createElement("Name");oTimerName.appendChild(xmlDoc.createCDATASection(tskName));
        oTask.appendChild(oTimerName);      
        
        var oTime = xmlDoc.createElement("Time");
        var oTimeType = xmlDoc.createElement('Type');  oTimeType.appendChild(xmlDoc.createCDATASection(nTimeType));
        var oTimeParam  = xmlDoc.createElement('Param0');oTimeParam.appendChild(xmlDoc.createCDATASection(sTimeParam));//"2013.01.29"
        var oTimeParam1 = xmlDoc.createElement('Param1');oTimeParam1.appendChild(xmlDoc.createCDATASection(sTimeParam1));//"12:20:22"
                
        oTime.appendChild(oTimeType);
        oTime.appendChild(oTimeParam);
        oTime.appendChild(oTimeParam1);
        oTask.appendChild(oTime); 
        
        //日期偏移，之前or 之后
        var offsetDateRds= document.getElementsByName('offsetDate'),nOffsetType=0;
        for(var i=0;i<offsetDateRds.length;i++)
        {
            if (offsetDateRds[i].checked) 
            {
                nOffsetType =i;
                break;
            }
        } 
          
        
        d  = ooffsetDayIpt.value;     if(!IsValidNum(d,-1e5,1e5)){alert('时间偏移输入框中，天数必须为-100000~100000之间的整数'); return; d=0;};   
        h  = ooffsetHourIpt.value;    if(!IsValidNum(h,-1e5,1e5)){alert('时间偏移输入框中，小时数必须为-100000~100000之间的整数'); return;h=0;};   
        f  = ooffsetMinIpt.value;     if(!IsValidNum(f,-1e5,1e5)){alert('时间偏移输入框中，分钟数必须为-100000~100000之间的整数'); return;f=0;};
        s  = ooffsetSecIpt.value;     if(!IsValidNum(s,-1e5,1e5)){alert('时间偏移输入框中，秒数必须为-100000~100000之间的整数'); return;s=0;};
  
        //下次任务被启动的日期：X年X月X日 时分秒  
        var oNextTime = xmlDoc.createElement("NextTrigTime");
        var oNextTimeType   = xmlDoc.createElement('Type');  oNextTimeType.appendChild(xmlDoc.createCDATASection(nTimeType));
        var oNextTimeParam  = xmlDoc.createElement('Param0');oNextTimeParam.appendChild(xmlDoc.createCDATASection(sTimeParam));//"2013.01.29"
        var oNextTimeParam1 = xmlDoc.createElement('Param1');oNextTimeParam1.appendChild(xmlDoc.createCDATASection(sTimeParam1));//"12:20:22"
        
        //oLeftTime.appendChild(xmlDoc.createCDATASection('-1#-1'));//oTimeParam+'#'+sTimeParam12013.01.29#12:20:22 
        oNextTime.appendChild(oNextTimeType);
        oNextTime.appendChild(oNextTimeParam);
        oNextTime.appendChild(oNextTimeParam1);
        oTask.appendChild(oNextTime); 
        
        var sParam =  d +'.'+ h +':'+ f +':'+ s;
        var sParam1 ='';
  
        var oOffset = xmlDoc.createElement('Offset');
            var oOffsetType = xmlDoc.createElement('Type');   oOffsetType.appendChild(xmlDoc.createCDATASection(nOffsetType));
            var oOffsetParam = xmlDoc.createElement('Param'); oOffsetParam.appendChild(xmlDoc.createCDATASection(sParam)); 
        oOffset.appendChild(oOffsetType);
        oOffset.appendChild(oOffsetParam);
 
        oTask.appendChild(oOffset); 
                 
        //执行频率
        var nRunTimes = parseInt(orunTimesIpt.value,10); 
        if (isNaN(nRunTimes)) 
        {
            nRunTimes = 0;
        }
 
        var nFreqType= 0;
        var oRds = document.getElementsByName('offsetMon');
        for(var i=0;i<oRds.length;i++)
        {
            if (oRds[i].checked) 
            {
                nFreqType = i;
                break;
            }
        }
 
        if (nFreqType ==1) 
        {
            d  = oIntvlDayIpt.value;     if(!IsValidNum(d,-1e5,1e5)){alert('时间间隔输入框中，天数必须为-100000~100000之间的整数'); return;d=0;};   
            h  = oIntvlHourIpt.value;    if(!IsValidNum(h,-1e5,1e5)){alert('时间间隔输入框中，小时数必须为-100000~100000之间的整数'); return;h=0;};   
            f  = oIntvlMinIpt.value;     if(!IsValidNum(f,-1e5,1e5)){alert('时间间隔输入框中，分钟数必须为-100000~100000之间的整数'); return;f=0;};
            s  = oIntvlSecIpt.value;     if(!IsValidNum(s,-1e5,1e5)){alert('时间间隔输入框中，秒数必须为-100000~100000之间的整数'); return;s=0;};        
            sParam =  d +'.'+ h +':'+ f +':'+ s; //nFreqType + '#ohs#'+
        }else if(nFreqType == 0)//默认值 
        {
            s = Comm.$('IntvlMonIpt').value; if(!IsValidNum(s,-1e5,1e5)){alert('时间间隔输入框中，月份数必须为-100000~100000之间的整数'); return;s=0;};
            sParam =  s;//nFreqType + '#ohs#'+
            
        }

        var oFreq = xmlDoc.createElement("Freq");
            var oFreqType  = xmlDoc.createElement('Type');      oFreqType.appendChild(xmlDoc.createCDATASection(nFreqType));
            var oFreqTimes = xmlDoc.createElement('Times');     oFreqTimes.appendChild(xmlDoc.createCDATASection(nRunTimes));
            var oFreqIntval = xmlDoc.createElement('Interval'); oFreqIntval.appendChild(xmlDoc.createCDATASection(sParam));
        oFreq.appendChild(oFreqType);
        oFreq.appendChild(oFreqTimes);
        oFreq.appendChild(oFreqIntval);
        oTask.appendChild(oFreq); 
        
        //执行动作
        oTask.appendChild(ogActionGroup); 

        //子任务集       
        oTask.appendChild(ogChildTskGroup.xmlDoc);  
        
        var root = xmlDoc.documentElement;
 
        window.external.sendTaskXml(oTask.xml, gTskId+'');

        
        window.external.CB_Close();
//root.appendChild(oTaskGroup);

        //xmlDoc.save("d:\\ddd.axl");
        
//        var fso = new ActiveXObject("Scripting.FileSystemObject");
//        var ForReading = 1, ForWriting = 2, ForAppending = 8;

//        var bbb = fso.OpenTextFile("J:\\11.xml", ForWriting, false);//CreateTextFile
//        bbb.Write(xmlDoc.xml);
//        bbb.Close(); 
        
//        var winSave = window.open();
//        winSave.document.open ("text/html","UTF-8");
//        winSave.document.write (a.xml);
//        winSave.document.execCommand ("SaveAs",true,"j:\\AppCfg.xml");
//        winSave.close();        

    });
    
});


function SetTskXml(sXml) 
{
    if (!sXml) 
    {
      return;
    }
    oxmlTaskDoc.loadXML(sXml);
    var xmlDoc = oxmlTaskDoc.xmlDoc;
    
    var nodeName = xmlDoc.selectSingleNode("//Name");  
    
    otitle_div.innerHTML = '编辑任务';
 
    var node = xmlDoc.selectSingleNode("//Id");  
    if (!node) 
    {
       return;
    }
 
    gTskId = node.text;
    
    node = xmlDoc.selectSingleNode("//State");  
    if (!node) 
    {
       return;
    }
    gTskState= node.text;

    //名称
    otskNameIpt.value = nodeName.text;
 
    var oRds = document.getElementsByName('taskStartType');
    node = xmlDoc.selectSingleNode("//Time/Type");  
    var sType  = node.text.match(/^([0-9])([0-9])$/);
    var oParam,oParam1,nIndex,sTmp,sTmp1;
    
    oParam = xmlDoc.selectSingleNode("//Time/Param0");
    
    if (sType[1]=='0') 
    {
       oRds[0].checked = true;
       var specialDateRds = document.getElementsByName('specialDate'),nspecialDateType=-1;
       nspecialDateType = parseInt(sType[2],10);       
       specialDateRds[nspecialDateType].checked = true; 
       specialDateRds[nspecialDateType].click();
       
       sTmp  = oParam.text.split('.'); 
 
       //当前，阳历，阴历，对应的参数也不一样
       switch(nspecialDateType)
       {
       case 0:
            //即时任务，则参数没有意义
            break;
       case 1:
            //更新阳历时间显示框
            y = sTmp[0];
            m = sTmp[1];
            d = sTmp[2];
            //s = sTmp[3].split(':');

            oyearSel0.selectedIndex = y - 1901 ; 
            omonthSel0.selectedIndex = m - 1;  
            odaySel0.selectedIndex = d- 1;   

            break;         
       case 2:         
            //更新阴历时间显示框
            y = sTmp[0];
            m = sTmp[1];
            d = sTmp[2];

            //阴历日历不一样，所以我需要重建列表            
            BuildYSel(y);
            oRd02.checked = true;
            BuildMSel(y,y,m);
            BuildDSel(y,m+1,GetDaysOfCurrMonth(y,m+1),y,m,d);  
                       
            oyearSel0.selectedIndex = y - 1901 ; 
            omonthSel0.selectedIndex = m - 1;  
            odaySel0.selectedIndex = d- 1;   
            break; 
       }//switch
    }else if (sType[1]=='1') 
    {
        //特殊节日
       oRds[1].checked = true;
       oRds[1].click();
       var oFestivalRds = document.getElementsByName('Festival'),nFestivalType=-1;
       nFestivalType = parseInt(sType[2],10);
       oFestivalRds[nFestivalType].checked = true; 
       
       nIndex = oParam.text.match(/^([0-9])-(.*)$/)[2];
       
       //不同的节日，对应的参数也不一样
       switch(nFestivalType)
       {
       case 0:
            onongliFestSel.selectedIndex = nIndex;
            break;
       case 1:
            oyangliFestSel.selectedIndex = nIndex;
            break;
       case 2:
            ojieqiFestSel.selectedIndex = nIndex;
            break;
       case 3:
            var nWeeks  = nIndex.split(',');  
            for(var i=0;i<nWeeks.length-1;i++)
            {
                oweekFestSel.options[parseInt(nWeeks[i],10)].selected = true;
            } 
            break;
       }//switch
    } 
    oParam1= xmlDoc.selectSingleNode("//Time/Param1"); 
    var y,m,d,h,f,sec;   
      
    sTmp1 = oParam1.text.split(':');  
    h = sTmp1[0];
    f = sTmp1[1];
    sec = sTmp1[2]; 
    
    ohour0.value = h;                   
    ominute0.value = f;                 
    osecond0.value = sec;  
    
    var offsetDateRds= document.getElementsByName('offsetDate'),nOffsetType=0;
    node = xmlDoc.selectSingleNode("//Offset/Type");  
    nOffsetType = parseInt(node.text,10);
    offsetDateRds[nOffsetType].checked = true;
    oParam = xmlDoc.selectSingleNode("//Offset/Param");      
    sTmp = oParam.text.split('.');
    d = sTmp[0];
    
    var s = sTmp[1].split(':');
    h = s[0];
    f = s[1];
    s = s[2];
    ooffsetDayIpt.value  = d; 
    ooffsetHourIpt.value = h;
    ooffsetMinIpt.value  = f;
    ooffsetSecIpt.value  = s;

    node = xmlDoc.selectSingleNode("//Freq/Type");  
    var nFreqType =  node.text;
    node = xmlDoc.selectSingleNode("//Freq/Times");             
    orunTimesIpt.value =  node.text;
    
    oParam = xmlDoc.selectSingleNode("//Freq/Interval");   
    sTmp = oParam.text;//.split('#ohs#')
 
    oRds = document.getElementsByName('offsetMon');
    
    if (nFreqType=='0') 
    {
        //week interval
        oRds[0].click();
        oIntvlMonIpt.value = sTmp;
    }else
    {
        oRds[1].click();
         
        sTmp = sTmp.split('.');
        d = sTmp[0];
        s = sTmp[1].split(':');
        h = s[0];
        f = s[1];
        s = s[2];
        
        oIntvlDayIpt.value =d; 
        oIntvlHourIpt.value =h;  
        oIntvlMinIpt.value=f;    
        oIntvlSecIpt.value=s;      
    }
    
    node = xmlDoc.selectSingleNode("//Actions");
    var ofirstAction = node.firstChild;

    var sParam =  '';
    var sParam1 ='';
    var sParam2 ='';
    var sId = '';
    
    
    while(ofirstAction)
    {  
        var nactionType  = ofirstAction.selectSingleNode("Type").text; 
        sId     = ofirstAction.selectSingleNode("Id").text; 
        sParam  = ofirstAction.selectSingleNode("Param0").text; 
        sParam1 = ofirstAction.selectSingleNode("Param1").text; 
        sParam2 = ofirstAction.selectSingleNode("Param2").text;
         
        var nIndex = parseInt(nactionType ,10)  ;
        s = actionNameAr[nIndex]; 
                   
        switch(nIndex) 
        {
        case 0: 
            //
            break;

        case 1:
            //
            break;
        case 2:
            //
            break;
        case 3:
            //
            break;
        case 4:
            break;
        case 5:
            //播放音乐,显示文件选择框 
            s += ': '+sParam;
	        break;
//        case 6:
//            //消息提示 
//            s += ': '+sParam; 
//	        break;
        case 6:
            //指定应用 
            s += ': '+sParam;
            s += '   '+sParam1;
	        break;   
        case 7:
            //
            break;	             	
        default:
        }  
            
        var _xmlDoc = oxmlActionGroupDoc.xmlDoc;
        var oAction = _xmlDoc.createElement("Action"); 
            var oActId = _xmlDoc.createElement('Id');          oActId.appendChild(_xmlDoc.createCDATASection(sId));// (Math.random() * 1000000).toFixed(0) 
            var oActType = _xmlDoc.createElement('Type');      oActType.appendChild(_xmlDoc.createCDATASection(nactionType));  
            var oActParam0 = _xmlDoc.createElement('Param0');  oActParam0.appendChild(_xmlDoc.createCDATASection(sParam));  
            var oActParam1 = _xmlDoc.createElement('Param1');  oActParam1.appendChild(_xmlDoc.createCDATASection(sParam1));
            var oActParam2 = _xmlDoc.createElement('Param2');  oActParam2.appendChild(_xmlDoc.createCDATASection(sParam2));
                         
        oAction.appendChild(oActId);             
        oAction.appendChild(oActType);
        oAction.appendChild(oActParam0);
        oAction.appendChild(oActParam1);
        oAction.appendChild(oActParam2); 
               
        ogActionGroup.appendChild(oAction);
        
        CreateActTag(oactCntDiv, s,oAction);
        ofirstAction = ofirstAction.nextSibling;
    } 

    node = xmlDoc.selectSingleNode("//Tasks");//"//Childs"
     
    ofirstAction = node.firstChild;
    while(ofirstAction)
    {  
        AddChildTskXml(ofirstAction.xml); 
        ofirstAction = ofirstAction.nextSibling;    
    } 
}//
  

function AddChildTskXml(s) 
{
    //var xmlDoc = new ActiveXObject("Msxml2.Domdocument"); 
    //xmlDoc.async=false;
    var xmlDoc = oxmlTaskDoc = new OHSXml();    
    xmlDoc.loadXML(s);
    var _xmlDoc = xmlDoc.xmlDoc;
    
    var nameNode = _xmlDoc.selectSingleNode("//Name");  
    
    var oState = _xmlDoc.selectSingleNode( "//State" );

    var root = _xmlDoc.documentElement;        
    var node = _xmlDoc.selectSingleNode("//Id");  
    var oOldNode = ogChildTskGroup.xmlDoc.selectSingleNode( "//Id[.='" + node.text + "']" );
    //var oOldNode=ogChildTskGroup.selectSingleNode("//Id[.='"+node.text+"']");  
    if (oOldNode) 
    {
        //存在原节点,则直接替换
        ogChildTskGroup.xmlDoc.replaceChild(node.parentNode,oOldNode.parentNode);
        
        var o = oOldNode.parentNode.firstChild;
        var oOldLine = Comm.$(oOldNode.text).firstChild;
        oOldLine.innerText = nameNode.text; 
    }else
    {    
        ogChildTskGroup.xmlDoc.appendChild(root );
        CreatTskTag(ochildTskCntDiv, nameNode.text, node.text, oState.text);
    }
    //alert( ogChildTskGroup.xml);
}