
      // 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(val,str) {
    str = theElement.value;
    len = str.length;
    if( (len != 5) && (len != 10) ) {
         strMessage = strMessage + "\n" + str;
       return false;
     }
    for(i = 0; i < len; i++) {
       c = str.charAt(i);
       if( (len == 10) && (i == 5) ) {
         if (c != "-") {
         strMessage = strMessage + "\n" + str;
          return false;
          }
        } else {
        if( (c < "0") || (c > "9") ) {
         strMessage = strMessage + "\n" + str;
          return false;
    } } } }
/****************************************************************/
   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;
	   }
      }
	  
	  /****************************************************/
	  // Phone number validation and Date validation
	  /****************************************************/
	  	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 PhoneCheck(strphone)
		{
			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;
			
			s=stripCharsInBag(strphone,validWorldPhoneChars);
			return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
		}
		
		//date
		function daysInFebruary (year){
			// February has 29 days in any year evenly divisible by four,
			// EXCEPT for centurial years which are not also divisible by 400.
			return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
		}
		function DaysArray(n) {
			for (var i = 1; i <= n; i++) {
				this[i] = 31
				if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
				if (i==2) {this[i] = 29}
		   } 
		   return this
		}
		
		function isDate(field){
			var dtStr = field.value;
			
			var dtCh= "/";
			var minYear=1900;
			var maxYear=2100;
		
			var daysInMonth = DaysArray(12)
			var pos1=dtStr.indexOf(dtCh)
			var pos2=dtStr.indexOf(dtCh,pos1+1)
			var strMonth=dtStr.substring(0,pos1)
			var strDay=dtStr.substring(pos1+1,pos2)
			var strYear=dtStr.substring(pos2+1)
			strYr=strYear
			if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
			if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
			for (var i = 1; i <= 3; i++) {
				if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
			}
			month=parseInt(strMonth)
			day=parseInt(strDay)
			year=parseInt(strYr)
			if (pos1==-1 || pos2==-1){
				//alert("The date format should be : mm/dd/yyyy")
				return false
			}
			if (strMonth.length<1 || month<1 || month>12){
				//alert("Please enter a valid month")
				return false
			}
			if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
				//alert("Please enter a valid day")
				return false
			}
			if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
				//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
				return false
			}
			if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
				//alert("Please enter a valid date")
				return false
			}
		return true
		}





