//<SCRIPT>
//Fip Generic, Do not modify this file!!!!

AC_PREVIOUS = 1;
AC_NEXT = 2;
AC_DEFINEDPAGE = 3;
AC_SAMEPAGE = 4;
AC_BACK = 5;
AC_LOGIN = 6;
AC_MEMBERS = 7;
AC_CANCEL = 8;

AC_PERSONAL = 10;
AC_SPOUSE = 11;
AC_DEPENDENT = 12;
AC_FINANCIAL = 13;
AC_ASSET = 14;
AC_LIABILITY = 15;
AC_INSURANCE = 16;
AC_FINANCIAL_TRACK = 17;
AC_MEMBERSEXT = 18;

AC_POLICY = 20;
AC_GOALS = 21;
AC_CASHFLOW = 22;
AC_RIDERS = 23;
AC_FUNDS = 24;
AC_SUBSTANDARD = 25;
AC_JOINT = 26
AC_RIDER_OI = 27;
AC_RIDER_PUA = 28;
AC_RIDER_CR = 33;
AC_PAYOR = 34;
AC_RIDER_OWP = 35;

AC_JOINTANNUITANT = 29;

AC_SCENARIO_ILL = 30;
AC_SCENARIO_APP = 31;
AC_CONCEPT = 32;

AC_NONLEVELS = 40;
//AC_PLANCHANGE = 41;

AC_ADVUND = 50;
AC_AU_BENEFIT = 56;       //Common Id for SD/DC
AC_AU_BENEFIT_SD = 51;
AC_AU_BENEFIT_DC = 52;
AC_AU_ROLLOUT = 53;
AC_AU_TERMDATA = 54;
AC_AU_CASEDATA = 55;

AC_GROUP = 60;
AC_GROUPMEMBERS = 61;
AC_GROUPSPLITDEFER = 62;
AC_GROUPADVISORS = 63;
AC_GROUPSELECT = 64;
AC_GROUP_BC = 65;
AC_GROUP_BV = 66;
AC_GROUP_KE = 67;
AC_GROUP_EC = 68;
AC_GROUP_EB = 69;

AC_MBA = 70;
AC_SIRA = 71;
AC_SIRATOANNUITY = 72;

AC_SELECT = 90;
AC_ADD = 91;
AC_REMOVE = 92;
AC_SAVE = 93;
AC_MODIFY = 94;
AC_REMOVEALL = 95;

AC_PROCESS = 99;
AC_PRINT = 100;
AC_LISTSCENE = 101;
AC_SUBMIT = 102;
AC_STATUS = 103;
AC_IMPORT = 104;
AC_EXPORT = 105;
AC_DUPLICATE = 106;
AC_SCANMESSAGE = 107;
AC_AGENTREPORT = 108;
AC_LP2000HOME = 109;
AC_SCENEDESCRIPTION = 110;
AC_PREVIEW = 111;
AC_COMPREPORTS = 112;
AC_LISTAGENTS = 113;
AC_SIG_COLLECT = 114;
AC_TEMPLATE = 115;
AC_CREATE_CATEGORY = 116;
AC_APPREMARKS = 117;
AC_SAVE_SCENE_AS = 118;
AC_VIEWONLY = 119;
AC_DEPENDENT_COVERAGE = 120;
AC_VIEWONLY2 = 121;

AC_REPROPOSALS = 123;
AC_REPO_SUBSTANDARD = 125;
AC_REPO_NONLEVEL = 126;

AC_BACKTO_FAGROUP = 130;
AC_SELECT_ALLGROUP = 131;

AC_REVISEDILL = 140;

AC_AGENTCREATE = 150;
AC_AGENTINFORMATION = 151;
AC_AGENTPREFERENCE = 152;
AC_AGENTMAINTENANCE = 153;
AC_AGENTDCHANNELSELECT=154;
AC_AGENTIMPERSONATION=155;
AC_AGENTINFO = 157;

AC_AGT_PWD = 160;
AC_REPORTSSEL = 161;
AC_REPORTSSEL2 = 162;
AC_IMPORTFIPFILE=163;
AC_RPU = 164;
AC_EMPLOYERS = 165;
AC_EMPLOYERSTARTSESSION = 183;
AC_EMPLOYERSESSION = 166;
AC_EMPLOYEESELECTION = 167;
AC_EMPLOYEEINTERVIEW = 168;
AC_EMPLOYEEINTERVIEW2 = 187;
AC_EMPLOYERENDSESSION = 169;
AC_EMPLOYEESPOUSE = 170;
AC_EMPLOYEEDEPENDENT = 171;
AC_EMPLOYEEPERSONAL = 179;
AC_EMPLOYEEPERSONALCASE = 181;
AC_DELETEAGT = 182;

// JMZ - Case building.
AC_GROUP_EMPLOYERS = AC_EMPLOYERS;
AC_GROUP_EMPLOYERINFO = 190;
AC_GROUP_PRODUCTS = 191;
AC_GROUP_ACCEPTANCE = 192;
AC_GROUP_AGENT = 193;
AC_GROUP_SET_ARSA = 194;

AC_GROUP_LOCATIONS = 195;
AC_LOCATION_INFO = 196;
AC_LOCATION_AGENTS = 197;
AC_LOCATION_EMPLOYEE = 198;

AC_GROUP_CASES = 199;
AC_CASE_PRODUCTS = 200;
AC_CASE_INFO = 201;
AC_CASE_BILLING = 202;
AC_CASE_ACCEPTANCE = 203;
AC_GROUP_EMPLOYERFORM = 204;
AC_GROUP_EMPLOYERGROUPFORM = 205;
AC_EMPLOYER_REPORTS = 206;
AC_EMPLOYER_REPORT_SEL_DEDUCTION = 207;
AC_EMPLOYER_REPORT_SEL_BENEFIT = 208;
AC_EMPLOYER_REPORT_SEL_APPLICATION = 209;
AC_EMPLOYER_REPORT_SEL_EMPLOYEE = 210;
AC_EMPLOYER_REPORT_EMPLOYEE = 211;
AC_EMPLOYER_REPORT_SEL_BENEFIT_PRINT = 212; 
AC_FEDERALRATE = 215;

AC_ARCHIVERETRIEVE=220;
AC_ARCHIVECONFIRM=221;
AC_MANUALARCHIVE=222;

AC_SELECT_PERSON=223;
AC_SELECT_GROUP=224;

PLAN_LIFE = 0x1;
PLAN_HEALTH = 0x2;
PLAN_GROUP = 0x4;

MC_GETITEM = 0x1;
MC_SETITEM = 0x2;
MC_DFLTITEM = 0x4;
MC_NOTIFY = 0x8;
MC_getList = 0x10;
MC_LISTALL = 0x20;
MC_GETEDITINFO = 0x40;
MC_GETSTRING = 0x80;
MC_NOPLANDATA = 0x200;
MC_CONFIRMED = 0x400;
MC_NOTIFYCHILD = 0x800;
MC_NONOTIFYCHILD = 0x1000;
MC_NOSETCHILD = 0x2000;
MC_NOSETPARENT = 0x4000;

MC_SETDFLT = 0x8000;

MC_SHOWITEM = (MC_GETITEM | MC_NOTIFY);
MC_SHOWALL = (MC_GETITEM | MC_NOTIFY | MC_NOTIFYCHILD | MC_NOSETPARENT);
MC_SETALL = (MC_SETITEM | MC_NOTIFY);
MC_DFLTALL = (MC_SETALL | MC_DFLTITEM);

//Return Codes
RC_MODIFIED = 0x1;
RC_NOTFOUND = 0x2;
RC_INVALID = 0x4;
RC_NOEDIT = 0x8;
RC_INFOMODIFIED = 0x10;
RC_UNAVAILABLE = 0x20;
RC_CANCELED = 0x40;
RC_confirm = 0x80;
RC_DISPMSG = 0x100;
RC_UNAVAILABLE_ALWAYS = 0x200;
RC_INFOREQUIRED = 0x800;
RC_INFOMISSING = 0x1000;
RC_INVISIBLE = 0x4000;

PLAN_TYPE_UL = 1;
PLAN_TYPE_WL = 101;
PLAN_TYPE_TERM = 102;
PLAN_TYPE_EI = 501;

PLAN_START_USE_AN = 200;
PLAN_TYPE_FPDA = 201;
PLAN_TYPE_SPDA = 202;
PLAN_TYPE_SPIA = 203;
PLAN_TYPE_SPCLA = 204;
PLAN_END_USE_AN  = 299;


PLAN_START_USE_VAN = 400;
PLAN_TYPE_VAN = 401;
PLAN_END_USE_VAN = 499;

CONCEPT_PRODILLUSTR = 1;
CONCEPT_INF = 2;
CONCEPT_SD = 3;
CONCEPT_EB = 4;
CONCEPT_DC = 5;
CONCEPT_SDDC = 6;
CONCEPT_MBA = 7;

DISPLAY_FORMAT_NOCOMMA = 0x1;
DISPLAY_FORMAT_NOSHOWZERO = 0x2;
DISPLAY_FORMAT_YEAR = (DISPLAY_FORMAT_NOCOMMA | DISPLAY_FORMAT_NOSHOWZERO);

// Scene status
SCENE_STATUS_INCOMPLETE = 1;
SCENE_STATUS_CAN_SUBMIT = 5; 
SCENE_STATUS_COMPLETED_WITHOUTSIG = 6;
SCENE_STATUS_READY_TOSIGN = 8;
SCENE_STATUS_LOCKED = 11;
SCENE_STATUS_START_SIGN = 11;
SCENE_STATUS_FINISH_SIGN = 12;
SCENE_STATUS_AGENT_RPT_DONE = 14;
SCENE_STATUS_COMPLETED = 20;
SCENE_STATUS_TOSUBMIT = 30;
SCENE_STATUS_RESUBMIT = 40;
SCENE_STATUS_SUBMITTED = 100;
SCENE_STATUS_READ_ONLY = 103;
SCENE_STATUS_RECEIVED = 110;
SCENE_STATUS_SAVED = 120;
SCENE_STATUS_READY = 130;
SCENE_STATUS_PRINTED = 140;
SCENE_STATUS_SENT = 150;
SCENE_STATUS_BADXML = 160;
SCENE_STATUS_TIMEOUT = 170;
SCENE_STATUS_PENDUNDWRITING = 180;
SCENE_STATUS_PENDING = 1000;
SCENE_STATUS_MIB_CLEARED = 1300;
SCENE_STATUS_MIB_NOT_CLEARED = 1400;
SCENE_STATUS_END_PENDING = 9999;
SCENE_STATUS_ISSUED = 10000;
SCENE_STATUS_DENIED = 10100;

//Scene Types
SceneTypeFI = 1;
SceneTypeIEW = 2;
SceneTypeAPE = 3;
SceneTypeForm = 4;
SceneTypeNewAPE = 5;
SceneTypeNewForm = 6;
SceneTypeScenario = 10;
SceneTypeGroupApplication = 25;
SceneTypeEmployerGroupApplication = 28;
SceneTypeEmployerApp = 110;
SceneTypeEmployerCaseApp = 120;

//MML 12/6/02 For DSM use
FIP_DSM_READONLY = 4;
FIP_DSM_CHECKEDOUT = 65;
FIP_DSM_PARTIALCHECKEDOUT = 130;

FLD_STYLE_VISIBLE = ""; 
FLD_STYLE_INVISIBLE = "none";

//grper_status
GRPER_STATUS_START = 0;

GRPER_STATUS_INCOMPLETE = 1;

GRPER_STATUS_COMPLETED_WITHOUTSIG = 6;

GRPER_STATUS_READY_TOSIGN = 8;

GRPER_STATUS_START_SIGN= 11;
GRPER_STATUS_FINISH_SIGN = 12;

GRPER_STATUS_COMPLETED = 20;

GRPER_STATUS_SIG_FC_NOLIFE = 25;
GRPER_STATUS_SIGNED_NOLIFE = 30;

GRPER_STATUS_SIG_FC_LIFE = 45;
GRPER_STATUS_SIGNED_LIFE = 50;

GRPER_STATUS_SUBMITTED = 100;

GRPER_STATUS_SUBMITTED_FC_NOLIFE = 125;
GRPER_STATUS_SUBMITTED_NOLIFE = 130;

GRPER_STATUS_SUBMITTED_FC_LIFE = 145;
GRPER_STATUS_SUBMITTED_LIFE = 150;

//grperstatus

GRPERCASE_STATUS_START = 0;

GRPERCASE_STATUS_INCOMPLETE = 1;

GRPERCASE_STATUS_COMPLETED_WITHOUTSIG = 6;

GRPERCASE_STATUS_READY_TOSIGN = 8;

GRPERCASE_STATUS_START_SIGN= 11;
GRPERCASE_STATUS_FINISH_SIGN = 12;

GRPERCASE_STATUS_COMPLETED = 20;
GRPERCASE_STATUS_INVALIDNUMBER = 40;
GRPERCASE_STATUS_INVALIDCASENUMCHANGED = 50;

GRPERCASE_STATUS_SUBMITTED = 100;
GRPERCASE_STATUS_VALIDATED = 200;

//Application Types - Table AppTypes
APP_TYPE_MULTIPLE = 1;
APP_TYPE_HEALTH = 2;
APP_TYPE_GROUP = 3;
APP_TYPE_INDIVIDUAL = 4;
APP_TYPE_MULTIPLE_NY = 5;

//PDF report
REPORT_MULTI = 0;
REPORT_COMPOSITE = 1;
REPORT_PRINT = 2;

//Sort Constant
SORT_NONE = 0;
SORT_ASCENDING = 1;
SORT_DESCENDING = 2;

var gbDesignMode = false;
var gbSubmitted = true;
var glSubmitTime = 0;
var gfFormSubmit;
var bRunDesktop = false;

var BusinessRules = new _BusinessRules();

function _BusinessRules() {
   this.InitialSetup = _InitialSetup;
   this.ValidatePage = _ValidatePage;

   this.cltInitialSetup = _EmptyFunction;
   this.SetFieldRules = _EmptyFunction;
   this.SetNotifyFields = _EmptyFunction;
   this.cltValidatePage = _EmptyFunction;
   this.cltInitOneField = _EmptyFunction;

   this.NotifyItem = _NotifyItem;
   this.NotifyIntItem = _NotifyIntItem;
   this.NotifyDblItem = _NotifyDblItem;
   this.NotifyDatItem = _NotifyDatItem;
   this.NotifyTxtItem = _NotifyTxtItem;
   this.NotifySltItem = _NotifySltItem;
   this.NotifyOptItem = _NotifyOptItem;
   this.NotifyChkItem = _NotifyChkItem;

   this.NotifyField = _NotifyField;
   this.NotifyIntField = _NotifyTxtField;
   this.NotifyDblField = _NotifyTxtField;
   this.NotifyDatField = _NotifyDatField;
   this.NotifyTxtField = _NotifyTxtField;
   this.NotifySltField = _NotifySltField;
   this.NotifyOptField = _NotifyOptField;
   this.NotifyChkField = _NotifyChkField;
   this.NotifyStxField = _NotifyStxField;   // Static Text
   this.NotifyNLButton = _NotifyNLButton;   // NonLevel Button 
   this.NotifyTR       = _NotifyTR;         // Table Row

   this.SetReqFieldFocus = _SetReqFieldFocus;
}

function _EmptyFunction() {

}

//"intx" and 'dblx" are just like "int" and "dbl" type fileds, but allow inputing empty string.
function _FipProperty(param) {
   var aFieldName = param[0].split("_");
   this.fieldType = aFieldName[0];
   this.level = parseInt(aFieldName[2],10);
   if (isNaN(this.level)) {
      this.level = aFieldName[2];
   }
   this.fieldCode = parseInt(aFieldName[1],10);
   if (isNaN(this.fieldCode)) {
      this.fieldCode = aFieldName[1];
   }
   
   if (this.fieldType=="txt") {
      this.value = param[1][0].toString();
      this.unsetValue = "";
   } else if (this.fieldType=="dbl" || this.fieldType=="dblx") {   	  
  	  if(this.fieldType=="dblx" && param[1][0].toString().length==0) {
			this.value = ""
	  } else {	
	      	this.value = NullZero(parseFloat(param[1][0],10));
	  }
      this.min = parseFloat(param[1][1],10);
      this.max = parseFloat(param[1][2],10);
      this.dft = NullZero(parseFloat(param[1][3],10));
      this.unsetValue = 0;
   } else if (this.fieldType=="stx") {
      this.value = param[1][0].toString();
   } else {
	  if (this.fieldType=="slt") {
		this.value = param[1][0].toString();
	  } else {
	  	if(this.fieldType=="intx" && param[1][0].toString().length==0) {
			this.value = ""
		} else {
			this.value = NullZero(parseInt(param[1][0],10));
		}
	  }	
      this.min = parseInt(param[1][1],10);
      this.max = parseInt(param[1][2],10);
      this.dft = NullZero(parseInt(param[1][3],10));
      this.unsetValue = 0;
   }
   this.digits = NullZero(parseInt(param[1][4],10));
   this.available = NullZero(parseInt(param[1][5],10));
   this.list = param[1][6];
   this.fullList = param[1][7];
   if (this.available & RC_UNAVAILABLE_ALWAYS) {
      this.alwaysDisabled = true;
   }
   this.allowNegative = false;
   // Create new property (merged with AU2 in V2.8 conversion).    
   this.Equals = _FipProperty_Equals;
}

// Merged with AU2 in V2.8 conversion
function _FipProperty_Equals(oProp) {
    
//alert(oProp.fieldCode);        
    if (oProp) {
        return ((this.fieldType == oProp.fieldType) && 
                (this.fieldCode == oProp.fieldCode) && 
                (this.level == oProp.level));
    } else {
        return false;
    }
}

function _InitialSetup(arrProp) {
   var len = arrProp.length;
   var oParam;

   if (len==0) {
		BusinessRules.cltInitialSetup();
		return;
   }
   var PropertyArray = new Array(len-1);
   for(var i=0; i<=len-1; i++) {
      PropertyArray[i] = new _FipProperty(arrProp[i]);
      var fld = FindObj(arrProp[i][0]);
      if (fld) {
         fld.FipProperty = PropertyArray[i];
         if (fld.length) {
            for (var j=0; j<fld.length; j++)
               fld[j].FipProperty = PropertyArray[i];
         }
         _initOneField(fld);
         if (BusinessRules.cltInitOneField) {
            BusinessRules.cltInitOneField(fld);
         }
         BusinessRules.NotifyField(fld);
      }
   }
   BusinessRules.PropertyArray = PropertyArray;
   BusinessRules.cltInitialSetup();
   if (BusinessRules.ShowRequiredFields) {
      BusinessRules.SetReqFieldFocus();
   }
}

function _initOneField(fld) {
   switch (fld.FipProperty.fieldType) {
      case "slt":
         if (!fld.onchange) 
            fld.onchange = _EditValidate;
         break;
      case "opt":
         if (fld.length) {
            for (var i=0;i<fld.length;i++) {
               if (!fld.item(i).onclick) 
                  fld.item(i).onclick = _EditValidate;
            }
         } else {
            if (!fld.onclick) 
               fld.onclick = _EditValidate;
         }
         break;
      case "chk":
         if (!fld.onclick) 
            fld.onclick = _EditValidate;
         fld.value = 1;
         break;
      case "dat":
         fld.onfocus = _FieldOnFocus;
         if (!fld.onblur) 
            fld.onblur = _EditValidate;
         break;
      case "dbl":
	  case "dblx":
         fld.onfocus = _FieldOnFocus;
         if (!fld.onblur) 
            fld.onblur = _EditValidate;
         break;
      case "int":
	  case "intx":
         fld.onfocus = _FieldOnFocus;
         if (!fld.onblur) 
            fld.onblur = _EditValidate;
         break;
      case "txt":
         fld.onfocus = _FieldOnFocus;
         if (!fld.onblur) 
            fld.onblur = _EditValidate;
         break;
      default:
         break;
   }
}

function _EditValidate() {
   var fld = this;
   if (BusinessRules.SigExist && BusinessRules.SigExist != "" && BusinessRules.SigExist != "0") {
	if(FindObj("PageName").value=="AppProposed" && !IsPersonLockedItem(fld.FipProperty.fieldCode)) {  
	}else if(FindObj("PageName").value=="AppProposedJoint" && !IsJointPersonLockedItem(fld.FipProperty.fieldCode)) {  
	} else {
      var value;
      var param = new Param(value, MC_GETITEM, false);
      BusinessRules.NotifyItem(fld, param);
      var newValue;
      switch (fld.FipProperty.fieldType) {
         case "dbl":
		 	newValue = parseFloat(fld.value);
            break;
		 case "dblx":
		 	if(fld.value.toString().length==0) {
				newValue = "";
			} else {
		 		newValue = parseFloat(fld.value);
			}
            break;
         case "int":
		 	newValue = parseInt(fld.value);
            break;
		 case "intx":
		 	if(fld.value.toString().length==0) {
				newValue = "";
			} else {
		 		newValue = parseInt(fld.value);
			}
            break;
         case "dat":
			newValue = ConvertDateStringToLong(fld.value);
            break;
         case "chk":
			newValue = (fld.checked?1:0);
			break;
         default:
            newValue = fld.value;
            break;
      }
      if (param.data != newValue) {
         var sMsg = "WARNING, Signatures have been accepted for this Illustration/Application.  Making changes " +
                    "will remove the signatures.  Press OK to continue with the changes and remove the signatures.  " + 
                    "Press Cancel to keep the signatures and ignore the change.";
         var bConfirmed = window.confirm(sMsg);
         if (!bConfirmed) {
			if(fld.FipProperty.fieldType=="opt") {
				BusinessRules.NotifyItem(FindObj(fld.name), new Param(fld.FipProperty.value, MC_NOTIFY, false));
			} else {
				BusinessRules.NotifyItem(fld, new Param(fld.FipProperty.value, MC_NOTIFY, false));
			}
            return;
         } else {
            BusinessRules.SigExist = 0;
            BusinessRules.SigInvalidate = 1;
         }
      }
    }
   }
   switch (fld.FipProperty.fieldType) {
      case "slt":
      _sltEditValidate(fld);
        break;
      case "opt":
        _optEditValidate(fld);
        break;
      case "chk":
      _chkEditValidate(fld);
        break;
      case "dat":
      _datEditValidate(fld);
        break;
      case "dbl":
	  case "dblx":
      _dblEditValidate(fld);
	    break;
      case "int":
	  case "intx":
      _intEditValidate(fld);
        break;
      case "txt":
      _txtEditValidate(fld);
        break;
      default:
        break;
   }
}

function _ValidatePage() {
   var retVar;
   if (BusinessRules.currField) {
      retVar = BusinessRules.currField.onblur;
      if (retVar & RC_INVALID) return retvar;
      if (BusinessRules.currField) {
         BusinessRules.currField.blur();
      }
   }
   if (BusinessRules.PropertyArray==null) {
      return false;
   }
   for (var i=0; i<BusinessRules.PropertyArray.length; i++) {
      var oProp = BusinessRules.PropertyArray[i];
      if (oProp.required) {
         if ((((oProp.fieldType == "txt" || oProp.fieldType == "intx" || oProp.fieldType == "dblx") && oProp.value.length == 0) || (oProp.fieldType != "txt" && oProp.fieldType != "intx" && oProp.fieldType != "dblx" && oProp.value == 0))
		 		 && !(oProp.available & (RC_NOEDIT | RC_UNAVAILABLE))) {			                        
			if(oProp.description) {
				alert("Required information missing - field <"+oProp.description+">");
			} else {
				alert("Required information missing");          
			}            
			var fld = FindObj(oProp.fieldType + "_" + oProp.fieldCode + "_" + oProp.level + "_");
			if (fld) {
				if (oProp.fieldType != "slt" && fld.length>1) {
					for (var j=0; j<fld.length; j++) {
						if (fld[j].disabled == false)	{
							fld[j].focus();
							return true;
						}
					}
				} else if (fld.disabled == false) {
            		fld.focus();
            		return true;
				}
			}
			
         }
      }
   }
   fld = FindObj("DefaultFields");
   if (fld) {
      fld.value = "";
      for (var i=0; i<BusinessRules.PropertyArray.length; i++) {
         var oProp = BusinessRules.PropertyArray[i];
         if (!(oProp.available & (RC_NOEDIT | RC_UNAVAILABLE))) {
            if (((oProp.fieldType=="chk" || oProp.fieldType=="opt") && oProp.value == 0) || 
               ((oProp.fieldType=="txt" || oProp.fieldType=="dat") && oProp.value == "") ||
               (oProp.fieldType=="slt" && oProp.value == -1)) {
               fld.value += (oProp.fieldType + "_" + oProp.fieldCode + "_" + oProp.level + "_" + ";");
            }
         }
      }  
   }
   return BusinessRules.cltValidatePage();
}

function Param(data, action, internal, retValue, errMsg){
   this.data = data;
   this.action = action;
   this.internal = internal;
   this.retValue = retValue;
   this.errMsg = errMsg;
}


function FindProperty(sFieldCode, lLevel) {
   for (var i=0; i<BusinessRules.PropertyArray.length; i++) {
      if (BusinessRules.PropertyArray[i].level==lLevel && BusinessRules.PropertyArray[i].fieldCode==sFieldCode) {
         return BusinessRules.PropertyArray[i];
      }
   }
   return null;
}

function FindField(sFieldCode, lLevel) {
   var prop = FindProperty(sFieldCode, lLevel);
   if (prop) {
      var fld = FindObj(prop.fieldType + "_" + sFieldCode + "_" + lLevel + "_");
      if (fld) return fld;
      return FindObj(prop.fieldType + "_" + sFieldCode + "_" + lLevel);
   }
   return null;
}

function _FieldOnFocus() {
   var fld = this;
   var oProp = fld.FipProperty;
   BusinessRules.currField = fld;
   if (oProp.fieldType=="dbl" || oProp.fieldType=="int" || oProp.fieldType=="dblx" || oProp.fieldType=="intx") {
      if (oProp.value == 0 && (oProp.displayFormat & DISPLAY_FORMAT_NOSHOWZERO))
         fld.value = "";
      else
         fld.value = fld.FipProperty.value;
   }
   fld.select();
}

function _intEditValidate(fld) {
   //var fld = this;
   var bAllowEmpty = (fld.FipProperty.fieldType=="intx" ? true : false);
   if(bAllowEmpty && fld.value.toString().length==0) {
		var value = "";
	} else {
	   var value = parseInt(fld.value, 10);
	   if (isNaN(value)) value = 0;
	}
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyIntItem(fld, param);

   fld.value = fld.FipProperty.value;
   if (param.retValue & RC_INVALID) {
         if(param.errMsg.length) alert(param.errMsg);
         fld.focus(); 
   } else {
      var oProp = fld.FipProperty;
      if (oProp.value == 0 && (oProp.displayFormat & DISPLAY_FORMAT_NOSHOWZERO))
         fld.value = "";
      else if (oProp.displayFormat & DISPLAY_FORMAT_NOCOMMA)
         fld.value = oProp.value;
      else
	  	if(bAllowEmpty && oProp.value.toString().length==0) {
			fld.value = "";
		} else {
	         fld.value = FormatDouble(NullZero(oProp.value),0);
		}
      BusinessRules.currField = null;
   }
}

function _txtEditValidate(fld) {
   //var fld = this;
   value = trim(fld.value);
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyTxtItem(fld, param);

   fld.value = trim(fld.FipProperty.value);
   if (param.retValue & RC_INVALID) {
         if(param.errMsg.length) alert(param.errMsg);
         fld.focus(); 
   } else {
      BusinessRules.currField = null;
   }
}

function _datEditValidate(fld) {
	var value;
	if(fld.value=="") {
		value = 0;
	} else if(ConvertDateStringToLong(fld.value)==0) {
		value = fld.FipProperty.value;
		alert("Invalid date entered.");
		fld.focus(); 
	} else {
		value = ConvertDateStringToLong(fld.value);
	}
	
   //var value = ConvertDateStringToLong(fld.value);
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyDatItem(fld, param);	
			
   fld.value = ConvertLongToDateString(fld.FipProperty.value);
   if (param.retValue & RC_INVALID) {
         if(param.errMsg.length) alert(param.errMsg);
         fld.focus(); 
   } else {
      BusinessRules.currField = null;
   }
}

function _dblEditValidate(fld) {
   //var fld = this;
   var bAllowEmpty = (fld.FipProperty.fieldType=="dblx" ? true : false);

   if(bAllowEmpty && fld.value.toString().length==0) {
		var value = "";
   } else {
	   var value = parseFloat(trim(fld.value));	   
	   if (isNaN(value)) value = 0;
   }
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyDblItem(fld, param);  
   if (param.retValue & RC_INVALID) {
         fld.value = fld.FipProperty.value;
         if(param.errMsg.length) alert(param.errMsg);
         fld.focus(); 
   } else {
   	  	if(bAllowEmpty && fld.FipProperty.value.toString().length==0) {
			fld.value = "";
		} else {
      		fld.value = FormatDouble(fld.FipProperty.value,fld.FipProperty.digits);
		}
      BusinessRules.currField = null;
   }
}

function _chkEditValidate(fld) {
   //var fld = this;
   var value = fld.checked?1:0;
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyChkItem(fld, param);
}

function _sltEditValidate(fld) {
   //var fld = this;
   var value = 0;
   if (fld.selectedIndex != -1){
      value = fld.value; //options[oField.selectedIndex].value;
   }
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifySltItem(fld, param);
}

function _optEditValidate(fld) {
   //var fld = this;
   var value = fld.value;
   var param = new Param(value, MC_SETITEM, false);
   BusinessRules.NotifyOptItem(fld, param);
}

function _NotifyItem(fld, param) {
   if (!fld.FipProperty) {
      if (fld.length && fld[0].FipProperty) {
         fld.FipProperty = fld[0].FipProperty;
      } else {
         return true;
      }
   }
   switch (fld.FipProperty.fieldType) {
      case "txt":
         BusinessRules.NotifyTxtItem(fld, param);
         break;
      case "int":
	  case "intx":
         BusinessRules.NotifyIntItem(fld, param);
         break;
      case "dbl":
	  case "dblx":
         BusinessRules.NotifyDblItem(fld, param);
         break;
      case "dat":
         BusinessRules.NotifyDatItem(fld, param);
         break;
      case "slt":
         BusinessRules.NotifySltItem(fld, param);
         break;
      case "opt":
         BusinessRules.NotifyOptItem(fld, param);
         break;
      case "chk":
         BusinessRules.NotifyChkItem(fld, param);
         break;
   }
}

function _NotifyIntItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;
   var bAllowEmpty = (oProp.fieldType=="intx" ? true : false);
   
   param.retValue = 0;
   value = oProp.value;
   save = value;
   available = oProp.available;

   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value != 0) {
         value = 0;
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if(param.action & MC_SETITEM) {
         if(param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else {
               value = 0;
            }
         } else if (param.data != null) {
            value = param.data;
         }
         
         if (oProp.checkMinMax) {
            value = oProp.checkMinMax(value, save, param);
         } else {
            if (!isNaN(oProp.min) && value < oProp.min) {
               value = (save>oProp.min) ? save : oProp.min;
               param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The minimum value is ", oProp.customErrMsgMin, oProp.min);
               //param.errMsg = "The minimum value is " + oProp.min;
            } else if (!isNaN(oProp.max) && value > oProp.max) {
               value = (save<oProp.max) ? save : oProp.max;
               param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The maximum value is ", oProp.customErrMsgMax, oProp.max);
               //param.errMsg = "The maximum value is " + oProp.max;
            }
         }
         if (value != save || (bAllowEmpty && value.toString().length != save.toString().length)) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }
         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
      }
   } 
   param.data = value;

   if((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyIntField(fld);
   }
}

function _NotifyDblItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;
   var bAllowEmpty = (oProp.fieldType=="dblx" ? true : false);
   
   param.retValue = 0;
   value = oProp.value;
   save = value;
   available = oProp.available;

   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value != 0) {
         value = 0;
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else {
               value = 0;
            }
         } else if (param.data != null) {
		 	if(bAllowEmpty && param.data.toString().length==0) {
				value = "";
			} else { 
	            value = RoundDouble(param.data,oProp.digits);
			}
         }
         if (oProp.checkMinMax) {
            value = oProp.checkMinMax(value, save, param);
         } else {
            if (!isNaN(oProp.min) && value < oProp.min) {
               value = (save>oProp.min) ? save : oProp.min;
               param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The minimum value is ", oProp.customErrMsgMin, FormatDouble(oProp.min, oProp.digits));
               //param.errMsg = "The minimum value is " + FormatDouble(oProp.min, oProp.digits);
            } else if (!isNaN(oProp.max) && value > oProp.max) {
               value = (save<oProp.max) ? save : oProp.max;
               param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The maximum value is ", oProp.customErrMsgMax, FormatDouble(oProp.max, oProp.digits));
               //param.errMsg = "The maximum value is " + FormatDouble(oProp.max, oProp.digits);
            }
         }
		 if (value != save || (bAllowEmpty && value.toString().length != save.toString().length)) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }
         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
         
      }
   } 
   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }     
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyDblField(fld);
   }
}

function _NotifySltItem(fld,param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available, list;
   
   param.retValue = 0;
   
   value = oProp.value;
   save = value;
   
   available = oProp.available;
   if (available & RC_UNAVAILABLE) {//Disable and no value
      if(value != 0) {
         value = 0;
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            value = oProp.dft;
         } else if (param.data != null) {
            value = param.data;
         }
         list = fld.FipProperty.list;
         if (list.length && isInList(list,value)<0) value = list[0][0]; 

         if (value != save) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }
         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
      }
   } 
   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }
   }

   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifySltField(fld);
   }
}

function _NotifyDatItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;

   param.retValue = 0;
   value = NullZero(oProp.value);        
   save = value;
   available = oProp.available;
   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value != 0) {
         value = 0;
         oProp.value = 0;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else {
               value = 0;
            }
         } else if (param.data != null) {       
            value = param.data;
         }

         // Merged with AU2 in V2.8 conversion
         if (oProp.checkMinMax) {
             value = oProp.checkMinMax(value, save, param);
         } else {
             var minDate = oProp.min;
             var maxDate = oProp.max;
             if (!isNaN(oProp.min) && value < minDate && value > 0) {
                value = (save>minDate) ? save : minDate;
                param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The earliest date is ", oProp.customErrMsgMin, ConvertLongToDateString(oProp.min));
                //param.errMsg = "The earliest date is " + ConvertLongToDateString(oProp.min);
             } else if (!isNaN(oProp.max) && value > maxDate) {
                value = (save<maxDate) ? save : maxDate;
                param.retValue = RC_INVALID;
			    param.errMsg = GetErrMsg("The latest date is ", oProp.customErrMsgMax, ConvertLongToDateString(oProp.max));
                //param.errMsg = "The latest date is " + ConvertLongToDateString(oProp.max);
             }
         }
         if (value != save) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }

         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
      }
   }

   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }     
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyDatField(fld);
   }
}

function _NotifyOptItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;
   
   param.retValue = 0;
   value = oProp.value;
   save = value;
   available = oProp.available;

   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value) {
         value = 0;
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else if (fld.length) {
               value = fld[0].value;
            } else {
               value = fld.value;
            }
         } else if(param.data != null) {
            value = param.data;
         }
         var list = fld.FipProperty.list;
         if (list && list.length && isInList(list,value)<0) value = list[0][0]; 
         
         if (value != save) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }
         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
      }
   } 
   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }     
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyOptField(fld);
   }
}

function _NotifyTxtItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;
   
   param.retValue = 0;
   value = oProp.value;
   save = value;
   available = oProp.available;

   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value) {
         value = "";
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else {
               value = "";
            }
         } else if (param.data != null) {
            value = param.data;
         }
         if (oProp.IsSSN) value = _ValidateSSNGen(value, save, param);
         if (oProp.IsTaxID) value = _ValidateTaxIDGen(value, save, param);
	 if (oProp.IsCaseNbr) value = _ValidateCaseNbr(value, save, param);
	 if (oProp.IsZIP) value = _ValidateZIP(value, save, param);
     if (oProp.IsRoutingNumber) value = _ValidateRoutingNumber(value, save, param, oProp.ShowConfirm);
	 if (oProp.IsPolicyNumber) value = _ValidatePolicyNumber(value, save, param);
	 
         if (value != save) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
            if (BusinessRules.ShowRequiredFields) {
               param.action |= MC_NOTIFY;
            }
         }
         if (value == oProp.unsetValue) {
            oProp.available |= RC_INFOMISSING;
         } else if (oProp.available & RC_INFOMISSING) {
            oProp.available ^= RC_INFOMISSING;
         }
      }
   } 
   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }     
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyField(fld);
   }

}

function _NotifyChkItem(fld, param) {
   BusinessRules.SetFieldRules(fld, param);
   var oProp = fld.FipProperty;
   var value, save, available;
   
   param.retValue = 0;
   value = oProp.value;
   save = value;
   available = oProp.available;

   if (available & RC_UNAVAILABLE) {//Disable and no value
      if (value) {
         value = 0;
         oProp.value = value;
         param.retValue |= RC_MODIFIED;
      }
   } else {
      if (param.action & MC_SETITEM) {
         if (param.action & MC_DFLTITEM) {
            if (oProp.dft!=null) {
               value = oProp.dft;
            } else {
               value = 0;
            }
         } else if(param.data != null) {
            value = param.data;
         }
         if (value != save) {
            oProp.value = value;
            param.retValue |= RC_MODIFIED;
         }
      }
   } 
   param.data = value;

   if ((param.action & MC_NOSETCHILD) == 0) {
      if (param.retValue & RC_MODIFIED) {
         BusinessRules.SetNotifyFields(fld, param);
      }     
   }
   
   if (param.action & MC_NOTIFY) {
      BusinessRules.NotifyChkField(fld);
   }

}

function _NotifyField(fld) {
   switch (fld.FipProperty.fieldType) {
      case "txt":
         BusinessRules.NotifyTxtField(fld);
         break;
      case "int":
	  case "intx":
         BusinessRules.NotifyIntField(fld);
         break;
      case "dbl":
	  case "dblx":
         BusinessRules.NotifyDblField(fld);
         break;
      case "dat":
         BusinessRules.NotifyDatField(fld);
         break;
      case "slt":
         BusinessRules.NotifySltField(fld);
         break;
      case "opt":
         BusinessRules.NotifyOptField(fld);
         break;
      case "chk":
         BusinessRules.NotifyChkField(fld);
         break;
      case "stx":
         BusinessRules.NotifyStxField(fld);
         break;
      case "nlb": 
         BusinessRules.NotifyNLButton(fld);
         break;
      case "row": 
         BusinessRules.NotifyTR(fld);
         break;
   }
}

function NotifyBuddy(fld,j) {
    CSS_CLASS_FLD_REQUIRED_NOVALUE = 'FldRequiredNoValue';
    CSS_CLASS_FLD_REQUIRED_HASVALUE = 'FldRequiredHasValue';
    CSS_CLASS_FLD_REQUIRED = 'FldRequired';
    
	var oBuddy = FindObj("lbl" + fld.name.substring(3));
    
	if (oBuddy) {
        var oProp = fld.FipProperty;
		if (NotifyBuddy.arguments.length >= 2 && oBuddy.length) {
			oBuddy[j].disabled = fld.disabled;
		} else {
			oBuddy.disabled = fld.disabled;
		}
        oBuddy.style.display = fld.style.display;
        if (BusinessRules.ShowRequiredFields) {
            if ((oProp.available & RC_INFOREQUIRED) != 0) {
                oBuddy.className = ((oProp.available & RC_INFOMISSING) != 0)? 
                        CSS_CLASS_FLD_REQUIRED_NOVALUE : CSS_CLASS_FLD_REQUIRED_HASVALUE;
            }
        } else if (oProp.required) {
            oBuddy.className = CSS_CLASS_FLD_REQUIRED;
        }
	}
}

function _NotifyDatField(fld) {
   var oProp = fld.FipProperty;
   if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
      fld.value = "";
   } else {
      fld.value = ConvertLongToDateString(oProp.value);
   }
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   NotifyBuddy(fld);
}

function _NotifyTxtField(fld) {
   var oProp = fld.FipProperty;
   if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
      fld.value = "";
   } else if (oProp.fieldType=="dbl") {
   	  fld.value = FormatDouble(oProp.value, oProp.digits);
   } else if (oProp.fieldType=="dblx") {
   	  if (oProp.value.toString().length==0) {
	  	fld.value = "";
	  } else {
      	fld.value = FormatDouble(oProp.value, oProp.digits);
	  }
   } else if (oProp.fieldType=="int") {
      if (oProp.value == 0 && (oProp.displayFormat & DISPLAY_FORMAT_NOSHOWZERO))
         fld.value = "";
      else if (oProp.displayFormat & DISPLAY_FORMAT_NOCOMMA)
         fld.value = oProp.value;
	  else
         fld.value = FormatDouble(NullZero(oProp.value),0);
   } else if (oProp.fieldType=="intx") {
      if (oProp.value == 0 && (oProp.displayFormat & DISPLAY_FORMAT_NOSHOWZERO))
         fld.value = "";
      else if (oProp.displayFormat & DISPLAY_FORMAT_NOCOMMA)
         fld.value = oProp.value;
      else if (oProp.value.toString().length==0)
	  	fld.value = "";
	  else
         fld.value = FormatDouble(NullZero(oProp.value),0);
   } else {
      fld.value = oProp.value;
   }
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   NotifyBuddy(fld);
}

function _NotifyOptField(fld) {
   if (fld.length) {
      for(var j=0; j<fld.length; j++){
         _NotifyOptField(fld[j]);
         NotifyBuddy(fld[j],j);
      }
   } else {
      var oProp = fld.FipProperty;
      if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
         fld.checked = false;
      } else {
         fld.checked = (fld.value == oProp.value);
      }
      if (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT))) {
         fld.disabled = true;
      } else if (oProp.list && oProp.list.length) {
         fld.disabled = isInList(oProp.list, fld.value) < 0;
      } else {
         fld.disabled = false;
      }      
      fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   }
}

function _NotifyChkField(fld) {
   var oProp = fld.FipProperty;
   if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
      fld.checked = false;
   } else {
      fld.checked = (fld.value == oProp.value);
   }
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   NotifyBuddy(fld);
}

function _NotifySltField(fld) {
   var oProp = fld.FipProperty;
   var Index;
   if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
      fld.length = 0;
   } else {
      PopulateList(fld, oProp.list, oProp.Sort);
      selectItemFromList(fld, oProp.value);
	  Index = selectItemFromList(fld, oProp.value);
	  if (Index == -1 && fld.length > 0 && fld.multiple!=true)
	  {
			fld.options[0].selected = true;
			fld.FipProperty.value = fld.value;
	  }
   }
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE |  RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   NotifyBuddy(fld);
}

function _NotifyStxField(fld) {
   var oProp = fld.FipProperty;
   if (oProp.alwaysDisabled || (oProp.available & RC_UNAVAILABLE)) {
      fld.innerText = "";
   } else {
      fld.innerText = oProp.value;
   }
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
}

function _NotifyNLButton(fld) {
   IMG_ONELEVEL = "Images/Changes.gif";
   IMG_MULTILEVELS = "Images/ChangesExist.gif";
   var oProp = fld.FipProperty;

   fld.src = (oProp.value > 1)? IMG_MULTILEVELS : IMG_ONELEVEL;
   fld.disabled = (oProp.alwaysDisabled || (oProp.available & (RC_UNAVAILABLE | RC_NOEDIT)));
   fld.style.display = ((oProp.available & RC_INVISIBLE) == 0)? FLD_STYLE_VISIBLE : FLD_STYLE_INVISIBLE;
   fld.style.cursor = (fld.disabled)? "default" : "hand";
}

function _NotifyTR(fld) {
   var oProp = fld.FipProperty;
   var oParent = fld.parentElement;
   while (oParent != null) {
	  if (oParent.tagName == "TR") break;
      oParent = oParent.parentElement;
   }
   if (oParent) {
      oParent.style.display = ((oProp.available & RC_INVISIBLE) != 0)? FLD_STYLE_INVISIBLE : FLD_STYLE_VISIBLE;
   }
}

function EnableKeyCheck() {
/*
	if (document.layers) {
		document.captureEvents(Event.MOUSEMOVE);
		document.captureEvents(Event.KEYPRESS);
		document.captureEvents(Event.KEYPDOWN);
	}
	document.onkeypress = _KeyPressHandler;
	if(!gbDesignMode) {
		document.onkeydown = _KeyDownHandler;
		document.body.oncontextmenu= _ContextMenuHandler;
	}
	
	try {
		if (navigator.userAgent.indexOf("Firefox")<0) {
			var oThisForm = FindObj("thisForm");
			if(oThisForm) {
				if (!gfFormSubmit) {			
					gfFormSubmit = oThisForm.submit;		
					oThisForm.submit = _FipFormSubmit;	
				}
			}
		}
	} catch (e) {
	}
*/
}

function _FipFormSubmit() {
	var lNewSubmitTime = new Date().valueOf();
	if(!gbSubmitted || (lNewSubmitTime - glSubmitTime>5000)) {
		gfFormSubmit();
		gbSubmitted = true;
		glSubmitTime = lNewSubmitTime;
	} else {
		//alert("_FipFormSubmit");
	}
}

function _KeyDownHandler() {
	var oActiveElement;

	if(window.event && window.event.keyCode == 116) { // Capture F5
		window.event.keyCode = 0;
		return false; 
	} else if(event.ctrlKey && window.event.keyCode == 78) {	// Capture Ctrl + N
		window.event.keyCode = 0;
		return false; 
	} else if(window.event && window.event.keyCode == 8) { // Capture backspace
		oActiveElement = window.document.activeElement;
		if(oActiveElement) {
			if(oActiveElement.type!="text" && oActiveElement.type!="textarea" && oActiveElement.type!="password") {
				window.event.keyCode = 0;
				return false; 
			}
		}
		//if(!window.document.activeElement.isContentEditable) {
        //    window.event.keyCode = 0;
		//	return false; 
		//}
	} else if(window.event && window.event.keyCode == 27) { // Capture ESC to prevent resetting fields on a page
		oActiveElement = window.document.activeElement;
		if(oActiveElement) {
			if(oActiveElement.type=="text" || oActiveElement.type=="textarea" || oActiveElement.type=="password") {
				window.event.keyCode = 0;
				return false; 
			}
		}
	}
}

function _ContextMenuHandler() {
	return false;
}

function _KeyPressHandler(e) {
   var bIsIE = (document.all)? true:false;
   var kCode = (bIsIE)? window.event.keyCode : e.which;
   if (kCode == 8) return;    // back
   var fld = (bIsIE)? window.event.srcElement : e.target;
   
   var aField, fldType = "", bAllowNegative = false;   


   try {
	if(fld.enableEnterKey && kCode==13 && fld.EnterKeyFunc) {
		fld.EnterKeyFunc();
		return IgnoreKeyStroke();
		}
   } catch (e) {
   }	

   if (fld.FipProperty) {   		
		fldType = fld.FipProperty.fieldType;
		bAllowNegative = fld.FipProperty.allowNegative;		
   } else if(fld.name){
	   	aField = fld.name.split("_");
   		if(aField.length>=2) fldType= aField[0];   
   }	

   var txtRange;
   
   switch (fldType) {
      case "int":
	  case "intx":
         if ((kCode < 48 || kCode > 57) && kCode != 45) { // 0 to 9
 			if (navigator.userAgent.indexOf("Firefox")!= -1) {
				if (kCode!=0){
           			return IgnoreKeyStroke();
				}
			}else{
           		return IgnoreKeyStroke();
			}
         }
         if (kCode == 45) {                // "-": 45
			txtRange = "";
            if (document.selection.type == "Text") {
               txtRange = document.selection.createRange().text;
            }
			if (!(bAllowNegative) || ((fld.value.indexOf("-") != -1) && (txtRange.indexOf("-") == -1))) {
          		return IgnoreKeyStroke();
          	}
      	 }
         break;
      case "dbl":
	  case "dblx":
         var bIgnore = false;
  		 if ((kCode == 45) || (kCode == 46)) {       // "-", "."
  		    txtRange = "";
            if (document.selection.type == "Text") {
               txtRange = document.selection.createRange().text;
            }
        	if (kCode == 46) {                       // ".": 46
                if ((fld.value.indexOf(".") != -1) && (txtRange.indexOf(".") == -1)) {
          			bIgnore = true;
          		}
  		    } else if (kCode == 45) {                // "-": 45
                if (!(bAllowNegative) || ((fld.value.indexOf("-") != -1) && (txtRange.indexOf("-") == -1))) {
          			bIgnore = true;
          		}
      		}
         } else if (!(kCode >= 48 && kCode <= 57)) { // 0 to 9
            if (navigator.userAgent.indexOf("Firefox")!= -1) {
				if (kCode!=0){
            		bIgnore = true;
				}
			}else{
            	bIgnore = true;
			}
         }
         if (bIgnore) {
  			return IgnoreKeyStroke();
         }
         break;
      case "dat":
         if (kCode != 45 && (kCode < 47 || kCode > 57)) {// "-": 45, "/": 47
            return IgnoreKeyStroke();
         }
         break;
	  default:
	   	try {
			if(ENABLE_ENTER_KEY) {
			   if(kCode==13 && fld.onclick) fld.onclick();
			}
	   	} catch (e) {
	   	}
		break;
   }
   if (fld.Clt_KeyPressHandler) {
   		return fld.Clt_KeyPressHandler(e, kCode);
	}
}

function IgnoreKeyStroke() {
   var bIsIE = (document.all)? true:false;
   if (bIsIE) window.event.keyCode = 0; 
   return false;
}

function isImgButtonEnabled(oCtrl) {
   return (oCtrl.style.cursor == "hand");
}

function colorMe(whatObj){
   whatObj.bgColor = "#FFFF99";
    whatObj.cells[0].borderColor = "#FFFF99";
    whatObj.cells[1].borderColor = "#FFFF99";
}
function unColorMe(whatObj){
   whatObj.bgColor = "#CCCC99";
    whatObj.cells[0].borderColor = "#CCCC99";
    whatObj.cells[1].borderColor = "#CCCC99";
}

function isInSet(params) {
    
    if (arguments.length < 2) {return false};
    for (var ptr=1; ptr <= arguments.length; ptr++) {
		if (arguments[0] == arguments[ptr]){
			return true;
		}
	}
	return false;
}

function getMenu_AU(concept) {
	switch (concept) {
		case CONCEPT_SD: 
			return gMenu_AU_SD;
			break;
		case CONCEPT_EB: 
			return gMenu_AU_EB;
			break;
		case CONCEPT_DC:
		case CONCEPT_SDDC: 
			return gMenu_AU_DC;
			break;
	}
}

function isConcept_AU(conceptCode){
	return isInSet(conceptCode, CONCEPT_SD, CONCEPT_EB, CONCEPT_DC, CONCEPT_SDDC);
}

function isConcept_InForce(conceptCode){
	return (conceptCode == CONCEPT_INF);
}

function isConcept_MBA(conceptCode){
	return (conceptCode == CONCEPT_MBA);
}

function isPlanType_AN(planType) {
    
    var bPlanTypeAN;
    
    if (planType > PLAN_START_USE_AN && planType < PLAN_END_USE_AN || 
        planType > PLAN_START_USE_VAN && planType < PLAN_END_USE_VAN) {
	        bPlanTypeAN = true;
    } else {
		    bPlanTypeAN = false;
    }
    return bPlanTypeAN;
}

function isPlanType_Term(planType) {
    
    var bPlanTypeTerm;
    
    if (planType == PLAN_TYPE_TERM) {
	        bPlanTypeTerm = true;
    } else {
		    bPlanTypeTerm = false;
    }
    return bPlanTypeTerm;
}



/***************************************************
	Menu class
***************************************************/
// 'actionId' attribute: required for each menu item; 
//  set it to AC_ code 
// 'noTabStop' attribute: set it for the items which shouldn't get focus

var Menu = new _Menu();
	
function _Menu() {
	this.MENU_TEXT_ID = "menu_text";
	this.setup = _MenuSetup;
	this.length = _MenuLength;
	this.item = _MenuItem;
	this.setVisible = _MenuSetVisible;
	this.getVisible = _MenuGetVisible;
	this.setNavigation = _MenuSetNavigation;
	this.getPrev = _MenuGetPrev;
	this.getNext = _MenuGetNext;
	this.getPrevId = _MenuGetPrevId;
	this.getNextId = _MenuGetNextId;
	this.getName = _MenuGetName;
	this.setName = _MenuSetName;
	this.SetAdvUndMenuName = _MenuSetAdvUndMenuName;
}

function _MenuSetup(curActionId) {

	this.curActionId = curActionId; //AC_ code of this page
	
	var arrMenu = new Array(0);
	var trs = document.getElementsByTagName("tr");
	var count=0;
	for (var i=0; i<trs.length; i++) {
		oTr = trs[i];
		if (oTr.actionId) {
			arrMenu.length = count + 1;
			arrMenu[count] = oTr;
			if (eval(oTr.actionId)) {
				// Replace Action AC_ string with its value
				oTr.actionId = eval(oTr.actionId);
			} else {
				oTr.actionId = 0;
			}
			if (oTr.noTabStop) {
				oTr.tabStop = false;
			} else {
				oTr.tabStop = true;
			}
			count++;
		}
	}
	this.arrMenu = arrMenu;
//Client hook
	try {
		clt_MenuSetup();
	} catch(e) {}
	
	this.setNavigation();

	if (this.item(AC_ADVUND)) {
		if (this.getVisible(AC_ADVUND)) {
			this.SetAdvUndMenuName();
		}
	}
}

function _MenuLength() {
	return this.arrMenu.length;
}

function _MenuItem(id) {
	for (var i = 0; i < this.length(); i++) {
		if (this.arrMenu[i].actionId == id) {
			return this.arrMenu[i];
		}
	}
	return null;
}

function _MenuGetPrev() {
	for (var cur = 0; cur < this.length(); cur++) {
		if (this.arrMenu[cur].actionId == this.curActionId) {
			break;
		}
	}
	for (var i=cur-1; i>=0; i--) {
		if (this.getVisible(this.arrMenu[i].actionId)) {
			if (this.arrMenu[i].noFocus) {
			} else {
				return this.arrMenu[i];
			}
		}
	}
	return null;
}

function _MenuGetNext() {
	for (var cur = 0; cur < this.length(); cur++) {
		if (this.arrMenu[cur].actionId == this.curActionId) {
			break;
		}
	}
	for (var i=cur+1; i<this.length(); i++) {
		if (this.getVisible(this.arrMenu[i].actionId)) {
			if (this.arrMenu[i].noFocus) {
			} else {
				return this.arrMenu[i];
			}
		}
	}
	return null;
}

function _MenuGetPrevId() {
	oPrev = this.getPrev();
	if (oPrev) {
		return oPrev.actionId;
	} else {
		return 0;
	}
}

function _MenuGetNextId() {
	oNext = this.getNext();
	if (oNext) {
		return oNext.actionId;
	} else {
		return 0;
	}
}

function _MenuSetVisible(actionId, isVisible) {
	for (var i=0; i<this.length(); i++) {
		if (this.arrMenu[i].actionId == actionId) {
			this.arrMenu[i].style.display = (isVisible) ? "block":"none";
			break;
		}
	}
}

function _MenuGetVisible(id) {
	for (var i=0; i<this.length(); i++) {
		if (this.arrMenu[i].actionId == id) {
			return (this.arrMenu[i].style.display == "none")? false : true;
		}
	}
}

function _MenuSetNavigation() {
	var oDiv, i;
	var checkItem;
	oDiv = FindObj("divPrev");
	if (oDiv) {
		checkItem = this.getPrev();
		if (checkItem) {
			if (!checkItem.tabStop) checkItem = null;
		}
		if(oDiv.length) {
			for(i=0; i<oDiv.length; i++) {
				oDiv[i].style.display = (checkItem == null)? "none":"block";				
				if (checkItem && oDiv[i].childNodes.length && oDiv[i].childNodes("imgPrev").length)
					if(oDiv[i].childNodes("imgPrev").children)
						oDiv[i].childNodes("imgPrev").children(0).alt = this.getName(checkItem);
			}
		} else {
			oDiv.style.display = (checkItem == null)? "none":"block";
			if (checkItem && oDiv.childNodes.length && oDiv.childNodes("imgPrev").length)
				oDiv.childNodes("imgPrev").children(0).alt = this.getName(checkItem);
		}
	}
	oDiv = FindObj("divNext");
	if (oDiv) {
		checkItem = this.getNext();
		if (checkItem) {
			if (!checkItem.tabStop) checkItem = null;
		}
		if(oDiv.length) {
			for(i=0; i<oDiv.length; i++) {
				oDiv[i].style.display = (checkItem == null)? "none":"block";				
				if (checkItem && oDiv[i].childNodes.length && oDiv[i].childNodes("imgNext").length)
					if(oDiv[i].childNodes("imgNext").children)
						oDiv[i].childNodes("imgNext").children(0).alt = this.getName(checkItem);
			}
		} else {
			oDiv.style.display = (checkItem == null)? "none":"block";
			if (checkItem && oDiv.childNodes.length && oDiv.childNodes("imgNext").length)
				oDiv.childNodes("imgNext").children(0).alt = this.getName(checkItem);
		}
	}
}

function _MenuSetName(id, name) {
	var oItem = this.item(id);
	if (oItem) {
		oItem.childNodes(this.MENU_TEXT_ID).innerText = name;
	}
}

function _MenuGetName(oItem) {
	if (oItem) {
		return oItem.childNodes(this.MENU_TEXT_ID).innerText;
	} else {
		return "";
	}
}

function _MenuSetAdvUndMenuName() {
	switch (BusinessRules.conceptCode) {
		case CONCEPT_SD:
			this.setName(AC_ADVUND, "Split Dollar");
			break;
		case CONCEPT_EB:
			this.setName(AC_ADVUND, "Executive Bonus");
			break;
		case CONCEPT_DC:
			this.setName(AC_ADVUND, "Deferred Compensation");
			break;
		case CONCEPT_SDDC:
			this.setName(AC_ADVUND, "Split Dollar /  Deferred Comp");
			break;
	}

}

/***************************************************/

function IsSignaturesStarted(sceneStatus) {
    return ((sceneStatus >= SCENE_STATUS_LOCKED) && (sceneStatus < SCENE_STATUS_FINISH_SIGN));
}

function IsSignaturesComplete(sceneStatus) {
    return (sceneStatus >= SCENE_STATUS_FINISH_SIGN);
}

function DoSignaturesCompleteWarning(AppName) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for " + AppName + ".  Making changes " + 
           "will remove the signatures.\nPress OK to continue and remove the signatures.  " + 
		   "Press Cancel to keep the signatures."

    return window.confirm(sMsg);
}

function DoSignaturesStartedWarning(AppName) {
    var sMsg;
    sMsg = "WARNING: Signature process has been started for " + AppName + 
        ". Do you want to remove the existing signatures?\n" +
        "Press OK to remove the signatures.  " +
        "Press Cancel to finish collecting signatures."

    return window.confirm(sMsg);
}

function DoScenarioSignaturesCompleteWarning(AppName) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for " + AppName + " in the same scenario.  Making changes " + 
           "will remove the signatures.\nPress OK to continue and remove the signatures.  " + 
		   "Press Cancel to keep the signatures."

    return window.confirm(sMsg);
}

function DoScenarioSignaturesStartedWarning(AppName) {
    var sMsg;
    sMsg = "WARNING: Signature process has been started for " + AppName + 
        " in the same scenario. Do you want to remove the existing signatures?\n" +
        "Press OK to remove the signatures.  " +
        "Press Cancel to finish collecting signatures."

    return window.confirm(sMsg);
}

function DoSignaturesExistWarning(AppName) {
    sMsg = "WARNING: Signatures have been accepted for " + AppName +
        ".  Making changes will remove the signatures.\n" +
        "Press OK to continue and remove the signatures.  " +
        "Press Cancel to keep the signatures."

    return window.confirm(sMsg);
}

function DoIllSignaturesRequiredWarning(AppName) {
    sMsg = "WARNING: The associated " + AppName +
        " is not signed.\nPress OK to sign the associated " + AppName +
        ". Press Cancel to discard " + AppName + "."

    return window.confirm(sMsg);
}

function DoIllSignaturesCompleteConfirm(SceneStatus) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for Illustration.  Making changes " + 
           "will remove the signatures.\nPress OK to continue and remove the signatures."
	if (SceneStatus > 11)
	{
		if (window.confirm(sMsg))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	return true;
}

function DoGrpSignaturesCompleteConfirm(ERStatus) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for this Employer.\n" +
		   "Only Product additions are allowed without removing signatures.\n" +
		   "If you remove signatures you will have to re-sign before you can Enroll.\n\n" +
		   "Press OK to REMOVE the signatures, press Cancel to Add Products or View Employer Information."

	if (window.confirm(sMsg))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function DoCaseSignaturesCompleteConfirm(ERStatus) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for this Case.\n" +
		   "Entering modify will remove the signatures.\n" +
		   "If you remove the signatures you will have to re-sign before you can Enroll.\n\n" +
		   "Press OK to REMOVE the signatures, press Cancel to view the data."
	if (window.confirm(sMsg))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function DoAppSignaturesCompleteWarning(Status) {
    var sMsg;
    sMsg = "WARNING: Signatures have been accepted for this app.  Making changes " + 
           "will remove the signatures.\nPress OK to continue and remove the signatures.  " + 
		   "Press Cancel to keep the signatures."

    return window.confirm(sMsg);
}

function AppendFieldName(oFldList, sFldName) {
	var s = oFldList.value;
	if (s.indexOf(sFldName) == -1) { 
		oFldList.value += sFldName + ';';
	}
}

function IsPersonLockedItem(lTag) {
	switch (lTag) {
	case tPER_PrInsuredFirstName:
	case tPER_PrInsuredMiddleInit:
	case tPER_PrInsuredLastName:
	case tPER_PrInsuredSuffix:
	case tPER_PrInsuredBirthDate:
	case tPER_PrInsuredAttainedAge:
	case tPER_PrInsuredSex:
		return true;
		break;
	default:
		return false;
		break;
	}
}

function IsJointPersonLockedItem(lTag) {
	switch (lTag) {
	case tPER_JointFirstName:
	case tPER_JointMiddleInit:
	case tPER_JointLastName:
	case tPER_JointSuffix:
	case tPER_JointBirthDate:
	case tPER_JointAttainedAge:
	case tPER_JointSex:
		return true;
		break;
	default:
		return false;
		break;
	}
}

function GetErrMsg(stdMsg, customMsg, value) {
	var errMsg;
	if (customMsg) {
		errMsg = (new String(customMsg)).replace("$VALUE$", value);
	} else {
		errMsg = stdMsg + value;
	}
	return errMsg;	
}

function _SetReqFieldFocus() {
   for (var i = 0; i < BusinessRules.PropertyArray.length; i++) {
      var oProp = BusinessRules.PropertyArray[i];
      if (oProp.available & RC_INFOREQUIRED) {
         if (oProp.available & RC_INFOMISSING) {			                        
			var fld = FindObj(oProp.fieldType + "_" + oProp.fieldCode + "_" + oProp.level + "_");
            if(oProp.fieldType != "slt" && fld.length > 1) fld = fld[0];
            if (fld) fld.focus();
            return true;
         }
      }
   }
}

function _ValidateSSNGen(value, save, param) {
	var MSG = "Wrong format of SSN. Use 123-45-6789 format.";
	
   if (value.length == 0) return "";
   if (value.length == 9) {
      if (!isNaN(value)) {
         return value.substring(0,3) + "-" + value.substring(3,5) + "-" + value.substring(5,9);
      }
   } else if (value.length == 11) {
      var ss = value.split("-");
      if (ss.length==3 && ss[0].length==3 && ss[1].length==2 && ss[2].length==4 && !isNaN(""+ss[0]+ss[1]+ss[2]))
         return value;
   }
   param.retValue = RC_INVALID;
   param.errMsg = MSG;
   return save;   
}

function _ValidateTaxIDGen(value, save, param) {
   var MSG = "Wrong format of Tax ID. Use 12-3456789 format.";

   if (value.length == 0) return "";
   if (value.length == 9) {
      if (!isNaN(value)) {
         return value.substring(0,2) + "-" + value.substring(2,9);
      }
   } else if (value.length == 10) {
      var ss = value.split("-");
      if (ss.length==2 && ss[0].length==2 && ss[1].length==7 && !isNaN(""+ss[0]+ss[1]))
         return value;
   }
   param.retValue = RC_INVALID;
   param.errMsg = MSG;
   return save;     
}

//mml v2.6, for Session TimeOut dialogbox
function DoResetTimer(){
	var sessionFrame;
	if (typeof(bNeedTimer) == "undefined" || bNeedTimer==true)
	{
		sessionFrame=FindSessionFrame(self);

		if(sessionFrame)
		{
			sessionFrame.ResetTimer();
		}

		if  (window.top.opener)
		{
			sessionFrame=FindSessionFrame(window.top.opener);
			if (sessionFrame)
			{
				sessionFrame.ResetTimerFromSubWin(window.top);
			}
		}
	}
	else{
		sessionFrame=FindSessionFrame(self);

		if(sessionFrame)
		{
			sessionFrame.DisableTimer();
		}
	}
}

function FindSessionFrame(currWin)
{
    try{
	    while(currWin.parent != currWin){
		if(currWin.parent.SessionCtlFrame) return currWin.parent.SessionCtlFrame;
		currWin=currWin.parent;
	    }
    }catch(e)
    {
    }
    return null;
}

DoResetTimer();

function SaveSceneAs() {

	var sNewDesc = prompt("Please input new scene description", "");
	if (sNewDesc == null) return;
	if (sNewDesc.length == 0) return;
	var fldParam = FindObj("SceneDescription");
	if (!fldParam) {
	    var sHtml = '<input name="SceneDescription" type="hidden">';
	    fldParam = document.createElement(sHtml);
	    FindObj("thisForm").appendChild (fldParam);
	}
    fldParam.value = sNewDesc;
	doSubmit(AC_SAVE_SCENE_AS);
}

function EnableRowMenu(obj, bEnabled) {	//Assume menu is enabled initially
	var bEnabledSave = (obj.style.cursor == "default") ? false : true;
	if(!bEnabled && bEnabledSave) {
		obj.onmousemoveSave = obj.onmousemove;
		obj.onmouseoverSave = obj.onmouseover;
		obj.onclickSave = obj.onclick;		
		obj.style.cursorSave = obj.style.cursor;
		
		obj.onmousemove = _EmptyFunction;
		obj.onmouseover = _EmptyFunction;
		obj.onclick = _EmptyFunction;
		obj.style.cursor = "default";
	} else if(bEnabled && !bEnabledSave) {
		if(obj.onmousemoveSave)	obj.onmousemove = obj.onmousemoveSave;
		if(obj.onmouseoverSave)	obj.onmouseover = obj.onmouseoverSave;
		if(obj.onclickSave)	obj.onclick = obj.onclickSave;
		if(obj.style.cursorSave) obj.style.cursor = obj.style.cursorSave;
	}
}

function IsGroupApplication(mSceneType) {
	var lSceneType=parseInt(mSceneType);
	return (lSceneType==SceneTypeGroupApplication || lSceneType==SceneTypeEmployerGroupApplication);
}

function _ValidateCaseNbr(value, save, param) {
	var i, ascvalue;
	
   if (value.length == 0) return "";
   if (value.length == 5) 
   {
   		if (value=="00000" || String(value).toUpperCase()=="NEWCS")
		{
			param.retValue = RC_INVALID;
		   	param.errMsg = "Cannot be 00000 or NewCS";
		   	return save;
		}
		else
		{
			for (i=0; i<5; i++)
			{
				ascvalue = value.substring(i,i+1).charCodeAt(0);
				if (!((ascvalue >= 48 && ascvalue <= 57) || (ascvalue >= 65 & ascvalue <= 90) || (ascvalue >= 97 & ascvalue <= 122)))
				{
					   param.retValue = RC_INVALID;
					   param.errMsg = "Invalid Format";
					   return save;   
				}
			}
		}
   } 
   else
   {
   		param.retValue = RC_INVALID;
	   	param.errMsg = "Length should be 5";
	   	return save; 	
   }
   return value;
}

// Merged with AU2 in V2.8 conversion
function getFieldName(oProp) {
    var sName = "";
    if (oProp) {
        sName = oProp.fieldType + '_' + oProp.fieldCode + '_' + oProp.level + '_';
    }
    return sName;
}

function SwitchDevUnit(bRunDesktop,sAgentUserName,sSessionGUID,sDevUnit,sClientCode,sPageName) {
	if (sDevUnit!=sClientCode){
		if (!(sPageName)) sPageName = FindObj("PageName").value;
		if (bRunDesktop) {
			FindObj('thisForm').action="/Fipsco.asp?devUnits="+ sDevUnit+ "&PageName=" + sPageName
			+ "&" +sDevUnit + "FIPSessionGUID=" + sSessionGUID + "&" + "FIP" + sDevUnit + "AgentUserName=" + sAgentUserName;
		} else {
			FindObj('thisForm').action="../"+sDevUnit+"/Fipsco.asp?PageName=" + sPageName + "&" +sDevUnit + "FIPSessionGUID=" + sSessionGUID + "&" + "FIP" + sDevUnit + "AgentUserName=" + sAgentUserName;
			var c,d;
			c=GetCookie(sClientCode + "FIPSessionGUID");
			d=GetCookie("FIP" + sClientCode + "AgentUserName");
			SetCookie(sDevUnit+"FIPSessionGUID",c,null,"/");
			DeleteCookie(sClientCode + "FIPSessionGUID");
			if (d!=null){
				SetCookie("FIP"+sDevUnit+"AgentUserName",d,null,"/");
			}
			DeleteCookie("FIP" + sClientCode + "AgentUserName");
		}
	}
}

function getCookieVal (offset) { 
var endstr = document.cookie.indexOf (";", offset); 
if (endstr == -1) 
endstr = document.cookie.length; 
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) { 
var arg = name + "="; 
var alen = arg.length; 
var clen = document.cookie.length; 
var i = 0; 
while (i < clen) { 
var j = i + alen; 
if (document.cookie.substring(i, j) == arg) 
return getCookieVal (j); 
i = document.cookie.indexOf(" ", i) + 1; 
if (i == 0) break; 
} 
return null;
}

function SetCookie (name, value) { 
var argv = SetCookie.arguments; 
var argc = SetCookie.arguments.length; 
var expires = (argc > 2) ? argv[2] : null; 
var path = (argc > 3) ? argv[3] : null; 
var domain = (argc > 4) ? argv[4] : null; 
var secure = (argc > 5) ? argv[5] : false; 
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) + 
((domain == null) ? "" : ("; domain=" + domain)) + 
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) { 
var exp = new Date(); 
exp.setTime (exp.getTime() - 1); 
// This cookie is history 
var cval = GetCookie (name); 
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()+";path=/;";

}


function ValidatePhoneNbr(value)
{
	var phonePattern1 = /[(]\d{3}[)]\d{3}[-]\d{4}/ 
	var phonePattern2 = /\d{10}/ 
	var phonePattern3 = /[(]\d{3}[)]\s\d{3}[-]\d{4}/
	if (phonePattern1.test(value) || phonePattern2.test(value) || phonePattern3.test(value) || value.length < 1) {
	   var newPhoneNum, tempPhoneNum, leng, i;
	   var value;
	   value = value;
	   if (value!=""){		        
		   leng = value.length
		   tempPhoneNum = ""
		   for( i=0; i<leng; i++){
			 if (!isNaN(parseInt(value.substr(i,1)))) { 
			 tempPhoneNum =  tempPhoneNum + value.substr(i,1) 
			 }
		   } 
		   if  (tempPhoneNum.substring(10)) {
			   newPhoneNum ="(" +tempPhoneNum.substring(0,3) + ") " +tempPhoneNum.substring(3,6) + "-" + tempPhoneNum.substring(6,10) + " ext. " + tempPhoneNum.substring(10);
			   value = newPhoneNum;				  
		   } else { 
			  newPhoneNum ="(" +tempPhoneNum.substring(0,3) + ") " +tempPhoneNum.substring(3,6) + "-" + tempPhoneNum.substring(6,10) + tempPhoneNum.substring(10);
			  value = newPhoneNum;
		   }				   
	   }
	} else {
	   alert("Please format the phone number to include the 3 digit area code and the 7 digit phone number.")
	   value = ""
	}
	return value;
}

function _ValidateZIP(value, save, param) {
    
   if (value.length == 0) return "";
   if ((value.length != 5 && value.length != 9) || isNaN(value)==true || value.indexOf(".")!=-1) {
   	   param.retValue = RC_INVALID;
	   param.errMsg = "Invalid Zip Code, please enter at least 5 numeric characters and proceed with application."; 
	   return save;
		
   } 
   return value;
}

function _ValidateRoutingNumber(value, save, param, bFormatWarning) {
	var bInvilad = false;
   	if (value.length == 0) return "";
   	if (value.length != 9) {
   		bInvilad = true;
	} else {
		var checkSum = ((parseInt(value.charAt(0))+parseInt(value.charAt(3))+parseInt(value.charAt(6)))*3+(parseInt(value.charAt(1))+parseInt(value.charAt(4))+parseInt(value.charAt(7)))*7+parseInt(value.charAt(2))+parseInt(value.charAt(5))).toString();
		if(parseInt(checkSum.charAt(checkSum.length-1))+parseInt(value.charAt(8))!=0 && parseInt(checkSum.charAt(checkSum.length-1))+parseInt(value.charAt(8))!=10) bInvilad = true;		
		if (parseInt(checkSum) == 0) bInvilad = true;
	}

   	if(bInvilad) {
   		if(bFormatWarning) {
			param.retValue = RC_INVALID; 
		    param.errMsg = "Invalid Routing Number. You must enter a valid routing number or select NO for 'Is the PAC form properly completed and signed?'"; 
			return save;
		} else {
   	   		param.retValue = RC_INVALID;
   	   		param.errMsg = "Invalid Routing Number."; 
			return save;
		}
   } 
   return value;
}

function _ValidatePolicyNumber(value, save, param) {
	//This is only a stub, client will implement its own logic.

	return value;   
}

function GetRuleIndex(oRules, lRuleCode) {
	var iRuleIdx = -1;
	for (var i = 0; i < oRules.length; i++) {
		if (oRules[i][0] == lRuleCode) {
			iRuleIdx = i;
			break;
		}
	}
	return iRuleIdx;
}

function GetRuleValue(oRules, lRuleCode) {
    var iRuleIdx;
    
    iRuleIdx = GetRuleIndex(oRules, lRuleCode);
    if (iRuleIdx != -1) {
        return oRules[iRuleIdx][1];
    }
    return null;
}

//Ajax support
AJAX_REQUEST_PARAM = "AjaxRequest";
REQUEST_GET = 1;
REQUEST_POST = 2;
REQUEST_SYNC = 1;
REQUEST_ASYNC = 2;

function AjaxAvailable() {
	return (GetXmlHttpObject() != null)
}

function GetXmlHttpObject() {
	if (window.XMLHttpRequest) {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject) {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

//AjaxRequest class - wrapper around XMLHttpRequest
function AjaxRequest() {
	this.xmlHttp = GetXmlHttpObject();
	this.url = '';
	this.params = '';
	this.setup = _AjaxRequestSetup;
	this.setResponseHandler = _AjaxRequestSetResponseHandler;
	this.send = _AjaxRequestSend;
	this.isReadyState = _AjaxResponseIsReadyState;
	this.isReadyStatus = _AjaxResponseIsReadyStatus;
	this.handleErrorStatus = _AjaxHandleErrorStatus;
}

function _AjaxRequestSetup(requestName, pageName, params, actionPage) {
	var rc = false;
	var requestParams;
	if (this.xmlHttp) {
		this.requestName = requestName;
		requestParams = "PageName=" + pageName + "&" + AJAX_REQUEST_PARAM + "=" + this.requestName + "&" + params;
		this.params = requestParams;
		this.url = "Fipsco.ASP";
		if (actionPage) {
			this.url = actionPage;
		}
		rc = true;
	}
	return rc;
}

function _AjaxRequestSetResponseHandler(responseHandler) {
	if (this.xmlHttp) {
		this.xmlHttp.onreadystatechange = responseHandler;
	}
}

function _AjaxRequestSend(requestType, flagSync) {
	if (this.url.length > 0) {
		if (requestType == REQUEST_GET) {
			this.params += "&sid=" + Math.random();
			this.xmlHttp.open("GET", this.url + "?" + this.params, (flagSync == REQUEST_ASYNC));
			this.xmlHttp.send(null);
		} else {
			this.xmlHttp.open("POST", this.url, (flagSync == REQUEST_ASYNC));
			this.xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xmlHttp.setRequestHeader("Content-length", this.params.length);
			this.xmlHttp.setRequestHeader("Connection", "close");			
			this.xmlHttp.send(this.params);
		}
	}
}

function _AjaxResponseIsReadyState() {
	return (this.xmlHttp.readyState == 4);
}

function _AjaxResponseIsReadyStatus() {
	return (this.xmlHttp.status == 200);
}

function _AjaxHandleErrorStatus() {
    if (this.xmlHttp.status == 404) {
         alert ("Requested URL is not found.");
    } else if (this.xmlHttp.status == 403) {
         alert("Access denied.");
    } else {
         alert("Request failed: status = " + this.status);
    }
}
