//window.onerror = function() {return true;}
function doCatch(o) {
	alert(o.name);
}
//window.onerror = doCatch(this);

function setActiveStyleSheet(title) {
	if (window.name == 'printfriendly') {
		title="printfriendly";
	}
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

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

function readCookie(name) {
  var nameEQ = 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;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

	function newWindow (name,url)
	{
		var externalLinkRegEx = /^https?:[\/\\]{2}/i;
		var blnPopUpsOffScreen=0;
		var intTop=200;
		var intLeft=200;
		var intHeight=290;
		var intWidth=480;
			var cookieStr = document.cookie;
			var cookieWinRegEx = /CSOFFSCREENPOPUPSALLOWED=\d/i;
			var rxVal = /\d+/;
			try
			{
				if (cookieStr && cookieStr.match(cookieWinRegEx))
				{
					var strVal=cookieStr.match(cookieWinRegEx);
					if (strVal)
						blnPopUpsOffScreen=strVal.toString().match(rxVal);
					else
						blnPopUpsOffScreen = 0;
				}
				else
					blnPopUpsOffScreen=0;
			}
			catch (oErr)
			{
				blnPopUpsOffScreen=0;
			}
			if(blnPopUpsOffScreen==1)
			{
				intTop=window.screen.height - 9;
				intLeft=window.screen.width - 9;
				intHeight=1;
				intWidth=1;
			}
			else
			{
				intTop=(window.screen.height / 2) - 109;
				intLeft=(window.screen.width / 2) - 210;
				intHeight=218;
				intWidth=421;
			}
			if(!url.match(externalLinkRegEx) && url.indexOf('kurrentPageID') == -1)
			{
				try
				{
					if( url.indexOf ('?') == -1 )
						url = url + '?kurrentPageID=' + kurrentPageID;
					else
						url = url + '&kurrentPageID=' + kurrentPageID;
				}
				catch (oErr)
				{ /* Do Nothing */ }
			}
		var re = new RegExp();
		re = /&amp;/gi;
		url = url.replace(re,"&");
		if(url.search(/[\/\\]/g) >= 0 && blnPopUpsOffScreen==0)
		{
			if(document.CS_StaticURL && window.location.href.indexOf(document.CS_StaticURL) == -1)
				url = '/commonspot/utilities/longproc.cfm?onlyurlvars=1&url=' + escape(url);
		}
		var strWinOptions = 'toolbar=no,resizable=yes,scrollbars=yes,menubar=no,location=no';
		if(arguments.length >= 2 && arguments[2])
		{
			var strOptions=arguments[2];
			var strTopPos=strOptions.match(/top=\s*(\d+)/i);
			if(strTopPos && strTopPos[1] >=0)
			{
				intTop=strTopPos[1];
				strOptions=strOptions.replace(/top=\s*\d+\s*,?/i,'')
			}
			var strLeftPos=strOptions.match(/left=\s*(\d+)/i);
			if(strLeftPos && strLeftPos[1] >=0)
			{
				intLeft=strLeftPos[1];
				strOptions=strOptions.replace(/left=\s*\d+\s*,?/i,'')
			}
			var strHeight=strOptions.match(/height=\s*(\d+)/i);
			if(strHeight && strHeight[1] >=0)
			{
				intHeight=strHeight[1];
				strOptions=strOptions.replace(/height=\s*\d+\s*,?/i,'')
			}
			var strWidth=strOptions.match(/width=\s*(\d+)/i);
			if(strWidth && strWidth[1] >=0)
			{
				intWidth=strWidth[1];
				strOptions=strOptions.replace(/width=\s*\d+\s*,?/i,'')
			}
			var strWinOptions = strOptions;
		}
		strWinOptions = strWinOptions + ',top='+ intTop + ',left=' + intLeft + ',height=' + intHeight + ',width=' + intWidth;
			var winWindow=window.open(url,name,strWinOptions);
		if (!winWindow)
			alert('Unable to open window - please make sure the pop-up blocker is disabled for this site');
		if(arguments.length==4 && arguments[3]==1 && winWindow)
			return winWindow;
	}
	  function openCustomWindow(newURL)
  {
    var w = 800, h = 600;
	if (document.all || document.layers)
	{
	  w = screen.availWidth;
	  h = screen.availHeight;
	}
	var popW = 800, popH = 600;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	newCustomWindow = window.open(newURL,'popup','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=yes' + ',resizable=yes');
	newCustomWindow.opener = window;
	newCustomWindow.focus();
  }