
function isValidDate(day, month, year){
	if (month < 1 || month > 12){return false;}
	if (day < 1 || day > 31){return false;}
	if ((month==4 || month==6 || month==9 || month==11) && day==31){return false;}
	
	if (month == 2)	{ // check for february 29th
	  var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	  if (day>29 || (day==29 && !isleap)){return false;}
	}
	return true;  // date is valid
}

function StripText(ob){
	var r, re;
	var s = ob.value;
	re = /'|"/gi;
	ob.value = s.replace(re,"");
}

function UpCaseText(ob){
	ob.value=ob.value.toUpperCase();
}

function isValidEmailChars(inStr){
	var emailRegExp = new RegExp("^([A-Za-z0-9])+([A-Za-z0-9_\.\-])+([A-Za-z0-9])+$|^[A-Za-z0-9]{2}?$");
	return emailRegExp.test(inStr);
}

function isValidEmailAddress(emailAddress){
	var ea = emailAddress;
	var r, d, i
	var isOK=true;
	
	r=ea.split("@");
	if (r.length!=2){
		isOK=false;
		//alert('No @ symbol or too many');
	}
	else if (ea.lastIndexOf(' ')!=-1){
		isOK=false;
		//alert('Not allowed spaces');
	}
	else if (r[0].length==0 || r[1].length==0){
		isOK=false;
		//alert("No text before or after @ symbol");	
	}
	else if (!isValidEmailChars(r[0])){
		isOK=false;
		//alert('Invalid characters before @ symbol');
	}
	else if (!isValidEmailChars(r[1])){
		isOK=false;
		//alert('Invalid characters after @ symbol');
	}
	else{
		d = r[1].split(".");
		if (d.length < 2){
			isOK=false;
			//alert('No .(dot) after @ symbol');
		}
		else {
			for (i=0; i<=d.length-1; i++){
				if (d[i].length==0){
					isOK=false;
					//alert('No text before or after a .(dot)');	
				}
			}
		}
	}
	return isOK;
}

//Check NINO numbers
function regExpNinoIs_valid(field)
{	var myRegExp = /\D{2}\d{6}\D/i;
	return !(myRegExp.test(field));	}
	
