//Validationfunctions
addLoadListener(init);

function init()
{
  document.forms[0].onsubmit = validateFields;
  return true;
}


function validateFields() 
{
	nme = (document.forms["paypalpay"]["item_name"].value);
	amt = (document.forms["paypalpay"]["amount"].value); 
	inl = (document.forms["paypalpay"]["item_number"].value);
	newnme = nme+' '+inl;
	document.forms["paypalpay"]["item_name"].value = newnme
 
 	if (amt == "") {
		alert('You must enter an amount');
		return false;
	}

	if (isNaN(amt)) {
		alert('Please enter a valid Amount - only numbers and decimal points accepted');
		return false;
	}

	if (inl.length < 4) { 
		alert('You must enter an Invoice number more than 4 characters long'); 
		return false;
	}
}


function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}
