<script type="text/javascript" language="javascript"> 
function ltrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=0,j=0;i<string.length;i++)
    {
      if(j==0)
      {
        if(string.charAt(i)!=" ")
        {
            string1[j++]=string.charAt(i);
        }
      }
      else
      {
        string1[j++]=string.charAt(i);
      }

    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    }
    return string;
  }
function rtrim(string)
  {
    string=new String(string);
    var string1=new Array();
    var i,j;
    for(i=string.length;i>=0;i--)
    {
      if(string.charAt(i-1)==" ")
      {
        continue;
      }
      else
      {
        for(j=0;j<i;j++)
        {
          string1[j]=string.charAt(j);
        }
        break;
      }

    }
    string="";
    for(i=0;i<string1.length;i++)
    {
      string+=string1[i];
    }


    return string;
  }

  function trim(string)
  {
    string=ltrim(string); // // This function is used to trim the left side of a String
    string=rtrim(string);// This function is used to trim the right side of a String
    return string;
  }
  ///////////////////////////////////////////////////

function validatePayment()
{
        if(trim(document.payment1.name.value).length<1)
    {
      alert("Please enter your name.");
      document.payment1.name.focus();
      return false;
    }
       if(trim(document.payment1.address1.value).length<1)
    {
      alert("Please enter your address.");
      document.payment1.address1.focus();
      return false;
    }
	      if(trim(document.payment1.postcode.value).length<1)
    {
      alert("Please enter your postcode.");
      document.payment1.postcode.focus();
      return false;
    }
       if(trim(document.payment1.country.value).length<1)
    {
      alert("Please enter your country.");
      document.payment1.country.focus();
      return false;
    }

        if(trim(document.payment1.telephone.value).length<1)
    {
      alert("Please enter your phone number.");
      document.payment1.telephone.focus();
      return false;
    }
   if(trim(document.payment1.email.value).length<1)
    {
      alert("Please enter your email address.");
      document.payment1.email.focus();
      return false;
    }
	 else
    {
    
        var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;

        if(!email.test(document.payment1.email.value))
	        {
 	 	        alert("Enter valid e-mail address");
		        document.payment1.email.value="";
		        document.payment1.email.focus();
		        return false;
	        }
    }

        if(trim(document.payment1.invoice.value).length<1)
    {
      alert("Please enter your ILS invoice number.");
      document.payment1.invoice.focus();
      return false;
    }
        if(trim(document.payment1.amount.value).length<1)
    {
      alert("Please enter the payment amount.");
      document.payment1.amount.focus();
      return false;
    }
	
       if (document.payment1.currency.value == 'Select')
    {
      alert("Please enter currency type.");
      document.payment1.currency.focus();
      return false;
    }

       	//document.payment1.action="payments/postpayment.php";
		document.payment1.action="index.php?option=com_content&view=article&id=247&Itemid=27"
		document.payment1.submit();
}


function clearPayment()
{
		document.payment1.name.value="";
		document.payment1.address1.value="";
		document.payment1.postcode.value="";
		document.payment1.country.value="";
		document.payment1.telephone.value="";
		document.payment1.email.value="";
		document.payment1.invoice.value="";
		document.payment1.amount.value="";
		document.payment1.currency.value = 'Select'
        
		document.payment1.action="clearform.php";
		document.payment1.submit();
       
}

</script>