<script type="text/javascript">
var t;
window.onload=resetTimer;
document.onmousedown=resetTimer;
document.onkeypress=resetTimer;

function logout()
{
	location.href='shop_welcome.php' 
}
function resetTimer()
{
	clearTimeout(t);
	t=setTimeout(logout,1000*240) //Shop welcome after 240 seconds of inactivity
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>YBDB</title>
<link href="css/transactions.css" rel="stylesheet" type="text/css" />
<link href="css/contacts.css" rel="stylesheet" type="text/css" />
<link href="css/css_yb_standard.css" rel="stylesheet" type="text/css" />
<link href="css/jquery.nouislider.css" rel="stylesheet" type="text/css" />
<link href="css/chosen.css" rel="stylesheet" type="text/css" />

<script src="js/jquery-2.1.1.js"></script>
<script src="js/transaction.js"></script>
<script src="js/contact.js"></script>
<script src="js/shop.js"></script>
<script src="js/jquery.mask.js"></script>
<script src="js/jquery.jeditable.js"></script>
<script src="js/jquery.nouislider.js"></script>
<script src="js/chosen.jquery.js"></script>
<script src="js/jquery.liblink.js"></script> 
<script src="js/wNumb.js"></script>
<script>
	
	$(function() {

		// prevent a double etherpad if shop_log_iframe is clicked on after a shop closes
		$("#shop_log_link").on("click keypress", function(e) { 
			if (window.location.pathname === '/shop_log_iframe.php') {
				e.preventDefault(); // hack to prevent open shop from reopening in same page
			}			
			$.post("json/transaction.php", {shop_exist: 1}, function(data) {
				if (data === "no_shop") {
					 window.top.location.href = "./start_shop.php";
				}
			});
		});

		// scroll back to same location when up, down, or updated are selected
		$(".down").on("click keypress", function(e) {

			var hash = document.body.scrollTop + 25;
			var query = window.location.search;
			query = query.split("&");
			var visit_id = query[1].split("=")[1] - 1;
			var new_query = query[0] + "&visit_id=" + visit_id;

			var new_url = window.location.origin + window.location.pathname + new_query + "&#" + hash;
			window.location = new_url;     

			
		});

		$(".up").on("click keypress", function(e) {

			var hash = document.body.scrollTop - 25;
			var query = window.location.search;
			query = query.split("&");
			var visit_id = parseInt(query[1].split("=")[1]) + 1;
			var new_query = query[0] + "&visit_id=" + visit_id;

			var new_url = window.location.origin + window.location.pathname + new_query + "&#" + hash;
			window.location = new_url;    
	
		});

		$(".close").on("click keypress", function(e) {

			var hash = document.body.scrollTop;
			var query = window.location.search;
			query = query.split("&");
			var new_query = query[0];
			
			var new_url = window.location.origin + window.location.pathname + new_query + "&#" + hash;   
			window.location = new_url; 
	
		});

		// have to do this a little differently because it is a submit, not a button
		$(".update_changes").on("click keypress", function(e) {

			var hash = parseInt(document.body.scrollTop);
			var query = window.location.search;
			query = query.split("&");
			var visit_id = parseInt(query[1].split("=")[1]);			
			var add_hash = "&#" + hash;
			var action = $("[name=FormUpdate_" + visit_id).attr("action");			
			$("[name=FormUpdate_" + visit_id).attr("action", action + add_hash);
				
		});
		// end scroll back to same location when up, down, updated are selected

	});

	$( window ).on( "load", function() {
	
		if(window.location.hash != "") {
			
			document.body.scrollTop = window.location.hash.replace("#", "") * 1;	
	
		}

	 });
	
</script>

</head>

<body class="yb_standard">
	
	<div style="float: left; width: 12.5%; height: 40px;"></div>
	<div style="align-content: center; height: 40px; float: left; width: 75%">
	  <div style="float: left; width: auto;"><a href="/shop_welcome.php">About/Help</a></div>	
	  <div style="float: right; width: auto;"><a id="shop_log_link" href="/shop_log.php">Sign In/Sign Out</a> | 
	  														<a href="/start_shop.php" target="_parent"> All Shops</a> | 
	  														<a href="/contact_add_edit_select.php" target="_parent">Add/Edit Contact</a> | 
	  														<a href="/stats.php" target="_parent">Reports</a>  | 
	  														<a href="/transaction_log.php" target="_parent">Transaction Log</a> |   
	  														<a href="http://www.positivespin.org" target="_blank">PS Home</a></div>
	  </div>
	<div style="float: left; width: 12.5%; height: 40px;"></div>