var isRegCode = false;
var isRegClass = true;

function CheckFormUserReg(strFormName) 
{
	/*
	var check = /^[A-Za-z0-9\_]*$/;
	if (!check.test(strFormName.iptAccount.value))
	{
		alertCUI(":-)  对不起!用户名" + "必须为英文,数字和下划线");
		strFormName.iptAccount.focus();
		return false;
	}
	*/
	if (isRegCode && GetStrLength(strFormName.iptRegCode.value) !=4 )
	{ 
		 alertCUI(':-)  对不起!请您填入正确的验证码'); 
		 strFormName.iptRegCode.focus();	 
		 return false;
	}


	if (GetStrLength(strFormName.iptAccount.value) < 2 || GetStrLength(strFormName.iptAccount.value) > 20 )
	{ 
		 alertCUI(':-)  对不起!请您填入用户名(2-20字)'); 
		 strFormName.iptAccount.focus();	 
		 return false;
	}

	if (!CheckEmail(strFormName.iptEmail.value))
	{  
		 alertCUI(':-)  对不起!请您填入正确的Email地址'); 
		 strFormName.iptEmail.focus();	 
		 return false;
	}

	if (GetStrLength(strFormName.iptRealName.value) < 2 || GetStrLength(strFormName.iptRealName.value) >10 )
	{
		 alertCUI(':-)  对不起!请您填入真实姓名(2-10字)'); 
		 strFormName.iptRealName.focus();	 
		 return false;
	}

	if (GetStrLength(strFormName.iptPassword.value) < 6 || GetStrLength(strFormName.iptPassword.value) >20  )
	{  
		 alertCUI(':-)  对不起!请您填入密码(6-20字)'); 
		 strFormName.iptPassword.focus();	 
		 return false;
	}

	if (GetStrLength(strFormName.iptPassword2.value) < 6 || GetStrLength(strFormName.iptPassword2.value) >20  )
	{  
		 alertCUI(':-)  对不起!请您确认密码(6-20字)'); 
		 strFormName.iptPassword2.focus();	 
		 return false;
	}

	if (strFormName.iptPassword2.value != strFormName.iptPassword.value)
	{
		alertCUI(':-)  对不起!您的密码和确认密码不符'); 
		strFormName.iptPassword.focus();	 
		return false;
	}

	if (GetStrLength(strFormName.iptQuestion.value) < 1 || GetStrLength(strFormName.iptQuestion.value) > 50)
	{
		alertCUI(':-)  对不起!请填入忘记密码后的提示问题'); 
		strFormName.iptQuestion.focus();	 
		return false;
	}

	if (GetStrLength(strFormName.iptAnswer.value) <1 || GetStrLength(strFormName.iptAnswer.value) > 50)
	{
		alertCUI(':-)  对不起!请填入忘记密码后的提示问题的答案'); 
		strFormName.iptAnswer.focus();	 
		return false;
	}

	if (isRegClass)
	{
		if (GetStrLength(strFormName.selClass.value) < 4 || GetStrLength(strFormName.selClass.value) > 200)
		{
			alertCUI(':-)  对不起!请填入在校班级'); 
			strFormName.selClass.focus();	 
			return false;
		}
	}

	if (GetStrLength(strFormName.iptWorkShop.value) < 4 || GetStrLength(strFormName.iptWorkShop.value) > 100)
	{
		alertCUI(':-)  对不起!请填入所在单位'); 
		strFormName.iptWorkShop.focus();	 
		return false;
	}

	submitonce(strFormName);

	return true;
}


function CheckEmail(address) 
{
	if ((address == "") || (address.indexOf ('@') == -1)|| (address.indexOf ('.') == -1))
      return false;
  return true;
}


// 显示班级
function DisplayClassList()
{ 
	updateSelClassList();			//从selClass更新selClassList
	
    var popClassObj = GetElem("popClass");
    popClassObj.style.display = "block";
    var selClassObj = GetElem("selClassList"); 
     
    GetElem("selClassDiv").style.display = "block";
}


//从selClass更新selClassList
function updateSelClassList()
{
	deleteAllSelClass();
	var selClassListObj = GetElem("selClassList"); 
	var selClassList = GetElem("selClass"); 
	var arrSelClass = selClassList.value.split(";");
	for (var iRows = 0; iRows < arrSelClass.length; iRows++)
	{
		var selValue = arrSelClass[iRows];
		var selText = arrSelClass[iRows];
		if (selValue.length > 0 || selText.length > 0)
		{
			var existFlag = false;
			
			//判断是否已经存在
			for(var j = 0; j < selClassListObj.length; j++)
			{
				if(selClassListObj.options[j].text == selText)
				{
					existFlag = true;
					break;
				}
			}

			//不存在则添加
			if(!existFlag)  selClassListObj[selClassListObj.length] = new Option( selText, selValue); 
		}
	}
}



//添加班级
function addClass()
{
    var classListObj = GetElem("lbClass");
    var selClassObj = GetElem("selClassList"); 
    for(var i = 0; i < classListObj.length; i++)
    { 
        if(classListObj.options[i].selected)
        {
            var selValue = classListObj.options[i].value;
            var selText = classListObj.options[i].text;
            var existFlag = false;
            //判断是否已经存在
            for(var j = 0; j < selClassObj.length; j++)
            {
                if(selClassObj.options[j].text == selText)
                {
                    existFlag = true;
                    break;
                }
            }
            //不存在则添加
            if(!existFlag)  selClassObj[selClassObj.length] = new Option( selText, selValue); 
        }
    } 
}


//全部添加班级
function addAllClass()
{
    var classListObj = GetElem("lbClass");
    var selClassObj = GetElem("selClassList"); 
    for(var i = 0; i < classListObj.length; i++)
    {
        var selValue = classListObj.options[i].value;
        var selText = classListObj.options[i].text;
         var existFlag = false;
        //判断是否已经存在
        for(var j = 0; j < selClassObj.length; j++)
        {
            if(selClassObj.options[j].text == selText)
            {
                existFlag = true;
                break;
            }
        }
        //不存在则添加
        if(!existFlag)  selClassObj[selClassObj.length] = new Option( selText, selValue);
       
    } 
}

//删除班级
function deleteSelClass()
{
    var selClassObj = GetElem("selClassList");
    for(var i = 0; i < selClassObj.length; i++)
    {
        if(selClassObj.options[i].selected)
        {
            selClassObj[i] = null;
            i--;
        }
    }
}

//删除所有选择班级
function deleteAllSelClass()
{
    var selClassObj = GetElem("selClassList");
    selClassObj.length = 0;
}

function showClass()
{
    var popClassObj = GetElem("popClass");
    popClassObj.style.display = "block";
    var selClassObj = GetElem("selClassList");
    
    GetElem("selClassDiv").style.display = "block";
}

//隐藏选择班级
function CancelSelelctClass()
{
    var popClassObj = GetElem("popClass");
    popClassObj.style.display = "none";
    GetElem("selClassDiv").style.display = "none";
}

//确认添加班级
function ConfirmAddClass()
{

    var selClassObj = GetElem("selClassList");
    var result="";//选择的用户
    for(var i = 0; i < selClassObj.length; i++)
    {
        result = result + selClassObj.options[i].value + ";";
    }
 
 
    addClassIntoInput(result);
 
    //确认后隐藏选择好友列表
    CancelSelelctClass();
}

//添加
function addClassIntoInput(classes)
{
    var toObj = GetElem("selClass");
    var retClass = Trim(toObj.value);	
    //toObj.value = retClass;
	
	//去掉重复

	var arrRetCalss = classes.split(";");
	if (arrRetCalss.length != null && arrRetCalss.length > 0)
	{
		var temClass = ";" + retClass + ";";
		for(var i = 0; i < arrRetCalss.length; i++)
		{
			if (temClass.indexOf(";" + arrRetCalss[i] + ";") < 0)
			{
				if (retClass.length > 0)
				{
					if (arrRetCalss[i].length > 0){retClass = retClass + ";" + arrRetCalss[i];}
				}
				else
				{
					retClass = arrRetCalss[i];
				}
			}
		}
	}

	toObj.value = classes;
    //toObj.onblur();//去掉重复
}
