//====================================================================================================
//	File Name		:	validate.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.
//	Author			:	Imtiyaz Jariwala
//	Creation Date	:	07-Oct-2005
//	Copyright		:	Copyrights © 2005 DotInfosys
//	Email			:	dinesh@dotinfosys.com
//	History			:
//						Date				Author					Remark
//						07-Oct-2005			Imtiyaz Jariwala		Initial Release
//
//====================================================================================================

//====================================================================================================
//	Function Name	:	IsEmpty
//	Purpose			:	checks whether a field has value or is blank, it returns false if a field
//						is empty otherwise true.
//	Parameters		:	fld	-	field name to be checked
//					    msg -   error message to be displayed
//	Return			:	true or false
//	Author			:	Imtiyaz
//	Creation Date	:	07-Oct-2005
//----------------------------------------------------------------------------------------------------
function IsEmpty(fld,msg)
{
	if((fld.value == "" || fld.value.length == 0) && (msg == ''))
	{
		return false;
	}
	if(fld.value == "" || fld.value.length == 0)
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//====================================================================================================
//	Function Name	:	IsEmail
//	Purpose			:	checks Email validity. Email must have character @ followed by one or more
//						dots. It returns flase if Email is invalid otherwise true.
//	Parameters		:	fld	-	field name to be checked
//					    msg -   error message to be displayed
//	Return			:	true or false
//	Author			:	Imtiyaz
//	Creation Date	:	07-Oct-2005
//----------------------------------------------------------------------------------------------------
function IsEmail(fld,msg)
{
	var regex = /^[\w]+(\.[\w]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/ ;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//====================================================================================================
//	Function Name	:	IsValidString
//	Purpose			:	checks if field value contains only alphanumeric and '_' charactes. Also checks
//						that alphabetical chars. and '_' must have to be come first and followed by
//						numbers. It returns false if above conditions will not satisfy otherwise true.
//	Parameters		:	fld	-	field name to be checked
//					    msg -   error message to be displayed
//	Return			:	true or false
//	Author			:	Imtiyaz
//	Creation Date	:	07-Oct-2005
//----------------------------------------------------------------------------------------------------
function IsValidString(fld,msg)
{
	var regex = /^[_]*[a-zA-Z_]+[a-zA-Z0-9_]*$/;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//====================================================================================================
//	Function Name	:	IsValidString
//	Purpose			:	checks if field value contains only alphanumeric and '_' charactes. Also checks
//						that alphabetical chars. and '_' must have to be come first and followed by
//						numbers. It returns false if above conditions will not satisfy otherwise true.
//	Parameters		:	fld	-	field name to be checked
//					    msg -   error message to be displayed
//	Return			:	true or false
//	Author			:	Imtiyaz
//	Creation Date	:	07-Oct-2005
//----------------------------------------------------------------------------------------------------
function IsPassword(fld,msg)
{
	var regex = /^[_]*[a-zA-Z]+[0-9]+[a-zA-Z0-9]*$/;
	if(!regex.test(fld.value))
  	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//====================================================================================================
//	Function Name	:	IsLen
//	Purpose			:	checks if field value has number of characters between two specified limits.
//						It returns false if no. of chars. is < min. length or > max. length
//						otherwise true.
//	Parameters		:	fld	   - field name to be checked
//						minlen - minimum length of a field
//						maxlen - maximum length of a field
//					    msg    -   error message to be displayed
//	Return			:	true or false
//	Author			:	Imtiyaz
//	Creation Date	:	07-Oct-2005
//----------------------------------------------------------------------------------------------------
function IsLen(fld, minlen, maxlen, msg)
{
	if(fld.value.length < minlen || fld.value.length > maxlen)
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}
//====================================================================================================
//	Function Name	:	IsUrl
//	Purpose			:	It check that if url starts with htpp://
//	Parameters		:	fld -  field name containig url
//						msg -  error message to be displayed
//	Return			:	true or false
//	Author			:	Dinesh Sailor
//	Creation Date	:	10-May-2003
//----------------------------------------------------------------------------------------------------
function IsUrl(fld,msg)
{
//	var regex = /^(http:\/\/)/;
	var regex = /^(http:\/\/|https:\/\/)/;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

