//Used to validate email address
function isValidEmail(email)
{
	var splitted = email.match("^(.+)@(.+)$");

	if(splitted == null) return false;
	if(splitted[1] != null )
	{
	  var regexp_user=/^\"?[\w-_\.]*\"?$/;
	  
	  if(splitted[1].match(regexp_user) == null) return false;
	}

	if(splitted[2] != null)
	{
	  var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
	
	  if(splitted[2].match(regexp_domain) == null) 
	  {
		var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	
		if(splitted[2].match(regexp_ip) == null) return false;
	  }

	  return true;
	}

	return false;
}

//Used to validate phone number
function isValidPhoneNumber(phoneNumber)
{
	var phoneRegEx = /^[+\(\)\s\-\.\d]*$/; 
 
    if (phoneRegEx.test(phoneNumber))
    {	    
	  return true;
    }	 

    return false;
}

//Used to validate website url
function isValidWebsiteUrl(url)
{
	var urlRegEx = /^(((http(s?))|(ftp))\:\/\/)?(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.(com|edu|gov|mil|net|org|biz|info|name|museum|us|ca|uk)(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*$/;
 
    if (urlRegEx.test(url))
    {	    
	  return true;
    }	 

    return false;
}


//Used to trim the particular text
function Trim(trim_value)
{  
	if(trim_value.length < 1)
	{
		return "";
	}

	trim_value = RTrim(trim_value);
	trim_value = LTrim(trim_value);
	if(trim_value=="") 
	{
		return "";
	} 
	else 
	{
		return trim_value;
	}
}

//Used to right trim the particular text
function RTrim(value)
{
	var w_space = String.fromCharCode(32);
	var v_length = value.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}

	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(value.charAt(iTemp) == w_space)
		{
		
		}
		else
		{
			strTemp = value.substring(0,iTemp +1);
			break;
		}

		iTemp = iTemp-1;

	}

	return strTemp;

} 

//Used to left trim the particular text
function LTrim(value) 
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}

	var v_length = value.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(value.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = value.substring(iTemp,v_length);
			break;
		}

		iTemp = iTemp + 1;
	}

	return strTemp;
}
