/*
This script contains common validation routines
*/

//*************************************************************************
//	Function	:	IsString
//	Description	:	Check the input and if it contains a-z A-z or 0-9 But this
//					String can't have Numbers at the begining of the string ( first letter )
//	Pre			:	Nothing
//	Returns		:	True or False according to the input
//************************************************************************

function IsString(string) {
	var pattern = /^[a-z]{1,}(\w|\s)*$/i;
	var status = true;
	
	if ( string ) {
		if ( string.search(pattern)) {
			status = false;
		}
	} else {
		status = false;
	}
	return status;
}

function IsAlpha(string) {
	var pattern = /^[0-z]{1,}|[a-z]{1,}\((\w|\s)*$/i;
	var status = true;
	if ( string ) {
		if (string.search(pattern)) {
			status = false;
		}
	} else {
		status = false;
	}
	return status;
}
//*************************************************************************
//	Function	:	IsNumeric
//	Description	:	Check the input and if it's other then numbers return false else true
//	Pre			:	Nothing
//	Returns		:	True or False according to the input
//************************************************************************

function IsNumeric(string){
	var pattern = /^\d*$/i;
	var status = true;
	if ( string ) {
		if (string.search(pattern)) {
			status = false;
		}
		
	} else {
		status = false;
	}
	return status;
}
//*************************************************************************
//	Function	:	IsEmail
//	Description	:	Check the input is a valid Email address it check for "@" and "."
//	Pre			:	Nothing
//	Returns		:	True or False according to the input
//************************************************************************

function IsEmail(string) {
var pattern = (/^[a-z0-9-](\.\w|\w|-)*@[a-z0-9-](\.\w|\w|-)*\.[a-z-]{2,10}$/i);
var status = true;
	if ( string ) {
		if (!pattern.test(string)) {
			status = false;
		}
	} else {
		status = false;
	}
	return status;
}
//*************************************************************************
//	Function	:	IsReal
//	Description	:	Check the input and if it's other then numbers return false else true
//	Pre			:	Nothing
//	Returns		:	True or False according to the input
//************************************************************************

function IsReal(string){
	var pattern = /(^\d+$){1}|(^\d+(\.\d+)$){1}/i;
	var status = true;
	if ( string ) {
		if (string.search(pattern)) {
			status = false; 
		}
		
	} else {
		status = false;
	}
	return status;
}//*************************************************************************
//	Function	:	IsTelephone
//	Description	:	Check the input for a telephone number
//	Pre			:	Nothing
//	Returns		:	True or False according to the input
//************************************************************************

function IsTelephone(string){
	var pattern = /^(\d{3}|(\+)\d{2}|(\+)\d{1})(-)(\d{3}|\d{2})(-)\d{7}$/i;
	var status = true;
	if ( string ) {
		if (string.search(pattern)) {
			status = false; 
		}
		
	} else {
		status = false;
	}
	return status;
}
