﻿
var ReAjax = function()
{}
ReAjax.prototype.GetHttpRequest = function()
{
	var reObj="";
	if ( window.XMLHttpRequest )		// 非IE ie7 
	{
		reObj= new XMLHttpRequest() ;
	}
	else if ( window.ActiveXObject )// IE
	{	
		try
		{
			reObj=new ActiveXObject("MsXml2.XmlHttp") ;
		}
		catch(e)
		{
			reObj=new 	ActiveXObject("microsoft.XmlHttp")
		}
	}
	return reObj;
}

ReAjax.prototype.LoadUrl = function( urlToCall,altDiv,valInput)
{	
	var oReAjax = this ;
	var oAjaxHttp = this.GetHttpRequest() ;
	oAjaxHttp.open( "GET", urlToCall, true) ;
	oAjaxHttp.onreadystatechange=function()
	{
		if(oAjaxHttp.readyState==4)
		{	if(altDiv!="")
		{
			document.getElementById(altDiv).innerHTML = oAjaxHttp.responseText;}
			else(alert(oAjaxHttp.responseText));
			if(oAjaxHttp.status==200||oAjaxHttp.status==304)
			{
				if(valInput!="")
				{
			 		if(document.getElementById(altDiv).innerHTML.indexOf('对不起')=='-1')
			 		{
				 		document.getElementById(valInput).value=1;
			 		}
			 			else
			 		{
				 		document.getElementById(valInput).value=0;
			 		}
				}
			}
			else
			{
				alert('Request error' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' );	
			}
		}
	}
	oAjaxHttp.send( null ) ;
	if(altDiv!=""){
	document.getElementById(altDiv).innerHTML="loading...";}
}

ReAjax.prototype.LoadUrl2 = function(urlToCall,altDiv)
{	
	var oReAjax = this ;
	var oAjaxHttp = this.GetHttpRequest() ;
	oAjaxHttp.open("GET", urlToCall, true) ;
	oAjaxHttp.onreadystatechange=function()
	{
		if(oAjaxHttp.readyState==4)
		{	
			document.getElementById(altDiv).innerHTML = oAjaxHttp.responseText;
		}
	}
	oAjaxHttp.send(null);
	if(altDiv!="")
	{
		document.getElementById(altDiv).innerHTML = "loading...";
	}
}

		function checkemail(email)
			{
				if(email.length==0)
				{return true;}
				var pn_0=email.indexOf("@");
				var pn_1=email.indexOf(".",pn_0);
				var pn_2=email.length;
				if(pn_0<1||pn_1<pn_0+2||pn_1+2>pn_2)
				{return false;}
				else
				{return true;}
			}

			function CheckUnique()
			{
				if(document.getElementById("username").value==""){
					return false;
					}
				if(document.getElementById("username").value.length<3||document.getElementById("username").value.length>16)
				{
					alert("User Name may only contains 3 to 16 characters or numbers!");
					return false;
				}
				var obj=document.getElementById("username").value;
				var obj=obj.match(/[\u4e00-\u9fa5]/g);
				if(obj!=null)
				{
					alert("User Name may only contains 3 to 16 characters or numbers! ");
					return  false;
				}
				var obj_1=document.getElementById("username").value;
				var user=encodeURIComponent(obj_1);
				ReAjax.prototype.LoadUrl('unique.cfm?UserName='+user+'&DataTable=CIGXE_Supplier&field=SupplierUserName_nvarchar',"uniqueNameCheck","");
			}
			function mail()
			{
				var error="";
				if(!(checkemail(document.all.emails.value)))
				{
					error+="请输入正确的邮箱格式.\n";
				}
				if(error!="")
				{
					alert(error);
					return false;
				}
			}
		function verify()
			{
				var error="";
				if (document.all.policy.checked==false)
				{
					error+="你必须同意用户协议。\n";
				}
				if(document.getElementById("username").value.length<3)
				{
					error+="用户名小于3位。\n";
				}
				var obj=document.getElementById("username").value;
				var obj=obj.match(/[\u4e00-\u9fa5]/g);
				if(obj!=null)
				{
					error+="登录名只能是字母、数字、下划线！\n";
				}
				if(!(checkemail(document.all.emailaddress.value)))
				{
					error+="请输入正确的E-mail地址.\n";
				}
				if(!(checkemail(document.all.alipay.value)))
				{
					error+="请输入正确支付宝帐号.\n";
				}
				if (document.all.password.value.length == 0)
				{
					error+="没有输入密码. \n";
				}
				if(document.all.password.value.length<5)
				{
					error+="密码至少5位. \n";
				}
				if (document.all.password.value != document.getElementById("confirm").value)
				{
					error+="两次密码不一致.\n";
				}
				
				if (document.all.alipay.value != document.getElementById("alipayconfirm").value)
				{
					error+="两次支付宝账号不一致.\n";
				}
				/*if(document.all.ICBCNo.value!=document.all.ICBCNoconfirm.value)
				{
					error+="两次工商银行账号不一致.\n";
				}
				if((document.all.ICBCNo.value=="")&&(document.all.alipay.value==""))
				{
					error+='支付宝账号或者工商银行账号必须输入一项！';	
				}*/
				if (!(verifyChar(document.all.phone.value)))
				{
					error+="电话号码不正确。\n";
				}
				var phone=document.getElementById("Mobile").value;
				if(phone!="")
				{
					if(phone.length!=11||(phone.substring(0,2)!="13" && phone.substring(0,2)!="15"))
					{
						error+="请输入有效的手机号码!\n";
					}
				}
//				if(document.all.hidSent.value=="")
//				{
//					error+="请确认你是否发送了手机验证码,没有验证码账号不能激活!\n";	
//				}
				if (!(verifyChar(document.all.qq.value)))
				{
					error+="QQ号码不正确。\n";
				}

				if(error!="")
				{
					alert(error);
					return false;
				}
				if(document.all.hidBBSUnique.value==0 && document.all.joinBBS.checked)
				{
					return confirm("你选择了自动注册到论坛，但你的用户名在论坛里被注册了。\n如果点「确定」将继续但不能成功注册到论坛,\n点「取消」你将可以修改后再提交。\n\n你确定要继续吗？");
				}
				if(document.all.hidBBSUnique.value==1 && document.all.joinBBS.checked)
				{
					CheckUniqueInBBS();//再次检查是否重复，因为可能在输入注册信息的时候被占用。
					if(document.all.hidBBSUnique.value==0)
					{
						return confirm("你选择了自动注册到论坛，但你的用户名在论坛里被注册了。\n如果点「确定」将继续但不能成功注册到论坛,\n点「取消」你将可以修改后再提交。\n\n你确定要继续吗？");
					}
				}
			}
			function verifyChar(obj)
			{
				var test1=/[0-9-]/;
				for(i=0;i<length+1;i++)
				{
					if(!(test1.test(obj.substring(i+1,i))))
					{
						return false;
					}
				}
				return true;
			}
			function CheckSendMail()
			{
				var result=ReAjax.prototype.LoadUrl('../product/trytest.cfm',"text");
				if(parseInt(result)==3)
				{
					window.location.href="../users/userlogin.cfm?error=您还没有登陆&reurl=../product/productinfo.cfm"
				}
				else
				{
					if(parseInt(result)==0)
					{
						alert("申请成功，请等待验证，审核通过后我们回把测试信息发送到您的邮箱中,请注意查收!");
					}
					else
					{
						if(parseInt(result)==4)
						{
							alert("您已经申请过代理服务器测试，正在审核中。审核通过后我们会发送邮件通知您");
						}
						if(parseInt(result)==5)
						{
							if(confirm("您确定要再次发送服务器测试邮件吗?"))
							{
								var result1=ReAjax.prototype.LoadUrl('../product/sendtrymail.cfm',"text");
								if(parseInt(result1)==0)
								{
									window.location.href="../users/userlogin.cfm?error=您还没有登陆&reurl=../product/productinfo.cfm"
								}
								else
								{
									alert("代理服务器测试邮件发送成功,请注意查收!")
								}
							}
						}
						
					}
				}
			}
			
	function getInfo()//读取答案与提示问题
	{
		var userName=document.all.hidUserName.value;
		var pwd=document.all.oldpwd.value;
		if(pwd!="" && userName!="")
		{
			var result=ReAjax.prototype.LoadUrl('GetQuestionAndAnswer.cfm?UserName='+userName+'&Pwd='+pwd,"text");
			var reArray=new Array();
			reArray=result.split("|");
			if(reArray.length>1)
			{
				document.all.question.value=reArray[0];
				document.all.answer.value=reArray[1];
			}
			else
			{alert(reArray[0]);}
		}
		document.getElementById("validateShow").value="";
	}
	
	function CheckAlipayInfo(values)// 检查支付宝账号
	{
		if(!(checkemail(values)))
		{
			alert("请输入正确的支付宝账号！");
			document.getElementById("alipay").focus();
		}
		else
		{
			var obj = document.getElementById("hid_alipay");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?Alipay="+values,"alipay_div");
			}
			obj.value = values;
		}
	}

	function CheckAlipayNameInfo(values)// 检查电话号码
	{
		if(values=="")
		{
			return false;
		}
		else
		{
			var obj = document.getElementById("hid_usaphone");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?usaphone="+values,"usaphone_div");
			}
			obj.value = values;
		}
	}
	
	function checkProqa(v){
	   if(document.getElementById("proQuestion").value==""){
		 alert("Secret question is required");
		 return false;
		}
		else if(v==""){
			alert("Secret answer is required");
		    return false;
			}
	   else if(v==document.getElementById("proQuestion").value){
			alert("Secret security questions and answers can not be the same.");
			return false;
			}	
	}
	
	function checkphone(values)
	{
	  	if(values=="")
		{
			alert("Non-USA format Telephone number is required.");
		}
		else
		{
			var obj = document.getElementById("hid_phone");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?phone="+values,"phone_div");
			}
			obj.value = values;
		}
	}
	
	function checkMSN(values){
		if(!(checkemail(values)))
		{
			alert("MSN is invalid.");
		}
		else
		{
			var obj = document.getElementById("hid_FtextMSN");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?FtextMSN="+values,"FtextMSN_div");
			}
			obj.value = values;
		}
	}
	
	function checkPaypal(values){
		if(!(checkemail(values)))
		{
			alert("Paypal is invalid.");
		}
		else
		{
			var obj = document.getElementById("FtextPaypal_div");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?FtextPaypal="+values,"FtextPaypal_div");
			}
			obj.value = values;
		}
	}
	
	function CheckEMAILInfo(values)// 检查E-Mail
	{
		if(!(checkemail(values)))
		{
			alert("E-mail is invalid!");
			return false;
		}
		else
		{
			var obj = document.getElementById("hid_emailaddress");
			if(obj.value != values)
			{
				ReAjax.prototype.LoadUrl2("unique.cfm?emailaddress="+values,"emailaddress_div");
			}
			obj.value = values;
		}
	}