function validateForm()
{
	
	var Name = new RegExp("^[0-9a-zA-Z\\s\\.]{3,100}$");
	var CN = new RegExp("^[0-9]{6,15}$");
   	var Add = new RegExp("^[A-Za-z0-9\\/\\#\\-\\_\\()\\s\\.\\,\\:\\&]{3,120}$");
	var amount = new RegExp("^([1-9]{1}[0-9]{0,7}|[1-9]{1}[0-9]{0,7}\\.[0-9]{2})$");
	
	if (checkName(document.form1.txtCustomerID.value))
	{
		alert("Please enter a valid Name (eg Sachin Sharma)");
		document.form1.txtCustomerID.focus();
		return false;
	}
	 if (checkAddress1(document.form1.txtAdditionalInfo1.value))
	{
		alert("Please enter a valid Address (eg 7/7 I Flr, Old Rajinder Nagar,N D-60)");
		document.form1.txtAdditionalInfo1.focus();
		return false;
	}
	if (!document.form1.txtAdditionalInfo2.value.match(CN))
	{
		alert("Please enter Phone No. (eg 9824555555)");
		document.form1.txtAdditionalInfo2.focus();
		return false;
	}
	if (document.form1.txtTxnAmount.value==0)
	{
		alert("Please Select the Amount of Donation (eg 3000.00)");
		document.form1.txtTxnAmount.focus();
		return false;
	}
	if (! document.form1.txtTxnAmount.value.match(amount))
	{
		alert("Please enter a valid Donation Amount (eg 3022.26)");
		document.form1.txtTxnAmount.focus();
		return false;
	}
	
		var str=document.form1.txtTxnAmount.value;
		if (str.indexOf(".")== -1)
		{
			str=str+".00";
		}
		document.form1.txtTxnAmount.value=str;
		//alert("Name of the donor = "+document.form1.txtCustomerID.value);
		//alert("Addess of the donor = "+document.form1.txtAdditionalInfo1.value);
		//alert("Name of the Type of pooja = "+document.form1.txtAdditionalInfo2.value);
		//alert("Name of the Pooja Details = "+document.form1.txtAdditionalInfo3.value);
		//alert("contact Number= "+document.form1.txtAdditionalInfo5.value);
		//alert("Amount of Donation (Rs. Ps.) = "+document.form1.txtTxnAmount.value);
		
		document.all.item("form1").action="https://www.billdesk.com/pgidsk/servlet/com.pgidsk.controller.PGIBillerRequestHandler"
		document.form1.submit();
	
}

function checkForPraSpcChar(str, obj)
{
	var str1 = str;
    var str2 = obj;
	var str2Len = obj.length;
    var i,j;
    var ch;
    var check=false;
	for (i=0; i<str2.length; i++)
	{
       	check=false;
       	ch = str2.charAt(i);
		for (j=0; j<str1.length; j++)
		{

   			if (ch == str1.charAt(j))
			{
		     			check=true;
            	break;
            }
     	}
		if (!check)
			break;
     }
	    return check;
}
function trimSpaces (str)
{
    var len = str.length;
	var str1 = str;
    var loop=true;

	while(loop)
	{

		if (str1.charAt(0) == " ")
		{
			str1 = str1.substring(1);
			len = str1.length;
		}
		else if(str1.charAt((len-1)) == " ")
		{
			str1 = str1.substring(0,(len-2));
			len = str1.length;
		}
		else
		{
			loop = false;
		}
	}
	return (str1);
}
function checkEmailid()
{
	var str=document.form1.txtAdditionalInfo2.value;
	str = trimSpaces(str);
	var len = str.length;

	if(str=="")
	{
			return true;
	}
	else if(str.length>40)
	{
			return true;
	}
	else if(str.indexOf("@")==-1)
	{
		return true;
    }
	else if(str.indexOf(".")==-1)
	{
		return true;
    }
	else if(str.substring(str.indexOf(".")+1).length <2)
	{
		return true;
    }
    else if (!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-", str)))
    {
		return true;
    }
    else if(str.indexOf("@",(str.indexOf("@")+1)) != -1)
    {
		return true;
    }
    else if( (str.charAt((len -1 )) == ".") || (str.charAt((len -1 )) == "@") || (str.charAt((len -1 )) == "_"))
    {
		return true;
	}
    else if( (str.charAt(0) == ".") || (str.charAt(0) == "@"))
    {
		return true;
	}
	else
	{
		return false;
	}
}


function checkName(str)
{
	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	else if(str.length>100 || str.length < 3)
	{
			return true;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ",str)))
    {
			return true;
    }
	else
	{
		return false;
	}
}
function checkAddress1(str)
{
	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	else if(str.length>120 || str.length < 3)
	{
			return true;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789., #&()/-_",str)))
    {
			return true;
    }
	else
	{
		return false;
	}
}
function checkAddress2(str)
{

	str = trimSpaces(str);
	if(str=="")
	{
			
			return true;
	}
	if(str.length>120 || str.length < 3)
	{
			return true;
	}
	else if(str=="")
	{
		
			return false;
	}
	else if(!(checkForPraSpcChar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. ,#&()/-_",str)))
    {	
			
			return true;
    }
	
	else
	{
			return false;
	}
}
function checkForPraSpcChar(str, obj)
{
	var str1 = str;
    var str2 = obj;
	var str2Len = obj.length;
    var i,j;
    var ch;
    var check=false;
	for (i=0; i<str2.length; i++)
	{
       	check=false;
       	ch = str2.charAt(i);
		for (j=0; j<str1.length; j++)
		{

   			if (ch == str1.charAt(j))
			{
		     			check=true;
            	break;
            }
     	}
		if (!check)
			break;
     }
	    return check;
}
function trimSpaces (str)
{
    var len = str.length;
	var str1 = str;
    var loop=true;

	while(loop)
	{

		if (str1.charAt(0) == " ")
		{
			str1 = str1.substring(1);
			len = str1.length;
		}
		else if(str1.charAt((len-1)) == " ")
		{
			str1 = str1.substring(0,(len-2));
			len = str1.length;
		}
		else
		{
			loop = false;
		}
	}
	return (str1);
}
