var popup = null;

function isEnterKey(e)
{
	var keyCode;
	if(window.event) // IE
	{
		keyCode = e.keyCode;
	}
	else 
	{
		keyCode = e.which;
	}

    if(keyCode == 13)
	{return true;}
    else
    {return false;}
}

function toggleAdditionalImages(imageCount,selectedImageID)
{
	try	{
		// Hide all additional images on catalog detail control
		for(i=1; i <= imageCount; i++)
		{
			var imageObj = document.getElementById("ImageItem" + i);
			if(imageObj != null)
			{
				imageObj.style.display="none";
			}
		}
		// Show the selected image
		document.getElementById("ImageItem" + selectedImageID).style.display="";
		
		// Clear all, then highlight the selected button
		for(i = 1; i <= imageCount; i++)
		{
			var img = document.getElementById("CatalogDetailCtrl_imageToggle" + i);
			if(img != null)
			{
				img.className="UnselectedImageToggle";
			}
		}
		document.getElementById("CatalogDetailCtrl_imageToggle" + selectedImageID).className="SelectedImageToggle";
	}
	catch(e)
	{}
}

function toggleElement(elementID,toggleFieldID)
{
	var toggleDiv = document.getElementById(elementID);
	var item = document.getElementById(toggleFieldID);
	if(item != null)
	{
		if(item.value == "1")
		{
			toggleDiv.style.display="none";
			item.value = "0";
		}
		else
		{
			toggleDiv.style.display="";
			item.value = "1";
		}
	}
}

function toggleSingleElement(elementID)
{
	var item = document.getElementById(elementID);
	if(item != null)
	{
		if(item.style.display != "none")
		{
			item.style.display="none";
		}
		else
		{
			item.style.display="";
		}
	}
}

function setFocusOnControl(controlName)
{
	var control = document.getElementById(controlName);
	if( control != null )
	{
		control.focus();
		return;
	}
}

function popPic (url){
	closePopup();
	popup = window.open(url , "picWin", "");
}

function openPopupWithScroll( url, name , height , width ) {
	closePopup();	//ONLY ONE POPUP, and the reference is stored in the variable popup (hardcoded!)
	var dialogparam = ",scrollbars=1,status=0,location=0,menubar=0,resizable=1";
	var screenparam = "height="+ height +",width="+ width ;
	params = screenparam+dialogparam;
	popup = window.open( url , name , params );
}

function openPopup( url, name , height , width ) {
	closePopup();	//ONLY ONE POPUP, and the reference is stored in the variable popup (hardcoded!)
	var dialogparam = ",scrollbars=0,status=0,location=0,menubar=0,resizable=0";
	var screenparam = "height="+height+",width="+width;
	params = screenparam+dialogparam;
	popup = window.open( url , name , params );
}

function closePopup() {
	var popup = popup;
	if (popup != null && popup.open) {
		popup.close();}
	popup = null;
}