
function isIE()
{
	return( window.navigator.userAgent.indexOf("MSIE") != -1 );
}

function isNetscape6()
{
	return( window.navigator.userAgent.indexOf("Netscape6") != -1 );
}

if ( isIE() )
{
	document.onkeypress = IEhandler; 
}
else if ( isNetscape6() )
{
	document.addEventListener("keypress", NS6Handler, true);
}


function IEhandler() 
{		
	if ( (window.event.keyCode == 13) && (window.event.srcElement.tagName == 'INPUT') )
	{	
		
		var okToSubmit = false;
		var element = document.getElementById(window.event.srcElement.PostingControlID);
		
		if(element!=null)
		{
		
			if(element.type=='image')
			{
				document.getElementById('PostingFacade1').name=element.name+".x";
				document.getElementById('PostingFacade1').value=1;

				document.getElementById('PostingFacade2').name=element.name+".y";
				document.getElementById('PostingFacade2').value=1;
				okToSubmit = true;
			}

			if(element.type=='button')
			{
				document.getElementById('PostingFacade1').name=element.name;
				document.getElementById('PostingFacade1').value=element.value;
				okToSubmit = true;
			}

			if(element.type=='submit')
			{
				document.getElementById('PostingFacade1').name=element.name;
				document.getElementById('PostingFacade1').value=element.value;
				okToSubmit = true;
			}

			window.event.keyCode = 0;
			
			if(okToSubmit)
			{
				document.forms(0).submit();
			}
		}
		else
		{
			window.event.keyCode = 0;
		}
	}	
}	

function NS6Handler(e)
{		
	if ( (e.which == 13) && (e.originalTarget.tagName == 'INPUT') )	
	{	
		e.cancelBubble = true;
	}			
}


function SwapImage(imageID, imageFile)
{
	document.getElementById(imageID).src = '../Images/' + imageFile;
}

function RedirectBrowser(redirectURL)
{
	location = redirectURL;
}

function PopupWindow(URL, width, height)
{
	var page;
	var popup;
	var windowprops = 'width='+width + ',height=' + height +',toolbar=no,titlebar=no,scrollbars=no,resizable=no,location=no,status=no,menubar=no'; 
	windowprops += ',top=' + parseInt((screen.availHeight/2)-(350/2)) + ',';
	windowprops += 'left=' + parseInt((screen.availWidth/2)-(350/2));
	popup = window.open(URL,page,windowprops); 
}

function PopupWindowOptions(URL, options)
{
	var page;
	var popup;
	var windowprops = options;
	
	if(options == '')
	{
		window.open(URL);
	}
	else
	{
		windowprops += ',top=' + parseInt((screen.availHeight/2)-(350/2)) + ',';
		windowprops += 'left=' + parseInt((screen.availWidth/2)-(350/2));
		popup = window.open(URL, page, windowprops);
	}
}

function toggle(itemName)
{
	var itm = document.getElementById(itemName);
	itm.style.display = (itm.style.display == 'none') ? '' : 'none';
}
function toggleBar(itm, e)
{
	if (e.type.toLowerCase() == 'mouseover')
	{
		itm.style.backgroundColor = '#CCCCCC';
		itm.style.borderColor = '#666666';
	}
	if (e.type.toLowerCase() == 'mouseout')
	{
		itm.style.backgroundColor = '#cadceb';
		itm.style.borderColor = '#A7AAAA';
	}
}
function toggleAll(name, itemCount)
{
	if (document.getElementById(name+'0'))
	{
		var isOpen = document.getElementById(name+'0').style.display == '';

		for (var i=0;i<itemCount;i++)
		{
			if (document.getElementById(name+i))
			{
				document.getElementById(name+i).style.display = (isOpen) ? 'none' : '';
				document.getElementById('plusMinus_'+i).src =
					(document.getElementById('recipeItems_'+i).style.display=='')
						? '../images/minus.gif' : '../images/plus.gif';
			}
		}
	}
}

function ConfirmDelete()
{
	if (confirm("Are you sure you want to delete this item?"))
		return true;
	else
		return false;
}
