
function changezm(value){
	gid=document.form1.gamename.value;
	if(gid==1){
		var ln=document.getElementById("servername1").options.length;
		for(i=0;i<ln;i++){
			a=document.getElementById("servername1").options[i].text;
			a=a.substr(0,1);
			if(a==value){
				document.getElementById("servername1").options[i].selected=true;
				changeprice();
				break;
			}
		}
	}
	else if(gid==133){
		var arr=new Array();
		var ln=document.getElementById("servername2").options.length;
		for(i=0;i<ln;i++){
			a=document.getElementById("servername2").options[i].text;
			a=a.substr(0,1);
			if(a==value){
				document.getElementById("servername2").options[i].selected=true;
				changeprice();
				break;
			}
		}	
	}
	finalprice();//调用最终价钱函数
}





function changeprice(){//更改游戏，服务器，数量相应的更改原价
	gid=document.form1.gamename.value;
	servername=document.form1.servername1.value;
	price1=servername.split(":");
	if(document.form1.methodtype[0].checked==true){//如果是即时交易
		price1=price1[2];
		document.getElementById("paimaiid").style.display="none";//隐藏拍卖物品名称输入框
	}
	else{//拍卖交易方式
		price1=price1[1];
		document.getElementById("paimaiid").style.display="";//显示拍卖物品名称输入框
	}
	num1=document.form1.num.value;//取得当前的下单数量
	huilv=document.form1.pay.value;//取得哪种币种
	huilv=huilv.split(":");
	huilv=huilv[1];
	var index1=document.form1.pay.selectedIndex;
	var text=document.form1.pay.options[index1].text;
	document.getElementById("fuhao").value=text;
	text1=text.substr(3,1);
	text2=text.substr(0,3);
	price1=price1/huilv*num1;//计算原价
	price1=price1.toFixed(2);
	if(price1>0){
	document.form1.listedprice.value=price1;//赋值给原价	
	}
	else{
	document.form1.listedprice.value=0;//赋值给原价				
	}
	document.form1.choosejifen.checked=false;//选择积分复位
	document.form1.creaditsprice.value=0;//可用积分为0
	finalprice();//调用下面显示价钱函数
}



//调用数量ajax	
var xmlHttpzz;//声明变量
var requestType="";//声明初始类型为空
function createXMLHttpRequestzz()//定义创建一个跨浏览器函数的开头
{
if(window.ActiveXObject)//ActiveXObject对象到找到的时候返回的是真，否则是假
{
   xmlHttpzz=new ActiveXObject("Microsoft.XMLHTTP");//这个是使用IE的方法创建XmlHttp
	
}
else if(window.XMLHttpRequest)
{
   xmlHttpzz=new XMLHttpRequest();//这个是使用非IE的方法创建XmlHttp
}
}
function aazz(){//判断返回的一个函数，来确定执行那个的函数
if(xmlHttpzz.readyState==4)
{//4说明是执行交互完毕0 (未初始化)1 (正在装载)2 (装载完毕) 3 (交互中)4 (完成)
	if(xmlHttpzz.status==200)
   {//http的一个报头说明成功找到
     showzz();//返回响应的显示
    
   }
}
}

function getOs()   
{   
   var OsObject = "";   
   if(navigator.userAgent.indexOf("MSIE")>0) {   
        return "MSIE";       //IE浏览器
   }
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){   
        return "Firefox";     //Firefox浏览器
   }
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {   
        return "Safari";      //Safan浏览器
   }
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){   
        return "Camino";   //Camino浏览器
   }
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){   
        return "Gecko";    //Gecko浏览器
   }   
   
}
function aa(value){//TOP页的注册和登录ajax函数
	if(value==1){
		email=document.getElementById("zcemail").value;
		password1=document.getElementById("zcpassword1").value;
		password2=document.getElementById("zcpassword2").value;
		phone=document.getElementById("zctelephone").value;
		fullname=document.getElementById("zcfullname").value;
		str="";
		if(fullname==''){
			str+="Fullname is empty!\n";
		}
		if(email==''){
			str+="E-mail is empty!\n";
		}
		else{
			var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
			if(!reg.test(email)){
				str+="E-mail form incorrect!\n";
			}	
		}
		if(password1=='' || password2==''){
			str+="Password is empty!\n";
		}
		else{
			if(password1!=password2){
				str+="Passwords are different!\n";
			}
			else{
				if(password1.length<6){
					str+="Password length must more than 6 characters!\n"
				}
			}
		}
		if(phone==''){
			str+="Phone is empty!\n";
		}
		else{
			if(phone.length<9){
				str+="Phone length must more than 9 characters!\n";
			}
		}
		if(str==''){
			document.getElementById("dlzc").value=1;//使状态改为注册状态
			var fullname=encodeURI(document.getElementById("zcfullname").value);
			var email=encodeURI(document.getElementById("zcemail").value);
			var password1=encodeURI(document.getElementById("zcpassword1").value);
			var telphone=encodeURI(document.getElementById("zctelephone").value);
			var action1=document.getElementById("zcaction").value;	
			createXMLHttpRequestzz();//调用创建XmlHttppp的函数
			var url='/zcajax.php?email='+email+'&password='+password1+'&telphone='+telphone+'&fullname='+fullname+'&action1='+action1+'&me='+Math.random();				
		}
		else{
			alert(str);
			return false;
		}			
	}
	else if(value==2){
			email=document.getElementById("dlemail").value;
			password=document.getElementById("dlpassword").value;
			str="";
			if(email=='' || email=='E-mail'){
				str+="E-mail is empty!\n";
			}
			else{
				var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
				if(!reg.test(email)){
					str+="E-mail  incorrect!\n";
				}	
			}
			if(password=='' || password=='PASSWORD'){
				str+="Password is empty!\n";
			}
			else if(password.length<6){
				str+="Password length is less than 6!\n";
			}
			if(str==''){
				document.getElementById("dlzc").value=2;//使状态改为登录状态
				var email=encodeURI(document.getElementById("dlemail").value);
				var password=encodeURI(document.getElementById("dlpassword").value);
				var action1=document.getElementById("dlaction").value;
				createXMLHttpRequestzz();//调用创建XmlHttppp的函数
				var url='/zcajax.php?email='+email+'&password='+password+'&action1='+action1+'&me='+Math.random();				
			}
			else{
				alert(str);
				return false;
			}
	}
	var btype=getOs();	
	if(btype=='Firefox'){
		xmlHttpzz.open("get",url,false);
	}
	else{
		xmlHttpzz.open("get",url,true);//建立服务器连接，异步传输true
	}
	xmlHttpzz.send(null);//执行程序函数这里的中间的参数是因为GET原因
	if(btype=='Firefox'){
		showzz();//返回响应的显示
	}
	else{
		xmlHttpzz.onreadystatechange=aazz	
	}
}
function showzz(){
	var returntxt=xmlHttpzz.responseText;	
	var type1=document.getElementById("dlzc").value;
	if(type1==1){
		if(returntxt==2){
			alert("E-mail exist!");//邮箱在该网站已存在
			document.getElementById("zcemail").select();
		}
		else if(returntxt==1){
			alert("Register success!");//注册成功
			location.reload();
		}
		else{
			alert("Unknow error!");//未知错误
		}		
	}
	else if(type1==2){
		if(returntxt==1){
			location.reload();//登录成功		
		}
		else if(returntxt==2){			
			alert("Password  false!");
			document.getElementById("dlpassword").select();
		}
		else if(returntxt==3){
			alert("Not exist email");
			document.getElementById("dlemail").select();
		}
		else{
			alert("Unknow error!");
		}
	}

}
//结束调用数量ajax
var ctype=0;//积分和优惠劵的属性默认值
function cjifen(){
	if(document.getElementById("choosejifen").checked==true){
		this.ctype=1;//使用积分调用ajax
		window.setTimeout(ajx, 150);
	}
	else{
		document.getElementById("creaditsprice").value=0;
	}
	finalprice();
}
function cdazhema(){
	dazhema=encodeURI(document.getElementById("dazhema").value);
	this.ctype=2;//使用打折码调用ajax
	if(dazhema!=''){
		document.getElementById("xhao").style.display="none";
		document.getElementById("duihao").style.display="none";
		window.setTimeout(ajx, 150);
	}
	else{
		document.getElementById("xhao").style.display="";
		finalprice();
	}	
}

function ajx(){
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	    http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
	    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	price=document.form1.listedprice.value;//取得现在的价钱
	if(this.ctype==1){
		var url="/priceajax.php?price="+price+"&type1="+this.ctype+"&me="+Math.random();
		http_request.open("GET",url,false);
		http_request.send(null);
		var returntxt=http_request.responseText;	
		document.getElementById("creaditsprice").value=returntxt;
	}
	else if(this.ctype==2){
		dazhema=encodeURI(document.form1.dazhema.value);
		var url="/priceajax.php?dazhema="+dazhema+"&type1="+this.ctype+"&me="+Math.random();
		http_request.open("GET",url,false);
		http_request.send(null);
		var returntxt=http_request.responseText;	
		ab=returntxt.split("|");
		if(ab[0]==1){
			document.form1.codeprice.value=ab[1];
			document.getElementById("xhao").style.display="none";
			document.getElementById("duihao").style.display="";
			document.form1.dazhema.readOnly=true;
		}
		else{
			document.form1.codeprice.value=1;
			document.getElementById("duihao").style.display="none";
			document.getElementById("xhao").style.display="";
			document.form1.dazhema.readOnly=false;
		}
	}
	finalprice();
}

function test(){//检测提交的表单内容是否正确
	gamename=document.form1.gamename.value;
	servername=document.form1.servername1.value;
	fullname=document.form1.fullname.value;
	email=document.form1.email.value;
	telphone=document.form1.telphone.value;
	charctname=document.form1.charctname.value;
	auction=document.form1.auction.value;
	tstype=document.form1.tstype.value;
	if(document.form1.methodtype[0].checked==true){
		methodtype=1;
	}
	else{
		methodtype=2;
	}
	str='';
	if(servername==''){
		str="Please select the server!\n";
	}
	if(fullname==''){
		str+="Full name is empty!\n";
	}
	if(email==''){
		str+="E-mail is empty!\n";
	}
	else{
		var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		if(!reg.test(email)){
			str+="E-mail form incorrect!\n";
		}	
	}
	if(telphone==''){
		str+="Phone is empty!\n";
	}
	else{
		if(telphone.length<9){
			str+="Phone length is less than 9!\n";
		}
	}
	if(charctname==''){
		str+="Character name is empty!\n";
	}
	if(methodtype==2 && auction==''){
		str+="Auction item name is empty!\n";
	}
	if(str!=''){
		alert(str);
		return false;
	}
	else{
		document.forms['form1'].submit();			
	}
}

function finalprice(){
	a11=document.form1.listedprice.value;//原价
	a22=document.form1.memberprice.value;//会员享受折扣
	a33=document.form1.codeprice.value;//打折码享受折扣
	a44=document.form1.creaditsprice.value;//积分抵用折扣
	a55=(parseFloat(a11)-parseFloat(a44))*a22*a33;//最终价格
	a55=a55.toFixed(2);
	a66=parseFloat(a11)-parseFloat(a55);//节省金额
	a66=a66.toFixed(2);
	document.getElementById("finalprice1").innerHTML=a55;
	document.getElementById("saveprice1").innerHTML=a66;
	document.getElementById("listedprice1").innerHTML=a11;
	document.form1.finalprice.value=a55;
	document.form1.saveprice.value=a66;
}

function email22(){
	email=document.form1.email.value;	
	var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if(reg.test(email) && document.form1.tstype.value==0){
		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
		    http_request = new XMLHttpRequest();
		} else if (window.ActiveXObject) { // IE
		    http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		var url="/displayajax.php?email="+email+"&me="+Math.random();
		http_request.open("GET",url,false);
		http_request.send(null);
		var returntxt=http_request.responseText;			
		if(returntxt==3){
				document.getElementById("displayemail").style.display="block";	
				txt="Welcome! You are a first time customer. <a onclick=\"openLayer('test1','test_con')\">Register now</a> to receive VIP membership discounts! All new members receive an instant 2% Off Junior VIP discount on top of our promotional discount coupons!"			
				document.getElementById("displayemail1").innerHTML=txt;
				document.getElementById("displayemail1").style.display="block";	
		}
		else{
			document.getElementById("displayemail").style.display="block";	
			aa=returntxt.split("|");
			if(aa[0]==1 || aa[0]==2){
				txt="Welcome! You are a "+aa[1]+ " member at our website. Please log into your account to enjoy your"+ aa[2] +"% Off VIP discount on top of our promotional discount coupons! If you’re not a member but a previous customer, <a href='forgot.php?email="+email+"' target='black'>Click Here</a> to obtain login password by email."
				document.getElementById("displayemail1").innerHTML=txt;
				document.getElementById("displayemail1").style.display="block";					
			}
			else{
				document.getElementById("displayemail").style.display="block";	
				txt="Welcome! You are a first time customer. <a onclick=\"openLayer('test1','test_con')\">Register now</a> to receive VIP membership discounts! All new members receive an instant 2% Off Junior VIP discount on top of our promotional discount coupons!"			
				document.getElementById("displayemail1").innerHTML=txt;
				document.getElementById("displayemail1").style.display="block";						
			}
		}
	}
	else{
		document.getElementById("displayemail").style.display="none";						
	}		
}
