// JavaScript Document
var error=Array("请选择业务种类","请输入电子邮件","请输入电话号码","请输入公司名称","请输入姓名","请输入地址","请输入手机","请输入部门","请输入留言");

function isEmail(s){
 	var p = /^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/i; 
 	return p.test(s);
}

function contactType(id){
	if(id=="1" || id=="2")
		$('#contact_type_1').html("*");
	else
		$('#contact_type_1').html("&nbsp;");
	$('#contact_type_error').text("请选择业务种类");
}

function on_focus(id,value){
	$('#'+id+'_error').html(value);	
}
var Err=new Array("业务种类必须选择","电话不能为空","公司名称必须输入","电子邮件必须输入","邮件地址格式不合法","姓名必须输入","留言必须输入");
function on_blur(id,value){
	var contact_type=$('#contact_type').val();
	if(id=="contact_type"){
		if(contact_type==""){
			$('#'+id+'_error').html(Err[0]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else if(id=="contact_tel"){
		var contact_tel=$('#contact_tel').val();
		if(contact_tel==""){
			$('#'+id+'_error').html(Err[1]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else if( (contact_type=="1" || contact_type=="2") && id=="contact_company"){
		var contact_company=$('#contact_company').val();
		if(contact_company==""){
			$('#'+id+'_error').html(Err[2]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else if(id=="contact_email"){
		var contact_email=$('#contact_email').val();
		if(contact_email==""){
			$('#'+id+'_error').html(Err[3]);
		}else if(!isEmail(contact_email)){
			$('#'+id+'_error').html(Err[4]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else if(id=="contact_name"){
		var contact_name=$('#contact_name').val();
		if(contact_name==""){
			$('#'+id+'_error').html(Err[5]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else if(id=="contact_msg"){
		var contact_msg=$('#contact_msg').val();
		if(contact_msg==""){
			$('#'+id+'_error').html(Err[6]);
		}else{
			$('#'+id+'_error').html("");
		}
	}else{
		$('#'+id+'_error').html(value);	
	}
}

function Contact(){
	var contact_type=$('#contact_type').val();
	if(contact_type==""){
		$('#contact_type_error').html(Err[0]);
		return false;
	}
	var contact_email=$('#contact_email').val();
	if(contact_email==""){
		$('#contact_email_error').html(Err[3]);
		return false;
	}else if(!isEmail(contact_email)){
		$('#contact_email_error').html(Err[4]);
		return false;
	}else{
		$('#contact_email_error').html("");	
	}
	var contact_tel=$('#contact_tel').val();
	if(contact_tel==""){
		$('#contact_tel_error').html(Err[1]);
		return false;
	}
	if(contact_type=="1" || contact_type=="2"){
		var contact_company=$('#contact_company').val();
		if(contact_company==""){
			$('#contact_company_error').html(Err[2]);
			return false;
		}
	}	
	var contact_name=$('#contact_name').val();
	if(contact_name==""){
		$('#contact_name_error').html(Err[5]);
		return false;
	}
	var contact_msg=$('#contact_msg').val();
	if(contact_msg==""){
		$('#contact_msg_error').html(Err[6]);
		return false;
	}
	return true;

}