Event.observe(window, 'load', function() {
	radioChkShow();
	showClass("st_5");
	getRecommendId();
	//getRecommendVal();
});
//获取推荐人ID
function getRecommendId()
{
   var a,b,c,d,e; 
   a = document.location.href;
   b = "http://"+location.hostname+"/user/register.html";
   c = "?recommend_id=";
   d = a.replace(b,""); 
   e = d.replace(c,"");
   if(!$('recommend_id'))
   {
   	   return false;
   }
   else
   {
   	   $("recommend_id").value = e;
   	   Ajax.call( '/user/register.php?action=getRecommendNickName', 'id=' + e, check_recommend_callback , 'GET', 'TEXT', true, true );
   } 
}
function check_recommend_callback(result)
{
	$("recommend_name").value = result;
	if(result != '')
	{
		$("recommend_name").setAttribute('disabled','disabled');
	}
}
function getRecommendVal()
{
	var recommend_val = $("recommend_name").value;
	if(recommend_val != '')
	{
		//$("recommend_name").contentEditable = false;
		//$("recommend_name").readOnly = true;
		$("recommend_name").setAttribute('disabled','disabled');
	}
}
//show class daohang
function showClass(id)
{
	if(!$(id)) return false;
	$(id).className = "on";
}
//根据radio选择切换公司和个人注册信息填写
function radioChkShow()
{
	if(!$("person")) return false;
	if(!$("company")) return false;
	if($("person").checked)
	{
		$("info_company").className = "dpN";
		$("info_person").className = "";
		document.form.onsubmit = function() {
			return register_submit_p();
			}
	}
	else if($("company").checked)
	{
		$("info_company").className = "";
		$("info_person").className = "dpN";
		document.form.onsubmit = function() {
			return register_submit();
			}
	}
}
function register_submit()
{			if(checkEmail()&&checkNickName()&&checkPassword()&&checkCompanyName()&&checkNumber('biz_phone1','biz_phone_error')&&checkNumber('biz_phone2','biz_phone_error')&&checkNumber('biz_phone3','biz_phone_error')&&checkMobile($('mobile').value)&&checkScode())
	{
		if( $("email_exist").style.display == '' || $("nickname_exist").style.display == '')
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
function register_submit_p()
{
	if(checkEmail()&&checkNickName()&&checkPassword()&&checkPersonName()&&checkNumber('biz_phone1_p','biz_phone_p_error')&&checkNumber('biz_phone2_p','biz_phone_p_error')&&checkNumber('biz_phone3_p','biz_phone_p_error')&&checkMobile($('mobile_p').value)&&checkScode())
	{
		if( $("email_exist").style.display == '' || $("nickname_exist").style.display == '')
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}	
}
//check Email
function checkEmail()
{  
  var email = $("email").value;
  if (email == '')
  {
	if($("email_null")) $("email_null").show();
	return false;
  }
  else if (!Utils.isEmail(email) || email.length > 60)
  {
    if($("email_error")) $("email_error").show();
	return false;
  }
  else if(!email == "")
  {
	   Ajax.call( '/user/register.php?action=checkReEmail', 'email=' + email, check_email_callback , 'GET', 'TEXT', true, true );
	   return true;
  } 
}
function check_email_callback(result)
{
  if ( result == 'true' )
  {
	if($("email_exist")) $("email_exist").show();
    return false;
  }
  else
  {
    return true;
  }
}
function checkRecommendNickName()
{
	var recommand_nickname = $('recommend_name').value;
	if( recommand_nickname !='')
	{
		Ajax.call( '/user/register.php?action=checkReNickname', 'nickname=' + recommand_nickname, check_recommand_nickname_callback , 'GET', 'TEXT', true, true );
	}
	return true;
}
function check_recommand_nickname_callback(result)
{
	if ( result == 'false' )
	{
		if($("recommend_name_exist")) $("recommend_name_exist").show();
		return false;
	}
	else
	{
		return true;
	}	
}
function hideRecommendError()
{
	if($("recommend_name_exist")) $("recommend_name_exist").hide();
}
//隐藏所有的提示信息
function hideAllNotice()
{
	if($("email_notice")) $("email_notice").hide();
	if($("pwd_notice")) $("pwd_notice").hide();
	if($("conform_password_notice")) $("conform_password_notice").hide();
	if($("nickname_notice")) $("nickname_notice").hide();
	if($("recommend_name_notice")) $("recommend_name_notice").hide();
	if($("company_name_notice")) $("company_name_notice").hide();
	if($("mobile_notice")) $("mobile_notice").hide();
	if($("biz_phone1_notice")) $("biz_phone1_notice").hide();
	if($("biz_phone2_notice")) $("biz_phone2_notice").hide();
	if($("biz_phone3_notice")) $("biz_phone3_notice").hide();
}
//隐藏E-mail错误信息
function hideUserError()
{
	if($("email_error")) $("email_error").hide();
	if($("email_exist")) $("email_exist").hide();
	if($("email_null")) $("email_null").hide();	
}
//隐藏密码错误信息
function hidePwdError()
{
	if($("pwd_error")) $("pwd_error").hide();	
	if($("pwd_null")) $("pwd_null").hide();		
}
//隐藏确认密码错误信息
function hideConfirmPwd()
{
	if($("conform_password_error")) $("conform_password_error").hide();		
}
//隐藏昵称错误信息
function hideNickNameError()
{
	if($("nickname_error")) $("nickname_error").hide();	
	if($("nickname_exist")) $("nickname_exist").hide();
	if($("nickname_null")) $("nickname_null").hide();
}
//隐藏验证码错误信息
function hideSecurityCodeError()
{
	if($("securitycode_error")) $("securitycode_error").hide();	
}
//隐藏公司信息
function comInfoError(val)
{
	if('company_name' == val)
	{
		if($("company_name_error")) $("company_name_error").hide();		
	}
	else if('mobile' == val)
	{
		if($("mobile_error")) $("mobile_error").hide();		
	}
	else if('biz_phone1' == val)
	{
		if($("biz_phone_error")) $("biz_phone_error").hide();		
	}
	else if('biz_phone2' == val)
	{
		if($("biz_phone_error")) $("biz_phone_error").hide();
	}
	else if('biz_phone3' == val)
	{
		if($("biz_phone_error")) $("biz_phone_error").hide();
	}
	else if('mobile' == val)
	{
		if($("mobile_error")) $("mobile_error").hide();	
	}
	else if('biz_email' == val)
	{
		if($("biz_email_error")) $("biz_email_error").hide();	
	}
}
//check password
function checkPassword()
{
	var password = $('password').value;
	if(password == '')
	{
		$("pwd_null").show();		
		return false;
	}
    else if ( !password.match(/^[A-Za-z0-9]{6,20}$/) )
    {
        $("pwd_error").show();		
		return false;
    }
    else
    {
        return true;
    }
}
//check confirm password
function checkConformPwd()
{
	if($("conform_password").value == '')
	{
		if($("conform_password_error")) $("conform_password_error").show();		
		return false;
	}
	else if($("password").value != $("conform_password").value)
	{
		if($("conform_password_error")) $("conform_password_error").show();	
		return false;
	}
	else
	{
		return true;
	}
}
//过滤特殊字符
function checkNickNameSpecial(input)
{
	if(/tootoo|too-too|too_too|ninetowns|nine-towns|nine_towns/ig.test(input.value))
	{
		input.value = input.value.replace(/tootoo|too-too|too_too|ninetowns|nine-towns|nine_towns/ig,'');
	}
}
//check nickname
function checkNickName()
{
	var nickname = $('nickname').value;
	if(nickname == '')
	{
		$("nickname_null").show();
		return false;	
	}
	else if(nickname.match(/[\d]{7,20}/))
	{
		$("nickname_error").show();
		return false;
	}
	else if(nickname.match(/^[A-Za-z]*[\d]{7,20}[A-Za-z]*$/))
	{
		//alert("1");
		$("nickname_error").show();
		return false;
	}
	else if (!nickname.match(/^[A-Za-z0-9][A-Za-z0-9|\-|\_]{2,18}[A-Za-z0-9]$/))
	{
		//alert("2");
		$("nickname_error").show();
		return false;
	}
	else if(!nickname == "")
	{
		Ajax.call( '/user/register.php?action=checkReNickname', 'nickname=' + nickname, check_nickname_callback , 'GET', 'TEXT', true, true );
		return true;
	}
	else
	{
		return true;	
	}
}
function check_nickname_callback(result)
{
  if ( result == 'true' )
  {
    $("nickname_exist").show();
    return false;
  }
  else
  {
    return true;
  }	
}
//check password strength
function checkPwdStrength()
{
	if(!$("password")) return false;
	var password = $("password").value;
	if(password.match(/^[A-Z]{6,20}$/) || password.match(/^[a-z]{6,20}$/) || password.match(/^[0-9]{6,20}$/))
	{
		$("pw_strength").src = "/images/seller/password-line-02.gif";
		$('character').innerHTML = "弱";	
		return false;
	}
	else if(password.match(/^[A-Za-z]{6,20}$/) || password.match(/^[a-z0-9]{6,20}$/) || password.match(/^[A-Z0-9]{6,20}$/))
	{
		$("pw_strength").src = "/images/seller/password-line-03.gif";	
		$('character').innerHTML = "中";	
		return false;
	}
	else if(password.match(/^[A-Za-z0-9]{6,20}$/))
	{
		$("pw_strength").src = "/images/seller/password-line-04.gif";
		$('character').innerHTML = "强";	
		return false;
	}
}
function checkNumber(id,error_id)
{
	var number = $(id).value;
	if(!Utils.isTel(number))
	{
		$(error_id).show();	
		return false;
	}
	else
	{
		return true;	
	}
}
//check company name & person name
function checkCompanyName()
{
	if($('company_name').value == '')
	{
		$('company_name_error').show();
		return false;
	}
	else
	{
		return true;	
	}
}
//隐藏所有的提示信息
function hideAllNoticeP()
{
	if($("email_notice")) $("email_notice").hide();
	if($("pwd_notice")) $("pwd_notice").hide();
	if($("conform_password_notice")) $("conform_password_notice").hide();
	if($("nickname_notice")) $("nickname_notice").hide();
	if($("recommend_name_notice")) $("recommend_name_notice").hide();
	if($("person_name_notice")) $("person_name_notice").hide();
	if($("mobile_p_notice")) $("mobile_p_notice").hide();
	if($("securitycode_notice")) $("securitycode_notice").hide();
	if($("biz_phone1_p_notice")) $("biz_phone1_p_notice").hide();
	if($("biz_phone2_p_notice")) $("biz_phone2_p_notice").hide();
	if($("biz_phone3_p_notice")) $("biz_phone3_p_notice").hide();
}
//隐藏个人信息提示
function perInfoError(val)
{
	if('person_name' == val)
	{
		if($("person_name_error")) $("person_name_error").hide();		
	}
	else if('mobile_p' == val)
	{
		if($("mobile_p_error")) $("mobile_p_error").hide();		
	}
	else if('biz_phone_p' == val)
	{
		if($("biz_phone_p_error")) $("biz_phone_p_error").hide();	
	}
	else if('biz_email_p' == val)
	{
		if($("biz_email_p_error")) $("biz_email_p_error").hide();	
	}
	else if('biz_phone1_p' == val)
	{
		if($("biz_phone_p_error")) $("biz_phone_p_error").hide();		
	}
	else if('biz_phone2_p' == val)
	{
		if($("biz_phone_p_error")) $("biz_phone_p_error").hide();
	}
	else if('biz_phone3_p' == val)
	{
		if($("biz_phone_p_error")) $("biz_phone_p_error").hide();
	}
}
//check person name & person name
function checkPersonName()
{
	if($('person_name').value == '')
	{
		$('person_name_error').show();
		return false;
	}
	else
	{
		return true;	
	}	
}
//only input number
function onlyDigital(input)
{
	if(/[^\d\/\d]/.test(input.value))
	{
		input.value = input.value.replace(/[^\d\/\d]/g,'');
	}
}
//check mobile
function checkMobile(mobile)
{
	if(!$('mobile_error')) return false;
	if(!$('mobile_p_error')) return false;
	var len = mobile.length;
	if( len < 11)
	{
		if($('mobile'))
		{
			$('mobile_error').show();
		}
		if($('mobile_p'))
		{
			$('mobile_p_error').show();
		}
		return false;
	}
	else if( len > 15)
	{
		if($('mobile'))
		{
			$('mobile_error').show();
		}
		if($('mobile_p'))
		{
			$('mobile_p_error').show();
		}	
		return false;
	}
	else
	{
		return true;	
	}
}
//check email format
function checkEmailFormat(email)
{
	if (email != '' && !email.match(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/))
	{
		if($('biz_email_error'))
		{
			$('biz_email_error').show();	
		}
		if($('biz_email_p_error'))
		{
			$('biz_email_p_error').show();		
		}
		return false;
	}
	else
	{
		return true;
	}
}
//国家列表
function getCountry()
{
	Ajax.call("/user/register.php?action=countryList",'',check_country_callback,'GET','TEXT', true, true);
}
function check_country_callback(result)
{
	if($('countrylist')) $('countrylist').innerHTML = result; 
}
function getCountryP()
{
	Ajax.call("/user/register.php?action=countryList&list=p",'',check_countryp_callback,'GET','TEXT', true, true);
}
function check_countryp_callback(result)
{
	if($('countrylist_p')) $('countrylist_p').innerHTML = result;	
}


