
function enablePopup() {
	return true;
}

function marketingPopUp(servletPath) {
	var height=300;
	var width=375;

	// The if statement below was added to solve ACC-611 mg@pensardigital.com 2006.04.10
	if (window.location.toString().indexOf('ACCM_general_article_2838') == -1)
	window.open('/us/globalPopup.do', 'newwindow', 'height='+height+',width='+width+',top='+((screen.height - height) / 2)+',left='+((screen.width - width) / 2)+',toolbar=no,menubar=no,scrollbars=auto,resizable=no,location=no,directories=no,status=no');
}

function fcnSwapImage(name, imageName) {
	// alert("fcnSwapImage(" + name + "," + imageName + ")");
	var imgObj = document.images[name];
	// alert("retrieved the image object to swap: imgObj.src = " + imgObj.src);
	eval("var newImageObj = " + imageName);
	// alert("grabbed the image variable: newImageObj.src = " + newImageObj.src);
	imgObj.src = newImageObj.src;
}

/**
 * Standard popup window open The first parameter will be the new URL. 
 * Subsequent parameters will be (if supplied) the width and height.
 * If not specified the width and height will be 500 and 200 respectively.
 */
function openWin() {
	var url, width=500, height=200, menu=""; args = arguments;
	url = args[0];
	
	if (args.length>1) {
		width=args[1];
	}

	if (args.length>2) {
		height=args[2];
	}

	if (args.length>3) {
		if (args[3]) {
			menu=",menubar=yes,toolbar=yes";
		}
	}

	var newwin = window.open(url, 'newWin'+Math.floor(Math.random()*1000), 'width='+width+',height='+height+',scrollbars,resizable' + menu);
}

/**
 * Standard popup window open The first parameter will be the new URL. Subsequent parameters will be (if supplied) the width and height. If not specified the width and height will be 500 and 200 respectively.
 */
function openMovieWin() {
	var url, width=500, height=200, menu=""; args = arguments;
	url = args[0];
	if (args.length>1) {
		width=args[1];
	}

	if (args.length>2) {
		height=args[2];
	}

	var newwin = window.open(url, 'newWin'+Math.floor(Math.random()*1000), 'width='+width+',height='+height+',scrollbars=no,resizable=no');
}

/**
 * Standard popup window open The first parameter will be the new URL. Subsequent parameters will be (if supplied) the width and height. If not specified the width and height will be 500 and 200 respectively. 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no,
 * scrollbars=no, width=300, height=200');
 */
function openCustomWin() {
	var url, width=500, height=200, toolbar=""; args = arguments; menubar="";scrollbars="";resizable="";screenX=200;screenY=200;
	url = args[0];
	if (args.length>1) {
		width=args[1];
	}

	if (args.length>2) {
		height=args[2];
	}

	if (args.length>3) {
		if (args[3]) {
			toolbar="toolbar=yes";
		}
	}

	if (args.length>4) {
		if (args[4]) {
			menubar="menubar=yes";
		}
	}

	if (args.length>5) {
		if (args[5]) {
			scrollbars="scrollbars";
		}
	}

	if (args.length>6) {
		if (args[6]) {
			resizable="resizable";
		}
	}

	if (args.length>7) {
		if (args[7]) {
			screenX=args[7];
		}
	}

	if (args.length>8) {
		if (args[8]) {
			screenY=args[8];
		}
	}

	var newwin = window.open(url, 'newWin', 'width='+width+',height='+height+','+toolbar+','+menubar+','+scrollbars+','+resizable+','+status+',screenX='+screenX+',screenY='+screenY);
}

function openNonEncodedUrlWin() {
	var url, width=500, height=200, menu=""; args = arguments;
	url = args[0];
	if (args.length>1) {
		width=args[1];
	}

	if (args.length>2) {
		height=args[2];
	}

	if (args.length>3) {
		if (args[3]) {
			menu=",menubar=yes,toolbar=yes";
		}
	}

	var newwin = window.open(url, 'newWin', 'width='+width+',height='+height+',scrollbars,resizable' + menu);
}

// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;
// initialize upon load to let all browsers establish content objects
function initDHTMLAPI () {
	if (document.images) {
		// isCSS = (document.body && document.body.style) ? true : false;
		isCSS = true;
		isW3C = (isCSS && document.getElementById) ? true : false;
		isIE4 = (isCSS && document.all) ? true : false;
		isNN4 = (document.layers) ? true : false;
		isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	}
}

// seek nested NN4 layer from string name
function seekLayer(doc, name) {
	var theObj;
	for (var i=0; i < doc.layers.length; i++) {
		if (doc.layers[i].name == name) {
			theObj = doc.layers[i];
			break;
		}

		// dive into nested layers if necessary
		if (doc.layers[i].document.layers.length > 0) {
			theObj = seekLayer(document.layers[i].document, name);
		}
	}

	return theObj;
}

// convert object name string or object reference
// into a valid element object reference

function getRawObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isW3C) {
			theObj = document.getElementById(obj);
		}

		else if (isIE4) {
			theObj = document.all(obj);
		}

		else if (isNN4) {
			theObj = seekLayer(document, obj);
		}
	}

	else {
		// pass through object reference
		theObj = obj;
	}

	return theObj;
}

// Convert object name string or object reference
// into a valid style (or NN4 layer) reference

function getObject(obj) {
	var theObj = getRawObject(obj);
	if (theObj && isCSS) {
		theObj = theObj.style;
	}

	return theObj;
}

// position the object at a specific pixel coordinate

function shiftTo(obj, x, y) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isCSS) {
			// equalize incorrect numeric value type
			var units = (typeof theObj.left == "string") ? "px" : 0;
			theObj.left = x + units;
			theObj.top = y + units;
		}

		else if (isNN4) {
			theObj.moveTo(x,y);
		}
	}
}

// move an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isCSS) {
			// equalize incorrect numeric value type
			var units = (typeof theObj.left == "string") ? "px" : 0;
			theObj.left = getObjectLeft(obj) + deltaX + units;
			theObj.top = getObjectTop(obj) + deltaY + units;
		}

		else if (isNN4) {
			theObj.moveBy(deltaX, deltaY);
		}
	}
}

// set the Z order of an object
function setZIndex(obj, zOrder) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.zIndex = zOrder;
	}
}

// set the background color of an object
function setBGColor(obj, color) {
	var theObj = getObject(obj);
	if (theObj) {
		if (isNN4) {
			theObj.bgColor = color;
		}

		else if (isCSS) {
			theObj.backgroundColor = color;
		}
	}
}

// set the visibility of an object to visible
function show(obj) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.display = "block";
	}
}

// set the visibility of an object to visible (inline)
function showInline(obj) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.display = "inline";
	}
}

// set the visibility of an object to hidden
function hide(obj) {
	var theObj = getObject(obj);
	if (theObj) {
		theObj.display = "none";
	}
}

// retrieve the x coordinate of a positionable object
function getObjectLeft(obj) {
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(elem, "");
		result = cssDec1.getPropertyValue("left");
	}

	else if (elem.currentStyle) {
		result = elem.currentStyle.left;
	}

	else if (elem.style) {
		result = elem.style.left;
	}

	else if (isNN4) {
		result = elem.left;
	}

	return parseInt(result);
}

function getObjectTop(obj) {
	var elem = getRawObject(obj);
	var result = 0;
	if (document.defaultView) {
		var style = document.defaultView;
		var cssDec1 = style.getComputedStyle(elem, "");
		result = cssDec1.getPropertyValue("top");
	}

	else if (elem.currentStyle) {
		result = elem.currentStyle.top;
	}

	else if (elem.style) {
		result = elem.style.top;
	}

	else if (isNN4) {
		result = elem.top;
	}

	return parseInt(result);
}

// retrieve the rendered width of an element
function getObjectWidth(obj) {
	var elem = getRawObject(obj);
	var result = 0;
	if (elem.offsetWidth) {
		if (elem.scrollWidth && (elem.offsetWidth != elem.scrollWidth)) {
			result = elem.scrollWidth;
		}

		else {
			result = elem.offsetWidth;
		}
	}

	else if (elem.clip && elem.clip.width) {
		result = elem.clip.width;
	}

	else if (elem.style && elem.style.pixelWidth) {
		result = elem.style.pixelWidth;
	}

	return parseInt(result);
}

// return the rendered height of an element
function getObjectHeight(obj) {
	var elem = getRawObject(obj);
	var result = 0;
	if (elem.offsetHeight) {
		result = elem.offsetHeight;
	}

	else if (elem.clip && elem.clip.height) {
		result = elem.clip.height;
	}

	else if (elem.style && elem.style.pixelHeight) {
		return elem.style.pixelHeight;
	}

	return parseInt(result);
}

// return available content width space in browser window
function getInsideWindowWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	}

	else if (isIE6CSS) {
		// measure the HTML element's clientWidth
		return document.body.parentElement.clientWidth;
	}

	else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}

	return 0;
}

// return the available content height space in the browser window
function getInsideWindowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	}

	else if (isIE6CSS) {
		// measure the HTML element's clientWidth
		return document.body.parentElement.clientHeight;
	}

	else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}

	return 0;
}

function printPage() {
	if (window.print)
	window.print()
	else
	alert( "Sorry, your browser doesn't support this feature. Please use the Print menu option of this browser to print the page. " );
}

function disableButton(theButton) {
	theButton.value="Processing...";
	theButton.disabled = true;
	theButton.form.submit();
}

function submitForm(myForm) {
	myForm.submit( );
	submitForm = blockIt;
	return false;
}

function submitEncryptedLoginForm(myform) {
	var oldPassword = myform.password.value;
	myform.password.value = base64encode(utf16to8(myform.password.value));
	myform.submit( );
	myform.password.value = oldPassword;
	submitEncryptedLoginForm = blockIt;
	return false;
}

function enterSubmitLogin(myform) {
	if (window.event && window.event.keyCode == 13) {
		submitEncryptedLoginForm(myform);
		enterSubmitLogin = blockIt;
	}

	else
	return true;
}

function enterSubmit(myform) {
	if (window.event && window.event.keyCode == 13) {
		submitForm(myform);
		enterSubmit = blockIt;
	}
	else
	return true;
}

function blockIt( ) {
	return false;
}

var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

function base64encode(str) {
	var out, i, len;
	var c1, c2, c3;
	len = str.length;
	i = 0;
	out = "";

	while(i < len) {
		c1 = str.charCodeAt(i++) & 0xff;

		if(i == len) {
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt((c1 & 0x3) << 4);
			out += "==";
			break;
		}

		c2 = str.charCodeAt(i++);

		if(i == len) {
			out += base64EncodeChars.charAt(c1 >> 2);
			out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
			out += base64EncodeChars.charAt((c2 & 0xF) << 2);
			out += "=";
			break;
		}

		c3 = str.charCodeAt(i++);
		out += base64EncodeChars.charAt(c1 >> 2);
		out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
		out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
		out += base64EncodeChars.charAt(c3 & 0x3F);
	}

	return out;
}

function utf16to8(str) {
	var out, i, len, c;
	out = "";
	len = str.length;

	for(i = 0; i < len; i++) {
		c = str.charCodeAt(i);

		if ((c >= 0x0001) && (c <= 0x007F)) {
			out += str.charAt(i);
		}
		else if (c > 0x07FF) {
			out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
			out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		}
		else {
			out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));
			out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));
		}
	}

	return out;
}

function toggleShippingFields(theForm) {
	if (theForm.useBillingAsShipping.checked) {
		theForm.firstNameShipping.value = "";
		theForm.lastNameShipping.value = "";
		theForm.addressShipping.value = "";
		theForm.address2Shipping.value = "";
		theForm.cityShipping.value = "";
		theForm.zipcodeShipping.value = "";
		theForm.countryShipping.value = "";
		theForm.saveShippingAddress.checked = false;

		theForm.firstNameShipping.disabled = true;
		theForm.lastNameShipping.disabled = true;
		theForm.addressShipping.disabled = true;
		theForm.address2Shipping.disabled = true;
		theForm.cityShipping.disabled = true;
		theForm.zipcodeShipping.disabled = true;
		theForm.countryShipping.disabled = true;
		theForm.saveShippingAddress.disabled = true;
	}
	else {
		theForm.firstNameShipping.disabled = false;
		theForm.lastNameShipping.disabled = false;
		theForm.addressShipping.disabled = false;
		theForm.address2Shipping.disabled = false;
		theForm.cityShipping.disabled = false;
		theForm.zipcodeShipping.disabled = false;
		theForm.countryShipping.disabled = false;
		theForm.saveShippingAddress.disabled = false;
	}
}
