/*
	*2009/1/4 增加prototype版检查功能！
*/
if (DEPLOY_MODE=='undefined'){//调适模式和部署模式怎么区分
	var DEPLOY_MODE=true
}

var mbDocument= {
	Version: '1.0.0.1',
	REQUIRED_PROTOTYPE: '1.6.0',
	ICONURL:'http://vote.pctutu.net/v11/static/images/upload/',
	      TASKSOFTIDS:'',//任务列表的所有id
        DRIVEIDS: new Array(),//驱动所有id
        SOFTS: new Array(),//软件所有id
        DRIVESNOW_TOTAL: 0,//驱动现在操作个数
	AllowDownCount:5,
	_debug:1,
	load: function() {
		function convertVersionString(versionString){
		  var r = versionString.split('.');
		  return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
		}

		if((typeof Prototype=='undefined') || (typeof Element == 'undefined') ||  (typeof Element.Methods=='undefined') ||  (convertVersionString(Prototype.Version) < convertVersionString(mbDocument.REQUIRED_PROTOTYPE)))
		   throw("mbDocument requires the Prototype JavaScript framework >= " + mbDocument.REQUIRED_PROTOTYPE);

	},
	tip:function(obj,str){
		infoobj=obj.up(0).select("SPAN.info")[0];
		if (obj.tagName=='INPUT') obj.activate();
		if (infoobj){
			if (str!=''){
				infoobj.update(str);
				infoobj.className='info';
				infoobj.addClassName('warning');
			}else{
				infoobj.update('OK');
				infoobj.className='info';
                infoobj.addClassName('Success');
			}
		}
	},
	SetDebuger:function(_debuge){
		this._debug = _debuge;
		if(_debuge == 0)
		{
			$('dbg_nav').hide();
		} else {
			$('dbg_nav').show();
		}
	},
	fixPng:function() {
		var arVersion = navigator.appVersion.split("MSIE")
		var version = parseFloat(arVersion[1])

		if ((version >= 5.5 && version < 7.0) && (document.body.filters)) {
			var png = /\.png$/i;
			var imgs = document.getElementsByTagName('img');
			for(var i = 0, l = imgs.length; i < l; i++) {
				if(png.test(imgs.item(i).src)) {
					imgs.item(i).style.width = imgs.item(i).offsetWidth;
					imgs.item(i).style.height = imgs.item(i).offsetHeight;
					imgs.item(i).style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgs.item(i).src + '\',sizingMethod=\'image\')';
					imgs.item(i).src = 'empty.gif';
				}
			}
		}

	},
	/**
	*tabSwitch(标头对象集，内容对象集，当前对象，对象CSS名称集['on','off'])
	*/
	tabSwitch:function(ttlObject,cntObject,selTab,classNames){
		//alert(selTab)
		if(Object.isUndefined(classNames)){
			classNames=['on','off']
		}
		selIndex=ttlObject.indexOf(selTab);
		if (selIndex==-1){
			return;
		}
		ttlObject.each(function(tab){
			//alert(ttlObject[selIndex],tab.index)
			tab.className=(ttlObject[selIndex]==tab)?classNames[0]:classNames[1];

		})
		cntObject.each(function(main){
			main.style.display=(cntObject[selIndex]==main)?'block':'none';
		})

	}
	,
	parseString:function(PString,div1,div2){
		if (PString=='' || PString.replace(/\s/g,'')==''){
			return new Array();
		}
		if(Object.isUndefined(div1)) div1='\n';
		if(Object.isUndefined(div2)) div2='|';
		var items=PString.split(div1);
		var result=new Array();
		for (i=0;i<items.length;i++){
			if (items[i].replace(/\s/g,'').length>1){
				result[result.length]=items[i].split(div2)
			}
		}
		return result;
	}
	,
	//id|softname|softico|softdescription|advices|status|isMicrosoft
	addItems:function(PString,index){
		if(Object.isUndefined(index)) index='0';
		var items = this.parseString(PString);
		$(index+'_Item_Length').innerHTML=items.length;

		var myTemplate = new Template(
			'<li id="'+index+'_item_#{0}" class="bgChange Status_#{5} MS_#{6}">'
			+'<div class="start_name2">'
			+'    <div class="softico fl"><img src="#{2}" width="32" height="32" /></div>'
			+'    <div class="kq fl">'
			+'      <div class="kq1">'
			+'				<div class="fl start_name3">#{1}</div>'
			+'				<div class="soft_beta fl">#{4} </div>'
			+'				<div class="soft_beta2 fl" id="'+index+'_status_Item_#{0}" style="display:none;"></div>'
			+'				<div class="starting fl" id="'+index+'_btn_Item_#{0}"></div>'
			+'				<div class="path" id="'+index+'_path_Item_#{0}"></div>'
/*			+'	<div style="clear:both"></div>'*/
			+'      </div>'
			+'      <div class="kq2"><a href="jvascript:;" title="#{3}" style="color:#c0c0c0">#{3}</a></div>'
			+'    </div>'
			+'  </div>'
			+'</li>'
		);

		var html="";
		var count=0;
		items.each(function(conv){
			count++;
			html+=myTemplate.evaluate(conv);
		})
		$(index+'_WinStartItem').innerHTML=html;
		var StartedApplication=0;
		items.each(function(conv){
			if (parseInt(conv[6])===1 && index==1){
				if (!$(index+'_lstMS_Item').checked) $(index+'_item_'+conv[0]).hide();
			}
			if (parseInt(conv[5])===0){
				$(index+'_btn_Item_'+conv[0]).innerHTML='<a href="ExecCmd=openItem;ID='+conv[0]+'"><img src="start.jpg" class="btn" /></a>'
				//$(index+'_status_Item_'+conv[0]).innerHTML="已禁止";
				if (!$(index+'_lstRootStart').checked && parseInt(conv[6])===0) $(index+'_item_'+conv[0]).hide();
			}else{
				$(index+'_btn_Item_'+conv[0]).innerHTML='<a href="ExecCmd=closeItem;ID='+conv[0]+'"><img src="ban.jpg" class="btn" /></a>'
				//$(index+'_status_Item_'+conv[0]).innerHTML="已启动";
				if (parseInt(conv[6])===0) StartedApplication++;
				$(index+'_path_Item_'+conv[0]).innerHTML='<a href="ExecCmd=openPath;ID='+conv[0]+'">位置</a>';
			}


		})
		$(index+'_Item_StartedLength').innerHTML=StartedApplication;
		this.btnStatus();
		this.bindLiMouse();
	},

	//id|osname|language|checked(1 is checked)|GUID
	addItemsOs:function(PString,index){
		index='2';
		var items = this.parseString(PString);
		$(index+'_Item_Length').innerHTML=items.length;

		var myTemplate = new Template(
			'<li id="'+index+'_item_#{0}" class="bgChange Status_#{3}">'
			+'	  <div class="mr">'
			//+'		 <form id="form1" name="form1" method="post" action="">'
			+'		   <label>'
			+'			  <input type="radio" name="os" id="os_#{0}" value="#{4}" />'
			+'			  <input type="hidden" name="osOrder_#{0}" id="osOrder_#{0}" value=#{0} />'
			+'		  </label>'
			//+'	   </form>'
			+'	  </div>'
			+'	  <div class="xtmc">#{1}</div>'
			+'	  <div class="yy">#{2}</div>'
			+'</li>		'
		);

		var html="";
		var count=0;
		items.each(function(conv){
			count++;
			html+=myTemplate.evaluate(conv);
		})
		$(index+'_WinStartItem').innerHTML=html;

		this.bindLiMouse();

		$(index+'_span1').innerHTML='<a href="javascript:onClick=mbDocument.move(\'up\',' + items.length + ');"><img height="29" width="80"  src="up.jpg"  class="btn" ></a>';
		$(index+'_span2').innerHTML='<a href="javascript:onClick=mbDocument.move(\'down\',' + items.length + ');"><img height="29" width="80"  src="down.jpg"  class="btn"></a>';
		this.btnStatus();

	},
	//id|osname|language|checked(1 is checked)|GUID
	addsoft_recom:function(Strinfo){
		var myTemplate = new Template(
                   '<li >'
                   +'	   <div ><img src="#{0}" width="32" height="32"></div>'
		   +'	   <div class="STYLE2">#{1}</div>'
		   +'	   <img class="btn" src="images/setup.png">'
		   +'</li>'
		);

		var items = this.parseString(Strinfo);
		var html="";
		var count=0;
		items.each(function(conv){
			count++;
			html+=myTemplate.evaluate(conv);
		})
                html='<ul>'+html+'</ul>';

		$('recomsofts').innerHTML=html;

	},
        page_tabswicth:function(num){
            var page=new Array('recommend','category','drive','progress');
            for(var i=0;i<page.length;i++){
                if(page[i]==num){
                   $(page[i]).show();
                }else{
                   $(page[i]).hide();
                }
            }
        },
        //添加软件列表： 类别|软件数
	addsortlist:function(Strinfo){
		 var ss = '';
		 if(this._debug == 1) {
                   ss = '<li id="category_#{1}" style="cursor: pointer;"  onclick="mbDocument.showpage(\'#{1}\')">';
                   } else {
                   ss = '<li id="category_#{1}" style="cursor: pointer;"  onclick="window.navigate(\'app://page=2&action=initsoftdetail&CID=#{1}\')">';
                 }
		var myTemplate = new Template(
                    ss
                   +'<span class="span1" >#{0}</span>'
                   +'<span class="span2" id="pcount_#{1}">#{2})</span>'
                   +'<span class="span2" id="sl_#{1}">(</span>'
                   +'</li>'
		);

		var myTemplatepage = new Template(
                    '<ul id="softlist_#{1}" style="display:none"></ul>'
		);

		var items = this.parseString(Strinfo);
		var html="";
                var count=new Array();
                var i=0;
                var k='';
		items.each(function(conv){
                        //添加右侧ul
                        if(i==0){
                            k='softlist_0';
                            //alert(k);
                            new Insertion.After(k,myTemplatepage.evaluate(conv));
                        }else{
                            k=i-1;
                            //alert(count[k]);
                            new Insertion.After(count[k],myTemplatepage.evaluate(conv));
                        }
                        count[i]='softlist_'+conv[1];
                        i++;
                        //添加left 列表
			html+=myTemplate.evaluate(conv);
		})
		$('sortlist').innerHTML=html;
	},
	addtasklist:function(Strinfo){
		var ss = '';
		 if(this._debug == 1){
		 	ss = ' <span class="li5" ><span  style="display:;" id="setup_t_#{0}"><a onclick="mbDocument.downSoft(#{0},0,0);"  href="#" title="安装"><img border="0/" src="images/setup.png"></a></span><span style="display:none" id="setupset_t_#{0}"><span  ><a onclick="mbDocument.pauseDownsoft(\'#{0}\',\'pausedown\');" href="#" id="pause_Soft_Down_t_#{0}" title="暂停下载"><img width="16" height="16" border="0/" src="images/pause.png"></a></span><span style="padding-left:10px;"><a onclick="mbDocument.pauseDownsoft(#{0},\'stopdown\');" href="#" id="cancel_Soft_Down_t_#{0}" title="取消下载"><img width="16" height="16" border="0/" src="images/esc.png"></a></span></span></span> ';

		} else {
			ss = ' <span class="li5" ><span  style="display:;" id="setup_t_#{0}"><a onclick="mbDocument.downSoft(#{0},0,0);window.navigate(\'app://page=2&action=downsoft&SID=#{0}\');"  href="#" title="安装"><img border="0/" src="images/setup.png"></a></span><span style="display:none" id="setupset_t_#{0}"><span  ><a onclick="mbDocument.pauseDownsoft(#{0},\'pausedown\');" href="#" id="pause_Soft_Down_t_#{0}" title="暂停下载"><img width="16" height="16" border="0/" src="images/pause.png"></a></span><span style="padding-left:10px;"><a  onclick="mbDocument.pauseDownsoft(#{0},\'stopdown\');" href="#" id="cancel_Soft_Down_t_#{0}" title="取消下载"><img width="16" height="16" border="0" src="images/esc.png"></a></span></span></span> ';
		}
		var myTemplate = new Template(
                    '<li id="s_t_#{0}">'
                    +' <span class="li1"><a onclick="mbDocument.soft_checked(#{0});" href="#"><img id="soft_t_#{0}_0" src="images/uncheckbox.png" class="btn"><img style="display:none;" id="soft_t_#{0}_1" src="images/checkbox.png" class="btn"></a><input type="hidden" id="soft_t_#{0}" name="softs[]" value=""></span>'
                    +' <span  class="li2" ><img src="'+this.ICONURL+'#{1}"></span>'
                    +' <span class="li3"><div  class="softitle">#{2}</div><div  class="softdec">#{3}</div></span>'
                    +' <span  class="li4"><span style="display:; margin-top:15px;"  id="softsize_t_#{0}">#{4}MB</span><span style="display:none;" class="posbg" id="jdt_t_#{0}"><span  id="jdt_percentage_t_#{0}" class="pos" style="width: 0%;"></span></span><span style="font-size:13px; margin-top:-5px;margin-left:20px;display:" id="speed_t_#{0}"></span></span> '
                    +ss
                    +'</li>'
		);


		var myTemplate_commend = new Template(
                    '<li id="s_t_#{0}" class="softbg">'
                    +' <span class="li1"><a onclick="mbDocument.soft_checked(#{0});" href="#"><img style="display:none;" id="soft_t_#{0}_0" src="images/uncheckbox.png" class="btn"><img  id="soft_t_#{0}_1" src="images/checkbox.png" class="btn"></a><input type="hidden" id="soft_t_#{0}" name="softs[]" value="1"></span>'
                    +' <span  class="li2" ><img src="'+this.ICONURL+'#{1}"></span>'
                    +' <span class="li3"><div  class="softitle">#{2}</div><div  class="softdec">#{3}</div></span>'
                    +' <span  class="li4"><span style="display:; margin-top:15px;"  id="softsize_t_#{0}">#{4}MB</span><span style="display:none;" class="posbg" id="jdt_t_#{0}"><span  id="jdt_percentage_t_#{0}" class="pos" style="width: 0%;"></span></span><span style="font-size:13px; margin-top:-5px;margin-left:20px;display:" id="speed_t_#{0}"></span></span> '
                    +ss
                    +'</li>'
		);
                    
		var items = this.parseString(Strinfo);
		var html="";
		var count=items.length;
                var kk='';
		items.each(function(conv){
                        if(conv[5]==1){//推荐
                            html+=myTemplate_commend.evaluate(conv);
                        }else{
                            html+=myTemplate.evaluate(conv);
                        }
			

                        var p=1;
                        for(var k=0;k<conv.length;k++){
                            if(p==1){
                               kk+=','+conv[0];
                            }
                            p++;
                        }


		})
		$('softlist_0').innerHTML=html;
                $('softlist_0').show();
                $('currentpage').value="0";

                $('pcount_0').innerHTML=count+')';

                //记录所有任务软件id
                kk=kk.substr(1);
                this.TASKSOFTIDS=kk;
                
                //this.setchkstatue(2,1);//任务软件全选

	},
        //添加软件页面
	addsoftlist:function(pageid,Strinfo){
		var ss = '';
		 if(this._debug == 1){
		 	ss = ' <span class="li5" ><span  style="display:;" id="setup_#{0}"><a onclick="mbDocument.downSoft(#{0},0,0);"  href="#" title="安装"><img border="0" class="btn" src="images/setup.png"></a></span><span style="display:none" id="setupset_#{0}"><span  ><a onclick="mbDocument.pauseDownsoft(#{0},\'pausedown\');" href="#" id="pause_Soft_Down_#{0}" title="暂停下载"><img width="16" height="16" border="0/" src="images/pause.png"></a></span><span style="padding-left:10px;"><a onclick="mbDocument.pauseDownsoft(#{0},\'stopdown\');" href="#" id="cancel_Soft_Down_#{0}" title="取消下载"><img width="16" height="16" border="0/" src="images/esc.png"></a></span></span></span>';

		} else {
			ss =' <span class="li5" ><span  style="display:;" id="setup_#{0}"><a onclick="window.navigate(\'app://page=2&action=downsoft&SID=#{0}\');"  href="#" title="安装"><img border="0" class="btn" src="images/setup.png"></a></span><span style="display:none" id="setupset_#{0}"><span  ><a onclick="mbDocument.pauseDownsoft(#{0},\'pausedown\');" href="#" id="pause_Soft_Down_#{0}" title="暂停下载"><img width="16" height="16" border="0/" src="images/pause.png"></a></span><span style="padding-left:10px;"><a onclick="mbDocument.pauseDownsoft(#{0},\'stopdown\');" href="#" id="cancel_Soft_Down_#{0}" title="取消下载"><img width="16" height="16" border="0/" src="images/esc.png"></a></span></span></span>';
		}
		var myTemplate = new Template(
                    '<li id="s_#{0}">'
                    //+' <span class="li1" ><a onclick="mbDocument.soft_checked(#{0});" href="#"><img id="soft#{0}_0" src="images/uncheckbox.png" class="btn"><img style="display:none;" id="soft#{0}_1" src="images/checkbox.png" class="btn"></a><input type="hidden" id="soft_#{0}" name="softs[]" value=""></span>'
                    +' <span class="li1_1" ><input type="hidden" id="soft_#{0}" name="softs[]" value=""></span>'
                    +' <span class="li2" ><img src="'+this.ICONURL+'#{1}"></span>'
                    +' <span class="li3" ><div class="softitle">#{2}</div><div class="softdec">#{3}</div></span>'
                    +' <span class="li4" ><span style="display:;"  id="softsize_#{0}" class="softsize">#{4}MB</span><span style="display:none;" class="posbg" id="jdt_#{0}"><span  id="jdt_percentage_#{0}" class="pos" style="width: 0%;"></span></span><span style="margin-left:20px;display:" class="speed" id="speed_#{0}"></span></span> '
                    + ss
                    +'</li>'
		);

		var items = this.parseString(Strinfo);
		var html="";
//		var count=items.length;
//                $('pcount_'+pageid).innerHTML=count+')';
		items.each(function(conv){
			html+=myTemplate.evaluate(conv);
 
		})
		$('softlist_'+pageid).innerHTML=html;

                //this.showpage(pageid);
	},
	adddrivelist:function(driveid,drivename,Strinfo){
                var htmltop,htmlbottom='',htmlmiddle;
		var myTemplate = new Template(
                    '<tr>'
                    +'  <td height="21">&nbsp;</td>'
                    +'  <td width="2%">&nbsp;&nbsp;&nbsp;</td>'
                    +'  <td width="39%" align="left">#{0}</td>'
                    +'  <td width="20%" align="left" class="font666766">#{1}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>'
		);

		var items = this.parseString(Strinfo);
		var html="";
                var drive_arr=new Array();
                var iL = 0;
		items.each(function(conv){
                    //conv[3]=i;
                    //根据状态设置不同的模板
                    if(conv[2]==0){
                       htmlmiddle='  <td width="22%"><span class="redfont" id="dcheck_'+driveid+'_'+conv[3]+'">未安装</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
                       htmlmiddle+='  <td width="25%"><span id="dupdate0_'+driveid+'_'+conv[3]+'"><a href="#" onclick="mbDocument.dri_checked(\''+driveid+'_'+conv[3]+'\');"><img class="btn" src="images/uncheckbox.png" id="drivespic0_'+driveid+'_'+conv[3]+'" ><img class="btn" src="images/checkbox.png" id="drivespic1_'+driveid+'_'+conv[3]+'" style="display:none;" ></a>&nbsp;<span class="valign">安装驱动</span></span>';
                       htmlmiddle+=' <input type="hidden" value="" name="drives[]" id="drives_'+driveid+'_'+conv[3]+'"></td>';
                       htmlmiddle+=' </tr>';
                    }else if(conv[2]==1){
                       htmlmiddle='  <td width="22%"><span class="greenfont" id="dcheck_'+driveid+'_'+conv[4]+'">已安装</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
                       htmlmiddle+='  <td width="25%"><span id="dupdate0_'+driveid+'_'+conv[3]+'"><a href="#" onclick="mbDocument.dri_checked(\''+driveid+'_'+conv[3]+'\');"><img class="btn" src="images/uncheckbox.png" id="drivespic0_'+driveid+'_'+conv[3]+'" ><img class="btn" src="images/checkbox.png" id="drivespic1_'+driveid+'_'+conv[3]+'" style="display:none;" ></a>&nbsp;<span class="valign">更新驱动</span></span>';
                                              htmlmiddle+=' <input type="hidden" value="" name="drives[]" id="drives_'+driveid+'_'+conv[3]+'"></td>';
                       htmlmiddle+=' </tr>';
                    }else if(conv[2]==2){
                       htmlmiddle='  <td width="22%"><span class="greenfont" id="dcheck_'+driveid+'_'+conv[3]+'">已安装</span>&nbsp;&nbsp;&nbsp;&nbsp;</td>';
                       htmlmiddle+='  <td width="25%"><span id="dupdate1_'+driveid+'_'+conv[3]+'" class="greenfont fontweight">已安装最新版</span></td>';
                       htmlmiddle+=' <input type="hidden" value="2" name="drives[]" id="drives_'+driveid+'_'+conv[3]+'"></td>';
                       htmlmiddle+=' </tr>';
                    }

                    drive_arr[iL]='drives_'+driveid+'_'+conv[3];
                    iL ++;

		                html+=myTemplate.evaluate(conv);
                    html+=htmlmiddle;
                    //i++;
								})
			iL = this.DRIVEIDS.length;
                for(var i=0;i<drive_arr.length;i++){
                	this.DRIVEIDS[iL+i] = drive_arr[i];
                }

                  if(driveid==1){
                      icon='titlelogo_mainboard.png';
                  }else if(driveid==2){
                      icon='titlelogo_memory.png';
                  }else if(driveid==3){
                      icon='titlelogo_network.png';
                  }else if(driveid==4){
                      icon='titlelogo_monitor.png';
                  }else if(driveid==5){
                      icon='titlelogo_hdd.png';
                  }else if(driveid==6){
                      icon='titlelogo_display.png';
                  }else if(driveid==7){
                      icon='titlelogo_cpu.png';
                  }else if(driveid==8){//声卡
                      icon='titlelogo_audio.png';
                  }else{
                      icon='titlelogo.png';
                  }
                var dirid_total=$('dirid_total').value;

                htmltop='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>';
                htmltop+='<td width="2%" height="28" >&nbsp;&nbsp;&nbsp;</td>';
                htmltop+='<td colspan="5" align="left" valign="bottom"><img src="images/'+icon+'" width="19" height="19" class="valign" />&nbsp;<span class="valign">'+drivename+'</span></td>';
                htmltop+='</tr>';

                htmlbottom='<tr>';
                htmlbottom+='<td ></td>';
                htmlbottom+='<td colspan="5"><img src="images/drive_bg.png" width="651" height="2" /></td>';
                htmlbottom+='</tr></table>';

                html=htmltop+html+htmlbottom;
                if(dirid_total==0){
                    $('drivelist').innerHTML='<div id="driveid_1">'+html+'</div>';
                    //alert('<div id="driveid_1">'+html+'</div>');
                }else{
                    var afterid=parseInt(dirid_total)+parseInt(1);
                    new Insertion.After('driveid_'+dirid_total,'<div id="driveid_'+afterid+'">'+html+'</div>');
                    //alert('<div id="driveid_'+dirid_total+'">'+html+'</div>');
                }
                $('dirid_total').value=parseInt(dirid_total)+parseInt(1);

                this.btnStatus();
	},
        setchkstatue:function(pageid,type){
             if(pageid==2){
                  var idx='';
                  var id='';
                  //alert('p:'+p);
                   var soft_arr=new Array();
                   soft_arr=this.TASKSOFTIDS.split(',');
                   for(var i=0;i<soft_arr.length;i++){

                       //任务id
                       var sid_t='soft_t_'+soft_arr[i];
                       var sid_t_img0=sid_t+'_0';
                       var sid_t_img1=sid_t+'_1';
                        if(type=='1'){//全选
                           $(sid_t_img0).hide();
                           $(sid_t_img1).show();
                           $(sid_t).value='1';
                           $('s_t_'+soft_arr[i]).className='softbg';
                        }else{//全不选
                           $(sid_t_img0).show();
                           $(sid_t_img1).hide();
                           $(sid_t).value='';
                           $('s_t_'+soft_arr[i]).className='';
                       }

//                      id=soft_arr[i];
//                       //软件id
//                       var sid='s_'+id;
//                       //var sid_img0='soft'+id+'_0';
//                       //var sid_img1='soft'+id+'_1';
//                       if($(sid).value==''){
//                           //$(sid_img0).hide();
//                           //$(sid_img1).show();
//                           $(sid).value='1';
//                           $('s_'+id).className='softbg';
//                       }else{
//                           //$(sid_img0).show();
//                           //$(sid_img1).hide();
//                           $(sid).value='';
//                           $('s_'+id).className='';
//                       }
                    }


                    //this.NotifyChkStatue();
                    this.btnStatus();
             }else if(pageid==3){
              var idx='';
              //alert('p:'+p);
               for(var i=0;i<this.DRIVEIDS.length;i++){
                   if($(this.DRIVEIDS[i]).value!='2' ){//等于2的是已安装更新
                       cid=this.DRIVEIDS[i].replace(/drives_/g,'');
                       var c_id=this.DRIVEIDS[i];
                       var cid_img0='drivespic0_'+cid;
                       var cid_img1='drivespic1_'+cid;
                       //alert(i+':'+this.DRIVEIDS[i]);


                       if(type=='1'){//全选
                           $(cid_img0).hide();
                           $(cid_img1).show();
                           $(c_id).value='1';




                       }else{//全不选
                           $(cid_img0).show();
                           $(cid_img1).hide();
                           $(c_id).value='';



                       }
                  }
                }
                this.NotifyChkStatue();
                this.btnStatus();
             }
        },
        pageint:function(){
                $('currentpage').value="0";
        },
	addsoftlist_ago:function(pageid,Strinfo){
		var myTemplate = new Template(
                    '<li>'
                   +'	   <span class="li1" ></span>'
                   +'	   <span class="li2" ><img src="'+this.ICONURL+'#{1}"></span>'
                   +'	   <span class="li3" >#{2}</span>'
                   +'	   <span class="li4" id="softsize_#{0}">8.7M</span><span class="li4" id="jdt_#{0}" style="display:none;"></span><span id="speed_#{0}"></span>'
                   +'	   <span class="li5" ><span class="margintop" id="setup_#{0}" onclick="mbDocument.downSoft(1,60,65);">安装</span><span class="margintop" id="setupset_#{0}" style="display:none;"><a title="暂停下载" id="pause_Soft_Down_#{0}" href="#" onclick="mbDocument.pauseDownsoft(#{0},\'pausedown\');"><img width="16" height="16" border="0/" src="images/pause.png"></a>&nbsp;&nbsp;<a title="取消下载" id="cancel_Soft_Down_#{0}"  href="#" onclick="mbDocument.pauseDownsoft(#{0},\'stopdown\');"><img width="16" height="16" border="0/" src="images/esc.png"></a></span></span>'
                  // +'	   <span class="li5" ><span class="margintop" id="setup_#{0}" onclick="window.navigate(\'app://page=2&action=downsoft&SID=#{0}\');">安装</span><span class="margintop" id="setupset_#{0}" style="display:none;"><a title="暂停下载" id="pause_Soft_Down_#{0}" href="#" onclick="window.navigate(\'app://page=2&action=downsoft&SID=#{0}\');"><img width="16" height="16" border="0/" src="images/pause.png"></a>&nbsp;&nbsp;<a title="取消下载" id="cancel_Soft_Down_#{0}"  href="#" onclick="window.navigate(\'app://page=2&action=stopdown&SID=#{0}\');"><img width="16" height="16" border="0/" src="images/esc.png"></a></span></span>'
                   +'</li>'
		);

		var items = this.parseString(Strinfo);
		var html="";
//		var count=items.length;
//                $('pcount_'+pageid).innerHTML=count+')';
		items.each(function(conv){
			html+=myTemplate.evaluate(conv);
 
			
		  })
 
		 
		$('softlist_'+pageid).innerHTML=html;

                this.showpage(pageid);
	},
	//暂停下载
	pauseDownsoft:function(id,action){ //pausedown stopdown
		        	  if(id=='-1'){//外部下载和本函数无关
        	     	  return;
        	      }
                if($('speed_'+id) && $('speed_t_'+id)){
                   var ids=new Array('t_','');
                }else if($('speed_'+id)){
                	 var ids=new Array('');
                }else{
                   var ids=new Array('t_');
                }

                for(var i=0;i<ids.length;i++){
                    sid=ids[i]+id;

                    if (action=='pausedown'){	//查找主对象是否存在
                            var pausePic=$('pause_Soft_Down_'+sid).select('img')[0].src;

                            if(pausePic.indexOf('continue.png')!=-1){
                               $('pause_Soft_Down_'+sid).select('img')[0].src='images/pause.png';	//更改图片
                               if(this._debug == 0){
                              	 window.navigate('app://page=2&action=downsoft&sid='+id);
                             }
                            }else{
                               $('pause_Soft_Down_'+sid).select('img')[0].src='images/continue.png';	//更改图片
                               if(this._debug == 0){
                              	 window.navigate('app://page=2&action=stopdown&sid='+id);
                             }
                            }

                    }else if(action=='stopdown'){
                            $('softsize_'+sid).show();
                            $('jdt_'+sid).hide();

                            $('setup_'+sid).show();
                            $('setupset_'+sid).hide();
                            $('speed_'+sid).hide();
                            $('pause_Soft_Down_'+sid).select('img')[0].src='images/pause.png';//图片变过来
                            if(this._debug == 0){
                            	//alert('aa');
                           	 window.navigate('app://page=2&action=stopdown&sid='+id);
                            }
                            
                    }else if(action=='stopdownByHost'){
                            $('softsize_'+sid).show();
                            $('jdt_'+sid).hide();

                            $('setup_'+sid).show();
                            $('setupset_'+sid).hide();
                            $('speed_'+sid).hide();
                            $('pause_Soft_Down_'+sid).select('img')[0].src='images/pause.png';//图片变过来                            
                            
                    }

                }
	},
	
        downSoft:function(id, percentage,speed){
        	      if(id=='-1'){//外部下载和本函数无关
        	     	  return;
        	      }
                //var ids=new Array('t_','');
                if($('speed_'+id) && $('speed_t_'+id)){
                   var ids=new Array('t_','');
                }else if($('speed_'+id)){
                	 var ids=new Array('');
                }else{
                   var ids=new Array('t_');
                }
                for(var i=0;i<ids.length;i++){
                        sid=ids[i]+id;
                        percentage=parseInt(percentage);
				if (percentage<100 && percentage>=0){
                                        $('softsize_'+sid).hide();
                                        $('jdt_'+sid).show();
					if($('jdt_percentage_'+sid)){//软件进度
					   $('jdt_percentage_'+sid).style.width=percentage+'%';//
                                           //$('jdt_percentage'+sid).innerHTML=percentage+'%';//
                                           //$('jdt_percentage'+sid).className='posbg';//
					}
          if(percentage==0){
                 $('speed_'+sid).innerHTML='等待下载';//
          }else{
                 $('speed_'+sid).innerHTML=percentage+'%  '+speed+'KB/S';//
          }				

                                        $('setup_'+sid).hide();
                                        $('setupset_'+sid).show();
                                        $('speed_'+sid).show();

                                        //任务列表
                                        //$('jdt_task_'+sid).style.wsidth=percentage+'%';//
                                        //$('speed_task_'+sid).innerHTML=percentage+'%<span>'+speed+'/S</span>';//
				}else if(percentage===-1){
					$('speed_'+sid).innerHTML='下载失败';	//列表速度 进度
				}else if(percentage==100){
					if($('jdt_percentage_'+sid)){//软件进度
					   $('jdt_percentage_'+sid).style.width=percentage+'%';//
					}
                                        $('softsize_'+sid).hide();
                                        $('jdt_'+sid).show();
                                        //$('setup_'+sid).hide();
                                        $('setupset_'+sid).hide();
					$('speed_'+sid).innerHTML='下载完成';
				}
                }

        },
        showpage:function(nextpage){
            var currentpage=$('currentpage').value;
           // alert(currentpage+'=='+nextpage);
            if(nextpage!=currentpage){
                $('currentpage').value=nextpage;
                $('softlist_'+currentpage).hide();//关闭当前页
                $('softlist_'+nextpage).show();//打开下一页
                $('softlist').scrollTop=0;
            }
            $('category_'+currentpage).className='';    //状态不显示
            $('category_'+nextpage).className='list_on';

            //全选按钮关闭
            if(nextpage!=0){
                $("softlist").className="softlist";
                $("checkall").hide();
            }else{
                $("softlist").className="softlist_task";
                $("checkall").show();
            }
            
        },
        //图片按钮选择
        pic_checked:function(cid){
               var c_id='c_'+cid;
               var cid_img0='recom'+cid+'_0';
               var cid_img1='recom'+cid+'_1';
               if($(c_id).value==''){
                   $(cid_img0).hide();
                   $(cid_img1).show();
                   $(c_id).value=cid;
               }else{
                   $(cid_img0).show();
                   $(cid_img1).hide();
                   $(c_id).value='';
               }
        },
        //软件按钮选择
        soft_checked:function(id){
               //任务id
               var sid_t='soft_t_'+id;
               var sid_t_img0='soft_t_'+id+'_0';
               var sid_t_img1='soft_t_'+id+'_1';
               if($(sid_t).value==''){
                   $(sid_t_img0).hide();
                   $(sid_t_img1).show();
                   $(sid_t).value='1';
                   $('s_t_'+id).className='softbg';
               }else{
                   $(sid_t_img0).show();
                   $(sid_t_img1).hide();
                   $(sid_t).value='';
                   $('s_t_'+id).className='';
               }

               //软件id
               var sid='soft_'+id;
               //var sid_img0='soft'+id+'_0';
               //var sid_img1='soft'+id+'_1';
               if($(sid).value==''){
                   //$(sid_img0).hide();
                   //$(sid_img1).show();
                   $(sid).value='1';
                   $('s_'+id).className='softbg';
               }else{
                   //$(sid_img0).show();
                   //$(sid_img1).hide();
                   $(sid).value='';
                   $('s_'+id).className='';
               }



        },
        //驱动图片按钮选择
        dri_checked:function(cid){
               var c_id='drives_'+cid;
               var cid_img0='drivespic0_'+cid;
               var cid_img1='drivespic1_'+cid;


               var driveidx_len=this.DRIVEIDS.length-1;//总长度
               var driveidx_len_1=driveidx_len-1;//总长度-1
               var p=this.dri_setupcount();

               //alert(this.DRIVESNOW_TOTAL);
               if($(c_id).value==''){
                   $(cid_img0).hide();
                   $(cid_img1).show();
                   $(c_id).value='1';


               }else{
                   $(cid_img0).show();
                   $(cid_img1).hide();
                   $(c_id).value='';



               }
               //全选发送消息
               this.NotifyChkStatue();
               this.btnStatus();
        },
        dri_setupcount:function(){
                   var p=0;
                   for(var j=0;j<this.DRIVEIDS.length;j++){
                   	  if($(this.DRIVEIDS[j]).value!=2){
                   	  	 p++;

                   	  }
                  }
                  return p;
        },

        NotifyChkStatue:function(){
        	var ics = 0,ic1 = 0;
        	ics = this.dri_setupcount();
        	for(var i=0;i<this.DRIVEIDS.length;i++){
        		if($(this.DRIVEIDS[i]).value==1){
        			ic1++;
        		}
        	}
        	if(ic1 == ics){
	        		if(this._debug == 1){
	        			alert('全选了...');
	        		}else{
	        			window.navigate('app://page=3&action=chkall');
	        		}
        		}else{
	        			if(this._debug == 1){
		        			alert('meiyselall...');
		        		}else{
		        			window.navigate('app://page=3&action=unchk');
		        		}
        		}
      	},
        //提交分类
        submit_category:function(){
               var cids=new Array(10403,10076,10087,10075,10086,10088,10085,10084);
               var cidstr="";
               for(var i=0;i<cids.length;i++){
                   if($('c_'+cids[i]).value!=''){
                       cidstr+=","+cids[i];                      
                   }
               }               
               return cidstr.substring(1);
        },
        //提交驱动选中
        submit_drive:function(){
               var cids=new Array();
               cids=this.DRIVEIDS;               
               var cidstr="";
               for(var i=0;i<cids.length;i++){
                   if($(cids[i]).value=='1' ){
                       cidstr+=","+cids[i];
                   }
               }
               if(this._debug == 1) {
                        alert(cidstr.substring(1));
                   } else {
                        return cidstr.substring(1);
               }
        },
        //提交软件选中
        submit_soft:function(){
 
               var cids=new Array();
               cids=this.TASKSOFTIDS.split(',');
               var cidstr='';
               if(this.TASKSOFTIDS==''){
               	  return '';
               }
               for(var i=0;i<cids.length;i++){
                   if($('soft_t_'+cids[i]).value=='1' ){
                       cidstr+=","+cids[i];
                   }
               }
               if(this._debug == 1) {
                        alert(cidstr.substring(1));
                   } else {
                        return cidstr.substring(1);
               }
        },
	chg_ItemStatus:function(id,status,index){
		if(Object.isUndefined(index)) index='0';
		if (parseInt(status)===0){
			$(index+'_btn_Item_'+id).innerHTML='<a href="ExecCmd=openItem;ID='+id+'"><img src="start" class="btn" /></a>'
			//$(index+'_status_Item_'+id).innerHTML="已禁止";

			$(index+'_item_'+id).removeClassName('Status_0');
			$(index+'_item_'+id).removeClassName('Status_1');
			$(index+'_item_'+id).addClassName('Status_0');
			$(index+'_path_Item_'+id).innerHTML="";
		}else{
			$(index+'_btn_Item_'+id).innerHTML='<a href="ExecCmd=closeItem;ID='+id+'"><img src="ban.jpg" class="btn" /></a>'
			//$(index+'_status_Item_'+id).innerHTML="已启动";
			$(index+'_path_Item_'+id).innerHTML="位置";
			$(index+'_item_'+id).removeClassName('Status_0');
			$(index+'_item_'+id).removeClassName('Status_1');
			$(index+'_item_'+id).addClassName('Status_1');
		}
		this.btnStatus();
	},
	EmptyItems:function(index){
		if(Object.isUndefined(index)) index=0;
		$(index+'_Item_Length').innerHTML=0;
		$(index+'_WinStartItem').innerHTML='';
	}
	,
	listAllRootStart:function(isList,index){
		if(Object.isUndefined(index)) index='0';
		var StartedApplication=0;
		$A($$('UL#'+index+'_WinStartItem li')).each(function(li){
			if (isList && li.hasClassName('Status_0') && !li.hasClassName('MS_1'))	{
				li.show();
			}else if(li.hasClassName('Status_0') && !li.hasClassName('MS_1')){
				li.hide();
			}
			if (li.style.display!='none' && li.hasClassName('Status_1') && li.hasClassName('MS_0')){
				StartedApplication++;
			}
		})
		$(index+'_Item_StartedLength').innerHTML=StartedApplication;
	}
	,
	listAllMicrosoftSvervice:function(isList){
		var StartedApplication=0;
		$A($$('UL#1_WinStartItem li')).each(function(li){
			if (isList && li.hasClassName('MS_1'))	{
				li.show();
			}else if(li.hasClassName('MS_1')){
				li.hide();
			}
			//if (li.style.display!='none'  && li.hasClassName('Status_1')){
		//		StartedApplication++;
		//	}
		})
		$(index+'_Item_StartedLength').innerHTML=StartedApplication;

	}
	,
	btnStatus:function(){
		$A($$('img.btn')).each(function(img){

			var perName=img.src.substr(img.src.length-3,3);
			var sourceName=img.src.replace('_1.'+perName,'.'+perName).replace('_2.'+perName,'.'+perName)
			img.onmouseover=function(){
				img.src=sourceName.replace('.'+perName,'_1.'+perName);
			}
			img.onmouseout=function(){
				img.src=sourceName
			}
			img.onclick=function(){
				img.src=sourceName.replace('.'+perName,'_2.'+perName);
				img.src=sourceName.replace('.'+perName,'_1.'+perName);
			}
		});

	},
	controlDisabled:function(){
		if($('2_lstRootStart').checked){
			$('TimeOut').enable();
		}else{
			$('TimeOut').disable();
		}
	},
        noneprogress:function(type){//进度页面无下载任务
        	      if(type==0){
        	      	$("none_progress").hide();
        	      }else{
        	      	$("none_progress").show();
        	      }     
        },
        downprogress:function(item,percentage,speed){//进度条页面
                $(item).show();
                $(item+'_percentage1').style.width=percentage+'%';
                $(item+'_percentage2').innerHTML=percentage+'%';
                $(item+'_speed').innerHTML=speed+"KB/S";
        },
        downprogress_info:function(item,info){//进度信息提示
               $(item+'_info').innerHTML=info;
        },
        downprogress_cancel:function(item){//取消进度条				
                
                $(item+'_percentage1').style.width=0+'%';
                $(item+'_percentage2').innerHTML=0+'%';
                $(item+'_speed').innerHTML='';
                $(item+'_info').innerHTML='请重新下载...';
                if(this._debug == 0){
                	 if(item=='soft_progress'){
                	 	 window.navigate('app://page=2&action=stopdown&sid=0');//sid=0表示终止所有下载
                	}else if ((item=='drive_progress')){
                		 window.navigate('app://page=3&action=stopdown&sid=0');//sid=0表示终止所有下载
                	}
                   
                }
				$(item).hide();	// Modify By Alan On 2011.08.29 放在前面的话会导致要点两下取消按钮才能隐藏大进度条
        },


//	SetStartTime: function(string,status){
//
//		if(status==1){
//
//			$('SetStartTime').innerHTML=string;
//
//		}else{
//
//			$('SetStartTime').innerHTML='您还没开启开机时间检测,<a href="javascript:;" onclick="mbDocument.OpenStartTime()">点击开启</a>';
//
//		}
//
//	},
	OpenStartTime: function(){
		//window.navigate('ExecCmd=OpenOldMagicSet');
	},
        //软件按钮选择
        softlist_checked:function(){
               //任务id
               if($('softlist_checkall').value==''){
                   $('softlist_checkall_0').hide();
                   $('softlist_checkall_1').show();
                   $('softlist_checkall').value='1';
                   this.setchkstatue(2,1);
               }else{
                   $('softlist_checkall_0').show();
                   $('softlist_checkall_1').hide();
                   $('softlist_checkall').value='';
                   this.setchkstatue(2,0);
               }
        }
}
mbDocument.load();

document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
