// JScript 文件

var softSetID=null;
var softSetObj=null;

function loadPage(){

	var tools=new toolsClass();
	var tDiv=$("toolsDiv");
	tools.add("","保存","saveAllSetup()","保存所有设定的设置")
	tools.add("","放到桌面","setDisktop()","把当前选择的软件在桌面上创建快捷方式")
	tools.add("","从桌面删除","delDisktop()","把当前选择的软件在桌面上的快捷方式删除掉")
	tools.add("","放到开始菜单","setStartMenu()","把当前选择的软件在桌面上创建快捷方式")
	tools.add("","移出开始菜单","delStartMenu()","把当前选择的软件在桌面上的快捷方式删除掉")
	tools.create(tDiv);
	
	
	var t=new outTitle();
	t.add("名称","","200");
	t.add("运行次数","","80");
	t.add("日期","","120");
	t.add("权限设置","","180");
	t.obj=document.getElementById("softTitle");
	t.create();	
	
	var objs=document.getElementsByName("softNameList");
	for (var i=0;i<objs.length;i++){
		objs[i].onmouseover=function(){
			this.style.backgroundColor="#d3e2f8";
		}
		
		objs[i].onmouseout=function(){
			if (softSetObj!=this){
				this.style.backgroundColor="#ffffff";
			}
		}
		
		objs[i].onclick=function(){
			this.style.backgroundColor="#d3e2f8";
			if (softSetObj!=null & softSetObj!=this){
				softSetObj.style.backgroundColor="#ffffff";
			}
			var obj=$("mUserText");
			var mu=this.muser;
			if (mu==null | mu==""){
				mu=""
			}
			obj.value=mu;
			softSetID=this.softid;
			softSetObj=this;
			switch (mu){
				case "":
					$("R3").checked=true;
					break;
				case "ALL":
					$("R1").checked=true;
					break;
				default:
					$("R2").checked=true;
					break;
					
					
			}
			
			//alert(this.softid);
		}
	}
	
	
	
	$("R3").onclick=function(){
		var obj=$("mUserText");
		obj.value="";
		savePower()
	}
	
	$("R1").onclick=function(){
		var obj=$("mUserText");
		obj.value="ALL";
		savePower()
	}
	
//	loadBodyclick();
	
	writeFettleLeft(" 请在这里设置管理员可以进入系统的哪些管理选项")
}

function delDisktop(){
  	var objAjax=new JAjax();
	var objResponse=new JHttpResponse();
	objResponse.write("softSetID",softSetID);
	var out=objAjax.getText("post","softPower.aspx?type=delDisktop",objResponse,null);
	if (out=="-1"){
	    alert("桌面不上存在此程序的图标");
	    return;
	}
	
	
	if (out=="1"){
	     alert("图标删除成功, 刷新页面后图标从桌面删除");
	    return;
	}else{
	      alert(erStr(out));
	}

}


function setStartMenu(){ //把菜单放入开始菜单
    if (softSetObj==null){
		alert("请选择要作设置的项目");
		return;
	}
    var arr=openStartMenu();
   if (arr==null){return;}
   	var objAjax=new JAjax();
	var objResponse=new JHttpResponse();
	objResponse.write("softSetID",softSetID);
	objResponse.write("MID",arr[1]);
	var out=objAjax.getText("post","softPower.aspx?type=setStartMenu",objResponse,null);
	if (out=="1"){
	    alert("操作成功\n 刷新页面可以在开始菜单中找到这个程序");
	}else{
	    alert(erStr(out));
	}
}



function delStartMenu(){ //把菜单移出开始菜单
    if (softSetObj==null){
		alert("请选择要作设置的项目");
		return;
	}
   	var objAjax=new JAjax();
	var objResponse=new JHttpResponse();
	objResponse.write("softSetID",softSetID);
	var out=objAjax.getText("post","softPower.aspx?type=delStartMenu",objResponse,null);
	if (out=="1"){
	    alert("操作成功\n 刷新页面后此程序从开始菜单删除");
	}else{
	    alert(erStr(out));
	}
}



function setDisktop()
{
    //alert(softSetID);
   	var objAjax=new JAjax();
	var objResponse=new JHttpResponse();
	objResponse.write("softSetID",softSetID);
	var out=objAjax.getText("post","softPower.aspx?type=setDisktop",objResponse,null);
	if (out=="-1"){
	    alert("此程序不能放在桌面上");
	    return;
	}
	
	if (out=="-2"){
	  alert("桌面上已经有了此应用程序");
	    return;
	}
	
	if (out=="1"){
	     alert("创建图标成功, 刷新页面可以看到新程序图标");
	    return;
	}else{
	      alert(erStr(out));
	}
}


function sUser(){
	if (softSetObj==null){
		alert("请选择要作设置的项目");
		return;
	}
	
	var u=openSelectUser("admin");
	if (u!=null){
		var obj=$("mUserText");
		obj.value=u;
		$("R2").checked=true;
		savePower();
	}
}

function savePower(){
	if (softSetObj==null){
		alert("请选择要作设置的项目");
		return;
	}
	
	var obj=$("mUserText");
	softSetObj.muser=obj.value;
	softSetObj.isModi="1";
}

function saveAllSetup(){
	var objAjax=new JAjax();
	var x=0;
	var objs=document.getElementsByName("softNameList");
	var objResponse=new JHttpResponse();
	var idList="";
	var uList="";
	for (var i=0;i<objs.length;i++){
		if (objs[i].isModi=="1"){
			idList=idList+objs[i].softid+c1;
			uList=uList+objs[i].muser+c1;
			objs[i].isModi=="0";
			x++;
		}
	}
	if (x==0){
		alert("您没有作任何改动");
		return;	
	}
	objResponse.write("idList",idList);
	objResponse.write("uList",uList);
	var out=objAjax.getText("post","softPower.aspx?type=saveAll",objResponse,null);
	if (out=="OK"){
		alert("数据保存成功");
	}else{
		alert(erStr(out));
	}
	//alert(uList);
	
	
}
