/* --- -----------------------------------------------------------------------------
 Filename:		JavaNav.js
 Description: 	Java Script navigation scripts 

 Copyright (c) 1999-2009 JADE International, Inc. All rights reserved.
------------------------------------------------------------------------------- */
function ConfirmDelete(form, action, strMsg) {
        if (confirm(strMsg)) {
			form.action=action;
			form.submit();
        }
}

function ConfirmFormAction(form, action, strMsg) {
        if (confirm(strMsg)) {
			form.action=action;
			form.submit();
        }
}

function ConfirmLinkAction(action, strMsg, strMsg2) {
	if (confirm(strMsg)) {
		if (typeof(strMsg2) == 'undefined' ){
			window.location=action;
		}
		else
		{
			if (confirm(strMsg2)) {
				window.location=action;
			}
		}
	}
} 		

function GoTo(strHref) {
	window.location.href = strHref;
}

function ExecuteForm(form, action) {
	form.action=action;
	form.submit();
}

function openHelpWindow (parHref)
{
  openWindow (parHref, 300, 300, 20, 30);
}

function openWindow(parHref, width, height, screenX, screenY) 
{
  // Check if screenX and screenY are undefined
  if(typeof(screenX)=="undefined"){ screenX = 80 }
  if(typeof(screenY)=="undefined"){ screenY = 60 }
  
  winOptions = 'width=' + width + ',height=' + height 
             + ',screenx=' + screenX + ',screeny=' + screenY
             + ',left=' + screenX + ',top=' + screenY
             + ',toolbar=no,location=no,resizable=yes,scrollbars=yes';
  winName = 'Window' + width + height;
  newWindow = window.open(parHref, winName, winOptions)
		newWindow.focus();
}

function getRadioButtonValue (radio)
{
  var found=0;
  for (var i = 0; i < radio.length; i++)
  {
    if (radio[i].checked)
	{
	  var found=found+1;
	  return radio[i].value;
	}
  }
  if (found == 0)
  {
    return false;
  }
}

// Field validation
function checkLen(field, intLen, divMsg)
{
	if (field.value.length >= intLen)
	{
		divMsg.innerHTML = "0 Characters left";
		field.value = field.value.substr(0, intLen);
		return false;
	}

	intRemainder = intLen - field.value.length;

	if (intRemainder > 1)
		divMsg.innerHTML = intRemainder + " characters left.";
	else
		divMsg.innerHTML = intRemainder + " character left.";
	
	return true;
}

// String trim functions
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

// Catalog quantity field validation
function validateOrderQty (fldQty)
{
	if (trim (fldQty.value).length == 0)
	{
		alert ("Please enter a quantity.");
		fldQty.focus();
		return false;
	}
	
	if (!isNumeric (fldQty.value))
	{
		alert ("Please enter a valid quantity.");
		fldQty.value = "";
		fldQty.focus();
		return false;
	}

	return true;
}

function isNumeric (number)
{
	var NumericRegExp = /^\d+$/;
	return NumericRegExp.test (number);
}

function incValue (field)
{
		if (isNaN (parseInt (field.value)))
			field.value = 1;
		else
			field.value = parseInt (field.value) + 1
}

function autoResize(id, height, width)
{
	
	var obj = $("#" + id);
	var image = new Image();
	
	image.onload = function()
	{
		
		var newH = image.height > height ? height : image.height;
		var newW = image.height > height ? image.width*(height/image.height) : image.width;
		
		var newH = newW > width ? newH*(width/newW) : newH;
		var newW = newW > width ? width	: newW;
		
		obj.attr("height", Math.ceil(newH));
		obj.attr("width", Math.ceil(newW));
		obj.css("height", Math.ceil(newH) + "px");
		obj.css("width", Math.ceil(newW) + "px");
	};
	
	image.src = obj.attr("src");
}


// ------------------------------------------------------------
// Roll over Image Functions
// These functions are used for the roll over navigation images
// ------------------------------------------------------------

//Change Images Function
// This function swaps the OFF image with the ON image
function RCChangeImages(imgName, state) 
{
	if (document.images && (RCPreloadFlag == true)) 
	{	
		// Turn on/off current link
		if(state == "on")	
		{
			document[imgName].src = RolloverImages[imgName][1];
		}
		else
		{
			document[imgName].src = RolloverImages[imgName][0];
		}
	}
}		

// Preload Images function
// This function loads all of the images for the rollovers so that
// they are cached in the browser for faster viewing.
function RCPreloadImages() 
{
	if (document.images) 
	{
		// To prevent a memory leak, only define this object once
		var OnImage = new Image();
		
		for(var i in RolloverImages)
		{					
			OnImage.src = RolloverImages[i][1];
		}
		
		RCPreloadFlag = true;
	}
}