/*
 CA Library
 Version: 1.3
 */
var m_isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
var m_isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; // true if we're on windows
var m_jsVersion = 1.1;

//Allows for page sections to rotate using browser cookies.
//Takes an array of strings in 'ads' and a specific 'sSectionName' to store the cookie.
//Writes directly into the document object
function insertAdvertisement(ads, sSectionName)
{
  var lastAdIndex = -1;
  var allCookies = document.cookie;
  var pos = allCookies.indexOf( sSectionName + "=")
  if(pos != -1)
  {
   	var start = pos +  sSectionName.length + 1;
	var end = allCookies.indexOf(";",start);
	if (end == -1) end = allCookies.length;
	value = allCookies.substring(start, end);
	value = unescape(value);
	lastAdIndex = value;
   }   
   var newAdIndex = ++lastAdIndex;

   if (newAdIndex >= ads.length) newAdIndex = 0;
   document.cookie =  sSectionName + "=" + newAdIndex;	
   document.write (ads[newAdIndex]);
}

//Takes a UTC date string and outputs a localized date
//Depends on a locale file to be included by page
function insertDate(sDate, dateFormatLength)
{
	if(sDate.length >0)
	{
		var sDateFormat = '';
		for(var i = 0; i < m_dateFormats.length; i++)
			if (m_dateFormats[i][0] == dateFormatLength)
				sDateFormat = m_dateFormats[i][1];
		if(sDateFormat == '') sDateFormat = dateFormatLength;

		if(sDateFormat != '')
		{
			var dateParts = (sDate.split('T')[0]).split('-');

			sDate = sDateFormat.replace('yyyy',dateParts[0]);
			sDate = sDate.replace('yy',dateParts[0].substring(2,4));

			sDate = sDate.replace('dd', ("0" + dateParts[2]).substring(dateParts[2].length-1,dateParts[2].length+1));
			sDate = sDate.replace('d', dateParts[2]);
			sDate = sDate.replace('MMMM', m_MonthsWide[dateParts[1]-1]);
			sDate = sDate.replace('MMM', m_MonthsAbbreviated[dateParts[1]-1]);
			sDate = sDate.replace('MM', dateParts[1]);
			sDate = sDate.replace('mmmm', m_MonthsWide[dateParts[1]-1]);
			sDate = sDate.replace('mmm', m_MonthsAbbreviated[dateParts[1]-1]);
			sDate = sDate.replace('mm', dateParts[1]);
			var d1 = new Date(dateParts[0],dateParts[1]-1,dateParts[2]);

			sDate = sDate.replace('EEEE', m_DaysWide[d1.getDay()]);
			sDate = sDate.replace('EEE', m_DaysAbbreviated[d1.getDay()]);

			document.write (sDate);			 
		}
	}
}

function languageCheck(sLanguageISO, sLanguage)
{
	var sLocale;

	sLocale = _page.locale;
	if(sLocale == 'global') sLocale = 'us_en';

	if(sLocale.indexOf(sLanguageISO,2) == -1)
		return confirm(_page.text["confirmation2"].replace('{LANGUAGE}',sLanguage));
}

function rotateContent(element)
{
	var divs = element.getElementsByTagName("DIV");
	var lis = element.getElementsByTagName("LI");
	var sSectionName = element.id;
	var lastAdIndex = -1;
	var c;
	
	c = getCookie(sSectionName);
	if (c != null) lastAdIndex = c;
	var newAdIndex = ++lastAdIndex;
	if ((newAdIndex >= divs.length && divs.length) || (newAdIndex >= lis.length && lis.length)) newAdIndex = 0;
	setCookie(sSectionName, newAdIndex);
	
	if (divs.length) divs[newAdIndex].className = divs[newAdIndex].className.replace('hide','');
	if (lis.length) lis[newAdIndex].className = lis[newAdIndex].className.replace('hide','');
}

function setURLTarget(link, sTarget)
{
	link.target = sTarget;
	return true;
}

function printPage()
{
	if (document.getElementById != null)
	{
		var html;
		html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n'
		html += '<html xmlns="http://www.w3.org/1999/xhtml">\n<head>\n';

		if (document.getElementsByTagName != null)
		{
			var headTags = document.getElementsByTagName("head");
			if (headTags.length > 0)
				html += headTags[0].innerHTML;
		}
		
		html += '\n</head>\n<body class=\"print\"><div id=\"pageLayout\"><div id=\"topnav\" class=\"clearfix\"><div id=\"enclosure\" class=\"clearfix\"><div id=\"main-content\"><div id=\"sectionb\" class=\"clearfix\"><div id=\"#container3\">\n';
		
		var printReadyElem = document.getElementById("container3");
		
		if (printReadyElem != null)
			html += printReadyElem.innerHTML;
		else
		{
			window.print();
			return;
		}
			
		html += '</div></div></div></div></div></div>\n</body>\n</html>';
		
		var printWin = window.open("","printSpecial");
		printWin.document.open();
		printWin.document.write(html);
		printWin.document.close();
		printWin.print();
	}
	else
		window.print();
}

function emailLink(sSubject, sBody) 
{
	var s = sSubject;
	var b = sBody;

	s = s.replace('%TITLE%', document.title)	
	s = s.replace('%LOCATION%', document.location)	
	b = b.replace('%TITLE%', document.title)	
	b = b.replace('%LOCATION%', document.location)	

	window.location = 'mailto:?subject=' + s + '&body=' + b;
}

function constructPanel(element)
{
	element.className = element.className.replace('hide','');
	element.parentNode.className = element.parentNode.className.replace('hide','');
	element.parentNode.parentNode.className = element.parentNode.parentNode.className.replace('hide','');
}

function constructSubscriptionPanel(element)
{
	var divs = element.getElementsByTagName("DIV");
	var forms = element.getElementsByTagName("FORM");
	var i;
	var sBody;
	var sSubcrCode = getCookie('subscrcode');
	var bShowParents = 0;
	
	if (getCookie("Subscribed") == null && sSubcrCode == '0') sSubcrCode = null;

	if (sSubcrCode != null)
	{
		for(i =0; i < divs.length;i++) 
		{
			bShowParents = 1;
			divs[i].className = divs[i].className.replace('hide','');
			sBody = getCookie('subscrmsg');
			sBody = sBody.replace("%Name%",getCookie("Name"));
			
			divs[i].innerText = sBody;
		}
	}
	else
		if (getCookie("Subscribed") == null)
			for(i = 0; i < forms.length;i++) 
			{
				bShowParents = 1;
				forms[i].className = forms[i].className.replace('hide','');
			}
	if (bShowParents) constructPanel(element);
}

function constructPollPanel(element, pollId)
{
	var divs = element.getElementsByTagName("DIV");
	var forms = element.getElementsByTagName("FORM");
	var i;
	var sBody;
	var hasPolled = getCookie('poll' + pollId) != null;
	var bShowParents = 0;

	if (hasPolled)
	{
		for(i =0; i < divs.length;i++) 
		{
			bShowParents = 1;
			divs[i].className = divs[i].className.replace('hide','');
		}
	}
	else
	{
		for(i = 0; i < forms.length;i++) 
		{
			bShowParents = 1;
			forms[i].className = forms[i].className.replace('hide','');
		}
	}
	if (bShowParents) constructPanel(element);
}


function constructLoginPanel(logonPanel, logonForm, logonError, logonSuccess,changelogonForm,chpwdError,pwdchangedSuccess,logonBefore)
{
	var element= null;
	var bShowParents = 0;
	var sClientLogonStatus = getCookie("ClientLogonStatus");
	var clientBadge = getCookie("ClientBadge");
 
	if (sClientLogonStatus == null) sClientLogonStatus = '';
	if (clientBadge == null) clientBadge = '';

	switch(sClientLogonStatus)
	{
		case 'pwdchgd':
			if(pwdchangedSuccess != null)
				pwdchangedSuccess.className = pwdchangedSuccess.className.replace('hide','');
			bShowParents = 1;
			element = pwdchangedSuccess;
			break;
		case 'badpwd':
			if(changelogonForm != null)
				changelogonForm.className = changelogonForm.className.replace('hide','');
			if(chpwdError != null)
				chpwdError.className = chpwdError.className.replace('hide','');
			bShowParents = 1;
			element = chpwdError;
			break;
		case 'chpwd':
			if(changelogonForm != null)
				changelogonForm.className = changelogonForm.className.replace('hide','');

			bShowParents = 1;
			element = changelogonForm;
			break;
		case 'error':
			if(logonError != null)
				logonError.className = logonError.className.replace('hide','');
			if(logonForm != null)
				logonForm.className = logonForm.className.replace('hide','');
			bShowParents = 1;
			element = logonError;
			break;
		case 'ok':
			if(logonSuccess != null)
			{
				var sHTML = logonSuccess.innerHTML.replace("[Name]",getCookie("Name"));
				logonSuccess.innerHTML = sHTML;
				logonSuccess.className = logonSuccess.className.replace('hide','');
			}
			element = logonSuccess;
			bShowParents = 1;
			break;
		default:
			if (clientBadge == '')	//Display the logon form
			{
				bShowParents = 1;
				if(logonForm != null)
					logonForm.className = logonForm.className.replace('hide','');
				element = logonForm;
			}
			else
			{
				if(logonBefore != null)
					logonBefore.className = logonBefore.className.replace('hide',''); 			
				element = logonBefore;
			}
			bShowParents = 1
			break;
	}
	
	if (bShowParents) constructPanel(element);
}

function constructLogoffButton(logoffElement)
{
    if(logoffElement != null)
    {   
        var sStatus;
		var sClientLogonStatus = getCookie("ClientLogonStatus");
		var clientBadge = getCookie("ClientBadge");
		
		if (sClientLogonStatus == null) sClientLogonStatus = '';
		if (clientBadge == null) clientBadge = '';

        if (clientBadge == '')
            logoffElement.style.display = 'none';
        else
            logoffElement.style.display = 'inline';
     }
}

function getURLParameter(sName)
{
	var v = document.URL.split('?');
	var i;
	
	if (v.length > 1)
		v = v[1].split('&');

	for (i=0; i < v.length; i++)
	{
		var p = v[i].split('=');
		if(p[0].toLowerCase() == sName.toLowerCase())
			if(p.length>1) return unescape(p[1]);
	}
	return null;
}

function getCookieVal(offset) 
{
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
 
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function fixCookieDate(date) 
{
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

function deleteCookie(name,path,domain) 
{
  if (getCookie(name)) 
  {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Fri, 02-Jan-70 00:00:00 GMT";
  }
}
function setCookie(name,value,expires,path,domain,secure) 
{
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function getCookie(name) 
{
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}

function leavePage(e)
{
	var aDate = new Date();
	
	aDate.setTime(aDate.getTime() + 3000);
	setCookie("NR","1",aDate);
}

var m_flash2Installed = false;
var m_flash3Installed = false;
var m_flash4Installed = false;
var m_flash5Installed = false;
var m_flash6Installed = false;
var m_flash7Installed = false;
var m_flash8Installed = false;
var m_flash9Installed = false;
var m_maxVersion = 9;             // highest version we can actually detect
var m_actualVersion = 0;          // version the user really has
var m_hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var m_requiredVersion = 7;   // Version the user needs to view site (max 9, min 2)

if(m_isIE && m_isWin)
{
	document.write('<scr' + 'ipt type="text/vbscript"\> \n');
	document.write('on error resume next \n');
	document.write('m_flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('m_flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('m_flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('m_flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	document.write('m_flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	document.write('m_flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('m_flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	document.write('m_flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
	document.write('<\/scr' + 'ipt\> \n'); // break up end tag so it doesn't end our script
}

function detectFlash() 
{  
	if (navigator.plugins) 
	{
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
		{
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
			var flashVersion = parseInt(flashDescription.substring(16));
			m_flash2Installed = flashVersion == 2;    
			m_flash3Installed = flashVersion == 3;
			m_flash4Installed = flashVersion == 4;
			m_flash5Installed = flashVersion == 5;
			m_flash6Installed = flashVersion == 6;
			m_flash7Installed = flashVersion == 7;
			m_flash8Installed = flashVersion == 8;
			m_flash9Installed = flashVersion >= 9;
		}
	}
  
	for (var i = 2; i <= m_maxVersion; i++) 
		if (eval("m_flash" + i + "Installed") == true) m_actualVersion = i;
  
	if(navigator.userAgent.indexOf("WebTV") != -1) m_actualVersion = 4;  
  
	if (m_actualVersion >= m_requiredVersion) 
	{
		m_hasRightVersion = true;                
	} 
}

function openWindow(sName, shref,popup_width,popup_height)
{
	var w=window.open(shref,sName,'height='+popup_height+',width='+popup_width+',toolbar=no,scrollbars=yes')
	var intwidt;
	var intheight;
	intwidth=screen.availWidth;
	intheight=screen.availHeight;
	intwidth=parseInt(intwidth);
	intheight=parseInt(intheight);
	if(intwidth>0&&intheight>0)
	{
		w.moveTo(((intwidth-popup_width) / 2), ((intheight - popup_height) / 2));
		w.focus();
	}
}
function cleanupForm(aForm)
{
	var inputs = aForm.getElementsByTagName("input");
	var i;
	
	for (i = 0; i< inputs.length; i++)
	{
		if(inputs[i].type == 'checkbox')
		{
			if(inputs[i].checked == false)
			{
				inputs[i].checked = true;
				inputs[i].value = '';
			}
		}
	}
}

function openFullScreenWindow(shref)
{
	var w=window.open(shref,'_blank','scrollbars=no, fullscreen=yes, resizeable=yes,titlebar=no,status=no',false)
}
