var defaultEmptyOK = false;
var whitespace = " \t\n\r";
function isEmpty(s){return ((s == null) || (s.length == 0))}

function isEmail(s)
{
	if(s=="")return false;
	else{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(s))return true;
		else return false;
	}
}

function isWhitespace (s)

{   var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }

    return true;
}

		function CheckDate(imonth,iday,iyear,descr){
		badmonth = false;
		badday = false;
		badyear = false;
		ierrors = "";
		if(!isNumeric(imonth))badmonth = true;
		if(!isNumeric(iday))badday = true;
		if(!isNumeric(iyear))badyear = true;
		if(!badmonth && eval(imonth) > 12)badmonth = true;
		if(!badday && eval(iday) > 31)badday = true;
		if(!badyear && iyear.length < 4)badyear = true;
		imonth = imonth - 1;
		if(!badyear && !badmonth && !badday){
			TempDate = new Date(iyear,imonth,iday);
			if(iyear != TempDate.getFullYear())badyear = true;
			if(eval(imonth) != TempDate.getMonth())badmonth = true;
			if(iday != TempDate.getDate())badday = true;
		}
			if(badmonth)ierrors+="\nPlease enter in a valid month for " + descr;
			if(badday)ierrors+="\nPlease enter in a valid day for " + descr;		
			if(badyear)ierrors+="\nPlease enter in a valid year for " + descr;
		return ierrors;	
		}

function SSNValidation(ssn) {
	var matchArr = ssn.match(/^(\d{3})-?\d{2}-?\d{4}$/);
	var numDashes = ssn.split('-').length - 1;
	if (matchArr == null || numDashes == 1) return false;
	else if (parseInt(matchArr[1],10)==0) return false;
	else return true;
}

function replace(string,substring1,substring2) {
	temp = "" + string; // temporary holder

	while (temp.indexOf(substring1)>-1) {
	pos= temp.indexOf(substring1);
	temp = "" + (temp.substring(0, pos) + substring2 + 
	temp.substring((pos + substring1.length), temp.length));
	}
	return temp;
}

function isNumeric(sText)
{
   sText = replace(sText,",","");
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
if(sText!=""){
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   }
   else return false;//if empty
   }
