function checkForm() {
		
	var name = trim(document.mailForm.name.value);
	if(name.length == 0) {
		alert('姓名不能为空');
		document.mailForm.name.focus();
		return false;
	}
    
    var company = trim(document.mailForm.company.value);
	if(company.length == 0) {
		alert('公司不能为空');
		document.mailForm.company.focus();
		return false;
	}
    
    var email = trim(document.mailForm.email.value);
	if(email.length == 0) {
		alert('邮箱不能为空');
		document.mailForm.email.focus();
		return false;
	}
    
    if(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email)) {
    } else {
        alert('邮箱格式错误');
        document.mailForm.email.focus();
		return false;
    }
    
	var channel = $('select[name="channel"]').val();
	if(channel == '-1') {
		alert('获知顺科的渠道不能为空');
		$('select[name="channel"]').focus();
		return false;
	} else {
		if(channel == 'Others') {
			var otherChannel = $('input[name="otherChannel"]').val();
			if(otherChannel.length == 0) {
				alert('获知顺科的渠道不能为空');
				$('input[name="otherChannel"]').focus();
				return false;
			}
		}
	}
	
	
	var message = trim(document.mailForm.message.value);
	if(message.length == 0) {
		alert('内容不能为空');
		document.mailForm.message.focus();
		return false;
	}
	
	var idcode = trim(document.mailForm.idcode.value);
	var result = jQuery('#result').text();
	if(idcode.length == 0) {
		alert('验证码不能为空');
		document.mailForm.idcode.focus();
		return false;
	}else {
		if(!checkIdcode(idcode, result)) {
			alert('验证码错误');
			document.mailForm.idcode.focus();
			return false;
		}
	}

	return true;
}
function trim(str)
{
	for(var i=0;i<str.length&&str.charAt(i)==" ";i++);
	for(var j=str.length;j>0&&str.charAt(j-1)==" ";j--);
	if(i>j)   
		return  "";  
	return str.substring(i,j);  
}


//产生随机数
function boundrandom(bound1, bound2) {
	var bound1 = parseFloat(bound1);
	var bound2 = parseFloat(bound2);
	return Math.random() * (bound1 - bound2) + bound2;
}

//验证结果
function checkIdcode(idcode, result) {
	if(idcode == result) {
		return true;
	}else{
		return false;
	}
}

$(document).ready(function () {
	var a = Math.floor(boundrandom(1,100));
	var b = Math.floor(boundrandom(1,100));
	var result = a*b;
	$('#num1').text(a);
	$('#num2').text(b);
	$('#result').text(result);
	
	$('select[name="channel"]').click(function(){
		var value = $('select[name="channel"]').val();
		if(value == 'Others') {
			$('input[name="otherChannel"]').show();
		} else {
			$('input[name="otherChannel"]').val('');
			$('input[name="otherChannel"]').hide();
		}
	});
});
