var isRightValidateCode=-1;
var rightMobile=false;
var rightEmail=false;

var noCard=false;
var card=false;

/****************
 *
 *定义所有的产品
 *
***************/ 
var allProduct;
var allProductCount;
	allProduct = new Array();
	allProductCount=49;
	//pid,name,info,discount,price,readyonly
	allProduct[0]= new Array("000024","300元大众健身季卡套餐","<b>300元</b> 定额，享受健身 <b>每次10元</b> 服务","","300","true");	
	allProduct[1]= new Array("000060","滑雪温泉金卡","<b>滑雪温泉享受超值金卡折扣</b>","","680","true");	
	allProduct[2]= new Array("000073","2680元尊贵健身年卡套餐(限武汉)","<b>促销价1999元</b> 享受 <b>一年135次</b> 高端健身","","1999","true");
	allProduct[3]= new Array("000053","798元健身金卡套餐","<b>1年健身金卡折扣</b>","","798","true");
	allProduct[4]= new Array("000044","999元时尚瑜伽卡套餐","<b>1年享受瑜伽金卡折扣</b>","","999","true");
	allProduct[5]= new Array("000045","2300元尊贵瑜伽卡(限北京)","<b>原价2300元，促销价1999元，有效期一年，尽情享受100次瑜伽健身</b>","","1999","true");
	allProduct[6]= new Array("000046","280元大众游泳卡套餐(限北京、武汉)","<b>1年享受游泳银卡折扣</b>","","280","true");
	allProduct[7]= new Array("000047","400元时尚游泳卡套餐(限北京、武汉)","<b>两个月享受游泳40次</b>","","400","true");
	allProduct[8]= new Array("000038","2680元尊贵健身年卡套餐","<b>2680元</b> 享受 <b>一年135次</b> 高端健身","","2680","true");
	allProduct[9]= new Array("000040","300元洗衣银卡套餐","<b>300元</b>，所有洗衣 <b>6折起</b>","","300","true");
	allProduct[10]= new Array("000041","500元洗衣金卡套餐（限上海、武汉）","<b>500元</b>，所有洗衣 <b>5.5折起</b>","","500","true");	
	allProduct[11]= new Array("000058","888元大众足疗洗浴卡套餐（限北京）","<b>888元</b>，所有足疗洗浴 <b>银卡折扣</b>","","888","true");	
	allProduct[12]= new Array("000059","3888元尊贵足疗洗浴卡套餐（限北京）","<b>3888元</b> 所有足疗洗浴 <b>VIP折扣</b>","","3888","true");	
	allProduct[13]= new Array("000028","999元i美金卡套餐(限上海、武汉)","<b>999元</b> 定额，享受美容美发 <b>金卡折扣</b> 服务","","999","true");
	allProduct[14]= new Array("000056","880元秋冬美白护肤卡(限北京)","<b>880元</b> 享受10次超值美白护理服务","","880","true");
	allProduct[15]= new Array("000027","1999元i美VIP卡套餐（限上海、武汉）","<b>1999元</b> 定额，享受美容美发 <b>VIP折扣</b> 服务","","1999","true");
	allProduct[16]= new Array("000030","2999元望京一卡通(限北京)","<b>2999元</b> 望京地区一卡通用","","2999","true");
	allProduct[17]= new Array("000036","1000元美发金卡(限北京)","<b>1000元</b> 美发4折起","","1000","true");
	allProduct[18]= new Array("000037","2000元美发VIP卡(限北京)","<b>2000元</b> 美发3.8折起","","2000","true");
	allProduct[19]= new Array("000042","2680元车友金卡(限北京)","<b>2680元</b> 车友金卡，享受雅酷所有项目金卡折扣。","","2680","true");
	allProduct[20]= new Array("000043","5000元车友VIP卡(限北京)","<b>5000元</b> 车友VIP卡，享受雅酷所有项目VIP折扣。","","5000","true");
	allProduct[21]= new Array("000010","自由充套餐","1元起充,您将实际获得 <b>雅酷自由充</b> 折扣。","(可修改)","1","false");
	allProduct[22]= new Array("000011","银卡套餐","您将实际获得 <b>雅酷银卡</b> 折扣。","(可修改)","1000","false");
	allProduct[23]= new Array("000012","金卡套餐","您将实际获得 <b>雅酷金卡</b> 折扣。","(可修改)","3000","false");
	allProduct[24]= new Array("000013","VIP套餐","您将实际获得 <b>雅酷VIP</b> 折扣。","(可修改)","5000","false");	
	allProduct[25]= new Array("000062","210元大众健身自选次卡套餐(限北京)","<b>210元</b> 雅酷大众健身自选次卡，可自选三家店消费","","210","true");
	allProduct[26]= new Array("000063","280元大众健身自选季卡套餐(限北京)","<b>280元</b> 雅酷大众健身自选季卡，可自选三家店消费","","280","true");	
	allProduct[27]= new Array("000067","360元白领健身自选次卡套餐(限武汉)","<b>360元</b> 雅酷白领健身自选次卡，可自选三家店消费","","360","true");
	allProduct[28]= new Array("000068","650元白领健身自选季卡套餐(限武汉)","<b>促销价558元</b> 雅酷白领健身自选季卡，可自选三家店消费","","558","true");
	allProduct[29]= new Array("000070","1380元白领健身自选年卡套餐(限武汉)","<b>1380元</b> 雅酷白领健身自选年卡，可自选三家店消费","","980","true");
	allProduct[30]= new Array("000072","380元电影VIP卡套餐(限北京)","<b>电影消费4折起</b>","","380","true");	
	allProduct[31]= new Array("000076","1980元豪华健身年卡套餐","最多消费100次/1年","","1980","true");
	allProduct[32]= new Array("000077","600元家庭健身季卡套餐","最多消费60次/3个月","","600","true");	
	allProduct[33]= new Array("000064","360元豪华健身自选次卡套餐","<b>360元</b> 雅酷豪华健身自选次卡，单店消费","","360","true");
	allProduct[34]= new Array("000065","雅酷豪华健身自选季卡","<b>458元</b> 雅酷豪华健身自选季卡，单店消费","","458","true");
	allProduct[35]= new Array("000032","988元大众健身卡套餐","一年有效，每天可消费一次。 雅酷品牌健身商户通用","","988","true");
	allProduct[36]= new Array("200000","雅酷通用卡","100元起充，100元的整倍数","(可修改)","100","false");
	allProduct[37]= new Array("000090","680元电影VIP卡套餐(限北京)","<b>电影消费4折起</b>","","680","true");
	allProduct[38]= new Array("000088","288元8次电影套餐(限北京)","<b>按人次扣费,36元/场/人</b>","","288","true");
	allProduct[39]= new Array("000081","100元英派斯体验月卡套餐","<b>单店消费，可消费10次</b>","","100","true");
	allProduct[40]= new Array("000082","40元新浪乐居特惠影票","一年有效，每天可消费一次。 雅酷品牌健身商户通用","","40","true");
	allProduct[41]= new Array("000083","850元白领健身自选半年卡套餐(限武汉)","<b>850元</b> 雅酷白领健身自选半年卡，可自选三家店消费","","700","true");
	allProduct[42]= new Array("000084","1380尊贵健身半年卡套餐","","","1380","true");
	allProduct[43]= new Array("000085","788时尚健身年卡套餐","","","788","true");
	allProduct[44]= new Array("000086","1280豪华健身卡套餐","","","1280","true");
	allProduct[45]= new Array("000089","500元42次电影套餐(限北京)","<b>根据影院及场次不同，1-5次/场次</b>","","500","true");
	allProduct[46]= new Array("000094","380元健身电影通卡套餐","","","380","true");
	allProduct[47]= new Array("000096","160元16次非常惠电影套餐","","","160","true");
	allProduct[48]= new Array("000098","4000元团购健身卡套餐","","","4000","true");


	function getProductName(productValue){
	for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==productValue){
			return allProduct[i][1];
		}
	}
	return "";
}

function getProductInfo(productValue){
	for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==productValue){
			return allProduct[i][2];
		}
	}
	return "";
}

function mySubmit(){  
  if(formCheck()){
        var validatecode=trimPrefix(document.purchaseForm.validateCode.value," ");
	if(validatecode.length==0){
	alert("请输入验证码！");
	return false;
	}
	//提交逻辑在验证码验证成功后
	validateValidateCode(validatecode);
	document.purchaseForm.submit();
  }
}

function mySubmit1(){  
  if(formCheck1()){
  	document.purchaseForm.submit();
	}
}

function ljSubmit(){  if(ljCheck()){
        var validatecode=trimPrefix(document.purchaseForm.validateCode.value," ");
	if(validatecode.length==0){
	alert("请输入验证码！");
	return false;
	}
	//提交逻辑在验证码验证成功后
	validateValidateCode(validatecode);
	
  }

  }

function ljCheck(){  
        if(document.purchaseForm.name.value==''){
          alert("请输入您的真实姓名！");
          return false;
          }

	var phonenumber=trimPrefix(document.purchaseForm.phoneNumber.value," ");	
	if(phonenumber==''){
		alert("请输入您的手机号码！");
		return false;
	}
	if(isNaN(parseInt(phonenumber))){
		alert("手机号码应该都是数字！");
		return false;
	}		
	if(document.purchaseForm.phoneNumber.value.length<11){
		alert("不正确的手机号码长度！");
		return false;
	}
	var email=trimPrefix(document.purchaseForm.email.value," ");
	
	if(email.length==0){
		alert("请输入邮箱地址！");
		return false;
	}
	if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email)){
		alert("请输入正确的邮箱地址！");
		return false;
	}
	if(document.purchaseForm.amount.value==''){
          alert("请输入您的购买张数！");
          return false;
        }
        if(isNaN(parseInt(document.purchaseForm.amount.value))){
		alert("购买张数应该是数字！");
		return false;
	}
	if((parseInt(document.purchaseForm.amount.value))>6){
	         alert("购买张数不能多于6张!");
	         return false;
	}		
	return true;
}

function formCheck1(){
    if(card==true){
    if(document.getElementById("card_id").value==''){
			alert("请输入您的卡号！");
			return false;
		}
		if(document.purchaseForm.card_id.value.length!=12){
			alert("卡号应为12位数字！");
			return false;
		}
      }
     if(document.purchaseForm.nickname.value==''){
          alert("请输入您的用户名！");
          return false;
          }
    if(document.purchaseForm.password.value==''){
          alert("请输入您的密码！"); 
          return false;
          }
    if(document.purchaseForm.password_confirm.value==''){
          alert("请再次输入您的密码！");     
          return false;
          }
    if(document.purchaseForm.password.value!=document.purchaseForm.password_confirm.value){
          alert("请确认两次密码输入一致！");       
          return false;
          }
         
   /*
     if(document.purchaseForm.name.value==''){
          alert("请输入您的真实姓名！");     
          return false;
          }         
	var phonenumber=trimPrefix(document.purchaseForm.phoneNumber.value," ");	
	if(phonenumber==''){
		alert("请输入您的手机号码！");
		return false;
	}
	if(isNaN(parseInt(phonenumber))){
		alert("手机号码应该都是数字！");
		return false;
	}		
	if(document.purchaseForm.phoneNumber.value.length<11){
		alert("不正确的手机号码长度！");
		return false;
	}
	//验证手机号码的唯一性
	if(noCard.checked==true&&rightMobile==false){
		validateMobile(phonenumber);
		if(!rightMobile)
			return false;
	}
*/
	var email=trimPrefix(document.purchaseForm.email.value," ");
	
	if(email.length==0){
		alert("请输入邮箱地址！");
		return false;
	}
	if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email)){
		alert("请输入正确的邮箱地址！");
		return false;
	}
	//验证邮箱的唯一性
	if(noCard.checked==true&&rightEmail==false){
		validateEmail(email);
		if(!rightEmail)
			return false;
	}
/*
	var district=document.purchaseForm.district.value;
		if(district=="all"){
			alert("请您选择自己所在的区县！");
			return false;
		}		
	if(document.purchaseForm.mailAddress.value==''){
	       alert("请输入您的地址！");	
	       return false;
	    }
*/
	//if(document.purchaseForm.postCode.value==''){
	      //alert("请输入您的邮政编码！");
	      //return false;
	      //}       
	if(!document.purchaseForm.agree.checked){
		alert("请选择是否同意雅酷时空用户守则！");
		return false;
	}		
	return true;
}

function reset(){    
  document.purchaseForm.reset();
}

function showCharNum(){
	tt.innerHTML = document.purchaseForm.card_id.value.length;
	pwd.style.display="none";
	error_card.innerHTML="";
}

function trimPrefix(str,prefix)
{
	var tmpstr = str;
	var len = prefix.length;
	
	while(tmpstr.substring(0,len) == prefix)

	{
		tmpstr = tmpstr.substr(len);		
	}
	return tmpstr;
}

function formCheck(){
	if(noCard==true){
		var district=document.purchaseForm.district.value;
		if(district=="all"){
			alert("请您选择自己所在的区县");
			return false;
		}		
	}
	else{
		if(document.purchaseForm.card_id.value==''){
			alert("请输入您的卡号！");
			return false;
		}
		if(document.purchaseForm.card_id.value.length!=12){
			alert("卡号应为12位数字！");
			return false;
		}
	}
		
	var phonenumber=trimPrefix(document.purchaseForm.phoneNumber.value," ");	
	if(phonenumber==''){
		alert("请输入您的手机号码！");
		return false;
	}
	if(isNaN(parseInt(phonenumber))){
		alert("手机号码应该都是数字！");
		return false;
	}		
	if(document.purchaseForm.phoneNumber.value.length<11){
		alert("不正确的手机号码长度！");
		return false;
	}
	//验证手机号码的唯一性
	if(noCard.checked==true&&rightMobile==false){
		validateMobile(phonenumber);
		if(!rightMobile)
			return false;
	}
	
	var email=trimPrefix(document.purchaseForm.email.value," ");
	
	if(email.length==0){
		alert("请输入e-mail地址！");
		return false;
	}
	if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email)){
		alert("请输入正确的e-mail地址！");
		return false;
	}
	//验证邮箱的唯一性
	if(noCard.checked==true&&rightEmail==false){
		validateEmail(email);
		if(!rightEmail)
			return false;
	}
	if(document.purchaseForm.paynum.value==''){
		alert("请输入您的充值金额！");
		return false;
	}			
	if(isNaN(document.purchaseForm.paynum.value)){
		alert("您输入了错误的金额数，请重新输入！");
		return false;
	}		
	if(document.purchaseForm.paynum.value<1){
		alert("您的充值金额不能小余1￥！");
		return false;
	}	
	if(document.purchaseForm.paynum.value.indexOf(".")!=-1){
		alert("您只能输入不得小于1元的整数金额！");
		return false;
	}	
	//谢超添加。判断产品金额是否正确
	//var pid=document.purchaseForm.product.options[document.purchaseForm.product.selectedIndex].value;
	var pid=document.purchaseForm.product.value;
		
	var val=document.purchaseForm.paynum.value;
	if(pid=="000011")
	{
		if(val < 1000 || val >= 3000)
		{
			alert("银卡充值金额需在1000元~3000元之间。请重新输入！");
			return false;
		}
	}
	else if(pid=="000010")
	{
		if(val >= 1000)
		{
			alert("自由充充值金额需在1元~1000元之间。请重新输入！");
			return false;
		}
	}
	else if(pid=="000012")
	{
		if(val < 3000 || val >= 5000)
		{
			alert("金卡充值金额需在3000元~5000元之间。请重新输入！");
			return false;
		}
	}
	else if(pid=="000013")
	{
		if(val < 5000)
		{
			alert("VIP充值金额需在5000元以上。请重新输入！");
			return false;
		}
	}
	else if(pid=="000062"||pid=="000063"||pid=="000067"||pid=="000068"||pid=="000070"||pid=="000083"){
		var providerId =document.purchaseForm.providerId.value;
		if(providerId ==""){
			alert("请为单店卡选择商户！");
			return false;
		}
	}	
	
	return true;
}
function showdiscount(){
	var payNum=document.purchaseForm.paynum.value;
	var pid=document.purchaseForm.product.value;
	if(pid==""||pid=="000010"||pid=="000011"||pid=="000012"||pid=="000013"){
		if(payNum<1000&&payNum>=1){
			pid="000010";
			document.purchaseForm.product.value="000010";
		}
		else if(payNum<3000&&payNum>=1000){
			pid="000011";
			document.purchaseForm.product.value="000011";
		}
		else if(payNum<5000&&payNum>=3000){
			pid="000012";
			document.purchaseForm.product.value="000012";
		}
		else if(payNum>=5000){
			pid="000013";
			document.purchaseForm.product.value="000013";
		}else{
			pid="";
		}
	}
	if(pid==""){
		document.purchaseForm.productName.value = "";
		productInfo.innerHTML="";
		discountInfo.innerHTML="";
		return;
	}
	for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==pid){	
			document.purchaseForm.productName.value = allProduct[i][1];
			productInfo.innerHTML=allProduct[i][2];
			discountInfo.innerHTML=allProduct[i][3];
			break;
		}
	}
}
function showReg(){
document.getElementById("table1").style.display="";
document.getElementById("table2").style.display="none";
document.getElementById("card").style.display="none";
card=false;
document.getElementById("change1").innerHTML="<li class='none'><font onmouseover='showReg()'>未注册用户快速购买</font></li>";
document.getElementById("change2").innerHTML="<li><font onmouseover='showLogin()'>已注册用户</font></li>";
document.getElementById("change3").innerHTML="<li><font onmouseover='showActive()'>未激活雅酷卡用户</font></li>";
}

function showLogin(){
document.getElementById("table1").style.display="none";
document.getElementById("table2").style.display="";
document.getElementById("change1").innerHTML="<li><font onmouseover='showReg()'>未注册用户快速购买</font></li>";
document.getElementById("change2").innerHTML="<li class='none'><font onmouseover='showLogin()'>已注册用户</font></li>";
document.getElementById("change3").innerHTML="<li><font onmouseover='showActive()'>未激活雅酷卡用户</font></li>";
}

function showActive(){
document.getElementById("table1").style.display="";
document.getElementById("table2").style.display="none";
document.getElementById("card").style.display="";
card=true;
document.getElementById("change1").innerHTML="<li><font onmouseover='showReg()'>未注册用户快速购买</font></li>";
document.getElementById("change2").innerHTML="<li><font onmouseover='showLogin()'>已注册用户</font></li>";
document.getElementById("change3").innerHTML="<li class='none'><font onmouseover='showActive()'>未激活雅酷卡用户</font></li>";
}

function showdiscount1(){
	var payNum=document.purchaseForm2.paynum2.value;
	var amount=document.purchaseForm2.amount.value;
    total.innerHTML=payNum*amount;
    document.purchaseForm2.paynum.value=payNum*amount;
	var pid=document.purchaseForm2.product.value;
	if(pid==""||pid=="000010"||pid=="000011"||pid=="000012"||pid=="000013"){
		if(payNum<1000&&payNum>=1){
			pid="000010";
		}
		else if(payNum<3000&&payNum>=1000){
			pid="000011";
		}
		else if(payNum<5000&&payNum>=3000){
			pid="000012";
		}
		else if(payNum>=5000){
			pid="000013";
		}else{
			pid="";
		}
	}
	if(pid==""){
		productName2.innerHTML="";
		return;
	}
	for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==pid){	
			productName2.innerHTML = allProduct[i][1];
			break;
		}
	}
}
function calculatediscount(){
	var amount=document.purchaseForm2.amount.value;
	var num=document.purchaseForm2.paynum2.value;
	var payNum=amount*num;
	document.purchaseForm2.paynum.value=payNum;
	//document.purchaseForm2.paynum2.value=payNum;
	total.innerHTML=payNum;
}
function initProduct(){
	changeProduct();
}
function initProduct1(){
var pid=document.purchaseForm2.product.value;
for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==pid){
		    document.purchaseForm2.productName.value=allProduct[i][1];
		    document.getElementById("productName2").innerHTML = allProduct[i][1];
		    break;
		}
	}
}
function initProduct2(){
var pid=document.purchaseForm.product.value;
for(var i=0;i<allProductCount;i++){
		if(allProduct[i][0]==pid){	
			document.getElementById("productName2").innerHTML = allProduct[i][1];
			break;
		}
	}
}
//修改购买产品进行相应描述信息的更新和修改
function changeProduct(){
	var pid=document.purchaseForm.product.value;
	var productName = getProductName(pid);
	var productInfo = getProductInfo(pid);
	document.purchaseForm.productName.value=productName;
	if(document.getElementById("productInfo")){
	document.getElementById("productInfo").innerHTML=productInfo;}
	var oProvider = document.getElementById("divProvider");
	oProvider.style.display = "none";
	if(pid=="000062"||pid=="000063"||pid=="000064"||pid=="000065"||pid=="000067"||pid=="000068"||pid=="000070"||pid=="000083"){
		oProvider.style.display = "";	
		var oProviderName =document.getElementById("providerName");
		oProviderName.readOnly="true"; 
	}
	for(var i=0;i<allProductCount;i++){
			if(allProduct[i][0]==pid){	
			//productInfo.innerHTML=allProduct[i][2];
			document.purchaseForm.paynum.value=allProduct[i][4];
			if(allProduct[i][5]=="true"){
				document.purchaseForm.paynum.readOnly="true";
			}else{
				document.purchaseForm.paynum.readOnly="true";
				document.purchaseForm.paynum.readOnly=!document.purchaseForm.paynum.readOnly;
			}
			document.purchaseForm.productName.value = allProduct[i][1];
			break;
		}
	}
        var productName1 =document.getElementById("productName1");
        if(productName1){
	productName1.innerHTML=productName;}
	if(document.getElementById("providertr")){
		document.getElementById("providertr").style.display="none";
	}
	document.purchaseForm.providerId.value="";
	var oProviderName1 =document.getElementById("providerName");
	oProviderName1.value="";	
	}

function login(){
	var inputId=document.purchaseForm.card_id.value;
	var validateId=document.purchaseForm.hidden_card_id.value;
	if(inputId==''){
		alert("请输入您的卡号！");
		return;
	}
	if(inputId.length!=12){
		alert("卡号应为12位数字！");
		return;
	}
	if(validateId==inputId){
		//直接加载
		document.purchaseForm.name.value=document.purchaseForm.hidden_name.value;
		document.purchaseForm.phoneNumber.value=document.purchaseForm.hidden_phoneNumber.value;
		document.purchaseForm.email.value=document.purchaseForm.hidden_email.value;
	}
	else{
		//显示密码框
		var pwdTable=document.getElementById("pwd");
		pwdTable.style.display="";
	}
}

function loadMyInfo(){
	var inputId=document.purchaseForm.card_id.value;
	if(inputId==''){
		alert("请输入您的卡号！");
		return false;
	}
	if(inputId.length!=12){
		alert("卡号应为12位数字！");
		return false;
	}
	document.purchaseForm.step.value="loginInfo";
	document.purchaseForm.submit();
}

function ifvalidate(){
	if(event.keyCode==13){
		loadMyInfo();
	}
}
function ifsubmit(){
	if(event.keyCode==13){
		submit();
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//判断持卡人的卡类型：yacol卡，kaixuan卡，cheyou卡....
var pur_req;
function getCardType(){
	var cardId=document.getElementById("card_id").value;
	if(cardId==null||trimPrefix(cardId," ").length!=0){
		var url="./purchase.do?validateCardId="+cardId;
		if (window.XMLHttpRequest) { // Non-IE browsers
			pur_req = new XMLHttpRequest();		
			try {			
				pur_req.open("GET", url, true);				
				pur_req.onreadystatechange =function(){reg_processStateChange(validatorType)};
				pur_req.send();
			} catch (e) {
				alert(e);
			}
			//pur_req.onreadystatechange = reg_processStateChange;
			//pur_req.send(null);
		} else if (window.ActiveXObject) { // IE
			pur_req = new ActiveXObject("Microsoft.XMLHTTP");
			if (pur_req) {						
				pur_req.open("GET", url, true);
				pur_req.onreadystatechange =function(){pur_processReturn()};
				pur_req.send();
			}
		}
	}
}

function pur_processReturn(){
	var reg_returnText;
	if (pur_req.readyState == 4) { // Complete
		if (pur_req.status == 200) {	                		
        		var blsuccess=pur_req.responseXML.getElementsByTagName("blSuccess")[0];						                		            			                			                		
        		if(blsuccess.childNodes[0].nodeValue!="true"){
        			var errorinfo = pur_req.responseXML.getElementsByTagName("procInfo")[0].childNodes[0].nodeValue;
        			alert(errorinfo);        			                     
        		} 
        		else{	 	                			        			
        			var cardType = pur_req.responseXML.getElementsByTagName("cardType")[0].childNodes[0].nodeValue;
        			document.purchaseForm.cardType.value=cardType;
        		}                                               
        }
	}
}

//非法字符
var laylessStr=new Array("\u96c5\u9177","yacol","yaku","ya\u9177","\u96c5ku");

function validateNickName(nickName){
	var name=trimPrefix(nickName," ");
	var pattern=/^[a-zA-Z0-9_-\u4e00-\u9fa5]+$/;
	if(name.length>0){
	chkFlag = pattern.test(name);
	if(!chkFlag){
	document.getElementById("us").innerHTML="<font color='8e0047'>昵称中有非法字符</font>";
   // document.purchaseForm.nickname.focus();
    return false;
	}else{
	document.getElementById("us").innerHTML="";
	}
	}
	var	_name=name.replace(/\s*/g,"");
    _name=_name.toLowerCase();
    for(var i=0;i<laylessStr.length;i++){
    	if(_name.indexOf(laylessStr[i])!=-1){
    		alert("你输入了非法字符");
    		return false;
    	}
    }
	if(name.length==0){		
		rightNickName=false;	
		return false;
	}	
	reg_requestUrl="./register.do?validateNickName="+name;	
	reg_retrieveURL(reg_requestUrl,"1");
}

//检验邮箱
function validateEmail(Email){		
	var email=trimPrefix(Email," ");
		if(email.length==0){						
			rightEmail=false;
			return false;
		}
	var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    chkFlag = pattern.test(email);
    if(!chkFlag){
	document.getElementById("ema").innerHTML="<font color='8e0047'>邮箱格式不正确</font>";
  //  document.purchaseForm.email.focus();
    return false;
	}else{
	document.getElementById("ema").innerHTML="";
	}	
	reg_requestUrl="./purchase.do?validateEmail="+email;	
	reg_retrieveURL(reg_requestUrl,"2");
}

//检验密码
function validatePassword(password,flag){
		if(password!=null&&password!=""){
		if(password.length<4){
		if(flag==0){
		document.getElementById("pw0").innerHTML="<font color='8e0047'>密码不能小于4位</font>";						
		document.purchaseForm.password.value="";
		document.purchaseForm.password.focus();
		return false;
		}else if(flag==1){
		document.getElementById("pw1").innerHTML="<font color='8e0047'>密码不能小于4位</font>";
		document.purchaseForm.password_confirm.value="";
		document.purchaseForm.password_confirm.focus();
		return false;
	    }
	    }else if(password.length>16){
	    if(flag==0){
		document.getElementById("pw0").innerHTML="<font color='8e0047'>密码不能大于16位</font>";						
		document.purchaseForm.password.value="";
		document.purchaseForm.password.focus();
		return false;
		}else if(flag==1){
		document.getElementById("pw1").innerHTML="<font color='8e0047'>密码不能大于16位</font>";
		document.purchaseForm.password_confirm.value="";
		document.purchaseForm.password_confirm.focus();
		return false;
	    }
	  }else {
	    if(flag==0){
		document.getElementById("pw0").innerHTML="";						
		return false;
		}else if(flag==1){
		document.getElementById("pw1").innerHTML="";
		return false;
	    }
	  }
    }
}

//检验验证码

function validateValidateCode(validateCode){

	var code=trimPrefix(validateCode," ");
	if(code.length==0){	
		rightValidateCode=false;		
		return false;
	}
	var pur_requestUrl;		
	pur_requestUrl="./purchase.do?validateValidateCode="+code;	
	reg_retrieveURL(pur_requestUrl,"4");
}

function reg_retrieveURL(url,validateType) {

	if (window.XMLHttpRequest) { // Non-IE browsers
		pur_req = new XMLHttpRequest();		
		try {			
			pur_req.open("GET", url, true);
			pur_req.onreadystatechange =function(){reg_processStateChange(validateType)};
			pur_req.send(null);
		} catch (e) {
			alert(e);
		}
	} else if (window.ActiveXObject) { // IE
		pur_req = new ActiveXObject("Microsoft.XMLHTTP");
		if (pur_req) {			
			pur_req.open("GET", url, true);
			pur_req.onreadystatechange =function(){reg_processStateChange(validateType)};
			pur_req.send();
		}
	}
	
}

function reg_processStateChange(validateType) {
	var reg_returnText;
	if (pur_req.readyState == 4) { // Complete
		if (pur_req.status == 200) { // OK response			
			reg_returnText = pur_req.responseText;					
			if(reg_returnText.indexOf("false")!=-1){
				if(validateType=="1"){
					document.getElementById("us").innerHTML="<font color='8e0047'>昵称已被注册</font>";					
					//document.getElementById("nickname").focus();						
					//isRightValidateCode=0;
				}else if(validateType=="4"){
				        alert("验证码输入错误！");
				        return false;
                    }else if(validateType=="3"){
					rightMobile=false;
					document.getElementById("pcode").innerHTML="<font color='8e0047'>手机号码已被注册</font>";								
					//document.getElementById("phoneNumber").focus();
				}else if(validateType=="2"){
					rightEmail=false;					
					document.getElementById("ema").innerHTML="<font color='8e0047'>邮箱已被注册</font>";					
					//alert("你输入的邮箱已经被注册，请重新输入。");	
					//document.getElementById("email").focus();											
				}				
			}
			else if(reg_returnText.indexOf("true")!=-1){
				if(validateType=="1"){
				  //  rightNickName=true;
					document.getElementById("us").innerHTML="<font color='8e0047'>昵称有效</font>";	
					
				//selectProduct();
				//if(newWindow==null||newWindow.closed){
   			//newWindow=window.open("purchase/tanchuchanp_bj.jsp");
   			//testWindowIsClose();
   		//}else{
   			//newWindow.focus();
   		//}
   		           //  popup_show();
					//window.open("purchase/chanp_4.jsp","确认信息","width=325px,height=205px,resizable=no,scrollbars=no");
				}
				else if(validateType=="3"){
					rightMobile=true;
					var pattern = /^[0-9]*$/g; 
					if(!pattern.test(document.purchaseForm.phoneNumber.value)) {
		           document.getElementById("pcode").innerHTML="<font color='8e0047'>手机号码应该都是数字</font>";				
	             	return false;
                	}	
            	    if(document.purchaseForm.phoneNumber.value.length<11){
		            document.getElementById("pcode").innerHTML="<font color='8e0047'>不正确的手机号码长度</font>";			
	            	return false;
	               }
					document.getElementById("pcode").innerHTML="<font color='8e0047'>手机号码有效</font>";								
				   }
				else if(validateType=="2"){					
					rightEmail=true;
					document.getElementById("ema").innerHTML="<font color='8e0047'>邮箱有效</font>";											
				}
				else if(validateType=="4"){					
					document.purchaseForm.submit();
											
				}

			}
			else if(reg_returnText.indexOf("error")!=-1){						
				isRightValidateCode=false;
				alert("检查验证码时发生错误！");				
			}
		} else {
			alert("检查验证码时发生错误: " + pur_req.statusText);
			isRightValidateCode=0;
		}
	}
}

function showRegInfo(){	
    document.getElementById("change1").innerHTML="<li ><font onmouseover=this.style.cursor='hand' onclick='showOrderInfo()'>持卡用户</font></li>";
    document.getElementById("change2").innerHTML="<li id='voucher_sort_s1'><font onmouseover=this.style.cursor='hand' onclick='showRegInfo()'>无卡用户</font></li>";
	document.getElementById("reginfo").style.display="";				
	document.getElementById("sex").style.display="";
	document.getElementById("address").style.display="";
	document.getElementById("card").style.display="none";
	document.getElementById("pwd").style.display="none";	
	var purchaseForm = document.purchaseForm;
	purchaseForm.card_id.value="";
	purchaseForm.name.value="";
	purchaseForm.phoneNumber.value="";
	purchaseForm.email.value="";
	purchaseForm.hidden_phoneNumber.value="";
	purchaseForm.name.value="";
	purchaseForm.hidden_name.value="";
	purchaseForm.hidden_card_id.value="";
	purchaseForm.password.value="";
	noCard=true;
}

//function showOrderInfo(){
	//document.getElementById("sex").style.display="none";
	//document.getElementById("address").style.display="none";
	//document.getElementById("card").style.display="";
	//document.getElementById("reginfo").style.display="none";
	//noCard=false;
	//window.location.reload();
//}

function showOrderInfo(){
document.getElementById("change1").innerHTML="<li id='voucher_sort_s1'><font onmouseover=this.style.cursor='hand' onclick='showOrderInfo()'>持卡用户</font></li>";
document.getElementById("change2").innerHTML="<li ><font onmouseover=this.style.cursor='hand' onclick='showRegInfo()'>无卡用户</font></li>";
document.getElementById("sex").style.display="none";
document.getElementById("address").style.display="none";
document.getElementById("card").style.display="";
document.getElementById("reginfo").style.display="none";
noCard=false;
}

function changeProvince(locationid)
{
	document.purchaseForm.city.length = 0;
	document.purchaseForm.district.length = 0;
	document.purchaseForm.district.options.add(new Option("请选择","all"));
	var locationid=locationid;
	var i;

	document.purchaseForm.city.options[0] = new Option('请选择','all');
	for (i=0;i <cityCount; i++)
	{
		if (city[i][2] == locationid)
		{
			document.purchaseForm.city.options[document.purchaseForm.city.length]=new Option(city[i][0], city[i][1]);
		}
	}
}
	/*********************************************
	 *
	 * 改变城市的时候动态的改变区县
	 * 从数据库动态的获得
	 *
	 ********************************************/
	 
	function changeCity(locationid){
		if(locationid=="all"){
			document.purchaseForm.district.length=0;
			document.purchaseForm.district.options.add(new Option("请选择","all"));
		}else{
			initDistrict(document.cityActionForm.classId.value, locationid);
		}
	}

	function initDistrict(classId,cityCode){
		query_requestUrl="./getArea.do?classID="+classId+"&cityCode="+cityCode;
		query_sel=document.getElementById("district");
		query_retrieveURL(query_requestUrl);
	}


function changeProvince_cc(locationid)
{
	document.purchaseForm.city_cc.length = 0;	
	var locationid=locationid;
	var i;
	for (i=0;i <cityCount; i++)
	{
		if (city[i][2] == locationid)
		{
			document.purchaseForm.city_cc.options[document.purchaseForm.city_cc.length]=new Option(city[i][0], city[i][1]);
		}
	}
}

//检验邮箱
function validateEmail(Email){		
	var email=trimPrefix(Email," ");
		if(email.length==0){						
			rightEmail=false;
			return false;
		}
		
	reg_requestUrl="./purchase.do?validateEmail="+email;	
	reg_retrieveURL(reg_requestUrl,"2");
}

//检验手机号
function validateMobile(mobile){

	var myMobile=trimPrefix(mobile," ");
	if(myMobile.length==0){			
		rightMobile=false;	
		return false;
	}	
	reg_requestUrl="./purchase.do?validateMobile="+myMobile;	
	reg_retrieveURL(reg_requestUrl,"3");
}

function checkMobile(mobile){
	if(trimPrefix(mobile," ").length==0)
		return true;
	
	if(noCard==true){
		return validateMobile(mobile);
	}
}
function checkEmail(email){
	if(trimPrefix(email," ").length==0)
		return true;
	
	if(noCard==true){
		return validateEmail(email);
	}
}

/**
   * 加载单店卡可消费商户列表
   */
  function toLoadProviders(){
        var productId;
  	//var productId=document.purchaseForm.product.options[document.purchaseForm.product.selectedIndex].value;
  	if(document.purchaseForm){
  	productId=document.purchaseForm.product.value;
  	}else if(document.purchaseForm2){
  	productId=document.purchaseForm2.product.value;
  	}
  	var planId= null;
  	if(productId=="000062" || productId=="000063"){
  		planId = "106";
  	}
  	else if(productId=="000064" || productId=="000065"){
  		planId = "107";
  	}
  	else if(productId=="000067" || productId=="000068"){
  		planId = "109";
  	}
  	else if(productId=="000070"){
  		planId = "110";
  	}
  	else if(productId=="000083"){
  		planId = "110";
  	}

  	if(planId != null){
	  	var url="./loadProductProvider.do?plan="+planId;
	  	window.open(url,'dlgProvider',"modal=yes,width=800px,height=600px");
  	}
  	else{
  		alert("非单店卡，无须选择商户！");
  	}
  }
 
    /**
   * 关闭产品可消费商户窗口
   */
  function closeProviderWin(owindow){
  	owindow.returnValue = null;
  	owindow.close();
  }
  
  function getProviderInfo(){
  	if(!validitcheck())
  		return;
  	var aProviders = document.getElementsByName("providerId");
  	var aNames = document.getElementsByName("providerName");
  	var index = 0;
  	var providerId="";
  	var oName="";
  	var num=0;
  	for(var i=0;i<aProviders.length;i++){
  		if(aProviders[i].checked){
  			index=i;
  			providerId=providerId+aProviders[index].value+";";
  			oName=oName+aNames[index].value+";";
  			num++;
  		}
  	}  
  	if(num!=3){
  		alert("请您选择3家商户！！");
  		return;
  	}
  	
  	//var providerId = aProviders[index].value;
  	//var oName = document.getElementById("name_"+providerId);
  	//alert(oName.substring(0,oName.length-1)+"-"+providerId.substring(0,providerId.length-1));
  	
  	refreshProviderInfo(providerId.substring(0,providerId.length-1),oName.substring(0,oName.length-1)); 
  	window.close();
  }
  
  function refreshProviderInfo(providerId,providerName){
  var oProviderId;
  if(window.opener.document.purchaseForm&&window.opener.document.purchaseForm.providerId){
    	oProviderId = window.opener.document.purchaseForm.providerId;
  	}else if(window.opener.document.purchaseForm2&&window.opener.document.purchaseForm2.providerId){
  	oProviderId = window.opener.document.purchaseForm2.providerId;
  	}
  var oProviderName = window.opener.document.getElementById("providerName");
  	oProviderId.value=providerId;
  	oProviderName.value = providerName;
  	oProviderName.readOnly ="true";
  	if(oProviderName!=""){
        window.opener.document.getElementById("providertr").style.visibility="visible";
	window.opener.document.getElementById("providertr").style.display="";
  	window.opener.document.getElementById("providerName1").innerHTML=providerName;
  	}
     }
  
  function validitcheck(contextPath){  	
  	var providers = document.getElementsByName("providerId");
  	var iCount = 0;
  	for(var i=0;i<providers.length;i++){
  		if(providers[i].checked){
  			iCount++;
  		}
  	}  	
  	if(iCount == 0){
  		alert("请选择商户！");
  		return false;
  	}
	return true;
  } 
  /*************************
   *
   * 选择产品
   *
   *************************/
   var newWindow=null;
   function selectProduct(){
   		if(newWindow==null||newWindow.closed){
   			newWindow=window.open("/card.jsp");
   			testWindowIsClose();
   		}else{
   			newWindow.focus();
   		}
   }
   /*************************
    *
    * 获得产品
    *
    *************************/
    function getProduct(){
    	window.opener.document.purchaseForm.product.value=getRadioValue(document.productsForm.productradio);
    	window.close();
    }
  	function closeWindow(){
  		window.close();
  	}
  	/************************
  	 *
  	 *获得一个单选框的值
  	 *
  	 ************************/
  	 function getRadioValue(radioObj){
  	 	if(radioObj.value){
  	 		return radioObj.value;
  	 	}
  	 	for(var i=0;i<radioObj.length;i++){
  	 		if(radioObj[i].checked==true){
  	 			return radioObj[i].value;
  	 		}
  	 	}
  	 }
  	 /***************************
  	  *
  	  *过三十秒检测一次查看窗口是否关闭
  	  *
  	  ***************************/
  	  var windowcloseindex;
  	  function testWindowIsClose(){
  	  	windowcloseindex=window.setInterval(changResult,30);
  	  }
  	  /************************
  	   *
  	   *处理函数
  	   *
  	   ************************/
  	   function changResult(){
  	   		if(newWindow.closed){
  	   			window.clearInterval(windowcloseindex);
  	   			changeProduct();
  	   		}
  	   }
  	   
  	    function checkForm(){
  	    var pid=document.purchaseForm2.product.value;
  	    	if(pid=="000062"||pid=="000063"||pid=="000067"||pid=="000068"||pid=="000070"||pid=="000083"){
		var providerId =document.purchaseForm2.providerId.value;
		if(providerId ==""){
			alert("请为单店卡选择商户！");
			return false;
	      }
	    }	
  	   } 	
  	   
  	   function basicCheck(){
  	   	var name=document.purchaseForm.name.value;
		if(name==""){
			alert("请填写您的真实姓名!");
			return false;
		}
		var phoneNumber=document.purchaseForm.phoneNumber.value;
		if(phoneNumber==""){
			alert("请填写您的手机号码,否则雅酷网将无法与您联系!");
			return false;
		}
		if(isNaN(parseInt(trimPrefix(document.purchaseForm.phoneNumber.value," ")))){
		alert("手机号码应该都是数字！");
		return false;
	        }		
	if(document.purchaseForm.phoneNumber.value.length<11){
		alert("不正确的手机号码长度！");
		return false;
	}
	var mailAddress=document.purchaseForm.mailAddress.value;
		if(mailAddress==""){
			alert("请填写您的真实地址!");
			return false;
		}
	
	}
