// JavaScript Document
function checksubmit()
{
	companyname = $("#companyname").val();
	if(companyname == '')
	{
		$("#validatecompanyName").html("<font color=red>公司名称不能为空</font>");
		return false;
	}

	return checkUserName();
	Email = $("#companyEmail").val();

	return checkemail(Email);

	return true;
}

function checkUserName()
{
	userName = $("#userName").val();
	if(userName=='')
	{
		$("#validateuserName").html("<font color=red>用户名不能空</font>");
		return false;
	} else if (userName.length < 4 || userName.length > 12) {
		$("#validateuserName").html("<font color=red>用户名密码在6-12位之间</font>");
		return false;
	} else {
		$.get('http://www.ef007.com/agency.php?ac=shopreg&op=existUsername&username=' + userName,null,callback);
	}
}

function callback(data){
	if(data == 1)
	{
		$("#validateuserName").html("<font color=red>用户名可以注册</font>");
		return true;
	} else {
		$("#validateuserName").html("<font color=red>用户名已经被注册</font>");
		return false;
	}
	
}

function isnumber(str)
{
	var number_chars = "1234567890";
	var i;
	for(i=0; i < str.length; i++)
	{
		if(number_chars.indexOf(str.charAt(i))==-1) return false;
	}
	return true;
}

function checkemail(string)
{
	if(string.length != 0)
	{
		if(string.charAt(0)=="." || string.charAt(0) =="@" || string.indexOf('@',0) == -1 || string.indexOf('.',0) == -1)
		{
			$("#validatecompanyEmail").html("<font color=red>电子邮件格式不正确</font>");
			return false;
		} else {
			$("#validatecompanyEmail").html("<font color=red>正确</font>");
			return false;
		}
	} else {
		$("#validatecompanyEmail").html("<font color=red>电子邮件不能为空</font>");
		return false;
	}
	
	return true;
}
