if(typeof(diy)=='undefined'){
	var	diy = {
		closeModule:function(mid){
			if(mid>0){
				showmessage('提示',"sure:关闭后,此模块不在首页显示,请确认?:diy.sureCloseModule:"+mid,320);
			}
		},
		sureCloseModule:function(mid){
			try{
				$.getJSON('?_do=school-ajaxCloseModule-mid-'+mid,function(res){
					if(res.succ==1){
						$("div .box"+mid).remove();
						$("#components_"+mid).attr("checked",false);
					}else{
						showmessage('提示',"tips:"+res.desc);
					}
				});
			}catch(ex){
				alert(ex);
			}
		}
	}
}


// 验证input长度..
function checkStrLen(objid, len) {
	var v = $('#' + objid).val();
	var f = true;

	if (document.getElementById(objid).value.length > len) {
		showmessage('提示', "tips:请输入" + len + "个以内的字符");
		f = false;
		$('#' + objid).focus();
	} else if ($.trim(v) == '') {
		showmessage('提示', "tips:请输入专辑的名称和描述");
		f = false;
		$('#' + objid).focus();

	}

	return f;
}

//=====================

//学校权限设定页面的js http://s.thenet.com/index.php?_do=admin-usertorole-school_id-28252.shtml
//角色管理usertorole.html roleAdmin.html
function roleAdmin(){
	var school_id = $("#school_id").val();
	popMiddleDiv("roleAdminBox","roleAdminTitle"); 
	createMask('roleAdminBoxMask',350);
	$("#roleAdminCon").html("请稍后，正在载入....");
	$("#roleAdminCon").load("/index.php?_do=admin-usertorole-act-loadSchoolUserRole-school_id-"+school_id,function(){
		popMiddleDiv("roleAdminBox","roleAdminTitle"); 
	});
}
//关闭角色管理层，装载角色
function closeRoleAdmin(){	
	var school_id = $("#school_id").val();
	$("#roleAdminCon").html("请稍后，正在关闭....");
	$.getJSON('/index.php?_do=admin-usertorole-act-getRoleList-school_id-'+school_id,
		function(res){
			var html = '<option value=0 >请选择</option>';
			var rid = $("#role_id").attr("rel");
			for(i in res){
			  sel = (rid==res[i].id) ? "selected" : ""; 
			  html += '<option value="'+res[i].id+'" '+sel+'> '+res[i].name+' </option>';
			}
		    $("#role_id").html(html);	
		    removeMask('roleAdminBoxMask');
			$("#roleAdminBox").hide();	
			popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); //添加教师可拖动
		}
	);	
}
//重设添加角色form
function resetRoleForm(){
	document.getElementById("roleform").reset();
	$("#roleTle").html("添加新角色");
}
//修改学校角色
function editRole(id,name,purview){
	$("#roleid").val(id);
	var purviewArr = purview.split(",");
	$("input[type=checkbox][name=purview]").each(function(){
		if(inArray($(this).val(),purviewArr)){
			$(this).attr("checked",true);
		}else{
			$(this).attr("checked",false);
		}
	});
	$("#rolename").val(name);
	if(id>0){
		$("#roleTle").html("正在修改角色(我要<a href='javascript:;' onclick=\"editRole(0,'','');\" >添加角色</a>)");
	}else{
		resetRoleForm();
	}	
	$("#rolename").focus();
}
//删除学校角色
function delRole(id){
	var school_id = $("#school_id").val();
	if(confirm("你确认要删除该角色吗？")){
		$.getJSON
		(
				'/index.php?_do=admin-usertorole-act-delRole-school_id-'+school_id+"-roleid-"+id,
				function(res){
					if(res.succ==1){
						resetRoleForm();
						$("#roletr"+id).remove();
					}else{
						alert("删除失败，请稍后再试");
					}
				}
		);
		
	}
}
//保存学校用户角色
function saveRole(){
	var roleid= $("#roleid").val();
	var school_id = $("#school_id").val();
	var rolename = $("#rolename").val();
	if(rolename==''){
		$("#rolename").focus();
		alert("请输入角色名称");
		return ;
	}
	rolename = encodeURIComponent(rolename);
	if($("input[type=checkbox][name=purview]:checked").size()==0){
		alert("请选择角色的权限");
		return ;
	}
	var purviewArr = [];
	$("input[type=checkbox][name=purview]:checked").each(function(){
		purviewArr.push($(this).val());
	});
	var purview = purviewArr.join(',');
		$.getJSON
		(
				'/index.php?_do=admin-usertorole-act-saveRole-school_id-'+school_id+"-roleid-"+roleid+"-rolename-"+rolename+"-purview-"+purview,
				function(res){
					if(res.succ>0){
						$.getJSON('/index.php?_do=admin-usertorole-act-getRoleList-school_id-'+school_id,
							function(res){
								var html = '';
								for(i in res){
								  name = res[i].name.replace('"','\"');
								  isedit = (res[i].access!='R') ? '<span class="color_adam"><a href="javascript:;" onclick="editRole('+res[i].id+',\''+name+'\',\''+res[i].purview+'\');return false;">编辑</a></span>' : '';
								  isdel = (res[i].access=='D') ? '<span class="color_adam"><a href="javascript:;" onclick="delRole('+res[i].id+');return false;">删除</a></span>' : '';
								  html += '<tr id="roletr'+res[i].id+'"><td>'+res[i].name+'</td><td>'+isedit+'</td><td>'+isdel+'</td></tr>';
							   }
							    $("#roleTbody").html(html);		
							}
						);
						showmessage("提示","tips:保存成功!");
					}else{
						alert("保存失败，请稍后再试");
					}
				}
		);
		
	 
}

//确认选择的教师
function confirmSelTeacher(){
	if($("input[type=radio][name=teacher]:checked").size()==0){
		alert("你至少要选择一个");
	}else{
	/*
		var tidArr = [];
		var tnameArr = [];
		$("input[type=checkbox][name=teacher]:checked").each(function(i){
			tidArr.push($(this).val());
			tnameArr.push($("#t"+$(this).val()).html());
		});
		$("#teacher_ids").val(tidArr.join(","));
		$("#teacher_names").val(tnameArr.join(","));
	*/
		var uid = $("input[type=radio][name=teacher]:checked").val();
		$("#teacher_ids").val(uid);
		$("#teacher_names").val($("#t"+uid).html());	 
		var status = $("input[type=radio][name=teacher]:checked").attr("curr_status");
		
		if(status=='Y'){
			$("#role_id option[access=R]").attr("selected","selected");
		}else{
			$("#role_id option[access=W]").attr("selected","selected");
		}
		closeTeacherDiv();
	}
}

function selSchoolUser(page){
	var school_id = $("#school_id").val();
	popMiddleDiv("teacherListDiv","teacherListTitle"); 
	removeMask();
	createMask(undefined,350);
	var p = page == undefined ? 1 : page;
	var uname = document.getElementById("user_name")!=undefined ? $("#user_name").val() : "";
	$("#teacherListCon").html("请稍后，正在载入....");
	$.get(
		"/index.php?_do=admin-ajaxGetSchoolUserBySchoolId-school_id-"+school_id+"&page="+p+"&name="+encodeURIComponent(uname)+"&t="+Math.random(),
		function(html){
		    $("#teacherListCon").html(html);
		    popMiddleDiv("teacherListDiv","teacherListTitle"); 
		}
	);
}

//选择教师
function selTeacher(page){
	var school_id = $("#school_id").val();
	popMiddleDiv("teacherListDiv","teacherListTitle"); 
	removeMask();
	createMask(undefined,350);
	var p = page == undefined ? 1 : page;
	$("#teacherListCon").html("请稍后，正在载入....");
	$.getJSON(
		"/index.php?_do=admin-ajaxGetTeacherBySchoolId-school_id-"+school_id+"&page="+p,
		function(rs){
			var res = rs.list;
			var pagestr = rs.pagestr;
			var html = '';
			for(i in res){
			  html += '<li><input name="teacher"  type="radio" value="'+res[i].uid+'" curr_status="'+res[i].curr_status+'" /> <span >'+res[i].teacher_name+'</span> </li>';
			}
			if(res.length == 0){
				html = "<p>没有教师可以选择，请先录入老师!</p>";
			}else{
				html += (pagestr.length>0) ? "<div class='page' style='clear:both'>"+pagestr+"</div>" : "";
			}
		    $("#teacherListCon").html(html);
		    popMiddleDiv("teacherListDiv","teacherListTitle"); 
		}
	);
	
}
//关闭教师层
function closeTeacherDiv(){
	$('#teacherListDiv').hide();
	removeMask();
}
//编辑用户与角色
function editUserToRole(id,role_id,uid,uname){
	$("#id").val(id);
	$("option[value="+role_id+"]","#role_id").attr("selected","selected");
	$("#teacher_ids").val(uid);
	$("#teacher_names").val(uname);
	if(id>0){
		$("#editTitle").html("正在修改管理员(我要<a href='javascript:;' onclick=\"editUserToRole(0,0,0,'');\" >添加管理员</a>)");
		$("#selTeacherSpan").hide();
	}else{
		resetUserRoleForm();
	}	
	$("#role_id").focus();
}

//删除用户与角色
function delUserToRole(id){
	var school_id = $("#school_id").val();
	if(confirm("你确认要删除吗？")){
		$.getJSON
		(
				'/index.php?_do=admin-usertorole-act-del-school_id-'+school_id+"-id-"+id,
				function(res){
					if(res.succ==1){
						resetUserRoleForm();
						$("#utr"+id).remove();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						alert(msg);
					}
				}
		);
		
	}
}
//删除用户的角色
function clearRole(id){
	showmessage('提示','sure:这将去除他的管理员角色的权限，他仍然是学校成员,你确定吗？:doClearRole:'+id,600);
}

function doClearRole(id){

	var school_id = $("#school_id").val();
	$.getJSON
		(
				'/index.php?_do=admin-usertorole-act-setRole-role_id-0-school_id-'+school_id+"-id-"+id,
				function(res){
					if(res.succ==1){
						resetUserRoleForm();
						$("#utr"+id).remove();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						alert(msg);
					}
				}
		);

}


//保存用户与用色
function saveUserToRole(){
	if($("#teacher_ids").val()==''){		
		showmessage("提示","tips:请选择教师");
		return false;
	}

		if($("#role_id").val()=='0'){		
			showmessage("提示","tips:请选择角色");
			$("#role_id").focus();
			return false;
		}
	
	$("#form").submit();
}
//重设form
function resetUserRoleForm(){
	document.getElementById("form").reset();
	$("#editTitle").html("添加管理员");
	$("#selTeacherSpan").show();
}

//////////////////////////////////////////////////////////////////
//职位管理http://s.thenet.com/index.php?_do=admin-position-school_id-28252.shtml
//职位管理position.html

//编辑职位
function editPosition(id){
	$("#pid").val(id);
	var name = $("#posname"+id).html();
	$("#name").val(name);
	var desc = $("#posdesc"+id).attr('title');
	$("#desc").val(desc);
	if(id>0){
		$("#posTle").html("正在修改职位(我要<a href='javascript:;' onclick=\"editPosition(0);\" >添加新职位</a>)");
	}else{
		resetPositionForm();
	}	
	$("#name").focus();
}

//删除职位
function delPosition(id){
	 showmessage('提示','sure:你确定要删除吗?:doDelPosition:'+id);
}

function doDelPosition(id){
	var school_id = $("#school_id").val();
	$.getJSON
		(
				'/index.php?_do=admin-position-act-delPosition-school_id-'+school_id+"-pid-"+id,
				function(res){
					if(res.succ==1){
						$("#pos"+id).remove();
						resetPositionForm();
					}else{
						alert("删除失败，请稍后再试");
					}
				}
		);
}
function resetPositionForm(){
	$("#posTle").html("添加新职位");
	$("#name").val('');
	$("#desc").val('');
	$("#pid").val('0');
}
//保存职位
function savePosition(){
	var name = $.trim($("#name").val());
	
	if(name==''){
		alert("请输入名称");
		$("#name").focus();
		return;
	}
	$("#form").submit();	
}

///////////////////////////////////////////////////////////////////////
//教师管理http://s.thenet.com/index.php?_do=admin-teacher-school_id-28252.shtml
//添加教师
function addTeacher(){	
	popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
	var school_id = $("#school_id").val();
	var status = $("#status").val();
	var statusName = $("#statusName").val();
	createMask('editTeacherDivMask',350);
	$("#editTeacherContent").html("请稍后，正在载入....");
	$("#spanTle").html("添加"+statusName);
	$("#editTeacherContent").load("/index.php?_do=admin-teacher-status-"+status+"-act-loadTeacherEdit-id-0-school_id-"+school_id+"&t="+Math.random(),function(){
		popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
		$("ul[rel=noEdit]").show();
		$("div[rel=noEdit]").show();		
	});
}
//关闭添加/编辑教师的层
function closeEditTeacherDiv(){
	/*if(confirm('是否刷新页面？查看教师列表')){
	  window.location.reload();
	}*/
	$("#editTeacherContent").html("请稍后，正在关闭....");	
	//removeMask('editTeacherDivMask');
	window.location.reload();
	
}

//编辑教师
function editTeacher(id){
	var school_id = $("#school_id").val();
	popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
	createMask('editTeacherDivMask',350);
	var status = $("#status").val();
	var statusName = $("#statusName").val();
	$("#spanTle").html("编辑"+statusName+"(我要<a href='javascript:;' onclick='addTeacher();return false;'>添加一个"+statusName+"</a>)");
	$("#editTeacherContent").html("请稍后，正在载入....");	
	$("#editTeacherContent").load("/index.php?_do=admin-teacher-status-"+status+"-act-loadTeacherEdit-id-"+id+"-school_id-"+school_id,function(){
		popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
		$("ul[rel=noEdit]").hide();
		$("div[rel=noEdit]").hide();		
	});
	
}


//编辑一个导入错误的教师进行导入
function editErrorTeacher(id){
	var school_id = $("#school_id").val();
	var status = $("#status").val();
	var statusName = $("#statusName").val();
	popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
	createMask('editTeacherDivMask',350);
	$("#spanTle").html("编辑"+statusName+"(我要<a href='javascript:;' onclick='addTeacher();return false;'>添加一个"+statusName+"</a>)");
	$("#editTeacherContent").html("请稍后，正在载入....");	
	$("#editTeacherContent").load("/index.php?_do=admin-teacher-status-"+status+"-act-loadErrorTeacherEdit-id-"+id+"-school_id-"+school_id,function(){
		popMiddleDiv("editTeacherDiv","editTeacherDivTitle"); 
	});
	
}

//删除教师
function delErrorUser(id){
	var school_id = $("#school_id").val();
	var status = $("#status").val();
	if(confirm("删除后不能恢复，你确认要删除它吗？")){
		try{
			$.getJSON
			(
					'/index.php?_do=admin-ajaxDelErrorUser-status-'+status+'-school_id-'+school_id+"-id-"+id+"&t="+Math.random(),
					function(res){
						if(res.succ==1){
							 $("#tr"+id).remove();
						}else{
							msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
							alert(msg);
						}
					}
			);
		}catch(ex){
			alert(ex);
		}
	}
}

//删除教师
function delTeacher(id){
	var ids = [];
	if(id>0){
	   ids.push(id);
	}else{		
		$(":checkbox[name=id]:checked").each(function(i){
			ids.push($(this).val());
		});	
	}
	if(ids.length==0){
		alert("你至少得选择一个成员");
		return false;
	}
	ids = ids.join(",");
	showmessage('提示','sure:您确定要删除吗？:doDelTeacher:'+ids);
}

function doDelTeacher(id){
	   var school_id = $("#school_id").val();
	   var status = $("#status").val();
	   $.getJSON
		(
				'/index.php?_do=admin-teacher-status-'+status+'-act-del-school_id-'+school_id+"-id-"+id+"&t="+Math.random(),
				function(res){
					if(res.succ==1){
						 closeEditTeacherDiv();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						alert(msg);
					}
				}
		);
}

//保存教师
function saveTeacher(){
	var status = $("#status").val();
	var data = {};
	var school_id = data.school_id = $("#school_id").val();
	var id = data.id = $("#id").val();
	var uid = data.uid = $("#uid").val();
	var name = data.name = $("#name").val();
	var email = data.email = $("#email").val();
	var birthday = data.birthday = $("#birthday").val();
	var password = data.password = $("#password").val();
	var pids = [];
	$("input[name=pid[]]:checked").each(function(){
		pids.push($(this).val());
	});
	var pid = data.position = pids.join(",");
	var role_id = data.role_id = $("#role_id").val();
	var is_good = data.is_good = $("#is_good").attr('checked') ? "Y" :"N";
	var is_go = data.is_go = $("#is_go").attr('checked') ? "N" :"Y";
	var error_id = data.error_id = $("#error_id").val();
	data.gender = $("input[name=gender][type=radio]:checked").val();
	data.intro = $("#intro").val();
	data.mobile = $("#mobile").val();
	data.address = $("#address").val();
	if(id==0){
		if(checkEmailExist()==false)
		  return ;	
	    if(password.length < 6){
	    	$("#password").focus();
	    	alert("请输入6位以上的密码");
	    	return ;
	    }
	}
	if(name==''){	
		$("#name").focus();
		alert('请输入姓名！');
		return false;
	}
	if(birthday==''){
		$("#birthday").focus();
		alert("请输入生日");
		return ;
	}
	$("#editTeacherContent").html("请稍后，正在保存....");	
	$.post("index.php?_do=admin-teacher-status-"+status+"-act-save",data,function(res){
		eval("var r="+res+";");
		if(r.succ==1){
			$("#editTeacherContent").html("保存成功....");	
			window.location.reload();
		}else{
			if(id>0){
				editTeacher(id);
			}else{
				addTeacher();
			}
			alert(r.desc);			
		}
	});
}

//批量添加表单
function batAddTeacher(){
	popMiddleDiv("importTeacher","importTeacherTitle"); 
	createMask(undefined,350);	
}

//关闭表单
function closeBatAddTeacher(){
   removeMask();	
   $("#importTeacher").hide();
}

///////////////////////////////////////////////////////////////////////
//学生管理http://s.thenet.com/index.php?_do=admin-student-school_id-28252.shtml
//添加学生
function addStudent(){	
	popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
	var school_id = $("#school_id").val();
	createMask('editStudentDivMask',350);
	$("#editStudentContent").html("请稍后，正在载入....");
	$("#spanTle").html("添加新学生");
	$("#editStudentContent").load("/index.php?_do=admin-student-act-loadStudentEdit-id-0-school_id-"+school_id+"&t="+Math.random(),function(){
		popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
		$("ul[rel=noEdit]").show();
		$("div[rel=noEdit]").show();		
	});
}

//关闭添加/编辑学生的层
function closeEditStudentDiv(){
	/*if(confirm('是否刷新页面？查看学生列表')){
	  window.location.reload();
	}*/
	$("#editStudentContent").html("请稍后，正在关闭....");	
	//removeMask('editStudentDivMask');
	window.location.reload();
	
}

//编辑学生
function editStudent(id){
	var school_id = $("#school_id").val();
	popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
	createMask('editStudentDivMask',350);
	$("#spanTle").html("编辑学生(我要<a href='javascript:;' onclick='addStudent();return false;'>添加一个学生</a>)");
	$("#editStudentContent").html("请稍后，正在载入....");	
	$("#editStudentContent").load("/index.php?_do=admin-student-act-loadStudentEdit-id-"+id+"-school_id-"+school_id,function(){
		popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
		$("ul[rel=noEdit]").hide();
		$("div[rel=noEdit]").hide();		
	});
	
}
//编辑未导入的学生
function editErrorStudent(id){	
	var school_id = $("#school_id").val();
	popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
	createMask('editStudentDivMask',350);
	$("#spanTle").html("编辑学生(我要<a href='javascript:;' onclick='addStudent();return false;'>添加一个学生</a>)");
	$("#editStudentContent").html("请稍后，正在载入....");	
	$("#editStudentContent").load("/index.php?_do=admin-student-act-loadErrorStudentEdit-id-"+id+"-school_id-"+school_id,function(){
		popMiddleDiv("editStudentDiv","editStudentDivTitle"); 
	});
}
//删除学生
function delStudent(id){
	var ids = [];
	if(id>0){
	   ids.push(id);
	}else{		
		$(":checkbox[name=id]:checked").each(function(i){
			ids.push($(this).val());
		});	
	}
	if(ids.length==0){
		alert("你至少得选择一个成员");
		return false;
	}
	ids = ids.join(",");
	showmessage('提示','sure:您确定要删除吗?:doDelStudent:'+ids);
}

function doDelStudent(id){
	var school_id = $("#school_id").val();
	$.getJSON
		(
				'/index.php?_do=admin-student-act-del-school_id-'+school_id+"-id-"+id,
				function(res){
					if(res.succ==1){
						 closeEditStudentDiv();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						alert(msg);
					}
				}
	);
}


//保存学生
function saveStudent(){
	var data = {};
	var school_id = data.school_id = $("#school_id").val();
	var id = data.id = $("#id").val();
	var uid = data.uid = $("#uid").val();
	var name = data.name = $("#name").val();
	var email = data.email = $("#email").val();
	var birthday = data.birthday = $("#birthday").val();
	var password = data.password = $("#password").val();
	var cids = [];
	$("input[name=cids[]]:checked").each(function(){
		cids.push($(this).val());
	});
	/*
	if(cids.length==0){
		$("#cids").focus();
		alert('请选择所在班级！');
		return false;
	}
	*/
	data.cids = cids.join(",");
	var role_id = data.role_id = $("#role_id").val();
	var is_good = data.is_good = $("#is_good").attr('checked') ? "Y" :"N";
	var is_go = data.is_go = $("#is_go").attr('checked') ? "N" :"Y";
	data.gender = $("input[name=gender][type=radio]:checked").val();
	data.intro = $("#intro").val();
	data.error_id = $("#error_id").val();
	data.mobile = $("#mobile").val();
	data.address = $("#address").val();
	if(id==0){
		if(checkEmailExist()==false)
		  return ;		
	    if(password.length < 6){
	    	$("#password").focus();
	    	alert("请输入6位以上的密码");
	    	return ;
	    }
	}
	if(name==''){	
		$("#name").focus();
		alert('请输入姓名！');
		return false;
	}
	if(birthday==''){
		$("#birthday").focus();
		alert("请学生生日");
		return ;
	}
	var mobile = $("#mobile").val();
	var uid = $("#uid").val() ;
	if (!checkMobile(mobile)){
		alert('请输入正确的手机号码');
	    return false;
	}else {
		$.ajax({
			url:"/interface/ajax.php?_do=check_mobile_can_register&mobile="+encodeURIComponent(mobile)+"&uid="+uid+"&rid="+parseInt(Math.random()*999999),
			type:"get",
			async:false,
			success:function(ret){
				eval('var ret = ' + ret + ';');
				if( ret['success']==1 ){
					;
				}
				else{
					alert('手机号码重复，请重新输入'); 
					
				}
			}
			
		}) ;
	}
	$("#editStudentContent").html("请稍后，正在保存....");	
	$.post("index.php?_do=admin-student-act-save",data,function(res){
		eval("var r="+res+";");
		if(r.succ==1){
			$("#editStudentContent").html("保存成功....");	
			window.location.reload();
		}else{
			if(id>0){
				editStudent(id);
			}else{
				addStudent();
			}
			alert(r.desc);			
		}
	});
}

//批量添加表单
function batAddStudent(){
	popMiddleDiv("importStudent","importStudentTitle"); 
	createMask(undefined,350);	
}

//关闭表单
function closeBatAddStudent(){
   removeMask();	
   $("#importStudent").hide();
}

//修改校长介绍和寄语
function editIntroSpeak(id){
	var spk = $("#speak"+id).attr("title");
	var intro = $("#intro"+id).attr("title");
	$("#speak").val(spk);
	$("#intro").val(intro);
	$("#id").val(id);
	popMiddleDiv("editContent","editContentTitle"); 
	createMask(undefined,350);	
}
//关闭介绍和寄语
function closeEditContent(){
	$("#editContent").hide();
	removeMask();	
}

//保存介绍和寄语
function saveIntroSpeak(){
	var id = $("#id").val();
	if(id>0){
		var data = {};
		data.id = id;
		data.speak = $("#speak").val();
		data.intro = $("#intro").val();
		data._do = "-saveIntroSpeak";
		$.post('index.php',data,function(rs){
			eval("var res="+rs+";");
			if(res.succ==1){
				$("#speak"+id).html(data.speak.substr(0,200));
				$("#intro"+id).html(data.intro.substr(0,50));
				$("#speak"+id).attr("title",data.speak);
				$("#intro"+id).attr("title",data.intro);
				closeEditContent();
			}else{
				msg = res.desc == undefined ? "操作失败，请稍后再试" : res.desc;
				alert(msg);
			}
		});
	}else{
		alert('保存介绍和寄语的参数错误');
	}
}

//取消、设为优秀教师
function setGood(id,flag){
	$("#submitmsgContent").html("正在设置，请稍后...");
	popMiddleDiv("submitmsg","submitmsgTitle");	
	createMask(undefined,350);		
	$.getJSON("/index.php?_do=school-setGood-sid-"+sid+"-id-"+id+"-flag-"+flag+"&t="+Math.random(),
	function(res){
		if(res.succ==1){
			$("#submitmsgContent").html("设置成功，正在刷新页面，请稍后...");
			//alert(res.desc);
			window.location.reload();
		}else{
			msg = res.desc == undefined ? "操作失败，请稍后再试" : res.desc;
			removeMask();
			$("#submitmsg").hide();			
			alert(msg);
		}
	});
	
}

//取消、设为优秀教师
function setGoodClass(id,flag){
	$("#submitmsgContent").html("正在设置，请稍后...");
	popMiddleDiv("submitmsg","submitmsgTitle");	
	//createMask(undefined,999);	
	$.getJSON("/index.php?_do=class-setGoodClass-school_id-"+sid+"-cid-"+id+"-flag-"+flag+"&t="+Math.random(),
	function(res){
		if(res.succ==1){
			$("#submitmsgContent").html("设置成功，正在刷新页面，请稍后...");
			window.location.reload();
		}else{
			msg = res.desc == undefined ? "操作失败，请稍后再试" : res.desc;
			removeMask();
			$("#submitmsg").hide();			
			alert(msg);
		}
	});
	
}
var as = null;
//编辑学校简介
function checkSchoolInfo(){	
	if(as.getAreaIds().length==0){
		showmessage('提示',"tips:学校地址必须选择！");
		//$("#province").focus();
		return false;
	}
	if($("#school_name").val()==''){
		showmessage('提示',"tips:学校名称不能为空！");
		//$("#school_name").focus();
		return false;
	}
	$("#areaids").val(as.getAreaIdStr());
	
	return true;
}

//学校申请表单检测
function chkapplyuser(){
	if($("#isAdmin:checked").val()==1 ){
		if($("#remark").val()==''){
			showmessage('提示','tips:申请成为超级管理员必须填写备注');
			return false;
		}
	}
	return true;
}
//全选不选
function checkall(obj){
	if($(obj).attr("checked")){
		$(":checkbox").attr("checked",true);
	}else{
		$(":checkbox").attr("checked",false);
	}
}
//批量审核成员 val=1 审核不过，val=2审核通过
function checkmenber(val){
	if($(":checkbox[name=id]:checked").size()==0){
		alert("你至少得选择一个成员");
		return false;
	}
	var ids = [];
	$(":checkbox[name=id]:checked").each(function(i){
		ids.push($(this).val());
	});
	$(":radio[name=role][value=0]").attr("checked",true);
	$("#ids").val(ids.join(","));
	$(":radio[name=check][value="+val+"]").attr("checked",true);
	popMiddleDiv("importTeacher","importTeacherTitle"); 
	createMask(undefined,350);		
}
//保存
function saveCheckMember(){	
	var check = $("input[name=check]:checked").val();
	var role = $("input[name=role]:checked").val();
	var ids =  $("#ids").val();
	var remark = encodeURIComponent($("#checkRemark").val());
	if(ids==''){
		alert("你至少得选择一个成员");
		return false;
	}
	if(check==undefined){
		alert('你必须选择审核选项');
		return false;
	}
	var msg = "你确定要";
	if(check==1){
		msg += "审核不过?";
	}else{
		msg += "审核通过?";
	}	
	if(confirm(msg)){
		$.ajax({
			type:'POST',
			url:'/index.php?_do=admin-checkMember-check-'+check+'-ids-'+ids+'-sid-'+sid+"-role-"+role+"&t="+Math.random(),
			data:"remark="+remark,
			dataType:'json',
			success:function(res){
				if(res.succ==1){
					alert('操作成功');
					window.location.reload();
				}else{
					alert(res.desc);
				}
			}
		});
	}
}
//审核一个成员
function checkmemberByid(id,isrole){
	id = parseInt(id);
	if(isNaN(id) || id<=0){
		alert("你至少得选择一个成员");
		return false;
	}	
	$("#ids").val(id);
	if(typeof(isrole)!='undefined' && parseInt(isrole)>0){
		$(":radio[name=role][value=1]").attr("checked",true);
	}else{
		$(":radio[name=role][value=0]").attr("checked",true);
	}
	popMiddleDiv("importTeacher","importTeacherTitle"); 
	createMask(undefined,350);
}
//删除成员
function delMember(id){
	var ids = [];
	if(id>0){
	   ids.push(id);
	}else{		
		$(":checkbox[name=id]:checked").each(function(i){
			ids.push($(this).val());
		});	
	}
	if(ids.length==0){
		alert("你至少得选择一个成员");
		return false;
	}
	ids = ids.join(",");	
	var msg = "你确定要删除吗？";
	showmessage('提示','sure:'+msg+":doDelMember:"+ids);
}

function doDelMember(ids){
		$.ajax({
			type:'POST',
			url:'/index.php?_do=admin-delMember-ids-'+ids+'-sid-'+sid+"&t="+Math.random(),
			dataType:'json',
			success:function(res){
				if(res.succ==1){
					showmessage('提示','tips:操作成功');
					window.location.reload();
				}else{
					alert(res.desc);
				}
			}
		});
}
//学生申请加入表单检查
function chkstudentapply(){
	if($('#cid').val()==0){
		//$('#cid').focus();
		//showmessage('提示',"tips:请选择班级"); 
		$("#applyForm").attr('action','/index.php?_do=school-applyUserSave-sid-'+sid);
	}else{
		$("#applyForm").attr('action','/index.php?_do=school-studentApplyUserSave-sid-'+sid); 
	}
	return true;
}

//园长信箱发信检查表单
function checkMsgForm(){
	if($("#title").val()==''||$("#title").val()=='信件标题'){
		showmessage('提示',"tips:请输入标题");
		//$("#title").focus();
		return false;
	}
	if($("#content").val()==''){
		showmessage('提示',"tips:请输入内容");
		//$("#content").focus();
		return false;
	}
	return true;
}
//检查保存版块的表单
function checkFieldForm(){
	if($("#title").val()==''){
		showmessage('提示',"tips:请输入标题");
		//$("#title").focus();
		return false;
	}
	return true;
}
//添加新版块
function addNewField(){
	$("#title").val('');
	$("#content").val('');
	$("#set1").attr('checked',true);
	$("#set3").attr('checked',true);
	$("#set5").attr('checked',true);
	$("#field_id").val('0');
	$("#succ_tip").html('');
}
//删除贴子
function delDiscuss(id){
	if(confirm('这将删除此贴子与其所有帖子的回复,并且不可恢复\r\n你确定要删除吗')){
		location = '?_do=discuss-del-id-'+id;
	}
}
//删除帖子回复
function delDiscussReply(id){
	if(confirm('删除后不可恢复\r\n你确定要删除吗')){
		$.getJSON('?_do=discuss-delReply-id-'+id+"&t="+Math.random(),function(res){
			if(res.err==0){
				window.location.reload();
			}else{
				msg = res.msg ? res.msg : '出错啦，请联系网站客服反馈此问题'; 
				alert(msg);
			}
		});
	}
}
//判断回复帖子标题和内容
function discussCheckSubmit()
{
     var discussTitle = $("#discussTitle").val();
     var editor = $("#editor").val()
      if(discussTitle == '')
      {
         showmessage('提示','tips:回复帖子的标题不能为空!');
         return false;
      }
      if (editor == '')
      {
         showmessage('提示','tips:回复帖子的内容不能为空!');
         return false;
      }
      $("#threadsubmit").submit();
}
//判断发表帖子标题和内容
function CheckSubmitThread()
{
      var discussTitle = $("#discussTitle").val();
      var editor = $("#editor").val();
      //if($(":input[type='checkbox']").attr('checked') == false)
     // {
         // showmessage("提示:",'请您选择一个要标志的!');
     // }
      if(discussTitle == '')
      {
         showmessage('提示','tips:帖子的标题不能为空!');
         return false;
      }
      if (editor == '')
      {
         showmessage('提示','tips:帖子的内容不能为空!');
         return false;
      }
      $("#threadsubmit").submit();
}
//检查增加修改新闻公告的表单 gg
function checkNews(){
	  var title = $("#title").val();
      var editor = $("#editor").val();
    
      if(title == '')
      {
         $("#title").focus();
         showmessage('提示','tips:标题不能为空!');
         return false;
      }
      if (editor == '')
      {
         showmessage('提示','tips:内容不能为空!');
         return false;
      }
      return true;

}

//检查教师文集的表单
function checkTeachingCollection(){
	  var title = $("#title").val();
      var editor = $("#editor").val();     
      if(title == '')
      {
         $("#title").focus();
         showmessage('提示','tips:标题不能为空!');
         return false;
      }
      /*
      if($("#category").val() == '0')
      {
         $("#title").focus();
         showmessage('提示','tips:标题不能为空!');
         return false;
      }  
      */    
      if (editor == '')
      {
         showmessage('提示','tips:内容不能为空!');
         return false;
      }
      return true;
}

//保存模块的现实个数.
function saveModuleShowNum(id)
{
	if ( typeof(id) == 'undefined' )
	{
		showmessage('提示','tips:设置失败,请刷新页面重试!');
		return false ;
	}
	var showNum = $('#showNum_'+id).val() ;
	
	var pattern = /^[1-9]\d{0,1}$/; 
	var newstr = showNum.match(pattern) ;
	newstr = newstr ? parseInt(newstr,10) : newstr;
	if ( newstr != null && newstr < 20 )
	{
		$.post('/?_do=school-setModuleShowNum',{'module_id':id,'showNum':newstr,"t=":Math.random()},function(data){
			
			$('#showNumDiv_'+id).hide();
			showmessage('提示','tips:显示个数保存成功,刷新页面即可查看!',400);
			
		});
		
	} else {
		
		showmessage('提示','tips:设置显示个数请设置在 1 至 20 之前!');
		return false;
	}
}

//检查友情链接的表单的值
function checkLinkForm(){
      if($.trim($("#title").val())==''){
      		//$("#content").focus();
      		showmessage('提示','tips:请输入链接标题');
            return false; 
      }	
      var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/  
      var theurl = $("#content").val();
      if (!tomatch.test(theurl)){ 
      		//$("#content").focus();
      		showmessage('提示','id:content_tip',350);
            return false;    
      }  
	  return true;    	
}
//ajax进行留言
function ajaxAddMessage(){
	var content = $("#content").val();
	var is_secret = $("#is_secret").attr("checked") == true ? 1 : 0;
	if(content==''){
		showmessage('错误', 'tips:留言内容不能为空！');
		return false;
	}
	$.ajax({
				type:'POST',
				url:'?_do=messageboard-ajaxAddMessage',
				data:'&content='+encodeURIComponent(content)+'&is_secret='+is_secret+'&t='+Math.random(),
				dataType : 'json',
				success:function(r){
					try{
						if(r.succ==1){
							showmessage('成功', r.desc,350);
							setTimeout('window.location.reload();',2000);
						}else{
							showmessage('错误', "tips:"+r.desc);
						}
					}catch(ex){
						alert(ex);
						//showmessage('错误', 'tips:系统出错啦');
					}
				}
	});
} 
//留言审核
function verifyComment(comment_id){
			if(comment_id==''||comment_id==null){
				return ;
			}
			$.ajax({
				type:'POST',
				url:'?_do=messageboard-ajaxVerifyComment',
				data:'&comment_id='+comment_id+'&is_verify=2',
				success:function(res){
					eval('var r='+res+';');
					try{
						if(r==1){
							showmessage('成功', '审核成功');
							setTimeout('window.location.reload();',2000);
						}else{
							showmessage('错误', 'tips:操作失败，请重新尝试');
						}
					}catch(ex){
						showmessage('错误', 'tips：操作失败，请重新尝试');
					}
				}
			})
}
//留言表单检查
function checkCommentForm(){
			if($(".commentsText").val()==''){
				showmessage('错误', 'tips:留言内容不能为空！');
				return false;
			}
}
//验证email add wangendong 20111115
function checkEmailExist(){
	var email = $("#email").val();
		if( email=="" ){
			alert('请输入有效的用户名(邮箱地址)！');
			return false;
		}
		if( !checkEmail(email) ){
			alert('用户名(邮箱)格式有误,必须要正确的邮箱格式,请重新输入！');
			return false;
		}
		var pars = "_do=check_email_can_register&email="+encodeURIComponent(email)+"&rid="+parseInt(Math.random()*999999);	
		var ret = $.ajax({
		'type' : 'POST',
		'url' : "/interface/ajax.php",
		'data' : pars,  
		async: false                 
		}).responseText; 
	    eval('var ret = ' + ret + ';');			
		if( ret['success']!=1 ){
			alert("此用户名(邮箱)已经存在，不允许再次添加,请修改");
			return false;
		}
		return true;
}
//验证邮件格式是否正确
function checkEmail(email){
	return email.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/)
}
// wangendong20091123增加
function checkMobile(mobile){

	var a = /^((\(\d{3}\))|(\d{3}\-))?13\d{9}|15\d{9}|18[789]\d{8}$/ ;
	if( mobile.length!=11||!mobile.match(a) )
	{
		return false;
	}
	else
	{
		return mobile.match(a);
	}
}
//删除用户所在的角色
function delUserRole(roleid){
	showmessage('提示', 'sure:这将去掉这个人在这个学校所管理的所有班级的权限，你确定吗？:doDelRole:'+roleid);
}

function doDelUserRole(roleid){
	$.GET('/index.php?_do=admin-setRole-role_id-0',function(res){
					if(res.succ==1){
						$("#utr"+id).remove();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						showmessage('提示',msg);
					}	
	});
}

//删除学校成员
function delSchoolMember(id){
	showmessage('提示','sure:您确定要删除吗?:doDelSchoolMember:'+id);
}
//删除学校成员
function doDelSchoolMember(id){
	var school_id = $("#school_id").val();
	$.getJSON
		(
				'/index.php?_do=admin-delSchoolMember-school_id-'+school_id+"-id-"+id,
				function(res){
					if(res.succ==1){
						 window.location.reload();
					}else{
						msg = res.desc == undefined ? "删除失败，请稍后再试" : res.desc;
						alert(msg);
					}
				}
	);
}

//同意or拒绝成员
function allowMemberById(id,check){
	var id = parseInt(id);
	var ids = [];
	if(isNaN(id) || id<=0){
		if($(":checkbox[name=id]:checked").size()==0){
			showmessage("提示","tips:你至少得选择一个成员");
			return false;
		}
		$(":checkbox[name=id]:checked").each(function(i){
			ids.push($(this).val());
		});
	}else{
		ids.push(id);
	}
	createMask(undefined,350);		
	loadingDiv();
	$.ajax({
			type:'POST',
			url:'/index.php?_do=admin-checkMember-check-'+check+'-ids-'+ids+'-sid-'+sid+"-role-0&t="+Math.random(),
			data:"remark=",
			dataType:'json',
			success:function(res){
				removeMask(undefined);		
				removeLoading();
				if(res.succ==1){
					showmessage("提示",'tips:操作成功');
					window.location.reload();
				}else{
					alert(res.desc);
				}
				
			}
	});	

}

function sendSms(){
	   if($(":checkbox[name=id]:checked").size()==0){
			showmessage("提示","tips:你至少得选择一个成员");
			return false;
		}
		var names = [];
		$(":checkbox[name=id]:checked").each(function(i){
			id = $(this).val();
			names.push($("#username_"+id).html());
		});
	$("#to_username").html(names.join(","));
	popMiddleDiv("sendbox","sendboxT");
}

function doSendSms(){
	 if($(":checkbox[name=id]:checked").size()==0){
			showmessage("提示","tips:你至少得选择一个成员");
			return false;
		}
	var ids = [];
		$(":checkbox[name=id]:checked").each(function(i){
			ids.push($(this).attr("uid"));
		});
	var content = $("#smsContent").val();
	if(content.length==0){
		showmessage("提示","tips:短信内容不能为空");
		return false;
	}
	ids = ids.join(",");
	
	$.ajax({
		url:"index.php?_do=admin-sendSms"+'-sid-'+sid+"&t="+Math.random(),
		type:"POST",
		data:"toid="+ids+"&sendtype=&invite=1&msg="+content,
		//dataType:"json",
		success:function(res){
			showmessage("提示","tips:发送成功");
		}
	});
}
//开通取消短信服务，open为1时开通，0为关闭
function smsReceived(uid,open){
	ids = uid;
	msg = open==0 ? "取消短信服务" : "开通短信服务";
	op = open == 0 ? -2 : 1;
	$.ajax({
		url:"index.php?_do=admin-smsReceivedSet"+'-sid-'+sid+"&t="+Math.random(),
		type:"POST",
		data:"uids="+ids+"&open="+open,
		//dataType:"json",
		success:function(res){
			if(res=='OK'){
				showmessage("提示","tips:"+msg+"成功");
				window.location.reload();
			}else{
				showmessage("提示","tips:"+msg+"失败，请填写正确的手机号码");
			}
		}
	});
}
var schoolAdmin = {
		delCheckedUsers : function(){
			var ids = [];
			if($(":checkbox[name=id]:checked").size()==0){
				showmessage("操作失败","tips:您还没有选择要删除的学生，请先选择！");
				return false;
			}
			$(":checkbox[name=id]:checked").each(function(){
				ids.push($(this).val());
			});
			ids = ids.join(',');
			$.ajax({
				url:"index.php?_do=admin-ajaxDelCheckedUsers&t="+Math.random(),
				type:"POST",
				data:"ids="+ids,
				success:function(res){
					eval('var r='+res+';');
					if(r['succ']==1){
						var idsArr = ids.split(',');
						$.each(idsArr,function(i){
							$('#tr_'+idsArr[i]).remove();
						});
						showmessage("操作成功","tips:删除学校用户成功。");
					}
				}
			});
		}		
};


