var g_Loc;
g_Loc = 0;

function CheckForm()
{
  iLoc = g_Loc;
  if (g_Loc == 0)
    return false;
    
  var iQty = document.forms['paypal'].quantity.value;
  
  if (!IsNumeric(iQty)) iQty = 0;
  
  if (iQty <1 )
  {
    alert('Please enter a valid quantity');
    return false;
  }

  var ship = 10;
  
  if (iLoc == '1')
  {
    if (iQty>8) ship=20; else
    if (iQty>4) ship=15; else
    if (iQty>2) ship=10; else
    if (iQty>1) ship=6.5; else
                ship=5;
  }
  else
  {
    if (iQty>8) ship=25; else
    if (iQty>4) ship=20; else
    if (iQty>2) ship=15; else
    if (iQty>1) ship=12; else
                ship=10;
  }
  document.forms['paypal'].shipping.value = ship;
  return true;  
}

function BuyNow(sName, iLoc)
{ 
  document.forms['paypal'].item_name.value=sName;
  g_Loc = iLoc;
  CheckForm();
  document.forms['paypal'].submit();   
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}
