
      // whitespace characters
      var whitespace = " \t\n\r";
		
	  // used for page level validation	
	  var strMessage="";
	  
      /****************************************************************/

      // 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 ForceEntry(val, str) {
           var strInput = new String(val.value);

           if (isWhitespace(strInput)) {
                   strMessage = strMessage + "\n" + str;
                   return false;
           } else
		   {
                return true;
			}	
				

      }

      /****************************************************************/
      // Returns true if the string passed in is a valid number
      //  (no alpha characters), else it displays an error message
     
	 function ForceNumber(objField, str)
      {
	    var strField = new String(objField.value);
    	if (isWhitespace(strField)) return true;
        	var i = 0;
            for (i = 0; i < strField.length; i++)
        		if (strField.charAt(i) < '0' || strField.charAt(i) > '9') {
 	    			strMessage = strMessage + "\n" + str;
    			return false;
	          	}
        	return true;
      }

/****************************************************************/	  
      // require at least one radio button be selected

       function ForceRadio(val,str)
        {
            var radioSelected = false;
            
            for (i = 0;  i < val.length;  i++)
             {
		if (val[i].checked)
		radioSelected = true;
	      }
		
                if (!radioSelected)
                 {
 	    			strMessage = strMessage + "\n" + str;
                    return false;
                 } 

	}

      /****************************************************************/
	// alert if the box is NOT checked
	function ForceCheckBox(val,str){
 
           if (!val.checked){
				strMessage = strMessage	 + "\n" + str ;
			 }
        }

      /****************************************************************/
     function emailCheck (val) {
        var emailStr = val.value;
       var checkTLD=1;
       var knownDomsPat=/^(COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM|com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
       var emailPat=/^(.+)@(.+)$/;
       var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
       var validChars="\[^\\s" + specialChars + "\]";
       var quotedUser="(\"[^\"]*\")";
       var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
       var atom=validChars + '+';
       var word="(" + atom + "|" + quotedUser + ")";
       var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
       var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
       var matchArray=emailStr.match(emailPat);
     
	   if (matchArray==null) {
          strMessage = strMessage + "\n" + "Email address seems incorrect (check @ and .'s)";
          return false;
        }
       var user=matchArray[1];
       var domain=matchArray[2];

       for (i=0; i<user.length; i++) {
          if (user.charCodeAt(i)>127) {
            strMessage = strMessage + "\n" + "Ths username contains invalid characters." ;
            return false;
          }
        }

        for (i=0; i<domain.length; i++) {
           if (domain.charCodeAt(i)>127) {
            strMessage = strMessage + "\n" +  "Ths domain name contains invalid characters.";
            return false;
          }
       }

        if (user.match(userPat)==null) {
          strMessage = strMessage + "\n" +  "The username doesn't seem to be valid.";
          return false;
        }

         var IPArray=domain.match(ipDomainPat);
         if (IPArray!=null) {
           for (var i=1;i<=4;i++) {
              if (IPArray[i]>255) {
                 strMessage = strMessage + "\n" +  "Destination IP address is invalid!";
                 return false;
               }
            }
           return true;
          }
 
         var atomPat=new RegExp("^" + atom + "$");
         var domArr=domain.split(".");
         var len=domArr.length;
         for (i=0;i<len;i++) {
           if (domArr[i].search(atomPat)==-1) {
               strMessage = strMessage + "\n" +  "The domain name does not seem to be valid.";
               return false;
             }
        }
        if (checkTLD && domArr[domArr.length-1].length!=2 && 
         domArr[domArr.length-1].search(knownDomsPat)==-1) {
         strMessage = strMessage + "\n" +  "The address must end in a well-known domain or two letter " + "country.";
         return false;
       }

        if (len<2) {
           strMessage = strMessage + "\n" +  "This address is missing a hostname!";
           return false;
         }
       return true;
     }
      /****************************************************************/
// Displays an alert box with the passed in string...

function PromptErrorMsg(Field,strError)
{
	strMessage = strMessage + "\n" + strError;
	Field.focus();
}

/****************************************************************/
	  
 function ForceDate(strDate,strError)
{
	var str = new String(strDate.value);

	if (isWhitespace(str)) {
		return true;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != "-") && i < count)
		i++;

	if (i == count || i > 2) {
	   strMessage = strMessage + "\n" + strError;
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
     	strMessage = strMessage + "\n" + strError;
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != "-") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
     	strMessage = strMessage + "\n" + strError;
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
    	strMessage = strMessage + "\n" + strError;
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
     	strMessage = strMessage + "\n" + strError;
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
     	strMessage = strMessage + "\n" + strError;
		return false;
	}

	return true;
}

/****************************************************************/

// This function determines if the string passed in is a valid
// US zip code.  It accepts either ##### or #####-####.  If the
// string is valid, it returns true, else false.

function isZipCode(theElement,msg) {
str = theElement.value;
len = String(str).length;

if( (len != 5) && (len != 10) ) {
        strMessage = strMessage + "\n" + msg;
    return false;
    }
for(i = 0; i < len; i++) {
    c = str.charAt(i);
    if( (len == 10) && (i == 5) ) {
        if (c != "-") {
        strMessage = strMessage + "\n" + msg;
        return false;
        }
    } else {
    if( (c < "0") || (c > "9") ) {
        strMessage = strMessage + "\n" + msg;
        return false;
	}// end if
	}// end else 
}// end for
return true;
}// end function
/****************************************************************/
function chkpassword(pw1,pw2){
    if(pw1.value != pw2.value){
	    strMessage = strMessage + "\n" +  "Password dosn't match with Confirm password";
		
		return false;
    }
    return true;
}
/****************************************************************/
function ForceSelect(field, strmsg){
    var sel = field.options[field.selectedIndex].value;
    if (sel ==""){
	strMessage = strMessage + "\n" +strmsg;
	return false;
    }
    return true;
}
/****************************************************************/
function IsStringAllowedLength(stringA, lengthLimitA, messageString) {
	if (stringA.length > lengthLimitA) {                          
			strMessage = strMessage + "\n" + messageString;
			return false;
	} else  {
		return true;
	}
}

