// Copyright (c) 2005 IBM Corp. All rights reserved.
// $Id$

// ibmCommonLenovoLinkPopup shows a popup notice, if a clickthrough parameter is provided once per session as per CR043
//
// Assumptions:
// JavaScript 1.2 is supported and enabled
// If session cookies are not enabled the popup will be shown for every invocation
// The alternate version will be handled outside of the script
//
// Usage:
// <script type="text/javascript" language="JavaScript1.2" src="//www.pescasen.com/common/lenovo/link.js"></script>
//
// <a href="fullnotice.html" onclick="return ibmCommonLenovoLinkPopup('popupnotice.html')">Link description</a>
// or
// <a href="fullnotice.html" onclick="return ibmCommonLenovoLinkPopup('popupnotice.html', 'target.html')">Link description</a>

// Load cookie library if needed
if (typeof ibmCommonCookie == 'undefined') {
document.write('<script type="text/javascript" language="JavaScript1.2" src="//www.pescasen.com/common/cookie/cookie.js"></script>');
}

function ibmCommonLenovoLinkPopup(popupurl, clickurl) {
	var c = new ibmCommonCookie();
	var name = 'ibmCommonLenovoLinkPopup';
	var value = 'shown';

	var host = window.location.host.toString().toLowerCase() || '';
	if (typeof(popupurl) != "undefined" &&
		popupurl &&
		host.indexOf(".ibm.com") != -1) {

		// follow link without popup if clickurl is provided and valid and cookie is set
		if (typeof(clickurl) == "string" &&
			clickurl &&
			c.getCookie(name)) {
			window.location.href = clickurl;
			return false;
		}
		// show popup if popupurl defined but clickurl not defined or cookie not set
		else {
			c.setCookie(name, value, 0, window.location.pathinfo, host);
			var w = window.open(popupurl, 'ibmCommonLenovoLinkWindow', 'width=550,height=350,screenX=30,screenY=20,top=20,left=30,status=yes,location=no,toolbar=no,directories=no,menubar=no,resizable=yes,scrollbars=yes');
			if (typeof(w) == "object" && w && !w.closed) {
				if (typeof w.opener == "undefined") {
					w.opener = window;
				}
				w.focus();
				return false;
			}
		}
	}

	// Use noscript alternative in all other cases
	return true;
}
//