var whitespace = " \t\n\r";
var decimalPointDelimiter = "."

var defaultEmptyOK = false

function isEmpty(s){
	
   for(var i = 0; i < s.length; i++) 	
	{
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '\t')) 
		return false;	
	}
	return true;
}

function isWhitespace (s)
{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}
function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s)) 
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
function isEmail (s)
{   if (isEmpty(s)) 
    if (isEmail.arguments.length == 1) return defaultEmptyOK;
    else return (isEmail.arguments[1] == true);
	
    // is s whitespace?
    if (isWhitespace(s)) return false;
  
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;
	var q
	//alert(s.substr(0,1))
	if(isDigit(s.substr(0,1))) return false;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
	for(j=0;j<i;j++){
		q=s.charAt(j)
		if((isDigit(q)==false)&&(isLetter(q)==false)&&(q!="_")&&(q!=".")&&(q!="-"))return false
	} 
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;	
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    {
		q=s.charAt(i)
		if((isDigit(q)==false)&&(isLetter(q)==false)&&(q!="-")&&(q!=".")&&(q!="-"))return false 
		i++
    }    
    
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;    
	else	// Check whether invalid character after "."     
		for(var k =i ;k <s.length ; k++){
			q = s.charAt(k)
			if((isDigit(q)==false)&&(isLetter(q)==false)&&(q!="."))return false 
    }
    return true;
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

function isAlphanumeric1 (s)
{   // this function is wrote for checking the addresss like office address as well as residential address
	var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) || (c==" ")||(c=="/")||(c==",")||(c==".")||(c=="-")||(c=="'")||(c=="`")||(c=="(")||(c==")")) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}
function isPhone(s)
{   // this function is wrote for checking the addresss like office address as well as residential address
	var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);
    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (!(isDigit(c) ||(c==",") || (c=="-")) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}

function isLetter(c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) 
}

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isValiduser(s){

	for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);
      
        if ((isLetter(c)==false)&&(isDigit(c)==false)&& (c!="_")&&(c!=".")){
            return false;
        }
    }
    
}


function isAlphabetic (s)

{   var i;

    //if (isEmpty(s)) 
      // if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
      // else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if ((isLetter(c)==false)){
			if((c!="'")&&(c!="-")&&(c!="`")){
				return false;
			}
        }
    }
    // All characters are letters.
    return true;
}	

function isAlphabetic1 (s)
// this function is to alow in space in alphabetic  the 
{   var i;

    //if (isEmpty(s)) 
      // if (isAlphabetic.arguments.length == 1) return defaultEmptyOK;
      // else return (isAlphabetic.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is letter.
        var c = s.charAt(i);
        if ((isLetter(c)==false)){
			if((c!=" ")&&(c!="'")&&(c!="`")&&(c!="-")&&(c!=".")){
				return false;
			}
        }
    }
    // All characters are letters.
    return true;
}	


function isDate(sendDate)
{
	
	var mon = sendDate.substring(3,5);
	for(da=0;da<sendDate.length;da++){
		 var c = sendDate.charAt(da);
		if(c!="/"){
			if (!isDigit(c)) return false;
		}
	}
	if ((sendDate.substring(2,3) != "/") || (sendDate.substring(5,6) != "/"))
	{	
		return false;	
	}
	if ((sendDate.substring(3,5) > 12) || (isNaN(sendDate.substring(0,2))))
	{
		return false;
	}
	if (isNaN(sendDate.substring(7,8)))
	{
		return false;
	}
	else if ((sendDate.substring(0,2) > 31) || (isNaN(sendDate.substring(3,5))))
	{
		return false;
	}
	else if ((sendDate.length < 8)||(sendDate.length > 8))
	{
		return false;
	}
	else if (((mon == 04) || (mon == 06) || (mon == 09) || (mon == 11)) && ((sendDate.substring(0,2)) > 30))
	{
		return false;
	}
	else if ((mon == 02) && (sendDate.substring(0,2) > 28))
	{	
		var year = sendDate.substring(6,8);
		var yy = (((year % 4 == 0) && (!(year % 100 == 0) || (year % 400 == 0) ) ) ? 29 : 28);
		if (yy != sendDate.substring(0,2))
		{
			return false;
		}
	}
	return true;
}

function isTime(s)
{
	//alert(s.substring(0,2))
	if (s.length < 5) return false;
	if (s.substring(2,3)!=".") return false;
	if(s.substring(0,2)>24) return false;
	if(s.substring(3,5)>59) return false;
	
}

function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isvalidDate(sendDate)
{
	
	var mon = sendDate.substring(3,5);
	
	if ((sendDate.substring(2,3) != "/") || (sendDate.substring(5,6) != "/"))
	{	
		return false;	
	}
	if ((sendDate.substring(3,5) > 12) || (isNaN(sendDate.substring(0,2))))
	{
		return false;
	}
	else if ((sendDate.substring(0,2) > 31) || (isNaN(sendDate.substring(3,5))))
	{
		return false;
	}
	else if ((sendDate.length < 10)||(sendDate.length > 10))
	{
		return false;
	}
	else if (((mon == 04) || (mon == 06) || (mon == 09) || (mon == 11)) && ((sendDate.substring(0,2)) > 30))
	{
		return false;
	}
	else if ((mon == 02) && (sendDate.substring(0,2) > 28))
	{	
		var year = sendDate.substring(6,10);
		var yy = (((year % 4 == 0) && (!(year % 100 == 0) || (year % 400 == 0) ) ) ? 29 : 28);
		if (yy != sendDate.substring(0,2))
		{
			return false;
		}
	}
	return true;
}
