// isWhitespace (s)                    Check whether string s is empty or whitespace.
// isEmpty(s)                          Check whether string s is empty. 
// isDigit (c)                         Check whether character c is a digit 
// isInteger (s [,eok])                True if all characters in string s are numbers.
// isEmail (s [,eok])                  True if string s is a valid email address.
// isDate (year, month, day)           True if string arguments form a valid date.
// isYear (s [,eok])                   True if string s is a valid Year number.
// isMonth (s [,eok])                  True if string s is a valid month between 1 and 12.
// isDay (s [,eok])                    True if string s is a valid day between 1 and 31.
// daysInFebruary (year)               Returns number of days in February of that year.
// isUrl (s)                           True if string s is a valid URL.
// hasMinLength(v,min)                 TRUE if string is grater than min length 

var whitespace = " \t\n\r";
var defaultEmptyOK = false


//#########################################################################
//############################ Empty String ###############################
//#########################################################################
// Check whether string s is empty.

function isEmpty(s)
{   
    return ((s == null) || (s.length == 0))
}

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 checkEmpty(field,msg)
{
	if(isWhitespace(field.value) || isEmpty(field.value) )
     {
                alert(msg);
                field.focus();
                return true;
     }
}
//#########################################################################
//################################ Email ##################################
//#########################################################################
// isEmail (STRING s [, BOOLEAN emptyOK])
// 
// Email address must be of form a@b.c -- in other words:
// * there must be at least one character before the @
// * there must be at least one character before and after the .
// * the characters @ and . are both required
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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;

        // look for @
        while ((i < sLength) && (s.charAt(i) != "@"))
        { i++
        }

        if ((i >= sLength) || (s.charAt(i) != "@")) return false;
        else i += 2;

        // look for .
        while ((i < sLength) && (s.charAt(i) != "."))
        { i++
        }

        // there must be at least one character after the .
        if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
        else return true;
}

function checkMail(field,msg)
{
	if(!isEmail(field.value))
     {
                alert(msg);
                field.focus();
                return true;
     }
}
//#########################################################################
//############################## Integer ##################################
//#########################################################################

// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   
    return ((c >= "0") && (c <= "9"))
}
// isInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating 
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true), 
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true 
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

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 checkInteger(field,msg)
{
	if(!isInteger(field.value) && !checkDecimals(field,msg))
     {
                //alert(msg);
				field.value="";
                field.focus();
                return true;
     }
	
			
}
function checkOnlyInteger(field,msg)
{
	if(!isInteger(field.value))
     {
                alert(msg);
				field.value="";
                field.focus();
                return true;
     }
	
			
}
//#########################################################################
//############################## Drop Down ################################
//#########################################################################
// Check whether drop down box s is not selected.
function isSelected(s)
{   
    return ((s == 0) || (s == "") || (s == "-1"))
}

// Returns true if string s is empty or 
// whitespace characters only.


function checkDropdown(field,msg)
{
	if(isSelected(field.value))
     {
                alert(msg);
                field.focus();
                return true;
     }
}
//#########################################################################
//############################## Upload Field #############################
//#########################################################################

function filterFileType(field, ext) 
{
if (field.value.indexOf('.' + ext) == -1) {
return false;
}
return true;
} // end function filterFileType

function checkUpload(field,msg,ext)
{
	if (!filterFileType(field,ext))
     {
                alert(msg);
                field.focus();
                return true;
     }
}
//#########################################################################
//############################## URL ######################################
//#########################################################################
function isUrl(s)
{
    var temp=new Array()
    if (s!="")
    {
        var pos1=s.length;
        var value=s;
        pos1=pos1-4
        value=value.substring(pos1,pos1+1)
        
        var pos2=StringTrim(s).indexOf(".",0);
        if (pos2 == -1 || pos2<3 ) 
        {
            return false;
        }
        
        var arrEndUrl=new Array()
        arrEndUrl=[".com",".net",".org",".edu",".uni",".in",".uk",".ac",".de"]
        for(i=0;i<arrEndUrl.length;i++)
        {
            pos2=(StringTrim(s)).indexOf(arrEndUrl[i],0);
            if(pos2!=-1)
                break;
            
        }
        if (pos2 == -1) 
        {
            return false;
        }
        
        var arrEndUrl=new Array()
        arrEndUrl=["http://","www.","ftp://","https://"]
        for(i=0;i<arrEndUrl.length;i++)
        {
            pos2=StringTrim(s).indexOf(arrEndUrl[i],0);
            if(pos2!=-1)
                break;
        }
        
        
        if (pos2 == -1) 
        {
            return false;
        }
        return true ;
    }   
}

function StringTrim(objvalue)
{
    var TestString = objvalue;
    var SpaceChar  = " ";
    while (TestString.charAt(0) == SpaceChar) {TestString = TestString.substr(1)};
    while (TestString.charAt(TestString.length-1) == SpaceChar) {TestString = TestString.substr(0,TestString.length-1)};
    return TestString.toString();
}


function checkUrl(field,msg)
{
	if(!isUrl(field.value))
     {
                alert(msg);
                field.focus();
                return true;
     }
}

//#########################################################################
//############################ Checkbox Array #############################
//#########################################################################

 //Function To validate checkbox array
function checkBoxArray(Fldname,Msg)
{
var len=Fldname.length;
var chk=-1;
for (var i = 0;i<len;i++)
{	
	if(Fldname[i].checked==true)
	{
		chk=i;
	}
//alert(document.Frm["normalCheckBoxes[]"][i].checked);
}
		if(chk==-1)
		{
			alert(Msg);
			return false;
		}	
		return true;
}


//#########################################################################
//########################Select Al least one Option#######################
//#########################################################################
//for radio button

function checkOptButton(Fldname,Msg)
{
	// place any other field validations that you require here
	// validate myradiobuttons
	myOption = -1;
	for (i=0; i<Fldname.length; i++) 
	{
		if (Fldname[i].checked)
		{
			myOption = i;
		}
	}
	if (myOption == -1)
	{
		alert(Msg);
		return true;
	}
	else
	{
	   return false;
	}

	/*
	alert("You selected button number " + myOption
	+ " which has a value of "
	+ Fldname[myOption].value);
	*/

}

//#########################################################################
//############################ Alphanumeric ###############################
//#########################################################################

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 isLetter (c)
{   
    return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == "_") )
}



// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   
    return ((c >= "0") && (c <= "9"))
}

//#########################################################################
//######################## Non negative Integer ###########################
//#########################################################################

// isNonnegativeInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if string s is an integer >= 0.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}
// isSignedInteger (STRING s [, BOOLEAN emptyOK])
// 
// Returns true if all characters are numbers; 
// first character is allowed to be + or - as well.
//
// Does not accept floating point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.
//
// EXAMPLE FUNCTION CALL:          RESULT:
// isSignedInteger ("5")           true 
// isSignedInteger ("")            defaultEmptyOK
// isSignedInteger ("-5")          true
// isSignedInteger ("+5")          true
// isSignedInteger ("", false)     false
// isSignedInteger ("", true)      true

function isSignedInteger (s)

{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;

        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

        // skip leading + or -
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

//#########################################################################
//########################## Telephone Number #############################
//#########################################################################

function checktelephonenumber(s)
{
    var numVal=s;
    var len=numVal.length;
    if (len > 0) 
    {
        for ( var i=0 ; i<len ; i++)
        {
            var strVal=numVal.charAt(i);
            if ( strVal != 1 && strVal != 2 &&  strVal != 3&& strVal != 4&& strVal != 5&& strVal != 6&& strVal != 7&& strVal != 8&& strVal != 9&& strVal != 0 && strVal!='(' && strVal!=')' && strVal!='-' ) 
            {
                return false;
            }
        }
    }
    return true;
}

//#########################################################################
//############################### Fax Number ##############################
//#########################################################################

function checkfaxnumber(s)
{
    var numVal=s;
    var len=numVal.length;
    if (len > 0) 
    {
        for ( var i=0 ; i<len ; i++)
        {
            var strVal=numVal.charAt(i);
            if ( strVal != 1 && strVal != 2 &&  strVal != 3&& strVal != 4&& strVal != 5&& strVal != 6&& strVal != 7&& strVal != 8&& strVal != 9&& strVal != 0 && strVal!='(' && strVal!=')' && strVal!='-' ) 
            {
                return false;
            }
        }
    }
    return true;
}
//#########################################################################
//###################function to open new window###########################
//#########################################################################

function wopen(url, w, h)
{
// Fudge factors for window decoration space.
 // In my tests these work well on all platforms & browsers.
w += 32;
h += 96;
 var win = window.open(url,
  'popup', 
  'width=' + w + ', height=' + h + ', ' +
  'location=no, menubar=no, ' +
  'status=no, toolbar=no, scrollbars=no, resizable=no');
 win.resizeTo(w, h);
 win.focus();
}



//#########################################################################
//###################function to validate US phone no #####################
//#########################################################################

/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}


//#########################################################################
//###################function to validate US zip code #####################
//#########################################################################


<!-- Begin
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
   }
}
return true;
}
//  End -->



//#########################################################################
//###################function to validate Decimal value ###################
//#########################################################################


<!-- Begin
function checkDecimals(fieldName,msg) {

decallowed = 2;  // how many decimals are allowed?
var fieldValue = fieldName.value;

if (isNaN(fieldValue) || fieldValue == "") {
//alert("Please enter a valid number.");
alert(msg);
fieldName.select();
fieldName.focus();
}
else {
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

if (dectext.length > decallowed)
{
alert ("Please enter a number with up to " + decallowed + " decimal places.  Please try again.");
fieldName.select();
fieldName.focus();
      }
else {
		//alert ("That number validated successfully.");
		return true;
      }
   }
}
//  End -->


//#########################################################################
//###################function to validate Price ###################
//#########################################################################


<!-- Begin
function checkDecimalsPrice(fieldName) {

var re = /\$|,|/g;

decallowed = 2;  // how many decimals are allowed?

var fieldValue = fieldName.value.replace(re, ""); 

if (isNaN(fieldValue) || fieldValue == "") {
alert("Please enter a valid number.");
fieldName.select();
fieldName.focus();
}
else {
if (fieldValue.indexOf('.') == -1) fieldValue += ".";
dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

if (dectext.length > decallowed)
{
alert ("Please enter a number with up to " + decallowed + " decimal places.  Please try again.");
fieldName.select();
fieldName.focus();
      }
else {
		//alert ("That number validated successfully.");
		return true;
      }
   }
}



//#########################################################################
//###########function to Check Word Limit In Textarea######################
//#########################################################################

function count_words(tbox_input)
{
var msg = "";
var c = 0;
w = tbox_input.value.split(" ");
no_words = w.length;
for (x = 0; x < no_words; x++)
{
if (c >= 200)
{
tbox_input.value = msg;
return true;
break;
}
msg = msg + w[x] + " ";
c++;
}
return false;
}

function checkcountwords(field,msg)
{
if(count_words(field))
     {
           alert(msg);
           field.focus();
           return true;
     }
}



//#########################################################################
//########################### Checkbox validation##########################
//#########################################################################

 //Function To validate checkbox array
function checkBoxvalidation(Fldname,Msg)
{
		if(!Fldname.checked)
		{
			alert(Msg);
			return true;
		} 
  }

//  End -->



