/* popup window */
function popWin(url,winName, popWidth,popHeight,popScroll) { 
	    var options = 'width='+popWidth+',height='+popHeight+',scrollbars='+popScroll+',location=no,toolbar=0,menubar=0,resizable=0,directories=0';
            var myWin = window.open(url, winName, options);
	    myWin.focus();
}
  	
var condText; 
function clearTextBoxOnCondition(textBox,conditionText){
        if(textBox.value == conditionText)
          textBox.value="";
	  condText=conditionText;
    }   

function fillTextBoxOnCondition(textBox){
        if(textBox.value == "") {
          textBox.value=condText;
        }
}

function checkMaxLength (textarea, evt, maxLength) {
	if (textarea.selected && evt.shiftKey)
	// ignore shift click for select
		return true;
	var allowKey = false;
	if (textarea.selected && textarea.selectedLength > 0)
		allowKey = true;
	else {
		var keyCode = document.layers ? evt.which : evt.keyCode;
		if (keyCode < 32 && keyCode != 13)
			allowKey = true;
		else
			allowKey = textarea.value.length < maxLength;
		}
	textarea.selected = false;
	return allowKey;
}

function storeSelection (field) {
	if (document.all) {
		field.selected = true;
		field.selectedLength = field.createTextRange ? document.selection.createRange().text.length : 1;
	}
}

/* Copied from elcNavigation and head_common.tmpl */
if ((typeof wsmlMakeWebServiceHref) == "undefined")
{
  wsmlMakeWebServiceHref =
  wsmlMakeResourceHref =
  wsmlMakeResourceUrl =
  wsmlMakeLeakHref =
  wsmlMakeComponentHref =
  wsmlMakeCssHref = new Function ("u", "return u;");
}

function elcSendURL( url ) {
	location.replace(wsmlMakeWebServiceHref(url));
}

function setPNGtrans(img) {
	img.src='/images/shim.gif';
}

/* adapted from Mac KR */
//var minPageHeight = 1000;
var minPageHeight = 0;
var iOriginsContentH = 0;
var bracerNameArr = new Array("originslnav", "originsrnav");
//var bracerNameArr = new Array("originslnav");
var bracerObjArr = new Array();
var iBracerY = minPageHeight;
var iFooterOffset = 0;
var iFooterPadding = 12;
var iGlobalNavHeight = 142;
var nestedContentLayers = new Object();
var footerDebug;
	
function addBracerObj(sLayerName) {
	var myLayer = new elcLayer(sLayerName);
	if (!(myLayer == "undefined" || myLayer == null) && myLayer.css) {
		bracerObjArr[bracerObjArr.length] = new elcLayer(sLayerName);
	}
}

function setFooterY() {
	oOriginsContentObj = new elcLayer("elIIContent");
	iOriginsContentH = (oOriginsContentObj && oOriginsContentObj.h)? oOriginsContentObj.h : iOriginsContentH;

	// nestedContentLayers array is establised by the creator template or manually in the template
	if (!(nestedContentLayers == "undefined" || nestedContentLayers == null) && nestedContentLayers.length) {
		var nestedContentH = 0;
		for (var i=0; i<nestedContentLayers.length; i++) {
			var nestedContentLayer = new elcLayer( nestedContentLayers[i] );
			if (nestedContentLayer) {
				var thisBottomYPos = nestedContentLayer.y + nestedContentLayer.h;
				if (thisBottomYPos > nestedContentH) { nestedContentH = thisBottomYPos }
			}
		}
		iOriginsContentH = nestedContentH;
	}

	if (!(bracerNameArr == "undefined" || bracerNameArr == null) && bracerNameArr.length) {
		for (var i=0; i<bracerNameArr.length; i++) {
			addBracerObj(bracerNameArr[i]);			
			if (bracerObjArr[i] && bracerObjArr[i].h && (bracerObjArr[i].h > iBracerY)) {
				iBracerY = bracerObjArr[i].h;
			}
		}
	}
	iBracerY += iGlobalNavHeight; // need to make this configurable

	iFooterOffset = ((iBracerY - iOriginsContentH) > 0) ? iBracerY : iOriginsContentH;
	if (iFooterOffset > 0) {
		iFooterOffset -= iGlobalNavHeight; // accounts for the height of the header
		iFooterOffset += iFooterPadding;
		document.write('<div><table border="0" cellpadding="0" cellspacing="0" width="750"><tr><td><img src="/images/site/spacer.gif" height="' + iFooterOffset + '" width="1" border="0"></td></tr></table></div>');
	}
}

// SYNDICATION SUPPORT
// moveFooter
// injects a spacerDiv into the container page to ensure the height of the content area
// of the module spans the height of the module content.
// spacerDiv is supplied by the syndicator footer
var moduleHeight = 0;
var moduleFooterHeight = 30;
var spacerImgPath = '/images/site/spacer.gif';

function moveFooter(){
	var i;
	if (document.layers) return;
	if (document.getElementsByTagName && !document.all) {
		if (!document.getElementById('elIIFooter')) return;
		tagAry = document.getElementsByTagName('div');
		for (i=0;i<tagAry.length;i++){
			if ((tagAry[i].offsetTop + tagAry[i].offsetHeight) > moduleHeight){moduleHeight = (tagAry[i].offsetTop + tagAry[i].offsetHeight);}
		}
		moduleHeight+=moduleFooterHeight;
		document.getElementById('spacerDiv').innerHTML = "<div style='height:" + moduleHeight + "px;'><img src='/images/global/space.gif' border='0' alt='' width='1' height='" + moduleHeight + "' /></div>";
		// experimental
		var footerLayer = new elcLayer( 'elIIFooter' );
		footerLayer.moveTo( 0, moduleHeight -  20 );
		footerLayer.show();
	} else if(document.all.tags && document.all.spacerDiv){
		if (!document.all.elIIFooter) return;
		len = document.all.tags('div').length;
     		for (i=0;i<len;i++){
			ieHeight = parseInt(document.all.tags('div')[i].offsetHeight);
			ieTop = parseInt(document.all.tags('div')[i].offsetTop);
			if ((parseInt(document.all.tags('div')[i].offsetHeight) + parseInt(document.all.tags('div')[i].offsetTop)) > moduleHeight){moduleHeight = (parseInt(document.all.tags('div')[i].offsetHeight) + parseInt(document.all.tags('div')[i].offsetTop));}
		}
		moduleHeight+=moduleFooterHeight;
		document.all.spacerDiv.innerHTML = "<img src='/images/global/space.gif' border='0' alt='' width='1' height=\"" + moduleHeight + "\"' />";  }
		var footerLayer = new elcLayer( 'elIIFooter' );
		footerLayer.moveTo( 0, moduleHeight - 20 );
		footerLayer.show();
}

function checkGiftwrapFields() {
  // If any of the message fields on the giftwrap section
  // have text in them, the radio button will automatically
  // change from No to Yes (and vice versa)
  if(document.all.CARDMESSAGE_TO.value   != "" ||
     document.all.CARDMESSAGE.value      != "" ||
     document.all.CARDMESSAGE_FROM.value != "" ) {

    document.all.GIFTWRAP[0].checked = true;

  } else {

    document.all.GIFTWRAP[1].checked = true;

  }
}

/* COMMERCE */
function mADD(qtyBox, formName) {
	if (!formName) {
		formName = 'prodform';
	}
	if (!document.forms[formName].elements[qtyBox].value) {
		document.forms[formName].elements[qtyBox].value=1;
	}
	document.forms[formName].submit();
}
