
function isFilled(elm) {


	if (elm == "" || elm == null) {
		return false;
	}
	else if (elm.charAt(0) == " ") {
		var Test;
		Test = false;
		for (i = 0; i < elm.length; i++) {
			if (elm.charAt(i) != " ") {
				Test = true;
				i = elm.length;
			}
		}
		return Test;			
	}
	else 
		return true;
}


function isSelected(elm) {
	if(elm == "-1") {
		return false;
	}
	return true;
}



function checkDate(DOB) {

	// validates a date value as a string in the form "dd/mm/yy"
	// checks for general format, passes through to doDateChecks for days in month, leap years

	pattern = new RegExp("\\d{2}[/]{1}\\d{2}[/]{1}\\d{4}");

	// check the format
	if (!pattern.test(DOB))
	{
		alert ("Sorry, dates must be in format dd/mm/yyyy");
		return false;
	}
	
	// convert to numbers and pass through
	return doDateChecks((DOB.substring(0, 2) - 0), (DOB.substring(3, 5) - 0), (DOB.substring(6, 10) - 0));
	
}


function doDateChecks(day, month, year) {

if (month  > 12 || month  < 1) {
		alert("Sorry, there are 12 months in a year.");	
		return false;
  	}   
  	if (day  < 1 || day  > 31 ) {
		alert("Sorry, but months have between 1 and 31 days."); 	
		return false;
  	}  
  	if (day  > 28) {
		if(month  == 2) {
			if (day  > 29) {
		 		alert("February cannot have more than 29 days.");	
				return false;
			}
			else {
			 	if (( year % 4 == 0 ) && ( ( year % 100 != 0 ) || ( year % 400 == 0 ) ) ) {
					// empty
				}
				else {
	 				alert("Sorry, " + year + " was not a leap year.");		
					return false;
				}
			}
		}
	}
  	if(day  > 30) {
		if (month  < 7) {
			if ((month  % 2) == 0) {
		 		alert("That month does not have 31 days.");	 		
				return false;
			}
		}
		else {
			if ((month  % 2) != 0) {
		 		alert("That month does not have 31 days.");	
				return false;
			}		
		}   
   	}  	

	return true;   


}


function isInt(elm) {
	var isNumeric = elm + "";
	if (isNumeric == "" ) { 
		return false;
	}
	for (var i = 0; i < isNumeric.length; i++) {
		if (isNumeric.charAt(i) < "0" || isNumeric.charAt(i) > "9") {
			return false;
		}
	}
	return true;
}



function checkEmail(elm) {
	if ((elm.indexOf('@') == -1) || (elm.indexOf('@') == elm.length-1)  || (elm.indexOf('.') == -1) || (elm.indexOf('.') == elm.length-1)){
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

function checkvalue(testtype,patternvalue,teststring) {
//Validation routine
//Parameters:
//	testtype = 0	any character
//		   1	alphanumeric (allows spaces also)
//		   2	alphanumeric (no spaces)
//		   3	alphabetic (allows hyphens and spaces)
//		   4	alphanumeric (URL format)
//		   5	alphanumeric (email address)
//		   6	numeric (allows minus sign and decimal point)
//		   7	numeric (digits only)
//
//	patternvalue = 	1	disallow AND
//			2	disallow OR
//			4	disallow IN
//			8	disallow WITH
//			16	disallow LIKE
//			32	disallow SELECT
//			64	disallow INSERT
//			128	disallow UPDATE
//			256	disallow DELETE
//			512	disallow DROP
//
//	teststring	the string being validated.
//

var i;
var regEx;
var retval=false;
var result=false;

// Set pattern to look for: except for 5, this consists of a list of valid characters; if a character other than these
// is found, the validation fails.  Type 5 however, tries to match a specific pattern to validate an email address.
// The match is always case insensitive.
switch (testtype)
{
case 1:
	regEx=/[^a-z \d]/i;
	break;
case 2:
	regEx=/[^a-z\d]/i;
	break;
case 3:
	regEx=/[^a-z \-]/i;
	break;
case 4:
	regEx=/[^a-z\d\/\:\.]/i;
	break;
case 5:
	regEx=/^[a-z\.\d]+@astrazeneca.com/i;
	break;
case 6:
	regEx=/[^ \d\.\-]/i;
	break;
case 7:
	regEx=/[^\d]/i;
	break;
}

// Perform pattern match (except for 0, where any character is allowed).
if (testtype>0) retval=regEx.test(teststring);

// For 5, no match means failure; for the others, match means failure.
if ((retval && testtype!=5) || (!retval && testtype==5)) 
{
	result=false;
}
else
{
	result=true;

	//If alphas allowed, check that no keyword is present (AND, OR, IN, WITH, LIKE, SELECT, INSERT, UPDATE, DELETE, DROP)
	//but these strings are allowed if they are embedded, ie not flanked by WORD boundary characters.
	if (testtype < 6) 
	{
		for (i=0; i<=9; i++)
		{
			if (patternvalue && 2^i) 
			{ 
				switch (i)
				{
				case 0:
					regEx=/\band\b/i;
				case 1:
					regEx=/\bor\b/i;
				case 2:
					regEx=/\bin\b/i;
				case 3:
					regEx=/\bwith\b/i;
				case 4:
					regEx=/\blike\b/i;
				case 5:
					regEx=/\bselect\b/i;
				case 6:
					regEx=/\binsert\b/i;
				case 7:
					regEx=/\bupdate\b/i;
				case 8:
					regEx=/\bdelete\b/i;
				case 9:
					regEx=/\bdrop\b/i;
				}
				retval=regEx.test(teststring);
				if (retval)
				{
				//Found keyword, so exit
					result=false;
					break;
				}
			}
		}
	}
}
return result;
}


