var timeout_id

function ShowPopUp(sURL,sWinName,iWinWidth,iWinHeight)
{
	var winPopUp = window.open(sURL,sWinName,'height=' + iWinHeight + ',width=' + iWinWidth + ',resizable=yes,scrollbars=yes');
	if(window.focus){winPopUp.focus()}
}

function RefreshParent(bClose)
{
	/*
		called by popup window.
		will refresh the window that raised the popup
		If bClose = true then closes the popup
	*/
	window.opener.location.reload();
	if(bClose)
	{
		window.close();
	}
}


function stopTimer()
{
     clearTimeout(timeout_id);
}


function closeMenuDiv(subitemNumber)
{
	 // hides the div containing submenu items
	 myMenu = document.getElementById("subitem" + subitemNumber)
	 myMenu.style.display = "none";
}

function startTimer(subitemNumber)
{
     timeout_id = setTimeout('closeMenuDiv(' + subitemNumber+ ')',3000)
}

function showMenuItem(subitemNumber)
 {
	 var myMenu;
	 myMenu = document.getElementById("subitem" + subitemNumber)
	 if(myMenu.style.display == "none")
	 {
        myMenu.style.display = "";
	 }
	 else
	 {
	    myMenu.style.display = "none";
	 }
 }



// Restricts characters from being entered into the quantity box on the basket screen
function getKeyCode(e)
{
 if (window.event)
    return window.event.keyCode;
 else if (e)
    return e.which;
 else
    return null;
}

function keyRestrict(e, validchars) {
 var key='', keychar='';
 key = getKeyCode(e);
 if (key == null) return true;
 keychar = String.fromCharCode(key);
 keychar = keychar.toLowerCase();
 validchars = validchars.toLowerCase();
 if (validchars.indexOf(keychar) != -1)
  return true;
 if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
  return true;
 return false;
}

function countryChanged(source, args)
{
	if (source.selectedIndex == -1)
		return;
	
	if (!(args && args.target))
		return;
		
	var target = document.getElementById(args.target);
	
	if (!(target && target.options))
		return;
		
	var code = source.options[source.selectedIndex].value.toUpperCase();
		
	for (var i = 0; i < target.options.length; i++)
	{
		var codes = target.options[i].codes;
		
		if (codes && codes.length > 0)
		{
			codes = codes.toUpperCase();
			
			if (codes.match(code))
			{
				target.selectedIndex = i;
				return;
			}
		}
	}
}