
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

// These are probably helping to preload into the browser,
//  but we're not using the image variable itself in changeImages().
//  That function is changing the src as a string.
//  So, we're counting on the browser caching the image, which is still ok.
//  These variable names are unused, but cannot match the image name itself.
//  Include this in body tag when needed: onload="preloadImages();"
var preloadFlag = false;
function preloadImages() {
	if (document.images) {
		// none for now. This is the format:
		// btn_cart_over = newImage("/img/btn_cart_over.gif");
		preloadFlag = true;
	}
}

// 2007-08-14 TaskID:5961 RBC
function PopProductImage(url)
{
  popwin = window.open(url,"winImg",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=500,height=500');
  popwin.focus();   // Bring it to the front when reloading it.
  self.name = "mainWin"; 
}

// findPos from www.quirksmode.org/js/findpos.html
function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    curleft = obj.offsetLeft
    curtop = obj.offsetTop
    while (obj = obj.offsetParent)
    {
      curleft += obj.offsetLeft
      curtop += obj.offsetTop
    }
  }
  return [curleft, curtop];
}


// Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
//  Usage: <textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>
// This is a complex issue, but this script seems to handle most of the situations, including pasting. 
//  See comments at the bottom of www.codeproject.com/KB/aspnet/Textarea_Length_Validator.aspx for overkill.
function ismaxlength(obj)
{
  var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength)
      obj.value=obj.value.substring(0,mlength)
}

// Set an element's css class name.
function SetElementCssClass(elementId, className)
{
  var el = document.getElementById(elementId);
  if (el)
  {
    el.className = className;
  }
}

// Set an element's display style.
function SetElementDisplay(elementId, displayValue)
{
  var el = document.getElementById(elementId);
  if (el)
  {
    el.style.display = displayValue;
  }
}

// Toggle two elements' display styles.
//  Toggle one element to 'none', the other to 'block'.
//  ASSUME: For current state, look for 'none', else displayed;
//          since if the style isn't set, the element is displayed.
//  ASSUME: Element 1's current state determines the toggle.
function ToggleElementDisplays(elementId1, elementId2)
{
  var elem1 = document.getElementById(elementId1);  // Name avoids el1 confusion.
  var elem2 = document.getElementById(elementId2);
  if (elem1 && elem2)
  {
    if (elem1.style.display != "none")
    {
      elem1.style.display = "none";
      elem2.style.display = "block";
    }
    else
    {
      elem1.style.display = "block";
      elem2.style.display = "none";
    }
  }
}

// Toggle a 'read more' construct:
//  Expanding element's css class, Read More trigger's display text.
//  ASSUME: Use the class name to condition the current state.
//          If the class name is neither, it will default to state 1.
function ToggleMore(classElementId, className1, className2, moreElementId, moreText1, moreText2)
{
  var el = document.getElementById(classElementId);
  if (el)
  {
    var isState2 = (el.className == className1);
    el.className = (isState2) ? className2 : className1;

    // In here, instead of fully independent, because it assumed the class name conditions the state.
    el = document.getElementById(moreElementId);
    if (el)
    {
      el.innerText = (isState2) ? moreText2 : moreText1;
    }
  }
}

