/*****************************************************************************************************************************************
  Language & version : JavaScript, 1.2
  Unit         :
  FormName     :
  Heirarchy    :
  Tables used  :
  Done by      :   Deep Kumar                              Dt. : 10-06-04
  Reviewed by : 		       Dt :
  Description  : This script file stores the common function used in the validation.
  Attention : 	

  Modifications...
  Done by     :                                Dt. :		Req.No :
  Description :
*******************************************************************************************************************************************/
/*****************************************************************************************************************************************
Name        : check_email
Done by     :  Deep Kumar                              Dt. : 10-06-04
Description :  will check whether the string passed is a valid email address or not. 
Visiblity (Private\Protected\Public) : Public
Parameters: email_string, a string.
ReturnValue(if relevant) : True, if the string is a valid email address; False otherwise
Attention :

Modifications...
  Done by     :                                Dt. :		Req.No :
  Description :

*******************************************************************************************************************************************/
function check_email(email_string) {
	var split_val = email_string.split('@');
	
	if(split_val.length <= 1) 
	{
		alert("Please enter a valid email address");
		return false;
	}
	if(split_val[0].length <= 0 || split_val[1].length <= 0) 
	{
		alert("Please enter a valid email address");
		return false;
	}
	
	split_domain = split_val[1].split('.');
	if(split_domain.length <= 1) 
	{
		alert("Please enter a valid email address");
		return false;
	}
	if(split_domain[0].length <= 0 || split_domain[1].length <= 1) 
	{
		alert("Please enter a valid email address");
		return false;
	}
	return true;
}

/*****************************************************************************************************************************************
Name        : trim_spaces
Done by     : Deep Kumar                               Dt. : 10-06-04
Description : This function will remove all leading and trailing spaces from the string passed into
Visiblity (Private\Protected\Public) : Public
Parameters: string_value, a string
ReturnValue(if relevant) : the string with leading and trailing spaces removed.
Attention :

Modifications...
  Done by     :                                Dt. :		Req.No :
  Description :

*******************************************************************************************************************************************/

function trim_spaces(string_value) {
	// Checks the first occurance of spaces and removes them
	for(var i = 0; i < string_value.length; i++) 
	{
		if(string_value.charAt(i) != " ") 
		{
			break;
		}
	}
	if(i > 0) 
	{
		string_value = string_value.substring(i);
	}
	
	// Checks the last occurance of spaces and removes them
	str_length = string_value.length - 1;
	for(i = str_length; i >= 0; i--) 
	{
		if(string_value.charAt(i) != " ") 
		{
			break;
		}
	}
	if(i < str_length) 
	{
		string_value = string_value.substring(0, i + 1);
	}
	
	// Returns the string after removing leading and trailing spaces.
	return string_value;
}
