function rltrim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
}
function popupRank(href){
	window.open(href,'','height=700px,width=1012px,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,status=no');
}
function setSelectRadioValue(radio,value){
        if(value!=""){
                var radioValue=document.getElementById(radio).value;
                if(radioValue==value){
                   document.getElementById(radio).checked=true;
                 }
        }
}
function checkBuyUser(payFlag){
        var selectFlag=true;
		var userName=document.getElementById("userName").value;
		var userAddress=document.getElementById("userAddress").value;
		var userPhone=document.getElementById("userPhone").value;
		var paymentRadio=document.getElementsByName("paymentMethod");
		var rbtnIsAccept=document.getElementById("rbtnIsAccept").checked;
		for(var t=0;t<paymentRadio.length;t++){
		      if(paymentRadio[t].checked){
		        selectFlag=false;
		      }
		}
		   if(userName==""||userName.length==0){
				alert("User's Name can't be empty!!!please enter User Name! ");
			}else if(userAddress==""||userAddress.length==0){
				alert("User's Address can't be empty!!!please enter userAddress!");
			}else if(!isemail(userAddress)){
			    alert("User's Address is incorrect!Please input User's Address again!!!");
			}else if(userPhone==""||userPhone.length==0){
				alert("User'Telephone can't be empty!!!please enter userPhone!");
			}else if(selectFlag){
			    alert("Please Select Payment Method!!!");
			}else if(!rbtnIsAccept){
			   alert("Please check the box about terms and conditions!");
			}else{
			     document.formc.action="../buyinfo/BuyInfoView.jsp";
		         document.formc.submit();
		    }
		}
		
	   function isemail(v){
	    	return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v);
	   }
	   
var http_request = false; 
var tPrice=0;
function checkDiscount(gameName,totalPrice){
var bonus=rltrim(document.getElementById("bonusInput").value);
	if(bonus=="" || bonus.length == 0) 
		return;
		if(window.XMLHttpRequest){
			http_request = new XMLHttpRequest();
			if(http_request.overrideMimeType){
				http_request.overrideMimeType("text/xml");
			}
		}else if(window.ActiveXObject){
			try{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(e){}
			}
		}
		
		if(!http_request){
			window.alert("This function needs the support of ajax, and such browser doesn't support ajax!");
			return false;
		}
		tPrice=rltrim(totalPrice);
		http_request.onreadystatechange = processTextResponse;
		http_request.open("post","../disaccount/discount.jsp",true);
		http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http_request.send("bonus="+bonus+"&totalPrice="+totalPrice);
}

function processTextResponse() {
		if(http_request.readyState == 4){
			if(http_request.status == 200){
				var str=rltrim(http_request.responseText);
				var defaultPrice=document.getElementById("defaultPrice").value;
		        if(str.indexOf("Error1")!=-1){
		         document.getElementById("disSavePrice").innerHTML=rltrim(defaultPrice);
		         document.getElementById("disAccountTotalPrice").innerHTML=rltrim(tPrice);
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>Error!!!Invalid Coupon Code!!!</strong></font>";
		        }else if(str.indexOf("Error2")!=-1){
		         document.getElementById("disSavePrice").innerHTML=rltrim(defaultPrice);
		         document.getElementById("disAccountTotalPrice").innerHTML=rltrim(tPrice);
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>Error!!!Coupon Code  has been used up!!!</strong></font>";
		        }else if(str.indexOf("Error3")!=-1){
		         document.getElementById("disSavePrice").innerHTML=rltrim(defaultPrice);
		         document.getElementById("disAccountTotalPrice").innerHTML=rltrim(tPrice);
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>Coupon Code  has expired!!!</strong></font>";
		        }else if(str.indexOf("Error4")!=-1){
		         document.getElementById("disSavePrice").innerHTML=rltrim(defaultPrice);
		         document.getElementById("disAccountTotalPrice").innerHTML=rltrim(tPrice);
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>Coupon Code  have been terminated to use!!!</strong></font>";
		        }else if(str.indexOf("Error5")!=-1){
		         document.getElementById("disSavePrice").innerHTML=rltrim(defaultPrice);
		         document.getElementById("disAccountTotalPrice").innerHTML=rltrim(tPrice);
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>The application is to maintain!!!</strong></font>";
		       }else{
		             var priceFlag=rltrim(document.getElementById("priceFlag").value);
		             var savePrice=rltrim(document.getElementById("savePrice").value);
		             if(parseInt(tPrice)-parseInt(str)<0){
		              document.getElementById("disSavePrice").innerHTML=rltrim("-"+priceFlag+(-parseInt(((parseInt(tPrice)-parseInt(str))+parseFloat(savePrice))))+".00");
		             }else{
		              document.getElementById("disSavePrice").innerHTML=rltrim(priceFlag+(parseInt((parseInt(tPrice)-parseInt(str))+parseFloat(savePrice)))+".00");
		            }
		            document.getElementById("disAccountTotalPrice").innerHTML=rltrim(str);
		            document.getElementById("applyError").innerHTML="";
		       }
		    }
		}
	}
	

