//Browser Support Code
function ajaxFunction(){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			var ajaxDisplay = document.getElementById('result');
			ajaxDisplay.innerHTML = ajaxRequest.responseText;
		}
	}
	var name = document.getElementById('name').value;
	var address = document.getElementById('address').value;
	var request = document.getElementById('request').value;
	var amount = document.getElementById('amount').value;
	var queryString = "?request=" + request + "&address=" + address + "&name=" + name + "&amount=" + amount;
	ajaxRequest.open("GET", "rate.php" + queryString, true);
	ajaxRequest.send(null); 
}

function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function confirm_trade() {
	 if (document.getElementById("address").value) {
	  if (document.getElementById("name").value) {
	   if (document.getElementById("amount").value) {
	    if (document.getElementById("op").value) {
	     if (document.getElementById("amount").value) {
		 	if(document.getElementById("amount").value < 10) {
				alert("The minimum amount allowed to trade is 10.");
				window.location.reload();
				return false;
			}
			else {
			                     var alphaPattern = /[^0-9\.]/; // anything but numbers

  				if(alphaPattern.exec(document.getElementById("amount").value)) {
					alert ("Please Make Sure The Amount Contains Numbers Only")
					window.location.reload();
			      return false;
   				}
	}
	     } else {
	      alert ("Please Make Sure The Amount Contains Numbers Only")
		  window.location.reload();
	      return false;
	     }
	    } else {
	     alert ("Please Select An Option To Sell W$ or T$")
		 window.location.reload();
	     return false;
	    }
	   } else {
	    alert ("Please Enter An Amount");
		window.location.reload();
	    return false;
	   }
	  } else {
	   alert ("Please Enter PokerStars ID");
	   window.location.reload();
	   return false;
	  }
	 } else {
	  alert ("Please Enter An Email Address");
	  window.location.reload();
	  return false;
	 }
	 
	 if(echeck(document.main.address.value)==false) {
	 	alert("Please enter a valid email address");
		window.location.reload();
		return false;
	}
	var selltext = "sell";
	var currency = "W$";
	var direction = "to";
		
	if(document.main.op.value == 1) {
		selltext = "sell";
		currency = "T$";
	}
	else if(document.main.op.value == 2) {
		selltext = "sell";
		currency = "W$";
	}
	else if(document.main.op.value == 3) {
		selltext = "buy";
		currency = "W$";
		direction = "from";
	}
	
	if(confirm('By clicking OK you confirm that: ' + document.main.name.value + ' agrees to ' + selltext + ' ' + document.main.amount.value + currency + ' ' + direction + ' TourneyDollars for $' + document.main.rate.value)) {
		return true;
	}
	else
		return false;
}

function calc(tt,c) {
	document.getElementById("op").value = tt;
	document.getElementById("b").innerHTML=c;
	calc1();
}

function check(){

} 

function isNumber(str) {
    return (("" + parseInt(str)) == str);
}

