
//add trim function to the string object
function strtrim() {
    return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

String.prototype.trim = strtrim;
/////////////////////////////////////////////

//Check for valid dollar value, only allow number and period, no dollar sign or commas
function isDollarValid(Amount)
{
    var checkOK = "0123456789.";
  var allValid = true;

  for (i = 0;  i < Amount.value.length;  i++)
  {
    ch = Amount.value.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }    
  }
  if (allValid == false)
  {
    alert("Please enter the dollar amount without any commas or extra characters.");
    Amount.focus();
  }
  return allValid;  
}
//Phone Number Validation
function isValidPhoneNum(phonenumber, phonetype)
{
	if (phonenumber.value != "")
	{
		//a '+' in the first space of the phone number indicates a long distance number 
		//do not format or test if long distance 
		if (phonenumber.value.substr(0, 1) != "+")  
		{
			var formatnumber = FormatPhoneNum(getPhoneNum(phonenumber));
			if ((formatnumber.length < 14) || (! isPhoneNum(formatnumber)))
			{
				if (phonetype == 'fax')
					alert("The fax number is invalid.");
				else
					alert("The " + phonetype + " telephone number is invalid.");

				phonenumber.focus();
				return false;
			}
			phonenumber.value = formatnumber;
		}
	}
	return true;
}
function getPhoneNum(phonenum)
{//strips out any characters entered by the user so the phone number can be formatted
	var phonenumber = new String(phonenum.value);
	var formatphonenum = new String();
    for(var i=0; i<phonenumber.length; i++)
    {
		if (! isNaN(phonenumber.substr(i, 1)))
		{
			formatphonenum = formatphonenum + phonenumber.substr(i, 1);
		}
    }
	return formatphonenum;
}

function FormatPhoneNum (phonenum)
{//formats the phone number to (xxx) xxx-xxxx
	var phonenumber = new String(phonenum);
	if (phonenumber.substr(0, 1) != "(")
	{	phonenumber = "(" + phonenumber;	}
	if (phonenumber.substr(4, 1) != ")")
	{	phonenumber = phonenumber.substr(0, 4) + ")" + phonenumber.substr(4, phonenumber.length);	}
	if (phonenumber.substr(5, 1) != " ")
	{	phonenumber = phonenumber.substr(0, 5) + " " + phonenumber.substr(5, phonenumber.length);	}
	if (phonenumber.substr(9, 1) != "-")
	{	phonenumber = phonenumber.substr(0, 9) + "-" + phonenumber.substr(9, phonenumber.length);	}
	return phonenumber;
}

function isPhoneNum(phonenum)
{//returns true if the phone number is in one of the following formats:
 //xxx xxx-xxxx, xxx-xxx-xxxx, (xxx) xxx-xxxx, (xxx)xxx-xxxx
	var PhoneReqExp = /^(((\(\d{3}\)( )?)|(\d{3}( |\-)))\d{3}\-\d{4})$/;
	
	if (!PhoneReqExp.test(phonenum))
	{
		return false;
	}
	return true;
}

//Zip Code Validation
function isValidZipCode(zipcode)
{
	var regexp = /^\d{4}(\d|\d\-\d{4})$/;
	if (zipcode.value != "")
	{
		if (!regexp.test(zipcode.value))
		{
			alert("The Zip Code is invalid.");
			zipcode.focus();
			return false;
		}
	}
	return true;
}

//Date Validation
function CompareDate(dateField, compareDate, operator, fieldName)
{
	/*This function compares two dates or compares a date to the system date.  
	  The CompareDate function expects valid dates to be entered.  
	  Check for valid dates before calling this function.  The dateField and compareDate 
	  parameters must be valid dates.
	  Parameters
		example : "return CompareDate(this, 'system', '<', 'Date of Appeal');"  the dateField is checked to see if 
		           it is less than or equal to the system date
		     or : "return CompareDate(this, '1/1/2003', '>', 'Date of Appeal');" the dateField is checked to see 
		           if it is greater than or equal to 1/1/2003
		dateField	- the date field entered by the user.  This can be called by passing 'this'
		compareDate - can pass 'system' or a valid date to compare against the dateField
		operator	- tells the function if the dateField can be greater than or equal to, or less than or equal to.
					  valid parameters are '<' or '>'
		fieldName	- the name of the field being validated.  This value is displayed to the user
		              when the alert is thrown
	*/
    var systemDate = new Date();
    var vdateIn = new Date(dateField.value);
    var vdateField = new Date(vdateIn.getYear(), vdateIn.getMonth(), vdateIn.getDate(), 0, 0, 0, 0);
    if (compareDate == 'system')
    {
        var vcompareDate = new Date(systemDate.getYear(), systemDate.getMonth(), systemDate.getDate(), 0, 0, 0, 0);
    }
    else
    {
		var vcompareDate = new Date(compareDate);
    }
	var datedisplay = new String((vcompareDate.getMonth() + 1) + '/' + vcompareDate.getDate() + '/' + vcompareDate.getYear());
    if (operator == ">") 
    {
        if (parseInt(vcompareDate.getTime()) > parseInt(vdateField.getTime()))
        {
            alert ("The " + fieldName + " must be equal to or greater than " + datedisplay + ".");
            dateField.focus();
            return false;
        }
    }
    else if (operator == "<") 
    {
        if (parseInt(vcompareDate.getTime()) < parseInt(vdateField.getTime()))
        {
            alert ("The " + fieldName + " must be equal to or less than " + datedisplay + ".");
            dateField.focus();
            return false;
        }
    }
    return true;
}

var defaultEmptyOK = false
var iDay = "Invalid day entered for this month.  Try again."
var iMonth = "This field must be a month number between 1 and 12.  Try again."
var iYear = "This field must be a 2 or 4 digit year.  Try again."

var daysInMonth = new Array(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

function isYear (s)
{
   if (isEmpty(s)) 
    if (!isNonnegativeInteger(s)) 
    { 
        return false;
    }
    return ((s.length == 2) || (s.length == 4));
}
function isMonth (s)
{   if (isEmpty(s)) 
       if (isMonth.arguments.length == 1) return defaultEmptyOK;
       else return (isMonth.arguments[1] == true);
    return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}

function checkYear (theField, emptyOK)
{   if (checkYear.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isYear(theField.value, false)) 
       return warnInvalid (theField, iYear);
    else return true;
}

function checkMonth (theField, emptyOK)
{   if (checkMonth.arguments.length == 1) emptyOK = defaultEmptyOK;
    if ((emptyOK == true) && (isEmpty(theField.value))) return true;
    if (!isMonth(theField.value, false)) 
       return warnInvalid (theField, iMonth);
    else return true;
}

function checkDay (theDay, theMonth)
{   
    if (!isDay(theDay, theMonth)) 
       return warnInvalid (theDay, iDay);
    else return true;
}

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 isDateValid (strDate)
{//ensures that the string entered is a valid date
 if(strDate.value.length>0)
 {  
   if(strDate.value.length>7)
    {    //check validity of date for mm/dd/yyyy format
       var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
       var match=strDate.value.match(dateregex);
       if (match)
       {
            var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
           //check to make sure year entered is between 1800 and 2200
            if ((parseInt(match[3],10) < 1800) || (parseInt(match[3],10) > 2200))
            {
               alert("The year you entered is invalid, please enter a year between 1800 and 2200.");
               strDate.focus();      
               return false;
            }
            //check to make sure date entered is not greater than current date
             var myDate = new Date(parseInt(match[3],10),parseInt(match[1],10)-1,parseInt(match[2],10));
             var todaysDate = new Date();
             myDate.setHours(todaysDate.getHours());
             myDate.setMinutes(todaysDate.getMinutes());
             myDate.setSeconds(todaysDate.getSeconds());
             myDate.setMilliseconds(todaysDate.getMilliseconds());            
             if (myDate.valueOf() > todaysDate.valueOf()) 
             { 
                alert("The date entered may not be greater than the current date.");
                strDate.focus();      
                return false;
             } 
            if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10))
            {  return true; }
       }
       alert("Please enter valid values for the date, in the format of MM/YYYY or MM/DD/YYYY.");
       strDate.focus();      
       return false;
    }
    else
    {    //check validity of date for mm/yyyy format
       pos = strDate.value.indexOf("/");
       if (pos > 0)
       {  
            var mon = strDate.value.substr(0,pos);           
            var yr = strDate.value.substr(pos+1,4);          
            var now = new Date();
            var month = now.getMonth();
            var thisyr = now.getFullYear();
            //alert('yr='+yr+' thisyr='+thisyr+' mon='+mon+' month='+month);
            
           //check to make sure year entered is between 1800 and 2200
            if ((yr < 1799) || (yr > 2201))
            {
               alert("The year you entered is invalid, please enter a year between 1800 and 2200.");
               strDate.focus();      
               return false;
            }
            if (yr > thisyr)
            { 
               {alert("The date entered cannot be greater than the current date.");
               strDate.focus();
               return false;}
            }
            if ((mon > month+1) && (yr == thisyr))
            { 
               {alert("The date entered cannot be greater than the current date.");
               strDate.focus();
               return false;}
            }
            // alert('yr='+yr+' thisyr='+thisyr+' mon='+mon+' month='+month + '(mon < 13)&& (mon > 0) && (yr > 1799) && (yr < thisyr+1)');  
            if ((mon < 13) && (mon > 0) && (yr > 1799) && (yr < thisyr+1))  
            {  return true; }       
       }
       alert("Please enter valid values for the date, in the format of MM/YYYY or MM/DD/YYYY.");
       strDate.focus();      
       return false;
    } 
 } 
 return true;
}

/*
function isDateValid (strDate)
{//ensures that the string entered is a valid date
 if(strDate.value.length>0)
  {    
       var dateregex=/^[ ]*[0]?(\d{1,2})\/(\d{1,2})\/(\d{4,})[ ]*$/;
       var match=strDate.value.match(dateregex);
       if (match)
       {
            var tmpdate=new Date(match[3],parseInt(match[1],10)-1,match[2]);
           //check to make sure year entered is between 1800 and 2200
            if ((parseInt(match[3],10) < 1800) || (parseInt(match[3],10) > 2200))
            {
               alert("The year you entered is invalid, please enter a year between 1800 and 2200.");
               strDate.focus();      
               return false;
            }
            //check to make sure date entered is not greater than current date
             var myDate = new Date(parseInt(match[3],10),parseInt(match[1],10)-1,parseInt(match[2],10));
             var todaysDate = new Date();
             myDate.setHours(todaysDate.getHours());
             myDate.setMinutes(todaysDate.getMinutes());
             myDate.setSeconds(todaysDate.getSeconds());
             myDate.setMilliseconds(todaysDate.getMilliseconds());            
             if (myDate.valueOf() > todaysDate.valueOf()) 
             { 
                alert("The date entered may not be greater than the current date.");
                strDate.focus();      
                return false;
             } 
            if (tmpdate.getDate()==parseInt(match[2],10) && tmpdate.getFullYear()==parseInt(match[3],10) && (tmpdate.getMonth()+1)==parseInt(match[1],10))
            {  return true; }
       }
       alert("Please enter valid values for the day, month and year, in the format of MM/DD/YYYY.");
       strDate.focus();      
       return false;
   }
  else
   {  return true; }
}*/

function isDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    
 
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function isEmpty(field)
{
    return ((field == null) || (field.length == 0));
}

function isValidMonths(Field)
{// ensures that user enters null or 0-11 for number of months question on form 1
  if (Field.value != "")
  {
     if (isNumber(Field))
     {
        if ((Field.value < 0) || (Field.value > 11))
        {
           alert("The value for the number of months is not valid.  Please enter a number between 0 and 11.");
           Field.focus();
           return false;
        }
     }     
  }
  return true;
}


//Number functions
function isNumber(s)
{
    var checkOK = "0123456789";
  var allValid = true;

  for (i = 0;  i < s.value.length;  i++)
  {
    ch = s.value.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }    
  }
  if (allValid == false)
  {
    alert("Please enter only numbers for this field, no characters are allowed.");
    s.focus();
  }
  return allValid;  
}

//check to make sure dollar amount is valid
function isDollarAmount(s)
{
  var checkOK = "0123456789.";
  var allValid = true;

  for (i = 0;  i < s.value.length;  i++)
  {
    ch = s.value.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }    
  }
  if (allValid == false)
  {
    alert("Please enter an amount without commas or the $.");
    s.focus();
  }  
  return allValid; 
}

function isInteger (s)
{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    return true;
}

function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);
}

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];

    // The next line is a bit byzantine.  What it means is:
    // a) s must be a signed integer, AND
    // b) one of the following must be true:
    //    i)  s is empty and we are supposed to return true for
    //        empty strings
    //    ii) this is a number >= 0

    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Catch non-integer strings to avoid creating a NaN below,
    // which isn't available on JavaScript 1.0 for Windows.
    if (!isInteger(s, false)) return false;

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    var num = parseInt (s);
    return ((num >= a) && (num <= b));
}

//String Validation
function isStringNull(Field)
{
  // Pass in the document form field name
  // Returns true if the field value is empty; false otherwise
  return (Field.value.trim() == "")
}

function isMinLength(Field, Len)
{
  // Pass in the document form field name, and mininum length value
  // Returns true if the field value's length >= than the Len value passed in
  return ((Field.value.length > 0) && (Field.value.length < Len))
}

function isAlphaNumeric(Field)
{
 // Pass in a value
 // Returns true if the field value only contains alphanumerics, no spaces, no special chars

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var allValid = true;

  for (i = 0;  i < Field.value.length;  i++)
  {
    ch = Field.value.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }    
  }
  return allValid;  
}

	   function HasReqField(Field, VarName)
	   { // pass in form field and form label name
	     //  if it exists, then return true;
	     //  if not, alert user, set focus on field, and return false
	     if (isStringNull(Field))
	     {
	        alert("The " + VarName + " is a required field.  Please enter a value for this field.");
	        Field.focus();
	        return false;	        
	     }
	     return true;
	   }
	   function isReqSelected(Field, VarName)	   
	   {  // Pass in the select field, and the form label name
	      // if a choice is not selected from the drop down list, alert user, return false
	      //   if a choice has been selected, return true
	      if (Field.selectedIndex == 0)
	      {
	        alert("The " + VarName + " is a required field.  Please select a value from the drop down list.");
	        Field.focus();
	        return false;	      
	      }
	      return true;
	   }
	   
	   function CheckReqNames(field1, field2)
	   { // Used in createuser.aspx
	     //Check that user has entered values for first name & last name
	     if (HasReqField(field1, 'first name'))	     
	     {
	        if (HasReqField(field2,'last name'))
	        { return true; }
	     }
	     return false;
	   }
	   //Checks whether the string contains atleast one Alphabet
	   //This is used to make sure the userID contains atleast one alphabet
	   function IsThereAnAlphabet(Str)
	    {
		  var letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		  for (i=0;i<Str.length;i++)
	      {
				if(letters.indexOf(Str.substring(i,i+1))>=0) 
				return true;
	      }
	      return false;
       }
	   function vUserID(Field, CheckEmpty)
	   {// Used in createuser.aspx
	    // Validates the Login name field has valid input
	    //  if CheckEmpty = true; Login Name field must not be empty 
	    if (CheckEmpty == true)
	      {
	         if (Field.value == "")
	         {
	            alert("You must enter a login name.  Please enter a value in this field.");
	            Field.focus();
	            return false;
	         }
	      }	      
	      if (isMinLength(Field,6))
	      {
	         alert("Your login name must be at least 6 characters long.");
	         return false;
	      }
	      if (!isAlphaNumeric(Field))
	      {
	         alert("Your login name must contain letters or numbers only, no special characters or spaces.");
	         return false;
	      }
	      if (!IsThereAnAlphabet(Field.value))
		  {
			alert("Your login name must contain atleast one letter.");
			Field.focus();
			Field.select();
			return false;
		  }
	      if ((document.Form1.Createuser1tbl_txtPassword.value != "") && (document.Form1.Createuser1tbl_txtPassword.value == Field.value))
	      {
	         alert("Your login name and password may not be the same.\nPlease change your password or login name.");
	         return false;
	      }
	      if ((document.Form1.Createuser1tbl_txtPassword2.value != "") && (document.Form1.Createuser1tbl_txtPassword2.value == Field.value))
	      {
	         alert("Your login name and confirmation password may not be the same.\nPlease change your confirmation password or login name.");
	         return false;
	      }
	      return true;
	   }
	   function vPassword(Field, CheckEmpty, isNewUser, LogonName)
	   {// Used in createuser.aspx
	    // Validates the Password field has valid input
	    //  if CheckEmpty = true; password field must not be empty
	
	     if (CheckEmpty == true)
	      {
	         if (Field.value == "")
	         {
	            alert("You must enter a password.  Please enter a value in this field.");
	            Field.focus();
	            return false;
	         }
	      }
	         if (isMinLength(Field,6))
	         {
	            alert("Your password must be at least 6 characters long.");
	            return false;
	         }
	         if (!isAlphaNumeric(Field))
	         {
	            alert("Your password must contain letters and numbers only, no special characters or spaces.");
	            return false;
	         }	      
	         if (isNewUser == true)
	         { //only do the following check if creating a new user--called from createuser.aspx
	            if ((document.Form1.Createuser1tbl_txtUserID.value != "") && (document.Form1.Createuser1tbl_txtUserID.value  == Field.value))
	            {
	               alert("Your login name and password may not be the same.\nPlease change your password or login name.");
	               return false;
	            }
	            if ((document.Form1.Createuser1tbl_txtPassword2.value != "") && (document.Form1.Createuser1tbl_txtPassword2.value != Field.value))
	            {
	               alert("The password confirmation failed.\nPlease make sure you type the same password into the Password and Confirm Password fields.");
	               return false;
   	            }
   	         }
   	         else
   	         {
   	           if (Field.value == LogonName)
   	           {
   	              alert("Your login name and password may not be the same.\nPlease change your password or login name.");
   	              return false;
   	           }
   	         }
   	         return true;
	   }
	   function vPassword2(Field, CheckEmpty, isNewUser)
	   {// Used in createuser.aspx
	    // Validates the confirm Password field has valid input
	    //  if CheckEmpty = true; confirm password field must not be empty
	 
	     if (CheckEmpty == true)
	      {
	         if (Field.value == "")
	         {
	            alert("You must enter the password again in the Confirm Password field.");
	            Field.focus();
	            return false;
	         }
	      }
	         if (isMinLength(Field,6))
	         {
	            alert("Your password must be at least 6 characters long.");
	            return false;
	         }
	         if (!isAlphaNumeric(Field))
	         {
	            alert("Your confirmation password must contain letters and numbers only, no special characters or spaces.");
	            return false;
	         }
	         if (isNewUser==true)
	         {
	            if ((document.Form1.Createuser1tbl_txtPassword.value != "") && (document.Form1.Createuser1tbl_txtPassword.value  != Field.value))
	            {
	               alert("The password confirmation failed.\nPlease make sure you type the same password into the Password and Confirm Password fields.");
	               return false;
	            }
	            if ((document.Form1.Createuser1tbl_txtUserID.value  != "") && (document.Form1.Createuser1tbl_txtUserID.value  == Field.value))
	            {
	               alert("Your login name and password may not be the same.\nPlease change your password or login name.");
	               return false;
	            }
	         }	         
	         else
	         {
	            if ((document.Form1.txtPW.value != "") && (document.Form1.txtPW.value  != Field.value))
	            {
	               alert("The password confirmation failed.\nPlease make sure you type the same password into the Password and Confirm Password fields.");
	               return false;
	            }
	         }
	         return true;	    
	   }
	   function ValidateUserLogin()
	   {  // Used in createuser.aspx
	      // Checks to make sure Login name, Password, and confirmation Password
	      //  are entered and are valid values
	      if (vUserID(document.Form1.Createuser1tbl_txtUserID, true)==true)
          {
             if (vPassword(document.Form1.Createuser1tbl_txtPassword, true, true)==true)
             { 
                if (vPassword2(document.Form1.Createuser1tbl_txtPassword2,true, true)==true)
                { return true;} 
             }
          }
          return false;
	   }
	   
	   function ValidateUser(LogonName)
	   {  // Used in Edituser.aspx
	      // Checks to make sure Password is valid and has email
	      //  are entered and are valid values
	   	     var PostIt = true;
	         if (!isStringNull(document.Form1.txtPW))
	         {
                if (vPassword(document.Form1.txtPW, true, false, LogonName)==true)
                { 
                   if (vPassword2(document.Form1.txtPW2,true, false)!=true)
                  // {  __doPostBack('btnSave','');} 
                 
                  
                   { PostIt= false;}
                }
                else
                { PostIt= false;}
             } 
             return PostIt;                                                      
	   }
	   
	    function isValidNum(Field) 
	   { 
	   //  checks input string for all digits; returns true if all digits; ret false otherwise 
	        var checkOK = "0123456789";
            var checkStr = Field.value;
            var allValid = true;
            var allNum = "";
            for (i = 0;  i < checkStr.length;  i++)
            {
               ch = checkStr.charAt(i);
               for (j = 0;  j < checkOK.length;  j++)
                  if (ch == checkOK.charAt(j))
                  break;
                  if (j == checkOK.length)
                  {
                     allValid = false;
                     break;
                  }
                  allNum += ch;
            }
            if (!allValid)
            { return (false); }
            return true;
       }
	   
	   function ValidateMidInit(Field)
	   {
	    // Pass in Middle Initial field, if not empty and has only one character, add a period
	    if (!isStringNull(Field))
	    {  
	       if (Field.value.length == 1)
	       {       
	          Field.value = Field.value + "."
	       }
	    }	    
	   }
	   
	   function isPhoneExtOk(Field, ExtField, VarName)
	   {  // Used in createuser.aspx
	      // pass in the phone field, extension field, and the field name on the form
	      // function checks to see if an extension is entered w/o a phone number
	      //          if phone number has an extention, validate its value
	      // Returns False if any of the checks fail
	      //         True otherwise
	     if (isStringNull(Field) && (!isStringNull(ExtField)))
	     {
	        alert("You may not have an extension for the "+ VarName + " phone number if the " + VarName + " phone number field is blank.");
	         ExtField.focus();
	        return false;
	     }
	     else if (!isValidNum(ExtField))
	          {   alert("The extension for the " + VarName + " phone number is invalid.  Only use numbers for this field.");
	              ExtField.focus();
	              return false;
	          }
	     return true;	      
	   }
	     	
	   function ValidateAddress()
	   { // Used in Edituser.aspx
	     // Checks to make sure the Address street field is not empty and a country as been selected.	   
	      var PostIt = true;
	      
          SelCountry = document.Form1.lstCountry.options[document.Form1.lstCountry.selectedIndex].value;
	      if (SelCountry==840)
	         {
	            if (HasReqField(document.Form1.txtStreet, 'address'))	
	            {
	               if (HasReqField(document.Form1.txtCity, 'city'))	
	               {
	                  if (isReqSelected(document.Form1.lstState,'state'))
	                  {   
	                     if (HasReqField(document.Form1.txtZip, 'zip code'))	
	                     {
	                        if (isValidZipCode(document.Form1.txtZip))
	                        {  PostIt= true; }
	                        else
	                        { PostIt= false; }
	                     }
	                     else
	                     { PostIt= false; }
	                  }
	                  else
	                  { PostIt= false; }
	               }
	               else
	               { PostIt= false; }	               
	            }
	            else
	            { PostIt= false; }	            
	         }	            
	      return PostIt;
	   }	  
	     	   
	   function ValidateAddr()
	   { // Used in createuser.aspx 
	     // Checks to make sure email address is entered and that zip code, if entered is valid.
	     //	if country=USA, make sure that all address fields are entered.   
	      if (HasReqField(document.Form1.Createuser3tbl_txtEmail, 'e-mail address'))
	      {  
	         if (!(emailCheck(document.Form1.Createuser3tbl_txtEmail.value))){
	            return false;
	         }
	      
	         SelCountry = document.Form1.Createuser3tbl_lstCountry.options[document.Form1.Createuser3tbl_lstCountry.selectedIndex].value;
	         if (SelCountry==840)
	         {
	            if (HasReqField(document.Form1.Createuser3tbl_txtStreet, 'address'))	
	            {
	               if (HasReqField(document.Form1.Createuser3tbl_txtCity, 'city'))	
	               {
	                  if (isReqSelected(document.Form1.Createuser3tbl_lstState,'state'))
	                  {   
	                     if (HasReqField(document.Form1.Createuser3tbl_txtZip, 'zip code'))	
	                     {
	                        if (isValidZipCode(document.Form1.Createuser3tbl_txtZip))
	                        {  return true; }
	                        else
	                        { return false; }
	                     }
	                     else
	                     { return false; }
	                  }
	                  else
	                  { return false; }
	               }
	               else
	               { return false; }	               
	            }
	            else
	            { return false; }	            
	         }
	         return true;	          
	      }	
	      return false;
	   }	  
	   
	   function ValidatePhoneNum (PhoneField, ExtField, FieldName)
	   { // Used in createuser.aspx
	     // function does all checks to validate a phone number, returns true if correct value
	     //  returns false otherwise	     
	     if (isValidPhoneNum(PhoneField, FieldName)==true)
	     {
	        if (isPhoneExtOk(PhoneField, ExtField, FieldName)==true)  
	        {   return true;  }	        
	     }
	     else
	     {
	        PhoneField.focus();
	        return false;
	     }
	   }
	   
	   function ValidateNamePhone()
	   {  // Used in Edituser.aspx
	      // Validate Phone numbers and extensions prior to submission	   
	      var PostIt = true;
	    if (HasReqField(document.Form1.txtEmail, 'e-mail address'))
	    {	     
          if (!(emailCheck(document.Form1.txtEmail.value))){
	         return false;
	      }
	      if (CheckReqNames(document.Form1.txtFName, document.Form1.txtLName)== true)
	      {
	        ValidateMidInit(document.Form1.txtMName)
	         if (ValidatePhoneNum(document.Form1.HPhone,document.Form1.Hext,'home')==true)
	         {
	            if (ValidatePhoneNum(document.Form1.WPhone,document.Form1.Wext,'work')==true)
	            {
	               if (ValidatePhoneNum(document.Form1.Fax,document.Form1.Fext,'fax')==true)
	               {
	                  if (ValidatePhoneNum(document.Form1.OPhone,document.Form1.Oext,'other')!=true)
	                 // {  __doPostBack('btnSave','');}
	                  //else
	                  { PostIt= false;}
	                  else
	                  {
	                    if (document.Form1.OPhone.value != "")
                         {  
                            if (document.Form1.lstPhoneType.value == " ")
                            {
                                alert("Select Other Phone Type");
                                return false;
                            }
                         }
	                    return true;
	                  }  
	               }
	               else
	               { PostIt= false;}	               
	            }
	            else
	            { PostIt= false;}
	         }
	         else
	         { PostIt= false;}
	      }
	      else
	       { PostIt= false;}  	      
	     }
	     else
	     { PostIt= false;}      
	     return PostIt;
	   }
	   
	   function ValidateData()
	   {  // Used in createuser.aspx
	      // Validate Phone numbers and extensions prior to submission
	      if (CheckReqNames(document.Form1.Createuser2tbl_txtFirstName,document.Form1.Createuser2tbl_txtLastName)== true)
	      {
	         ValidateMidInit(document.Form1.Createuser2tbl_txtMiddleName)
	         if (ValidatePhoneNum(document.Form1.Createuser2tbl_HPhone,document.Form1.Createuser2tbl_Hext,'home')==true)
	         {
	            if (ValidatePhoneNum(document.Form1.Createuser2tbl_WPhone,document.Form1.Createuser2tbl_Wext,'work')==true)
	            {
	               if (ValidatePhoneNum(document.Form1.Createuser2tbl_Fax,document.Form1.Createuser2tbl_Fext,'fax')==true)
	               {
	                  if (ValidatePhoneNum(document.Form1.Createuser2tbl_OPhone,document.Form1.Createuser2tbl_Oext,'other')==true)
	                  { 
	                    //alert(document.Form1.Createuser2tbl_OPhone.value != "");
	                    if (document.Form1.Createuser2tbl_OPhone.value != "")
                         {  
                            if (document.Form1.Createuser2tbl_lstPhoneType.value == " ")
                            {
                                alert("Select Other Phone Type");
                                return false;
                            }
                         }
	                    return true;
	                  }
	               }
	            }
	         }	     
	      }
	      return false;	     
	   }
	   
	   function ValidateLogin(CheckEmpty)
{
  // if CheckEmpty = true then the Login field is required, check to see if a value exists
  // called when user changes the Login Name text
  // checks to make sure the length is appropriate, no special chars, no spaces
   
      if (CheckEmpty == true)
      {
         if (isStringNull(document.Form1.txtLogin))
         { 
            alert("The Login Name field is required.  Please enter a value for this field");
            document.Form1.txtLogin.focus();
            return false;
         }
      }
      if (isMinLength(document.Form1.txtLogin,6))
      {
       alert("The login name must be at least 6 characters long.");
       return false;      
      }      
      if ((document.Form1.txtLogin.value.length > 0) && (!isAlphaNumeric(document.Form1.txtLogin)))
      {
        alert("The login name must contain letters and numbers only, no spaces or special characters");       
        return false;
      }
            
      return (true);
}

function ValidatePW(CheckEmpty)
{
  // if CheckEmpty = true then the Password field is required, check to see if a value exists
 //called when user changes the Password text
 // checks to make sure the length is correct & no special chars
      if (CheckEmpty == true)
      {
         if (isStringNull(document.Form1.txtPassword))
         { 
            alert("The Password field is required.  Please enter a value for this field");
            document.Form1.txtPassword.focus();
            return false;
         }
      }
     if (isMinLength(document.Form1.txtPassword,6))
      {
       alert("The password must be at least 6 characters long.");  
       return false;  
      }
     if ((document.Form1.txtPassword.value.length > 0) && (!isAlphaNumeric(document.Form1.txtPassword)))
      {
        alert("The password must contain letters and numbers only, no spaces, or special characters");       
        return false;
      }
     return true;
}

function pageValidate()
{ // Validate a page's fields prior to submission
  //   Ensures:
  //   Login must not be blank & valid
  //   Password must not be blank & valid
    
        if (ValidateLogin(true)==true)
        {
           if (ValidatePW(true)==true)
           {       
             return true;
           }
        }
        return false;
}

function HasEmailBody()
{ //used in feedback.aspx
  //Checks that feedback field has not empty before sending off email to MSPB
  if (isStringNull(document.Form1.txtFeedback))
  {
     alert("You must enter some feedback text before you send an e-mail to MSPB.");
     document.Form1.txtFeedback.focus();
     return false;
  }
  else
     return true;
}

// Show/Hide Field help text for all pages  -- Begin --
function ShowFieldHelpSpan(spanName)
{
  browserTest = navigator.appName;
    
  if (browserTest=="Netscape")
  {
	// Handle Netscape browser
    objSpanCollection = document.getElementsByTagName("SPAN");
    for(var i = 0; i < objSpanCollection.length; i++)
	{
		var thisElement = document.getElementById(objSpanCollection[i].id);
  		if (spanName == objSpanCollection[i].id)
  		{
			thisElement.style.left = 30;
			thisElement.style.top = 350;
			thisElement.style.visibility =  "visible";
  		}
  		else
  		{
  			if (objSpanCollection[i].id.substring(0,9) == spanName.substring(0,9))
  			{
	            thisElement.style.visibility =  "hidden";
  			}
  		}
	}
  }
  else
  {
	// Handle other (IE) browser
	objSpanCollection = document.body.getElementsByTagName("SPAN");
	for(var i = 0; i < objSpanCollection.length; i++)
	{
  		var objSpan = objSpanCollection(i);
  		if (objSpan.id == spanName)
  		{
  			objSpan.style.visibility = "visible";
  		}
  		else
  		{
  			if (objSpan.id.substring(0,9) == spanName.substring(0,9))
  			{
  				objSpan.style.visibility = "hidden";
  			}
  		}
	}
  }
}

function ShowHideOtherField(objListBox, txtBoxObjId, promptSpanId)
{
	if (objListBox.options[objListBox.selectedIndex].value == "0")
	{
		objTxt = document.getElementById(txtBoxObjId);
		objTxt.style.visibility = "visible";
		objSpan = document.getElementById(promptSpanId);
		objSpan.style.visibility = "visible";
	}
	else
	{
		objTxt = document.getElementById(txtBoxObjId);
		objTxt.value = ""
		objTxt.style.visibility = "hidden";
		objSpan = document.getElementById(promptSpanId);
		objSpan.style.visibility = "hidden";
	}
}
// -- end -- Show/Hide Field help text for all pages

function SingleSelectCheckBoxList(spanName)
	   {//used in Interview.aspx and Select Appeal Type
	   // ensures that user only selects one checkbox item at a time
			browserTest = navigator.appName;
    
			if (browserTest=="Netscape")
			{
				// Handle Netscape browser
				objInputCollection = document.getElementsByTagName("INPUT");
				for(var i = 0; i < objInputCollection.length; i++)
				{
					var thisElement = document.getElementById(objInputCollection[i].id);
  					if (objInputCollection[i].id == spanName.id.substring(4))
  					{
  						if (!objInputCollection[i].checked)
  						{
  							objInputCollection[i].checked = false
  						}
  					}
  					else
  					{
						objInputCollection[i].checked = false
  					}
				}
			}
			else
			{
				// Handle other (IE) browser
				objInputCollection = document.body.getElementsByTagName("INPUT");
				for(var i = 0; i < objInputCollection.length; i++)
				{
  					var objInput = objInputCollection(i);
  					if (objInput.id == spanName.id.substring(4))
  					{
  						if (!objInput.checked)
  						{
  							objInput.checked = false;
  						}
  					}
  					else
  					{
  						objInput.checked = false;
  					}
				}
			}
	   }
	   
	   function CheckTextAreaLength(objTextArea, iMaxChars)
	   {
	     //alert("Hello");
	     //alert(objTextArea.value.length);
	     if (objTextArea.value.length > iMaxChars)
	     {
	       alert("Text is too long (" + objTextArea.value.length + ").  You may only enter " + iMaxChars + " characters maximum.\n" +
	             "If you continue, the text will be truncated.");
	       objTextArea.focus();
	       return false;
	     }
	   }
	   
	   function CheckTextAreaLengthCR(objTextArea, iMaxChars)
	   {	   //checks to see if the field length is too long    
	     if (objTextArea.value.length > iMaxChars)
	     {
	       alert("Text is too long (" + objTextArea.value.length + ").  You may only enter " + iMaxChars + " characters maximum.\n" +
	             "If you continue, the text will be truncated.");
	       objTextArea.focus();
	       return false;
	     }
	      //checks to see if more than 2 lines are entered (by counting the carriage returns)	     
	     if (objTextArea.value.indexOf('\n') != objTextArea.value.lastIndexOf('\n'))
	        {  alert("This Street field of the address is restricted to two lines, for printing reasons.  Please re-enter your data, using only one carriage return.");
	           objTextArea.focus();
	           return false;
	        }	
	   }
	   
function checkEmail(emailStr) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailStr)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}

function emailCheck (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

var knownCountryCode=/^(af|al|dz|as|ad|ao|ai|aq|ag|ar|am|aw|au|at|az|bs|bh|bd|bb|by|be|bz|bj|bm|bt|bo|ba|bw|bv|br|io|bn|bg|bf|bi|kh|cm|ca|cv|ky|cf|td|cl|cn|cx|cc|co|km|cd|cg|ck|cr|ci|hr|cu|cy|cz|dk|dj|dm|do|tl|ec|eg|sv|gq|er|ee|et|fk|fo|fi|fr|fx|gf|pf|tf|ga|gm|ge|de|gh|gi|gr|gl|gd|gp|gu|gt|gn|gw|gy|ht|hm|hn|hk|hu|is|in|id|ir|iq|ie|il|it|jm|jp|jo|kz|ke|ki|kp|kr|kw|kg|la|lv|lb|ls|lr|ly|li|lt|lu|mo|mk|mg|mw|my|mv|ml|mt|mh|mq|mr|mu|yt|mx|fm|md|mc|mn|ms|ma|mz|mm|na|nr|np|nl|an|nc|nz|ni|ne|ng|nu|nf|mp|no|om|pk|pw|ps|pa|pg|py|pe|ph|pn|pl|pt|pr|qa|re|ro|ru|rw|kn|lc|vc|ws|sm|st|sa|sn|sc|sl|sg|sk|si|sb|so|za|gs|es|lk|sh|pm|sd|sr|sj|sz|se|ch|sy|tw|tj|tz|th|tg|tk|to|tt|tn|tr|tm|tc|tv|ug|ua|ae|gb|us|um|uy|uz|vu|va|ve|vn|vg|vi|wf|eh|ye|yu|zm|zw|uk)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

alert("The email username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (domArr[domArr.length-1].toLowerCase() == "cm" || domArr[domArr.length-1].toLowerCase() == "co" || domArr[domArr.length-1].toLowerCase() == "om") {
alert("The address must end in a well-known domain. You might mean .com instead of ." + domArr[domArr.length-1].toLowerCase() + ".");
return false;
}

if (domArr[domArr.length-1].toLowerCase() == "ne" || domArr[domArr.length-1].toLowerCase() == "nt" || domArr[domArr.length-1].toLowerCase() == "et") {
alert("The address must end in a well-known domain. You might mean .net instead of ." + domArr[domArr.length-1].toLowerCase() + ".");
return false;
}

if (domArr[domArr.length-1].toLowerCase() == "ml" || domArr[domArr.length-1].toLowerCase() == "il") {
alert("The address must end in a well-known domain. You might mean .mil instead of ." + domArr[domArr.length-1].toLowerCase() + ".");
return false;
}

if (domArr[domArr.length-1].toLowerCase() == "go" || domArr[domArr.length-1].toLowerCase() == "gv" || domArr[domArr.length-1].toLowerCase() == "ov") {
alert("The address must end in a well-known domain. You might mean .gov instead of ." + domArr[domArr.length-1].toLowerCase() + ".");
return false;
}

if (checkTLD && domArr[domArr.length-1].toLowerCase().search(knownCountryCode) == -1 && 
domArr[domArr.length-1].toLowerCase().search(knownDomsPat) == -1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

function Email_Validation(objName)
{ 
   obj = document.getElementById(objName)
   if (document.getElementById(objName)){
      if (obj.value != ""){
         if (!(emailCheck(obj.value))){
	        return false;
	     }
      }   
   }
   return true;
}  

function File_Validation(objName,validExtensions)
{ 
   obj = document.getElementById(objName)
   if (document.getElementById(objName)){
      if (obj.value != ""){
         if (!(validFiles(objName,validExtensions))){
	        return false;
	     }
      }   
   }
   return true;
}  

	   function ValidateDocketNumber(sValue)
{
  // called when user changes the Docket Number text
  // checks to make sure the format is appropriate
   // controls cursor based on sValue
		var sMesage;
		var bInvalid;
		if (sValue == 'FF')
		{
			if ((document.Form1.txtDocketFF.value.length >= 2))
			{
				document.Form1.txtDocketCCCC.focus();
			}
		}
		/*
         if (isStringNull(document.Form1.txtDocketFF))
         { 
            alert("Docket Number is required field.  Please enter a valid Docket Number in the field");
            document.Form1.txtDocketNo.focus();
            return false;
         }
    */
      return (true);
}

//Confirms whether user knowingly did not answer a required question
function AnswerThePleadingQuestion(pbLastQInSection)
{
	if(confirm('You have not answered the required question.\nClick OK to continue with the next question or Cancel to answer the required question(s) on this page.'))
		window.location.href = pbLastQInSection ? "PleadingSectionCompleted.aspx" : "PleadingInterview.aspx";
	else
		window.location.href="PleadingInterview.aspx?FailRequired=Y"
}

//Confirms whether user knowingly denied entering agreement into the record
//the check box id of No id <QuestionID>_1, Question ID is passed to this function
function VerifyEnterAgreementIntoTheRecord(QID)
{
	obj = document.getElementById(QID + '_1');
	if (document.getElementById(QID + '_1')){
		if (obj.checked == true){
			var sMsg='You have selected not to enter the agreement into the record.\n';
				sMsg = sMsg + 'The Board lacks the authority to enforce a settlement agreement that has not been entered into the official record.\n';
				sMsg = sMsg + 'Click OK to continue with your selection Or Cancel to change your option.\n';
			if(confirm(sMsg))
				window.location.href = "PleadingInterview.aspx?Selected=Y";
			else
				window.location.href = "PleadingInterview.aspx?FailRequired=Y";
		}
		else{
			window.location.href = "PleadingInterview.aspx?Selected=Y";
		}	
    }
}
/*
function ConfirmEfilingSelection(QID)
{
	obj1 = document.getElementById(QID + '_1');
	obj2 = document.getElementById(QID + '_2');
		if (obj1.checked == true){
			var sMsg='You are declining e-filing.  Your appeal will be submitted electronically to MSPB, they will reply via Postal mail.\n';
			sMsg = sMsg + 'All communications between MSPB and you will be paper based.  To proceed press OK.\n\n';
			sMsg = sMsg + 'If you would like to receive documents from MSPB and possibly the agency electronically, press Cancel and elect e-filing.';
			if(confirm(sMsg)){
				//window.location.href = "interviews.aspx?Selected=Y";
				window.location.href = "interviewsectioncompleted.aspx";
				}
			else{
				window.location.href = "Interview.aspx?FailRequired=Y";
			}
		}	
    else if (obj2.checked == true){
			var sMsg='By electing to e-File, you agree to be served electronically by MSPB and other parties in the case that have also elected to e-File.\n';
			sMsg = sMsg + 'If you agree, press OK.  To change your election, press Cancel.\n';
			if(confirm(sMsg)){
				//window.location.href = "Interview.aspx?Selected=Y";
				window.location.href = "interviewsectioncompleted.aspx";
				}
			else{
				window.location.href = "Interview.aspx?FailRequired=Y";
			}
		}
}
*/

//Confirm e-Filing selection
function ConfirmEfilingSelection(QID)
		{
		
			obj1 = document.getElementById(QID + '_1');
			obj2 = document.getElementById(QID + '_2');
				if (obj1.checked == true){
					var sMsg='You are declining e-filing.  Your appeal will be submitted electronically to MSPB, they will reply via Postal mail.\n';
					sMsg = sMsg + 'All communications between MSPB and you will be paper based.  To proceed press OK.\n\n';
					sMsg = sMsg + 'If you would like to receive documents from MSPB and possibly the agency electronically, press Cancel and elect e-filing.';
					if(confirm(sMsg)){
						return true ;
						}
					else{
						return false;
					}
				}	
			else if (obj2.checked == true){
					var sMsg='By electing to e-File, you agree to be served electronically by MSPB and other parties in the case that have also elected to e-File.\n';
					sMsg = sMsg + 'If you agree, press OK.  To change your election, press Cancel.\n';
					if(confirm(sMsg)){
						return true;
						}
					else{
						return false;
					}
				}
		}
		
//Confirm e-Filing selection for Appellant
function ConfirmEfilingSelectionForAppellant(QID)
		{
		
			obj1 = document.getElementById(QID + '_1');
			obj2 = document.getElementById(QID + '_2');
				if (obj1.checked == true){
					var sMsg='You are declining e-filing for Appellant.  Your appeal will be submitted electronically to MSPB, they will reply to Appellant via Postal mail.\n';
					sMsg = sMsg + 'All communications between MSPB and Appellant will be paper based.  To proceed press OK.\n\n';
					sMsg = sMsg + 'If you would like the Appellant to receive documents from MSPB and possibly the agency electronically, press Cancel and elect e-filing for Appellant.';
					if(confirm(sMsg)){
						return true ;
						}
					else{
						return false;
					}
				}	
			else if (obj2.checked == true){
					var sMsg='By electing to e-File for Appellant, you agree that the Appellant will be served electronically by MSPB and other parties in the case that have also elected to e-File.\n';
					sMsg = sMsg + 'If you agree, press OK.  To change election for Appellant, press Cancel.\n';
					if(confirm(sMsg)){
						return true;
						}
					else{
						return false;
					}
				}
		}
		

//Confirm e-Filing selection
function ConfirmEfilingSelectionForRep(QID)
		{
		
			obj1 = document.getElementById(QID + '_1');
			obj2 = document.getElementById(QID + '_2');
				if (obj1.checked == true){
					var sMsg='You are declining e-filing.  Your appeal will be submitted electronically to MSPB, they will reply via Postal mail.\n';
					sMsg = sMsg + 'All communications between MSPB and you will be paper based.  To proceed press OK.\n\n';
					sMsg = sMsg + 'If you would like to receive documents from MSPB and possibly the agency electronically, press Cancel and elect e-filing.';
					if(confirm(sMsg)){
						return true ;
						}
					else{
						return false;
					}
				}	
			else if (obj2.checked == true){
					var sMsg='By electing to e-File, you agree to be served electronically by MSPB and other parties in the case that have also elected to e-File.\n';
					sMsg = sMsg + 'If you agree, press OK.  To change your election, press Cancel.\n';
					if(confirm(sMsg)){
						return true;
						}
					else{
						return false;
					}
				}
			else if (obj2.checked == false && obj1.checked == false){
					var sMsg='You have not answered the required question.\nYou must answer this question to continue further.';
					alert(sMsg);
					return false;
				}
		}
		
//Confirm OPM Case Number
function ConfirmOPMCaseNumber(objName)
{
   obj = document.getElementById(objName)
   if (document.getElementById(objName)){
      if (obj.style.visibility == "visible"){
         if (obj.value == ""){
					var sMsg='The OPM case number is important information and failing to provide it may delay processing of their appeal.';
					if(confirm(sMsg)){
						return true ;
						}
					else{
						return false;
					}
         }
      }   
   }   
}

//The following javascript functions are to handle tooltip help on input html controls.
//Added by PC on 10/11/2006

function showHelpFloatWindow(windowID, obj, horizPadding, vertPadding, msg)
{
   
   var horizPadding = parseInt(horizPadding); //-20;
   var vertPadding = parseInt(vertPadding);  //0;
   var goRight = true;
   
   var w = document.getElementById(windowID);
   
   if (w != null)
   {
        w.style.width = 250;
         w.style.display = 'block';
      w.style.visibility = 'visible';
      w.innerText = msg;
      w.style.top = getAscendingTops(obj) + vertPadding;
      if (getAscendingTops(obj) + vertPadding < 0) w.style.top = 0;
      if (goRight == true){
            w.style.top = getAscendingTops(obj);
            w.style.left = getAscendingLefts(obj) + obj.offsetWidth + horizPadding + 2;
        }
      else
      {
         w.style.left = getAscendingLefts(obj) - horizPadding;
         if ((getAscendingLefts(obj) - horizPadding) < 0)
            w.style.left = getAscendingLefts(obj) + obj.offsetWidth + horizPadding;
      }
   }
}    

function showDynamicFloatWindow(windowID, obj, horizPadding, vertPadding, cntrl)
{
   
   var horizPadding = parseInt(horizPadding); //0;
   var vertPadding = parseInt(vertPadding);  //25;
   var goRight = true;

   var msg = document.getElementById(cntrl);

   //alert(obj.id);
   //alert('html:' + msg.innerHtml);
   
   if(msg != null){
        msg = msg.innerText;
   }else{
        msg = cntrl;
   }

   var w = document.getElementById(windowID);
   
   if (w != null)
   {
        w.style.width = 250;
         w.style.display = 'block';
      w.style.visibility = 'visible';
      w.innerText = msg;
      w.style.top = getAscendingTops(obj) + vertPadding;
      if (getAscendingTops(obj) + vertPadding < 0) w.style.top = 0;
      if (goRight == true){
            w.style.top = getAscendingTops(obj);
            w.style.left = getAscendingLefts(obj) + obj.offsetWidth + horizPadding + 2;
        }
      else
      {
         w.style.left = getAscendingLefts(obj) - horizPadding;
         if ((getAscendingLefts(obj) - horizPadding) < 0)
            w.style.left = getAscendingLefts(obj) + obj.offsetWidth + horizPadding;
      }
   }
} 
    
function hideHelpFloatWindow(windowID)
{
  var w = document.getElementById(windowID);
  if (w != null)
  {
    w.style.display = 'none';
    w.style.visibility = 'hidden';
    
    w.top = -999;
    w.left = -999;
  }
}
    
function getAscendingTops(elemID){
    //var offsetTrail = document.getElementById(elemID);
    var offsetTrail = elemID;
   
    var offsetTop = 0;
    while (offsetTrail) {
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetTop += document.body.topMargin;
    }
    return offsetTop;
}
    
function getAscendingLefts(elemID){
    //var offsetTrail = document.getElementById(elemID);
    var offsetTrail = elemID;
           
    var offsetLeft = 0;
    
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetTop += document.body.topMargin;
    }
    return offsetLeft;
}
    
function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

function CheckOtherPhoneSelection(objName) {
    
   obj = document.getElementById("Phone_Number4");
   
   if (document.getElementById("Phone_Number4")){
      if (obj.value != ""){
         if (document.getElementById("OTHER_PHONE_TYPE_KEY").value == -1){
            alert("Select other phone type.");
	        return false;
	     }
      }   
   }
   return true;
}
