﻿function submitOnEnter(e, callback)
{
	var key;
	if (window.event) // IE
	{
		key = e.keyCode;
	}
	else if (e.which) // Netscape, Firefox, Opera
	{
		key = e.which;
	}
	if (key != 13)
	{
		return true;
	}
	else
	{
		callback();
		return false;
	}
}
function forgotPassword()
{
	if (document.getElementById("forgotPass").style.display == "none")
	{ $("#forgotPass").animate({ height: 'show' }, 'fast'); }
	else
	{ $("#forgotPass").animate({ height: 'hide' }, 'fast'); }
}
function getPassword()
{
	var s = document.getElementById("tbLogin_SerialNo");
	var r = document.getElementById("getPassResponse").innerHTML = "Processing...";
	if (s != null)
	{
		if (s.value == null || s.value == "")
		{
			msgBox("Please enter an agency id or \nserial number to retrieve your password");
			s.focus();
			return;
		}
		else
		{
			document.body.style.cursor = 'wait';
			$.ajax({
				type: "POST",
				url: "http://www.policetrak.net/getpassword.php",
				data: 	"serialno=" + document.getElementById("tbLogin_SerialNo").value,
				success: function(html){
					$("#getPassResponse").html(html);
					document.body.style.cursor = 'auto';
				}
			});
			document.body.style.cursor = 'auto';
		}
	}
}
function doLogin()
{
	$("#loginResult").html = "";
	var a = document.getElementById("tbLogin_LoginID");
	var p = document.getElementById("tbLogin_Password");
	if (a != null && p != null)
	{
		if (a.value == null || a.value == "")
		{
			msgBox("You must enter your agency id to log in");
			a.focus();
			return;
		}
		if (p.value == null || p.value == "")
		{
			msgBox("You must enter your password to log in");
			p.focus();
			return;
		}
		document.body.style.cursor = 'wait';
		$.ajax({
			type: "POST",
			url: "http://www.policetrak.net/login.php",
			data: 	"loginid=" + document.getElementById("tbLogin_LoginID").value + "&password=" + document.getElementById("tbLogin_Password").value, 
			success: function(html){
				$("#loginResult").html(html);
				document.body.style.cursor = 'auto';
			}
		});
		document.body.style.cursor = 'auto';
	}
}
function hideDiv(tagName)
{
	var section = document.getElementById(tagName);
	section.style.display = 'none';
}
function showDiv(tagName)
{
	var section = document.getElementById(tagName);
	section.style.display = 'block';
}
function toggleDisplay(divid)
{
	if (document.getElementById(divid).style.display == 'none')
	{
		document.getElementById(divid).style.display = 'block';
	}
	else
	{
		document.getElementById(divid).style.display = 'none';
	}
}
function msgBox(message)
{
	alert(message);
}
function confirmBox(message)
{
	return window.confirm(message);
}
function SetTemplateFocus(editor)
{
	if (typeof (editor) != undefined)
	{
		editor.SetFocus();
	}
}
function refreshPage()
{
	window.location.reload( true );
}
function showTip(text, width) {
	var xOffset = 12;
	var yOffset = 10;
	var st = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
	var leftPos = event.clientX;
	if (leftPos < 0) { leftPos = 0; }
	if (document.getElementById('tipContainer') == null) {
		var tipDiv = document.createElement('<div>');
		tipDiv.setAttribute('id', 'tipContainer');
		document.body.appendChild(tipDiv);
	}
	var obj = document.getElementById('tipContainer');
	obj.innerHTML = text;
	if (width != null) { obj.style.width = Math.max(width, 10); } else { obj.style.width = 'auto'; }
	if (leftPos + xOffset + obj.offsetWidth >= document.documentElement.clientWidth) {
		obj.style.left = (event.clientX - obj.offsetWidth) + 'px';
	} else { obj.style.left = leftPos + xOffset + 'px'; }
	if (event.clientY + st + yOffset + obj.offsetHeight >= document.documentElement.clientHeight)
	{ obj.style.top = st + event.clientY - obj.offsetHeight + 'px'; } else { obj.style.top = event.clientY + yOffset + st + 'px'; }
	obj.style.visibility = 'visible';
}
function hideTip() {
	var obj = document.getElementById('tipContainer');
	if (obj != null) {
		obj.style.visibility = 'hidden';
	}
}
function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g, "");
}
function ltrim(stringToTrim)
{
	return stringToTrim.replace(/^\s+/, "");
}
function rtrim(stringToTrim)
{
	return stringToTrim.replace(/\s+$/, "");
}
function findPos(obj)
{
	var curleft = curtop = 0;
	do
    {
      	curleft += obj.offsetLeft;
       	curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft, curtop];
}

