//<script>
/******************************************************************************
* NAME: CValidateProperty()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: This JavaScript class will handle validations for property forms. It is 
*       a sub class of CValidate.
* MODS: 
*		
******************************************************************************/
function CValidateProperty() {
	// member variables
	this.error						= false;						// Keep track of whether validation failed
	
	// member functions
	this.IsError					= IsError;						// Return whether validation failed
	this.HandleReqFieldErrors		= HandleReqFieldErrors;			// Required field rules
	this.CheckReqFields				= CheckReqFields;				// Check required fields for all pages
	this.CheckScreenerReqFields		= CheckScreenerReqFields;		// Check required fields for screener page
	this.CheckPolicyReqFields		= CheckPolicyReqFields;			// Check required fields for Policy info page
	this.CheckPolicyHolderReqFields	= CheckPolicyHolderReqFields;	// Check required fields for Policy info page
	this.CheckIncidentReqFields		= CheckIncidentReqFields;		// Check required fields for Policy info page
	this.CheckMaxLength 			= CheckMaxLength;			// Check whether the length of the field has exceeded the max length
	this.CheckBlurLength 			= CheckBlurLength;			// Check whether the length of the field has exceeded the max length
	this.CheckLength 				= CheckLength;				// Check to see if user has entered correct number of characters

}
CValidateProperty.prototype			= new CValidate();


/******************************************************************************
* NAME: CheckReqFields(objForm)
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check required fields for the specified page
* MODS: 
*		
******************************************************************************/
function CheckReqFields(objForm, strAction) {
	var error = false;

	// Check the required fields based on different forms
	switch ( objForm.name ) {
		case "frmHOBegin"		:	this.CheckScreenerReqFields(objForm);		break;
		case "frmHOPolicy"		:	this.CheckPolicyReqFields(objForm, strAction);			break;
		case "frmHONOLA"		:	this.CheckPolicyHolderReqFields(objForm);	break;
		case "frmHONOLB"		:	this.CheckIncidentReqFields(objForm);		break;

	}
	
	if ( this.Errors() != 0 ) {
		error		= true;
	} 
	
	// Manipulate the asterisk color and the message
	this.HandleReqFieldErrors(objForm);
		
	return error;
	
}

/******************************************************************************
* NAME: HandleReqFieldErrors()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Change the color of required field asterisks
* MODS: 
*		
******************************************************************************/
function HandleReqFieldErrors(objForm) {
	var oRequired = document.getElementsByName("required");
	var oRequiredTR = document.getElementsByName("requiredTR");

	// Reset the class name for the asterisk
	idRequiredMsg.className = "clsHide";
	for (var i = 0; i < oRequired.length; i++) {
		oRequired[i].className = "formCellMarginL";
		oRequiredTR[i].className = "";
	}

	// show text and red asterisk if required field is missing
	// and put a light yellow background
	if ( this.Errors() != 0 ) {
		idRequiredMsg.className = "clsShow";
		for (var i = 0; i < oRequired.length; i++) {
			for (var j = 0; j < this.Errors(); j++) {
				if ( i == parseInt(this.errorList[j]) - 1 ) {
					oRequired[i].className = "clsRequired";
					oRequiredTR[i].className = "bgRequired";
				}
			}
	
		}
		
	} 
	
	this.errorList.length = 0;

}

/******************************************************************************
* NAME: CheckScreenerReqFields()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check required fields for screener page
* MODS: 
*		
******************************************************************************/
function CheckScreenerReqFields(objForm) {
	if ( !objForm.rbHomeInjured[0].checked && !objForm.rbHomeInjured[1].checked ) {
		this.RaiseError("1");
	}
	if ( !objForm.rbHomeDamage[0].checked && !objForm.rbHomeDamage[1].checked ) {
		this.RaiseError("2");
	}
	if ( !objForm.rbHomeLiveable[0].checked && !objForm.rbHomeLiveable[1].checked ) {
		this.RaiseError("3");
	}
	if ( !objForm.rbIdTheft[0].checked && !objForm.rbIdTheft[1].checked ) {
		this.RaiseError("4");
	}
}

/******************************************************************************
* NAME: CheckPolicyReqFields()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check required fields for Policy page
* MODS: 
*		
******************************************************************************/
function CheckPolicyReqFields(objForm, strAction) {
	var strSelected = "no";
	
	if ( objForm.efLossDateMonth.value == "" ||  objForm.efLossDateDay.value == "" || objForm.efLossDateYear.value == "" ) {
		this.RaiseError("1");
	}
	if ( this.TrimAll(objForm.hdnPending.value) != "Y" ) {
		if ( objForm.efPolicyNumber.selectedIndex < 1 ) {
			this.RaiseError("2");
		}
	}

	//If region 72 host claim make sure loss and policy state ddlb are filled in.
	/*
	if (this.TrimAll(objForm.hdnPending.value) != "Y" && (objForm.efRO.value=="72" || g_oValidateProperty.IsAlliedPolicy(objForm.efAlliedMinorPfx.value))) {
		if ( objForm.efIncidentState.selectedIndex < 1 ) {
			this.RaiseError("3");
		}
		if ( objForm.efPolicyState.selectedIndex < 1 ) {
			this.RaiseError("4");
		}		
	}
	*/
	//After the policy has been verified
	//make sure that at lease one location or item or not listed check box has 
	//been selected
	//this section should only apply when user try to continue to next page
	if ( strAction != "policyinquiry" && this.TrimAll(objForm.hdnPending.value) != "Y" ) {
		var oSFTable = document.getElementsByName("lbSFTable");
		var oSITable = document.getElementsByName("lbSITable");
		for (var i = 0; i < oSFTable.length; i++) {
			if ( oSFTable[i].checked ) strSelected = "yes";
		}
		for (i = 0; i < oSITable.length; i++) {
			if ( oSITable[i].checked ) strSelected = "yes";
		}
		if ( objForm.cbxLOCNotListed != null && objForm.cbxLOCNotListed.checked )  strSelected = "yes";
		if ( objForm.cbxSINotListed != null && objForm.cbxSINotListed.checked )  strSelected = "yes";
		if ( strSelected == "no" ) {
			//if (objForm.efRO.value=="72" || g_oValidateProperty.IsAlliedPolicy(objForm.efAlliedMinorPfx.value)) {
			//	this.RaiseError("5");
			//}
			//else {
				this.RaiseError("3");
			//}	
		}
	}
	
}

/******************************************************************************
* NAME: CheckPolicyHolderReqFields()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check required fields for Policyholder page
* MODS: 
*		
******************************************************************************/
function CheckPolicyHolderReqFields(objForm) {
	if ( objForm.efFPHFirstName.value == "" || objForm.efFPHLastName.value == "" ) {
		this.RaiseError("1");
	}
	if ( objForm.efPHAddress.value == "" ) {
		this.RaiseError("2");
	}
	if ( objForm.efPHCity.value == "" ) {
		this.RaiseError("3");
	}
	if ( objForm.efPHState.value == "" ) {
		this.RaiseError("4");
	}
	if ( objForm.efPHZip.value == "" ) {
		this.RaiseError("5");
	}
	if ( objForm.efPHCounty.value == "" ) {
		this.RaiseError("6");
	}
	if ( objForm.efFPHHomePhone1.value == "" || objForm.efFPHHomePhone2.value == "" || objForm.efFPHHomePhone3.value == "" ) {
		this.RaiseError("7");
	}
	
}

/******************************************************************************
* NAME: CheckIncidentReqFields()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check required fields for Incident page
* MODS: 
*		
******************************************************************************/
function CheckIncidentReqFields(objForm) {
	if ( objForm.efLossAddress.value == "" ) {
		this.RaiseError("1");
	}
	if ( objForm.efLossCity.value == "" ) {
		this.RaiseError("2");
	}
	if ( objForm.efLossState.value == "" ) {
		this.RaiseError("3");
	}
	if ( objForm.efLossZip.value == "" ) {
		this.RaiseError("4");
	}
	if ( objForm.efLossCounty.value == "" ) {
		this.RaiseError("5");
	}
	if ( objForm.ddlbLossCause.value == "" ) {
		this.RaiseError("6");
	}
	
	// If other items is shown, then it's required
	if ( this.TrimAll(objForm.lbSITable.value) != "" ) {
		if ( !objForm.rbOtherItems[0].checked &&  !objForm.rbOtherItems[1].checked ) {
			this.RaiseError("7");
		}
		if ( !objForm.cbxDamageType1.checked && !objForm.cbxDamageType2.checked && !objForm.cbxDamageType3.checked ) {
			this.RaiseError("8");
		}
		if ( objForm.efNOLLossDesc.value == "" ) {
			this.RaiseError("9");
		}
		if ( objForm.efLossAgeCost.value == "" ) {
			this.RaiseError("10");
		}
	} else {
		if ( !objForm.cbxDamageType1.checked && !objForm.cbxDamageType2.checked && !objForm.cbxDamageType3.checked ) {
			this.RaiseError("7");
		}
		if ( objForm.efNOLLossDesc.value == "" ) {
			this.RaiseError("8");
		}
		if ( objForm.efLossAgeCost.value == "" ) {
			this.RaiseError("9");
		}
	}
	
}



/******************************************************************************
* NAME: IsError()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check if there is an error on validation
* MODS: 
*		
******************************************************************************/
function IsError() { return this.error; }

/******************************************************************************
* NAME: CheckMaxLength()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check whether the length of the field has exceeded the max length on the
*		onkeypress event
* MODS: 
*		
******************************************************************************/
function CheckMaxLength(objField, intMax){
  	if ( objField.value.length > ( intMax -1 ) ) {
	   	g_oMessage.HandleAlert(g_oMessage.WARN_ALL_MAXLENGTH);
		var s = objField.value;
	   	objField.value = s.substr(0,intMax);
		//objField.select();
	   	return false;
	}
}

/******************************************************************************
* NAME: CheckBlurLength()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check whether the length of the field has exceeded the max length on the onblur 
*		event
* MODS: 
*		
******************************************************************************/
function CheckBlurLength(objField, intMax){
  	if ( objField.value.length > ( intMax ) ) {
	   	g_oMessage.HandleAlert(g_oMessage.WARN_ALL_MAXLENGTH);
		var s = objField.value;
	   	objField.value = s.substr(0,intMax);
		//objField.select();
	   	return false;
	}
}

/******************************************************************************
* NAME: CheckLength()
* AUTH:	Li Tan
* DATE: 08/2006
*
* DESC: Check whether the length of the field has exceeded the max length
* MODS: 
*		
******************************************************************************/
function CheckLength(field, len, type){
	if (field.value == "") return(true);
	if (field.value.length < len) {
		switch(type) {
			case "phone":
				g_oMessage.HandleAlert(g_oMessage.WARN_PHONE_INVALIDNUM);
				break;
			case "zip":
				g_oMessage.HandleAlert(g_oMessage.WARN_ZIP_INVALIDNUM);
				break;
		}
		
		field.value = "";
		//field.select();
		return false;
	}
}
//</script>
