﻿// Browser check....
var isNav4, isIE4;
if (parseInt(navigator.appVersion.charAt(0)) >= 4)
   {
   isNav4 = (navigator.appName == "Netscape") ? 1 : 0;
   isIE4 = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
   }    // End if parseInt


function displaypopUp(left, top, wdth) {	//function to display popup (used internally)
	if (document.all.PopUp) {
		var sty = document.all.PopUp.style;
		sty.left = left;
		sty.top = top;
		sty.width = wdth;
		sty.visibility = "visible";
	}
}

function clearPopUp() { //function to "erase" popup
	if (document.all.PopUp) {
		document.all.PopUp.style.visibility = "hidden";
		document.all.PopUp.innerHTML='';
	}
}

function activatePopUp(html, wdth) {	//make popup active item
	if (document.all.PopUp) {
		clearPopUp();
		checkpopUp(wdth);
		document.all.PopUp.innerHTML=html;
	}
}

function checkpopUp(wdth) { //function to move popup (used internally)
	try
	{
		var left = event.clientX + document.body.scrollLeft - 120;
		var top = event.clientY + document.body.scrollTop - 100;
	}
	catch(er)
	{
		var top=200;
		var left=100;
	}

	if (left > document.body.clientWidth-wdth) left=document.body.clientWidth-wdth;
	
	setTimeout("displaypopUp("+left+","+top+","+wdth+")",1);
}





function openCashDrawer(){
	var drwr = document.getElementById('Drawer');
	if (drwr) {
		try {
			drwr.OpenCashDrawer();
		}
		catch(msg) {
			alert('ActiveX cash drawer control not properly registered');
		}
	}
	else alert('ActiveX cash drawer control not loaded');
}


/* original function that worked...

function openCashDrawer(){
	var drwr = document.getElementById('Drawer');
	if (drwr) drwr.OpenCashDrawer();
	else alert('ActiveX cash drawer control not loaded');
}
*/

function printThisPage(intNumberOfPrints){
	if (document.all.factory) {
		document.all.factory.printing.header = '';
		document.all.factory.printing.footer = '';
		document.all.factory.printing.leftMargin = '.75';
		document.all.factory.printing.topMargin = '.75';
		document.all.factory.printing.rightMargin = '.75';
		document.all.factory.printing.bottomMargin = '.75';
		document.all.factory.printing.portrait = true;
		document.all.factory.printing.Print(false);
		setTimeout("return true;", 2000); 
	}
	else alert('ActiveX print control not loaded');
}


function checkForChange(inputCtrlId, amountDue)
{
	if (IsNumeric(amountDue) == false) amountDue = '-1';

	var txt = document.getElementById(inputCtrlId);
	if (txt) {
		var txtval = txt.value;
		
		//if the amount we're paying is 0.00, then
		//we neither need to open the cash drawer
		//nor check for change
		//if (txtval > 0) {
			if (IsNumeric(txtval) && (txtval > 0)) {
				openCashDrawer();
				var pmtAmt = parseFloat(txtval);
				
				//only if we have SPECIFIED an AmountDue
				//should we bother to check for change due
				if (amountDue >= 0) {
					if (pmtAmt > amountDue)
						confirm('Change: $' + (-(Math.round((amountDue - pmtAmt)*100)/100)).toFixed(2));					else return true;
				}
				else return true;
			}
			else
			{
				alert(txtval + ' is an invalid payment!!!');
				event.cancel = true;
				event.returnValue= false;
			}
		//}
	}
}



function IsNumeric(sText){
	if (!sText) return false;
	if (sText == '.') return false;
	
	var ValidChars = '0123456789';
	var ValidSigns = '+-';
	var dotCount = 0;
	var signCount = 0;
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			if (Char == '.') dotCount += 1;
			else if ((ValidSigns.indexOf(Char) != -1) && (i == 0)) signCount += 1;
			else IsNumber = false;
		}
	}
	return (IsNumber && dotCount <= 1 && signCount <= 1);   
}



function reFocus(control)
{
  var id = control.id;
  if (control.value == '')
  setTimeout("document.all." + id + ".focus()",20); 
}



function logOffOK()
{
	var fRet;
	fRet = confirm('Are you sure you wish to log off KeyPro?');
	if(!fRet)
	{
		event.returnValue=false;
		event.cancel = true;
	}
}


function minimize()
{
	window.innerWidth = 100;
	window.screenX = screen.width;
	window.screenY = screen.height;
	window.screenY = screen.height;
	alwaysLowered = true;
}


function maximize()
{
	window.moveTo(0,0);
	window.resizeTo(screen.width,screen.height);
}



function CatchKeyPress(KeyCode, Sender) {
	if(Sender.getAttribute("AllowEnterKey") == null) {
		var btnToBeClicked = null;
		
		RemoveEnterAndEscEvents();
		
		if(KeyCode == '13') {
			var ButtonName = Sender.getAttribute("TargetButton");
			btnToBeClicked = document.getElementById(ButtonName);
			
			if(btnToBeClicked) {
				btnToBeClicked.click();
			}
		}
	} 
}


function RemoveEnterAndEscEvents() {
	if (event.keyCode == 13 || event.keyCode == 27) {
		event.cancelBubble = true;
		event.returnValue = false;
	}
}


function SetFocus(field) {
	if (document.getElementById(field) != null) {
		document.getElementById(field).focus();
	} 
}


function popupMap(sAddr, sCity, sState, sZip)
{
    var sPage, sOptions

    sPage = "http://www.expedia.com/pub/agent.dll?qscr=mcst&strt1=" + sAddr + "&city1=" + sCity + "&stnm1=" + sState + "&zipc1=" + sZip;
    
    sOptions = "toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=633,height=610";
    
    var theWindow = window.open(sPage, "ExpediaMap", sOptions);
    
    //centerWindow(theWindow);
}



function centerWindow(theWindow)
{
// modified to support ie6 on 2/16/2004 by beldridge
    var pointLeft;
    var pointTop;

    if (isNav4)
        {
        pointLeft = (screen.width - theWindow.innerWidth) / 2;
        pointTop = (screen.height - theWindow.innerHeight) / 2;
//      alert("Nav: Left = " + pointLeft + " Top = " + pointTop);
        } // End if isNav4
        
    if (isIE4)
        {
        var winWidth;
        var winHeight;
        var d = theWindow.document;
        
        if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0) 
            {
            winWidth = d.documentElement.clientWidth
            winHeight = d.documentElement.clientHeight
            } 
        else 
            {
            if (d.body && typeof d.body.clientWidth!='undefined') 
                {
                winWidth = d.body.clientWidth
                winHeight = d.body.clientHeight
                }
            }
        
        pointLeft = (screen.width - winWidth) / 2;
        pointTop = (screen.height - winHeight) / 2;
        }

//    theWindow.moveTo(pointLeft, pointTop);
}
