
function ValidateSubmit() 
{
	var strMessage = "";
	var now = new Date();
	var jsCrLf = String.fromCharCode(10,13);
	var strEndMsg = " (\<\>\;\"\\(\)[\]\%\+\*\/\+\-\.\ are not permitted)." + jsCrLf;
	var x;
	var d;
	var currentYear;
	var currentMonth;
	var currentDate;
	var difference1;
	var difference2;
	var difference3;

	
	

	
	
	if (!ExtendedDateVal(document.ChildTrustFund.ctfdate.value,document.ChildTrustFund.ctfmonth.value,document.ChildTrustFund.ctfyear.value))
	
	strMessage += 'Please enter a date in the format dd/mm/yyyy that is between 01/09/2002 and today inclusive.\n';
	
	if (document.ChildTrustFund.pt_amt.value == "")

		strMessage += 'Please enter a payment amount.\n';
	
	
	if (document.ChildTrustFund.pt_amt.value !="")
	{
		
		if(isNaN(document.ChildTrustFund.pt_amt.value))
		strMessage += 'Please enter a valid payment amount.\nThe maximum payment is 100 if paying monthly,\notherwise maximum payment is 1200 if paying annually.\n';			
	}	
	

	if ( (document.ChildTrustFund.pt_amt.value !="") && (!isNaN(document.ChildTrustFund.pt_amt.value)) )
	{
		var pstrStringToCheck = document.ChildTrustFund.pt_amt.value;
		var strillegalchars = '()<>;"[]&@^*!%+.-/';
		
		for (var i=0; i < pstrStringToCheck.length; i++) 
		{		  
			var letter = pstrStringToCheck.charAt(i).toLowerCase();
			if (strillegalchars.indexOf(letter) != -1)
			{
			
			strMessage += 'Please enter a valid payment amount.\nThe maximum payment is 100 if paying monthly,\notherwise maximum payment is 1200 if paying annually.\n';
			break;
			}
			else
			{
			continue;
			}
		}
		
		
	}	
	
	if (document.ChildTrustFund.pt_amt.value != "" && !isNaN(document.ChildTrustFund.pt_amt.value) )
	{
		if( (document.ChildTrustFund.pt_frequency.value == "Annual" && document.ChildTrustFund.pt_amt.value > 1200 ) || 
		+  (document.ChildTrustFund.pt_frequency.value == "Monthly" && document.ChildTrustFund.pt_amt.value > 100 ) )

		strMessage += 'Please enter a valid payment amount.\nThe maximum payment is 100 if paying monthly,\notherwise maximum payment is 1200 if paying annually.\n';
	}
	
	

	if (strMessage != "") 
	{		
		alert(strMessage);
		return false;
	}	
	else 
	{
		return true;
	}


}


function ExtendedDateVal(day,month,year)
{
	
	if(isNaN(day) || isNaN(month) || isNaN(year))
	{
	
		return false;
	}	

	if(year.length == 0 || month.length == 0 || day.length==0)
	{
	
		return false;
	}
	
	if(day < 1)
	{
		return false;
	}
	

	
	/* for validate dob should not less than 01/09/2002 */
	var startdate;
	var startmonth;
	var startyear;

	stardate = 01;
	startmonth = 09;
	startyear = 2002;
	

	
	
	if(year < startyear)
	{
		
		return false;
	}
	

	if (year == startyear)
	{
		
		if(month<startmonth)
		{
		return false;
		}
		if(month == startmonth)
		{
			if (day<startdate)
			{
			return false;
			}
		}
	}
	
	/* for validate dob should not greater than current date */
	

	x=new Date();

	currentYear=x.getFullYear();
	currentMonth=x.getMonth()+1;
	currentDate=x.getDate();
	
	
	
	if(year > currentYear)
	{
		return false;
	}
	
	if (year == currentYear)
	{
		
		if(month>currentMonth)
		{
		
		return false;
		}
		if(month == currentMonth)
		{
		 
		 	if (day>currentDate)
		 	{
		  	return false;
			}
		}
	}

	switch(month)
	{
		case "01": case "03": case "05": case "07": case "08": case "10": case "12":
	
		if(day > 31)
		{
			return false;
			break;
		}
		else
		{
			return true;
			break;
		}
				
		case "04": case "06": case "09": case "11":

		if(day > 30)
		{
			return false;
			break;
		}
		else
		{
			return true;
			break;
		}
			
		case "02":

		if (year % 4 == 0)
		{
			if (year % 400 == 0)
			{
				// is a leap year
				if(day > 29)
				{
					return false;
					break;
				}  
				else
				{
					return true;
					break;
				}    
			}
			else if (year % 100 == 0)
			{
				//not a leap year
				if(day > 28)
				{
					return false;
					break;
				}	  
			}
			else
			{
				//is a leap year
				if(day > 29)
				{
					return false;
					break;
				}
				else
				{
					return true;
					break;
				}    
			}
		}
		else
		{
			//not a leap year
			if(day > 28)
			{
				return false;
				break;
			}
			else
			{
				return true;
				break;
			}	  
		}
			
		default:
		return false;
		break;
			
	}
		
}



function CheckIllegalChars(pstrStringToCheck)
{
  var strillegalchars = '()<>;"[]&@^*!%+.-/';
  
  for (var i=0; i < pstrStringToCheck.length; i++) 
  {
    var letter = pstrStringToCheck.charAt(i).toLowerCase();
    if (strillegalchars.indexOf(letter) != -1)
    {
		return true;
    }
	else
	{
		continue;
	}
  }
return false;
}

