// this function repositions a menu to the speicified offset from center
function repositionMenu(menu, offset)
{
	// the new left position should be the center of the window + the offset
	var width = jQuery(document).outerWidth();
	//var width = getWindowWidth();

	var newLeft = width / 2 + offset;
	jQuery('#debug').text(width+' width, new "Left" = '+newLeft);

	// setting the left position in netscape is a little different than IE
	menu.container.style ? menu.container.style.left = newLeft + "px" : menu.container.left = newLeft;
}
 
// this function calculates the window's width - different for IE and netscape
function getWindowWidth()
{
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}

/* Slide-out menu control */
jQuery(document).ready(function(){
	jQuery("a[@rel].slideoutMenuLink").mouseover(
		function()
		{
			if( jQuery("#"+this.rel+"Container").html() != null )
			{
				ypSlideOutMenu.showMenu(this.rel);
			}
		}
	);
	
	jQuery("a[@rel].slideoutMenuLink").mouseout(
		function()
		{
			if( jQuery("#"+this.rel+"Container").html() != null )
			{
				ypSlideOutMenu.hideMenu(this.rel);
			}
		}
	);
	
	jQuery('#menus div.slideoutMenu').hover(
		function()
		{
			//first, get the ID of the div container.  we need to determine the button that is 'attached' to this slideout menu, and we can
			//	find that from the ID of the div container
			var theID = jQuery(this).attr('id');
			if(theID.indexOf('Container') > 0)
			{
				var theRel = theID.substring(0, theID.length - 'Container'.length);
				jQuery('a[@rel='+theRel+']').addClass('overMenu');
			}
			
		},
		function()
		{
			var theID = $(this).attr('id');
			if(theID.indexOf('Container') > 0)
			{
				var theRel = theID.substring(0, theID.length - 'Container'.length);
				jQuery('a[@rel='+theRel+']').removeClass('overMenu');
			}
		}
	)
});


function formValidation(theForm)
{

  if (theForm.qty.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"quantity\" field.");
    theForm.qty.focus();
    return (false);
  }

  var checkOK = "0123456789,";
  var checkStr = theForm.qty.value;
  var allValid = true;
  var validGroups = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digit characters in the \"qty\" field.");
    theForm.qty.focus();
    return (false);
  }
    if (checkStr == "")
  {
    alert("Please enter a quantity to be ordered.");
    theForm.qty.focus();
    return (false);
  }

  var chkVal = allNum;
  var prsVal = parseInt(allNum);
  if (chkVal != "" && !(prsVal >= 0))
  {
    alert("Please enter a value greater than or equal to \"0\" in the \"qty\" field.");
    theForm.qty.focus();
    return (false);
  }
  return (true);
}
