//This function checks if the email is valid
function isEmail(emailVal)
{
	var errStr = "" //Hold The error 
    var regex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;

	if (emailVal.length <=0)
		errStr = errStr+"Enter the e-mail address. it should be like you@yourisp.com\n";
	else
	{
	    emailVal = emailVal.replace(/^\s+|\s+$/g, ''); // replace leading and trailing spaces

		if (!regex.test(emailVal))
		{
			errStr = errStr+"Enter the correct e-mail. it should be like you@yourisp.com\n";
		}
	}	
	return errStr;	//return the error string
 }
 
 //This function checks a comma-delimited list of email addresses (or just one email address) and validates each via isEmail()
 //returns false if any email address in the list fails.
 function isEmailList(emailVal) {
	var errStr = "";
	var arrEmails = emailVal.split(",");
	var x;
	for (x = 0; x < arrEmails.length; x++) {
		errStr = isEmail(arrEmails[x]);
		if (errStr != "") {return "One or more of the email addresses entered are not valid.  Please verify the format, eg: you@yourisp.com,another@isp.com\n";}
	}
	return errStr;
 }
 
 
 
 //This function is used to check if the phone number is valid
 function isPhone(phoneVal)
 {
	var errStr = "";	//to hold the error string
	var strModPhone;
	
	if (phoneVal.length <=0)
		errStr = errStr+"Enter the Phone number\n";
	else
	{
		strModPhone = phoneVal.replace(/[\s()\.-]/g,"");
		if (!strModPhone.match(/^\+{0,1}[0-9]+(ext|ext\.|x){0,1}[0-9]*$/gi))
		{
			errStr = errStr + "Enter Only Numbers, (), +, ., e, x, t, and - in phone number field\n";
		}
	}
	
	return errStr;
 }
 
 //This function checks if the value passed is numeric. If not it returns false
function isNumeric(inputValue)	{
	
	//Intialize the return flag
	var bReturnFlag = true;
	
	//Check for the validity of the input value
	if (inputValue.length <=0)
		bReturnFlag = false;
	else
	{
		for (var i = 0; i < inputValue.length; i++) {
			testChar = inputValue.charAt(i);
			if(testChar >= '0' && testChar <= '9')
				continue;
		bReturnFlag = false;
		break;
		}
	}
	
	return bReturnFlag;
}
 
 //This function checks if the valed passed is empty .if so it returns  true
function isEmpty(inputValue)	{
	
	//Intialize the return flag
	var bReturnFlag = true;
	
	//Check for the validity of the input value
	//Check for length of the input value if it is  <= 0 then return true
	//if it is greateer than 0 then check if we have only spaces in the field
	if (inputValue.length <=0)
		bReturnFlag = true;
	else
	{
		for (var i = 0; i < inputValue.length; i++) {
			testChar = inputValue.charAt(i);
			if(testChar == ' ')
				continue;
		bReturnFlag = false;
		break;
		}
	}
	
	return bReturnFlag;
}

