function fnIsValidEmail(sEmailAddr) {
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(sEmailAddr);
}
function fnGetRadioValue(objRadio) {
	if ( !(objRadio))
		return false;
	for (var i = 0; i < objRadio.length; i++) {
		if ( objRadio[i].checked == true)
   			return objRadio[i].value;
	}
	if (objRadio.checked == true)
		return objRadio.value;
	return '';
}
function fnSetRadioValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}
//function fnSetSelectValue(SelectName, Value) {
//  eval('SelectObj = document.' + 
//    SelectName + ';');
function fnSetSelectValue(SelectObj, Value) {
  for(index = 0; 
    index < SelectObj.length; 
    index++) {
   if(SelectObj[index].value == Value)
     SelectObj.selectedIndex = index;
   }
}
function fnIsValidDate (sDateIn) {
	var dateFormat = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;
	return sDateIn.match(dateFormat);
}
function fnIsValidCurrency ( fld ) { 
   var temp_value = fld.value; 

   if (temp_value == "") 
   { 
     fld.value = "0.00"; 
     return true; 
   } 
   var Chars = "0123456789.,-"; 
   for (var i = 0; i < temp_value.length; i++) 
   { 
       if (Chars.indexOf(temp_value.charAt(i)) == -1) 
       { 
           alert("Invalid Character(s)\n\nOnly numbers (0-9), commas, periods, or negative signs are allowed in this field."); 
           fld.focus(); 
       fld.select(); 
           return false; 
       } 
   }
   return true; 
} 
function fnCalcAge(sDateIn){
  var t, mon, day, year, DD, MM, YY, age;
  var fnDIM = new fnGetDaysInMonth();
  YY   = parseInt(sDateIn.split('/')[2]);	// year of birth (4 digits)
  MM   = parseInt(sDateIn.split('/')[1]);	// month of birth (1-12)
  DD   = parseInt(sDateIn.split('/')[0]);	// date of birth (1-31)
  if (fnDIM[MM] < DD || DD < 1) return -1;
  t    = new Date();	// get current date
  year = t.getFullYear();	// get year of current
  mon  = t.getMonth() + 1;	// get month of current
  day  = t.getDate();	// get date of current
  if (MM == 2 && DD == 29){	// check leap year
 //   if (!(((YY % 4 == 0) && (YY % 100 != 0)) || (YY % 400 == 0))){
 //     alert('The year ' +YY+ ' ends at 28th of '+MM+' month\nPlease check the date.');
 //     return -1;
 //   }
  }
  age = year - YY;
  if ((MM > mon) || (MM == mon && day < DD)) age --;
  return age;
}
function fnGetDaysInMonth(){
  var i = 0;
  this[i++] = 0; // dummy
  this[i++] = 31;
  this[i++] = 29;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 31;
  this[i++] = 30;
  this[i++] = 31;
  this[i++] = 30;
  this[i  ] = 31;
  this.length = i;
}
function fnShowSpan (objSpan, bShowSpan) {
	if (bShowSpan) {
       	objSpan.style.visibility = "visible";
       	objSpan.style.display = "";
    }
    else {
       	objSpan.style.visibility = "hidden";
       	objSpan.style.display = "none";
    }
}
function fnTrim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function fnLTrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function fnRTrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

