﻿function $$(id)
{	
	return document.getElementById(id);
}
function isLimitLen(message,total)
{
	var max;
	max = total;
	if (message.value.length > max) {
		message.value = message.value.substring(0,max);
		return true;
	}
	else {
		return false;
	}
}
function isInteger(str)
{  
	var regu = /^[-]{0,1}[0-9]{1,}$$/;
	return regu.test(str);
}
function trim(str)
{
	return str.replace(/(^[\s　]*)|([\s　]*$$)/g, '');
}
function checkform()
{
	var title =$$("zxtitle");
	var content =$$("zxcontent");
	var sex =$$("zxsex");
	var age =$$("zxage");
	//var ks =$$("zxclass");
	var name =$$("zxname");
	var tel =$$("zxtel");
	if(trim(title.value).length<=0)
	{
		alert('咨询主题不能为空！');
		document.form1.zxtitle.focus();
		return false;
	}
	if(trim(title.value).length>100)
	{
		alert('咨询主题字数不能大于50个汉字！');
		document.form1.zxtitle.focus();
		return false;
	} 
	if(trim(name.value).length<=0)
	{
		alert('姓名不能为空！');
		document.form1.zxname.focus();
		return false;
	}
	if(trim(sex.value).length<=0)
	{
		alert('请选择您的性别！');
		document.form1.zxsex.focus();
		return false;
	}
	/*
	if(trim(age.value).length<=0)
	{
		alert('您的年龄不能为空！');
		document.form1.zxage.focus();
		return false;
	}
	*/
	if(!isInteger(age.value))
	{
		alert('您的年龄只能为数字！');
		document.form1.zxage.focus();
		return false;
	}
	
	if(trim(age.value).length<=0 || trim(age.value).length>3)
	{
		alert('请准确填写您的年龄！');
		document.form1.zxage.focus();
		return false;
	}
	/*
	if(trim(tel.value).length<=0)
	{
		alert('电话不能为空！');
		document.form1.zxtel.focus();
		return false;
	}
	*/
	if(trim(content.value).length<=0)
	{
		alert('咨询详情不能为空！');
		document.form1.zxcontent.focus();
		return false;
	}
	if(trim(content.value).length>500)
	{
		alert('咨询详情不能大于250个汉字！');
		document.form1.zxcontent.focus();
		return false;
	}
	return true;
}

