<?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>
window.replainSettings = { id: 'eb9a83fd-56bb-4587-8b0f-07e32dca088a' };
(function(u){var s=document.createElement('script');s.async=true;s.src=u;
var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);
})('https://widget.replain.cc/dist/client.js');
</script>
    <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("ui-autocomplete")._renderItem = function(ul, item) {
						return $("<li></li>").data("ui-autocomplete-item", 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();
			});
		});
		function toggle() {
			var ele = document.getElementById("selector");
			if (ele.style.display == "block") {
				ele.style.display = "none";
			} else {
				ele.style.display = "block";
			}
		}
	    $(function() {
                $( "#reportdate" ).datepicker({
			showOn: "button",
			buttonImage: "assets/img/calendar.gif",
			buttonImageOnly: true
		    });
	    });
	</script>

		<table width="90%">
			<tr>
				<td><a href="<?php echo $defaultHomeLink; ?> " target="_blank" Title="WtrBill.com"><img src="assets/img/wtrbilllogo.svg" alt="WtrBill.com" height="70" width="130"/></a></td>
				<td width="80%"><h1><?php echo $_SESSION['company'];?></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 name="mainx" data-role="header" data-theme="a">
	    <div id="divAuthorizeNetPopup" style="display:none;" class="AuthorizeNetPopupGrayFrameTheme">
	<div class="AuthorizeNetPopupOuter">
		<div class="AuthorizeNetPopupTop">
			<div class="AuthorizeNetPopupClose">
				<a href="javascript:;" onclick="AuthorizeNetPopup.closePopup();" title="Close"> </a>
			</div>
		</div>
		<div class="AuthorizeNetPopupInner">
			<iframe name="iframeAuthorizeNet" id="iframeAuthorizeNet" src="empty.html" frameborder="0" scrolling="no"></iframe>
		</div>
		<div class="AuthorizeNetPopupBottom">
               </div>
	</div>
        	</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 style="padding-left: 25px;" ><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 style="padding-left: 25px;" ><button title="Return to the Customer Information screen." type="button" value="GoAccount" onClick=location.reload()>Clear Search
							</button></td><td><input type="text" name="reportdate" id="reportdate" value="<?echo date('m/d/Y');?>"></td></tr>
							</table>
			<div id="repinfo"></div>
            <table>
                <tr><th>* Reports with an asterik on the button will be for the month or day selected above!</th></tr>
                <tr><th>Single account reports will be for the account selected above.</th></tr>
            </table>
            <table>
                <tr>
                <td>
			        <table>
				    <tr>
					    <th>Single Account Reports </th>
				    </tr>
				    <tr>
					    <td style="text-align: center"><button title="Click to print an Account Detail Report" type="button" value="GoAccount" onClick="window.open('includes/acreports.php?submitType=cust&comnum=<? echo $_SESSION['comnum'];?>&id='+$('#combobox1').val(), '_blank'); return false;">Account Detail</button></td>
				    </tr>
				    <tr>
					    <td style="text-align: center"><button title="Click to print an Account Audit Report" type="button" value="GoAccount" onClick="window.open('includes/acreports.php?submitType=audit&comnum=<? echo $_SESSION['comnum'];?>&id='+$('#combobox1').val(), '_blank'); return false;">Account Audit</button></td>
				    </tr>
			</table>
                </td>
                <td>
                        <table>
				<tr>
					<th>General Reports </th>
				</tr>
				<tr>
					<td style="text-align: center"><button title="This is an accounts recievable aging report" type="button" value="GoAccount" onClick="window.open('includes/balances.php?submitType=aging&reportdate='+$('#reportdate').val(), '_blank'); return false;">Account Aging</button></td>
				</tr>
				<tr>
					<td style="text-align: center"><button title="This is a list of accounts with a credit balance" type="button" value="GoAccount" onClick="window.open('includes/balances.php?submitType=posrec&reportdate='+$('#reportdate').val(), '_blank'); return false;">Account Credit Balance</button></td>
				</tr>
                <tr>
					<td style="text-align: center"><button title="This is the monthly directors report" type="button" value="GoAccount" onClick="window.open('includes/totals.php?submitType=totals&reportdate='+$('#reportdate').val(), '_blank'); return false;">Monthly Directors Report*</button></td>
				</tr>
                <tr>
					<td style="text-align: center"><button title="This is the monthly billing report" type="button" value="GoAccount" onClick="window.open('includes/totals.php?submitType=billing&reportdate='+$('#reportdate').val(), '_blank'); return false;">Monthly Billing Report*</button></td>
				</tr>

			</table>
                                 </td>
                                </tr>
                        </table>
		</div>
		<div id="tabs-3">
			<h4>To start a manual read batch, click on Manual Read</h4>
            <h4>To start a Radio or Touch read batch, click on Auto Read</h4>
            <h4>To start a WtrFlw Mobile read batch, click on Mobile 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')">
				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')">
				Auto Read
			</button>
            <button title="Work on WtrFlw mobile reading batch setup and import" type="button" value="Add2Account" onClick="dynamic_Select('includes/amrinfo.php', '#mrinfo','cust', '0')">
				Mobile Read
			</button>
			<button title="Please click for more information" type="button" value="Add3Account" onClick="dynamic_Select('includes/resmrinfo.php', '#mrinfo','cust', '0')">
				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>
            <button <?php if ($_SESSION['access'] > 2) { echo 'disabled="disabled"';	} ?>
				title="View or edit your company's logo!" type="button" value="acount" onClick="dynamic_Select('includes/logoinfo.php', '#setinfo','cust', '0')">Company Logo
			</button>
			<div id="setinfo"></div>
		</div>
	</div>
<script>
(function () {
            if (!window.AuthorizeNetPopup) window.AuthorizeNetPopup = {};
            if (!AuthorizeNetPopup.options) AuthorizeNetPopup.options = {
                onPopupClosed: null
                };

            AuthorizeNetPopup.closePopup = function () {
                //document.getElementById("divAuthorizeNetPopupScreen").style.display = "none";
                document.getElementById("divAuthorizeNetPopup").style.display = "none";
                document.getElementById("iframeAuthorizeNet").src = "empty.html";
                document.getElementById("btnOpenAuthorizeNetPopup").setAttribute("hidden","hidden");
                document.getElementById("btnPostEPayment").click();
                if (AuthorizeNetPopup.options.onPopupClosed) AuthorizeNetPopup.options.onPopupClosed();
                };


            AuthorizeNetPopup.openPopup = function () {
                var popup = document.getElementById("divAuthorizeNetPopup");
                var popupScreen = document.getElementById("divAuthorizeNetPopupScreen");
                var ifrm = document.getElementById("iframeAuthorizeNet");
                var form = document.forms["formAuthorizeNetPopup"];
                $("#popupToken").val($("#inputtoken").val());
                form.action = "https://test.authorize.net/payment/payment";
                ifrm.style.width = "700px";
                ifrm.style.height = "578px";

                form.submit();

                popup.style.display = "";
                //popupScreen.style.display = "";
                centerPopup();
                };

            AuthorizeNetPopup.onReceiveCommunication = function (querystr) {
                    var params = parseQueryString(querystr);
                    switch (params["action"]) {
                        case "successfulSave":
                            AuthorizeNetPopup.closePopup();
                            break;
                        case "cancel":
                            AuthorizeNetPopup.closePopup();
                            break;
                        case "transactResponse":
                            var response = params["response"];
                            document.getElementById("token").value = response;
                            document.cookie = `response=${response}`;
                            //alert(response);
                            AuthorizeNetPopup.closePopup();
                            break;
                        case "resizeWindow":
                            var w = parseInt(params["width"]);
                            var h = parseInt(params["height"]);
                            var ifrm = document.getElementById("iframeAuthorizeNet");
                            ifrm.style.width = w.toString() + "px";
                            ifrm.style.height = h.toString() + "px";
                            centerPopup();
                            break;
                        }
                };


            function centerPopup() {
                var d = document.getElementById("divAuthorizeNetPopup");
                d.style.left = "50%";
                d.style.top = "50%";
                var left = -Math.floor(d.clientWidth / 2);
                var top = -Math.floor(d.clientHeight / 2);
                d.style.marginLeft = left.toString() + "px";
                d.style.marginTop = top.toString() + "px";
                d.style.zIndex = "2";
                if (d.offsetLeft < 16) {
                    d.style.left = "16px";
                    d.style.marginLeft = "0px";
                    }
                if (d.offsetTop < 16) {
                    d.style.top = "16px";
                    d.style.marginTop = "0px";
                    }
                }

            function parseQueryString(str) {
                    var vars = [];
                    var arr = str.split('&');
                    var pair;
                    for (var i = 0; i < arr.length; i++) {
                        pair = arr[i].split('=');
                        vars.push(pair[0]);
                        vars[pair[0]] = unescape(pair[1]);
                    }
                    return vars;
                }
        }());
        </script>
<?php
//render('_footer');
?>


