	var historyLoaded = false;
	function changeStatus(level, objectKey, newStatus) {
		if (level > 0 && level < 5) {
			executeRemotePostRequest(contextPath + '/secure/account/' + translateLevelToName(level, false) + '.do', 
				'navigator=changeStatus&requestedObjectID=' + objectKey + 
				'&changeStatusTo=' + newStatus + 
				'&nextFunction=afterChangeStatus(' + translateLevelToName(level, false) + ', false)');
		}
	}
	
	function checkModification(level, objectKey) {
		if (level > 0 && level < 5) {
			executeRemotePostRequest(contextPath + '/secure/account/' + translateLevelToName(level, false) + '.do', 
				'navigator=checkModification&requestedObjectID=' + objectKey + 
				'&nextFunction=afterChangeStatus(' + translateLevelToName(level, false) + ', true)');
		}
	}
	
	
	function afterChangeStatus(tmpObj, updateFlag) {
		if (tmpObj != null) {
			if (tmpObj.status) {
				if (tmpObj.saved != null) {
					if (updateFlag) {
						updateDataAfterSaving(tmpObj.saved);
					}
					else { 
						updateDataAfterChangedStatus(tmpObj.saved);
					}
				}
			}
			else {
				alert(tmpObj.errorMessage);
			}
		}
	}
	
	function afterSavingCommon(tmpObj, updateFunction) {
		document.getElementById("editingAreaStatus").innerHTML = '';
		$.modal.close();
		if (tmpObj.status) {
			document.getElementById("editingErrorPane").innerHTML = '';
			document.getElementById("editingErrorRow").style.display = 'none';
	
			if (tmpObj.saved != null) { 
				document.getElementById("requestedObjectID").value = tmpObj.saved.objectId;
				updateDataAfterSaving(tmpObj.saved);
			}
			eval(updateFunction);
					
			if (actionAfterSaving != null){
				eval(actionAfterSaving);
			}	
		}
		else {
			processError(tmpObj.errorMessage, tmpObj.error);
		}
		actionAfterSaving = null;
	}

	function buildSavingRequest(afterSavingFunction) {
		document.getElementById("editingAreaStatus").innerHTML = 'Requesting to save data...';
		return buildCommonRequest("save", afterSavingFunction);
	}
	
	function buildCommonRequest(requestedMethod, onCompleteFunction) {
		result = "navigator=" + requestedMethod + "&requestedObjectID=" + encodeURIComponent(document.getElementById("requestedObjectID").value);
		if (onCompleteFunction != null) {
			result += "&nextFunction=" + encodeURIComponent(onCompleteFunction) ;
		}
		return result;
	}

	function setValue(idName, value, ignored) {
		if (document.getElementById(idName) != null) {
			document.getElementById(idName).value = value;
			if (!ignored) { 
				trackDataItem(idName);
			}
		}
	}
	
	function setValueFormat(idName, value, ignored, formatType) {
		var obj = document.getElementById(idName)
	    
		if (obj != null) {
		   if (formatType) {
		    	if (formatType == 'Integer') {
		    		value = formatIntegerValue(value);
		    	}
		    	else if (formatType == 'Decimal') {
		    		value = formatDecimalValue(value);
		    	}
		    	else if (formatType == 'Decimal4') {
		    		value = formatDecimalValue2(value);
		    	}
		    }
		    
			obj.value = value;
			if (!ignored) { 
				trackDataItem(idName);
			}
		}
	}
	
	function setValueForPhoneNumber(prefix, phoneNumber) {
		setValue(prefix + ".areaCode", phoneNumber.areaCode);
		setValue(prefix + ".phoneNumber3", phoneNumber.phoneNumber3);
		setValue(prefix + ".phoneNumber4", phoneNumber.phoneNumber4);
	}

	function setValueForAccountNumber(prefix, accountNumber, disableAll) {
		tempArray = accountNumber.split("-");
		if(tempArray.length > 2 && tempArray[2].length == 2){
			tempArray[2] = '0' + tempArray[2];
		}
		if(tempArray.length > 3 && tempArray[3].length == 5){
			tempArray[3] = '0' + tempArray[3];
		}
		for (var i = 0; i < tempArray.length; i++) {
			setValue(prefix + ".accountNumber." + (i + 1), tempArray[i]);
			if (document.getElementById(prefix + ".accountNumber." + (i + 1)) != null) {
				document.getElementById(prefix + ".accountNumber." + (i + 1)).disabled = true; 
			}
		}

		if (!disableAll) {
			setFocus(prefix + ".accountNumber." + (tempArray.length + 1));
		}
		else if (document.getElementById(prefix + ".accountNumber.4") != null) {
			document.getElementById(prefix + ".accountNumber.4").disabled = true; 
		}
	}

	function buildParameter(prefix, name) {
		if (document.getElementById(prefix + '.' + name) != null) {
			return "&" + name + "=" + encodeURIComponent(document.getElementById(prefix + '.' + name).value);
		}
		return '';
	}

	function buildParameterForRadioButton(prefix, name) {
		tmp = prefix + "." + name;
		if (document.getElementById(tmp + ".yes") != null && document.getElementById(tmp + ".no") != null) {
			return "&" + name + "=" + document.getElementById(tmp + ".yes").checked ; 
		}
		return '';
	}

	function buildParameterForPhoneNumber(prefix, name) {
		return buildParameter(prefix, name + ".areaCode") +
				buildParameter(prefix, name + ".phoneNumber3") + 
				buildParameter(prefix, name + ".phoneNumber4"); 
	}

	function buildParameterForAccountNumber(prefix) {
		accountNumber = document.getElementById(prefix + '.accountNumber.1').value;		
		for (var i = 2; i < 5; i++) {
			if (document.getElementById(prefix + '.accountNumber.' + i) != null) {
				accountNumber += '-' + document.getElementById(prefix + '.accountNumber.' + i).value;
			}
		}
		return "&accountNumber=" + encodeURIComponent(accountNumber);
	}
	
	function separateZipCodes(zipCode) {
		var zipCodes = new Array('', '');

		if (zipCode.indexOf("-") > 0) {
			var tempArray = zipCode.split("-");
			zipCodes[0] = tempArray[0];
			zipCodes[1] = tempArray[1];
		}
		else {
			zipCodes[0] = zipCode;
		}
		
		return zipCodes;
	}
	
	function updateAddressForm(prefix, addressInfo) {
		setValue(prefix + ".addressLine1", addressInfo.addressLine1); 
		setValue(prefix + ".addressLine2", addressInfo.addressLine2); 
		setValue(prefix + ".city", addressInfo.city); 
		setValue(prefix + ".state", addressInfo.state);
		
		var zipCodes = separateZipCodes(addressInfo.zipCode);

		setValue(prefix + ".zipCode1", zipCodes[0]);
		setValue(prefix + ".zipCode2", zipCodes[1]);
	}
	
	function updateLocationForm(prefix, locationInfo, notForUnit) {
		updateAddressForm(prefix, locationInfo);

		setValueForAccountNumber(prefix, locationInfo.accountNumber, loggedUserRole != 1);
		setValue(prefix + ".accountName", locationInfo.accountName);
		setValueFormat(prefix + ".commonSqft", locationInfo.commonSqft, false, 'Decimal'); 
		setValueFormat(prefix + ".totalSqft", locationInfo.totalSqft, false, 'Decimal'); 
		setValueFormat(prefix + ".nbBedrooms", locationInfo.nbBedrooms, false, 'Integer'); 
		setValueFormat(prefix + ".nbOccupants", locationInfo.nbOccupants, false, 'Decimal'); 
		
		if (notForUnit) {
			setValue(prefix + ".contactName", locationInfo.contactName); 
			setValueForPhoneNumber(prefix + ".contactPhone", locationInfo.contactPhone); 
			setValue(prefix + ".billLayout", locationInfo.billLayout);

			if (loggedUserRole == 1) {
				document.getElementById("button.ImportMeterReadings").disabled = false;
			}
		}

		updateMeterReadingPanel(prefix, locationInfo);
		showHideMeterReading('currentCycle');
	}
	
	function updateMeterReadingPanel(prefix, locationInfo) {
		locationCurrentBillingCycle = locationInfo.currentCycle;
		locationCurrentReadingData  = locationInfo.currentReading;

		if (locationCurrentBillingCycle && locationCurrentBillingCycle != null) {
			forProperty = (locationInfo.portfolioId ? true : false);
			
			billingCycleInfo = locationCurrentBillingCycle.description + 
				" (" + locationCurrentBillingCycle.fromDate + " - " + locationCurrentBillingCycle.toDate + ")";
			
			if (loggedUserRole == 1) {
				document.getElementById("meterReading.currentCycle.addNew").innerHTML = '<a href="javascript:editMeterReading(\'' + prefix + '\',-1)">Add Service</a>';
				
			}
			var billingCycleName = locationCurrentBillingCycle.description.replace(/\'/g,"\\\'");

			if(loggedUserRole == 1 && prefix == 'property'){
				document.getElementById("meterReading.currentCycle.delete").innerHTML = '<a href="javascript:deleteBillingCycle(\''+ billingCycleName + '\','+ locationCurrentBillingCycle.bcKey + ',false);">Delete</a>';
			}
			
			document.getElementById("meterReading.currentCycle.caption").innerHTML = ((prefix == 'unit' || loggedUserRole != 1) ? billingCycleInfo :
			 			'<a href="javascript:updateBillingCycle(' + forProperty + ', false)">' + billingCycleInfo + "</a>");
		}
		else {
			document.getElementById("meterReading.currentCycle.caption").innerHTML = "";
		}
		
		updateDataToMeterTableAll(prefix);
		
		if (historyLoaded && document.getElementById("requestedObjectID").value > 0) {
			var parameters = buildCommonRequest("historyReadings", "showHistory("+ prefix + ",\'"+ prefix +"\')"); 
			executeRemotePostRequest(contextPath + "/secure/account/" + prefix + ".do", parameters);
		}
	}

	function buildAddressParameters(prefix, name) {
		name = (name == null ? '' : name + '.');

		//for Zipcode
		var zipCodeField = prefix + '.' + name + "zipCode";
		var zipCodeValue = document.getElementById(zipCodeField + '1').value;
		if (document.getElementById(zipCodeField + '2').value.length > 0) {
			zipCodeValue += '-' + document.getElementById(zipCodeField + '2').value;
		}
		
		return buildParameter(prefix, name + "addressLine1") + 
				buildParameter(prefix, name + "addressLine2") + 
				buildParameter(prefix, name + "city") + 
				buildParameter(prefix, name + "state") +
				"&" + name + "zipCode=" + encodeURIComponent(zipCodeValue); 
	}

	function buildLocationParameters(prefix, notForUnit) {
		return buildAddressParameters(prefix, null) +
			buildParameterForAccountNumber(prefix) + buildParameter(prefix, "accountName") + 
			buildParameter(prefix, "commonSqft") + buildParameter(prefix, "totalSqft") + buildParameter(prefix, "nbBedrooms") +
			buildParameter(prefix, "nbOccupants") +  
			(notForUnit ?
				buildParameter(prefix, "contactName") +
				buildParameterForPhoneNumber(prefix, "contactPhone") +
				buildParameter(prefix, "billLayout")
				: 
				'');  
	}

	function generateAddressTable(prefix) {
		var stateOptions = "";
		for (var x = 0; x < jsArrayState.length; x++) { 
			stateOptions += '<option value="' + jsArrayState[x][0] + '">' + jsArrayState[x][1] + '</option>';
		}
		
		var strTable = "";
		strTable += '<table border="0" cellpadding="2" cellspacing="0">';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption_left" colspan="3">Address Line 1</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td colspan="3" class="field_content"><input type="text" id="' + prefix + '.addressLine1" size="50" value=""></td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption_left" colspan="3">Address Line 2</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td colspan="3" class="field_content"><input type="text" id="' + prefix + '.addressLine2" size="50" value=""></td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption_left">City</td>';
		strTable += '		<td class="field_caption_left">State</td>';
		strTable += '		<td class="field_caption_left">Zip+4</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_content"><input type="text" id="' + prefix + '.city" size="20" value=""></td>';
		strTable += '		<td class="field_content"><select size="1" id="' + prefix + '.state">' + stateOptions + '</select></td>';
		strTable += '		<td class="field_content">';
		strTable += '			<input type="text" id="' + prefix + '.zipCode1" maxlength="5" size="5" value="" onkeyup="keyUpInPhoneField(event, this, \'' + prefix + '.zipCode2\');">-'; 
		strTable += '			<input type="text" id="' + prefix + '.zipCode2" maxlength="4" size="4" value="">';
		strTable += '		</td>';
		strTable += '	</tr>';
		strTable += '</table>';

		return strTable;
	}
	
	function generateUSPhoneFields(fieldName, nextField) {
		var tmp = '';
		
		if (nextField && nextField != null) {
			tmp = ' onkeyup="keyUpInPhoneField(event, this, \'' + nextField + '\');"';
		}
		
		return '<input type="text" id="' + fieldName + '.areaCode" size="3" maxlength="3" onkeyup="keyUpInPhoneField(event, this, \'' + fieldName + '.phoneNumber3\');">-' + 
				'<input type="text" id="' + fieldName + '.phoneNumber3" size="3" maxlength="3" onkeyup="keyUpInPhoneField(event, this, \'' + fieldName + '.phoneNumber4\');">-' +
				'<input type="text" id="' + fieldName + '.phoneNumber4" size="4" maxlength="4"' + tmp + '>';
	}
	
	var keyChangedInPhoneField = false;
	function keyUpInPhoneField(objEvent, obj, nextFieldId) {
		objEvent = (objEvent) ? objEvent : event;
		var iKeyCode = (objEvent.charCode) ? objEvent.charCode : 
						((objEvent.keyCode) ? objEvent.keyCode : 
							((objEvent.which) ? objEvent.which : 0));

		if (((iKeyCode >= 48 && iKeyCode <= 57) || (iKeyCode >= 96 && iKeyCode <= 105))
				&& obj.value.length == obj.maxLength && keyChangedInPhoneField) {
				setFocus(nextFieldId);
				keyChangedInPhoneField = false;
				return;
		}
		keyChangedInPhoneField = true;
	}

	function generateCalendarField(fieldName, func) {
		strTable = "";
		strTable += '<input size="10" id="' + fieldName + '" name="' + fieldName + '" type="text" class="date-pick"';
		if (typeof(func) != 'undefined' && func != null) {
			strTable += func;
		}
		strTable += '>';		
		return strTable;
	}
			
	
	function generateAccountNumberFields(level) {
		fieldName = translateLevelToName(level, false) + '.accountNumber';
		
		strFields = '<input type="text" class="account_field" id="' + fieldName + '.1" size="2" maxlength="2">';
		if (level > 1) {
			strFields += '-<input type="text" class="account_field" id="' + fieldName + '.2" size="4" maxlength="4">';
		}
		if (level > 2) {
			strFields += '-<input type="text" class="account_field" id="' + fieldName + '.3" size="2" maxlength="3">';
		}
		if (level > 3) {
			strFields += '-<input type="text" class="account_field" id="' + fieldName + '.4" size="' + UNIT_ACCOUNT_LENGTH + '" maxlength="' + UNIT_ACCOUNT_LENGTH + '">';
		}
		
		return strFields;
	}
	
	function newMeterReading(prefix) {
		var strTable = '';
		strTable +='<table border="0" cellspacing="0" cellpadding="0" width="100%">';
		strTable +='	<tr class="light_gray">';
		strTable +='		<td align="left">';
		strTable +='			<table border="0" cellspacing="0" cellpadding="3" width="100%">';
		strTable +='				<tr>';
		strTable +='					<td align="center" width="10"><a href="javascript:nothing();"><img src="' + nodeIconPlus + '" border="0" id="meterReading.currentCycle.cmd" onclick="javascript:showHideMeterReading(\'currentCycle\');"></a></td>';
		strTable +='					<td align="left" nowrap="nowrap">Current Billing Cycle</td>';
		strTable +='					<td align="left" id="meterReading.currentCycle.addNew" nowrap="nowrap"></td>';
		strTable +='					<td id="meterReading.currentCycle.caption" align="right" width="100%"> </td>';
		//Delete BillingCycle
		strTable +='					<td id="meterReading.currentCycle.delete" align="right" width="100%"> </td>';
		strTable +='				</tr>';
		strTable +='			</table>';
		strTable +='		</td>';
		strTable +='	</tr>';

		strTable +='	<tr id="meterReading.currentCycle" style="display:none">';
		strTable +='		<td>';
		strTable +='			<table border="0" cellspacing="1" cellpadding="3" width="100%" id="meterReading.currentCycle.table">';
		strTable +='				<thead>';
		strTable +='					<tr class="table_header">';
		strTable +='						<th>Service</th>';
		strTable +='						<th>Calc Type</th>';
		strTable +='						<th>Current Reading</th>';
		strTable +='						<th>Previous Reading</th>';
		strTable +='						<th>Usage</th>';
		strTable +='						<th>TOM</th>';
		strTable +='						<th>Billing Period</th>';
		strTable +='						<th>Rate</th>';
		strTable +='						<th>Amount</th>';
		if (prefix == 'unit') {
			strTable +='						<th>Prorated Amount</th>';
		}
		strTable +='					</tr>';
		strTable +='				</thead>';
		strTable +='				<tbody></tbody>';
		strTable +='			</table>';
		strTable +='		</td>';
		strTable +='	<tr>';

		strTable +='	<tr height="5"/>';

		strTable +='	<tr class="light_gray">';
		strTable +='		<td align="left">';
		strTable +='			<table border="0" cellspacing="0" cellpadding="3" width="100%">';
		strTable +='				<tr>';
		strTable +='					<td align="center" width="10"><a href="javascript:nothing();"><img src="' + nodeIconPlus + '" border="0" id="meterReading.previousCycles.cmd" onclick="javascript:showHideMeterReading(\'previousCycles\', \'' + prefix + '\');"></a></td>';
		strTable +='					<td align="left" width="100%">Previous Billing Cycles</td>';
		strTable +='				</tr>';
		strTable +='			</table>';
		strTable +='		</td>';
		strTable +='	</tr>';

		strTable +='	<tr id="meterReading.previousCycles" style="display:none">';
		strTable +='		<td id="meterReading.previousCycles.data">...</td>';
		strTable +='	</tr>';
		strTable +='</table>';
		
		historyLoaded = false;
		return strTable;
	}	

	function makeASimpleImportForm(objectKey, dialogCation, objectName, actionName, afterImportFunc) {
		if (afterImportFunc == null) {
			afterImportFunc = 'afterSimpleImportDone(' + objectName + ')';
		}
	
		var strTable = '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
		strTable += '	<tr class="panel_header">';
		strTable += '		<td align="left">' + dialogCation + '</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td align="left">';

		strTable += '			<form id="simpleImportForm" action="' + contextPath + '/secure/account/' + objectName+ '.do" enctype="multipart/form-data" method="post" onsubmit="return false;">';
		strTable += '			<input type="hidden" name="requestedObjectID" value="' + objectKey + '">';
		strTable += '			<input type="hidden" name="navigator" value="' + actionName + '">';
		strTable += '			<input type="hidden" name="nextFunction" value="' + afterImportFunc + '">';
		strTable += '			<table border="0" cellpadding="5" cellspacing="0" width="100%">';
		strTable += '				<tr>';
		strTable += '					<td class="field_caption" align="right" nowrap>File Name</td>';
		strTable += '					<td class="field_content"><input name="importFile" size="38" value="" type="file" id="data.import"></td>';
		strTable += '				</tr>';
		strTable += '				<tr height="10"/>';
		strTable += '				<tr>';
		strTable += '					<td class="field_caption_left"> </td>';
		strTable += '					<td class="field_caption_left">';
		strTable += '						<input type="button" value="Upload" class="button" onclick="javascript:uploadASimpleImport();">';
		strTable += '						<input type="button" value="Cancel" class="button" onclick="javascript:closePopupDialog();">';
		strTable += '					</td>';
		strTable += '				</tr>';
		strTable += '			</table>';
		strTable += '			</form>';
		
		strTable += '		</td>';
		strTable += '	</tr>';
		strTable += '	<tr><td class="summit_errors" id="simpleImportForm.status"> </td></tr>';
		strTable += '</table>';
		
		if (showDialogPopupWidthContent(strTable, 400, 200)) {
			setFocus("data.import");
		}
	} 
	
	function makeCASSImportStatusDialog(propertyId) {	
		var afterImportFunc = 'afterSimpleImportDone(property)';
		var strTable = '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
		strTable += '	<tr class="panel_header">';
		strTable += '		<td align="left"> CASS Import Message</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td align="left">';

		strTable += '			<form id="updateImportStatusForm" action="' + contextPath + '/secure/account/property.do" method="post" onsubmit="return false;">';
		strTable += '				<input type="hidden" name="nextFunction" value="' + afterImportFunc + '">';
		strTable += '				<input type="hidden" name="requestedObjectID" value="' + propertyId + '">';
		strTable += '				<input type="hidden" name="navigator" value="updateImportStatus">';
		strTable += '				<table width="99%" cellspacing="0" cellpadding="0">';
		strTable += '					<tr class="field_caption_left">';
		strTable += '						<td><div id="importCASSStatusDiv"></div></td>';		
		strTable += '					</tr>';
		strTable += '					<tr height="10"/>';
		strTable += '					<tr>';
		strTable += '						<td align="center" >' ;
		strTable += '							<input class="button" type = "button" value="Submit" onclick="javascript:fxnFileSubmitter(\'updateImportStatusForm\');">';
		strTable += '							<input type="button" value="Cancel" class="button" onclick="javascript:closePopupDialog();">';
		strTable += '						</td>';
		strTable += '					</tr>';
		strTable += '				</table>';
		strTable += '			</form>';

		strTable += '		</td>';
		strTable += '	</tr>';
		strTable += '	<tr><td class="summit_errors" id="simpleImportForm.status"> </td></tr>';
		strTable += '</table>';

		document.getElementById("TB_ajaxContent").innerHTML = strTable;
		showDialogPopup("div_dialog", 800, 450);		
	}
	
	function buildImportCASSStatusTable(tableData, msg) {
		var elementDiv = document.getElementById("importCASSStatusDiv");
		elementDiv.innerHTML = "";
		var strTable = "";
		
		strTable += '<table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#eeeeee">';		
		strTable += '	<tr class="table_header">';
		strTable += '		<td align="center">Account #</td>';
		strTable += '		<td align="center">Message </td>';
		strTable += '		<td align="center">Confirmation</td>';
		strTable += '	</tr>';	
		for (var i = 0; i < tableData.length; i++) {
			strTable += '	<tr bgcolor="#ffffff">';
			strTable += '		<td>' + tableData[i]["PIDN"] + '</td>';
			strTable += '		<td>' + tableData[i]["message"] + '</td>';
			strTable += '		<td>';
			if (tableData[i]["confirmable"]) {
				strTable += '		<input type="radio" name="checkChange' + i + '" value="' + tableData[i]["PIDN"] + '"/> Yes&nbsp;&nbsp;<input type="radio" name="checkChange' + i + '" value="0"/> No';
			}
			strTable += '		&nbsp;</td>';
			strTable += '	</tr>';	
		}
		strTable += '</table>' + msg;
		elementDiv.innerHTML = strTable;
	}
	
	function uploadASimpleImport() {
		if (document.getElementById("data.import").value == ""){
			document.getElementById("simpleImportForm.status").innerHTML = 'Please choose file to import!';
		}
		else {
			var supportedFileTypes = new Array('CSV', 'TXT', 'XML', 'TAB', 'XLS');
			var fileName = document.getElementById("data.import").value.toUpperCase();

			for (var i = 0; i < supportedFileTypes.length; i++) {
				if (fileName.lastIndexOf("." + supportedFileTypes[i]) > 0) {
					document.getElementById("simpleImportForm.status").innerHTML = 'Uploading...';
					fxnFileSubmitter('simpleImportForm');
					return;
				}
			}

			document.getElementById("simpleImportForm.status").innerHTML = 'File type is not correct.';
			document.getElementById("data.import").value = "";
		}
	}
	
	function afterSimpleImportDone(result) {
		if (result.changedAddressesArr && result.changedAddressesArr != null) {
			for (var i = 0; i< result.changedAddressesArr.length; i++) {
				var unit = rootNode.searchByAccountNumber(result.changedAddressesArr[i]["accountNumber"]);
				if (unit != null) {
					unit.setAddress(result.changedAddressesArr[i]["address"]);
				}
			}
		}
		
		if (result.status) {
			document.getElementById("simpleImportForm.status").innerHTML = 'Import successfully. Reloading data...';
			closePopupDialog();
			
			if (typeof(result.info) != 'undefined' && result.info != null) {
				updateMeterReadingPanel(result.prefix, result.info);
			}
			
			if (result.errorMessage && result.errorMessage != "") {
				alert(result.errorMessage);
			}
		} 
		else if (result.statusList != null){
			makeCASSImportStatusDialog(result.propertyId);
			buildImportCASSStatusTable(result.statusList, result.errorMessage);
		}
		else {
			processError(result.errorMessage, result.error, "simpleImportForm.status");
		}
	}
	
	function showHideMeterReading(sessionName, prefix) {
		var imgObj = document.getElementById("meterReading." + sessionName + ".cmd");

		if (imgObj != null) {
			if (imgObj.src.indexOf(nodeIconMinus) > -1) {
				imgObj.src = nodeIconPlus;
				document.getElementById("meterReading." + sessionName).style.display = 'none';
			}
			else if (imgObj.src.indexOf(nodeIconPlus) > -1) {
				imgObj.src = nodeIconMinus;
				document.getElementById("meterReading." + sessionName).style.display = '';
			}
		}
		
		if ('previousCycles' == sessionName && !historyLoaded && document.getElementById("requestedObjectID").value > 0) {
			imgObj.src = loadingIcon;
			historyLoaded = true;
			var parameters = buildCommonRequest("historyReadings", "showHistory("+ prefix + ",\'"+ prefix +"\')"); 
			executeRemotePostRequest(contextPath + "/secure/account/" + prefix + ".do", parameters);
		}
	}
	
	function showHistory(location,prefix) {
		document.getElementById("meterReading.previousCycles.cmd").src = nodeIconMinus;;
		
		if (!location.status) {
			document.getElementById("meterReading.previousCycles.data").innerHTML = location.errorMessage;
			return;
		}
		var strTable = ""; 		
		
		strTable +='<table border="0" cellspacing="1" cellpadding="3" width="100%" id="meterReading.previousCycles.table">';
		strTable +='	<thead><tr class="table_header">';
		strTable +='		<th>Service</th>';
		strTable +='		<th>Calc Type</th>';
		strTable +='		<th>Current Reading</th>';
		strTable +='		<th>Previous Reading</th>';
		strTable +='		<th>Usage</th>';
		strTable +='		<th>TOM</th>';
		strTable +='		<th>Billing Period</th>';
		strTable +='		<th>Rate</th>';
		strTable +='		<th>Amount</th>';
		if (location.isUnit) {
			strTable +='		<th>Prorated Amount</th>';
		}
		strTable +='	</tr></thead><tbody>';
		
		for (var i = 0; i < location.history.length; i++) {
			strTable += '<tr class="light_gray" height="25" valign="bottom"><td colspan="10" align="left"><strong>' + location.history[i].name + '</strong>';
			if(loggedUserRole == 1 && prefix == 'property'){
				strTable += ' <a href="javascript:deleteBillingCycle(\''+ location.history[i].bcName + '\','+ location.history[i].bcId + ',false);">Delete</a></td></tr>';
			}else{
				strTable += '</td></tr>';
			}
			for (var j = 0; j < location.history[i].details.length; j++) {
				strTable += '<tr class="' + (j % 2 == 0 ? 'odd' : 'even') + '">';
				strTable += '<td align="left">' + location.history[i].details[j].serviceName + '</td>';
				strTable += '<td align="left">' + location.history[i].details[j].formulaName + '</td>';
				strTable += '<td align="right">' + formatDecimalValue(location.history[i].details[j].currentReading) + '</td>';
				strTable += '<td align="right">' + formatDecimalValue(location.history[i].details[j].previousReading) + '</td>';
				var usage = location.history[i].details[j].usage;
				if (typeof(usage) == 'undefined' || usage == null || usage == '') {
					usage = location.history[i].details[j].calculatedUsage;
				}
				strTable += '<td align="right">' + formatDecimalValue(usage) + '</td>';
				strTable += '<td align="left">' + location.history[i].details[j].tom + '</td>';
				strTable += '<td align="center">' + location.history[i].details[j].billingFrom + '-' + location.history[i].details[j].billingTo + '</td>';
				strTable += '<td align="right">' + formatDecimalValue2(location.history[i].details[j].rate) + '</td>';
				var amount = location.history[i].details[j].alteredAmount;
				if (typeof(amount) == 'undefined' || amount == null || amount == '') {
					amount = location.history[i].details[j].amount;
				}
				strTable += '<td align="right">' + formatDecimalValue(amount) + '</td>';
				if (location.isUnit) {
					strTable += '<td align="right">' + formatDecimalValue(location.history[i].details[j].proratedAmount) + '</td>';
				}
				strTable += '</tr>';
			}
		}
		
		strTable +='	</tbody></table></td><tr>';
		document.getElementById("meterReading.previousCycles.data").innerHTML = strTable;
	}
	
	function fxnFileSubmitter(formName, loggedIn) {
		if (!loggedIn) {
			var tempFlags = "navigator=checkLogin&nextFunction=" + encodeURIComponent("fxnFileSubmitter('" + formName + "', true)");
			executeRemotePostRequest(contextPath + '/login.do', tempFlags);
			return;
		}
		
		if (!login.status) {
			alert(login.errorMessage + '\nPlease re-login and try again!');
			if (typeof(system_current_page) != 'undefined') {
				document.location = system_current_page;
			}
			return;
		}
		
		var tempForm = document.getElementById(formName);
		var tempName = 'randomForm' + Math.floor(Math.random() * 99999);  
		var tempDiv = document.createElement('div');  
	
		tempDiv.innerHTML = '<iframe style="display:none" src="about:blank" id="' + tempName + 
			'" name="' + tempName+'" onload="ajaxFrameOnLoad(\'' + tempName + '\');"></iframe>';  
		document.body.appendChild(tempDiv);  
		tempForm.setAttribute('target', tempName);
		
		tempForm.submit();
	}
	
	function ajaxFrameOnLoad(id) {
		var i = document.getElementById(id);
		if (i.contentDocument) {
			var d = i.contentDocument;
		} 
		else if (i.contentWindow) {
			var d = i.contentWindow.document;
		} 
		else {
			var d = window.frames[id].document;
		}
        
		if (d.location.href == "about:blank") {
			return;
		}
		
		try {
			eval(d.body.innerHTML);
			//removeElementIfExists(id);
		}
		catch (e) {
			alert("Your session might expire. Please try to check again!");
			if (typeof(system_current_page) != 'undefined') {
				document.location = system_current_page;
			}
		}
    }
		
	function makeMeterReadingImportForm(objectKey, dialogCation, objectName, actionName, afterImportFunc) {
		if (afterImportFunc == null) {
			afterImportFunc = 'afterSimpleImportDone(' + objectName + ')';
		}

		var strTable = '<table border="0" cellpadding="0" cellspacing="0" width="100%">';
		strTable += '	<tr class="panel_header">';
		strTable += '		<td align="left">&nbsp;' + dialogCation + '</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td align="left">';

		strTable += '			<form id="simpleImportForm" action="' + contextPath + '/secure/account/' + objectName+ '.do" enctype="multipart/form-data" method="post" onsubmit="return false;">';
		strTable += '			<input type="hidden" name="requestedObjectID" value="' + objectKey + '">';
		strTable += '			<input type="hidden" name="navigator" value="' + actionName + '">';
		strTable += '			<input type="hidden" name="nextFunction" value="' + afterImportFunc + '">';
		strTable += '			<input type="hidden" name="serviceIdHidden" value="">';
		strTable += '			<input type="hidden" name="isStartNewBillingCycle" value="">';		
		strTable += '			<table border="0" cellpadding="3" cellspacing="0" width="100%">';
		strTable += '				<tr>';
		strTable += '					<td class="field_caption" align="right">File Name</td>';
		strTable += '					<td class="field_content"><input name="importFile" size="37" value="" type="file" id="data.import"></td>';
		strTable += '				</tr>';
		strTable += '				<tr>';
		strTable += '					<td class="field_caption" align="right">Service</td>';
		strTable += '					<td class="field_content"><select name="importServiceId" id="selectServiceId"></select></td>';
		strTable += '				</tr>';
		//strTable += '				<tr>';
		//strTable += '					<td class="field_caption" align="right">&nbsp;</td>';
		//strTable += '					<td class="field_content"><input name="newBillingCycle" value="0" type="checkbox" onclick="javascript:isNewBillingCycleCheck(this);">  Start a new billing cycle?</td>';
		//strTable += '				</tr>';
		strTable += '				<tr>';
		strTable += '					<td colspan="2" align="center">';
		strTable += '						<div id="importNewBillingCycleId"></div>';
		strTable += '					</td>';		
		strTable += '				</tr>';		
		strTable += '				<tr><td class="field_caption_left"> </td>';
		strTable += '					<td class="field_caption_left">';
		strTable += '						<input type="button" value="Upload" class="button" onclick="javascript:uploadASimpleImport();">';
		strTable += '						<input type="button" value="Cancel" class="button" onclick="javascript:closePopupDialog();">';
		strTable += '					</td>';
		strTable += '				</tr>';
		strTable += '			</table>';
		strTable += '		</form>';
		
		strTable += '		</td>';
		strTable += '	</tr>';
		strTable += '	<tr height="10"/>';
		strTable += '	<tr><td class="summit_errors" id="simpleImportForm.status"> </td></tr>';
		strTable += '</table>';
	
		
		if (showDialogPopupWidthContent(strTable, 400, 220)) { 
			setFocus("data.import");
			setupComboBox("selectServiceId", globalServiceList, "", true);
		}			
	} 
	
	function isNewBillingCycleCheck(obj) {
		if (obj.checked) {
			if (locationCurrentBillingCycle != null && locationCurrentBillingCycle.errorMessage != '') {
				alert(locationCurrentBillingCycle.errorMessage);
				obj.checked = false;
				obj.value="0";
				return;
			}

			document.getElementById("importNewBillingCycleId").innerHTML = getNewBillingCycleForm();
			$(function()
		            {            	
		            	Date.format='mm/dd/yyyy';
		            	initDatePicker() ;
		    });
			obj.value="1";
		}
		else{
			document.getElementById("importNewBillingCycleId").innerHTML = "";
			obj.value="0";
		}
	}
		
	function getNewBillingCycleForm() {
		var strTable = '';
		strTable = '<table border="0" cellspacing="0" cellpadding="0" width="100%%">';
		strTable += '	<tr class="panel_header">';
		strTable += '		<td align="left">&nbsp;New Billing Cycle</td>';
		strTable += '	</tr>';
		strTable += '<tr><td align="center" bgcolor="#cccccc"><table border="0" width="100%" cellspacing="1" cellpadding="1">';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption">From Date</td>';
		strTable += '		<td class="field_content">' + generateCalendarField('currentCycle.fromDate') + '</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption">To Date</td>';
		strTable += '		<td class="field_content">' + generateCalendarField('currentCycle.toDate') + '</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption">Due by Date</td>';
		strTable += '		<td class="field_content">' + generateCalendarField('currentCycle.dueByDate') + '</td>';
		strTable += '	</tr>';
		strTable += '	<tr>';
		strTable += '		<td class="field_caption">Description</td>';
		strTable += '		<td class="field_content"><input type="text" size="30" value="" name="currentCycle.description"></td>';
		strTable += '	</tr></table>';		
		strTable += '	<tr><td class="summit_errors" id="newBillingCycle.status" bgcolor="#ffffff"> </td></tr>';
		strTable += '</td></tr></table>';
		return strTable; 
	} 
	
	function processError(msg, errors, shownInId) {
		textError = "";
		if (msg == "MULTI_ERRORS") {
			textError = '<div class="summit_errors"><dl style="margin: 5px;"><dt><strong>Please correct the following error(s):</strong></dt><dd>';
			
			for (i = 0; i < errors.length; i++) {
				textError += '<li style="padding-top: 3px;">' + errors[i] + '</li>';
			}

			textError += '</dd></dl></div>';
		}
		else {
			textError = '<div class="summit_errors"><dl style="margin: 5px;"><dt><strong>' + msg + '</strong></dt></dl></div>';
		}
		if (shownInId == null) {
			document.getElementById("editingErrorPane").innerHTML = textError;
			document.getElementById("editingErrorRow").style.display = '';
			document.location = '#top';
		}
		else {
			document.getElementById(shownInId).innerHTML = textError;
		}
	}
	

	function setChangedDataField(fieldName, oldValue, multiUses) {
		var element = document.getElementById(fieldName);
		
		if (element != null) {
			var tooltiptext = '';
			var diffirent = false;
			
			if (element.type == 'checkbox') {
				diffirent = (element.checked != oldValue);
				tooltiptext = (oldValue ? 'Checked' : 'Not checked');
			}
			else {
				//if (!isNaN(oldValue)) {
				//	oldValue = (element.value.indexOf('.') > 0 ? formatDecimalValue(oldValue) : formatIntegerValue(oldValue));
				//}
				diffirent = (oldValue != element.value);
				tooltiptext = oldValue;
			}

			if (diffirent) {
				element.style.background = '#FFFFCC';
				if (tooltiptext == '') {
					tooltiptext = "[empty]";
				}
				element.title = tooltiptext;
			}
			else if (multiUses) {
				element.style.background = '#FFFFFF';
				element.title = '';
			}
		}
	}
	
	function setChangedDataFieldForPhoneNumber(prefix, phoneNumber, multiUses) {
		setChangedDataField(prefix + ".areaCode", phoneNumber.areaCode, multiUses);
		setChangedDataField(prefix + ".phoneNumber3", phoneNumber.phoneNumber3, multiUses);
		setChangedDataField(prefix + ".phoneNumber4", phoneNumber.phoneNumber4, multiUses);
	}
	
	function setChangedDataFieldForAddressForm(prefix, addressInfo, multiUses) {
		setChangedDataField(prefix + ".addressLine1", addressInfo.addressLine1, multiUses); 
		setChangedDataField(prefix + ".addressLine2", addressInfo.addressLine2, multiUses); 
		setChangedDataField(prefix + ".city", addressInfo.city, multiUses); 
		setChangedDataField(prefix + ".state", addressInfo.state, multiUses);
		
		var zipCodes = separateZipCodes(addressInfo.zipCode);
		 
		setChangedDataField(prefix + ".zipCode1", zipCodes[0], multiUses);
		setChangedDataField(prefix + ".zipCode2", zipCodes[1], multiUses);
	}
	
	function setChangedDataFieldForLocationForm(prefix, locationInfo, notForUnit) {
		setChangedDataFieldForAddressForm(prefix, locationInfo);

		setChangedDataFieldForAccountNumber(prefix, locationInfo.accountNumber);
		setChangedDataField(prefix + ".accountName", locationInfo.accountName); 
		setChangedDataField(prefix + ".commonSqft", formatDecimalValue(locationInfo.commonSqft)); 
		setChangedDataField(prefix + ".totalSqft", formatDecimalValue(locationInfo.totalSqft)); 
		setChangedDataField(prefix + ".nbBedrooms", formatIntegerValue(locationInfo.nbBedrooms)); 
		setChangedDataField(prefix + ".nbOccupants", formatDecimalValue(locationInfo.nbOccupants)); 
		
		if (notForUnit) {
			setChangedDataField(prefix + ".contactName", locationInfo.contactName); 
			setChangedDataFieldForPhoneNumber(prefix + ".contactPhone", locationInfo.contactPhone); 
			setChangedDataField(prefix + ".billLayout", locationInfo.billLayout);
		}
	}
	
	function setChangedDataFieldForAccountNumber(prefix, accountNumber, disableAll) {
		tempArray = accountNumber.split("-");
		for (var i = 0; i < tempArray.length; i++) {
			setChangedDataField(prefix + ".accountNumber." + (i + 1), tempArray[i]);
		}
	}
	
	function buildHeaderSession(level) { 
		var prefix = translateLevelToName(level, false)
		var tempString = '';

		tempString += '	<tr class="panel_header" valign="middle">';
		tempString += '		<td align="left" nowrap="nowrap" colspan="2">';
		tempString += '			<table border="0" width="100%" cellspacing="0" cellpadding="0">';
		tempString += '				<tr>';
		tempString += '					<td align="left" nowrap="nowrap">' + translateLevelToName(level, true) + ' Information</td>';
		tempString += '					<td align="right" nowrap="nowrap" id="navigatorId">&nbsp;</td>';
		tempString += '				</tr>';
		tempString += '			</table>';
		tempString += '		</td>';
		tempString += '	</tr>';

		tempString += '	<tr id="changedInformation_tr" style="display:none;background:#FFFFEE;">';
		tempString += '		<td align="left" nowrap="nowrap" colspan="2">';
		tempString += '			<table border="0" width="100%" cellspacing="0" cellpadding="0">';
		tempString += '				<tr>';
		tempString += '					<td align="left" height="15px" id="changedInformation" style="color:green; font-size: 11px;"></td>';		
		tempString += '					<td align="right"><div id="changedInformationButtons">';
		tempString += '						<input type="button" class="button" value="Deny Changes" onclick="javascript:denyChanges(\'' + prefix + '\');" style="width:125px;">';
		tempString += '						<input type="button" class="button" value="Approve Changes" onclick="javascript:approveChanges(\'' + prefix + '\');" style="width:125px;">';
		tempString += '					</div></td>';
		tempString += '				</tr>';
		tempString += '			</table>';
		tempString += '		</td>';
		tempString += '	</tr>';

		return tempString;
	}
	
	function showChangedInformationSession(strInfo) {
		if (loggedUserRole != 1) {
			removeElementIfExists("changedInformationButtons");
		}
		document.getElementById("changedInformation").innerHTML = strInfo;
		document.getElementById("changedInformation_tr").style.display = "";
	}
	
	function buildUtilitySession(prefix) {
		var tmpStr = '';
		tmpStr +='<tr class="panel_header" valign="middle">';
		tmpStr +='	<td align="left">Utility Information&nbsp;&nbsp;';
		
		if (prefix == 'building' || prefix == 'property') {
			tmpStr += '<input type="button" style="width:165px;" id="button.ImportMeterReadings" class="button" value="Import Meter Readings" onclick ="javascript:importMeterReading(' + (prefix == 'property') + ');" disabled>';
			if (prefix == 'property') {
				tmpStr += '<input type="button" style="width:165px;" id="button.StartNewBillingCycle" class="button" value="Start new billing cycle" onclick="updateBillingCycle(true, true);" disabled>';
			}
		}
		
		tmpStr +='	</td>';
		tmpStr +='	<td align="right">';
		tmpStr +='		<input type="button" onclick="javascript:requestCalculation(\'' + prefix + '\');" value="Calculate" class="button" id="button.calculate"; disabled>';
		tmpStr +='	</td>';
		tmpStr +='</tr>';
		tmpStr +='<tr><td colspan="2">' + newMeterReading(prefix) + '</td></tr>';
		
		return tmpStr;
	}
	
	function requestCalculation(prefix) {
		document.getElementById("editingAreaStatus").innerHTML = 'Requesting to calculate. Please wait...';
		var parameters = buildCommonRequest("calculate", "afterSavingCommon(" + prefix + ", 'update" + prefix.charAt(0).toUpperCase() + prefix.substr(1) + "Form()')"); 
		executeRemotePostRequest(contextPath + "/secure/account/" + prefix + ".do", parameters);
		displayProgress("progressBarMainDiv");
		//setTimeout("executeRemotePostRequest('" + contextPath + "/secure/account/" + prefix + ".do', 'navigator=checkProgress&nextFunction=checkActionRunning(\"progressBarMainDiv\", true, \"/secure/account/" + prefix + ".do\", \"\");')", 200);
	}
	
	function denyChanges(prefix) {
		if (confirm('Are you sure you want to deny changes?')) {
			var parameters = buildCommonRequest("denyChanges", "afterSavingCommon(" + prefix + ", 'update" + prefix.charAt(0).toUpperCase() + prefix.substr(1) + "Form()')"); 
			executeRemotePostRequest(contextPath + "/secure/account/" + prefix + ".do", parameters);
		}
	}

	function approveChanges(prefix) {
		var parameters = buildCommonRequest("approveChanges", "afterSavingCommon(" + prefix + ", 'update" + prefix.charAt(0).toUpperCase() + prefix.substr(1) + "Form()')"); 
		executeRemotePostRequest(contextPath + "/secure/account/" + prefix + ".do", parameters);
	}