String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };

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;
}

function contacttelephone(tel, action) {
// trim whitespace
tel = tel.trim();
// check for numbers spaces only or whatever else paypal allow
	if(IsNumeric(tel) && tel.length >= 7)
		{	if(action=='verify')
				return true;
			if(action=='change')
				window.document.order_completion.contact_tel.value = tel;
				window.document.checkout.night_phone_b.value = tel;
		}
   else { 	window.document.order_completion.contact_tel.value='';
			alert('Invalid Contact Telephone Number.\n\nPlease enter numbers only.');
			if(action=='verify')
			return false;
	    }
}
function ponum(po, action) {
// trim whitespace
po = po.trim();
// check for entry
	if(po.length>=1)
		{	if(action=='verify')
				return true;
			if(action=='change')
				window.document.order_completion.po_number.value = po;
				//window.document.checkout.invoice.value = po;
				
		}
   else { window.document.order_completion.po_number.value='';
			alert('Invalid entry in Purchase Order Number Field.\n\nPlease correct.');
			if(action=='verify')
				return false;				
	    }
}
