function shimImage(img){ img.src = "/store/catalog/images/shim.gif"; }

/*
  onloadDelegate can be used to specify the use of the window.onload function
  after the body declaration.
 */
function onloadDelegate(function1, function2){
  return function(){
    if(function1){ function1(); }
    if(function2){ function2(); }
  }
}

/*
  HeightSpan, HeightSpanOnLoad, and HeightSpanTimeout can be used to set
  the height of a specific element equal to the height of a reference element
*/
function HeightSpan( sRefElement, sAdjElement, sPixAdj ){
	this.refElem = document.getElementById(sRefElement);
  this.adjElem = document.getElementById(sAdjElement);
  if( sPixAdj ){ this.pixAdj = new Number(sPixAdj) }
  else{ this.pixAdj = new Number(0); }
}
function HeightSpanOnLoad( sRefElement, sAdjElement, sPixAdj ){
  HeightSpan.call( this, sRefElement, sAdjElement, sPixAdj );
  window.onload = onloadDelegate(window.onload, HeightSpan.adjust(this));
}HeightSpanOnLoad.prototype=new HeightSpan();

function HeightSpanTimeout( sRefElement, sAdjElement, sPixAdj ){
  HeightSpan.call( this, sRefElement, sAdjElement, sPixAdj );
  HeightSpan.adjust(this);
  var callFunc = function(){ HeightSpan.adjust(this); }
  var checkInterval = window.setInterval( callFunc,500 );
  window.setTimeout( function(){clearInterval(checkInterval);}, 1000);
}HeightSpanTimeout.prototype=new HeightSpan();

HeightSpan.adjust = function(obj){
	if(obj.refElem && obj.adjElem){
		adjSize = new Number(obj.refElem.offsetHeight) -1 + obj.pixAdj;
		elemSize = new Number( obj.adjElem.offsetHeight);
		if(elemSize < adjSize){ obj.adjElem.style.height = new String(adjSize)+"px";	}
	}
}

RowHeightEval = function(){
	this.rowElements = new Array();
	this.maxRowHeight = new Number(0);
	this.padTop = new Number(0);
	this.padBottom = new Number(0);

	RowHeightEval.prototype.add = function( elemId ){
		var elem = document.getElementById(elemId);
		this.rowElements[this.rowElements.length] = elem;
		elemH = new Number(elem.offsetHeight);
		if(elemH > this.maxRowHeight){
			elem.style.paddingTop=0;
			this.padTop = elemH - elem.offsetHeight;
			elem.style.paddingBottom=0;
			this.padBottom = elemH - this.padTop - elem.offsetHeight;
			this.maxRowHeight = elemH;
			elem.style.paddingTop = this.padTop+"px";
			elem.style.paddingBottom= this.padBottom+"px";
		}
	};

	RowHeightEval.prototype.adjust = function(){
		for(i=0; i<this.rowElements.length; i++){
			if(this.rowElements[i].offsetHeight < this.maxRowHeight){
				mrHeight=this.maxRowHeight-( this.padTop + this.padBottom );
				this.rowElements[i].style.height = new String(mrHeight)+"px";
			}
		}
		this.maxRowHeight = new Number(0);
		this.rowElements = new Array();
	};
};

function replaceWithText( idRefElement, strText ){
	var refElem = document.getElementById(idRefElement);

	if(refElem.hasChildNodes()){
		domUtil.removeChildNodes(refElem);
	}

	var replacementTextNode = document.createTextNode(strText);
   refElem.appendChild(replacementTextNode);

}

function domUtil(){}

domUtil.removeChildNodes = function(node) {
	while (node.childNodes.length > 0) {
		node.removeChild(node.childNodes[0]);
	}
}

function readCookie(s_name){
	var nameEQ = s_name+"=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// wrap functions to avoid JS name clash

var NMUtil = {
	getDimensions: function(element) {
		element = YAHOO.util.Dom.get(element);
		var display = YAHOO.util.Dom.getStyle(element, 'display');
		if (display != 'none' && display != null) {
			// Safari bug
			return {width: element.offsetWidth, height: element.offsetHeight};
		}
		
		// All *Width and *Height properties give 0 on elements with display none,
		// so enable the element temporarily
		var els = element.style;
		var originalVisibility = els.visibility;
		var originalPosition = els.position;
		var originalDisplay = els.display;
		els.visibility = 'hidden';
		els.position = 'absolute';
		els.display = 'block';
		var originalWidth = element.clientWidth;
		var originalHeight = element.clientHeight;
		els.display = originalDisplay;
		els.position = originalPosition;
		els.visibility = originalVisibility;
		return {width: originalWidth, height: originalHeight};
	},

	getHeight: function(element) {
		return NMUtil.getDimensions(element).height;
	},

	getWidth: function(element) {
		return NMUtil.getDimensions(element).width;
	},

	roundCorners: function(id, prefix, squareTL, squareTR, squareBL, squareBR) {
		var original = document.getElementById(id);
		if( original ){
			if(!squareTL) {
				var div1 = document.createElement('div');
				div1.className = prefix + "_tl";
				original.appendChild(div1);
			}

			if(!squareTR) {
				var div2 = document.createElement('div');
				div2.className = prefix + "_tr";
				original.appendChild(div2);
			}

			if(!squareBR) {
				var div3 = document.createElement('div');
				div3.className = prefix + "_br";
				original.appendChild(div3);
			}

			if(!squareBL) {
				var div4 = document.createElement('div');
				div4.className = prefix + "_bl";
				original.appendChild(div4);
			}
		}
	},
	removeDescendantsRoundCorners: function(elementId, prefix, ignoreElementIdRoundCorners){
		if(ignoreElementIdRoundCorners == null){
			ignoreElementIdRoundCorners = false;
		}
		var theElement = $(elementId);
		var roundCornerDiv = $$('div.'+prefix+'_tl','div.'+prefix+'_tr','div.'+prefix+'_bl','div.'+prefix+'_br');
		for(var pos=0;pos<roundCornerDiv.length;pos++){
			if(roundCornerDiv[pos].descendantOf(theElement)){
				if(ignoreElementIdRoundCorners == false || roundCornerDiv[pos].parentNode.id != theElement.id){
					roundCornerDiv[pos].remove();
				}
			}
		}
	},
	roundCornersExist: function(elementId, prefix){
		var theElement = $(elementId);
		var roundCornerDiv = $$('div.'+prefix+'_tl','div.'+prefix+'_tr','div.'+prefix+'_bl','div.'+prefix+'_br');
		for(var pos=0;pos<roundCornerDiv.length;pos++){
			if(roundCornerDiv[pos].parentNode.id == elementId){
				return true;
			}
		}
		return false;
	}
}
