
function  validateNumeric( strValue ) 
{
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  return objRegExp.test(strValue);
}

function checkNum(inValue)
{
	if (!validateNumeric(inValue.value))
	{
		inValue.value = "";
		alert("Invalid number");
		return false;
	}
}

function validateEmail( strValue) 
{
	var objRegExp  = /(^[a-z]([a-z_\.-]*)@([a-z_\.-]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.-]*)@([a-z_\-.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
	
	  //check for valid email
	  return objRegExp.test(strValue);
}

// Ex. (999) 999-9999 or (999)999-9999
function validateUSPhone( strValue ) 
{
	var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
	return objRegExp.test(strValue);
}

function validateNotEmpty( strValue ) 
{
	var strTemp = strValue;
   	strTemp = trim(strTemp);
   
	if(strTemp.length > 0)
		return true;

	return false;
}

function validateUSZip( strValue ) 
{
	var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	return objRegExp.test(strValue);
}

//  Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
function validateUSDate( strValue ) 
{
    var objRegExp = /^\d{1,2}\/\d{1,2}\/\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; 
  else{
	var strSeparator = strValue.substring(strValue.indexOf("/"),strValue.indexOf("/") + 1)
    var arrayDate = strValue.split(strSeparator); 

    var arrayLookup = { '1' : 31,'3' : 31, 
                        '4' : 30,'5' : 31,
                        '6' : 30,'7' : 31,
                        '8' : 31,'9' : 30,
						'01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1]); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) 
	{
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    var intMonth = parseInt(arrayDate[0]);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
	   
       if (intDay > 0 && intDay < 29) 
	   {
           return true;
       } else if (intDay == 29)  {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || (intYear % 400 == 0)) 
		 {
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

function removeCommas( strValue )
{
  var objRegExp = /,/g; //search for commas globally

  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}



function addCommas( strValue ) 
{
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match,
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}

function trim( strValue ) 
{
 	var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function formatSocSec(inStrValue)
{
	inStrValue = inStrValue.toString().replace(/[^1-9]/g,'');
	inStrValue = inStrValue.substring(0,9)
	
	var objRegExp  = new RegExp('([0-9]{3})([0-9]{2})([0-9]{4})');

	while(objRegExp.test(inStrValue)) 
		inStrValue = inStrValue.replace(objRegExp, '$1-$2-$3');
	
	return inStrValue;
}

function formatCurrency(num) 
{
	num = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num))
		num = "0";
		
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if(cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
	
	num.substring(num.length-(4*i+3));
	
	return (((sign)?'':'-') + num + '.' + cents);
}


function toUnicode(inElement_FROM, inElementId_TO)
{
	if (inElement_FROM.value.length==inElement_FROM.maxLength)
	{
		document.getElementById(inElementId_TO).focus();
	}
}
