// JavaScript Document
var ERO_CY = "网络中断,请确认您现在可以上网!";
String.prototype.Trim = function() 
{ 
return this.replace(/(^\s*)|(\s*$)/g, ""); 
} 

String.prototype.LTrim = function() 
{ 
return this.replace(/(^\s*)/g, ""); 
} 

String.prototype.RTrim = function() 
{ 
return this.replace(/(\s*$)/g, ""); 
} 

function login(){
	loginFrom.cardid.value = loginFrom.cardid.value.Trim();
	loginFrom.userpass.value = loginFrom.userpass.value.Trim();
	
	if(loginFrom.cardid.value==""||loginFrom.userpass.value==""){
		alert("学习卡号与密码不能为空");
		return;
	}

	document.getElementById("l_2").style.display = 'block';
	document.getElementById("l_1").style.display = 'none';
	AjaxRequest.submit(
		loginFrom,
			{
			'url':'/cardid.ww',
			'onSuccess':function(req){ 
				if(req.responseText.indexOf("success")>=0){
					if(document.location.href.indexOf("/nbstudy")>0){
						window.location.reload();
					}else{
						getCadre();
						window.document.cycware_vssno.SetVariable("login", "login");
						openZx();
					}
				}else if(req.responseText.indexOf("verify")>=0){
					alert("校验码出错!");
				}else if(req.responseText.indexOf("userlock")>=0){
					alert("用户为锁定状态，不能登录");
				}else if(req.responseText.indexOf("userrepace")>=0){
					alert("用户已在另外一台电脑上登录，请将此前的登录退出,然后再登录!");
				}else{
					alert("用户名或密码出错!");
				}
				document.getElementById("l_2").style.display = 'none';
				document.getElementById("l_1").style.display = 'block';
			},
			'onError':function(req){
			},
			'method':'POST'
			}
	);	
	
}

function getCadre(){
	AjaxRequest.get(
		{
			'url':'/vm/inc/_cadre.jsp',
			'onSuccess':function(req){ 
				document.getElementById("cadreInfo").innerHTML = req.responseText;
			}
			,
			'onError':function(req){
				alert("网络连接错误");
			}
		}
	);	
}

function openZx(){
	var win = window.open('/nbstudy/index/index.phtml','','');
	if(!win){
		alert("窗口打开失败，请关闭浏览器拦截窗口功能");	
	}	
}

function cancellogin(){
	document.getElementById("l_2").style.display = 'none';
	document.getElementById("l_1").style.display = 'block';
}


function getHtml(url){
	window.open(url,'courseList','')	
}


function showSdiv(v,o){
	if(o==0){
		document.write("<img src='/images/bk_ar.gif' width=1 height=18>")
		return;
	}
	document.write("<img src='/images/bk_ar.gif' width="+((v/o)*50)+" height=18>"+FormatNumber((v/o)*100,2)+"%")
}

function chagePass(){
	if(passForm.oldpass.value==""){
		alert("请输入原有旧密码")
		return false;
	}
	if(passForm.newpass.value==""){
		alert("请输入要修改的密码")
		return false;
	}
	if(passForm.newpass.value!=passForm.newpass2.value){
		alert("两次密码输入不一致")
		return false;
	}
	document.getElementById("status").style.display = 'block';
	AjaxRequest.submit(
		passForm,
			{
			'url':'chagePassRs.jsp',
			'onSuccess':function(req){ 
				if(req.responseText.indexOf("true")>=0){
					alert("密码修改成功!");
					self.close();
				}else{
					alert("密码修改失败!");
				}
				document.getElementById("status").style.display = 'none';
			},
			'onError':function(req){
			},
			'method':'POST'
			}
	);	
	return false;
}

function logout(){
	window.location.href='/logout.ww'	
}


//--在线报名--------------------------------------------
function regeditLoad(){
	document.getElementById("status").style.display = 'none';
	AjaxRequest.get(
		{
			'url':'/nbstudy/class/load.ww',
			'onSuccess':function(req){ 
				if(req.responseText.length>10)
					document.getElementById("classInfo").innerHTML = req.responseText;
				document.getElementById("status").style.display = 'none';
			}
			,
			'onError':function(req){
				alert(ERO_CY);
			}
		}
	);	
}


function regeditClear(){
	document.getElementById("status").style.display = 'none';
	AjaxRequest.get(
		{
			'url':'/nbstudy/class/clear.ww',
			'onSuccess':function(req){ 
				document.getElementById("classInfo").innerHTML = req.responseText;
				document.getElementById("status").style.display = 'none';
			}
			,
			'onError':function(req){
				alert(ERO_CY);
			}
		}
	);	
}


function regeditExport(){
	document.getElementById("status").style.display = 'none';
	AjaxRequest.get(
		{
			'url':'/nbstudy/class/export.ww',
			'onSuccess':function(req){ 
				if(req.responseText.indexOf("success")){
					alert("上传报名信息成功");
				}
				document.getElementById("status").style.display = 'none';
			}
			,
			'onError':function(req){
				alert(ERO_CY);
			}
		}
	);	
}


function regeditReg(url){
	if(!check())
		return;

	document.getElementById("regedit.name").value = z.getComboText(); 
	if(document.getElementById("regedit.name").value.indexOf("请选择")>=0){
		alert("请选择或录入相关人员姓名");
		return;
	}
	
	document.getElementById("status").style.display = 'block';
	AjaxRequest.submit(
		regeditForm,
			{
			'url' : '/nbstudy/class/regedit.ww',
			'onSuccess':function(req){ 
				if(req.responseText.indexOf("success")>=0){
					regeditRefresh();
				}else{
					alert("人员报名失败!");
				}
				document.getElementById("status").style.display = 'none';
			},
			'onError':function(req){
				alert(ERO_CY);
			},
			'method':'POST'
			}
	);		
}

function regeditDel(classid,cardid){
		if(!confirm("确认要删除此人员班次信息吗?")){
			return;
		}
		parent.document.getElementById("status").style.display = 'none';
		AjaxRequest.get(
			{
				'url':'/nbstudy/class/delete.ww?regedit.classid='+classid+'&regedit.cardid='+cardid,
				'onSuccess':function(req){ 
					if(req.responseText.indexOf("success")>=0){
						alert("数据中人员信息删除成功");
						parent.regeditRefresh();
					}
					parent.document.getElementById("status").style.display = 'none';
				}
				,
				'onError':function(req){
					alert(ERO_CY);
				}
			}
		);	
	}


//---------------------------------------------------------------
function questionSave(){
	if(document.getElementById("question.question").value==""){
		alert("请输入要提问的内容");
		return false;
	}
	return true;
}

function setResponse(id){
	if(document.getElementById("ans_"+id+"_d").style.display=='block'){
	document.getElementById("ans_"+id+"_d").style.display='none';
	document.getElementById("ans_"+id).style.display='block';	
	}else{
	document.getElementById("ans_"+id+"_t").value = document.getElementById("ans_"+id).innerHTML;
	document.getElementById("ans_"+id+"_d").style.display='block';
	document.getElementById("ans_"+id).style.display='none';
	}
}

function questionResponse(){
	var form = document.getElementById("form_"+id)
	if(form){
		form.action="/nbstudy/question/response.ww";
		return true;
	}
	return false;
}

function questionDel(id){
	if(!confirm("确认要删除此条记录吗?"))
		return;
	var form = document.getElementById("form_"+id)
	if(form){
		form.action="/nbstudy/question/delete.ww";
		form.submit();
	}
}

//小数格式化
function   FormatNumber(srcStr,nAfterDot)   
  {   
  　　var   srcStr,nAfterDot;   
  　　var   resultStr,nTen;   
  　　srcStr   =   ""+srcStr+"";   
  　　strLen   =   srcStr.length;   
  　　dotPos   =   srcStr.indexOf(".",0);   
  　　if   (dotPos   ==   -1){   
  　　　　resultStr   =   srcStr+".";   
  　　　　for   (i=0;i<nAfterDot;i++){   
  　　　　　　resultStr   =   resultStr+"0";   
  　　　　}   
  　　　　return   resultStr;   
  　　}   
  　　else{   
  　　　　if   ((strLen   -   dotPos   -   1)   >=   nAfterDot){   
  　　　　　　nAfter   =   dotPos   +   nAfterDot   +   1;   
  　　　　　　nTen   =1;   
  　　　　　　for(j=0;j<nAfterDot;j++){   
  　　　　　　　　nTen   =   nTen*10;   
  　　　　　　}   
  　　　　　　resultStr   =   Math.round(parseFloat(srcStr)*nTen)/nTen;   
  　　　　　　return   resultStr;   
  　　　　}   
  　　　　else{   
  　　　　　　resultStr   =   srcStr;   
  　　　　　　for   (i=0;i<(nAfterDot   -   strLen   +   dotPos   +   1);i++){   
  　　　　　　　　resultStr   =   resultStr+"0";   
  　　　　　　}   
  　　　　　　return   resultStr;   
  　　　　}   
  　　}   
  } 
  
  
//补报班次信息
function classnet(){
	if(!check())
		return;
	
	document.getElementById("status").style.display = 'block';
	AjaxRequest.submit(
		netForm,
			{
			'url':'/nbstudy/class/classnet!saveClass.ww',
			'onSuccess':function(req){ 
				if(req.responseText.indexOf("error")<0){
					alert("培训班次信息保存成功,请录入人员信息")
					document.all.netreg.disabled = false;
					document.getElementById("regedit.classid").value = req.responseText;
				}else{
					alert("班级信息保存失败!");
				}
				document.getElementById("status").style.display = 'none';
			},
			'onError':function(req){
				alert(ERO_CY);
			},
			'method':'POST'
			}
	);		 
}


function check(){
	var inputs = document.getElementsByTagName("input"); 
	for (var i=0; i<inputs.length; i++) { 
		var input = inputs[i];
		if(input.title!=""&&input.value.Trim()==""){
			alert(input.title);
			input.focus();
			return false;
		}
	}
	return true;
}

//小时转为分钟
function min2hour(m){
	document.write(FormatNumber(m/60,2));
}


function setProfile(url){
	AjaxRequest.get(
			{
				'url':url,
				'onSuccess':function(req){ 
					window.location.reload();
				}
				,
				'onError':function(req){
					alert(ERO_CY);
				}
			}
		);	
}



function onloadEvent(func){
	var one=window.onload
	if(typeof window.onload!='function'){
		window.onload=func
	}
	else{
		window.onload=function(){
			one();
			func();
		}
	}
}
function showtable(){
	var tableid='talist';		//表格的id
	var overcolor='#FCF9D8';	//鼠标经过颜色
	var color1='#FFFFFF';		//第一种颜色
	var color2='#E6E6E6';		//第二种颜色
	var tablename=document.getElementById(tableid)
	var tr=tablename.getElementsByTagName("tr")
	for(var i=1 ;i<tr.length;i++){
		tr[i].onmouseover=function(){
			this.style.backgroundColor=overcolor;
		}
		tr[i].onmouseout=function(){
			if(this.rowIndex%2==0){
				this.style.backgroundColor=color1;
			}else{
				this.style.backgroundColor=color2;
			}
		}
		if(i%2==0){
			tr[i].className="color1";
		}else{
			tr[i].className="color2";
		}
	}
}


function setSelectValue(id,va){
	var objSelect = document.getElementById(id)
	var length = objSelect.options.length; 
    for(var i=0; i<length; i++){ 
        if(objSelect.options[i].value == va){    
			objSelect[i].selected = true;
        }    
    }    

}