// JavaScript Document

//注册表单检查
function check_register_form() {
	
	var input_email = get_value('mail');
	if (input_email == '') {
		form_notice('Email地址不能为空', 'mail');
		return ;
	}
	if (!check_email(input_email)) {
		form_notice('请填写正确的Email地址', 'mail');
		return ;
	}
	
	var input_password = get_value('password');
	if(input_password == '') {
		form_notice('密码不能为空', 'password');
		return ;
	}
	if(input_password.length<3 || input_password.length>18) {
		form_notice('密码长度必须在3至18个字符', 'password');
		return ;
	}
	if(input_password != get_value('password1')) {
		form_notice('两次输入密码不相同', 'password1');
		return ;
	}
	
        if(get_value('company_name') == '') {
                form_notice('公司名必须填写', 'company_name');
                return ;
        }
        if(get_value('idcname') == '') {
                form_notice('请填写IDC简称', 'idcname');
                return ;
        }
	var site_url = get_value('site_url');
        if(site_url == '') {
                form_notice('公司网址必须填写', 'site_url');
                return ;
        }
	if (!IsURL(site_url)) {
		form_notice('网址格式不正确', 'site_url');
                return ;
	}
        if(get_value('intro') == '') {
                form_notice('请填写公司介绍', 'intro');
                return ;
        }
	if(get_value('address') == '') {
                form_notice('请填写公司地址', 'address');
                return ;
        }
	if(get_value('zipcode') == '') {
                form_notice('请填写公司邮编', 'zipcode');
                return ;
        }
	if(get_value('contact') == '') {
                form_notice('请填写公司联系人', 'contact');
                return ;
        }
	if(get_value('telephone') == '') {
                form_notice('请填写公司联系电话', 'telephone');
                return ;
        }
	if(get_value('fax') == '') {
                form_notice('请填写公司传真', 'fax');
                return ;
        }
	if(get_value('email') == '') {
                form_notice('请填写公司联系邮箱', 'email');
                return ;
        }
	if(get_value('qq') == '') {
                form_notice('请填写公司客服QQ', 'qq');
                return ;
        }
	
	document.forms['form1'].submit();
}

//获取某个id的值
function get_value(e_id) {
	return document.getElementById(e_id).value;
}

//表单提醒
function form_notice(msg, input) {
	alert(msg);
	document.getElementById(input).focus();
}

//检查email格式
function check_email(email) {
	var patrn = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
	if (email.search(patrn) == -1) {
		return false;
	} else {
		return true;
	}
}

//检查是否为网址
function IsURL(urlString)
{
        regExp = /(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i;
        if (urlString.match(regExp)){
		return true;
	}
        else{
		return false;
	}
}
