var InvalidMsg = "Invalid Character(s) entered. \nPlease avoid these characters ~ \" & ' # % ";

function reset()
{
    document.frmPayName.txtName.value = "";        
    document.frmPayName.txtAddress.value = "";
    document.frmPayName.txtCity.value = "";
    document.frmPayName.txtState.value = "";
    document.frmPayName.txtpincode.value = "";
    document.frmPayName.txtMobile.value = "";
    document.frmPayName.txtEMail.value = "";
    document.frmPayName.txtAmount.value = "";
    document.frmPayName.txtOthers.value = "";        
}
function ChkAddcount()
{
    var add = document.frmPayName.txtAddress.value;
    if(add.length > 99)
    {
        alert("Address should be within 100 characters");
        return false;
    }
}

//Trim
function Trim(sString)
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

//Page Validation
function validate(Opt)
{
    var str1=document.frmPayName.txtEMail.value
    var filter1=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    commfilter = new RegExp("[~\"'&#%]")
    
    if(Trim(document.frmPayName.txtName.value) == "")
    {
        alert("Enter Name");
        document.frmPayName.txtName.focus();
        return false;
    }
    if(commfilter.test(document.frmPayName.txtName.value))
    {
        alert(InvalidMsg);
        document.frmPayName.txtName.focus();
        return false;
    }
    var addresss = document.frmPayName.txtAddress.value;
    if(Trim(addresss) == "")
    {
        alert("Enter Address");
        document.frmPayName.txtAddress.focus();
        return false;
    }  
    if(addresss.length > 99)
    {
        alert("Address should be within 100 characters");
        document.frmPayName.txtAddress.focus();
        return false;
    }
    if(commfilter.test(addresss))
    {
        alert(InvalidMsg);
        document.frmPayName.txtAddress.focus();
        return false;
    }
    if(Trim(document.frmPayName.txtCity.value) == "")
    {
        alert("Enter City");
        document.frmPayName.txtCity.focus();
        return false;
    }
    if(commfilter.test(document.frmPayName.txtCity.value))
    {
        alert(InvalidMsg);
        document.frmPayName.txtCity.focus();
        return false;
    }
    if(Trim(document.frmPayName.txtState.value) == "")
    {
        alert("Enter State");
        document.frmPayName.txtState.focus();
        return false;
    }
    if(commfilter.test(document.frmPayName.txtState.value))
    {
        alert(InvalidMsg);
        document.frmPayName.txtState.focus();
        return false;
    }
    var pincode1 = document.frmPayName.txtpincode.value;

    if(pincode1 == "")
    {
        alert("Enter Pincode");
        document.frmPayName.txtpincode.focus();
        return false;
    }
    if(isNaN(pincode1)||pincode1.indexOf(" ")!=-1)
    {
        alert("Enter Valid Pincode")
        document.frmPayName.txtpincode.focus();
	    return false;
    }
    if(document.frmPayName.txtMobile.value == "")
    {
        alert("Enter Mobile");
        document.frmPayName.txtMobile.focus();
        return false;
    }
    var mobileno = document.frmPayName.txtMobile.value;

    if(mobileno.charAt(0) != "9" && mobileno.charAt(0) != "8" && mobileno.charAt(0) != "7")
    {		 
	    alert("Enter Valid Mobile Number");
	    document.frmPayName.txtMobile.focus();
	    return false;
    }    	
    if(isNaN(mobileno)||mobileno.indexOf(" ")!=-1)
    {
        alert("Enter Valid Mobile Number")
        document.frmPayName.txtMobile.focus();
	    return false;
    }       
    if(document.frmPayName.txtEMail.value == "")
    {
        alert("Enter EMail ID");
        document.frmPayName.txtEMail.focus();
        return false;
    }
    if(document.frmPayName.txtEMail.value !="")
    {	 
	    if (!filter1.test(str1))
	    {  
		    alert("Invalid E-mail Address! Please re-enter.")
		    document.frmPayName.txtEMail.focus();
		    return false;
	    } 
    }
    var amount = document.frmPayName.txtAmount.value;

    if(amount == "")
    {
        alert("Enter Amount to be transferred");
        document.frmPayName.txtAmount.focus();
        return false;
    }
    if(isNaN(amount)||amount.indexOf(" ")!=-1)
    {
        alert("Enter Valid Amount")
        document.frmPayName.txtAmount.focus();
	    return false;
    }
    var amtarray = new Array();
    amtarray = amount.split('.');
    if(amtarray.length >1)
    {
        if(amtarray[1].length >2)
        {
            alert('Only 2 numbers allowed after decimal point in Amount field');
            document.frmPayName.txtAmount.focus();
	        return false;
        }
    }
    if(Trim(document.frmPayName.txtOthers.value) == "")
    {
        alert("Enter purpose of transaction");
        document.frmPayName.txtOthers.focus();
        return false;
    }
    if(commfilter.test(document.frmPayName.txtOthers.value))
    {
        alert(InvalidMsg);
        document.frmPayName.txtOthers.focus();
        return false;
    }
    if(Opt=="C")
    {
        document.frmPayName.action="Check.aspx";
        document.frmPayName.submit(); 
    }
    else
    {
        document.frmPayName.action="PaymentGateway.aspx";
        document.frmPayName.submit();        
    }
}

//Number Validation
function NoCharacter(objEvent)
{
    var iKeyCode;
    var IsValid = false ;
    if(window.event) // IE
    {
        iKeyCode = objEvent.keyCode
    }
    else if(objEvent.which) // Netscape/Firefox/Opera
    {
        iKeyCode = objEvent.which
    }
    //alert(iKeyCode);
    if(!(iKeyCode==8||iKeyCode==45||iKeyCode==46||iKeyCode==48||iKeyCode==49||iKeyCode==50||iKeyCode==51||iKeyCode==52||iKeyCode==53||iKeyCode==54||iKeyCode==55||iKeyCode==56||iKeyCode==57))
	{
	    if(window.event) 
        {
            objEvent.returnValue=false; 
        }
        else if(objEvent.which) 
        {
            return false;            
        }
    }
}
function RedirectPayment(Opt)
{
    if(Opt=="C")
    {
      window.location="../PayNow.aspx?Opt=C";
    }
    else
    {
      window.location="../PayNow.aspx?Opt=T";
    }
}
