function radioCheck(ss) {
  for(var i = 0; i < ss.length; i++) {
	  if(ss[i].checked) { return ss[i].value; }
	  }
  return false;
}

function checkbox_empty(ss) {
  for(var i = 0; i < ss.length; i++) {
	   if(ss[i].checked) { return false; }
	 }
  return true;
}

function dropdown_empty(ss){
// Note: ss will need to be fetched via document.getElementById('ss-id-name') for multi-select menus
  for(var i = 0; i < ss.length; i++) {
    if(ss[i].selected) {
      if(ss[i].value.length) { return false; }
    }
  }
  return true;
}

function stripChars(pstrSource){ 
  var m_strOut = new String(pstrSource); 
		// Non-alpha characters
  //m_strOut = m_strOut.replace(/[^0-9]/g, '');
		
		// remove spaces, ( ), -, and .
		m_strOut = m_strOut.replace(/[\-|(|)|\.| ]/g, ''); 

  return m_strOut; 
}
	
function disableForm(formID){
  var element = document.getElementById(formID);
  element.style.display = "none;";
}

// ----------- validation functions ------------------------------------------

function validateDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
 
  //check to see if in correct format
  if(!objRegExp.test(strValue)){
    return false; //doesn't match pattern, bad date
	}
  else{
    var strSeparator = strValue.substring(2,3);
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '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],10); 

    //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
			}
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    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)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}	

function  validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
  True if valid, otherwise false.
******************************************************************/
var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

	
function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
//var objRegExp = /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;
var objRegExp = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function validateUSPhone_Old( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

  //check for valid us phone with or without space between
  //area code
  return objRegExp.test(strValue);
}

function validateUSPhone(strValue){
    var objRegExp = /^[\(]{0,1}[0-9]{3,3}[ .-]{0,1}[\)]{0,1}[0-9]{3,3}[ .-]{0,1}[0-9]{4,4}$/;
    return objRegExp.test(strValue);
}

function validateZip( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

// function to see if date 1 occurs before date 2
function validFromDate(fromDate,toDate){

	// Assuming that the date was in the correct format, this is our separator
 var separator1 = fromDate.charAt(2);
	var arrDate1 = fromDate.split(separator1);

	var checkFromDate = new Date();
	checkFromDate.setFullYear(arrDate1[2],arrDate1[0]-1,arrDate1[1]);
	
 var separator2 = toDate.charAt(2);
	var arrDate2 = toDate.split(separator2);
	
	var checkToDate = new Date();
	checkToDate.setFullYear(arrDate2[2],arrDate2[0]-1,arrDate2[1]);
	
	if (checkToDate > checkFromDate){
	  return true;
	}
	else {
	  return false;
	}
}



function validateName_Strict(strValue){
    var Pattern = /^[a-zA-Z]{1,30}[ ][a-zA-Z]{1,30}$/;
    return Pattern.text(strValue);
}


function validateName_NotStrict(strValue){
    var Pattern = /^[a-zA-Z -]+$/;
    return Pattern.test(strValue);
}