// $Header: /export/www/htdocsdev/fmr_usair/RCS/usair.js,v 1.54.1.2 2010/06/14 14:46:46 rich Exp $

global_main_img_src = '';

var curImage = 0;	//keep track of last image displayed
var maxImages = 3;
var fadeMSOpacityAmt = 5;	//percent fade for each interval
var fadeMSInterval = 40;	//millisecs per image level fade
var exchMSInterval = 10000;	//millisecs per image swap (10 sec = 10000ms)
var arrImages = new Array();
var timerObj = '';
for (i=1; i<= maxImages; ++i) {
    arrImages[i] = new Image();
    arrImages[i].src = 'images/joinus' + i + 'nt.png';
}

//######################################################

function navbuttons_off() {
    document.getElementById('nav_prog').className='pagenavbuttons nav_prog_OFF';
    document.getElementById('nav_news').className='pagenavbuttons nav_news_OFF';
    document.getElementById('nav_find').className='pagenavbuttons nav_find_OFF';
    document.getElementById('nav_contactus').className='contactusbutton nav_contactus_OFF';
} //navbuttons_off

//######################################################

/* manage button nav states and page content for main panel (Prog Basics, News/Insights, Find Res, Contact Us) */
function main_button_nav(pagename,subpagename) {
    /* turn state off for the three main nav buttons - selected one is set below */
    navbuttons_off();
    /* if Program Basics is selected, handle content using the popup; */
    /* when user selects a group from the popup, we'll come here again with subpagename defined */
    if (pagename == "nav_prog" && subpagename == "") {
	makeModal('nav_prog', 'pb-popup', -20, -80, 'pb-popup-ie6');
	clearPopupFields('pb-popup');
	return;
    }

    /* Change background image and turn on red bottom border for detailed content pages; */
    /* note that nav back to home page must turn the border off and reset the background image. */
    /* This is (currently) done via the USAirways logo (clickable to go to home page). */
    /* Background image in the middle (1px high) gets stretched in height to fit content in main-iframe. */
    document.getElementById('main-iframe-border').style.display = 'block';
    document.getElementById('background_page').innerHTML = ''
	+ '<DIV><IMG src="images/background_detail_top.png" /></DIV>\n'
	+ '<DIV id="bgimg"><IMG src="images/background_detail_mid.png" id="background_repeat" style="width: 954px; height: 1px;"/></DIV>\n'
	+ '<DIV><IMG src="images/background_detail_bot.png" /></DIV>\n'
	;
    if (document.getElementById(pagename) && pagename == "nav_contactus")
	document.getElementById('nav_contactus').className='contactusbutton nav_contactus_ON';
    else if (document.getElementById(pagename))
	document.getElementById(pagename).className='pagenavbuttons ' + pagename + '_ON';

    /* "Five Things" graphic needs to remain visible on Program Basics page(s) */
    if (pagename == "nav_prog")
	document.getElementById('five_things').style.display = "block";
    else
	document.getElementById('five_things').style.display = "none";
    document.getElementById('prof_banner').style.display = "none";
    document.getElementById('prof_stats').style.display = "none";
    document.getElementById('prof_headshots').style.display = "none";
    document.getElementById('home_content').style.display = "none";

    var frameobj = document.getElementById('main-iframe');
    if (pagename == "nav_contactus")  {
	document.getElementById('newsbox').innerHTML = " "
	    + "<DIV id='newsbox_content' style='padding-top: 5px; padding-bottom: 5px;'>\n"
	    + "<A href='#' onClick='elink(\"http://e-learning.netbenefits.com\")'>Set up Your Personal Identification Number (PIN)</A>\n"
	    + "<br />\n"
	    + "To manage your US Airways 401(k) Savings Plan account online or by phone, you'll need to create\n"
	    + "a Personal Identification Number (PIN).\n"
	    + "</DIV>\n"
	    ;
	frameobj.style.display = "block";
	frameobj.src = pagename + '.phtml';
    } else if (pagename == "nav_find")  {
	document.getElementById('newsbox').innerHTML = " "
	    + "<DIV id='newsbox_hdr'>TAKE AN INVESTING WORKSHOP</DIV>\n"
	    + "<DIV id='newsbox_content'>\n"
	    + "<P><A href='#' onClick='elink(\"http://e-learning.netbenefits.com\")'>Create an Investment Profile</A>\n"
	    + "<br />\n"
	    + "Learn how your risk tolerance and time horizon influence your investor profile when\n"
	    + "it comes to saving for retirement.\n"
	    + "</P>\n"
	    + "<P><A href='#' onClick='elink(\"http://e-learning.netbenefits.com\")'>Allocating Your Workplace Savings</A>\n"
	    + "<br />\n"
	    + "This workshop teaches you the role of an investment strategy when you are choosing\n"
	    + "investments for your workplace savings plan\n"
	    + "</P>"
	    + "<P><A href='#' onClick='elink(\"http://e-learning.netbenefits.com\")'>Evaluating Investment Options</A>\n"
	    + "<br />"
	    + "Managing your workplace savings includes learning how to evaluate investment options\n"
	    + "to ensure that they are meeting your expectations.\n"
	    + "</P>\n"
	    + "</DIV>\n"
	    ;
	frameobj.style.display = "block";
	frameobj.src = pagename + '.phtml';
    } else if (pagename == "nav_news") {
	document.getElementById('newsbox').innerHTML = " "
	    + "<DIV id='newsbox_hdr'>GET INSIGHT FROM<BR />FIDELITY INVESTMENTS</DIV>\n"
	    + "<DIV id='newsbox_content'>"
	    + "<P><A href='#' onClick='elink(\"http://personal.fidelity.com/products/publications\")'>Fidelity Investor's Weekly</A><BR />\n"
	    + "Investing news, analysis and insights from Fidelity\n"
	    + "</P>\n"
	    + "<P><A href='#' onClick='elink(\"https://news.fidelity.com/news/ArticlePageFragment.jhtml?key=/pf/content/insights/index.html&nodisclaimer=true\")'>Insights</A><BR />\n"
	    + "Insight from experts on current events and the financial markets\n"
	    + "</P>\n"
	    + "</DIV>\n"
	    ;
	frameobj.style.display = "block";
	frameobj.src = pagename + '.phtml';
    } else if (pagename == "nav_prog") {
	var doclink = '';
	var doctitle = '';
	var doclink2 = '';
	var doctitle2 = '';
	switch (subpagename) {
	    case 'pb_non_contract':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_dispatchers':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_passenger_service':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_mech_east':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_mech_west':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_stock_clerks_west':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_fleet_maint_east':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_fleet_maint_west':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_flight_attend_east':
		doctitle = 'US Airways, Inc., Employee<br />Savings Plan';
		doclink = 'pdf/SPD_Employee_Savings_Plan.pdf';
		break;
	    case 'pb_flight_attend_west':
		doctitle = '<b>Future Care:</b> America<br />West Airlines 401(k)<br />Plan - Flight Attendants';
		doclink = 'pdf/SPD_Future_Care_Plan_Flight_Attendants.pdf';
		break;
	    case 'pb_pilots_east':
		/*
		NOTE: This group has two plans, and the panel content allows the user to toggle between the two
		with embedded links under the title used to switch panel content; the default display is the 401k
		plan (see pb_pilots_east_*.phtml); SPD newsbox display is constant - show both SPDs for both pages
		 */
		subpagename += '_401k';	/* other page is '_rsp' - handled by embedded link to switch content */
		doctitle = 'US Airways, Inc., 401(k)<br />Savings Plan for Pilots';
		doclink = 'pdf/SPD_USAirways_401k_Savings_Plan_for_Pilots.pdf';
		doctitle2 = 'Retirement Savings Plan for<br />Pilots of US Airways, Inc.';
		doclink2 = 'pdf/SPD_Retirement_Savings_Plan_for_Pilots.pdf';
		break;
	    case 'pb_pilots_west':
		doctitle = '<b>Future Care:</b><br />America West Airlines<br />401(k) Plan - Pilots';
		doclink = 'pdf/SPD_Future_Care_Plan_Pilots.pdf';
		break;
	}
	var divcontent = "<DIV id='newsbox_hdr'>SUMMARY PLAN DESCRIPTION</DIV>\n"
	    + "<DIV id='newsbox_content'>\n"
	    + "  <DIV class='newsbox_content_pdficon'><IMG src='images/pdf.png'></DIV>\n"
	    + "  <DIV class='newsbox_content_pdflink'><A target='_blank' href='"
	    + doclink + "'>" + doctitle + "</A></DIV>\n"
	    ;
	if (doclink2) {		/* second document display needed */
	    divcontent = divcontent
		+ "  <DIV style='clear: both;'></DIV>\n"
		+ "  <DIV class='newsbox_content_pdficon'><IMG src='images/pdf.png'></DIV>\n"
		+ "  <DIV class='newsbox_content_pdflink'><A target='_blank' href='"
		+ doclink2 + "'>" + doctitle2 + "</A></DIV>\n"
		;
	}
	divcontent += "</DIV>\n";
	document.getElementById('newsbox').innerHTML = divcontent;
	frameobj.style.display = "block";
	frameobj.src = subpagename + '.phtml';
    }
    //re-adjust quicklinks box position to 20px below bottom of SPD box (changes in vertical size based on content)
    var nboxobj = document.getElementById('newsbox');
    document.getElementById('quicklinks').style.top = (nboxobj.offsetHeight + nboxobj.offsetTop + 20) + "px";
    //re-adjust fivethings box position to 20px below bottom of quicklinks box
    var nboxobj2 = document.getElementById('quicklinksid');
    document.getElementById('five_things').style.top = nboxobj2.offsetHeight + nboxobj.offsetHeight + nboxobj.offsetTop + 60 + "px";
} //main_button_nav

//######################################################

function pb_showpg(me) {
    var pagename = me.value;
    unmodalize('pb-popup', 'pb-popup-ie6');
    main_button_nav("nav_prog",pagename);
} //pb_showpg

//######################################################

function elink(myurl) {
    if (myurl == '')
	return;
    if (myurl.indexOf('://') > 0)
	window.open(myurl, 'newwin');	/* external link */
    else
	top.location.href = myurl;	/* internal link */
} //elink

//######################################################

//handle mouse clicks on the employee profile images ("head shots") at the bottom of the main page
function pmouse(stat,what) {
    //get image objects
    var v1 = document.getElementById('prof1');
    var v2 = document.getElementById('prof2');
    var v3 = document.getElementById('prof3');
    var vstats = document.getElementById('prof_stats_img');
    var vcontent = document.getElementById('main_content_img');
    var vclose = document.getElementById('close_button_img');
    if (stat == 0) {	//moved off all images
	vstats.src = 'images/profile_clicktext.png';	//back to "click on..." text
	vstats.style.display = 'block';
	v1.className='profimg png prof1_ON';
	v2.className='profimg png prof2_ON';
	v3.className='profimg png prof3_ON';
    } else if (stat == 1) {		//moved over a photo - dim the other two
	switch (what.id) {
	    case 'prof1':
		v1.className='profimg png prof1_ON';
		v2.className='profimg png prof2_OFF';
		v3.className='profimg png prof3_OFF';
		vstats.src = 'images/profile_lee_stats.png';
		break;
	    case 'prof2':
		v1.className='profimg png prof1_OFF';
		v2.className='profimg png prof2_ON';
		v3.className='profimg png prof3_OFF';
		vstats.src = 'images/profile_carmen_stats.png';
		break;
	    case 'prof3':
		v1.className='profimg png prof1_OFF';
		v2.className='profimg png prof2_OFF';
		v3.className='profimg png prof3_ON';
		vstats.src = 'images/profile_enrique_stats.png';
		break;
	}
	vstats.style.display = 'block';
    } else {			//clicked a photo - undim the others, dim this one and display its content
	vstats.src = '';	//no more stats in profiles banner area (to left of photos)
	vstats.style.display = 'none';
	vclose.style.display = 'block';
	if (timerObj) {
	    clearTimeout(timerObj);
	    timerObj = '';
	}
	switch (what.id) {
	    case 'prof1':
		v1.className='profimg png prof1_OFF';
		v2.className='profimg png prof2_ON';
		v3.className='profimg png prof3_ON';
		vcontent.src = 'images/profile_lee_content.png';
		break;
	    case 'prof2':
		v1.className='profimg png prof1_ON';
		v2.className='profimg png prof2_OFF';
		v3.className='profimg png prof3_ON';
		vcontent.src = 'images/profile_carmen_content.png';
		break;
	    case 'prof3':
		v1.className='profimg png prof1_ON';
		v2.className='profimg png prof2_ON';
		v3.className='profimg png prof3_OFF';
		vcontent.src = 'images/profile_enrique_content.png';
		break;
	}
    }
} //pmouse

//######################################################

function pclose() {			//close ee profile image, redisplay main page "Join US" image(s)
    //get image objects
    var v1 = document.getElementById('prof1');
    var v2 = document.getElementById('prof2');
    var v3 = document.getElementById('prof3');
    var vstats = document.getElementById('prof_stats_img');
    var vclose = document.getElementById('close_button_img');
    //turn the ee images back on
    v1.className='profimg png prof1_ON';
    v2.className='profimg png prof2_ON';
    v3.className='profimg png prof3_ON';
    vclose.style.display = 'none';			//turn off close button
    curImage = 0;					//reset image counter
    load_main_img();					//and start the image cycle again
    vstats.src = 'images/profile_clicktext.png';	//back to "Click on the portraits..." text
} //pclose

//######################################################

function load_main_img() {		//load a random image from the set of 3
    var newImage = curImage+1;
    if (newImage > maxImages)
	newImage = 1;
    var vcontent = document.getElementById('main_content_img');
    if (vcontent && arrImages[newImage].complete) {	//has page finished loading and is image also loaded?
	if (curImage == 0) {	//first time called
	    curImage = newImage;
	    vcontent.src = arrImages[curImage].src;
	    fadeImg('main_content_img', 1, 100);
	} else {
	    fadeImg('main_content_img', -1, 100);
	}
    } else {
	timerObj = setTimeout('load_main_img()', 500);
    }
} //load_main_img

//######################################################

function fadeImg(objId, fadedir, opacity) {	//fade from one image to the next on main page
    var obj = document.getElementById(objId);
    if (fadedir < 0 && opacity == 0) {
	//down to 0 on fade OUT - switch images and fade in
	var newImage = curImage+1;
	if (newImage > maxImages)
	    newImage = 1;
	fadedir = 1;			//change fade direction (increasing)
	opacity = 0;			//starting percent
	var vcontent = document.getElementById(objId);
	vcontent.src = arrImages[newImage].src;		//change to new image
	curImage = newImage;		//remember it
    } else if (fadedir > 0 && opacity == 100) {
	//set timer for next image change
	timerObj = setTimeout('load_main_img()', exchMSInterval);
	return;
    }
    setOpacity(obj, opacity);		//set desired opacity on current image
    opacity = opacity + (fadedir < 0 ? -fadeMSOpacityAmt : fadeMSOpacityAmt);	//set next increment for timer call
    setTimeout("fadeImg('" + objId + "'," + fadedir + "," + opacity + ")", fadeMSInterval);
} //fadeImg

//######################################################

function setOpacity(obj, opacity) {
    //avoid FF bug with 100% (causes flicker)
    opacity = (opacity == 100 ? 99.999 : opacity);
    //IE/Win
    obj.style.filter = "alpha(opacity:" + opacity + ")";
    // older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    //Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
} //setOpacity

//######################################################

//resize main-iframe after content has loaded by obtaining the size of the rendered content; this method does not work in FF
function autoIframe(frameId) {
    var doparent = 0;
    myframe = document.getElementById(frameId);
    //we might be called from inside the iframe - need to go to parent
    if (! myframe) {
	myframe = parent.document.getElementById(frameId);
	doparent = 1;
    }
    if (myframe.contentDocument) {
	mydoc = myframe.contentDocument;
    }
    else if (myframe.contentWindow.document) {
	mydoc = myframe.contentWindow.document;
    }
    else {
	mydoc = myframe.document;
    }
    objToResize = (myframe.style ? myframe.style : myframe);//window.alert(document.getElementById('main-iframe').offsetHeight);
    if (navigator.userAgent.indexOf("MSIE") != -1) {
	var mbs = (mydoc.body.scrollHeight == 0? 430:mydoc.body.scrollHeight);
	objToResize.height = mbs + 'px';
	/* resize the middle 1-px high bg image to fit the new content size */
	myimg = (doparent ? parent.document.getElementById("background_repeat") : document.getElementById("background_repeat"));
	myimg.style.height = (mbs - 430) + 'px';
	//objToResize.height = mydoc.body.scrollHeight + 'px';
	//    /* resize the middle 1-px high bg image to fit the new content size */
	//myimg = (doparent ? parent.document.getElementById("background_repeat") : document.getElementById("background_repeat"));
	//myimg.style.height = (mydoc.body.scrollHeight - 430) + 'px';        
    } 
    else {
	objToResize.height = '430px';        /* Mozilla/Firefox gets fixed-height window w/scrollbars, for now */
    }
} //autoIframe

//######################################################

//clear a form of any checked radio buttons 
    function clearPopupFields(formid) {
	var form = document.getElementById(formid) 
	    var elements = form.getElementsByTagName('input');
	var elm, i;
	for (i=0; elm=elements.item(i); i++) {
	    if (elm.getAttribute('type') == 'radio')
		elm.checked = false;
	}
    } //clearPopupFields

//######################################################

//######################################################
// modal popup code - for Contact Us MODAL popup
//######################################################

function makeModal(elid, popid, hoff, voff, iframeid, popid2) {
    //elid - DOM element you want to align the top of the popup with
    //popid - id of DOM element popup (usually a <div>)
    //hoff, voff - (opt) horizontal and vertical offsets (from top-left of elid) to placement of popup
    //iframeid - (opt) iFrame id that, if found, will be used to layer an iframe *under* the popup to fix an IE6 bug with SELECTs
    //popid2 - (opt) id of second DOM element popup that will be used in width calculation for iframeid underlayer
    //  (last arg is needed when popid DIV is composed of two absolute-positioned side-by-side child DIVs)

    //show gray background; explicit sizing of height required for IE6, but need to make it work for all
    document.getElementById('pagemask').style.display = 'inline';
    bhgt = (window.innerHeight ? window.innerHeight :
	    (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight));
    document.getElementById('pagemask').style.height = bhgt + "px";

    //set default offsets
    if (hoff+0 == 0)
	hoff = 200;
    if (voff+0 == 0)
	voff = 20;
    alignTop(elid,popid,hoff,voff);
    //if IE 6.x or below, place an iframe between the popup and the underlying form to hide SELECT dropdowns (hack to fix IE6 bug)
    if (iframeid) {
	var pop = document.getElementById(popid);
	var iframe = document.getElementById(iframeid);
	if (iframe) {           //won't be found if NOT IE 6, since we conditionalized the <IFRAME></IFRAME> line
	    var pop2 = (popid2 ? document.getElementById(popid2) : null);       //if provided, secondary panel that we need width of
	    iframe.style.display = 'block';
	    iframe.style.width = parseInt(pop.offsetWidth) + parseInt(pop2 ? pop2.offsetWidth : 0);
	    iframe.style.height = pop.offsetHeight;
	    iframe.style.left = pop.offsetLeft;
	    iframe.style.top = pop.offsetTop;
	}
    }
    disable_form(popid);                //turn off all input elements on the main form so they cannot be tabbed or typed into
} //makeModal

//######################################################

function adjustModal(popid, iframeid, popid2) {
    //adjust height/width of IE6 IFRAME that hides underlying HTML form SELECT fields that will otherwise bleed through
    if (iframeid) {
	var pop = document.getElementById(popid);
	var iframe = document.getElementById(iframeid);
	if (iframe) {           //won't be found if NOT IE 6, since we conditionalized the <IFRAME></IFRAME> line
	    var pop2 = (popid2 ? document.getElementById(popid2) : null);       //if provided, secondary panel that we need width of
	    iframe.style.width = parseInt(pop.offsetWidth) + parseInt(pop2 ? pop2.offsetWidth : 0);
	    iframe.style.height = pop.offsetHeight;
	    iframe.style.left = pop.offsetLeft;
	    iframe.style.top = pop.offsetTop;
	}
    }
} //adjustModal

//######################################################

function alignTop(elid, popid, horoffset, veroffset) {
    if (document.getElementById(elid)) {
	var vEl = document.getElementById(elid);
    } else {
	vEl = elid; 
    }
    xPos = vEl.offsetLeft;
    yPos = vEl.offsetTop;
    tempEl = vEl.offsetParent;
    while (tempEl != null) {
	xPos += tempEl.offsetLeft;
	yPos += tempEl.offsetTop;
	tempEl = tempEl.offsetParent;
    }
    layerswap(popid, eval(xPos+horoffset), eval(yPos+veroffset));
} //alignTop

//######################################################

function layerswap(id, xPos, yPos) {
    document.getElementById(id).style.left = xPos + "px";
    document.getElementById(id).style.top = yPos + "px";
    if ((document.getElementById(id).style.display == "none") || (! document.getElementById(id).style.display)) {
	document.getElementById(id).style.display = 'inline';
    } else {
	document.getElementById(id).style.display = 'none';
    }
} //layerswap

//######################################################

function unmodalize(popid, iframeid) {
    document.getElementById(popid).style.display = 'none';
    document.getElementById('pagemask').style.display = 'none';
    if (iframeid) {
	var iframe = document.getElementById(iframeid);
	if (iframe) {           //won't be found if NOT IE 6
	    iframe.style.display = 'none';
	}
    }
    enable_form(popid);         //re-enable all main form input fields
} //unmodalize

//######################################################

//disable all input elements in the main form while popup is displayed, else you can tab through the fields!
function disable_form(popid) {
    var myforms = document.forms;
    for (var f=0; f<myforms.length; ++f) {
	var fels = document.forms[f].elements;
	for (var i=0; i<fels.length; i++) {
	    //make sure we do not disable form elements in the popup screen, which are child elements of the main form
	    if (! child_of_popup(fels[i], popid))
		fels[i].disabled = true;
	}
    }

} //disable_form

//######################################################

//disable all input elements in the main form while popup is displayed, else you can tab through the fields underneath the popup!
function enable_form(popid) {
    var myforms = document.forms;
    for (var f=0; f<myforms.length; ++f) {
	var fels = document.forms[f].elements;
	for (var i=0; i<fels.length; i++) {
	    fels[i].disabled = false;
	}
    }
} //enable_form

//######################################################

//check if a form element is a child of a particular object id
function child_of_popup(el, id) {
    var parent = el;
    while (parent = parent.parentNode)
	if (parent.id == id)
	    return true;
    return false;
} //child_of_popup


//##################### nav_news.phtml #############################
//  to include new .pdf's
//  => add category to array where category# is the next in sequence (if category does not exist)
//  => add date to array
//  => add the title to be displayed
//  => add the the pathname to .pdf in array

var arrselcategory = Array(
    "1","401(k) Savings Plan for Pilots",
    "2","Employee Savings Plan",
    "3","Future Care Plan",
    "4","Retirement Savings Plan for Pilots"
    );

    //NOTE: category '0' is used for documents that should appear for all categories (but only once if ALL docs are displayed)
    //ALSO: one doc is duplicated for categories 1, 2, and 3
var arrselcatdat = Array(
    "0","10/26/2009",
    "0","10/26/2009",
    "0","04/28/2009",
    "0","04/17/2009",
    "0","02/17/2009",
    "0","01/26/2009",
    "1","06/11/2010",
    "1","08/29/2007",
    "1","12/31/2003",
    "1","04/13/2009",
    "1","04/01/2007",
    "1","04/17/2009",				//duped from category 2 
    "2","06/11/2010",
    "2","12/31/2003",
    "2","05/01/2008",
    "2","04/07/2007",
    "2","04/17/2009",				//was "12/06/2007", now dupe of next line for this category
    "3","06/11/2010",
    "3","04/17/2009",
    "3","05/01/2008",
    "3","04/13/2009",
    "3","12/06/2007",
    "3","08/29/2007",
    "4","06/18/2009",
    "4","06/19/2009",
    "4","08/29/2007",
    "4","04/13/2009",
    "4","04/07/2007"
    );

var arrselcattit = Array(   
    "0","Update: IRS Limits",
    "0","Update: Minimum Required Distributions",
    "0","401(k) Awareness Days Are Coming!",
    "0","Investing Basics",
    "0","Guide to Fidelity Investor Centers",
    "0","Key US Airways 401(k) Savings Plan Provisions",
    "1","New Fund Announced",
    "1","Information on Plan Investing - Pilots 401k",
    "1","Non US Equity Fund  - Pilots 401k",
    "1","Money Market Fund  - Pilots 401k",
    "1","Notice of Plan Changes - Pilots 401k",
    "1","New Investments",
    "2","New Fund Announced",
    "2","Non US Equity Fund  - Employee Savings Plan",
    "2","New Funds in Employee Savings Plan",
    "2","Notice of Plan Changes - Employee Savings Plan",
    "2","New Investments",
    "3","New Fund Announced",
    "3","New Investments",
    "3","New Funds - Future Care",
    "3","Money Market Fund - Future Care",
    "3","Plan Consolidation - Certain Future Care Participants",
    "3","Information on Plan Investing - Future Care",
    "4","BrokerageLink Notice",
    "4","Fund Additions and Changes",
    "4","Information on Plan Investing - Pilots RSP",
    "4","Money Market Fund - Pilots RSP",
    "4","Notice of Plan Changes - Pilots RSP"
    );

    //some docs are repeated in multiple categories (but not all 4)
var dupdocname1 = "pdf/USAirways_74435_Future_Care_Plan.pdf";
var dupdocname2 = "pdf/US_Airways_Fund_Change.052610.pdf";

var arrseldoclink = Array(
    "0","pdf/US_Airways_IRS_Limits_Update.Final.102609.pdf",
    "0","pdf/US_Airways_MRDs_Update.Final.102609.pdf",
    "0","pdf/401k_Day_Meetings_042809_FINAL.pdf",
    "0","pdf/US_Air_Investment_Basics_041709_FINAL.pdf",
    "0","pdf/Guide_to_Fidelity_Investor_Centers_021709_FINAL.pdf",
    "0","pdf/Key_US_Air_Savings_Plan_Features_012609_FINAL.pdf",
    "1",dupdocname2,
    "1","pdf/USAir_PlanInvest_082907_401k_SP_for_Pilots.pdf",
    "1","pdf/USAir_6plans_CGIntEq_020304_Employee_SP.pdf",
    "1","pdf/MKTG_Statement_Govt_Plan_401k_SP_for_Pilots.pdf",		//DOES NOT DISPLAY?
    "1","pdf/USAir_74435_FundChanges_401k_SP_for_Pilots.pdf",
    "1",dupdocname1,
    "2",dupdocname2,
    "2","pdf/USAir_6plans_CGIntEq_020304_Employee_SP.pdf",
    "2","pdf/USAir_35020_LowPricedStk_052808_Employee_SP.pdf",
    "2","pdf/USAir_90223_FundChanges_Employee_SP.pdf",
    "2",dupdocname1,
    "3",dupdocname2,
    "3",dupdocname1,
    "3","pdf/USAir_35020_LowPricedStk_Future_Care_Plan.pdf",
    "3","pdf/MKTG_Statement_Govt_Plan_Future_Care_Plan.pdf",
    "3","pdf/USAir_35020_SPChanges_022708_Future_Care_Plan.pdf",
    "3","pdf/USAir_Plan_Invest_082907_Future_Care_Plan.pdf",
    "4","pdf/Brokerage_Link_Notice_-_RSP_for_Pilots.pdf",
    "4","pdf/RSP_Fund_Additions_and_Changes.pdf",
    "4","pdf/USAir_PlanInvest_082907_RSP_for_Pilots.pdf",
    "4","pdf/MKTG_Statement_Govt_Plan_RSP_for_Pilots.pdf",
    "4","pdf/USAir_90223_FundChanges_RSP_for_Pilots.pdf"
    );

// update list
function getNewsArr() {
    if(!document.getElementById('selcat').selectedIndex) {
	document.getElementById('selcat').selectedIndex = 0;
    }
    createNewsArr();
    sortNewsArr();
    displayNewsArr();
    autoIframe('main-iframe');
} //getNewsArr

//##################### nav_news.phtml #############################

function displayCategories() {
    var str = ""
	+ "CATEGORY:\n"
	+ "<select class='sel selbg' id ='selcat' onchange='javascript: getNewsArr();'>\n"
	+ "<option class='opt' style='font-weight: bold; color: #9f2120;'>ALL</option>\n"
	;
    for (var x=1; x<arrselcategory.length; x=x+2) {
	str += "<option class='opt'"
	    + (arrselcategory[x].toLowerCase()=="employee savings plan" ? " selected='selected'" : "")
	    + ">" + arrselcategory[x] + "</option>\n"
	    ;
    }
    str = str + "</select>";
    document.getElementById('selcont').innerHTML = str;
}// displayCategories
//##################### nav_news.phtml #############################

// create temp arrays
var arrselcatdattemp = Array();
var arrselcattittemp = Array();

function createNewsArr() {
    var temparrdat = Array();
    var temparrtit = Array();
	//which category was selected for display? (0=all)
    var selcat = document.getElementById('selcat').selectedIndex;

    // clear arrays
    arrselcatdattemp.length = 0;
    arrselcattittemp.length = 0;

    // set temp arrays
    for(var x=0; x<arrselcatdat.length; x++) {
	temparrdat[x] = arrselcatdat[x];
	temparrtit[x] = arrselcattit[x];
    }

    if(selcat == 0) {
	    //ALL docs get displayed - but eliminate dupdocname dupes
	for(var x=1; x<temparrdat.length; x+=2) {
	    if (arrseldoclink[x] == dupdocname && arrseldoclink[x-1] > 1)
		continue;
	    arrselcatdattemp[x] = temparrdat[x];
	    arrselcattittemp[x] = temparrtit[x];
	}
    } else {
	    //only 1 category gets displayed (plus the '0' category)
	for(var x=0; x<temparrdat.length; x+=2) {
	    if(temparrdat[x] == (selcat + "") || temparrdat[x] == "0") {
		arrselcatdattemp[x+1] = temparrdat[x+1];
		arrselcattittemp[x+1] = temparrtit[x+1];
	    }
	}
    }
    // wash out the undefined elements
    var tarrdat = Array();
    var tarrtit = Array();
    var y = 0;
    for(var x=0; x<arrselcattittemp.length; x++) {
	if(arrselcatdattemp[x] != null) {
	    tarrdat[y] = arrselcatdattemp[x];
	    tarrtit[y] = arrselcattittemp[x];
	    y++;
	}
    }
    //reset arrays
    arrselcatdattemp.length = 0;
    arrselcattittemp.length = 0;
    for(var x=0; x<tarrdat.length; x++) {
	arrselcatdattemp[x] = tarrdat[x];
	arrselcattittemp[x] = tarrtit[x];
    }
} //createNewsArr

//##################### nav_news.phtml #############################

    //determine sort
var arrtemp2 = Array();

function sortNewsArr() {
    var tempstr1,tempstr2;

    // clear array
    arrtemp2.length = 0;

    if(document.getElementById('sortbydateid').checked) {
	for(var x=0; x<arrselcatdattemp.length; x++) {
	    tempstr1 = arrselcatdattemp[x];
	    arrtemp2[x] = tempstr1 + "@" + arrselcatdattemp[x] + "@" + arrselcattittemp[x];
	}
	arrtemp2.sort(datesort);

    } else {
	for(var x=0; x<arrselcatdattemp.length; x++) {
	    arrtemp2[x] = arrselcattittemp[x] + "@" + arrselcatdattemp[x];
	}
	arrtemp2.sort();

    }
} //sortNewsArr

//##################### nav_news.phtml #############################

    //sort mm/dd/yyyy dates, newest first
function datesort(a,b) {
    var as = a.split('/');
    var bs = b.split('/');
    if (as[2] > bs[2])
	return -1;
    else if (as[2] < bs[2])
	return 1;
    else if (as[0] > bs[0])
	return -1;
    else if (as[0] < bs[0])
	return 1;
    else if (as[1] > bs[1])
	return -1;
    else if (as[1] < bs[1])
	return 1;
    else
	return 0;
} //datesort

//##################### nav_news.phtml #############################

function displayNewsArr() {
    var strdat = "";
    var strtit = "";
    var arrt = Array();
    var lnk = "";      

    // split into smaller arrays
    for (var x=0; x<arrtemp2.length; x++) {
	arrt = arrtemp2[x].split("@");
    }

	// display based on sort selection
    if (document.getElementById('sortbydateid').checked) {
	for (var x=0; x<arrtemp2.length; x++) {
	    arrt = arrtemp2[x].split("@");
	    strdat += "<div class='sdate sortfont' id='sdate" + x + "'>" + arrt[1] + "</div>";
	    // add link to pdf
	    for (var y=1; y<arrselcattit.length; y=y+2) {
		if (arrselcattit[y] == arrt[2]) {
		    lnk = arrseldoclink[y];
		}
	    }
	    strtit += "<div class='stitle sortfont' id='stitle" + x + "'><a href='"
		+ lnk + "' target='_Blank'>" + arrt[2] + "</a></div>";
	}
    } else {		//sort by title
	for (var x=0; x<arrtemp2.length; x++) {
	    arrt = arrtemp2[x].split("@");
	    strdat += "<div class='sdate sortfont' id='sdate" + x + "'>" + arrt[1] + "</div>";
		// add the link to the pdf
	    for (var y=1; y<arrselcattit.length; y=y+2) {
		if (arrselcattit[y] == arrt[0]) {
		    lnk = arrseldoclink[y];
		}
	    }
	    strtit += "<div class='stitle sortfont' id='stitle" + x + "'><a href='"
		+ lnk + "' target='_Blank'>" + arrt[0] + "</a></div>";
	}
    }

	//add dynamic html
    document.getElementById('sdates').innerHTML = strdat;
    document.getElementById('stitles').innerHTML = strtit;

	//match date height to title height
    for (var x=0; x<100; x++) {
	if (document.getElementById('sdate'+x) && document.getElementById('stitle'+x)) {
	    document.getElementById('sdate'+x).style.height = document.getElementById("stitle"+x).offsetHeight - 8 + "px";
	}
    }

	//fill in gray area
    document.getElementById('sortbyinner').style.height = document.getElementById("rowtopsec").offsetHeight + 27 + "px";

} //display_sort

//##################### breaking news #############################

var g_dat1 = "", g_dat2 = "", g_dat3 = "";
var g_tit1 = "", g_tit2 = "", g_tit3 = "";
var g_lnk1 = "", g_lnk2 = "", g_lnk3 = "";

    // function to load BREAKING NEWS box with most recent 3 articles; called at bottom of home page in JS
function breakingNews() {
    var tmparr = Array();
    var temparr1 = Array();
    var temparr2 = Array();
    var yindex = 0;
	//start loop at 1 to skip first category number in each array, then increment by 2 to get to next element value
	//so, x is 1,3,5, etc, for element values, and we use [x-1] to check the category number for the current element
    for (var x=1; x<arrselcatdat.length; x+=2) {
	    //skip the duplicated document name if past category 1
	if (arrseldoclink[x] == dupdocname && arrseldoclink[x-1] > 1)
	    continue;
        temparr1 = arrselcatdat[x].split("/");
	    //put date in ymd order so sort works correctly
        temparr2[yindex] = temparr1[2] + temparr1[0] + temparr1[1] + "@" + arrselcattit[x] + "@" + arrseldoclink[x];
        yindex++;
    }
    
	// sort strings by date in reverse
    temparr2.sort(mysort);
    temparr2.reverse();
    
    tmparrfinal1 = Array();
    tmparrfinal2 = Array();
    tmparrfinal3 = Array();
    tmparrfinal1 = temparr2[0].split("@");
    g_tit1 = tmparrfinal1[1];
    g_lnk1 = tmparrfinal1[2];
    tmparrfinal2 = temparr2[1].split("@");
    g_tit2 = tmparrfinal2[1];
    g_lnk2 = tmparrfinal2[2];
    tmparrfinal3 = temparr2[2].split("@");
    g_tit3 = tmparrfinal3[1];
    g_lnk3 = tmparrfinal3[2];
    
    document.getElementById('newsbox_content').innerHTML = ""
	+ "<P>"+ g_dat1 + g_tit1 + "&nbsp; <b><a target='_Blank' href='" + g_lnk1 + "'>Learn&nbsp;more</a>&nbsp;&raquo;</b></P>\n"
	+ "<P>"+ g_dat2 + g_tit2 + "&nbsp; <b><a target='_Blank' href='" + g_lnk2 + "'>Learn&nbsp;more</a>&nbsp;&raquo;</b></P>\n"
	+ "<P>"+ g_dat3 + g_tit3 + "&nbsp; <b><a target='_Blank' href='" + g_lnk3 + "'>Learn&nbsp;more</a>&nbsp;&raquo;</b></P>\n"
	;
} //breakingNews

    // function to sort strings that contain both numbers and letters
function mysort(strOne, strTwo) {
	// get integers that make up first part of string
    var intOne = parseInt(strOne);
    var intTwo = parseInt(strTwo);

	// both are not numbers
    if ( isNaN(intOne) && isNaN(intTwo) ) {
	// sort as strings
	if (strOne > strTwo)
	    return 1;
	else if (strOne < strTwo)
	    return -1;
	else
	    return 0;
    } else if ( isNaN(intOne) ) {	// item one is not number - item two is number
	return 1;
    } else if ( isNaN(intTwo) ) {
	return -1;
    } else if ( intOne > intTwo ) {
	return 1;
    } else if ( intOne < intTwo ) {
	return -1;
    } else {
	return 0;
    }
} //mysort
