  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 validateZIP(field) 
  {
    if (!(trim(field))=="")
    {
      var valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var hyphencount = 0;
      if (field.length!=5 && field.length!=10) 
      {
        alert("You have entered an invalid Zip Code.  Please enter a 5-digit or a 9-digit Zip Code: ‘12345’ or ‘12345-6789’");
        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("The Zip Code you entered contains invalid characters.  Please try again.");
          return false;
        }
        if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
        {
                alert("Use a hyphen to properly format a 9-digit Zip Code: ‘12345-6789.’   Please try again.");
          return false;
        }
      }
    }
    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 check_email(e) 
    {
      var ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

      for(i=0; i < e.length ;i++)
      {
        if(ok.indexOf(e.charAt(i))<0)
        { 
          return (false);
        }	
      } 

      if (document.images)
      {
        re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
        re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
        if (!e.match(re) && e.match(re_two))
        {
          return (-1);		
        } 
      }
    }

  /* function check_phonenumber(fld)
    {
      var strPhoneNumber = fld
      if (strPhoneNumber.length > 0)
      {
        // 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;

        s=stripCharsInBag(strPhoneNumber,validWorldPhoneChars);
        //return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
        if(!(isInteger(s) && s.length >= minDigitsInIPhoneNumber))
        {
          return false;
        }
        return true;
      }
      return true;
    }*/
    
    function check_phonenumber(fld)
    {
      var phone = fld.value
      var matchArr = phone.match(/^(\d{3})-?\d{3}-?\d{4}$/);
      var numDashes = phone.split('-').length - 1;
      if (matchArr == null || numDashes == 1) {
  
            alert('You have entered an invalid phone number. The phone number must contain 10-digits: ‘123-456-7890.’');
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else 
      if (parseInt(matchArr[1],10)==0) {
        alert("You have entered an invalid area code. Please enter a valid area code.");
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else {
      //msg = "appears to be valid";
      
      return true;
      }
    }
    
    
     function check_cellphonenumber(fld)
    {
      var phone = fld.value
      var matchArr = phone.match(/^(\d{3})-?\d{3}-?\d{4}$/);
      var numDashes = phone.split('-').length - 1;
      if (matchArr == null || numDashes == 1) {
           alert('You have entered an invalid cell phone number. The cell phone number must contain 10-digits: 123-456-7890.');
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else 
      if (parseInt(matchArr[1],10)==0) {
            alert("You have entered an invalid area code.  Please enter a valid area code.");
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else {
      //msg = "appears to be valid";
      
      return true;
      }
    }
    
    
    function check_faxnumber(fld)
    {
      var fax = fld.value
      var matchArr = fax.match(/^(\d{3})-?\d{3}-?\d{4}$/);
      var numDashes = fax.split('-').length - 1;
      if (matchArr == null || numDashes == 1) {
          alert("You have entered an invalid fax number.  The fax number must contain 10-digits: ‘123-456-7890.’");
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else return true
    }
    
    function check_pagernumber(fld)
    {
      var pager = fld.value
      var matchArr = pager.match(/^(\d{3})-?\d{3}-?\d{4}$/);
      var numDashes = pager.split('-').length - 1;
      if (matchArr == null || numDashes == 1) {
           alert("You have entered an invalid pager number. The pager number must contain 10-digits: '123-456-7890.'");
      msg = "does not appear to be valid";
      //fld.focus();
      return false;
      }
      else return true
    }
    
  function validatePhoneNumber(e)
  {
    if((isInteger(String.fromCharCode(e.keyCode)))||(String.fromCharCode(e.keyCode)=="-")||(String.fromCharCode(e.keyCode)=="+")||(String.fromCharCode(e.keyCode)==" "))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
  function validateZipNumber(e)
  {
    var valid = "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if (valid.indexOf(String.fromCharCode(e.keyCode)) == "-1")
    {
      return false;
    }
    else
    {
      return true;
    }
  }
  function validateConfNumber(e)
  {
    var valid = "0123456789";
    if (valid.indexOf(String.fromCharCode(e.keyCode)) == "-1")
    {
      return false;
    }
    else
    {
      return true;
    }
  }

function ltrim ( s )
{
  return s.replace( /^\s*/, "" );
}

function rtrim ( s )
{
  return s.replace( /\s*$/, "" );
}

//Combine the rtrim() and ltrim() functions to make the trim() function, which just wraps both calls together:

function trim ( s )
{
  return rtrim(ltrim(s));
}

function changeCase(frmObj)
{
  var oldValue = frmObj.value;
  var arrTemp = oldValue.split(" ");
  var newValue = new String;
  var tempString = new String;
  var strLen;
  var blnConverted;
  for (var loop=0; loop < arrTemp.length; loop++)
  {
    //document.writeln(friend_array[loop] + " is my friend.<br>");
    tempString = arrTemp[loop]
    strLen = tempString.length 
    if(loop==0)
    {
      newValue = tempString.substring(0,1).toUpperCase() + tempString.substring(1,strLen).toLowerCase();
    }
    else
    {
      //we are not converting a name so we have to not cap words like the and to
      //rule for to,the,and,of
      if((tempString.toLowerCase()=="de")||(tempString.toLowerCase()=="to")||(tempString.toLowerCase()=="the")||(tempString.toLowerCase()=="and")||(tempString.toLowerCase()=="of"))
      {
        newValue = newValue + " " + tempString.toLowerCase();
      }
      else
      {
        newValue = newValue + " " + tempString.substring(0,1).toUpperCase() + tempString.substring(1,strLen).toLowerCase();
      }
    }  
  }
  //Now we need to check for periods
  oldValue = newValue;
  arrTemp = oldValue.split(".");
  newValue = new String;
  tempString = new String;
  for (var loop=0; loop < arrTemp.length; loop++)
  {
    tempString = arrTemp[loop]
    strLen = tempString.length
    if(loop==0)
    {
      newValue = tempString    
    }
    else
    {
      newValue = newValue + "." + tempString.substring(0,1).toUpperCase() + tempString.substring(1,strLen)    
    }
  }  
  
  
  frmObj.value = newValue;
  return true;
}


function changeToLowerCase(frmObj)
{
  var oldValue = frmObj.value;
  var newValue = new String;
  newValue = oldValue
  newValue = newValue.toLowerCase()
  frmObj.value = newValue;
  return true;
}

function checkDateFormat(dateValue)
{
  dates = dateValue.split("/");
 
  if(dates.length!=3)
    return "1";
  if(dates[0].length!=2 ||dates[1].length!=2 || dates[2].length!=4)
    return "1";
  if(isNaN(dates[0]) || isNaN(dates[0] || isNaN(dates[1]) )) 
    return "2";
  return "0";
}

function CheckDate(obj)
{ 
if (obj.value != '') {
    if(checkDateFormat(obj.value)=="1") 
    {
     
      alert('Please enter the date in the following format: MM/DD/YYYY');
      return false;
    }
    if(checkDateFormat(obj.value)=="2") 
    {
      alert('Please enter a valid date: MM/DD/YYYY');
      return false;
    }
    if(checkDateFormat(obj.value)=="0")
      return true;
  }
else { return true;}  
}

function doAlert(strString){
	alert(strString);
};

function SSNValidation(frmssn) {
var ssn = frmssn.value
var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
var numDashes = ssn.split('-').length - 1;
if (matchArr == null || numDashes == 1) {
alert('You have entered an invalid SSN. The SSN must contain 9-digits: 123-45-6789.');
msg = "does not appear to be valid";
frmssn.focus();
return false;
}
else 
if (parseInt(matchArr[1],10)==0) {
alert("You have entered an invalid SSN. The SSN cannot begin with 000.");
msg = "does not appear to be valid";
frmssn.focus();
return false;
}
else {
 
return true;
   }
}


//javascript routine to validate international numbers

function CheckIntPhoneNumber(TheNumber) {
	var valid = 1
	var GoodChars = "0123456789()-+ "
	var i = 0
	if (TheNumber=="") {
		// Return false if number is empty
		valid = 0
	}
	for (i =0; i <= TheNumber.length -1; i++) {
  		if (GoodChars.indexOf(TheNumber.charAt(i)) == -1) {
  // Note: Remove the comments from the following line to see this
  // for loop in action.
  // alert(TheNumber.charAt(i) + " is not valid.")
  			valid = 0
  		} // End if statement
	} // End for loop
	return valid
}

//Formatting functions
function formatPhone(str){
	str = strip("*() -./_\n\r\t\\",str);
	 
	if(str.length==10)
		return reformat(str,"",3,"-",3,"-",4);
	 
}
   
   // Support Functions
function strip(filter,str){
	var i,curChar;
	var retStr = '';
	var len = str.length;
	for(i=0; i<len; i++){
		curChar = str.charAt(i);
		if(filter.indexOf(curChar)<0) //not in filter, keep it
			retStr += curChar;
	}
	return retStr;
}
function reformat(str){
	var arg;
	var pos = 0;
	var retStr = '';
	var len = reformat.arguments.length;
	for(var i=1; i<len; i++){
		arg = reformat.arguments[i];
		if(i%2==1)
			retStr += arg;
		else{
			retStr += str.substring(pos, pos + arg);
			pos += arg;
		}
	}
	return retStr;
}
//End Support Functions 
