﻿function ToggleDisplay(cat, id)
{
    var elem = document.getElementById(cat + "" + id);
    if (elem) {
        if (elem.style.display != 'block') {
            elem.style.display = 'block';
            elem.style.visibility = 'visible';
        } 
        else {
            elem.style.display = 'none';
            elem.style.visibility = 'hidden';
        }
    }
}
function changeQtyU(thisItem) {
	var thisItemId = thisItem + '_q';
	thisItemId = thisItemId.replace(/_/g,"$");
	var thisForm = 'aspnetForm';
	var testName = eval("document.forms['"+thisForm+"']."+thisItemId+"");
	var thisTotal = testName.value;
	if (thisTotal == "") {
		thisTotal = 0;
	}
	if (thisTotal!= 99) {
	    var newTotal = parseInt(thisTotal) + 1;
	    testName.value = newTotal;
	}
}
function changeQtyD(thisItem) {
	var thisItemId = thisItem + '_q';
	thisItemId = thisItemId.replace(/_/g,"$");
	var thisForm = 'aspnetForm';
	var testName = eval("document.forms['"+thisForm+"']."+thisItemId+"");
	var thisTotal = testName.value;
	if (thisTotal!= 0) {
		var newTotal = parseInt(thisTotal) - 1;
		testName.value = newTotal;
	}
}
// used for coord entry only
function QtyU(thisItem) {
	var thisItemId = thisItem + '_txtQty';
	thisItemId = thisItemId.replace(/_/g,"$");
	var thisForm = 'aspnetForm';
	var testName = eval("document.forms['"+thisForm+"']."+thisItemId+"");
	var thisTotal = testName.value;
	if (thisTotal == "") {
		thisTotal = 0;
	}
	if (thisTotal!= 99) {
	    var newTotal = parseInt(thisTotal) + 1;
	    testName.value = newTotal;
	}
}
function QtyD(thisItem) {
	var thisItemId = thisItem + '_txtQty';
	thisItemId = thisItemId.replace(/_/g,"$");
	var thisForm = 'aspnetForm';
	var testName = eval("document.forms['"+thisForm+"']."+thisItemId+"");
	var thisTotal = testName.value;
	if (thisTotal!= 0) {
		var newTotal = parseInt(thisTotal) - 1;
		testName.value = newTotal;
	}
}

function toggleContent(li,item,i)
{
	if( document.getElementById("li" + li + "" + i).className == 'selected' )
	{   // was selected, now slide up
	    document.getElementById("tab" + item + "" + i).style.display = 'none';
		document.getElementById("li" + li + "" + i).className = '';
	}
	else
	{   // slidedown down
		for( x=1; x<=4; x++ )
		{
			document.getElementById("li" + li + "" + x).className = '';
			document.getElementById("tab" + item + "" + x).style.display = 'none';
		}
		document.getElementById("li" + li + "" + i).className = 'selected';
		document.getElementById("tab" + item + "" + i).style.display = '';
	}
}

function Ensure(str)
{
    var key = window.event.keyCode;
    
    // control keys
    if( (key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) ) {
        window.event.returnValue = true;
        return;
    }

    keychar = String.fromCharCode(key);
    keychar = keychar.toLowerCase();

    if( str.indexOf(keychar) < 0 )
        window.event.returnValue = false;
}
function JumpNext( thisField, nextField, limit )
{
    if( thisField.value.length >= limit )
        document.getElementById(nextField).focus();
}
function NumberRange( ElementID, min, max )
{
    if( parseInt(document.getElementById(ElementID).value) < parseInt(min) )
        document.getElementById(ElementID).value = min;
    else if( parseInt(document.getElementById(ElementID).value) > parseInt(max) )
        document.getElementById(ElementID).value = max;
}