var empty = ['', '', '', '', '', '', ''];
function ChangeCmptTab (group, current_id, amount) {
	border_color = ['', '#fcdcdb', '#f4ddc8', '#bccfe0', '#cecece'];
	for (i = 1; i <= amount; i++ ) {
		if (i != current_id) {
			$("cmap_cmpt_text" + i).style.display = "none";
			$("cmap_cmpt_grp" + i).style.background = "url('/img/cmap/tab_cmpt_grp" + i + ".gif') bottom no-repeat";
		}
	}
	$("cmap_cmpt_text" + current_id).style.display = "block";
	$("cmap_cmpt_grp" + current_id).style.background = "url('/img/cmap/tab_cmpt_grp" + current_id + "_on.gif') top no-repeat";

	$("cmap_cmpt_text").style.border = "solid 1px " + border_color[current_id];
	$("cmap_cmpt_text").style.borderTop = "none";
	$("cmap_cmpt_tab").style.background = "url('/img/cmap/cmpt_tab_bg_grp" + current_id + ".gif') repeat-x";
}

function ChangeCmptFrame (group, current_id, amount) {
	color = ['', '#ff8080', '#ffcc99', '#9999ff', '#7c7c7c'];
	for (i = 1; i <= amount; i++ ) {
		$("cmpt_frame_" + i).style.display = "none";
	}
	$("cmpt_frame_" + current_id).style.display = "block";
	$("cmpt_frame_" + current_id).style.background = "url('/img/cmap/cmpt_frame_bg_grp" + current_id + ".gif') no-repeat";
	$("cmpt_frame_title" + current_id).style.color = color[current_id];
	$("cmpt_frame_title" + current_id).style.borderColor = color[current_id];
}

function Expand (l) {
	if (l.style.display == "none") {
		l.style.display = "block";
		$("cmap_breif_txt").style.display = "none";
		$("btn_expand").src = "/img/cmap/btn_shrink.gif";
	}
	else {
		l.style.display = "none";
		$("cmap_breif_txt").style.display = "block";
		$("btn_expand").src = "/img/cmap/btn_expand.gif";
	}
}

function ValidComments () {
	if ($("Comments").value == "") {
		alert ("请填写您的评论");
		$("Comments").focus();
		return false;
	}
	else if ($("Code").value == "") {
		alert ("请输入验证码");
		$("Code").focus();
		return false;
	}
}

function Activity (action, id, cmpt) {//能力活动
	if (action == 'NewPlan') {
		if (!confirm("该活动还未创建“计划表”\n\n现在创建？")) {
			return false;	
		}
	}
	else if (action == 'NewInterview') {
		if (!confirm("该活动还未创建“三次谈话”\n\n现在创建？")) {
			return false;	
		}
	}
	else if (action == 'NewCase') {
		if (!confirm("该活动还未创建“案例”\n\n现在创建？")) {
			return false;	
		}
	}
	$("Action").value = action;
	$("ActivityID").value = id;
	$("CompetencyClass").value = cmpt;
	$("MyActivity").submit();
}
function checkInput () {//查询填写内容
	var unfilled = 0;
    var m = document.getElementsByTagName("input");

	for (i = 0; i < m.length; i ++) {
		if ((m[i].type == 'text') && m[i].name != "k") {
			if (m[i].value == '')  {
				unfilled ++;
				m[i].className = "redborder";
			}
			else {
				m[i].className = "";
			}
		}
	}

    var n = document.getElementsByTagName("textarea");
	for (i = 0; i < n.length; i ++) {
		if (n[i].value == '')  {
			unfilled ++;
			n[i].className = "redborder";
		}
		else {
			n[i].className = "";
		}
	}


	if (unfilled == 0) {
		if ($("CompleteDate").value <= $("StartDate").value) {
			alert("活动开始时间、结束时间有误\n\n请重新选择!");
			return false;
		}
		else {
			return true;
		}
	}
    else {
    	alert("每一项内容都需要填写，还有" + unfilled + "项未填！\n\n如确实没有相关信息请输入”略“！");
		return false;
	}
}
function addTblLine(TblID, asData) {
	row = $(TblID).insertRow();
	row.vAlign = 'top';
	j = $(TblID).rows.length;

	if ($(TblID).id == 'CaseStepTbl') {
		c = row.insertCell(0);
		c.style.border = 'none';
		c.innerHTML = '<input type="text" style="width:80px" name="txtStepName[]"/>';
		c = row.insertCell(1);
		c.style.border = 'none';
		c.innerHTML = '<textarea name="txtStepComments[]"></textarea>';
		c = row.insertCell(2);
		c.style.border = 'none';
		c.innerHTML = '<input type="button" value="删除" onclick="delTR(' + TblID + ')" class="actionbtn" style="width:40px;"/>';
	}
	if ($(TblID).rows.length > 10) {
		$("btn_addstep").disabled = true;
		alert("您最多可以添加10个环节！");
	}
}
function delTR(TblID) {
	rownum = window.event.srcElement.parentElement.parentElement.rowIndex;
	TblID.deleteRow(rownum);
	if ($(TblID).rows.length < 11) {
		$("btn_addstep").disabled = false;
	}
}
function ToggleLearnRoute(d, sub_id) {
    var on_img = "/img/admin/btn_minus.gif";
    var off_img = "/img/admin/btn_expand.gif";
    if ($(d + sub_id).style.display == "none") {
    	$("btn_" + sub_id).src = on_img;
    }
    else {
    	$("btn_" + sub_id).src = off_img;
    }
    Effect.toggle(d + sub_id, "appear"); return false;
}
function CMapUser (w) {//用户管理
	var check = 0;
	var m = $("User").getElementsByTagName("input");
	for(i=0;i<m.length;i++) {
		if((m[i].type == 'checkbox') && (m[i].checked == true)) {
			check ++;
		}
	}
	if (check == 0) {
		alert("请选择学员");
		return false;
	}
	else {
		if (w == 'NewLearnRoute') {
			$("ActionID").value = "配置学习路径";
			$("User").action = "/CMap/SetLearnRoute.php";
			$("User").submit();
		}
		else if (w == 'DeleteUser') {
			if (confirm("确定")) {
				$("ActionID").value = "删除学员";
				$("User").action = "/CMap/MyUser.php";
				$("User").submit();
			}
		}
	}
}
function SelectCmptSource() {//选择能力资源
	if ($('CompetencySourceClassID').value != 0 && $('CompetencySourceClassID').value !='') {
		var xmlDoc = checkXMLDocObj("SourceClass.php?Action=SourceXml&ID=" + $('CompetencySourceClassID').value + "&CompetencyClassID=" + $("CompetencyClassID").value);
		for(i=$("CmptSource").options.length-1;i>=0;i--) {
			$("CmptSource").remove(i);
		}
		root = xmlDoc.documentElement;
		nodeList = root.selectNodes("competency_sources/competency_source");
		path = "competency_sources/competency_source[";
		for (i = 0; i < nodeList.length; i ++) {
			CmptSourceID = root.selectSingleNode(path + i +"]/@competency_source_id").text;
			CmptSourceTitle = root.selectSingleNode(path + i +"]/title").text;
			objOption = new Option(CmptSourceTitle, CmptSourceID);
			$("CmptSource").add(objOption, i);
		}
	}
}
function AddCmptSource() {//添加资源
	var opt = $("CmptSource").options;
    len = opt.length;
    for (i=len-1;i>-1;i--) {
        if (opt[i].selected) {
            $("CmptSourceN").appendChild(opt[i]);
        }
    }
}
function DelCmptSource() {//删除资源
    var opt = $("CmptSourceN").options;
    len = opt.length;
    for(i=len-1;i>-1;i--) {
        if(opt[i].selected){
            //$("CmptSource").appendChild(opt[i]);
            $("CmptSourceN").remove(i);
        }
    }
}
function SetLearnRoute(ActionName, IsActive) {//创建修改学习路径
	var hint = "";
	var chkUser = 0;
	var m = $("UserCmptSource").getElementsByClassName("u");
	for(i = 0; i < m.length; i ++) {
		if(m[i].checked == true)  {
			chkUser ++;
		}
	}
	if (chkUser == 0) {
		hint = "<div>请选择需要配置资源的学员</div>";	
	}
	
	l = $("CmptSourceID[]").length;
	if (l == 0) {
		hint += "<div>请配置资源</div>";
	}
	else if (l < 3 || l > 10) {
		hint += "<div>配置资源数量在3至10条间</div>";
	}
	else {
		for (i = 0; i < l; i ++) {
			$("CmptSourceID[]").options[i].selected = true;
		}	
	}
	if (hint != "") {
		$("hintbox").innerHTML = hint;
		$("hintbox").style.display = "block";
	}
	else {
		$("hintbox").style.display = "none";
		if (ActionName == 'Create') {
			$("IsActive").value = IsActive;
			$("Action").value = "创建学习路径";
		}
		else {
			$("Action").value = "修改学习路径";
		}
		$("UserCmptSource").submit();
	}
}
function Modify (Sort, id) {//修改信息
	if (Sort == "User") {
		var xmlDoc = checkXMLDocObj("MyUser.php?Action=Xml&UserID=" + id);
		root = xmlDoc.documentElement;
		$("UserID").value = id;
		$("UserName").value = root.selectSingleNode("users/user/name").text;
		$("Gender").value = root.selectSingleNode("users/user/@gender").text;
		$("DeptName").value = root.selectSingleNode("users/user/dept_name").text;
		$("Phone").value = root.selectSingleNode("users/user/phone").text;
		$("Email").value = root.selectSingleNode("users/user/email").text;
		$("user_info").style.display = 'block';
		$("Action").value = "修改学员信息";
	}	
}
function ValidUserInfo() {
	var unfilled = 0;
    var m = $("UserInfo").getElementsByTagName("input");

	for (i = 0; i < m.length; i ++) {
		if (m[i].type == 'text') {
			if (m[i].value == '')  {
				unfilled ++;
				m[i].className = "redborder";
			}
			else {
				m[i].className = "";
			}
		}
	}
	
	if (unfilled !=0) {
		alert("请填上姓名、部门、电话及邮件");
		return false;	
	}
	
	email = $("Email").value;
	if (email == "") {
		alert("请输入您的邮件！");
		$("Email").focus();
		altCssClass("inputEmail", "redborder");
		return false;
	}
	else {
		altCssClass("inputEmail", "");
	}

	var regu = "^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT|cn|CN)$"
	var re = new RegExp(regu);
	if (email.search(re) == -1) {
		window.alert ("请输入有效的E-mail地址 ！");
		$("Email").focus();
		altCssClass("inputEmail", "redborder");
		return false;
	}
	else {
		$("Email").value = email.toLowerCase();
		altCssClass("inputEmail", "");
	}
}

