function checkEmail(obj)
{
	if (obj.value != "")
	{
		var str=obj.value
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str))
			testresults=true;
		else{
			alert("Please input a valid email address!");
			obj.focus();
			testresults=false;
			}
		return (testresults);
	}
}

function NumericKeyStrokes(object,evt)
{
   var charCode = (navigator.appName == "Netscape") ? evt.which : evt.keyCode;

   if (charCode > 31 && ((charCode < 48 && charCode != 46) || charCode > 57))
   {
      return false;
   }
   else
   {
      var val = object.value;
      if ((charCode == 46) && (val.length > 0))
      {
         if (val.indexOf(".") == -1)
         {
            return true;
         }
         else
         {
            return false;
         }
      }
      else
      {
         return true;
      }
   }
}

function ToDate(val)
{
    var day, month, year;
    var Exp = new RegExp("^\\s*(\\d{4})([-/])(\\d{2})([-/])(\\d{2})\\s*$");
    m = val.match(Exp);
    if (m != null)
    {
       day = m[5];
       month = m[3];
       year =  m[1];
    }
    else
    {
       Exp = new RegExp("^\\s*(\\d{2})([-/])(\\d{2})([-/])(\\d{4})\\s*$");
       m = val.match(Exp);
       if (m != null)
       {
         day = m[1];
         month = m[3];
         year = m[5];
       }
       else
       {
          Exp = new RegExp("^\\s*(\\d{4})(\\d{2})(\\d{2})\\s*$");
          m = val.match(Exp);
          if (m == null)
          {
             return null;
          }
          day = m[3];
          month = m[2];
          year = m[1];
       }
    }
    var datestring = year + "/" + month + "/" + day;
    month -= 1;
    var date = new Date(year, month, day);
    return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? datestring : null;
}

function vfDateField(objName,strFormat) {
var datefield = objName;
if (chkdate(objName,strFormat) == false) {
datefield.select();
alert("That date is invalid.  Please try again.");
datefield.focus();
return false;
}
else {
return true;
   }
}


function chkdate(objName,strFormat) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArrayShort = new Array(12);
var strMonthArrayLong = new Array(12);

	strMonthArrayShort[0] = "Jan";
	strMonthArrayShort[1] = "Feb";
	strMonthArrayShort[2] = "Mar";
	strMonthArrayShort[3] = "Apr";
	strMonthArrayShort[4] = "May";
	strMonthArrayShort[5] = "Jun";
	strMonthArrayShort[6] = "Jul";
	strMonthArrayShort[7] = "Aug";
	strMonthArrayShort[8] = "Sep";
	strMonthArrayShort[9] = "Oct";
	strMonthArrayShort[10] = "Nov";
	strMonthArrayShort[11] = "Dec";

	strMonthArrayLong[0] = "January";
	strMonthArrayLong[1] = "Febuary";
	strMonthArrayLong[2] = "March";
	strMonthArrayLong[3] = "April";
	strMonthArrayLong[4] = "May";
	strMonthArrayLong[5] = "June";
	strMonthArrayLong[6] = "July";
	strMonthArrayLong[7] = "August";
	strMonthArrayLong[8] = "September";
	strMonthArrayLong[9] = "October";
	strMonthArrayLong[10] = "Novemeber";
	strMonthArrayLong[11] = "December";

strDate = datefield.value;
if (strDate.length < 1) 
{
	return true;
}
if ((strDate.length >= 1) && (strDate.length <= 5))
{
	return false;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArrayShort[i].toUpperCase() || strMonth.toUpperCase() == strMonthArrayLong[i].toUpperCase()) {
intMonth = i+1;
if (strFormat == "Short")
{
	strMonth = strMonthArrayShort[i];
}
else
{
	strMonth = strMonthArrayLong[i];
}

i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") 
{
	datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else 
{
	if (intday < 10)
	{
		if (strFormat == "Short")
		{
			datefield.value = "0" + intday + " " + strMonthArrayShort[intMonth-1] + " " + strYear;
		}
		else
		{
			datefield.value = "0" + intday + " " + strMonthArrayLong[intMonth-1] + " " + strYear;
		}
	}
	else
	{
		if (strFormat == "Short")
		{
			datefield.value = intday + " " + strMonthArrayShort[intMonth-1] + " " + strYear;
		}
		else
		{
			datefield.value = intday + " " + strMonthArrayLong[intMonth-1] + " " + strYear;
		}
	}
}
return true;
}


function fNumberFormat(num,decplc)
{
   var str = "" + Math.round(eval(num) * Math.pow(10,decplc));
   while (str.length <= decplc)
   {
      str = "0" + str;
   }
   var decpt = str.length - decplc
   if (decplc > 0)
   {
      return SetNumberFormat(str.substring(0,decpt)) + "." + str.substring(decpt,str.length);
   }
   else
   {
      return SetNumberFormat(str.substring(0,decpt));
   }
}