// JavaScript Document

function checkUserName(){
	if($('username').value.length<3 || $('username').value.length>12){
		$('usernameinfo').innerText = '必须在3-12个字符以内！';
		$('username').focus();
		return false;
	}else{
		$('usernameinfo').innerText = '正确！';	
		return true;
	}
}

function checkPassword(){
	if($('password').value.length<6 || $('password').value.length>12){
		$('passwordinfo').innerText = '必须在6-12个字符以内！';
		$('password').focus();
		return false;
	}else{
		$('passwordinfo').innerText = '正确！';	
		return true;
	}
}

function checkPassword2(){
	if($('password2').value != $('password').value){
		$('password2info').innerText = '前后密码必须一致！';
		$('password2').focus();
		return false;
	}else{
		$('password2info').innerText = '正确！';	
		return true;
	}
}

function checkRealName(){
	var reg = /^[\u4e00-\u9fa5]+$/i; 
	if($('realname').value.length < 2 || $('realname').value.length > 6 || !reg.test($('realname').value)){
		$('realnameinfo').innerText = '请输入真实姓名！';
		$('realname').focus();
		return false;
	}else{
		$('realnameinfo').innerText = '正确！';	
		return true;
	}
}

function checkMobilePhone(){
	var reg = /^[0-9]+$/; 
	if($('mobilephone').value.length != 11 || !reg.test($('mobilephone').value)){
		$('mobilephoneinfo').innerText = '请输入有效手机号码！';
		$('mobilephone').focus();
		return false;
	}else{
		$('mobilephoneinfo').innerText = '正确！';	
		return true;
	}
}

function checkEmail(){
	var email = $('email').value;
	email = email.replace(/＠/ig, "@");
    if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)!=-1){
		$('emailinfo').innerText = '正确！';	
		$('email').focus();
	  	return true;
	}else{
		$('emailinfo').innerText = '邮箱格式错误！';	
		return false;
	}
}

function checkValidateCode(){
	if($('validcode').value != getCookie("ValidCode")){
		$('validcodeinfo').innerText = '验证码错误！';
		return false;
	}else{
		$('validcodeinfo').innerText = '正确！';
		return true;
	}
}

function checkEducation(){
	if($('education').value.length < 2){
		$('educationinfo').value = '请输入有效学历！';
		return false;
	}else{
		$('educationinfo').value = '';
		return true;
	}
}

function checkJobName(){
		if($('jobname').value.length< 2){
		$('jobnameinfo').innerText = '请输入有效职位！';
		$('jobname').focus();
		return false;
	}else{
		$('jobnameinfo').innerText = '';	
		return true;
	}
}

function checkDescription(){
	if($('description').value.length<8){
		$('descriptioninfo').innerText = '个人简历必须详细！';
		$('description').focus();
		return false;
	}else{
		$('descriptioninfo').innerText = '';	
		return true;
	}	
}

function checkCompany(){
	if($('company').value.length<8){
		$('companyinfo').innerText = '所在公司必须明确！';
		$('company').focus();
		return false;
	}else{
		$('companyinfo').innerText = '';	
		return true;
	}		
}

function checkWorkName(){
	if($('workname').value.length<1){
		$('worknameinfo').innerText = '作品名称不能为空！';
		return false;
	}else{
		$('worknameinfo').innerText = '';	
		return true;
	}
}

function submitRegForm(){
	if(checkUserName() && checkPassword() && checkPassword2() && checkRealName() && checkMobilePhone() && checkMobilePhone() && checkEmail() && checkValidateCode()){
		document.regform.submit();
	}else{
		alert('填写信息有误！');
	}
}

function submitLoginForm(){
	if(checkUserName() && checkPassword() && checkValidateCode()){
		document.loginform.submit();
	}else{
		alert('填写信息有误！');
	}	
}

function submitFindJob(){
	if(checkRealName() && checkEducation() && checkJobName() && checkDescription()){
		if(confirm('此次确定将不可更改，您确定此次提交吗？'))
		document.findjobform.submit();
	}else{
		alert('填写信息有误！');
	}	
}

function submitRecruitmentForm(){
	if(checkJobName() && checkCompany()){
		if(confirm('此次确定将不可更改，您确定此次提交吗？'))
		document.recruitmentform.submit();
	}else{
		alert('填写信息有误！');
	}		
}

function submitEditUserInfoForm(){
	if(checkMobilePhone() && checkMobilePhone() && checkEmail() && checkValidateCode()){
		if($('password').value.length>0 && $('password2').value.length>0){
			if(checkPassword() && checkPassword2()){
				document.edituserinfoform.submit();	
			}else{
				alert('填写信息有误！');	
			}	
		}else{
			document.edituserinfoform.submit();		
		}
		
	}else{
		alert('填写信息有误！');	
	}
}

function getTeamWorkCategory(){
	if($('workcategoryid').options.length==8){
		for(var i=7;i>=4;i--){
			$('workcategoryid').removeChild($('workcategoryid').options[i]);
		}
	}
}
	
function getPersonWorkCategory(){
	if($('workcategoryid').options.length==4){
		for(var i=5;i<=8;i++){
			var tag = document.createElement('OPTION');
			tag.value = i;
			$('workcategoryid').appendChild(tag);
			switch (i){
			case 5:tag.innerText = '幽默漫画（四格漫画、多格漫画）';break;
			case 6:tag.innerText = '手绘插画';break;
			case 7:tag.innerText = '动漫大赛海报';break;
			case 8:tag.innerText = '周边艺术';break;
			}
		}
	}
}

function submitUploadWorkForm(){
	var j = 0;
	if(parseInt($('workcategoryid').value) == 1){
		if($('otherdongman').value==''){alert('请选择文件！');return;}
		for(var i=1;i<=4;i++){
			if($('otherimg' + i).value != '') j++;	
		}
		if(j<3){alert('至少三幅截图！');return;}
	}else if(parseInt($('workcategoryid').value) == 2){
		if($('flafile').value==''){alert('请选择fla格式文件！');return;}
		if($('swffile').value==''){alert('请选择swf格式文件！');return;}
		for(var i=1;i<=4;i++){
			if($('flashimg' + i).value != '') j++;	
		}
		if(j<3){alert('至少三幅截图！');return;}
	}else{
		for(var i=1;i<=20;i++){
			if($('img' + i).value != '') j++;	
		}
		if(j==0){alert('请选择文件');return;}
	}
	if(checkWorkName() && checkValidateCode()){
		if(confirm('你确定此次提交吗？'))document.uploadform.submit();	
	}else{
		alert('填写信息有误！');	
	}
}