﻿$(function(){
	$("#Add").find("tbody").slideDown('fast');
	
	$(".toggleBg tr").hover(function(){
		$(this).addClass("current");
	}, function(){
		$(this).removeClass("current");
	});
	
	$(".iformTable thead").toggle(function(){
		$(this).parents("table").find("tbody").slideDown('fast');
	}, function(){
		$(this).parents("table").find("tbody").slideUp('fast');
	});

	$("input[@value=取消]").click(function(){
		$(this).parents("form.editForm").slideUp('fast');
		$(this).parents("div.infoBlock").find("#Add").show();
	});
	//是否有亲属在亿达
	$("#ingroup").hide();
	$("#isingroup").change(function(){
		if($("#isingroup").val() == '0'){
			$("#ingroup").hide();
		}
		else{
			$("#ingroup").show();
		}
	});
});

function editItem(theLink, data, id) {
	$(theLink).parents("div.infoBlock").find("#Add").hide();
	var theEditForm = $(theLink).parents("div.infoBlock").find("form.editForm");
	for(var itemName in data[id]) {
		theEditForm.find("input[@name="+itemName+"]").attr("value", data[id][itemName]);
		theEditForm.find("textarea[@name="+itemName+"]").html(data[id][itemName]);
	}
	theEditForm.slideDown('fast');
}

//简历基本信息的验证
function checkresume(){
	var emailformat=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	var ageformat=/^[0-9]{1,2}$/;
	var cardformat=/^([0-9]{14}[0-9xX]{1}|[0-9]{17}[0-9xX]{1})$/;
	var mobileformat=/^[0-9]{8,11}$/;
	if(document.rsform.name.value==''){
		document.rsform.name.focus();
		alert('姓名不能为空！');
		return false;
	}
	if(document.rsform.age.value==''){
		document.rsform.age.focus();
		alert('年龄不能为空！');
		return false;
	}
	if((!ageformat.exec(document.rsform.age.value)) && (document.rsform.age.value!='')){
		document.rsform.age.focus();
		alert('年龄格式不正确！');
		return false;
	}
	if(document.rsform.mobile.value==''){
		document.rsform.mobile.focus();
		alert('手机号不能为空！');
		return false;
	}
	if((!mobileformat.exec(document.rsform.mobile.value)) && (document.rsform.mobile.value!='')){
		document.rsform.mobile.focus();
		alert('手机号格式不正确！');
		return false;
	}
	if(document.rsform.email.value==''){
		document.rsform.email.focus();
		alert('电子邮件不能为空！');
		return false;
	}
	if((!emailformat.exec(document.rsform.email.value)) && (document.rsform.email.value!='')){
		document.rsform.email.focus();
		alert('电子邮件格式不正确！');
		return false;
	}
	if(document.rsform.card.value==''){
		document.rsform.card.focus();
		alert('身份证号不能为空！');
		return false;
	}
	if((!cardformat.exec(document.rsform.card.value)) && (document.rsform.card.value!='')){
		document.rsform.card.focus();
		alert('身份证号格式不正确！');
		return false;
	}
	if(document.rsform.major.value==''){
		document.rsform.major.focus();
		alert('专业不能为空！');
		return false;
	}
}

//应聘者登录验证
function checklogin(){
	var emailformat=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(document.loginform.email.value==''){
		document.loginform.email.focus();
		alert('请输入帐号！');
		return false;
	}
	if((!emailformat.exec(document.loginform.email.value)) && (document.loginform.email.value!='')){
		document.loginform.email.focus();
		alert('帐号格式不正确！');
		return false;
	}
	if(document.loginform.password.value==''){
		document.loginform.password.focus();
		alert('请输入密码！');
		return false;
	}
}

//应聘者注册验证
function checkreg(){
	var emailformat=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	if(document.regform.email.value==''){
		document.regform.email.focus();
		alert('请输入帐号！');
		return false;
	}
	if((!emailformat.exec(document.regform.email.value)) && (document.regform.email.value!='')){
		document.regform.email.focus();
		alert('帐号格式不正确！');
		return false;
	}
	if(document.regform.password.value==''){
		document.regform.password.focus();
		alert('请输入密码！');
		return false;
	}
	if(document.regform.password.value.length<6){
		document.regform.password.focus();
		alert('密码不能少于6个字符,请重新输入！');
		return false;
	}
	if(document.regform.repass.value!=document.regform.password.value){
		document.regform.repass.focus();
		alert('两次输入的密码不一致！');
		return false;
	}
}

//收藏本站
function bookmark() { 
	window.external.addFavorite('http://hr.yidagroup.com/','亿达集团招聘网站');
}

//应聘者修改密码
var pwd_key=0;
function checkoldpass(){
	var oldpwd=$("#oldpassword").val();
	$.get("index.php?controller=applicant&action=validatepwd",{oldpwd:oldpwd},function(data){
		if(data==0){
			$("#oldpwd_span").text('原始密码错误！请重新输入。');
			pwd_key=0;
		}
		else if(data==1){
			$("#oldpwd_span").text('');
			pwd_key=1;
		}
	});
}

function checknewpass(){
	if($("#newpassword").val().length<6){
		$("#newpwd_span").text('新密码不能少于6个字符！请重新输入');
		pwd_key=0;
	}
	else{
		$("#newpwd_span").text('');
		pwd_key=1;
	}
}

function checknewpass2(){
	if($("#newpassword2").val().length<6){
		$("#newpwd_span2").text('新密码不能少于6个字符！请重新输入');
		pwd_key=0;
	}
		
	if($("#newpassword2").val()!=$("#newpassword").val()){
		$("#newpwd_span2").text('两次输入密码不相同！请重新输入');
		pwd_key=0;
	}
		
	if($("#newpassword2").val().length>=6 && $("#newpassword2").val()==$("#newpassword").val()){
		$("#newpwd_span2").text('');
		pwd_key=1;
	}
}

//ajax判断应聘者是否填写简历基本信息
function checkbase(){
	$.get("index.php?controller=resume&action=checkbase",function(data){
		if(data==0){
			alert("请先填写基本信息!");
			window.location="index.php?controller=resume&action=editbase";
		}
	});
}

//教育经历的验证
function checkaddebg(){
	if(document.addform.starttime.value==''){
		document.addform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.endtime.value==''){
		document.addform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.school.value==''){
		document.addform.school.focus();
		alert('请输入学校！');
		return false;
	}
}

function checkeditebg(){
	if(document.editform.starttime.value==''){
		document.editform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.endtime.value==''){
		document.editform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.school.value==''){
		document.editform.school.focus();
		alert('请输入学校！');
		return false;
	}
}

//工作经历的验证
function checkaddwbg(){
	if(document.addform.starttime.value==''){
		document.addform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.endtime.value==''){
		document.addform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.company.value==''){
		document.addform.company.focus();
		alert('请输入单位名称！');
		return false;
	}
	if(document.addform.job.value==''){
		document.addform.job.focus();
		alert('请输入职务！');
		return false;
	}
	if(document.addform.desc.value==''){
		document.addform.desc.focus();
		alert('请输入工作描述！');
		return false;
	}
}

function checkeditwbg(){
	if(document.editform.starttime.value==''){
		document.editform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.endtime.value==''){
		document.editform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.company.value==''){
		document.editform.company.focus();
		alert('请输入单位名称！');
		return false;
	}
	if(document.editform.job.value==''){
		document.editform.job.focus();
		alert('请输入职务！');
		return false;
	}
	if(document.editform.desc.value==''){
		document.editform.desc.focus();
		alert('请输入工作描述！');
		return false;
	}
}

//培训经历的验证
function checkaddtbg(){
	if(document.addform.starttime.value==''){
		document.addform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.endtime.value==''){
		document.addform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.addform.school.value==''){
		document.addform.school.focus();
		alert('请输入培训机构！');
		return false;
	}
}

function checkedittbg(){
	if(document.editform.starttime.value==''){
		document.editform.starttime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.endtime.value==''){
		document.editform.endtime.focus();
		alert('请输入时间！');
		return false;
	}
	if(document.editform.school.value==''){
		document.editform.school.focus();
		alert('请输入培训机构！');
		return false;
	}
}

//家庭成员的验证
function checkaddfamily(){
	if(document.addform.name.value==''){
		document.addform.name.focus();
		alert('请输入姓名！');
		return false;
	}
	if(document.addform.relation.value==''){
		document.addform.relation.focus();
		alert('请输入与本人关系！');
		return false;
	}
}

function checkeditfamily(){
	if(document.editform.name.value==''){
		document.editform.name.focus();
		alert('请输入姓名！');
		return false;
	}
	if(document.editform.relation.value==''){
		document.editform.relation.focus();
		alert('请输入与本人关系！');
		return false;
	}
}