<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
global $defaultHomeLink;
render('_header');
 ?>
<div data-role="page">
	<?php
	if ($_SESSION['fsizex'] >= 30) {
		echo '<style> body { font-size: ' . $_SESSION['fsizex'] . '%;}';
	} else {
		echo '<style> body { font-size: 80.5%;}';
	}
 ?>
	.ui-combobox {
	position: relative;
	display: inline-block;
	}
	.ui-combobox-toggle {
	position: absolute;
	top: 0;
	bottom: 0;
	margin-left: -1px;
	padding: 0;
	}
	.ui-combobox-input {
	margin: 0;
	padding: 0.3em;
	}
	</style>
	<script>
		(function($) {
			$.widget("ui.combobox", {
				_create : function() {
					var input, self = this, select = this.element.hide(), selected = select.children(":selected"), value = selected.val() ? selected.text() : "", wrapper = this.wrapper = $("<span>").addClass("ui-combobox").insertAfter(select);
					input = $("<input>").appendTo(wrapper).val(value).addClass("ui-state-default ui-combobox-input").autocomplete({
						delay : 0,
						minLength : 0,
						source : function(request, response) {
							var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
							response(select.children("option").map(function() {
								var text = $(this).text();
								if (this.value && (!request.term || matcher.test(text) ))
									return {
										label : text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1"),
										value : text,
										option : this
									};
							}));
						},
						select : function(event, ui) {
							ui.item.option.selected = true;
							self._trigger("selected", event, {
								item : ui.item.option
							});
						},
						change : function(event, ui) {
							if (!ui.item) {
								var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"), valid = false;
								select.children("option").each(function() {
									if ($(this).text().match(matcher)) {
										this.selected = valid = true;
										return false;
									}
								});
								if (!valid) {
									// remove invalid value, as it didn't match anything
									$(this).val("");
									select.val("");
									input.data("autocomplete").term = "";
									return false;
								}
							}
						}
					}).addClass("ui-widget ui-widget-content ui-corner-left");
					input.data("autocomplete")._renderItem = function(ul, item) {
						return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>").appendTo(ul);
					};
					$("<a>").attr("tabIndex", -1).attr("title", "Show All Items").appendTo(wrapper).button({
						icons : {
							primary : "ui-icon-triangle-1-s"
						},
						text : false
					}).removeClass("ui-corner-all").addClass("ui-corner-right ui-combobox-toggle").click(function() {
						// close if already visible
						if (input.autocomplete("widget").is(":visible")) {
							input.autocomplete("close");
							return;
						}
						// work around a bug (likely same cause as #5265)
						$(this).blur();
						// pass empty string as value to search for, displaying all results
						input.autocomplete("search", "");
						input.focus();
					});
				},
				destroy : function() {
					this.wrapper.remove();
					this.element.show();
					$.Widget.prototype.destroy.call(this);
				}
			});
		})(jQuery);

		$(function() {
			$("#combobox").combobox();
			$("#toggle").click(function() {
				$("#combobox").toggle();
			});
		});
		$(function() {
			$("#combobox1").combobox();
			$("#toggle").click(function() {
				$("#combobox1").toggle();
			});
		});
	</script>
	<script language="javascript">
		function toggle() {
			var ele = document.getElementById("selector");
			if (ele.style.display == "block") {
				ele.style.display = "none";
			} else {
				ele.style.display = "block";
			}
		}
	</script>
	<div name="mainx" data-role="header" data-theme="a">
		<table width="90%">
			<tr>
				<td><a href="<?php echo $defaultHomeLink; ?> " target="_blank" Title="WtrFlw Services Online Services Hub Site"><img src="assets/img/wtrflwlogo.png" alt="WtrFlw Services LLC" height="70" width="130"/></a></td>
				<td width="80%"><h1><?php echo $title ?></h1></td>
				<td>
					<INPUT TYPE="button" onClick="parent.location='logout.php'" value="Logout">
					<INPUT TYPE="button" onClick="parent.location='includes/help/Help.pdf'" value="Help">
				</td>
			</tr>
		</table>
	</div>
	<div id="tabs">
		<ul>
			<li><a title="View or edit your customer's information" href="#tabs-1">Home</a></li>
			<li><a href="#tabs-2">Reports</a></li>
			<li><a title="Work on meter reading information" href="#tabs-3">Readings</a>	</li>
			<li><a title="View or edit your most general settings" href="#tabs-4">Settings</a></li>
		</ul>
		<div id="tabs-1">
			<div id="selector" style="display: block">
				<table>
					<tr>
						<td></td>
						<td width="60">
							<div class="ui-widget">
								<label for="combobox">Account: </label>
							</div>
						</td>
						<td>
							<select title="Select a customer to view or edit their information and/or make payments." class="combobox" id="combobox" name="combobox" width="300">
								<option value="">Select one...</option>
								<?php render($content) ?>
							</select>
						</td>
						<td><button title="Return to the Customer Information screen." type="button" value="GoAccount" onClick=location.reload()>Clear Search
							</button>
						</td>
					</tr>
				</table>
				<table>
					<tr>
						<td>
							<button title="View the Customer Information screen for currently selected customer" type="button" value="GoAccount" onClick="dynamic_Selectz('includes/acinfo.php', '#accinfo','cust', '#combobox', 'x')">
								Show Account
							</button>
						</td>
						<td>
							<button title="Click to show list for current account" type="button" value="GoAccount" onClick="dynamic_Selectz('includes/docinfo.php', '#accinfo','cust', '#combobox', 'x')">
								Document List
							</button>
						</td>
						<td>
							<button type="submit" title="Account balance audit information." value="Account Audit" onClick="dynamic_Selectz('includes/acinfo.php', '#accinfo','payment', '#combobox', 'x')">
								Audit Account
							</button>
						</td>
						<td>
							<button title="Add a new customer account" type="button" value="Add Account" onClick="javascript:toggle();dynamic_Select('includes/ncinfo.php', '#accinfo','cust', '0', 'z');">
								Add Account
							</button>
						</td>
					</tr>
				</table>				
	       </div>            
               <div id="accinfo">
               </div>            
        	</div>			
		<div id="tabs-2">
			<table><tr><td><div id="selector1" class="ui-widget">
				<label for="combobox1">Account: </label>
				<select title="Select a customer to view or edit their information and/or make payments." class="combobox1" id="combobox1" name="combobox1">
					<option value="">Select one...</option>
					<?php render($content) ?>
				</select>
			</div></td><td><button title="Return to the Customer Information screen." type="button" value="GoAccount" onClick=location.reload()>Clear Search
							</button></td></tr>
							</table>
			<div id="repinfo"></div>
                        <table><tr>
                                <td>
			<table>
				<tr>
					<th>Single Account Reports </th>
				</tr>
				<tr>
					<td><button title="Click to print an Account Detail Report" type="button" value="GoAccount" onClick="window.open('includes/acreports.php?submitType=cust&id='+$('#combobox1').val(), '_blank'); return false;">Account Detail</button></td>
				</tr>
				<tr>
					<td><button title="Click to print an Account Audit Report" type="button" value="GoAccount" onClick="window.open('includes/acreports.php?submitType=audit&id='+$('#combobox1').val(), '_blank'); return false;">Account Audit</button></td>
				</tr>
			</table>
                                </td>
                                <td>
                        <table>
				<tr>
					<th>General Reports </th>
				</tr>
				<tr>
					<td><button title="This is an accounts recievable aging report" type="button" value="GoAccount" onClick="window.open('includes/balances.php?submitType=aging', '_blank'); return false;">Account Aging</button></td>
				</tr>
				<tr>
					<td><button title="This is a list of accounts with a credit balance" type="button" value="GoAccount" onClick="window.open('includes/balances.php?submitType=posrec', '_blank'); return false;">Account Credit Balance</button></td>
				</tr>
			</table>
                                 </td>
                                </tr>
                        </table>
		</div>		
		<div id="tabs-3">
			<h4>To start a manual read batch, click on Manual Read</h4>
			<button title="Work on manual entry of your meter readings" type="button" value="Go1Account" onClick="dynamic_Selectz('includes/mrinfo.php', '#mrinfo','cust', '0', <?php echo $_SESSION['comnum'] ?>)">
				Manual Read
			</button>
			<button title="Work on radio, touch, or mobile reading batch setup and import" type="button" value="Add2Account" onClick="dynamic_Select('includes/arinfo.php', '#mrinfo','cust', '0', <?php echo $_SESSION['comnum'] ?>)">
				Auto Read
			</button>
			<button title="Please click for more information" type="button" value="Add3Account" onClick="dynamic_Select('includes/resmrinfo.php', '#mrinfo','cust', '0', <?php echo $_SESSION['comnum'] ?>)">
				Auto Adjust Read Order
			</button>
			<div id="mrinfo"></div>
		</div>
		<div id="tabs-4">
			<button <?php if ($_SESSION['access'] > 2) { echo 'disabled="disabled"';	} ?>
				title="View or edit your company's general information" type="button" value="acount" onClick="dynamic_Select('includes/compinfo.php', '#setinfo','cust', '0')">Company Settings
			</button>
			<button Title="Add or edit your company's rate codes" type="button" value="bcount" onClick="dynamic_Select('includes/rcinfo.php', '#setinfo','cust', '0')">
				Rate Codes
			</button>
			<button title="View or edit your company's payment types" type="button" value="ccount" onClick="dynamic_Select('includes/ptypeinfo.php', '#setinfo','cust', '0')">
				Payment Types
			</button>
			<button title="View or edit your company's miscellaneous charge types" type="button" value="dcount" onClick="dynamic_Select('includes/pctypeinfo.php', '#setinfo','cust', '0')">
				Charge Types
			</button>
			<button <?php if ($_SESSION['access'] > 1) { echo 'disabled="disabled"';	} ?>
				title="View or edit your company's user information" type="button" value="dcount" onClick="dynamic_Select('includes/userinfo.php', '#setinfo','list', '0')">Users
			</button>
			<div id="setinfo"></div>
		</div>
	</div>
