/*
	*2009/1/4 增加prototype版检查功能！
*/
if (DEPLOY_MODE=='undefined'){
	var DEPLOY_MODE=true
}

var mbDocument= {
	Version: '1.0.0.1',
	REQUIRED_PROTOTYPE: '1.6.0',
	AllowDownCount:5,
	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');
			}
		}
	},
	/**
	*tabSwitch(标头对象集，内容对象集，当前对象，对象CSS名称集['on','off'])
	*/
	tabSwitch:function(ttlObject,cntObject,selTab,classNames){

		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';
		})
		
	},
	
	
	/**
	*左侧列表菜单条点击事件
	*/
	menuLeft_1:function(evt){
		var menus=$A($$('ul.left_ul1 li'));
		if ((isNaN(evt))){
			evt=evt?evt:window.event;
			var srcElem=(evt.target)?evt.target:evt.srcElement;
			var obj=srcElem.tagName.toUpperCase()=='DIV'?srcElem.parentNode:srcElem;
		}else{
			evt=parseInt(evt);
			var obj=menus[evt]
		}
		var objId=parseInt(obj.id.replace('m_left_',''))

		//左侧所有li
		
		
		/*menus.each(function(li){
			//如果不是需要显示子菜单的
			if (li.className!='menu3'){
				if (objId==parseInt(li.id.replace('m_left_',''))){
					li.className='on'
				}else{
					li.className=''
				}
			}
		})
		*/
		mbDocument.switchMenuto(obj)		
	//	alert(objId)
	},
	menuLeft_2:function(evt){
		//var menus=$A($$('ul.rj_menu1 li,ul.left_ul1 li'));
		if ((isNaN(evt))){
			evt=evt?evt:window.event;
			var srcElem=(evt.target)?evt.target:evt.srcElement;
			var obj=srcElem.tagName.toUpperCase()=='IMG'?srcElem.parentNode:srcElem;
		}else{
			evt=parseInt(evt);
			//var obj=menus[evt]
			var obj=$('i_left_'+evt);
		}
		var objId=parseInt(obj.id.replace('i_left_',''));	

		//左侧所有li
	/*	menus.each(function(li){
			//如果不是需要显示子菜单的
			if (li.className!='menu3'){
				if (objId==parseInt(li.id.replace('i_left_',''))){
					if (!li.hasClassName('on')) li.addClassName('on')
				}else{
					li.removeClassName('on')
				}
			}
		})*/

		var obj=$A($$('ul.left_ul1'))[0];
		var obj_ico=$A($$('ul.rj_menu1'))[0];
		var obj_menu=$A($$('div.rj_menu2'))[0];
		var obj_menus=$A($$('div.rj_menu2 ul'));
		if (objId!=1 && objId!=2 && objId!=5){
			obj_ico.hide();
			obj_menu.hide();
			obj.show();
			$('m_left_'+objId).className='on';
		}else if(objId==1){
			obj_menus[0].show();
			obj_menus[1].hide();
			obj_menus[2].hide();
			obj_menus[0].select('li')[0].className="on";
		}else if(objId==2){	
			obj_menus[0].hide();
			obj_menus[1].show();
			obj_menus[2].hide();
			obj_menus[1].select('li')[0].className="on";
		}else if(objId==5){	
			obj_menus[0].hide();
			obj_menus[1].hide();
			obj_menus[2].show();
			
			obj_menus[2].select('li')[0].className="on";

		}
		$("menuMin").style.top="0px";
		mbDocument.menuPageLoad(objId);	
		
	
		
	}
	,
	switchMenuto:function(li){
		var obj=$A($$('ul.left_ul1'))[0];
		var obj_ico=$A($$('ul.rj_menu1'))[0];
		var obj_menu=$A($$('div.rj_menu2'))[0];
		var obj_menus=$A($$('div.rj_menu2 ul'));
 		//obj.morph('width:30px;');
		/*new Effect.Morph(obj, {
		  style: 'width:30px;', // CSS Properties
		  duration: 2.8 // Core Effect properties
		});
*/
		if (li.className=='menu3'){
			//new Effect.Squish(obj); 
			obj.hide();
			obj_ico.show();
			obj_menu.show();
			
			//为防止乱显示，在显示前全部隐藏
			obj_menus[0].hide();
			obj_menus[1].hide();
			obj_menus[2].hide();
		}
		var obj=li
		var objId=parseInt(obj.id.replace('m_left_',''))
		/*if (objId==1 || objId==2){
			obj_menus[objId-1].show();
			Effect.SlideDown(obj_menus[objId-1]); 	
		*/
		if(objId==1){
			obj_menus[0].show();
			obj_menus[1].hide();
			obj_menus[2].hide();
			obj_menus[0].select('li')[0].className="on";
		}else if(objId==2){	
			obj_menus[0].hide();
			obj_menus[1].show();
			obj_menus[2].hide();
			obj_menus[1].select('li')[0].className="on";
		}else if(objId==5){	
			obj_menus[0].hide();
			obj_menus[1].hide();
			obj_menus[2].show();
			obj_menus[2].select('li')[0].className="on";
		}
		this.menuPageLoad(objId);
	}
	,menuPageLoad:function(objId){
		if (objId==0){		//调入软件管理
			url='index-index.html';
			objName="Index";
		}else if (objId==1){		//调入装机必备的菜单
			url="zjbb.html";
			objName="Zjbb";			
		}else if (objId==2){			//调入软件大全的菜单
			url="rjdq.html"
			objName="Rjdq";
		}else if (objId==3){			//调入软件大全的菜单
			url="patch.html"
			objName="Patch";
		}else if (objId==4){			//调入下载设置
			url="set.html"
			objName="Set";
		}else if (objId==5){			//调入升级卸载的菜单
			url="update.html"
			objName="Update";
		}

		var menus=$A($$('ul.rj_menu1 li,ul.left_ul1 li'));
		menus.each(function(li){
			//如果不是需要显示子菜单的
			if (li.className!='menu3'){
				if (objId==parseInt(li.id.replace('i_left_','')) || objId==parseInt(li.id.replace('m_left_',''))){
					if (!li.hasClassName('on')) li.addClassName('on')
				}else{
					li.removeClassName('on')
				}
			}
		})
		html=$('page'+objName).innerHTML.replace(objName+'_allids','tmp_ids');
		//alert(html)
		$('pageMain').innerHTML=html;
		if (objName=='Zjbb'){
			$('pageIds').value=Zjbb_First_Ids;
		}else if(objName=='Rjdq'){
			$('pageIds').value=Rjdq_First_Ids;
		}
		//alert($('pageIds').value)
		//this.listPage(url)	
	}
	
	,
	Enabled_PageStatus:function(){
		$('MB_overlay1').hide();
	}
	,
	Disabled_PageStatus:function(){
		$('MB_overlay1').show();
	}
	
	,
	addUninstallSoftItem:function(PtString){
		//softid,softname,ico,version,description
		items1=PtString.split('\n');
		items=new Array();
		for (i=0;i<items1.length ;i++ ){
			tmp=items1[i].split('|');
			if (tmp.length==5) items[i]=tmp;

		}
		var myTemplate = new Template(
			'<li><div class="soft_about2"><span><img src="#{2}" width="32" height="32" /></span><P><h3>#{1}</h3>#{4} </P></div><div class="soft_beta">#{3}</div><div class="soft_cont" id="uninstall_buttion_#{0}"><a href="ExecCmd=Uninstall;ID=#{0}"><img src="images/uninstall.jpg" width="61" height="28" class="btn" /></a></div></li >'
		);
		var html="";
		var count=0;
		items.each(function(conv){
			count++;
			html+=myTemplate.evaluate(conv);
		})	
		
		var html='<div class="soft_list"><div class="list_title"><div class="soft_about2">软件名称</div><div class="soft_beta">版本号</div><div class="soft_cont">卸载</div></div><ul>'+html+'</ul></div>';
		if (Object.isElement($('pageUpdate'))){
			$('pageUpdate').innerHTML=html;
			mbDocument.menuLeft_1(5);
		}
		var uk='';
		if($('uninstallkeyword')){
			uk=$('uninstallkeyword').value;
		}
		var formStr="";
		

		var formStr='<div class="search_soft">';
    formStr+=' <form id="unseaform" name="unseaform" method="post" action="ExecCmd=FilterUninstallSoft">';
	  formStr+='<div class="search_soft2">搜索软件：';
		formStr+='  <input type="text" name="uninstallkeyword" id="uninstallkeyword" class="SearchInput" value="'+uk+'" \/>';
		formStr+='<\/div>';
		formStr+='<div >';	
		formStr+='<input  type="submit"  class="btn_uninstall" value="">';
		formStr+='<\/div>';
    formStr+='<\/form>';
    formStr+='<\/div>';
    
		
		$('pageMain').innerHTML=formStr+html;
		
		var ul=$A($$('div#menuMin ul'))[2];
		ul.select('li')[0].className="";
		ul.select('li')[1].className="on";
		mbDocument.btnStatus();
	
	},
	getUninstallSea: function(){
		 return $('uninstallkeyword').value;
	}
	,
	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);
			}
		});
	
	}
}
mbDocument.load();

//附近加的一个函数
function imgzoom(img,w){
	if (img.getWidth()>w){
		img.setStyle({width:w+'px'})
	}
}
if (!DEPLOY_MODE){
	window.onerror=function(){return false}
}
