<!-- Original:  Richard Gorremans (RichardG@spiritwolfx.com) -->
<!-- Web Site:  http://www.spiritwolfx.com -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
// Check browser version
var isNav4 = false, isNav5 = false, isIE4 = false
var strSeperator = "/"; 
// If you are using any Java validation on the back side you will want to use the / because 
// Java date validations do not recognize the dash as a valid date separator.
var vDateType = 3; // Global value for type of date format
//                1 = mm/dd/yyyy
//                2 = yyyy/dd/mm  (Unable to do date check at this time)
//                3 = dd/mm/yyyy
var vYearType = 4; //Set to 2 or 4 for number of digits in the year for Netscape
var vYearLength = 4; // Set to 4 if you want to force the user to enter 4 digits for the year before validating.
var err = 0; // Set the error code to a default of zero
if(navigator.appName == "Netscape") {
if (navigator.appVersion < "5") {
isNav4 = true;
isNav5 = false;
}
else
if (navigator.appVersion > "4") {
isNav4 = false;
isNav5 = true;
   }
}
else {
isIE4 = true;
}
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
//		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
//		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
//		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}


function isValidTime(timeStr) {
// Time validation function courtesty of 
// Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

var matchArray = timeStr.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
return false;
}
if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}
if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}
if (minute < 0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
return false;
}
return true;
}

// input the start date and end date and output the difference measured in days
function dateDiffdays(startdatestr, enddatestr) {
date1 = new Date();
date2 = new Date();
diff  = new Date();

if (isDate(startdatestr)) { // Validates first date 
date1temp = new Date(startdatestr);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits

if (isDate(enddatestr)) { // Validates second date 
date2temp = new Date(enddatestr);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits

// sets difference date to difference of first date and second date

diff.setTime(date2.getTime() - date1.getTime());

timediff = diff.getTime();

days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 

return days; 
}
//  End -->


function DateFormat(vDateName, vDateValue, e, dateCheck, dateType) {
  vDateType = dateType;
  // vDateName = object name
  // vDateValue = value in the field being checked
  // e = event
  // dateCheck 
  // True  = Verify that the vDateValue is a valid date
  // False = Format values being entered into vDateValue only
  // vDateType
  // 1 = mm/dd/yyyy
  // 2 = yyyy/mm/dd
  // 3 = dd/mm/yyyy
  //Enter a tilde sign for the first number and you can check the variable information.
  if (vDateValue == "~") {
    alert("AppVersion = "+navigator.appVersion+" \nNav. 4 Version = "+isNav4+" \nNav. 5 Version = "+isNav5+" \nIE Version = "+isIE4+" \nYear Type = "+vYearType+" \nDate Type = "+vDateType+" \nSeparator = "+strSeperator);
    vDateName.value = "";
    vDateName.focus();
    return true;
  }
  var whichCode = (window.Event) ? e.which : e.keyCode;
  // Check to see if a seperator is already present.
  // bypass the date if a seperator is present and the length greater than 8
  if (vDateValue.length > 8 && isNav4) {
    if ((vDateValue.indexOf("-") >= 1) || (vDateValue.indexOf("/") >= 1))
      return true;
  }
  //Eliminate all the ASCII codes that are not valid
  var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
  if (alphaCheck.indexOf(vDateValue) >= 1) {
    if (isNav4) {
      vDateName.value = "";
      vDateName.focus();
      vDateName.select();
      return false;
    }
    else {
      vDateName.value = vDateName.value.substr(0, vDateValue.length);
      return false;
   }
  }
  if (whichCode == 8) //Ignore the Netscape value for backspace. IE has no value
    return false;
  else {
    //Create numeric string values for 0123456789/
    //The codes provided include both keyboard and keypad values
    var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
    if (strCheck.indexOf(whichCode) != -1) {
      if (isNav4) {
        if (((vDateValue.length < 6 && dateCheck) || (vDateValue.length == 7 && dateCheck)) && (vDateValue.length >=1)) {
          alert("Invalid Date\nPlease Re-Enter");
          vDateName.value = "";
          vDateName.focus();
          vDateName.select();
          return false;
        }
        if (vDateValue.length == 6 && dateCheck) {
          var mDay = vDateName.value.substr(2,2);
          var mMonth = vDateName.value.substr(0,2);
          var mYear = vDateName.value.substr(4,4);
          //Turn a two digit year into a 4 digit year
          if (mYear.length == 2 && vYearType == 4) {
            var mToday = new Date();
            //If the year is greater than 30 years from now use 19, otherwise use 20
            var checkYear = mToday.getFullYear() + 30; 
            var mCheckYear = '20' + mYear;
            if (mCheckYear >= checkYear)
              mYear = '19' + mYear;
            else
              mYear = '20' + mYear;
          }
          var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
          if (!dateValid(vDateValueCheck)) {
            alert("Invalid Date\nPlease Re-Enter");
            vDateName.value = "";
            vDateName.focus();
            vDateName.select();
            return false;
          }
          return true;
        }
        else {
        // Reformat the date for validation and set date type to a 1
          if (vDateValue.length >= 8  && dateCheck) {
            if (vDateType == 1) // mmddyyyy
            {
              var mDay = vDateName.value.substr(2,2);
              var mMonth = vDateName.value.substr(0,2);
              var mYear = vDateName.value.substr(4,4);
              vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
            }
            if (vDateType == 2) // yyyymmdd
            {
              var mYear = vDateName.value.substr(0,4)
              var mMonth = vDateName.value.substr(4,2);
              var mDay = vDateName.value.substr(6,2);
              vDateName.value = mYear+strSeperator+mMonth+strSeperator+mDay;
            }
            if (vDateType == 3) // ddmmyyyy
            {
              var mMonth = vDateName.value.substr(2,2);
              var mDay = vDateName.value.substr(0,2);
              var mYear = vDateName.value.substr(4,4);
              vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
            }
            //Create a temporary variable for storing the DateType and change
            //the DateType to a 1 for validation.
            var vDateTypeTemp = vDateType;
            vDateType = 1;
            var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
            if (!dateValid(vDateValueCheck)) {
              alert("Invalid Date\nPlease Re-Enter");
              vDateType = vDateTypeTemp;
              vDateName.value = "";
              vDateName.focus();
              vDateName.select();
              return false;
            }
            vDateType = vDateTypeTemp;
            return true;
          }
          else {
            if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck))              && (vDateValue.length >=1)) {
              alert("Invalid Date\nPlease Re-Enter");
              vDateName.value = "";
              vDateName.focus();
              vDateName.select();
              return false;
            }
          }
        }
      }
      else {
      // Non isNav Check
        if (((vDateValue.length < 8 && dateCheck) || (vDateValue.length == 9 && dateCheck)) && (vDateValue.length >=1)) {
          alert("Invalid Date\nPlease Re-Enter");
          vDateName.value = "";
          vDateName.focus();
          return true;
        }
        // Reformat date to format that can be validated. mm/dd/yyyy
        if (vDateValue.length >= 8 && dateCheck) {
          // Additional date formats can be entered here and parsed out to
          // a valid date format that the validation routine will recognize.
          if (vDateType == 1) // mm/dd/yyyy
          {
            var mMonth = vDateName.value.substr(0,2);
            var mDay = vDateName.value.substr(3,2);
            var mYear = vDateName.value.substr(6,4);
          }
          if (vDateType == 2) // yyyy/mm/dd
          {
            var mYear = vDateName.value.substr(0,4)
            var mMonth = vDateName.value.substr(5,2);
            var mDay = vDateName.value.substr(8,2);
          }
          if (vDateType == 3) // dd/mm/yyyy
          {
            var mDay = vDateName.value.substr(0,2);
            var mMonth = vDateName.value.substr(3,2);
            var mYear = vDateName.value.substr(6,4);
          }
          if (vYearLength == 4) {
            if (mYear.length < 4) {
              alert("Invalid Date\nPlease Re-Enter");
              vDateName.value = "";
              vDateName.focus();
              return true;
            }
          }
          // Create temp. variable for storing the current vDateType
          var vDateTypeTemp = vDateType;
          // Change vDateType to a 1 for standard date format for validation
          // Type will be changed back when validation is completed.
          vDateType = 1;
          // Store reformatted date to new variable for validation.
          var vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
          if (mYear.length == 2 && vYearType == 4 && dateCheck) {
            //Turn a two digit year into a 4 digit year
            var mToday = new Date();
            //If the year is greater than 30 years from now use 19, otherwise use 20
            var checkYear = mToday.getFullYear() + 30; 
            var mCheckYear = '20' + mYear;
            if (mCheckYear >= checkYear)
              mYear = '19' + mYear;
            else
              mYear = '20' + mYear;
            vDateValueCheck = mMonth+strSeperator+mDay+strSeperator+mYear;
            // Store the new value back to the field.  This function will
            // not work with date type of 2 since the year is entered first.
            if (vDateTypeTemp == 1) // mm/dd/yyyy
              vDateName.value = mMonth+strSeperator+mDay+strSeperator+mYear;
            if (vDateTypeTemp == 3) // dd/mm/yyyy
              vDateName.value = mDay+strSeperator+mMonth+strSeperator+mYear;
          } 
          if (!dateValid(vDateValueCheck)) {
            alert("Invalid Date\nPlease Re-Enter");
            vDateType = vDateTypeTemp;
            vDateName.value = "";
            vDateName.focus();
            return true;
          }
          vDateType = vDateTypeTemp;
          return true;
        }
        else {
          if (vDateType == 1) {
            if (vDateValue.length == 2) {
              vDateName.value = vDateValue+strSeperator;
            }
            if (vDateValue.length == 5) {
              vDateName.value = vDateValue+strSeperator;
            }
          }
          if (vDateType == 2) {
            if (vDateValue.length == 4) {
              vDateName.value = vDateValue+strSeperator;
            }
            if (vDateValue.length == 7) {
              vDateName.value = vDateValue+strSeperator;
            }
          } 
          if (vDateType == 3) {
            if (vDateValue.length == 2) {
              vDateName.value = vDateValue+strSeperator;
            }
            if (vDateValue.length == 5) {
              vDateName.value = vDateValue+strSeperator;
            }
          }
          return true;
        }
      }
      if (vDateValue.length == 10&& dateCheck) {
        if (!dateValid(vDateName)) {
          // Un-comment the next line of code for debugging the dateValid() function error             messages
          //alert(err);  
          alert("Invalid Date\nPlease Re-Enter");
          vDateName.focus();
          vDateName.select();
        }
      }
      return false;
    }
    else {
      // If the value is not in the string return the string minus the last
      // key entered.
      if (isNav4) {
        vDateName.value = "";
        vDateName.focus();
        vDateName.select();
        return false;
      }
      else
      {
        vDateName.value = vDateName.value.substr(0, vDateValue.length);
        return false;
      }
    }
  }
}

function dateValid(objName) {
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 strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
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);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
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() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[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;
      }
   }
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}
//  End -->


////////////////////////////////////////////////////////////////////////////
// Function expired(expdate)                                              //
//   - checks to see if a form field 'expdate' is before today.           //
////////////////////////////////////////////////////////////////////////////
function expired(expdate)
{
   today = new Date()
   today_month = today.getMonth() + 1
   today_date = today.getDate()
   today_year = today.getFullYear()
   today_str = today_month.toString() + '/' + today_date.toString() + '/' + today_year.toString()
   daysbetween = dateDiffdays(today_str, expdate)
   if (daysbetween < 0 )
      return true
   else
      return false
}

////////////////////////////////////////////////////////////////////////////
// Function isEmpty(str)                                                  //
//   - checks to see if a form field 'str' is empty                       //
////////////////////////////////////////////////////////////////////////////
function isEmpty(str) {
   var empty = (str == null || str == "") ? true : false
   return empty
}

////////////////////////////////////////////////////////////////////////////
// Function numbersonly(e)                                                //
//   - only allows numerical characters to be entered in a form field     //
////////////////////////////////////////////////////////////////////////////
function numbersonly(e){
   var unicode=e.charCode? e.charCode : e.keyCode
   if (unicode!=8 && unicode!=9 && unicode!=13){ //if the key isn't the backspace, tab 
                                                 // or CR key (which we should allow)
      if (unicode<48||unicode>57) //if not a number
         return false //disable key press
   }
}

////////////////////////////////////////////////////////////////////////////
// Function floatsonly(e)                                                //
//   - only allows numerical characters and decimal point to be entered in a form field     //
////////////////////////////////////////////////////////////////////////////
function floatsonly(e){
   var unicode=e.charCode? e.charCode : e.keyCode
   if (unicode!=46 && unicode!=8 && unicode!=9 && unicode!=13){ //if the key isn't the backspace, tab 
                                                 // or CR key (which we should allow)
      if (unicode<48||unicode>57) //if not a number
         return false //disable key press
   }
}

////////////////////////////////////////////////////////////////////////////
// Function limitlength(obj, length)                                      //
//   - limits the number of characters entered in a form field to 'length'//
////////////////////////////////////////////////////////////////////////////
function limitlength(obj, length){
   var maxlength=length
   if (obj.value.length>maxlength)
      obj.value=obj.value.substring(0, maxlength)
}

////////////////////////////////////////////////////////////////////////////
// Function requirelength(obj, length)                                      //
//   - alerts user if the number of characters entered in a form field is //
//     not equal to a required 'length'                                   //
////////////////////////////////////////////////////////////////////////////
function requirelength(obj, length){
   var required_length=length
   alert("checking length, comparing "+obj.value.length+" with "+requiredlength)
   if (obj.value.length != required_length)
      alert("Enter exactly "+length+" characters in this field.")
	  obj.focus()
	  return false
}


////////////////////////////////////////////////////////////////////////////
// Function isValidPhone(str)                                             //
//   - checks to see if a form field 'str' is a valid phone number        //
////////////////////////////////////////////////////////////////////////////
function isValidPhoneOrBlank(str) {
   var empty = (str == null || str == "") ? true : false;
   if (!empty) {
      var tempph = str;
      tempph = tempph.replace(/'/g,"");
	  tempph = tempph.replace(/-/g,"");
	  tempph = tempph.replace(/\(/g,"");
	  tempph = tempph.replace(/\)/g,"");
      tempph = tempph.replace(/ /g,"");
      tempph = parseInt(tempph);
	  var notanumber = isNaN(tempph);
	  var numlength = tempph.toString().length;
      if (notanumber) { 
         return false;
      } else if (numlength != 10) {
         return false;
      } else {
         return true;
	  }
   } else {
      return true;
   }
}

////////////////////////////////////////////////////////////////////////////
// Function reformatPhone(str)                                            //
//   - reformats a form field 'str' into a (999)999-9999 format           //
////////////////////////////////////////////////////////////////////////////
function reformatPhone(str) {
   var empty = (str == null || str == "") ? true : false
   if (!empty) {
      var tempph = str
      tempph = tempph.replace(/'/g,"")
	  tempph = tempph.replace(/-/g,"")
	  tempph = tempph.replace(/\(/g,"")
	  tempph = tempph.replace(/\)/g,"")
      tempph = tempph.replace(/ /g,"")
	  var newphone = "(" + tempph.substr(0,3) + ") " + tempph.substr(3,3) + "-"
	  newphone += tempph.substr(6,4)
	  return newphone
   }
   return ""
}

<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->

var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}

ParseForNumber1(object)

if(keycode >= 48){
ValidatePhone(object)
}
}

function backspacerDOWN(object,e) {
if(e){
e = e
} else {
e = window.event
}
if(e.which){
var keycode = e.which
} else {
var keycode = e.keyCode
}
ParseForNumber2(object)
}

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp;

} else if(p.length >= 7){
p ="(" + p;
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
if (sChar.length == null)
{
zChar = new Array(sChar);
}
else zChar = sChar;

for (i=0; i<zChar.length; i++)
{
sNewStr = "";

var iStart = 0;
var iEnd = sStr.indexOf(sChar[i]);

while (iEnd != -1)
{
sNewStr += sStr.substring(iStart, iEnd);
iStart = iEnd + 1;
iEnd = sStr.indexOf(sChar[i], iStart);
}
sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

sStr = sNewStr;
}

return sNewStr;
}

<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function formatCurrency(num) {
num = parseFloat(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);
}
//  End -->

function formatPhone(phonefield) {
   var num = phonefield.value;
   var empty = (num == null || num == "") ? true : false
   var numstr = "";
   var numstr1 = "";
   var numstr2 = "";
   var numstr3 = "";
   
   num = num.replace(/'/g,"")
   num = num.replace(/-/g,"")
   num = num.replace(/\(/g,"")
   num = num.replace(/\)/g,"")
   num = num.replace(/ /g,"")
   num = parseInt(num)
   var numlength = num.toString().length
   if(isNaN(num)) {
	  if (!empty) {
	     alert("Enter a valid, 10-digit phone/fax number.  Enter only the numbers. The field will auto-format.");
	     phonefield.focus();
	  }
	  return (numstr);
   } else if (numlength == 10) {
	  numstr1 = num.toString().substr(0,3);
	  numstr2 = num.toString().substr(3,3);
	  numstr3 = num.toString().substr(6,4);
      numstr = "(" + numstr1 + ")" + numstr2 + "-" + numstr3;
      return (numstr);
   } else {
	  alert(num.toString().length + " digits entered. Enter a valid, 10-digit phone/fax number.  Enter only the numbers. The field will auto-format.");
	  phonefield.focus();
	  return (numstr);
   }
}


////////////////////////////////////////////////////////////////////////////
// Function validateAdminEntryForm()                                               //
////////////////////////////////////////////////////////////////////////////
function validateAdminEntryForm(adminform) {
   if (isEmpty(adminform.UserName.value)) {
      alert ("Please enter a valid Username.")
	  adminform.UserName.focus()
	  return false
   }
   if (isEmpty(adminform.Password.value)) {
      alert ("Please enter a correct Password.")
	  adminform.Password.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm0()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm0(form0) {
   if (isEmpty(form0.FEIN.value)) {
      alert ("Please enter a valid Federal Employer Identification Number.")
	  form0.FEIN.focus()
	  return false
   }
   if (String(form0.FEIN.value).length != 9) {
      alert ("Please enter your company's 9-digit Federal Employer Identification Number. "+form0.FEIN.value+" has only "+String(form0.FEIN.value).length+" digits.")
	  form0.FEIN.focus()
	  return false
   }
   if (isEmpty(form0.ProjID.value)) {
      alert ("Please enter a valid Project ID.")
	  form0.Password.focus()
	  return false
   }
   return true
}

function checklength(field, targetlength) {
	var val = field.value.toString();
	var length = val.length;
	if (!isEmpty(val) && length != targetlength) {
	   alert ("This field must contain exactly "+targetlength+" characters.");
	   field.focus();
	   return false;
	}
}

////////////////////////////////////////////////////////////////////////////
// Function validateNewEnroll1()                                               //
////////////////////////////////////////////////////////////////////////////
function validateNewEnroll1(form) {
   if (isEmpty(form.ProjID.value)) {
      alert ("Please enter a valid Project ID.")
	  form.ProjID.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateNewEnroll2()                                               //
////////////////////////////////////////////////////////////////////////////
function validateNewEnroll2(form) {
   if (isEmpty(form.AwardCont.value) || form.AwardCont.value < 0) {
      alert ("Please select an Awarding Contractor.")
	  form.AwardCont.focus()
	  return false
   }
   return true
}

function checklength(field, targetlength) {
	var val = field.value.toString();
	var length = val.length;
	if (!isEmpty(val) && length != targetlength) {
	   alert ("This field must contain exactly "+targetlength+" characters.");
	   field.focus();
	   return false;
	}
}

////////////////////////////////////////////////////////////////////////////
//  Script by hscripts.com   modified by Vartech Services                 //
////////////////////////////////////////////////////////////////////////////
function isAlphaNumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
	{
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if(!((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123)))
            return false;
 	}
	return true;
}

////////////////////////////////////////////////////////////////////////////
// Function validateNewProject()                                        //
////////////////////////////////////////////////////////////////////////////
function validateNewProject(form) {
   if (isEmpty(form.ProjID.value)) {
      alert ("Please enter the Project ID.")
	  form.ProjID.focus()
	  return false
   }
   if (isEmpty(form.ProjName.value)) {
      alert ("Please enter the Project Name.")
	  form.ProjName.focus()
	  return false
   }
   if (isEmpty(form.PrimaryFEIN.value)) {
      alert ("Please enter the Prime Contractor Federal Employer Identification Number (FEIN).")
	  form.PrimaryFEIN.focus()
	  return false
   }
   if (isEmpty(form.PrimaryName.value)) {
      alert ("Please enter Prime Contractor Company Name.")
	  form.PrimaryName.focus()
	  return false
   }
   if (isEmpty(form.PrimaryEmail.value)) {
      alert ("Please enter Prime Contractor Email Address.")
	  form.PrimaryEmail.focus()
	  return false
   }
   if (!isEmpty(form.Start.value) && !isDate(form.Start.value)) {
      alert ("Please enter a valid Project Start Date (mm/dd/yyyy). You entered " + form.Start.value)
	  form.Start.focus()
	  return false
   }
   if (!isEmpty(form.End.value) && !isDate(form.End.value)) {
      alert ("Please enter a valid Estimated Project End Date (mm/dd/yyyy). You entered " + form.End.value)
	  form.End.focus()
	  return false
   }
   if (isEmpty(form.Start.value)) {
      alert ("Please enter the Project Start Date.")
	  form.Start.focus()
	  return false
   }
   if (isEmpty(form.End.value)) {
      alert ("Please enter the Estimated Project End Date.")
	  form.End.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateNewContractor()                                        //
////////////////////////////////////////////////////////////////////////////
function validateNewContractor(form) {
   if (isEmpty(form.ProjID.value)) {
      alert ("Please enter the Project ID.")
	  form.ProjID.focus()
	  return false
   }
   if (isEmpty(form.ContName.value)) {
      alert ("Please enter the Company Name.")
	  form.ContName.focus()
	  return false
   }
   if (isEmpty(form.FEIN.value)) {
      alert ("Please enter the Company Federal Employer Identification Number (FEIN).")
	  form.FEIN.focus()
	  return false
   }
   if (isEmpty(form.ContAddr.value)) {
      alert ("Please enter Company Address.")
	  form.ContAddr.focus()
	  return false
   }
   if (isEmpty(form.ContCSZ.value)) {
      alert ("Please enter City, State and Zip Code.")
	  form.ContCSZ.focus()
	  return false
   }
   if (isEmpty(form.ContPhone.value)) {
      alert ("Please enter the Company Phone Number.")
	  form.ContPhone.focus()
	  return false
   }
   if (isEmpty(form.ContURL.value)) {
      alert ("Please enter the Company Web Address.")
	  form.ContURL.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateRegistration()                                        //
////////////////////////////////////////////////////////////////////////////
function validateLogin(form) {
   if (isEmpty(form.Username.value)) {
      alert ("Please enter your User Name.")
	  form.Username.focus()
	  return false
   }
   if (isEmpty(form.Password.value)) {
      alert ("Please enter your Password.")
	  form.Password.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateRegistration()                                        //
////////////////////////////////////////////////////////////////////////////
function validateRegistration(form) {
   if (isEmpty(form.FirstName.value)) {
      alert ("Please enter your First Name.")
	  form.FirstName.focus()
	  return false
   }
   if (isEmpty(form.LastName.value)) {
      alert ("Please enter your Last Name.")
	  form.LastName.focus()
	  return false
   }
   if (isEmpty(form.Email.value)) {
      alert ("Please enter your Email Address.")
	  form.Email.focus()
	  return false
   }
   if (isEmpty(form.Username.value)) {
      alert ("Please enter your desired User Name using 6-12 alphanumeric charactors.")
	  form.Username.focus()
	  return false
   }
   if (form.Username.value.length < 6 || form.Username.value.length > 12) {
      alert ("Please enter your desired User Name using 6-12 alphanumeric charactors.")
	  form.Username.focus()
	  return false
   }
   if (!isAlphaNumeric(form.Username.value)) {
      alert ("Please enter your desired User Name using 6-12 alphanumeric charactors.")
	  form.Username.focus()
	  return false
   }
   if (isEmpty(form.Password.value)) {
      alert ("Please enter a Password for your user account.")
	  form.Password.focus()
	  return false
   }
   if (isEmpty(form.Password2.value)) {
      alert ("Please re-type the same Password.")
	  form.Password2.focus()
	  return false
   }
   if (form.Password.value != form.Password2.value) {
      alert ("The Password entries do not match. Please re-type the two Password fields.")
	  form.Password.focus()
	  return false
   }
   if (isEmpty(form.Company.value)) {
      alert ("Please enter your Company name.")
	  form.Company.focus()
	  return false
   }
   if (isEmpty(form.FEIN.value)) {
      alert ("Please enter your company's Federal Employer Identification Number (FEIN).")
	  form.FEIN.focus()
	  return false
   }
   if (form.FEIN.value.length != 9) {
      alert ("Please enter exactly 9 digits for your company's Federal Employer Identification Number (FEIN).")
	  form.FEIN.focus()
	  return false
   }
   if (isEmpty(form.ProjID.value)) {
      alert ("Please enter the Project ID of a project your company is contracted to work on.")
	  form.ProjID.focus()
	  return false
   }
   if (isEmpty(form.AwardCont.value)) {
      alert ("Please enter the name of the company that awarded you the contract.")
	  form.AwardCont.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateContractorUpdate()                                    //
////////////////////////////////////////////////////////////////////////////
function validateContractorUpdate(form) {
   if (isEmpty(form.NewFEIN.value)) {
      alert ("Please enter the Contractor Name.")
	  form.NewFEIN.focus()
	  return false
   }
   if (form.NewFEIN.value.length != 9) {
      alert ("Please enter exactly 9 digits for your company's Federal Employer Identification Number (FEIN).")
	  form.NewFEIN.focus()
	  return false
   }
   if (isEmpty(form.NewContName.value)) {
      alert ("Please enter the Contractor Name.")
	  form.NewContName.focus()
	  return false
   }
   if (isEmpty(form.NewContAddr.value)) {
      alert ("Please enter the Contractor Street Address.")
	  form.NewContAddr.focus()
	  return false
   }
   if (isEmpty(form.NewContCSZ.value)) {
      alert ("Please enter the Contractor City, State and Zip Code.")
	  form.NewContCSZ.focus()
	  return false
   }
   if (isEmpty(form.NewContPhone.value)) {
      alert ("Please enter the Contractor Phone Number.")
	  form.NewContPhone.focus()
	  return false
   }
   form.NewContPhone.value = reformatPhone(form.NewContPhone.value)
   if (!isValidPhoneOrBlank(form.NewContPhone.value)) {
	   alert ("Please enter a valid, 10-digit Contrator phone number (type only numbers allowing field to auto-format).")
	   form.NewContPhone.focus()
	   return false
   }
   if (isEmpty(form.NewContURL.value)) {
      alert ("Please enter the Contractor Web Address.")
	  form.NewContURL.focus()
	  return false
   }
   if (isEmpty(form.NewContOwnType.value)) {
      alert ("Please enter the Contractor Ownership Type."+form.NewContOwnType.value)
	  form.NewContOwnType.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateNewProject()                                          //
////////////////////////////////////////////////////////////////////////////
function validateNewProject(form) {
   if (isEmpty(form.ProjID.value)) {
      alert ("Please enter the Project ID.")
	  form.ProjID.focus()
	  return false
   }
   if (isEmpty(form.ProjectName.value)) {
      alert ("Please enter the Project Name.")
	  form.ProjName.focus()
	  return false
   }
   if (isEmpty(form.ProjPrimary.value)) {
      alert ("Please enter the Project Primary Contractor's Federal Employer Identification Number (FEIN).")
	  form.ProjPrimary.focus()
	  return false
   }
   if (form.ProjPrimary.value.length != 9) {
      alert ("Please enter exactly 9 digits for Project Primary Contractor's Federal Employer Identification Number (FEIN).")
	  form.ProjPrimary.focus()
	  return false
   }
   if (isEmpty(form.ProjPrimaryName.value)) {
      alert ("Please enter the Primary Contractor's Company Name.")
	  form.ProjPrimaryName.focus()
	  return false
   }
   if (isEmpty(form.ProjPrimaryEmail.value)) {
      alert ("Please enter the Project Primary Contractor's Email Address.")
	  form.ContAddr.focus()
	  return false
   }
   if (!isEmpty(form.Start.value) && !isDate(form.Start.value)) {
      alert ("Please enter a valid Start Date (mm/dd/yyyy).")
	  form.Start.focus()
	  return false
   }
   if (!isEmpty(form.End.value) && !isDate(form.End.value)) {
      alert ("Please enter a valid Estimated Completion Date (mm/dd/yyyy).")
	  form.End.focus()
	  return false
   }
   if (!isEmpty(form.Start.value) && !isEmpty(form.End.value))
	{
	   Startyyyy = parseInt(form.Start.value.substr(6,9))
	   Startmm = parseInt(form.Start.value.substr(0,1)) - 1
	   Startdd = parseInt(form.Start.value.substr(3,4))
	   Endyyyy = parseInt(form.End.value.substr(6,9))
	   Endmm = parseInt(form.End.value.substr(0,1)) - 1
	   Enddd = parseInt(form.End.value.substr(3,4))
	   sdate = new Date(Startyyyy, Startmm, Startdd)
	   edate = new Date(Endyyyy, Endmm, Enddd)
      if (sdate > edate) {
         alert ("Please enter an Estimated Completion Date that is later than the Start Date.")
	      form.End.focus()
	      return false
		}
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateProjectUpdate()                                    //
////////////////////////////////////////////////////////////////////////////
function validateProjectUpdate(form) {
   if (isEmpty(form.NewProjID.value)) {
      alert ("Please enter the Project ID.")
	  form.NewProjID.focus()
	  return false
   }
   if (isEmpty(form.NewProjName.value)) {
      alert ("Please enter the Project Name.")
	  form.NewProjName.focus()
	  return false
   }
   if (isEmpty(form.NewProjPrimary.value)) {
      alert ("Please enter the Project Primary Contractor's Federal Employer Identification Number (FEIN).")
	  form.NewProjPrimary.focus()
	  return false
   }
   if (form.NewProjPrimary.value.length != 9) {
      alert ("Please enter exactly 9 digits for Project Primary Contractor's Federal Employer Identification Number (FEIN).")
	  form.NewProjPrimary.focus()
	  return false
   }
   if (isEmpty(form.NewProjPrimaryName.value)) {
      alert ("Please enter the Primary Contractor's Company Name.")
	  form.NewProjPrimaryName.focus()
	  return false
   }
   if (isEmpty(form.NewProjPrimaryEmail.value)) {
      alert ("Please enter the Project Primary Contractor's Email Address.")
	  form.NewContAddr.focus()
	  return false
   }
   if (!isEmpty(form.NewProjStartDate.value) && !isDate(form.NewProjStartDate.value)) {
      alert ("Please enter a valid Start Date (mm/dd/yyyy). You entered " + form.NewProjStartDate.value)
	  form.StartDate.focus()
	  return false
   }
   if (!isEmpty(form.NewProjEndDate.value) && !isDate(form.NewProjEndDate.value)) {
      alert ("Please enter a valid Estimated Completion Date (mm/dd/yyyy).")
	  form.NewProjEndDate.focus()
	  return false
   }
   if (!isEmpty(form.NewProjStartDate.value) && !isEmpty(form.NewProjEndDate.value))
	{
	   Startyyyy = parseInt(form.NewProjStartDate.value.substr(6,9))
	   Startmm = parseInt(form.NewProjStartDate.value.substr(0,1)) - 1
	   Startdd = parseInt(form.NewProjStartDate.value.substr(3,4))
	   Endyyyy = parseInt(form.NewProjEndDate.value.substr(6,9))
	   Endmm = parseInt(form.NewProjEndDate.value.substr(0,1)) - 1
	   Enddd = parseInt(form.NewProjEndDate.value.substr(3,4))
	   sdate = new Date(Startyyyy, Startmm, Startdd)
	   edate = new Date(Endyyyy, Endmm, Enddd)
      if (sdate > edate) {
         alert ("Please enter an Estimated Completion Date that is later than the Start Date.")
	      form.NewProjEndDate.focus()
	      return false
		}
   }
   if (!isEmpty(form.NewProjectCompletionDate.value) && !isDate(form.NewProjProjectCompletionDate.value)) {
      alert ("Please enter a valid Actual Completion Date (mm/dd/yyyy) or leave field blank.")
	  form.NewProjectCompletionDate.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm1()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm1(form1) {
	// alert("Validating form 1")
   if (isEmpty(form1.ContName.value)) {
      alert ("Please enter the Contractor Name.")
	  form1.ContName.focus()
	  return false
   }
   if (isEmpty(form1.ContAddr.value)) {
      alert ("Please enter the Contractor Street Address.")
	  form1.ContAddr.focus()
	  return false
   }
   if (isEmpty(form1.ContCSZ.value)) {
      alert ("Please enter the Contractor City, State and Zip Code.")
	  form1.ContCSZ.focus()
	  return false
   }
   if (isEmpty(form1.ContPhone.value)) {
      alert ("Please enter the Contractor Phone Number.")
	  form1.ContPhone.focus()
	  return false
   }
   form1.ContPhone.value = reformatPhone(form1.ContPhone.value)
   if (!isValidPhoneOrBlank(form1.ContPhone.value)) {
	   alert ("Please enter a valid, 10-digit Contrator phone number (type only numbers allowing field to auto-format).")
	   form1.ContPhone.focus()
	   return false
   }
   if (isEmpty(form1.ContURL.value)) {
      alert ("Please enter the Contractor Web Address.")
	  form1.ContURL.focus()
	  return false
   }
   if (isEmpty(form1.OffConName.value)) {
      alert ("Please enter the Office Contact Name.")
	  form1.OffConName.focus()
	  return false
   }
   if (isEmpty(form1.OffConPhone.value)) {
      alert ("Please enter the Office Contact Phone.")
	  form1.OffConPhone.focus()
	  return false
   }
   form1.OffConPhone.value = reformatPhone(form1.OffConPhone.value)
   if (!isValidPhoneOrBlank(form1.OffConPhone.value)) {
	   alert ("Please enter a valid, 10-digit Office Contact phone number (type only numbers allowing field to auto-format).")
	   form1.OffConPhone.focus()
	   return false
   }
   if (isEmpty(form1.OffConFax.value)) {
      alert ("Please enter the Office Contact Fax.")
	  form1.OffConFax.focus()
	  return false
   }
   form1.OffConFax.value = reformatPhone(form1.OffConFax.value)
   if (!isValidPhoneOrBlank(form1.OffConFax.value)) {
	   alert ("Please enter a valid, 10-digit Office Contact fax number (type only numbers allowing field to auto-format).")
	   form1.OffConFax.focus()
	   return false
   }
   if (isEmpty(form1.OffConEmail.value)) {
      alert ("Please enter the Office Contact Email.")
	  form1.OffConEmail.focus()
	  return false
   }
   if (isEmpty(form1.SafConName.value)) {
      alert ("Please enter the Safety Contact Name.")
	  form1.SafConName.focus()
	  return false
   }
   if (isEmpty(form1.SafConPhone.value)) {
      alert ("Please enter the Safety Contact Phone.")
	  form1.SafConPhone.focus()
	  return false
   }
   form1.SafConPhone.value = reformatPhone(form1.SafConPhone.value)
   if (!isValidPhoneOrBlank(form1.SafConPhone.value)) {
	   alert ("Please enter a valid, 10-digit Safety Contact phone number (type only numbers allowing field to auto-format).")
	   form1.SafConPhone.focus()
	   return false
   }
   if (isEmpty(form1.SafConFax.value)) {
      alert ("Please enter the Safety Contact Fax.")
	  form1.SafConFax.focus()
	  return false
   }
   form1.SafConFax.value = reformatPhone(form1.SafConFax.value)
   if (!isValidPhoneOrBlank(form1.SafConFax.value)) {
	   alert ("Please enter a valid, 10-digit Safety Contact fax number (type only numbers allowing field to auto-format).")
	   form1.SafConFax.focus()
	   return false
   }
   if (isEmpty(form1.SafConEmail.value)) {
      alert ("Please enter the Safety Contact Email.")
	  form1.SafConEmail.focus()
	  return false
   }
   form1.SiteConPhone.value = reformatPhone(form1.SiteConPhone.value)
   if (!isValidPhoneOrBlank(form1.SiteConPhone.value)) {
      alert ("Please enter a valid, 10-digit Site Contact Phone Number (type only numbers allowing field to auto-format).")
	  form1.SiteConPhone.focus()
	  return false
   }
   form1.SiteConFax.value = reformatPhone(form1.SiteConFax.value)
   if (!isValidPhoneOrBlank(form1.SiteConFax.value)) {
      alert ("Please enter a valid, 10-digit Site Contact Fax Number (type only numbers allowing field to auto-format).")
	  form1.SiteConFax.focus()
	  return false
   }
   form1.PayConPhone.value = reformatPhone(form1.PayConPhone.value)
   if (!isValidPhoneOrBlank(form1.PayConPhone.value)) {
      alert ("Please enter a valid, 10-digit Payroll Contact Phone Number (type only numbers allowing field to auto-format).")
	  form1.PayConPhone.focus()
	  return false
   }
   form1.PayConFax.value = reformatPhone(form1.PayConFax.value)
   if (!isValidPhoneOrBlank(form1.PayConFax.value)) {
      alert ("Please enter a valid, 10-digit Payroll Contact Fax Number (type only numbers allowing field to auto-format).")
	  form1.PayConFax.focus()
	  return false
   }
   if (isEmpty(form1.TypeWork.value)) {
      alert ("Please enter the Type of Work.")
	  form1.TypeWork.focus()
	  return false
   }
   // Enrollment Period Validity Check - end date must be later than the start date
   if (isEmpty(form1.StartDate.value) || !isDate(form1.StartDate.value)) {
      alert ("Please enter a valid Start Date (mm/dd/yyyy).")
	  form1.StartDate.focus()
	  return false
   }
   if (isEmpty(form1.EndDate.value) || !isDate(form1.EndDate.value)) {
      alert ("Please enter a valid Estimated Completion Date (mm/dd/yyyy).")
	  form1.EndDate.focus()
	  return false
   }
	enrolldiff = dateDiffdays(form1.StartDate.value, form1.EndDate.value);
	if (enrolldiff < 0)
	{
		alert("Please enter an Estimated Completion Date that is later than the Start Date.")
		form1.StartDate.focus()
		return false
	}
   val = parseFloat(form1.ContValue.value.replace(/\$|\,/g,""))
   if (isEmpty(form1.ContValue.value) || val <= 0.0 || isNaN(val)) {
      alert ("Please enter the Contract Value. The contract value must be greater than zero.")
	  form1.ContValue.focus()
	  return false
   }
   val = parseFloat(form1.TotalPay.value.replace(/\$|\,/g,""))
   if (isEmpty(form1.TotalPay.value) || val <= 0.0 || isNaN(val)) {
      alert ("Please enter the Estimated Payroll. The estimated payroll must be greater than zero.")
	  form1.TotalPay.focus()
	  return false
   }
   val = parseInt(form1.TotalHours.value)
   if (isEmpty(form1.TotalHours.value) || val <= 0 || isNaN(val)) {
      alert ("Please enter the Estimated Manhours. The estimated manhours must be greater than zero.")
	  form1.TotalHours.focus()
	  return false
   }
   if (isEmpty(form1.NumberSubs.value)) {
	  form1.NumberSubs.value = "0"
   }
   if (isNaN(parseInt(form1.NumberSubs.value))) {
      alert ("Please enter a number for Number of Subcontractors.")
	  form1.NumberSubs.focus()
	  return false
   }
   if (isEmpty(form1.HoursSub.value)) {
	  form1.HoursSub.value = "0.0"
   }
   if (isNaN(parseInt(form1.HoursSub.value))) {
      alert ("Please enter a number for Subcontractor hours.")
	  form1.HoursSub.focus()
	  return false
   }
	/*
   if (isEmpty(form1.AwardCont.value)) {
      alert ("Please enter the Awarding Contractor.")
	  form1.AwardCont.focus()
	  return false
   }
	*/
   if (isEmpty(form1.Form1Sig.value)) {
      alert ("Please enter the Signer's Name.")
	  form1.Form1Sig.focus()
	  return false
   }
   if (isEmpty(form1.Form1Title.value)) {
      alert ("Please enter the Signer's Title.")
	  form1.Form1Title.focus()
	  return false
   }
   if (isEmpty(form1.Form1Phone.value)) {
      alert ("Please enter the Signer's Phone Number.")
	  form1.Form1Phone.focus()
	  return false
   }
   form1.Form1Phone.value = reformatPhone(form1.Form1Phone.value)
   if (!isValidPhoneOrBlank(form1.Form1Phone.value)) {
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form1.Form1Phone.focus()
	   return false
   }
//   alert("Test checkbox.  Is it checked? " + form1.Fm1Affirm.checked)
   if (!form1.Fm1Affirm.checked) {
	   alert ("Please affirm your entries by checking the Affirmation box.")
	   form1.Fm1Affirm.focus()
	   return false
   }
//	alert("Checkbox was apparently checked")
   return true
}


	// converts num to Currency format
	// sets showDollarSign to true if you want a 
	// leading $, otherwise sets it to false
	function toCurrency(num, showDollarSign) {
		if(showDollarSign) {
			return "$" + roundFloat(num, 2)
		} else {
			return roundFloat(num, 2)
		}
	}
	
	// rounds a floating-point number to the
	// specified number of decimal places
	// returns the value in string format
	// to hold the decimal places if decimal
	// value is 0
	function roundFloat(num, decimalPlaces) {
		// convert num to a number if not already
		num = parseFloat(num)

		// multiply num by 10 to the x power, 
		// where x = number of decimalPlaces desired
		var temp = num * Math.pow(10, decimalPlaces)

		// now round to an integer to get rid of 
		// excess digits
		temp = Math.round(temp)

		//convert to a string
		temp = temp.toString()

		// pad numbers that are shorter than the number
		// of decimal points desired with leading zeros
		while (temp.length <= decimalPlaces) {
			temp = "0" + temp
		}

		// determine the index number where the decimal
		// point needs to be inserted and insert it
		var decNdx = temp.length - decimalPlaces
		temp = temp.substring(0, decNdx) + "." +
			   temp.substring(decNdx)
		return temp
	}
	
////////////////////////////////////////////////////////////////////////////
// Function validateForm2()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm2(form2) {
   var val
   var i
   if (isEmpty(form2.InsComp.value)) {
	  resetForm(form2) 
      alert ("Please enter the Insurance Broker or Agent Company Name.")
	  form2.InsComp.focus()
	  return false
   }
   if (isEmpty(form2.InsConPhone.value)) {
	  resetForm(form2) 
      alert ("Please enter the Insurance Broker Phone Number.")
	  form2.InsConPhone.focus()
	  return false
   }
   form2.InsConPhone.value = reformatPhone(form2.InsConPhone.value)
   if (!isValidPhoneOrBlank(form2.InsConPhone.value)) {
	  resetForm(form2) 
	   alert ("Please enter a valid, 10-digit Insurance Provider Phone Number (type only numbers allowing field to auto-format).")
	   form2.InsConPhone.focus()
	   return false
   }
   if (isEmpty(form2.WCComp.value)) {
	  resetForm(form2) 
      alert ("Please enter the Workmen's Compensation Insurance Broker or Agent Company Name.")
	  form2.WCComp.focus()
	  return false
   }
   if (isEmpty(form2.WCPolicyStart.value) || !isDate(form2.WCPolicyStart.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Policy Start Date (mm/dd/yyyy).")
	  form2.WCPolicyStart.focus()
	  return false
   }
   if (isEmpty(form2.WCPolicyEnd.value) || !isDate(form2.WCPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Policy End Date (mm/dd/yyyy).")
	  form2.WCPolicyEnd.focus()
	  return false
   }
   if (expired(form2.WCPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("The WC Policy End Date entered has already passed. Please enter a valid Policy End Date.")
	  form2.WCPolicyEnd.focus()
	  return false
   }
   // Coverage Period Validity Check - 1 year or less
	var today = new Date()
	var todaysDate = (today.getMonth() + 1)
	wcdiff = dateDiffdays(form2.WCPolicyStart.value, form2.WCPolicyEnd.value);
	if (wcdiff < 0)
	{
		alert("Please enter a WC Policy ending date later than the starting date.")
		form2.WCPolicyEnd.focus()
		return false
	}
	if (wcdiff > 366)
	{
		alert("Please enter a WC Policy period that is not more than one year.")
		form2.WCPolicyStart.focus()
		return false
	}
   if (isEmpty(form2.WCPolicyNumber.value)) {
	  resetForm(form2) 
      alert ("Please enter the Workmen's Compensation Insurance Policy Number.")
	  form2.WCPolicyNumber.focus()
	  return false
   }
   val = parseFloat(form2.WCExpModRate.value)
   if (isEmpty(form2.WCExpModRate.value) || val < 0.5 || val >10.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a valid value for WC Experience Modifier.")
	  form2.WCExpModRate.focus()
	  return false
   }
   val = parseInt(form2.WCCode1.value)
   if (isEmpty(form2.WCCode1.value) || form2.WCCode1.value == 0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for WC Code 1.")
	  form2.WCCode1.focus()
	  return false
   }
   val = parseFloat(form2.WCRate1.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.WCRate1.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for WC Rate 1.")
	  form2.WCRate1.focus()
	  return false
   }
   val = parseFloat(form2.WCPay1.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.WCPay1.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for WC Payroll 1.")
	  form2.WCPay1.focus()
	  return false
   }
   val = parseFloat(form2.WCPrem1.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.WCPrem1.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for WC Premium 1.")
	  form2.WCPrem1.focus()
	  return false
   }
   if (isEmpty(form2.GLComp.value)) {
	  resetForm(form2) 
      alert ("Please enter the General Liability Insurance Broker or Agent Company Name.")
	  form2.GLComp.focus()
	  return false
   }
   if (isEmpty(form2.GLPolicyStart.value) || !isDate(form2.GLPolicyStart.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid General Liability Policy Start Date (mm/dd/yyyy).")
	  form2.GLPolicyStart.focus()
	  return false
   }
   if (isEmpty(form2.GLPolicyEnd.value) || !isDate(form2.GLPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid General Liability Policy End Date (mm/dd/yyyy).")
	  form2.GLPolicyEnd.focus()
	  return false
   }
   if (expired(form2.GLPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("The GL Policy End Date entered has already passed. Please enter a valid Policy End Date.")
	  form2.GLPolicyEnd.focus()
	  return false
   }
   // Coverage Period Validity Check - 1 year or less
	gldiff = dateDiffdays(form2.GLPolicyStart.value, form2.GLPolicyEnd.value);
	if (gldiff < 0)
	{
		alert("Please enter a GL Policy ending date later than the starting date.")
		form2.GLPolicyEnd.focus()
		return false
	}
	if (gldiff > 366)
	{
		alert("Please enter a GL Policy period that is not more than one year.")
		form2.GLPolicyStart.focus()
		return false
	}
   if (isEmpty(form2.GLPolicyNumber.value)) {
	  resetForm(form2) 
      alert ("Please enter the General Liability Insurance Policy Number.")
	  form2.GLPolicyNumber.focus()
	  return false
   }
   if (isEmpty(form2.GLCode1.value) || form2.GLCode1.value == 0 || isNaN(parseInt(form2.GLCode1.value))) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for GL Code 1.")
	  form2.GLCode1.focus()
	  return false
   }
   val = parseFloat(form2.GLRate1.value.replace(/\$|\,/g,""))
   if (form2.GLRateBase.value == "Payroll" && (isEmpty(form2.GLRate1.value) || val == 0.0 || isNaN(val))) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for GL Rate 1.")
	  form2.GLRate1.focus()
	  return false
   }
   val = parseFloat(form2.GLPay1.value.replace(/\$|\,/g,""))
   if (form2.GLRateBase.value == "Payroll" && (isEmpty(form2.GLPay1.value) || val == 0.0 || isNaN(val))) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for GL Payroll 1.")
	  form2.GLPay1.focus()
	  return false
   }
   val = parseFloat(form2.GLPrem1.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.GLPrem1.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for GL Premium 1.")
	  form2.GLPrem1.focus()
	  return false
   }
   if (isEmpty(form2.WCSubTotPrem.value)) {
	  resetForm(form2) 
      alert ("Please enter WC data and the form computes the WC Premium Subtotal.")
	  form2.WCCode1.focus()
	  return false
   }
   if (isEmpty(form2.WCExpModRate.value)) {
	  resetForm(form2) 
      alert ("Please enter the WC Experience Modifier.")
	  form2.WCExpModRate.focus()
	  return false
   }
   if (isEmpty(form2.WCPrem.value)) {
	  resetForm(form2) 
      alert ("Please enter WC data and the form computes the WC Premium.")
	  form2.WCCode1.focus()
	  return false
   }
   if (isEmpty(form2.GLPrem.value)) {
	  resetForm(form2) 
      alert ("Please enter GL data and the form computes the GL Total Premium.")
	  form2.GLCode1.focus()
	  return false
   }
   if (isEmpty(form2.GLSubTotal.value)) {
	  resetForm(form2) 
      alert ("Please enter GL data and the form computes the GL Premium Subtotal.")
	  form2.GLCode1.focus()
	  return false
   }
   if (isEmpty(form2.UmbComp.value)) {
	  resetForm(form2) 
      alert ("Please enter the Umbrella Insurance Provider.")
	  form2.UmbComp.focus()
	  return false
   }
   val = parseFloat(form2.UmbLimit.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.UmbLimit.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for Umbrella Insurance Coverage Limit.")
	  form2.UmbLimit.focus()
	  return false
   }
   if (isEmpty(form2.UmbPolicyStart.value) || !isDate(form2.UmbPolicyStart.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Umbrella Insurance Policy Start Date (mm/dd/yyyy).")
	  form2.UmbPolicyStart.focus()
	  return false
   }
   if (isEmpty(form2.UmbPolicyEnd.value) || !isDate(form2.UmbPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Umbrella Insurance Policy End Date (mm/dd/yyyy).")
	  form2.UmbPolicyEnd.focus()
	  return false
   }
   if (expired(form2.UmbPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("The Umbrella Policy End Date entered has already passed. Please enter a valid Policy End Date.")
	  form2.UmbPolicyEnd.focus()
	  return false
   }
   // Coverage Period Validity Check - 1 year or less
	umbdiff = dateDiffdays(form2.UmbPolicyStart.value, form2.UmbPolicyEnd.value);
	if (umbdiff < 0)
	{
		alert("Please enter a Umbrella Policy ending date later than the starting date.")
		form2.UmbPolicyEnd.focus()
		return false
	}
	if (umbdiff > 366)
	{
		alert("Please enter a Umbrella Policy period that is not more than one year.")
		form2.UmbPolicyStart.focus()
		return false
	}
   if (isEmpty(form2.UmbPolicyNumber.value)) {
	  resetForm(form2) 
      alert ("Please enter the Umbrella Insurance Policy Number.")
	  form2.UmbPolicyNumber.focus()
	  return false
   }
   val = parseFloat(form2.UmbPrem.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.UmbPrem.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for Umbrella Insurance Premium.")
	  form2.UmbPrem.focus()
	  return false
   }
   if (isEmpty(form2.AutoComp.value)) {
	  resetForm(form2) 
      alert ("Please enter the Auto Insurance Provider.")
	  form2.AutoComp.focus()
	  return false
   }
   val = parseFloat(form2.AutoLimit.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.AutoLimit.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for Automobile Insurance Coverage Limit.")
	  form2.AutoLimit.focus()
	  return false
   }
   if (isEmpty(form2.AutoPolicyStart.value) || !isDate(form2.AutoPolicyStart.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Automobile Insurance Policy Start Date (mm/dd/yyyy).")
	  form2.AutoPolicyStart.focus()
	  return false
   }
   if (isEmpty(form2.AutoPolicyEnd.value) || !isDate(form2.AutoPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("Please enter a valid Automobile Insurance Policy End Date (mm/dd/yyyy).")
	  form2.AutoPolicyEnd.focus()
	  return false
   }
   if (expired(form2.AutoPolicyEnd.value)) {
	  resetForm(form2) 
      alert ("The Auto Policy End Date entered has already passed. Please enter a valid Policy End Date.")
	  form2.AutoPolicyEnd.focus()
	  return false
   }
   // Coverage Period Validity Check - 1 year or less
	autodiff = dateDiffdays(form2.AutoPolicyStart.value, form2.AutoPolicyEnd.value);
	if (autodiff < 0)
	{
		alert("Please enter a Auto Policy ending date later than the starting date.")
		form2.AutoPolicyEnd.focus()
		return false
	}
	if (autodiff > 366)
	{
		alert("Please enter a Auto Policy period that is not more than one year.")
		form2.AutoPolicyStart.focus()
		return false
	}
   if (isEmpty(form2.AutoPolicyNumber.value)) {
	  resetForm(form2) 
      alert ("Please enter the Auto Insurance Policy Number.")
	  form2.AutoPolicyNumber.focus()
	  return false
   }
   val = parseInt(form2.AutoNumVehicles.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.AutoNumVehicles.value) || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a value for Number of Vehicles.")
	  form2.AutoNumVehicles.focus()
	  return false
   }
   val = parseInt(form2.AutoNumVehiclesOnSite.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.AutoNumVehiclesOnSite.value) || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a value for Number of Vehicles On Site.")
	  form2.AutoNumVehiclesOnSite.focus()
	  return false
   }
   val = parseInt(form2.AutoNumMobileEquipment.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.AutoNumMobileEquipment.value) || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a value for Number of Mobile Equipment.")
	  form2.AutoNumMobileEquipment.focus()
	  return false
   }
   val = parseFloat(form2.AutoPrem.value.replace(/\$|\,/g,""))
   if (isEmpty(form2.AutoPrem.value) || val == 0.0 || isNaN(val)) {
	  resetForm(form2) 
      alert ("Please enter a non-zero value for Automobile Insurance Premium.")
	  form2.AutoPrem.focus()
	  return false
   }
   if (isEmpty(form2.Form2Compl.value)) {
	  resetForm(form2) 
      alert ("Please enter your name as the signer.")
	  form2.Form2Compl.focus()
	  return false
   }
   if (isEmpty(form2.Form2ComplPhone.value)) {
	  resetForm(form2) 
      alert ("Please enter your telephone number.")
	  form2.Form2ComplPhone.focus()
	  return false
   }
   form2.Form2ComplPhone.value = reformatPhone(form2.Form2ComplPhone.value)
   if (!isValidPhoneOrBlank(form2.Form2ComplPhone.value)) {
	  resetForm(form2) 
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form2.Form2ComplPhone.focus()
	   return false
   }
   if (!form2.Affirm.checked) {
	  resetForm(form2) 
      alert ("Please check the checkbox at the bottom of the form and then press the Send button.")
	  form2.Affirm.focus()
	  return false
   }
   // Enable GL fields
   GLwakeup(form2, 7)
   return true
}

function GLwakeup(theForm, numlines)
{
   var i;
   
   if (theForm.name == "Form2")
   {
      if (theForm.Affirm.checked)
		{
			if (!isEmpty(theForm.Form2Compl.value))
			{
				for (i=1; i <= numlines; i++) {
				  theForm["GLRate"+i].disabled = false;
				  theForm["GLPay"+i].disabled = false;
				  theForm["GLPrem"+i].disabled = false;
				}
				return true;
			}
			else
			{
				alert("Please enter your name on the signature line and the date before checking the confirmaton box.");
				theForm.Affirm.checked = false;
				theForm.Form2Compl.focus();
				return false;
			}
		}
		else
		{
		   GLsleep(theForm);
		}
   } else if (theForm.name == "Form3") {
      if (theForm.Affirm.checked)
		{
			if (!isEmpty(theForm.Form3Sig.value))
			{
				for (i=1; i <= numlines; i++) {
				  theForm["GLRate"+i].disabled = false;
				  theForm["GLPay"+i].disabled = false;
				  theForm["GLPrem"+i].disabled = false;
				}
				return true;
			}
			else
			{
				alert("Please enter your name on the signature line and the date before checking the confirmaton box.");
				theForm.Affirm.checked = false;
				theForm.Form3Sig.focus();
				return false;
			}
		}
		else
		{
			GLsleep(theForm);
		}
   }
}

function GLsleep(theForm)
{
   var i;
   var numlines = theForm.Num_GL_Lines.value;
   if (theForm.GLRateBase.value == "Payroll")
   {
      for (i=1; i <= numlines; i++) {
	     theForm["GLRate"+i].disabled = false;
	     theForm["GLPay"+i].disabled = false;
	     theForm["GLPrem"+i].disabled = true;
      }
   }
   else
   {
      for (i=1; i <= numlines; i++) {
	     theForm["GLRate"+i].disabled = true;
	     theForm["GLPay"+i].disabled = true;
	     theForm["GLPrem"+i].disabled = false;
      }
   }
}

function ClearAffirmBox(theForm)
{
      theForm.Affirm.checked = false;
}

function resetForm(theForm)
{
	GLsleep(theForm);
	ClearAffirmBox(theForm);
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm3()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm3(form3) {
   var val
/*
   if (isEmpty(form3.ContName.value)) {
      alert ("Please enter the Contractor Name.")
	  form3.ContName.focus()
	  return false
   }
   if (isEmpty(form3.ContAddr.value)) {
      alert ("Please enter the Contractor Street Address.")
	  form3.ContAddr.focus()
	  return false
   }
   if (isEmpty(form3.ContCSZ.value)) {
      alert ("Please enter the Contractor City, State and Zip Code.")
	  form3.ContCSZ.focus()
	  return false
   }
   if (isEmpty(form3.ContPhone.value)) {
      alert ("Please enter the Contractor Phone Number.")
	  form3.ContPhone.focus()
	  return false
   }
   form3.ContPhone.value = reformatPhone(form3.ContPhone.value)
   if (!isValidPhoneOrBlank(form3.ContPhone.value)) {
	   alert ("Please enter a valid, 10-digit Contrator phone number (type only numbers allowing field to auto-format).")
	   form3.ContPhone.focus()
	   return false
   }
   if (isEmpty(form3.OffConName.value)) {
      alert ("Please enter the Office Contact Name.")
	  form3.OffConName.focus()
	  return false
   }
   if (isEmpty(form3.OffConPhone.value)) {
      alert ("Please enter the Office Contact Phone.")
	  form3.OffConPhone.focus()
	  return false
   }
   form3.OffConPhone.value = reformatPhone(form3.OffConPhone.value)
   if (!isValidPhoneOrBlank(form3.OffConPhone.value)) {
	   alert ("Please enter a valid, 10-digit Office Contact phone number (type only numbers allowing field to auto-format).")
	   form3.OffConPhone.focus()
	   return false
   }
   if (isEmpty(form3.OffConFax.value)) {
      alert ("Please enter the Office Contact Fax.")
	  form3.OffConFax.focus()
	  return false
   }
   form3.OffConFax.value = reformatPhone(form3.OffConFax.value)
   if (!isValidPhoneOrBlank(form3.OffConFax.value)) {
	   alert ("Please enter a valid, 10-digit Office Contact fax number (type only numbers allowing field to auto-format).")
	   form3.OffConFax.focus()
	   return false
   }
   if (isEmpty(form3.OffConEmail.value)) {
      alert ("Please enter the Office Contact Email.")
	  form3.OffConEmail.focus()
	  return false
   }
*/

   val = parseFloat(form3.ContValue.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.ContValue.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter the Contract Value of the Additional Work. The contract value must be greater than zero.")
	  form3.ContValue.focus()
	  return false
   }
   
   if (isEmpty(form3.TypeWork.value)) {
      alert ("Please enter the Type of Work.")
	  form3.TypeWork.focus()
	  return false
   }
   if (isEmpty(form3.StartDate.value) || !isDate(form3.StartDate.value)) {
      alert ("Please enter a valid Start Date (mm/dd/yyyy).")
	  form3.StartDate.focus()
	  return false
   }
   if (isEmpty(form3.EndDate.value) || !isDate(form3.EndDate.value)) {
      alert ("Please enter a valid Estimated Completion Date (mm/dd/yyyy).")
	  form3.EndDate.focus()
	  return false
   }
   val = parseInt(form3.TotalHours.value)
   if (isEmpty(form3.TotalHours.value) || val == 0 || isNaN(val)) {
      alert ("Please enter the Estimated Manhours. The estimated manhours must be greater than zero.")
	  form3.TotalHours.focus()
	  return false
   }
/*
   if (isEmpty(form3.AwardCont.value)) {
      alert ("Please enter the Awarding Contractor.")
	  form3.AwardCont.focus()
	  return false
   }
*/

   if (isEmpty(form3.WCCode1.value) || form3.WCCode1.value == 0 || isNaN(parseInt(form3.WCCode1.value))) {
      alert ("Please enter a non-zero value for WC Code 1.")
	  form3.WCCode1.focus()
	  return false
   }
   val = parseFloat(form3.WCRate1.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.WCRate1.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter a non-zero value for WC Rate 1.")
	  form3.WCRate1.focus()
	  return false
   }
   val = parseFloat(form3.WCPay1.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.WCPay1.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter a non-zero value for WC Payroll 1.")
	  form3.WCPay1.focus()
	  return false
   }
   val = parseFloat(form3.WCPrem1.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.WCPrem1.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter a non-zero value for WC Premium 1.")
	  form3.WCPrem1.focus()
	  return false
   }
   if (isEmpty(form3.GLCode1.value) || form3.GLCode1.value == 0 || isNaN(parseInt(form3.GLCode1.value))) {
      alert ("Please enter a non-zero value for GL Code 1.")
	  form3.GLCode1.focus()
	  return false
   }
   val = parseFloat(form3.GLRate1.value.replace(/\$|\,/g,""))
   if (form3.GLRateBase.value != "Flat Premium" && (isEmpty(form3.GLRate1.value) || val == 0.0 || isNaN(val))) {
      alert ("Please enter a non-zero value for GL Rate 1.")
	  form3.GLRate1.focus()
	  return false
   }
   val = parseFloat(form3.GLPay1.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.GLPay1.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter a non-zero value for GL Payroll 1.")
	  form3.GLPay1.focus()
	  return false
   }
   val = parseFloat(form3.GLPrem1.value.replace(/\$|\,/g,""))
   if (isEmpty(form3.GLPrem1.value) || val == 0.0 || isNaN(val)) {
      alert ("Please enter a non-zero value for GL Premium 1.")
	  form3.GLPrem1.focus()
	  return false
   }
   if (isEmpty(form3.WCIncrLim.value)) {
      alert ("Please enter the WC Increased Limit Factor.")
	  form3.WCIncrLim.focus()
	  return false
   }
   if (isEmpty(form3.WCExpModAdj.value)) {
      alert ("Please enter the WC Experience Modifier.")
	  form3.WCExpModAdj.focus()
	  return false
   }
   if (isEmpty(form3.PremDiscount.value)) {
      alert ("Please enter the WC Premium Discount")
	  form3.PremDiscount.focus()
	  return false
   }
   if (isEmpty(form3.ExcessTotal.value)) {
      alert ("Please enter the Excess Liability.")
	  form3.ExcessTotal.focus()
	  return false
   }
   if (isEmpty(form3.Form3Sig.value)) {
      alert ("Please enter your name as the signer.")
	  form3.Form3Sig.focus()
	  return false
   }
//   alert("Document is signed");
   if (isEmpty(form3.Form3ComplTitle.value)) {
      alert ("Please enter your job title.")
	  form3.Form3ComplTitle.focus()
	  return false
   }
//   alert("Title? check");
   if (isEmpty(form3.Form3Phone.value)) {
      alert ("Please enter your telephone number.")
	  form3.Form3Phone.focus()
	  return false
   }
//   alert("Signer Phone? check");
   form3.Form3Phone.value = reformatPhone(form3.Form3Phone.value)
   if (!isValidPhoneOrBlank(form3.Form3Phone.value)) {
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form3.Form3Phone.focus()
	   return false
   }
//   alert("Phone valid? check");
   if (!form3.Affirm.checked) {
	  resetForm(form3) 
      alert ("Please check the checkbox at the bottom of the form and then press the Send button.")
	  form3.Affirm.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm4()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm4(form4) {
   var val
   if (isEmpty(form4.CompletionDate.value) || !isDate(form4.CompletionDate.value)) {
      alert ("Please enter a valid Completion Date (mm/dd/yyyy).")
	  form4.CompletionDate.focus()
	  return false
   }
   if (isEmpty(form4.AwardCont.value)) {
      alert ("Please enter the Awarding Contractor.")
	  form4.AwardCont.focus()
	  return false
   }
   if (isEmpty(form4.Form4Sig.value)) {
      alert ("Please enter your name as the signer.")
	  form4.Form4Sig.focus()
	  return false
   }
//   alert("Document is signed");
   if (isEmpty(form4.Form4Title.value)) {
      alert ("Please enter your job title.")
	  form4.Form4Title.focus()
	  return false
   }
//   alert("Title? check");
   if (isEmpty(form4.Form4Phone.value)) {
      alert ("Please enter your telephone number.")
	  form4.Form4Phone.focus()
	  return false
   }
//   alert("Signer Phone? check");
   form4.Form4Phone.value = reformatPhone(form4.Form4Phone.value)
   if (!isValidPhoneOrBlank(form4.Form4Phone.value)) {
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form4.Form4Phone.focus()
	   return false
   }
//   alert("Phone valid? check");
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm6()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm6(form6) {
   var val
   if (isEmpty(form6.CompletionDate.value) || !isDate(form6.CompletionDate.value)) {
      alert ("Please enter a valid Completion Date (mm/dd/yyyy).")
	  form6.CompletionDate.focus()
	  return false
   }
   if (isEmpty(form6.AwardCont.value)) {
      alert ("Please enter the Awarding Contractor.")
	  form6.AwardCont.focus()
	  return false
   }
   if (isEmpty(form6.Form6Sig.value)) {
      alert ("Please enter your name as the signer.")
	  form6.Form6Sig.focus()
	  return false
   }
//   alert("Document is signed");
   if (isEmpty(form6.Form6Title.value)) {
      alert ("Please enter your job title.")
	  form6.Form6Title.focus()
	  return false
   }
//   alert("Title? check");
   if (isEmpty(form6.Form6Phone.value)) {
      alert ("Please enter your telephone number.")
	  form6.Form6Phone.focus()
	  return false
   }
//   alert("Signer Phone? check");
   form6.Form6Phone.value = reformatPhone(form6.Form6Phone.value)
   if (!isValidPhoneOrBlank(form6.Form6Phone.value)) {
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form6.Form6Phone.focus()
	   return false
   }
//   alert("Phone valid? check");
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm5()                                               //
////////////////////////////////////////////////////////////////////////////
function validateForm5(form5, num_lines) {
   var val
   var i
   var codeID
   var codeval
   var payID
   var payval
   var hoursregID
   var hoursregval
   var hoursOTID
   var hoursOTval
	
   // Check validity of the Month.
   val = parseInt(form5.Month.value)
   if (isEmpty(form5.Month.value) || val == 0 || isNaN(val)) {
      alert ("Please select the Payroll Period Month.")
	  form5.Month.focus()
	  return false
   }
   // Check validity of the Year
   val = parseInt(form5.Year.value)
   if (isEmpty(form5.Year.value) || val == 0 || isNaN(val)) {
      alert ("Please select the Payroll Period Year.")
      form5.Year.focus()
      return false
   }
   for (i=1; i <= num_lines; i++) {
      // Check validity of WC Code
	  //    Must have atleast one WC Code on a form 5.
	  //    All WC Codes from enrollment should be listed, even if there are 0 hours to report.
	  //    Each WC Code must be a 4-digit number.
      codeID = "Fm5WCCode"+i
      codeval = form5[codeID].value
      val = parseInt(codeval)
	  if (i==1 && isEmpty(codeval)) {
         alert ("Please enter all WC Codes from your OCIP enrollment, even if there are 0 hours to report.")
		 form5[codeID].focus()
         return false
	  }
      if (!isEmpty(codeval) && (isNaN(val) || val > 9999) ) {
         alert ("Please enter a valid WC Code on line " + i + ".")
	     form5[codeID].focus()
	     return false
      }
      // Check validity of pay amount
	  //    If a WC Code is listed on the same line, a pay amount must be given.
	  //    If a pay amount is given, it must be a valid floating point number.
	  payID = "Fm5WCPay" + i
	  payval = form5[payID].value
	  val = parseFloat(payval.replace(/\$|\,/g,""))
      if (i==1 && isEmpty(payval)) {
	     alert ("Please enter a pay amount for line 1.")
		 form5[payID].focus()
		 return false
	  }
      if (!isEmpty(codeval) && ( isEmpty(payval) || payval < 0 || isNaN(val))) {
         alert ("Please enter a valid, positive WC Pay value on line " + i + ".")
	     form5[payID].focus()
	     return false
      }
	  // Check validity of Regular Hours
	  //    If a WC Code is listed on the same line, a regular hours worked amount must be given
	  //    If a regular hours amount is given, it must be a valid floating point number.
	  hoursregID = "Fm5HoursReg" + i
	  hoursregval = form5[hoursregID].value
      val = parseFloat(hoursregval)
	  if (i==1 && isEmpty(hoursregval)) {
		 alert ("Please enter the amount of regular hours worked on line " + i + ".")
		 form5[hoursregID].focus()
		 return false
	  }
      if (!isEmpty(codeval) && (isEmpty(hoursregval) || isNaN(val))) {
         alert ("Please enter a valid amount of regular hours worked on line " + i + ".")
		 form5[hoursregID].focus()
	     return false
      }
	  // Check validity of OverTime Hours
	  //    If a WC Code is listed on the same line, an OT hours worked amount must be given
	  //    If an OT hours amount is given, it must be a valid floating point number.
	  hoursOTID = "Fm5HoursOT" + i
	  hoursOTval = form5[hoursOTID].value
      val = parseFloat(hoursOTval)
	  if (i==1 && isEmpty(hoursOTval)) {
		 alert ("Please enter the amount of over time hours worked on line " + i + ".")
		 form5[hoursOTID].focus()
		 return false
	  }
      if (!isEmpty(codeval) && (isEmpty(hoursOTval) || isNaN(val))) {
         alert ("Please enter a valid amount of over time hours worked on line " + i + ".")
		 form5[hoursOTID].focus()
	     return false
      }
   }
/*
   // Check validity of the Number of Illness/Injury Cases
   val = parseInt(form5.NumCases.value)
   if (isEmpty(form5.NumCases.value) || isNaN(val)) {
      alert ("Please enter the number of work-related illness and injury cases.")
      form5.NumCases.focus()
      return false
   }
*/
   
   // Check validity of Form 5 Signature
   if (isEmpty(form5.Form5Sig.value)) {
      alert ("Please enter your name as the signer.")
	  form5.Form5Sig.focus()
	  return false
   }
   // Check validity of Form 5 Phone
   if (isEmpty(form5.Form5Phone.value)) {
      alert ("Please enter your telephone number.")
	  form5.Form5Phone.focus()
      return false
   }
   form5.Form5Phone.value = reformatPhone(form5.Form5Phone.value)
   if (!isValidPhoneOrBlank(form5.Form5Phone.value)) {
	   alert ("Please enter a valid, 10-digit Signer Phone Number (type only numbers allowing field to auto-format).")
	   form5.Form5Phone.focus()
	   return false
   }
   // Check validity of Form 5 Affirmation box
   if (!form5.Fm5Affirm.checked) {
      alert ("Please check the checkbox at the bottom of the form and then press the Complete button.")
	  form5.Fm5Affirm.focus()
	  return false
   }
   else
      return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm300()                              //
////////////////////////////////////////////////////////////////////////////
function validateForm300(form) {
   var val
   var i
   var j
   var checkedButton
   // Check validity of the Establishment Name.
   if (isEmpty(form.EstablishmentName.value) ) {
      alert ("Please enter the Establishment Name.")
	  form.EstablishmentName.focus()
	  return false
   }
   // Check validity of the City.
   if (isEmpty(form.City.value) ) {
      alert ("Please enter the City.")
	  form.City.focus()
	  return false
   }
   // Check validity of the State.
   if (isEmpty(form.State.value) ) {
      alert ("Please enter the State.")
	  form.State.focus()
	  return false
   }
   numcases = parseInt(form.numcases.value)
   for (i=0; i<numcases; i++)
   {
	   // Check Employee Name
	   if (isEmpty(form['EmployeeName'+i].value) ){
		  alert ("Please enter the Employee name on line #" + (i+1) + ".")
		  form['EmployeeName'+i].focus()
		  return false
	   }
	   // Check Job Title
	   if (isEmpty(form['JobTitle'+i].value) ){
		  alert ("Please enter the Job Title on line #" + (i+1) + ".")
		  form['JobTitle'+i].focus()
		  return false
	   }
	   // Check Illness/Injury Date
	   if (isEmpty(form['IllnessInjuryDate'+i].value) ){
		  alert ("Please enter the illness/Injury Date on line #" + (i+1) + ".")
		  form['IllnessInjuryDate'+i].focus()
		  return false
	   }
	   // Check Illness/Injury Location
	   if (isEmpty(form['IllnessInjuryLocation'+i].value) ){
		  alert ("Please enter the Illness/Injury Location on line #" + (i+1) + ".")
		  form['IllnessInjuryLocation'+i].focus()
		  return false
	   }
	   // Check Illness/Injury Description
	   if (isEmpty(form['IllnessInjuryDescription'+i].value) ){
		  alert ("Please enter the Injury/Illness Descrption on line #" + (i+1) + ".")
		  form['IllnessInjuryDescription'+i].focus()
		  return false
	   }
	   // Check the Classification
	   checkedButton = -1
	   for (j = 0; j < form["Classification"+i].length; j++) {
		   if (form["Classification"+i][j].checked) {
			   checkedButton = j
		   }
	   }
       if (checkedButton == -1) {	   
		  alert ("Please Classify the case (from columns G-J) on line #" + (i+1) + ".")
		  form['Classification'+i].focus()
		  return false
	   }
	   // Check validity of the Number of Days Lost Cases
	   val = parseInt(form['DaysLost'+i].value)
	   if (isEmpty(form['DaysLost'+i].value) || isNaN(val)) {
		  alert ("The days away count (column K) is either blank or not a number on line #" + (i+1) +".")
		  form['DaysLost'+i].focus()
		  return false
	   }
	   // Check validity of the Number of Days Restricted Cases
	   val = parseInt(form['DaysRestricted'+i].value)
	   if (isEmpty(form['DaysRestricted'+i].value) || isNaN(val)) {
		  alert ("The days restricted count (column L) is either blank or not a number on line #" + (i+1) +".")
		  form['DaysRestricted'+i].focus()
		  return false
	   }
	   // Check the Injury Type
	   checkedButton = -1
	   for (j = 0; j < form["InjuryType"+i].length; j++) {
		   if (form["InjuryType"+i][j].checked) {
			   checkedButton = j
		   }
	   }
       if (checkedButton == -1) {	   
		  alert ("Please select the Illness/Injury Type (column M)  on line #" + (i+1) + ".")
		  form['InjuryType'+i].focus()
		  return false
	   }
   }
   // Check validity of the Number of Death Cases
   val = parseInt(form.DeathCaseTotal.value)
   if (isEmpty(form.DeathCaseTotal.value) || isNaN(val)) {
      alert ("The death case total (column G) is either blank or not a number.")
      form.DeathCaseTotal.focus()
      return false
   }
   // Check validity of the Number of Days Away Cases
   val = parseInt(form.DaysAwayCaseTotal.value)
   if (isEmpty(form.DaysAwayCaseTotal.value) || isNaN(val)) {
      alert ("The days away from work total (column H) is either blank or not a number.")
      form.DaysAwayCaseTotal.focus()
      return false
   }
   // Check validity of the Number of Job Transfer or Restriction Cases
   val = parseInt(form.JobTransferCaseTotal.value)
   if (isEmpty(form.JobTransferCaseTotal.value) || isNaN(val)) {
      alert ("The job transfer or restriction total (column I) is either blank or not a number.")
      form.JobTransferCaseTotal.focus()
      return false
   }
   // Check validity of the Number of Other Recordable Cases
   val = parseInt(form.OtherRecordableCaseTotal.value)
   if (isEmpty(form.OtherRecordableCaseTotal.value) || isNaN(val)) {
      alert ("The other recordable cases total (column J) is either blank or not a number.")
      form.OtherRecordableCaseTotal.focus()
      return false
   }
   // Check validity of the Number of Days Lost Cases
   val = parseInt(form.DaysLostTotal.value)
   if (isEmpty(form.DaysLostTotal.value) || isNaN(val)) {
      alert ("The days away count total (column K) is either blank or not a number.")
      form.DaysLostTotal.focus()
      return false
   }
   // Check validity of the Number of Days Restricted Cases
   val = parseInt(form.DaysRestrictedTotal.value)
   if (isEmpty(form.DaysRestrictedTotal.value) || isNaN(val)) {
      alert ("The days restricted count total (column L) is either blank or not a number.")
      form.DaysRestrictedTotal.focus()
      return false
   }
   // Check validity of the Number of Injury Cases
   val = parseInt(form.InjuryTotal.value)
   if (isEmpty(form.InjuryTotal.value) || isNaN(val)) {
      alert ("The injury case total (column M-1) is either blank or not a number.")
      form.InjuryTotal.focus()
      return false
   }
   // Check validity of the Number of Skin Disorder Cases
   val = parseInt(form.SkinDisorderTotal.value)
   if (isEmpty(form.SkinDisorderTotal.value) || isNaN(val)) {
      alert ("The skin disorder case total (column M-2) is either blank or not a number.")
      form.SkinDisorderTotal.focus()
      return false
   }
   // Check validity of the Number of Respiratory Cases
   val = parseInt(form.RespiratoryTotal.value)
   if (isEmpty(form.RespiratoryTotal.value) || isNaN(val)) {
      alert ("The respiratory case total (column M-3) is either blank or not a number.")
      form.RespiratoryTotal.focus()
      return false
   }
   // Check validity of the Number of Poisoning Cases
   val = parseInt(form.PoisoningCaseTotal.value)
   if (isEmpty(form.PoisoningCaseTotal.value) || isNaN(val)) {
      alert ("The poisoning case total (column M-4) is either blank or not a number.")
      form.PoisoningCaseTotal.focus()
      return false
   }
   // Check validity of the Number of Hearing Loss Cases
   val = parseInt(form.HearingLossCaseTotal.value)
   if (isEmpty(form.HearingLossCaseTotal.value) || isNaN(val)) {
      alert ("The hearing loss case total (column M-5) is either blank or not a number.")
      form.HearingLossCaseTotal.focus()
      return false
   }
   // Check validity of the Number of All Other Illness Cases
   val = parseInt(form.OtherIllnessTotal.value)
   if (isEmpty(form.OtherIllnessTotal.value) || isNaN(val)) {
      alert ("The all other illness case total (column M-6) is either blank or not a number.")
      form.OtherIllnessTotal.focus()
      return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateForm5request_daterange()                              //
////////////////////////////////////////////////////////////////////////////
function validateForm5request_daterange(form) {
   var val
   // Date Range is mandatory
   // Check validity of the Start of the Date Range.
   val = parseInt(form.RangeStart.value)
   if (isEmpty(form.RangeStart.value) || !dateValid(val)) {
      alert ("Please enter a valid Date Range Start (mm/dd/yyyy).")
	  form.RangeStart.focus()
	  return false
   }
   // Check validity of the End of the Date Range
   val = parseInt(form.RangeEnd.value)
   if (isEmpty(form.RangeEnd.value) || !dateValid(val)) {
      alert ("Please enter a valid Date Range End (mm/dd/yyyy).")
	  form.RangeEnd.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function validateHelp()                                               //
////////////////////////////////////////////////////////////////////////////
function validateHelp(formH) {
   var val
   if (isEmpty(formH.subject.value)) {
      alert ("Please select the Subject.")
	  formH.subject.focus()
	  return false
   }
   if (isEmpty(formH.sender_name.value)) {
      alert ("Please enter your name.")
	  formH.sender_name.focus()
	  return false
   }
   formH.sender_phone.value = reformatPhone(formH.sender_phone.value)
   if (!isValidPhoneOrBlank(formH.sender_phone.value)) {
	   alert ("Please enter a valid, 10-digit Phone Number (type only numbers allowing field to auto-format).")
	   formH.sender_phone.focus()
	   return false
   }
   if (isEmpty(formH.sender_email.value)) {
      alert ("Please enter your Email Address.")
	  formH.sender_email.focus()
	  return false
   }
   if (isEmpty(formH.sender_company.value)) {
      alert ("Please enter your Company Name.")
	  formH.sender_company.focus()
	  return false
   }
   if (isEmpty(formH.sender_FEIN.value)) {
      alert ("Please enter your Company FEIN.")
	  formH.sender_FEIN.focus()
	  return false
   }
   if (isEmpty(formH.sender_projID.value)) {
      alert ("Please enter your Project ID.")
	  formH.sender_projID.focus()
	  return false
   }
   if (isEmpty(formH.sender_message.value)) {
      alert ("Please enter your message to OCIP Help.")
	  formH.sender_message.focus()
	  return false
   }
   return true
}

////////////////////////////////////////////////////////////////////////////
// Function checkRange()                                                  //
////////////////////////////////////////////////////////////////////////////
function checkRange(theForm, theField, val1, val2) {
   var testval = parseFloat(theField.value)
   if (isEmpty(testval)) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else if (testval < val1 || testval > val2) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else
      theField.value = roundFloat(theField.value, 3)
}

////////////////////////////////////////////////////////////////////////////
// Function checkRangeSetValue()                                          //
////////////////////////////////////////////////////////////////////////////
function checkRangeSetValue(theForm, theField, val1, val2,theSetField) {
   var testval = parseFloat(theField.value)
   if (isEmpty(testval)) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else if (testval < val1 || testval > val2) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else {
      theField.value = roundFloat(theField.value, 3)
	  theSetField.value = theField.value
   }
}

// calc_premium
//  compute the value of premium from rate and estimated payroll.
function calc_premium(theForm, premType, codeNum, numlines) {
   var rate = theForm[premType+"Rate"+codeNum].value
   var payroll = theForm[premType+"Pay"+codeNum].value
   var premID = premType+"Prem"+codeNum
   var premium = 0.00
   var premType2
   if (premType == "WC")
       premType2 = "GL"
   else
       premType2 = "WC"
   var rate2 = theForm[premType2+"Rate"+codeNum].value
   var payroll2 = theForm[premType2+"Pay"+codeNum].value
   premID2 = premType2+"Prem"+codeNum
   // Compute WC Premium or GL Premium if GL Premium is not a Flat Premium
   if ( (premType == "WC") || ((premType == "GL") && (theForm.GLRateBase.value == "Payroll")))
   {
      // Compute premiums as the product of the rate times the payroll divided by 100. 
      if (isEmpty(rate))
         theForm[premID].value = formatCurrency(0.00)
      else if (isEmpty(payroll))
         theForm[premID].value = formatCurrency(0.00)
      else {
         rate = parseFloat(rate.replace(/\$|\,|\ /g,""))
		 if (isNaN(rate))
		    rate = 0.0;
		 payroll = parseFloat(payroll.replace(/\$|\,|\ /g,""))
		 if (isNaN(payroll))
		    payroll = 0.0;
         premium = rate * payroll / 100.0
         theForm[premID].value = formatCurrency(premium)
      }
   }
   // Compute the Subtotal
   var subtotal = 0
   for (i=1; i<=numlines; i++) {
      premID = premType+"Prem"+i
      var premval = parseFloat(theForm[premID].value.replace(/\$|\,|\ /g,""))
      if (isNaN(premval))
         premval = 0;
      subtotal += premval
   }
   if (premType == "WC")
      var premsubtotalID = premType+"SubTotPrem"
   else if (premType == "GL")
      var premsubtotalID = premType+"SubTotal"
   theForm[premsubtotalID].value = formatCurrency(subtotal)
   // Compute the Standard Premium and Total Premium
   if (premType == "WC") {
      var stdpremID = premType+"Std"
      var wcincrlim = parseFloat(theForm['WCIncrLim'].value)
      var wcexpmodadj = parseFloat(theForm['WCExpModRate'].value)
		theForm['WCExpModAdj'].value = wcexpmodadj;
      var discount = parseFloat(theForm['PremDiscount'].value.replace(/\$|\,/g,""))
      //var retentioncredit = parseFloat(theForm['WCDedSIRC'].value)
      var stdprem = subtotal * wcexpmodadj
      theForm[stdpremID].value = formatCurrency(stdprem)
      var totpremID = premType+"Prem"
      var totprem = stdprem - discount
      theForm[totpremID].value = formatCurrency(totprem)
		 
      // copy WC payroll to GL payroll field
      var GLpayID = "GLPay"+codeNum
      theForm[GLpayID].value = formatCurrency(payroll)
	  var GLrateid = "GLRate"+codeNum
	  var GLpremid = "GLPrem"+codeNum
/*	  if (isEmpty(theForm[$GLrateid].value) {
         theForm[GLrateid].value = "$0.00"
		 theForm[GLpremid].value = "$0.00"
      }
*/   }
		
   if (premType == "GL") {
      var totpremID = premType+"Prem"
      theForm[totpremID].value = theForm[premsubtotalID].value
   }
   // compute the grand total premium
   var wcprem_str = theForm.WCPrem.value
   var wcprem = parseFloat(wcprem_str.replace(/\$|\,|\ /g,""))
   var glprem_str = theForm.GLPrem.value
   var glprem = parseFloat(glprem_str.replace(/\$|\,|\ /g,""))
   var umbprem_str = theForm.UmbPrem.value
   var umbprem = parseFloat(umbprem_str.replace(/\$|\,|\ /g,""))
   var brprem_str = theForm.BRPrem.value
   var brprem = parseFloat(brprem_str.replace(/\$|\,|\ /g,""))
   if (theForm.name == "Form3") {
      var excessliab_str = theForm.ExcessTotal.value
	  var excessliab = parseFloat(excessliab_str.replace(/\$|\,|\ /g,""))
   }
   if (isEmpty(wcprem))
      wcprem = 0.0
   else if (isNaN(wcprem))
      wcprem = 0.0
   if (isEmpty(glprem))
      glprem = 0.0
   else if (isNaN(glprem))
      glprem = 0.0
   if (isEmpty(umbprem))
      umbprem = 0.0
   else if (isNaN(umbprem))
      umbprem = 0.0
   if (isEmpty(brprem))
      brprem = 0.0
   else if (isNaN(brprem))
      brprem = 0.0
   var grandprem = wcprem + glprem + umbprem + brprem
	  theForm.TotalPrem.value = formatCurrency(grandprem)
   if (theForm.name == "Form3") {
      if (isEmpty(excessliab))
         excessliab = 0
      else if (isNaN(excessliab))
         excessliab = 0.0
      var wcgltotal = wcprem + glprem
      theForm.WCGLTotal.value = formatCurrency(wcgltotal)
      var grandtotal = wcgltotal + excessliab
      theForm.GrandTotal.value = formatCurrency(grandtotal)
   }
}

// adjust_premium
//  adjust the value of premium from increased limit factor, exp mod, std prem ....
function adjust_premium(theForm, premType) {
   // Compute the Standard Premium and Total Premium
   if (premType == "WC") {
      var stdpremID = premType+"Std"
	  var subtotal = parseFloat(theForm['WCSubTotPrem'].value.replace(/\$|\,/g,""))
	  var wcincrlim = parseFloat(theForm['WCIncrLim'].value.replace(/\$|\,/g,""))
	  var wcexpmodadj = parseFloat(theForm['WCExpModAdj'].value.replace(/\$|\,/g,""))
	  var discount = parseFloat(theForm['PremDiscount'].value.replace(/\$|\,/g,""))
	  var stdprem = subtotal * wcincrlim * wcexpmodadj
      theForm[stdpremID].value = formatCurrency(stdprem)
	  var totpremID = premType+"Prem"
	  var totprem = stdprem - discount
	  theForm[totpremID].value = formatCurrency(totprem)
   }
   if (premType == "GL") {
      var premsubtotalID = premType+"SubTotal"
	  var totpremID = premType+"Prem"
	  var subtotal = parseFloat(theForm[premsubtotalID].value.replace(/\$|\,/g,""))
	  var totprem = subtotal
	  theForm[totpremID].value = formatCurrency(totprem)
   }
   // compute the grand total premium
   var wcprem_str = theForm.WCPrem.value
   var wcprem = 0.00
   var glprem_str = theForm.GLPrem.value
   var glprem = 0.00
   var umbprem_str = theForm.UmbPrem.value
   var umbprem = 0.00
   var brprem_str = theForm.BRPrem.value
   var brprem = 0.00
   if (theForm.name == "Form3") {
	   var excessliab_str = theForm.ExcessTotal.value
   }
   if (isEmpty(wcprem_str))
      wcprem = 0.00
   else
      wcprem = parseFloat(wcprem_str.replace(/\$|\,/g,""))
   if (isEmpty(glprem_str))
      glprem = 0.00
   else
      glprem = parseFloat(glprem_str.replace(/\$|\,/g,""))
   if (isEmpty(umbprem_str))
      umbprem = 0.00
   else
      umbprem = parseFloat(umbprem_str.replace(/\$|\,/g,""))
   if (isEmpty(brprem_str))
      brprem = 0.00
   else
      brprem = parseFloat(brprem_str.replace(/\$|\,/g,""))
   var grandprem = 0.00
   grandprem = wcprem + glprem + umbprem + brprem
//alert ("wcprem="+wcprem+", glprem="+glprem+", umbprem="+umbprem+", brprem="+brprem+", grandprem="+grandprem)
   theForm.TotalPrem.value = formatCurrency(grandprem)
   if (theForm.name == "Form3") {
      if (isEmpty(excessliab_str))
         var excessliab = 0.00
      else
         var excessliab = parseFloat(excessliab_str.replace(/\$|\,/g,""))
      var wcgltotal = wcprem + glprem
      theForm.WCGLTotal.value = formatCurrency(wcgltotal)
      var grandtotal = wcgltotal + excessliab
      theForm.GrandTotal.value = formatCurrency(grandtotal)
   }
}
	
////////////////////////////////////////////////////////////////////////////
// Function checkRangeAdjustPrem()                                          //
////////////////////////////////////////////////////////////////////////////
function checkRangeAdjustPrem(theForm, theField, val1, val2, premType) {
   var testval = parseFloat(theField.value)
   if (isEmpty(testval)) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else if (testval < val1 || testval > val2) {
      alert ("Please enter a value between "+val1+" and "+val2+".")
	  theField.value = ""
	  theField.focus()
   }
   else {
      theField.value = roundFloat(theField.value, 2)
	  adjust_premium(theForm, premType)
   }
}

	
// set_GLPrem
// Disable or enable the GL Premium fields for editing.
function set_GLPrem(theForm, numlines) {
	var i
   if (theForm.GLRateBase.value != "Payroll") {
      for (i=1; i<=numlines; i++) {
	     theForm["GLRate"+i].disabled = true
		 theForm["GLRate"+i].value = "$0.00"
		// theForm["GLRate"+i].style="text-align: Right"
	     theForm["GLPay"+i].disabled = true
		 theForm["GLPay"+i].value = "$0.00"
		// theForm["GLPay"+i].style="text-align: Right"
		 theForm["GLPrem"+i].disabled = false
	  }
   } else {
      for (i=1; i<=numlines; i++) {
	     theForm["GLRate"+i].disabled = false
	     theForm["GLPay"+i].disabled = false
		 theForm["GLPrem"+i].disabled = true
	  }
   }
}

// calc_total
//  compute the total WC Pay, Hours Reg, or Hours OT.
function calc_total(theForm, val, Num_values) {
   var i
   var totalpay = parseFloat(0.00)
   var totalhoursreg = parseFloat(0.00)
   var totalhoursOT = parseFloat(0.00)
   // Fill blanks with 0
   if (isEmpty(theForm["Fm5WCPay"+val].value))
      theForm["Fm5WCPay"+val].value = "$0.00"
   if (isEmpty(theForm["Fm5HoursReg"+val].value))
      theForm["Fm5HoursReg"+val].value = 0.00
	else
      theForm["Fm5HoursReg"+val].value = roundFloat(theForm["Fm5HoursReg"+val].value,2)
   if (isEmpty(theForm["Fm5HoursOT"+val].value))
      theForm["Fm5HoursOT"+val].value = 0.00
	else
      theForm["Fm5HoursOT"+val].value = roundFloat(theForm["Fm5HoursOT"+val].value,2)
   for (i=1; i <= Num_values; i++) {
	   if (!isEmpty(theForm["Fm5WCPay"+i].value))
	      totalpay += parseFloat(theForm["Fm5WCPay"+i].value.replace(/\$|\,/g,""))
	   if (!isEmpty(theForm["Fm5HoursReg"+i].value))
	      totalhoursreg += parseFloat(theForm["Fm5HoursReg"+i].value)
	   if (!isEmpty(theForm["Fm5HoursOT"+i].value))
	      totalhoursOT += parseFloat(theForm["Fm5HoursOT"+i].value)	   
   }
   theForm["Fm5Pay"].value = formatCurrency(totalpay)
   theForm["Fm5HoursReg"].value = totalhoursreg.toFixed(2)
   theForm["Fm5HoursOT"].value = totalhoursOT.toFixed(2)
}

////////////////////////////////////////////////////////////////////////////
// Function calc_form300()                                                //
//    Computes OSHA Form 300 Log totals:                                  //
//       Death cases, Days away form work, Job transfer or restrictions, etc.  //
////////////////////////////////////////////////////////////////////////////
function calc_form300(theForm, num_cases) {
   var death_cases = 0;
   var days_away_cases = 0;
   var job_transfer_cases = 0;
   var other_cases = 0;
   var days_away = 0;
   var days_restricted = 0;
   var injury_cases =0;
   var skin_disorder_cases = 0;
   var respiratory_cases = 0;
   var poisoning_cases = 0;
   var hearing_loss_cases = 0;
   var all_other_cases = 0;
   var i;
   var j;
   var checkedButton;
   
   for (i=0; i < num_cases; i++)
   {
	   // For radio buttons, we must first determine which button has been checked
	   checkedButton = -1
	   for (j = 0; j < theForm["Classification"+i].length; j++) {
		  // alert("Is Classification"+i+"["+j+"] checked?  ")
		   if (theForm["Classification"+i][j].checked) {
			   checkedButton = j
		   }
	   }
       if (checkedButton != -1) {	
		  switch (theForm["Classification"+i][checkedButton].value)
		  {
			 case "Death" :
				death_cases++;
				break;
			 case "Lost Work" :
				days_away_cases++;
				break;
			 case "Job Transfer Or Restriction" :
				job_transfer_cases++;
				break;
			 case "Other Recordable" :
				other_cases++;
		  }
	   }
	   val = parseInt(theForm["DaysLost"+i].value)
	   if (!isNaN(val))
	      days_away += parseInt(theForm["DaysLost"+i].value);
	   val = parseInt(theForm["DaysRestricted"+i].value)
	   if (!isNaN(val))
	      days_restricted += parseInt(theForm["DaysRestricted"+i].value);
	   checkedButton = -1
	   for (j = 0; j < theForm["InjuryType"+i].length; j++) {
		   if (theForm["InjuryType"+i][j].checked) {
			   checkedButton = j
		   }
	   }
       if (checkedButton != -1) {	   
		  switch (theForm["InjuryType"+i][checkedButton].value)
		  {
			 case "Injury" :
				injury_cases++;
				break;
			 case "Skin Disorder" :
				skin_disorder_cases++;
				break;
			 case "Respiratory Condition" :
				respiratory_cases++;
				break;
			 case "Poisoning" :
				poisoning_cases++;
				break;
			 case "Hearing Loss" :
				hearing_loss_cases++;
				break;
			 case "Other Illness" :
				all_other_cases++;
		  }
       }
   }
   theForm["DeathCaseTotal"].value = death_cases;
   theForm["DaysAwayCaseTotal"].value = days_away_cases;
   theForm["JobTransferCaseTotal"].value = job_transfer_cases;
   theForm["OtherRecordableCaseTotal"].value = other_cases;
   theForm["DaysLostTotal"].value = days_away;
   theForm["DaysRestrictedTotal"].value = days_restricted;
   theForm["InjuryTotal"].value = injury_cases;
   theForm["SkinDisorderTotal"].value = skin_disorder_cases;
   theForm["RespiratoryTotal"].value = respiratory_cases;
   theForm["PoisoningTotal"].value = poisoning_cases;
   theForm["HearingLossTotal"].value = hearing_loss_cases;
   theForm["OtherIllnessTotal"].value = all_other_cases;
}
   
   
   

