// 初始化一个xmlhttp对象

function InitAjax(){
var ajax=false;
try {
　　ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
　} catch (e) { 
　　try { 
　　　ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
　　} catch (E) { 
　　　ajax = false; 
　　} 
　}
　if (!ajax && typeof XMLHttpRequest!='undefined') { 
　　ajax = new XMLHttpRequest(); 
　} 
　return ajax;
}

//ajax的post方法
function PostAjaxJs(url,posturl,showname){
　//获取显示层的位置
　var show = document.getElementById(showname); 
　//实例化Ajax对象
　var ajax = InitAjax();
　//使用Get方式进行请求
　ajax.open("POST", url, true); 
  ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");   

　ajax.send(posturl); 
　//获取执行状态
　ajax.onreadystatechange = function() { 
　　//如果执行是状态正常，那么就把返回的内容赋值给上面指定的层
　　if (ajax.readyState == 4 && ajax.status == 200) { 
　　　show.innerHTML = ajax.responseText; 
　　} 
　}
}

function ajaxcheck1()
{
	var username = document.getElementById("username").value;
	var productid = document.getElementById("productid").value;
	var productnum = document.getElementById("productnum").value;

	var pt1 = "[\u4e00-\u9fa5A-Za-z0-9_]{1,17}"; 
	if(!username.match(pt1)) 
	{ 
		alert("您的賬號格式錯誤，請重新輸入。"); 
		return;
	}
　//需要进行Ajax的URL地址
　var url = "checkclient.php?t=check1";
  var posturl = "user="+username+"&id="+productid+"&num="+productnum;
  PostAjaxJs(url,posturl,'div7');

}

function ajaxcheck2(minnum)
{
	var username = document.getElementById("username").value;
	var email = document.getElementById('email').value ;
	var phone1 = document.getElementById('phone1').value ;
	var phone2 = document.getElementById('phone2').value ;
	var accaddr = document.getElementById('accaddr').value ;
	var invoicecode = document.getElementById('invoicecode').value ;
	var invoicehead = document.getElementById('invoicehead').value ;

	var proName = document.getElementById("proName").value;
	var proPrice = document.getElementById('proPrice').value ;
	var prefePro = document.getElementById('prefePro').value ;
	var prefePrice = document.getElementById('prefePrice').value ;
	var lastPrice = document.getElementById('lastPrice').value ;
	var productid = document.getElementById('productid').value ;
	var playerid = document.getElementById('playerid').value ;

	var moneytype = document.getElementById('moneytype').value ;
	var spritename = document.getElementById('spritename').value ;
	
	var productnum = document.getElementById('productnum').value ;
	var perPrice = document.getElementById('perPrice').value ;

	if(productnum.length <=0)
	{
		alert("請輸入購買數量"); 
		return;
	}
	var pt1 = "^([1-9][0-9]*)$";
	if ( !productnum.match(pt1) )
	{
		alert("購買數量只能是數字");
		return;
	}
	if(productnum<minnum)
	{
		alert("購買數量最少是"+minnum);
		return;
	}
	if(username.length <=0 ||email.length <=0 ||phone2.length <=0)
	{
		alert("姓名，email和行動電話是必填項。"); 
		return;
	}
	var pt1="[\u4e00-\u9fa5A-Za-z][\u4e00-\u9fa5A-Za-z0-9_]{1,20}";
	if(!username.match(pt1))
	{
		alert("您的姓名格式錯誤，請重新輸入。"); 
		return;
	}
	if(!/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(email))
	{
		alert("您的email格式錯誤，請重新輸入");
		return;
	}
	if(isNaN(phone1)||isNaN(phone2))
	{
		alert("電話號碼只能是數字");
		return;
	}
　//需要进行Ajax的URL地址
　var url = "checkclient.php?t=check2";
  var posturl = "user="+username+"&email="+email+"&phone1="+phone1+"&phone2="+phone2+"&accaddr="+accaddr+"&invoicecode="+invoicecode+"&invoicehead="+invoicehead+"";
  posturl = posturl + "&proName="+proName+"&proPrice="+proPrice+"&prefePro="+prefePro+"&prefePrice="+prefePrice+"&lastPrice="+lastPrice+"&id="+productid+"&playerid="+playerid;
  posturl = posturl + "&moneytype="+moneytype+"&spritename="+spritename+"";//为第三步返回上一步传递的参数
  posturl = posturl + "&productnum="+productnum+"&perprice="+perPrice;//为點數支付所需传递的参数
  PostAjaxJs(url,posturl,'div7');
}

function ajaxcheck3()
{
	var username = document.getElementById("username").value;
	var email = document.getElementById('email').value ;
	var phone1 = document.getElementById('phone1').value ;
	var phone2 = document.getElementById('phone2').value ;
	var accaddr = document.getElementById('accaddr').value ;
	var invoicecode = document.getElementById('invoicecode').value ;
	var invoicehead = document.getElementById('invoicehead').value ;

	var proName = document.getElementById("proName").value;
	var proPrice = document.getElementById('proPrice').value ;
	var prefePro = document.getElementById('prefePro').value ;
	var prefePrice = document.getElementById('prefePrice').value ;
	var lastPrice = document.getElementById('lastPrice').value ;
	
	var id = document.getElementById('id').value ;
	var playerid = document.getElementById('playerid').value ;

	var productnum = document.getElementById('productnum').value ;
	var perPrice = document.getElementById('perPrice').value ;
　//需要进行Ajax的URL地址
　var url = "checkclient.php?t=check3";
  var posturl = "user="+username+"&email="+email+"&phone1="+phone1+"&phone2="+phone2+"&accaddr="+accaddr+"&invoicecode="+invoicecode+"&invoicehead="+invoicehead+"";
  posturl = posturl + "&proName="+proName+"&proPrice="+proPrice+"&prefePro="+prefePro+"&prefePrice="+prefePrice+"&lastPrice="+lastPrice+"";
  posturl = posturl + "&id="+id+"&playerid="+playerid+"";
  posturl = posturl + "&productnum="+productnum+"&perprice="+perPrice;//为點數支付所需传递的参数
  PostAjaxJs(url,posturl,'div7');
}

function ajaxcheck3_2()
{
	var username = document.getElementById("username").value;
	var email = document.getElementById('email').value ;
	var phone1 = document.getElementById('phone1').value ;
	var phone2 = document.getElementById('phone2').value ;
	var accaddr = document.getElementById('accaddr').value ;
	var invoicecode = document.getElementById('invoicecode').value ;
	var invoicehead = document.getElementById('invoicehead').value ;

	var proName = document.getElementById("proName").value;
	var proPrice = document.getElementById('proPrice').value ;
	var prefePro = document.getElementById('prefePro').value ;
	var prefePrice = document.getElementById('prefePrice').value ;
	var lastPrice = document.getElementById('lastPrice').value ;
	
	var id = document.getElementById('id').value ;
	var playerid = document.getElementById('playerid').value ;

	var moneytype = document.getElementById('moneytype').value ;
	var spritename = document.getElementById('spritename').value ;

	var productnum = document.getElementById('productnum').value ;
	var perPrice = document.getElementById('perPrice').value ;

　//需要进行Ajax的URL地址
　var url = "checkclient.php?t=check3-2";
  var posturl = "user="+username+"&email="+email+"&phone1="+phone1+"&phone2="+phone2+"&accaddr="+accaddr+"&invoicecode="+invoicecode+"&invoicehead="+invoicehead+"";
  posturl = posturl + "&proName="+proName+"&proPrice="+proPrice+"&prefePro="+prefePro+"&prefePrice="+prefePrice+"&lastPrice="+lastPrice+"";
  posturl = posturl + "&id="+id+"&playerid="+playerid+"";
  posturl = posturl + "&moneytype="+moneytype+"&spritename="+spritename+"";
  posturl = posturl + "&productnum="+productnum+"&perprice="+perPrice;//为點數支付所需传递的参数
  PostAjaxJs(url,posturl,'div7')
}