function isNatural( val )
{
    return ( (val > 0) && (Math.floor(val) == val) );
}
function paymoney(postid)
{
	this.spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});
	pid = postid;

	new Ajax.Request('xmlhttp.php?action=paymoney&my_post_key='+ my_post_key, {method: 'post',postBody:"pid="+pid, onComplete:paymoney_complete});
	return false;
}

function paymoney_complete(request)
{
	if(this.spinner)
	{
		this.spinner.destroy();
		this.spinner = '';
	}
	if(request.responseText.match(/<error>(.*)<\/error>/))
	{
		message = request.responseText.match(/<error>(.*)<\/error>/);
		alert(message[1]);
	}
	else if(request.responseText)
	{
	var message=request.responseText;
		$("pid_"+pid).innerHTML = message;
		Thread.qeCache[pid] = "";
	}
	
	}

function validateForm()
{
	this.spinner = new ActivityIndicator("body", {image: "images/spinner_big.gif"});

	
var x=document.forms["onlinepayment"]["r_pay"].value
var y=Math.floor(x-(-(x*20/100)));
if (x==null || x=="")
  {
  alert("مقدار اعتبار را وارد کنيد.");
  		this.spinner.destroy();
		this.spinner = '';

  return false;
  }
  if (x<4000 || !isNatural( x ))
  {
  alert("حد‌اقل باید 4000 تومان اعتبار خریداری کنید.");
  		this.spinner.destroy();
		this.spinner = '';

  return false;
  }
  else{
  confirmbuy = confirm("با افزایش20% هزینه‌ی نگهداری سایت، هزینه‌ی خرید، "+y+" تومان خواهد شد. آیا تأیید می‌کنید؟");
  if(!confirmbuy)
  {
    this.spinner.destroy();
	this.spinner = '';
    return false;
  }
}
}

