
// This function will check for the Email format Eg. a@b.c
function isEmail (s)
{
   var reEmail = /^.+\@.+\..+$/
   if (isEmpty(s))
	   return false;
    else {
	    return reEmail.test(s)
    }
}

//This function returns true if string will check the given string is a Empty string
function isEmpty(s)
{
   return ((s == null) || (s.length == 0))
}


//This function returns true if string s is a valid Digit
function isDigit (s)
{
	var reDigit = /^\d/
    return reDigit.test(s)
}

//This function returns true if string s is a valid U.S. Phone
//number.  
function isUSPhoneNumber (s)
{
   digitsInUSPhoneNumber = 12
   digitsInInterPhoneNumber = 14 
	
   reDigit = /[0-9][0-9][0-9][-][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]/
   reDigitInter = /[0-9][-][0-9][0-9][0-9][-][0-9][0-9][0-9][-][0-9][0-9][0-9][0-9]/
   if (isEmpty(s)) 
		return false;
    return(((reDigit.test(s)) && s.length == digitsInUSPhoneNumber) || ((reDigitInter.test(s)) && s.length == digitsInInterPhoneNumber))
}


// This function returns true if all characters in string s are numbers.
function isInteger (s)
{
   var reInteger = /^\d+$/
   var i;

    if (isEmpty(s)) 
		return false;
    return reInteger.test(s)
}

// This function returns true if string s is English letters 
// (A .. Z, a..z) and numbers only.
function isAlphanumeric (s)
{
    var i;
	var reAlphanumeric = /^[a-zA-Z0-9]+$/
    if (isEmpty(s)) 
		return false;
    else {
       return reAlphanumeric.test(s)
    }
}

function validatethis(ctl,option)
{
	switch (option)
	{
		case "phone" :
			if (isUSPhoneNumber(ctl.value) == false)
			{
				alert('Enter a Valid Phone Number (For Example 121-121-1234) or 1-123-123-1322'); 
				ctl.value= '';
				//ctl.focus();
			}
			break;
		
		case "ephone" :
			if (!isEmpty(ctl.value))
			{
				if (isUSPhoneNumber(ctl.value) == false)
				{
					alert('Enter a Valid Phone Number (For Example 121-121-1234 or 1-123-123-1322)'); 
					ctl.value= '';
					//ctl.focus();
				}
			}
			break;
			
		case "fax" :
			if (!isEmpty(ctl.value))
			{
				if (isUSPhoneNumber(ctl.value) == false)
				{
					alert('Enter a Valid Fax Number (For Example 121-121-1234 or 1-123-123-1322)'); 
					ctl.value= '';
					//ctl.focus();
				}
			}
			break;
		case "email" :
			if (isEmail(ctl.value) == false) 
			{
				alert('Enter a Valid EMail Address (For Example abc@efg.com)'); 
				ctl.value= '';
				//ctl.focus();
			}
			break;
			default :
				break;
	}
} 
//function to restrict the textarea value
function RestrictTextArea(obj,count)
{
	if (obj.value.length > count)
		obj.value = obj.value.substring(0,count);
}

//To validate the time 
function isValidTime(s)
{
   reDigit = /[0-9][0-9][:][0-9][0-9][A||a||p||P][M||m]/
   if (isEmpty(s)) 
		return false;
    return(reDigit.test(s))
}