function check(){
var selectFlag=true;
var userName=document.getElementById("userName").value;
var userEmail=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==""||trim(userName).lenght==0){
alert("Full Name can't be empty!!!Please Enter Your Full Name!");
document.getElementById("userName").focus();
}else if(userEmail==""||trim(userEmail).length==0){
alert("Email Address can't be empty!!!Please Enter Your Email Address!");
document.getElementById("userAddress").focus();
 }else if(!isemail(userEmail)){
 alert("Format of Email Address is incorrect!!!Please Enter Your Email Address In Correct Format!");
 document.getElementById("userAddress").focus();
 }else if(userPhone==""||trim(userPhone).length==0){
alert("User'Telephone can't be empty!!!Please enter Your Telephone!");
document.getElementById("userPhone").focus();
 }else if(!isphone(userPhone)){
alert("Format of Telephone is Incorrect!!!Please enter Your Telephone in Digit or -  Format!");
document.getElementById("userPhone").focus();
 }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 trim(s){
 return s.replace( /^\s*|\s*$/g, ""); 
}
function isemail(v){
 	return /\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v);
}
function isphone(v){
 return /[0-9\-]$/.test(v);
}

function setSelectRadioValue(radio,value){
        if(value!=""){
                var radioValue=document.getElementById(radio).value;
                if(radioValue==value){
                   document.getElementById(radio).checked=true;
                 }
        }
}
	   
var http_request = false; 
var tPrice=0;
function checkDiscount(gameName,totalPrice){
var bonus=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=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+"&gameName="+gameName+"&totalPrice="+totalPrice);
}

function processTextResponse() {
		if(http_request.readyState == 4){
			if(http_request.status == 200){
				var str=http_request.responseText;
				var defaultPrice=document.getElementById("defaultPrice").value;
		        if(str.indexOf("Error1")!=-1){
		         document.getElementById("disSavePrice").innerHTML=defaultPrice;
		         document.getElementById("disAccountTotalPrice").innerHTML=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=defaultPrice;
		         document.getElementById("disAccountTotalPrice").innerHTML=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=defaultPrice;
		         document.getElementById("disAccountTotalPrice").innerHTML=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=defaultPrice;
		         document.getElementById("disAccountTotalPrice").innerHTML=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=defaultPrice;
		         document.getElementById("disAccountTotalPrice").innerHTML=tPrice;
		         document.getElementById("applyError").innerHTML="<font color='red'><strong>The application is to maintain!!!</strong></font>";
		       }else{
		             var priceFlag=document.getElementById("priceFlag").value;
		             var savePrice=document.getElementById("savePrice").value;
		             if(parseInt(tPrice)-parseInt(str)<0){
		              document.getElementById("disSavePrice").innerHTML="-"+priceFlag+(-parseInt(((parseInt(tPrice)-parseInt(str))+parseFloat(savePrice))))+".00";
		             }else{
		              document.getElementById("disSavePrice").innerHTML=priceFlag+(parseInt((parseInt(tPrice)-parseInt(str))+parseFloat(savePrice)))+".00";
		            }
		            document.getElementById("disAccountTotalPrice").innerHTML=str;
		            document.getElementById("applyError").innerHTML="";
		       }
		    }
		}
	}	
