//Added on June 2nd, 2004, autoLoginLegacy() function
function autoLoginLegacy(url)
{
	if (url==null) {
		var viewAs = readCookie("VIEW_AS");

			//url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_LOGIN&KPage_Action=AUTO_LOGIN&LFGPage=/lfg/leg/secure.html";
			url = "https://"+location.host+"/LincolnPageServer?KPage_PageID=VIEW_LOGIN&KPage_Action=AUTO_LOGIN&LFGPage=/lfg/leg/log/index.html";
			
	}

	location.href=url;
	return url;	

}
 


function getCookie(Name) {
  var search = Name + "=";
  if (document.cookie.length > 0) {
    //if there are any cookies
    offset = document.cookie.indexOf(search);
    if (offset != -1) {
      //if cookie exists
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
        end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
    }
  }
 return null;
}

function searchFieldHasValue(theField)
{
	var theValue = theField.value.replace(/\W/g, "");
	if (theValue.length == 0)
	{
		alert("Please enter text to search before clicking \"Search\".");
		theField.select();
		theField.focus();
		return false;
	}
	else
		return true;
}

var relArticles = new Object();

function redirectToParent(href)
{
	if (top.opener && !top.opener.top.closed)
	{
		top.opener.top.location.href = href;
		top.opener.top.focus();
	}
	else
		top.location.href = href;
} 

function getRelated(articleKey)
{
	var dest = relArticles[articleKey];
	if (dest) return dest;
	return "";
}

function getRelatedURL(articleKey)
{
	var dest = getRelated(articleKey);
	var a = dest.indexOf("(");
	if (++a > 0)
	{
		var b = dest.indexOf(",", a);
		if (b == -1)
			b = dest.lastIndexOf(")");
		dest = dest.substring(a, b);
		if (dest.indexOf("(") != -1)
			dest = eval(dest);
		return dest;
	}
	else
		return "";
}

function goToRelated(articleKey)
{
	var dest = getRelated(articleKey);
	if (dest && dest.length) eval(dest);
}

function writeRelated(articleKey)
{
	var key, query = articleKey.indexOf("?"), hash = articleKey.indexOf("#");
	var split1 = Math.min(query, hash), split2 = Math.max(query, hash);
	if (split2 == -1) split2 = articleKey.length;
	if (split1 == -1) split1 = split2;
	key = articleKey.substring(0, split1);
	split1 = articleKey.substring(split1, split2);
	split2 = articleKey.substring(split2, articleKey.length);
	if (query == hash)
		query = hash = "";
	else if (query > hash)
	{
		hash = split1;
		query = split2.substring(1, split2.length);
	}
	else
	{
		hash = split2;
		query = split1;
		if (query.length > 0)
			query = query.substring(1, query.length);
	}
	var dest = getRelated(key);
	if (dest && dest.length)
	{
		if (hash.length > 0 || query.length > 0)
		{
			var url = getRelatedURL(key);
			if (query.length > 0)
			{
				query = query.replace(/%/g, "%25__");
				query = (url.indexOf("?") == -1 ? "?" : "&") + query;
			}
			url = url + query + hash;
			var a = dest.lastIndexOf(")");
			var b = dest.indexOf(")");
			if (b == a) b = dest.indexOf("(") + 1;
			var contents = dest.substring(b, a);
			contents = contents.split(",");
			contents[0] = "";
			dest = "goTo('" + url + "'" + contents.join() + ")";
		}
		document.write("<" + "a href=\"javascript:" + dest + "\">");
	}
	else
		document.write("<" + "a>");
}

function writeRelatedToParent(articleKey)
{
	var key = articleKey.indexOf("#"), hash = "";
	if (key == -1)
		key = articleKey;
	else
	{
		hash = articleKey.substring(key, articleKey.length);
		key = articleKey.substring(0, key);
	}
	var dest = getRelatedURL(key);
	if (dest && dest.length > 0)
	{
		dest = dest + hash;
		document.write("<a href=\"" + dest + "\" onClick=\"redirectToParent(this.href); return false\">");
	}
	else
		document.write("<a>");
}

function writeGlossaryLink(glossaryTerm)
{
	writeRelated("glossary#" + glossaryTerm);
}

function goTo(url, winName, features)
{
	var	tempVar = null;
	var feats = features ? features : null;
	url = url.replace(/%(25)?__/g, "%");
	if (feats == null)
		tempVar = window.open(url, winName ? winName : "_top");
	else
		tempVar = window.open(url, winName ? winName : "_top", feats);
	tempVar.focus();
}

function fundStr(tickerSymbol, pointer)
{
	return "/servlet/ContentServer?pagename=rpweb/fund&pointerID=" + pointer + "&tickerID=" + tickerSymbol;
}

function fund(tickerSymbol, pointer)
{
	top.location.href = fundStr(tickerSymbol, pointer);
}

function contentStr(articleID, pointer)
{
	var fieldName = articleID.length < 12 || articleID.replace(/\d/g, "").length > 0 ? "name" : "cid";
	var out = "/servlet/ContentServer?pagename=rpweb/content&" + fieldName + "=" + articleID;
	if (pointer) out += "&pointerID=" + pointer;
	return out;
}

function content(articleID, pointer)
{
	if (pointer)
		top.location.href = contentStr(articleID, pointer);
	else
		top.location.href = contentStr(articleID);
}