
/* 
***************************************************************************************************
This file contains global javascript functions for Onbuild.COM project

The following methods are implemented in this file
1. function isNotBlank(sValue)
2. function isPureNumeric(sValue)
3. function isNumeric(sValue)
4. function IsValid_US_Phone_Or_Fax(sValue)
5. function IsAlpha_Numeric(sValue)
6. function isValidEmail(sValue)
7. function IsValid_Name(sValue)

NOTE : All functions DO NOT ignore leading and trailing spaces. Hence any leading and trailing spaces will be 
treated as a part of the string. If you want the function to ignore these spaces, pass the trimmed values
as arguments.

Description:
1. isNotBlank()
		Args: svalue (any string)
		Returns: boolean value of true or false
		Conditions:  Returns false if the passed string is blank or contains only spaces
2. isPureNumeric()
		Args : svalue (any string)
		Returns : boolean true or false
		Conditions : Returns true if the passed value is PURE numeric. Returns false if it encounters hyphens or leading/trailing
		spaces or periods. So the following values will return false: "98.78","-67,"," 78","62 "
3. isNumeric()
		Args : svalue (any string)
		Returns : boolean true or false
		Conditions : Returns true if the passed value is numeric. A value is considered as Numeric even if it contains
		periods, leading/trailing spaces or hyphens in the beginning(as in negative numbers).
4. IsValid_US_Phone_Or_Fax()
		Args : sValue (any string)
		Returns : boolean true or false
		Conditions: Returns true if the passed value is a valid USA phone number or fax number. A valid phone number must
		have a ***-***-**** format. Inclusion of braces will make it an invalid number. If the user is capturing the phone
		number in three separate boxes, please concatenate them in the ***-***-**** format and send it to this function.
		Do not put in spaces in between the hyphens else the function will return a false.
5. IsAlpha_Numeric()
		Args : sValue (any string)
		Returns : boolean true or false
		Conditions: Returns true if the string is made of only AlphaNumeric characters. Returns false for any wild card
		Characters too.
6. isValidEmail()
		Args : sValue (any string)
		Returns : boolean true or false
		Conditions : Returns true if the passed value is a valid email id. Please read the function 
		to see the conditions that are being checked to validate the email id.
7. IsValid_Name()
		Args : sValue (any string)
		Returns : boolean true or false
		Conditions : Returns false if the passed value has any leading spaces or starts with any other character other
		than a-z (or A-Z).
***************************************************************************************************
*/


function isNotBlank(sValue)
{
	var iLen = sValue.length; // Stores the length of the passed parameter.
	var pad = " ";			//	Variable to store a value composed of only spaces and equal to the length
							// of the passed parameter.
							
	for (i=1 ; i < iLen ; i++)
	{
		pad = pad + " ";
	}
	if ((sValue != "") && (sValue != pad))
	{
		return true;
	}
	else
	{				
		return false;
	}

}


function isPureNumeric(sValue)
{
	// A pure numeric number (for eg. A US Zip Code should not contain periods,braces,hyphens or spaces.
	if (isNaN(sValue) || (sValue.indexOf(".") != -1 ) || (sValue.indexOf("-") != -1 ) || (!isNotBlank(sValue)) || (sValue.indexOf(" ") != -1 ))
	{
		return false;
	}else return true;
}

function isNumeric(sValue)
{
	// A numeric value can include decimal points,leading spaces and  hyphens to indicate negative values
	if (isNaN(sValue))
	{
		return false;
	}else return true;
}


function IsValid_US_Phone_Or_Fax(sValue)
{	
	
	if (sValue.length != 12 || (!isNotBlank(sValue)) || (sValue.charAt(0) == "0"))
	{
		return false;
	}else
		{
			var firstPart = sValue.substring(0,3);
			var firstHyphen = sValue.substring(3,4);
			var secondPart = sValue.substring(4,7);
			var secondHyphen = sValue.substring(7,8);
			var thirdPart = sValue.substring(8,12);
			if (!isPureNumeric(firstPart) || !isPureNumeric(secondPart) || !isPureNumeric(thirdPart) || firstHyphen != "-" || secondHyphen != "-")
					{
						return false
					}else
						{
							return true;	
						}
		}
}

function isValidPhoneValue(phoneValue) 
{
	var string = phoneValue;
	if (isNotBlank(string) && string.search(/^[0-9][0-9][0-9]\-[0-9][0-9][0-9]\-[0-9][0-9][0-9][0-9][ ]{0,}[^~]{0,}$/) != -1)
	{
		 return true;
	}
    else
	{
        return false;
	}
}

function IsAlpha_Numeric(sValue)
{
	var Alpha_Numeric_Set = /[a-zA-Z0-9]/;
	if ((sValue.search(Alpha_Numeric_Set) >= 0) && (sValue.charAt(0) != " "))
	{
		return true;
	}else
	{
		return false;
	}
}

function isValidEmail(sValue)
{
	
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$/;

	if((sValue.search(exclude) != -1)||(sValue.search(check) == -1)||(sValue.search(checkend) == -1))
	{
		return false; //Incorrect email address
	}
	else
	{
		return true; //Email address format OK.
	}
/*
Notes:
'exclude' checks 5 conditions:
a) characters that should not be in the address
b) characters that should not be at the start
c) & d) characters that shouldn't be together
e) there's not more than one '@'
'check' checks there's at least one '@', later followed by at least one '.'
'checkend' checks the address ends with a period followed by 2 or 3 alpha characters
*/

}

function IsValid_Name(sValue)
{
	var Alphabet_Set = /[a-zA-Z]/;
	if ((sValue != "") && (sValue.charAt(0).search(Alphabet_Set) != -1))
	{
		return true;
	}else
		{
			return false;
		}
}
// End of File 





