﻿// JavaScript Document
<!--
//判断是否为空
function checkIsNull(obj, msg, strlen)
{
    var obj = getId(obj);
    if (obj.value == '' || obj.value.length > strlen)
    {
        alert(msg);
        obj.focus();
        return false;
    }

    return true;
}

//判断是否数字
function checkIsNumeric(obj, msg)
{
	var reg = /^(?:[1-9][0-9]*(?:\.[0-9]+)?|0(?:\.[0-9]+)?)$/;

	if (!reg.exec(obj.value))
	{
		alert(msg);
		obj.focus();
		return false;
	}
	return true;
}

//判断是否是正确的邮箱
function isEmail(imail){   
	var emailPattern = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;   
	if (emailPattern.test(imail)==false){
		return false;
	}   
	else{
		return true;  
	}
}

//判断是否是正确电话号码
function isTel(itel){   
	var telPattern = /^[+]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{3,4}[-]{0,1}[0-9]{7,8}$/;   
	if (tel.test(itel)==false){
		return false;
	}   
	else{
		return true;  
	}
}

//刷新验证码
function refreshimg(){
  document.all.Code.src='../inc/CheckCode.asp';
}

//全选
function checkAll(e, itemName)
{
  var aa = document.getElementsByName(itemName);
  for (var i=0; i<aa.length; i++)
   aa[i].checked = e.checked;
}
function checkItem(e, allName)
{
  var all = document.getElementsByName(allName)[0];
  if(!e.checked) all.checked = false;
  else
  {
    var aa = document.getElementsByName(e.name);
    for (var i=0; i<aa.length; i++)
     if(!aa[i].checked) return;
    all.checked = true;
  }
}

//添加信息
function checkInforForm() {

	var obj = document.MyForm;
	if(!CheckIsNull(obj.InforTitle,"信息标题不能为空而且不能大于50个字符",50)) return false;
	if(!CheckIsNumeric(obj.ClassID,"请选择信息分类")) return false;
	if(!CheckIsNull(obj.Content,"请填写信息详细说明且不能超过500个字",1000)) return false;
	if(!CheckIsNumeric(obj.memProvince,"请信息所在选择区域")) return false;
	if(!CheckIsNull(obj.address,"请填写信息所在的具体联系地址且不能超过50个字",50)) return false;
	if(!CheckIsNull(obj.truename,"请填写正确的联系人",50)) return false;
	
	var email		= document.getElementById("email");
	var mobile		= document.getElementById("mobile");
	var tel			= document.getElementById("tel");
	var QQ			= document.getElementById("userQQ");
	
	//检测手机
	if(mobile.value.length>0){
		if(mobile.value.length<=10){
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;
		}
		if(!/^[0-9]{11,30}$/.exec(mobile.value)){
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;   
		}
	}
	
	//检测座机
	if(tel.value.length>0){
		if(!/^[+]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{7,8}$/.exec(tel.value)){
			alert("请填写正确的电话号码格式为：0731-84168716");
			tel.focus();
			return false;
		}
	}
	
	if(mobile.value.length<=0 && tel.value.length<=0){
		alert("手机跟座机必填其中一项");
		mobile.focus();
		return false;
	}
	
	if(email.value.length>0)
	{
		if(!isEmail(email.value))
		{
			alert("电子邮箱格式不对");
			email.focus();
			return false;
		}
	}
	
	if(QQ.value.length>0)
	{
		if(!/^[0-9]{4,15}$/.exec(QQ.value))
		{
			alert("请您用数字填写正确的QQ");
			QQ.focus();
			return false;
		}
	}
}

//修改信息
function checkModiInforForm() {

	var obj = document.MyForm;
	if(!CheckIsNull(obj.InforTitle,"信息标题不能为空而且不能大于50个字符",50)) return false;
	if(!CheckIsNumeric(obj.ClassID,"请选择信息分类")) return false;
	if(!CheckIsNull(obj.Content,"请填写信息详细说明且不能超过500个字",2000)) return false;
	if(!CheckIsNull(obj.address,"请填写信息所在的具体联系地址且不能超过50个字",50)) return false;
	if(!CheckIsNull(obj.truename,"请填写正确的联系人",50)) return false;
	
	var email		= document.getElementById("email");
	var mobile		= document.getElementById("mobile");
	var tel			= document.getElementById("tel");
	var QQ			= document.getElementById("userQQ");
	
	//检测手机
	if(mobile.value.length>0){
		if(mobile.value.length<=10){
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;
		}
		if(!/^[0-9]{11,30}$/.exec(mobile.value)){
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;   
		}
	}
	
	//检测座机
	if(tel.value.length>0){
		if(!/^[+]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{7,8}$/.exec(tel.value)){
			alert("请填写正确的电话号码格式为：0731-84168716");
			tel.focus();
			return false;
		}
	}
	
	if(mobile.value.length<=0 && tel.value.length<=0){
		alert("手机跟座机必填其中一项");
		mobile.focus();
		return false;
	}
	
	if(email.value.length>0)
	{
		if(!isEmail(email.value))
		{
			alert("电子邮箱格式不对");
			email.focus();
			return false;
		}
	}
	
	if(QQ.value.length>0)
	{
		if(!/^[0-9]{4,15}$/.exec(QQ.value))
		{
			alert("请您用数字填写正确的QQ");
			QQ.focus();
			return false;
		}
	}
}

//修改密码
function checkPasswordForm() {
	var str_password = document.getElementById("password");
	var str_nextpassword = document.getElementById("nextpassword");
	if(str_password.value.length<=5||str_password.value.length>=21){
		alert("请使用6-20位英文字母、数字、减号或下划线的组合，区分大小写");
		str_password.focus();
		return false;
	}
	if(str_nextpassword.value.length<=5 || str_nextpassword.value.length>=21){
		alert("请再输入一遍上面输入的密码");
		str_nextpassword.focus();
		return false;
	}
	if (str_password.value != str_nextpassword.value){
		alert("两次输入的密码不一样，请新输入");
		str_nextpassword.focus();
		return false;
	}
}

//修改邮箱
function checkEmailForm() {
	var email = document.getElementById("email");
	if (email.length<=0){
		alert("请输入电子邮箱");
		email.focus();
		return false;
	}
	if(!isEmail(email.value)){
		alert("电子邮箱格式不正正确");
		email.focus();
		return false;
	}
}

//验证登录
function checkLoginForm()
{
	if (!checkIsNull('username', '用户名不能为空而且不能大于20个字符', 20))
    {
        return false;
    }

	if (!checkIsNull('password', '密码不能为空而且不能大于30个字符', 30))
    {
        return false;
    }
}

//检测用户搜索
function checkSearchComProForm() {
	var obj = document.fomr_search_pro;
	if(!CheckIsNull(obj.s_keyword,"请输入搜索关键字，30个字符以内",30)) return false;
}

//检测添加新闻
function checkNewsForm() {
	if (!CheckIsNull(document.getElementById("title"),"新闻标题不能为空而且不能大于50个字符",50)) {
		return false;
	}
	
	var oEditor = FCKeditorAPI.GetInstance("content");
	var content = oEditor.GetXHTML();
	if ( content == "" ) {
		alert("请输入新闻内容");
		return false;
	}
	
	var keyword = document.getElementById("keyword");
	var keyword_len
	if ( keyword.value != "" ) {
		if ( keyword.value.length >= 50 ) {
			alert("关键词不能超过50个字符！");
			keyword.focus();
			return false;
		}
		else {
			keyword.value = keyword.value.replace(/，/g, ",");
			keyword_len = keyword.value.length - (keyword.value.replace(/,/g, "").length);
			if ( keyword_len >= 5 ) {
				alert("关键词不能超过5组！");
				keyword.focus();
				return false;
			}
			else {
				keyword.innerHTML = keyword.value;
			}
		}
	}
	
	if (!CheckIsNull(document.getElementById("news_from"),"新闻来源不能为空而且不能大于30个字符",30)) {
		return false;
	}
}

//添加信息
function checkJobsForm() {
	var jobs_type = document.getElementById("jobs_type");
	
	if(!CheckIsNull(document.getElementById("title"), "招聘主题不能为空而且不能大于50个字符", 50)) {
		return false;
	}
	
	if (jobs_type = 1) {
		if(!CheckIsNull(document.getElementById("number"), "请填写职业数量", 50)) {
			return false;
		}
	}
	
	if(!CheckIsNull(document.getElementById("content"), "请填写详细说明", 2000)) {
		return false;
	}
	
	if(!CheckIsNumeric(document.getElementById("memCity"), "请选择工作地点")) {
		return false;
	}
	
	if(!CheckIsNull(document.getElementById("address"), "请填写联系地址")) {
		return false;
	}
	
	if(!CheckIsNull(document.getElementById("man"), "请填写联系人")) {
		return false;
	}
	
	var email		= document.getElementById("email");
	var mobile		= document.getElementById("mobile");
	var tel			= document.getElementById("tel");
	var QQ			= document.getElementById("userQQ");
	
	//检测手机
	if(mobile.value.length > 0) {
		if(mobile.value.length <= 10) {
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;
		}
		if(!/^[0-9]{11,30}$/.exec(mobile.value)) {
			alert("请用数字填写正确的手机号码");
			mobile.focus();
			return false;   
		}
	}
	
	//检测座机
	if(tel.value.length > 0) {
		if(!/^[+]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{0,4}[-]{0,1}[0-9]{7,8}$/.exec(tel.value)) {
			alert("请填写正确的电话号码格式为：0731-84168716");
			tel.focus();
			return false;
		}
	}
	
	if(mobile.value.length <= 0 && tel.value.length <= 0) {
		alert("手机跟座机必填其中一项");
		mobile.focus();
		return false;
	}
	
	//检测邮箱
	if(email.value.length > 0) {
		if(!isEmail(email.value)) {
			alert("电子邮箱格式不对");
			email.focus();
			return false;
		}
	}
	
	//检测QQ
	if(QQ.value.length > 0) {
		if(!/^[0-9]{4,15}$/.exec(QQ.value)) {
			alert("请您用数字填写正确的QQ");
			QQ.focus();
			return false;
		}
	}
}

//判断搜索
function checkFormSearch()
{
    var s_keyword = getId('q');

    if (s_keyword.value == '' || s_keyword.value == '请输入关键词')
    {
        s_keyword.focus();
        return false;
    }
}

//-->

