 
var orArrowSpan;
var olArrowSpan;
 var oactionSel;
 var oactCntDiv;
 var omsgTips;
var ogActionGroup;
var oxmlActionGroupDoc  ;
var otitle_div;
var otskNameIpt;

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

var gChildId=0;//子任务唯一ID,用于编辑后修改目标子任务时进行查找和定位的依据
var gTskState=TSKSTATE.RUNNING;//任务状态，1表示运行，2表示停止，4表示暂停，8表示待删除，16表示过期，具体见\MemMapXml\TskTimer.h  enum TSKSTATE
 
    var ooffsetDayIpt ;
    var ooffsetHourIpt ;
    var ooffsetMinIpt ;
    var ooffsetSecIpt ;
    var orunTimesIpt ;
    var oIntvlDayIpt ;
    var oIntvlHourIpt ;    
    var oIntvlMinIpt  ;
    var oIntvlSecIpt ; 
    
    var osongPlaySettingSpan; 
    var omsgTipsSettingSpan;
    var oappRunSettingSpan;
    var osongfileIpt;
    var omsgIpt    ;
    var oappfileIpt ;
    var oappParamDiv ;
    var oappParamIpt ;
    var actionNameAr;
	


function CreateActTag(oParent, sCnt, oAction)
{
    var ndId     = oAction.selectSingleNode('Id');
    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 = 'taskBar';
 

    var _Id0 = 'dateSelectSpan' + (Math.random() * 1000000).toFixed(0);
    var _Id1 = 'delTblSpan' + (Math.random() * 1000000).toFixed(0);
    oTaskSpan.innerHTML = '<span class="left tskTagName" title="'+sCnt+'" id="' + _Id0 + '">' + sCnt + '</span><b class="right tskDel" 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 ;//oxmlActionGroupDoc
        }
        var i=0;
        for(i=0;i< oParent.childNodes.length;i++)
        {
            if (oParent.childNodes[i].id == this.parentNode.id) 
            {
               break;
            }
        }
        //var nLines  = oParent.childNodes.length;
        //var nLine =  - (-this.parentNode.line);
        var currNode = ogActionGroup.childNodes[i];//selectSingleNode("//Actions/Action["+nLine+"]");
 
        //alert(i+', '+currNode.xml);
        ogActionGroup.removeChild(currNode);
        //alert(ogActionGroup.xml);
        
        //删除当前标签
        oTaskSpan.parentNode.removeChild(oTaskSpan);
    });

}

function SetChildTskXml(s) 
{
    if (!s) 
    {
      return;
    }
    oxmlActionGroupDoc.loadXML(s);
    var node = oxmlActionGroupDoc.selectSingleNode("//Name");  
 
    //任务名称
    otskNameIpt.value = node.text;
 
    node = oxmlActionGroupDoc.selectSingleNode("//State");  
    if (!node) 
    {
       return;
    }
    gTskState= node.text;
    
    
    otitle_div.innerHTML = '编辑子任务';

    node = oxmlActionGroupDoc.selectSingleNode("//Id");  
    if (!node) 
    {
       return;
    }
    gChildId = node.text;

    //data offset
    node = oxmlActionGroupDoc.selectSingleNode("//Offset/Type"); 
    var offsetDateRds= document.getElementsByName('offsetDate') 
    //offsetDateRds[node.text].checked = true;
offsetDateRds[0].checked = true;

    node = oxmlActionGroupDoc.selectSingleNode("//Offset/Param"); 
    var s = node.text.match(/^(.*)(\.)(.*)$/);
    ooffsetDayIpt.value = s[1];

    var s1 = s[3].split(':');
    ooffsetHourIpt.value = s1[0];
    ooffsetMinIpt.value = s1[1];
    ooffsetSecIpt.value = s1[2];

    //execute times
    node = oxmlActionGroupDoc.selectSingleNode("//Freq/Type");  
    var nFreqType =  node.text;
    node = oxmlActionGroupDoc.selectSingleNode("//Freq/Times"); 
    orunTimesIpt.value =node.text;

    node = oxmlActionGroupDoc.selectSingleNode("//Freq/Interval"); 
    var sTmp = node.text;//.split('#ohs#');
    
    var oRds = document.getElementsByName('offsetMon');
    var oIntvlMonIpt = Comm.$('IntvlMonIpt');

    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;      
    
    }
    /*
    if (sTmp[0]=='0') 
    {
        //week interval
        oRds[0].click();
        oIntvlMonIpt.value = sTmp[1];
        
    }else
    {
        oRds[1].click();
        
        sTmp = sTmp[1].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;      
    
    }*/
//s = node.text.match(/^(.*)(\.)(.*)$/);
//oIntvlDayIpt.value= s[1]; 

//s1 = s[3].split(':');

//oIntvlHourIpt.value = s1[0];
//oIntvlMinIpt.value  = s1[1];
//oIntvlSecIpt.value  = s1[2];



//actions
node = oxmlActionGroupDoc.selectSingleNode("//Actions");
var ofirstAction = node.firstChild;


//Comm.removeAllChild(ogActionGroup);
    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:
            } 
 
            //alert(nIndex+', '+actionNameAr[nIndex]);
            
        var xmlDoc = oxmlActionGroupDoc;
        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;
} 
 
 
    //alert(node.text);
}

    
Comm.ReadyDoc(function () 
{
    olArrowSpan = Comm.$('lArrowSpan');
	orArrowSpan  = Comm.$('rArrowSpan');
	
    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
    
    
    oxmlActionGroupDoc = new ActiveXObject("Msxml2.Domdocument");
    oxmlActionGroupDoc.async=false;
    
    ogActionGroup = oxmlActionGroupDoc.createElement("Actions");
        
    otitle_div = Comm.$('title_div');
    oactionSel     = Comm.$('actionSel');
    oactCntDiv     = Comm.$('actCntDiv');
    
    oactionAddBtn  = Comm.$('actionAddBtn');
    omsgTips       = Comm.$('msgTips');
    osongfileIpt   = Comm.$('songfileIpt');
    omsgIpt        = Comm.$('msgIpt');
    oappfileIpt    = Comm.$('appfileIpt');
    oappParamDiv   = Comm.$('appParamDiv');
    oappParamIpt   = Comm.$('appParamIpt');
    
    osongPlaySettingSpan = Comm.$('songPlaySettingSpan'); 
    omsgTipsSettingSpan= Comm.$('msgTipsSettingSpan');
    oappRunSettingSpan= Comm.$('appRunSettingSpan');
 
    ooffsetDayIpt  = Comm.$('offsetDayIpt');
    ooffsetHourIpt  = Comm.$('offsetHourIpt');
    ooffsetMinIpt  = Comm.$('offsetMinIpt');
    ooffsetSecIpt  = Comm.$('offsetSecIpt');
    orunTimesIpt   = Comm.$('runTimesIpt');
    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;

	});
	
    otskNameIpt = Comm.$('tskNameIpt');
    
    
    actionNameAr = ["待机","休眠","关机","注销","重启","播放音乐","指定应用","唤醒"];//,"消息提示"
    for(var i=0;i<actionNameAr.length;i++)
    {
        var oOption =new Option(actionNameAr[i],i);
        oactionSel.options.add(oOption);
    }    
    
   
    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.$('actCntDiv');
//            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;//oactionSel.selectedIndex;
        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;
        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:
        }
    });
    
    Comm.addEvent(Comm.$('addTask'),'click',function () 
    { 
        var nCount=oactCntDiv.childNodes.length;
        if( 0 == nCount )
        {
            alert('请添加定时器触发后的执行动作');
            return;        
        } 
        
        gActionXmls=''; 
        var s ='' ; 
        var y=0,m=0,d=0,h=0,f=0,s=0;
        
        var xmlDoc = new ActiveXObject("Msxml2.Domdocument");
        xmlDoc.async=false;
        
 
        var oTask  = xmlDoc.createElement("Task");//"Child"
 
        var tskName = otskNameIpt.value;
        if (!tskName) 
        {
            tskName='未命名子任务';
        }
        tskName = tskName.substr(0,100);
  
        if (gChildId==0) 
        {
            gChildId=  (Math.random() * 1000000).toFixed(0);// 'TskChild' + 
        }
          
        var oChildId = xmlDoc.createElement("Id");oChildId.appendChild(xmlDoc.createCDATASection(gChildId));
        oTask.appendChild(oChildId);     
          
        oChildId = xmlDoc.createElement("State");oChildId.appendChild(xmlDoc.createCDATASection(gTskState));
        oTask.appendChild(oChildId);     
        
        var oTimerName = xmlDoc.createElement("Name");oTimerName.appendChild(xmlDoc.createCDATASection(tskName));
        oTask.appendChild(oTimerName);     
 
        //日期偏移，之前or 之后
        var offsetDateRds= document.getElementsByName('offsetDate'),nOffsetType=0;
//        for(var i=0;i<offsetDateRds.length;i++)
//        {
//            if (offsetDateRds[i].checked) 
//            {
//                nOffsetType =i;
//            }
//        } 
        nOffsetType =1;//只有之后，没有之前
        
        //下次任务被启动的日期：X年X月X日 时分秒  
        var oNextTime = xmlDoc.createElement("NextTrigTime");
        var oNextTimeType   = xmlDoc.createElement('Type');  oNextTimeType.appendChild(xmlDoc.createCDATASection("00"));
        var oNextTimeParam  = xmlDoc.createElement('Param0');oNextTimeParam.appendChild(xmlDoc.createCDATASection("-1"));//"2013.01.29"
        var oNextTimeParam1 = xmlDoc.createElement('Param1');oNextTimeParam1.appendChild(xmlDoc.createCDATASection("-1"));//"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); 
              
//        d  = ooffsetDayIpt.value;     if(!IsValidDay(d)){d=0;};   
//        h  = ooffsetHourIpt.value;    if(!IsValidHour(h)){h=0;};   
//        f  = ooffsetMinIpt.value;     if(!IsValidMin(f)){f=0;};
//        s  = ooffsetSecIpt.value;     if(!IsValidSec(s)){s=0;};

        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;};
  
        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=-1;
        var oRds = document.getElementsByName('offsetMon');
        for(var i=0;i<oRds.length;i++)
        {
            if (oRds[i].checked) 
            {
                nFreqType = i;
                break;
            }
        }
        
        if(nFreqType == 0)
        {
            s = Comm.$('IntvlMonIpt').value; if(!IsValidNum(s,-1e5,1e5)){alert('时间间隔输入框中，月份数必须为-100000~100000之间的整数'); return;s=0;};
            sParam =  s;//nFreqType + '#ohs#'+ ;
        }else if (nFreqType ==1) 
        {
//            d  = oIntvlDayIpt.value;     if(isNaN(d)){d=0;};   
//            h  = oIntvlHourIpt.value;    if(!IsValidHour(h)){h=0;};   
//            f  = oIntvlMinIpt.value;     if(!IsValidMin(f)){f=0;};
//            s  = oIntvlSecIpt.value;     if(!IsValidSec(s)){s=0;};
            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;        
        }
  


        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); 
        
        //执行动作
        var nactionType  = oactionSel.selectedIndex;
        sParam1 = '';
        if (osongfileIpt.style.visibility=='visible') 
        {
           sParam = osongfileIpt.value;
        }else if (omsgIpt.style.visibility=='visible') 
        {
           sParam = omsgIpt.value;        
        }else if (oappfileIpt.style.visibility=='visible') 
        {
           sParam = oappfileIpt.value;  
           sParam1 = oappParamIpt.value;           
        }
        
//        var oActionGroup = xmlDoc.createElement("Actions");
//        var oAction = xmlDoc.createElement("Action");
//            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));  
//        oAction.appendChild(oActType);
//        oAction.appendChild(oActParam0);
//        oAction.appendChild(oActParam1);
//        
//        oActionGroup.appendChild(oAction);
        oTask.appendChild(ogActionGroup); 
   
        //oChildGroup.appendChild(oTask);  
        
        //alert(oChildGroup.xml);
        
       
        window.external.sendChildTaskXml(oTask.xml, gChildId+'');
        //window.external.CB_Close();
        
         xmlDoc =null;
//         if (    otitle_div.innerHTML == '编辑子任务') 
//         {
//              alert('子任务修改成功');
//         }else
//         {
//              alert('成功添加子任务');
//         }
         window.external.CB_Close();
    });
    
    
});
