// JavaScript Document
function StrCheckDate()
{
   var strDate,args=StrCheckDate.arguments;
   strDate = args[0];

var pattern = new RegExp(/[0-3][0-9]-0|1[0-9]-19|20[0-9]{2}/);
	// Regular expression used to check if date is in correct format
   if(strDate.match(pattern))
   {
      var date_array = strDate.split('/');
      var day = date_array[0];

      // Attention! Javascript consider months in the range 0 - 11
      var month = date_array[1] - 1;
      var year = date_array[2];

      // This instruction will create a date object
      source_date = new Date(year,month,day);

      if(year != source_date.getFullYear())
         return false;

      if(month != source_date.getMonth())
         return false;

      if(day != source_date.getDate())
         return false;
   }
   else
      return false;

   return true;
}
function MM_validateForm() 
{ //v4.0
	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
	
	for (i=0; i<(args.length-2); i+=3) 
	{ 
		test=args[i+2]; 
		val=MM_findObj(args[i]);
		if (val) 
		{ 
			nm = args[i+1];
			if (nm=='')
				nm=val.name; 
			if (test.charAt(0) == 'C') 
			{
				if(val.checked == false)
					errors += '- '+nm+'\n'; 
			}
			else if (test.charAt(0) == 'E') 
			{
				if ((val=val.value)!="") 
				{
					re = /^[a-zA-Z -]{1,}$/i;
					if (!re.test(val)) 
						errors += '- '+nm+' contains illegal characters.\n'; 
				}
				else
				{
					errors += '- '+nm+' is required.\n'; 
				}
			}
			else if ((val=val.value)!="") 
			{
				if (test.indexOf('isEmail')!=-1) 
				{ 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) 
						errors+='- '+nm+' must contain an e-mail address.\n';
				} 
				else if (test.indexOf('isDate')!=-1) 
				{ 
					if (!StrCheckDate(val)) 
						errors+='- '+nm+' must contain a valid date (format: dd/mm/yyyy).\n';
				} 
				else if (test.indexOf('isInfDate')!=-1) 
				{ 
					if (!StrCheckDate(val)) 
						errors+='- '+nm+' must contain a valid birthday (format: dd/mm/yyyy).\n';
					else
					{
						  var date_array = val.split('/');
						  var day = date_array[0];
						  var month = date_array[1] - 1;
						  var year = date_array[2];
						  source_date = new Date(year,month,day);
						  var two_years=1000*60*60*24*365*2;
						  var now = new Date();
						  now = now.getTime();
						  
						  if((now - source_date.getTime()) > two_years)
							errors+='- '+nm+' is not valid for an infant. Maximum allowed age is 2 years.\n';
					}
				} 
				else if (test!='R') 
				{ 
					num = parseFloat(val);
					if (isNaN(val)) 
						errors+='- '+nm+' must contain a number.\n';
					if (test.indexOf('inRange') != -1) 
					{ 
						p=test.indexOf(':');
						min=test.substring(8,p); 
						max=test.substring(p+1);
						if (num<min || max<num) 
							errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
					} 
				}
			} 
			else if (test.charAt(0) == 'R') 
				errors += '- '+nm+' is required.\n'; 
		}
	} 
	if (errors) 
		alert('The following error(s) occurred:\n'+errors);
//		alert('<?php echo TL("The following error(s) occurred");?>:\n'+errors);
	document.MM_returnValue = (errors == '');
}

