// JavaScript Document

<!-- getElementById Shorthand --->

function element(elementName)
{
	element = document.getElementById(elementName);
}

<!-- Current Date -->

<!-- -------------------------------------------------------------- -->

      /* Updated By:    Long Tran on 05.22.07
         Purpose:
             Shows/Hides elements  */

		function show(value)
		{
			document.getElementById(value).style.display = '';
		}

		function hide(value)
		{
			document.getElementById(value).style.display = 'none';
		}

	/* In your HTML use the following format
    	<a href="#" onclick="javascript:show(idToShow);">Text text text</a>
		<div id="idToShow"></div>
    */

<!-- -------------------------------------------------------------- -->


      /* Updated By:    Long Tran on 02.25.07
         Purpose:
             Gives a Blank Pop up Placeholder  */
		function demoPopup()
		{
			window.open('../popups/blank.html','blank','menubar=no,scrollbars=yes,dependent=yes,width=630, height=450, left=164,top=4');
		}
		
		function tourPopup(value)
		{
			window.open(value,'blank','menubar=no,scrollbars=no,dependent=yes,width=700, height=566, left=164,top=4');
		}
		
		function contentPopup(value)
		{
			window.open('../popups/' + value + '.html','blank','menubar=no,scrollbars=yes,dependent=yes,width=630, height=500, left=164,top=4');
		}

		function demoAlert()
		{
			alert('Because this is a demo, some links and features are disabled.');
			// alert('You are viewing our demo. This feature is not enabled in the demo.');
		}
		
		function disabledDemo()
		{
			alert('This page has been disabled for the purposes of this alternate demo version.');
			return false;
		}

		function popupSwitch(value){
			window.open('../smartswitch/ss_letter-' + value + '.html','blank','menubar=yes,scrollbars=yes,dependent=yes,width=740, height=550');
		}


<!-- -------------------------------------------------------------- -->


      /* Updated By:    David M. Dailey on 10.05.06
         Purpose:
             Forwards the user to a new location, on selection of a menu item. */
    
        function changeLocation(PageToView)
		{
    
            location.replace(PageToView);
        
        }
    
      /* In your HTML use the following format
        
        <select id="Menu_1" onchange="changeLocation(this.value)">          use a UNIQUE id
          <option value="#" selected>Your First Selection</option>          value is where you want to go, use # to stay at current page.
          <option value="http://www.url.com">Your Next Selection</option>   
        </select> */


<!-- -------------------------------------------------------------- -->

    
      /* Updated By:    David M. Dailey on 10.05.06
         Purpose:
             Opens a new window for the user */
    
    
        function newLocation(PageToOpen)
		{
    
            window.open(PageToOpen,'','scrollbars=yes,menubar=no,height=600,width=680,resizable=yes,toolbar=no,location=no,status=no');
        }
    
      /* In your HTML use the following format
        
        <select id="Menu_1" onchange="newLocation(this.value)">             use a UNIQUE id
          <option value="#" selected>Your First Selection</option>          value is where you want to go, use # to stay at current page.
          <option value="http://www.url.com">Your Next Selection</option>   
        </select> */
        
    
<!-- -------------------------------------------------------------- -->


      /* Updated By:    David M. Dailey on 09.20.06
         Purpose:
             The 'Reveal' Function takes the values in an INPUT option, and displays a hidden block.
         The function first hides all associated blocks that the INPUT effects. Then it Displays the
         block associated with the users choice. */
    
        function Reveal(Value, Menu)
		{
      
            Value = Value.split(',');                                             // Breaks up the VALUE into an Array
                DISPLAY = Value[0];                                               // Item that needs to be shown.
                HIDE    = Value[1];                                               // Item that needs to be hidden
      
            TYPE = document.getElementById(Menu).type;                            // Determines what Type of INPUT is calling the function.
      
              if(TYPE == 'radio') {                                               // Accounts for Radio buttons that have no 'options'
        
                  document.getElementById(HIDE).style.display = 'none';           // Hides a block
    
                  document.getElementById(DISPLAY).style.display = 'block';       // Shows a block
        
              } else {
        
                  NumberOfOptions = document.getElementById(Menu).length;          // Retrieves the number of options in the selection.
        
                  x = 0;                                                           // Declares 'x' outside of the for loop, 'n' will NOT work.
    
                  for(n=1; n <= NumberOfOptions; n++) {                           // This loop is used to hide ALL the associated blocks with a given INPUT
    
                      Hide = document.getElementById(Menu).options[x].value;      // Assigns the VALUE to the variable 'Hide'
    
                      ToHide = Hide.split(',');                                   // Breaks up 'Hide'.
    
                      document.getElementById(ToHide[0]).style.display = 'none';  // Takes the first element in the VALUE, finds the ID that matches it, and hides that block
    
                      x++;
    
                  }
              }
        
            document.getElementById(DISPLAY).style.display = 'block';            // Displays block, associated with the selection
      
        }
    
      /* In your HTML use the following format
    
          <select id="Menu_1" onchange="Reveal(this.value, this.id)" >                          Use a UNIQUE ID
            <option value="Null,Null">Make a Selection</option>                                 VALUE needs to be Item_To_Show,Item_to_Hide use a comma to seperate. No whitespace
            <option value="BoxA,Null">Selection One</option>
            <option value="BoxB,Null">Selection Two</option>
          </select>
        <div id="BoxA" style="display:none;">Selection <b>One</b> was Chosen</div>            Use a UNIQUE id for your hidden block
        <div id="BoxB" style="display:none;">Selection <b>Two</b> was Chosen</div>
        <br />
        <div id="Null" style="display:none; width:0px; height:0px;"></div>                    Use a HIDDEN block at the BOTTOM of the page, that is always hidden. */


<!-- -------------------------------------------------------------- -->


      /* Updated By:    David M. Dailey on 01.10.07
         Purpose:
             Allows a Table ot Div to be hidden, while another is shown. For use
		particularly with Tabs */

			function displayTables(tableToHide, tableToShow)
			{
				document.getElementById(tableToHide).style.display = 'none';
				document.getElementById(tableToShow).style.display = '';
			}
	
 	/* In your HTML use the following format
		<div id="Item[0]" style="width:400px; height:200px; border:solid; border-width:1px; display:block;">
		
		  <a href="#" onclick="displayTables('Item[0]', 'Item[0]');">See Block One</a> | <a href="#" onclick="displayTables('Item[0]', 'Item[1]');">See Block Two</a><br />
		  <br />
		  This is Box One
		</div>
		
		<div id="Item[1]" style="width:400px; height:200px; border:solid; border-width:1px; display:none;">
		  <a href="#" onClick="displayTables('Item[1]', 'Item[0]');">See Block One</a> | <a href="#" onclick="displayTables('Item[1]', 'Item[1]');">See Block Two</a><br />
		  <br />
		  This is Box Two
		</div> */


<!-- -------------------------------------------------------------- -->


      /* Updated By:    David M. Dailey on 03.2.07
         Purpose:
             Generates Dynamic Quick Links based on the Pages 'Link' and 'sublink' being passed in the URL */

			function printQuicklinks()
			{
		
				function getURL_Value(name)
				{
			
					//Regular Expression that breaks down the URL and pulls out variables seperated by '&'
					var regexS = "[\\?&]"+name+"=([^&#]*)";
			
					// Creates a Regular Expression Object
					var regex = new RegExp( regexS );
			
					// Gets the current URL and stores it in a temp variable
					var tmpURL = window.location.href;
			
					// checks the URL using the Regular Expression Object against the temporary URL variable
					var results = regex.exec( tmpURL );
					
						if(results == null) {
				
							return "";
				
						} else {
				
							return results[1];
						}
					return;
				}
		
				quicklink = new Array();

					// 0 - Set Account Display Preferences
					quicklink[0] = "<a href=\"javascript:demoAlert();\" >Set Account Display Preferences</a>";
		
					// 1 - Customize My Quick Links
					quicklink[1] = "<a href=\"../service/quicklinks.html\">Customize My Quick Links</a>";
		
					// 2 - Link Accounts
					quicklink[2] = "<a href=\"../service/link.html\">Link Accounts</a>";
		
					// 3 - Send a Secure Message
					quicklink[3] = "<a href=\"../messages/inquiry.html\">Send a Secure Message</a>";
		
					// 4 - Set Alerts
					quicklink[4] = "<a href=\"../alerts/index.html\">Set Alerts</a>";
		
					// 5 - View Online Statements
					quicklink[5] = "<a href=\"../accounts/statements.html\">View Online Statements</a>";
		
					// 6 - Download Account History
					quicklink[6] = "<a href=\"../accounts/downloads.html\">Download Account History</a>";
		
					// 7 - View Account Details & History
					quicklink[7] = "<a href=\"../accounts/details.html\">View Account Details & History</a>";
		
					// 8 - Add New Payee
					quicklink[8] = "<a href=\"../billpay/addpayee.html\">Add New Payee</a>";
		
					// 9 - Transfer Funds
					quicklink[9] = "<a href=\"../transfers/index.html\">Transfer Funds</a>";
		
					// 10 - View Payment History
					quicklink[10] = "<a href=\"../billpay/processed.html\">View Payment History</a>";
		
					// 11 - Schedule a Bill Payment
					quicklink[11] = "<a href=\"../billpay/index.html\">Schedule a Bill Payment</a>";
		
					// 12 - View Pending Bill Payments
					quicklink[12] = "<a href=\"../billpay/pending.html\">View Pending Bill Payments</a>";
		
					// 13 - View Transfer History
					quicklink[13] = "<a href=\"../transfers/processed.html\">View Transfer History</a>";
		
					// 14 - View Scheduled Transfers
					quicklink[14] = "<a href=\"../transfers/pending.html\">View Scheduled Transfers</a>";
		
					// 15 - Funds Transfer User Guide
					quicklink[15] = "<a href=\"javascript:demoAlert()\">Funds Transfer User Guide</a>";
		
					// 16 - View Pending External Transfers
					quicklink[16] = "<a href=\"../transfers/efi_pending.html\">View Pending External Transfers</a>";
		
					// 17 - View External Transfer History
					quicklink[17] = "<a href=\"../transfers/efi_processed.html\">View External Transfer History</a>";
		
					// 18 - Link Non-Capital One Account
					quicklink[18] = "<a href=\"../transfers/efi_manage.html\">Link Non-Capital One Account</a>";
		
					// 19 - Self Service Center
					quicklink[19] = "<a href=\"../service/index.html\">Self Service Center</a>";
		
					// 20 - Update Contact Information
					quicklink[20] = "<a href=\"../service/address.html\">Update Contact Information</a>";
		
					// 21 - Change User ID
					quicklink[21] = "<a href=\"../service/userid.html\">Change User ID</a>";
		
					// 22 - Change Password
					quicklink[22] = "<a href=\"../service/password.html\">Change Password</a>";
		
					// 23 - Update Security Questions
					quicklink[23] = "<a href=\"../service/question_ia.html\">Update Security Questions</a>";
		
					// 24 - Set My Start Page
					quicklink[24] = "<a href=\"../service/landing.html\">Set My Start Page</a>";
		
					// 25 - Manage Payees (Builder/CC)
					quicklink[25] = "<a href=\"../billpay/managepayees.html\">Manage Payees</a>";
		
				function writeQuicklinks(a,b,c,d)
				{
		
					document.write(quicklink[a] + "<br />");
					document.write(quicklink[b] + "<br />");
					document.write(quicklink[c] + "<br />");
					document.write(quicklink[d] + "<br />");
					return;
		
				}
		
				switch (getURL_Value("link"))
				{
		
					case "1": // Accounts
			
						switch (getURL_Value("sublink"))
						{
			
							case "1": // Account Summary
		
								writeQuicklinks(0,1,2,3);
								break;
		
							case "2": // Account Details & History
		
								writeQuicklinks(0,4,5,6);
								break;
		
							case "3": // Statements
		
								writeQuicklinks(4,1,6,3);
								break;
		
							case "4": // Downloads
		
								writeQuicklinks(4,7,5,3);
								break;
		
							default:
		
								writeQuicklinks(0,1,2,3);
								break;
						}		
						break;
			
					case "2": // Bill Payments
		
						switch (getURL_Value("sublink"))
						{
			
							case "1": // Quick Payments 
		
								writeQuicklinks(8,4,7,3);
								break;
		
							case "2": // Schedule Payments
		
								writeQuicklinks(4,7,9,3);
								break;
		
							case "3": // Pending Payments
		
								writeQuicklinks(10,11,8,7);
								break;
		
							case "4": // Payment History
		
								writeQuicklinks(12,11,13,14);
								break;
		
							case "5": // Manage Payees
		
								writeQuicklinks(8,10,11,12);
								break;
		
							case "6": // Manage Payees
		
								writeQuicklinks(25,10,11,12);
								break;
		
							default:
		
								writeQuicklinks(0,1,2,3);
								break;
						}		
						break;
			
					case "3": // Transfers
		
						switch (getURL_Value("sublink"))
						{
			
							case "1": // Schedule Transfers
		
								writeQuicklinks(4,7,5,3);
								break;
		
							case "2": // Pending Transfers
		
								writeQuicklinks(4,7,5,3);
								break;
		
							case "3": // Transfer History
		
								writeQuicklinks(4,7,5,3);
								break;
		
							case "4": // Manage Non-Capital One Accounts
		
								writeQuicklinks(15,16,17,18);
								break;
		
							default:
		
								writeQuicklinks(0,1,2,3);
								break;
						}	
						break;
			
					case "4": // Message & Alerts
		
						switch (getURL_Value("sublink"))
						{
			
							case "1": // Message Center  	 	  	 	  	 	
		
								writeQuicklinks(19,7,2,20);
								break;
		
							case "2": // Compose Secure Message
		
								writeQuicklinks(19,7,2,20);
								break;
		
							case "3": // Set Alerts
		
								writeQuicklinks(7,14,12,5);
								break;
		
							case "4": // Manage Delivery Methods
		
								writeQuicklinks(20,21,22,23);
								break;
		
							default:
		
								writeQuicklinks(0,1,2,3);
								break;
						}	
						break;
			
					case "5": // Self Service
		
						switch (getURL_Value("sublink"))
						{
			
							case "1": // Self Service Center  	 	  	 	  	 	
		
								writeQuicklinks(7,3,24,0);
								break;
		
							default:
		
								writeQuicklinks(0,1,2,3);
								break;
						}	
		
						break;
			
					default: // Catch all default.
						writeQuicklinks(0,1,2,3);
						break;
		
				}
		
				return;
			}
        
    
<!-- -------------------------------------------------------------- -->


      /* Updated By:    David M. Dailey on 03.02.07
         Purpose:
 			Randomly Generates an Image for the Quick Links section. This is a Marketing Tool. */

			function displayRandomImage()
			{

				// Generate a Random Number
				var randomNumber = Math.round(Math.random()*4);

				var showImage = new Array();

					showImage[0] = "<img src=\"../images/products/img_01.gif\" width=\"190\" height=\"72\" border=\"0\">";
					showImage[1] = "<img src=\"../images/products/img_02.gif\" width=\"190\" height=\"72\" border=\"0\">";
					showImage[2] = "<img src=\"../images/products/img_03.gif\" width=\"190\" height=\"72\" border=\"0\">";
					// original img_04.jpg removed as requested by MM 11/28/06
					showImage[3] = "<img src=\"../images/products/img_08.jpg\" width=\"190\" height=\"72\" border=\"0\">";
					// showImage[4] = "<img src=\"/images/products/img_05.gif\" width=\"190\" height=\"72\" border=\"0\">";
					// showImage[5] = "<img src=\"/images/products/img_06.gif\" width=\"190\" height=\"72\" border=\"0\">";
					showImage[4] = "<img src=\"../images/products/img_07.gif\" width=\"190\" height=\"72\" border=\"0\">";

				document.write(showImage[randomNumber]);

			}
			

  
  //////////////////////////////////////////////////////////////////////////////
// addLoadEvent
//
//		Add a new function to the windows onload event without 
//		removing any previous existing functions.
//
//  @param   func - function name to add to windows.onload    
//  @return  void
//////////////////////////////////////////////////////////////////////////////
function addLoadEvent(func) {
	
	// Save current onload functions
	var oldonload = window.onload;
	
	// If this is the first function then assign it to window.onload
	// else assign it along with the current functions 
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		};
	}
}
		