var r=
{
  'special':/[\W]/g,
  'quotes':/['\''&'\"']/g,
  'notnumbers':/[^\d]/g
}

function valid(o,w)
{
  o.value = o.value.replace(r[w],'');
}

function trim(stringToTrim) 
{
    return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function CopyCountry(Country)
{
    document.paytopritam.vcountrycopy.value = Country;
}

function AlloteMonths(months)
{
    var rade = document.getElementById("monpay");
    rade.value = months + " - Months";
}
function DicePayment(gate)
{
    var ele = document.getElementById("payformonth");
    if(gate == 1)
    {
        ele.disabled = false;
    }
    else
    {
        ele.disabled = true;
        ele.options.selectedIndex=0;
    }
}

function ValidatePayer()
{
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    
    var amount = document.paytopritam.vamount.value;
    var name = document.paytopritam.vfirst_name.value;
    var country = document.paytopritam.vcountry_code.value;
    var phone_a = document.paytopritam.vnight_phone_a.value;
    var phone_b = document.paytopritam.vnight_phone_b.value;
    var mail = document.paytopritam.vemail.value;
    
    name = trim(name);
    mail = trim(mail);
    amount = trim(amount);
    
    if(amount != null)
    {
       if ((amount.length==0) || (parseInt(amount)==0))
       {
            alert("You need to fill in the amount that you wish to contribute");
            document.paytopritam.vamount.focus();
            return false;
       }
    }
    else
    {
        alert("please fill in the amount");
        document.paytopritam.vamount.focus();
        return false;
    }
        
    if(name != null)
    {
       if (!name.match(/^[a-z A-Z]+$/))
       {
            alert("Name can't be blank or alphanumeric");
            document.paytopritam.vfirst_name.focus();
            return false;
       }
    }
    else
    {
        alert("please fill in your first name");
        document.paytopritam.vfirst_name.focus();
        return false;
    }
    
    if(country=="--")
    {
        alert("Please select your country first");
        document.paytopritam.vcountry_code.focus();
        return false
    }

    if(phone_a != null)
    {
        if(phone_a.length<1)
        {
            alert("Please check country code");
            document.paytopritam.vnight_phone_a.focus();
            return false;
        }
    }
    else
    {
        alert("please fill in your country code");
        document.paytopritam.vnight_phone_a.focus();
        return false;
    }
    
    if(phone_b != null)
    {
        if(phone_b.length<7)
        {
            alert("Please check phone number. Add area code before number");
            document.paytopritam.vnight_phone_b.focus();
            return false;
        }
    }
    else
    {
        alert("please fill in your phone number");
        document.paytopritam.vnight_phone_a.focus();
        return false;
    }
    
    if(mail != null)
    {
        if(mail.length<=7)
        {
           alert("Email address needs to be corrected");
           document.paytopritam.vemail.focus();
           return false;
        }
        else
        {
           if(reg.test(mail) == false) 
           {
              alert("Invalid Email Address");
              document.paytopritam.vemail.focus();
              return false;
           }
        }
    }
    else
    {
        alert("please fill in your email address");
        document.paytopritam.vemail.focus();
        return false;
    }
}
