/* jQuery */
$(document).ready(function() {
	/* Slideshow */
	$('.slideshow').cycle({
		fx: 'fade'
	});
	loadTable("pa",0);
	
	/* unified right-hand banner portlet - overwrites /financial-services/securities/article/home_right_article.dwt */
	var banner_string = '';
	<!--banner_string += '<a id="ad1" style="display:block;" href="/financial-services/securities/mortgages.htm"><img title="J.P. Morgan Mortgages now available for J.P. Morgan Securities clients" border="0" alt="J.P. Morgan Mortgages now available for J.P. Morgan Securities clients" src="/financial-services/securities/images/mortgages.gif" /></a>';-->
	<!--banner_string += '<a id="ad2" style="display:block;" href="/summer"><img title="J.P. Morgan Summer Reading List 2011" border="0" alt="J.P. Morgan Summer Reading List 2011" src="/financial-services/securities/images/summer_reading_list_banner_2011.gif" /></a>';-->
	<!--banner_string += '<a id="ad2" style="display:block;" href="http://www.jpmorgansecurities.com/seasonofgiving"><img title="J.P. Morgan Holiday Reading List 2011" border="0" alt="J.P. Morgan Holiday Reading List 2011" src="/financial-services/securities/images/2011_wrl_banner.jpg" /></a>'; -->
	banner_string += '<a id="ad3" style="display:block;" href="http://www.jpmorgan.com/pages/jpmorgan/about/businesses/glance" target="_blank"><img title="J.P. Morgan An Industry Leader" border="0" alt="" src="/financial-services/securities/images/141997_ad_bw.jpg" /></a>';
	banner_string += '<a id="ad4" style="display:block;" href="https://www.icsdelivery.com/jpmorganclearing_new/formNew3.asp" target="_blank"><img title="eDelivery" border="0" alt="eDelivery" src="/financial-services/securities/images/edelivery.gif" name="eDelivery" width="195" height="65" id="eDelivery" onmouseover="MM_swapImage(\'eDelivery\',\'\',\'/financial-services/securities/images/edelivery2.gif\',1)" onmouseout="MM_swapImgRestore()" /></a>';
	$('#adPad').html(banner_string);
	
	/* shared About JPMS text */
	var aboutjpms_string = '';
	aboutjpms_string += '<h1>About J.P. Morgan Securities</h1>';
	aboutjpms_string += '<p>J.P. Morgan Securities leverages one of the most comprehensive product platforms in the industry, as well as the financial strength of JPMorgan Chase &amp; Co., one of the world&rsquo;s oldest, largest and best known financial institutions. Our Financial Advisors offer clients a broad suite of transactional, wealth management and investment advisory services. They provide highly personalized service and access to world-class products and services offered through the global financial resources of J.P. Morgan.</p>';
	aboutjpms_string += '<p>The views and strategies described may not be suitable for all investors. This material has been prepared for informational purposes only, and is not intended to provide, and should not be relied on for tax, legal or accounting advice. You should consult your own tax, legal and accounting advisors before engaging in any transaction. Securities are offered by J.P. Morgan Securities LLC. (&quot;JPMS&quot;), member FINRA, NYSE and SIPC. When JPMS acts as a broker-dealer, a client\'s relationship with us and our duties to the client will be different in some important ways than a client\'s relationship with us and our duties to the client when we are acting as an investment advisor. A client should carefully read the agreements and disclosures received (including our Form ADV disclosure brochure, if and when applicable) in connection with our provision of services for important information about the capacity in which we will be acting.</p>';
	$('#aboutJPMS').html(aboutjpms_string);
	
	/* moblie client logon checker */
	if (screen.width < 500 || navigator.userAgent.match(/Android/i) ||  navigator.userAgent.match(/webOS/i) ||  navigator.userAgent.match(/iPhone/i) ||  navigator.userAgent.match(/iPod/i)) { 
		$('#logonPad').hide();
		$('#logonPadMobile').show(); 
	}
});

/* code to display tabs */
var _className = $("#current_tab").attr("class")
$("#tmp_main_container").attr("class",_className + "On");
$("#bannerHome").attr("style","background-image: url(/financial-services/securities/images/jpms_banner_" + _className + ".jpg)");

function showSection(section_id,element_id){
 try{	
 $("#" + section_id).animate({opacity:"toggle",height:"toggle"});
 var _text = $("#" + element_id).text();
 var _text_arr = $("#" + element_id).text();
 var _show_hide = "";
 if(_text.indexOf("show") !=-1){
	 _text_arr = _text.split("show");
	 _show_hide = "hide";
 } else if(_text.indexOf("Show") !=-1){
	 _text_arr = _text.split("Show");
	 _show_hide = "Hide";
 } else if(_text.indexOf("hide") !=-1){
	 _text_arr = _text.split("hide");
	 _show_hide = "show";
 } else if(_text.indexOf("Hide") !=-1){
	 _text_arr = _text.split("Hide");
	 _show_hide = "Show";
 }
 $("#" + element_id).text(_show_hide + _text_arr[1]);
 } catch(e){
 }
}

/* Dreamweaver generic scripts */
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/* code to Sweep Option Yield page */
function loadTable(fund_category, tab_n){
	//this avoids receiving a script error on pages other than the sweep option yield page
	var urlCheck = new String(location.href);
	if (urlCheck.indexOf('sweepoptionyield') != -1) {
		$("#soy-tabs .soy-tab").removeClass("selected");
		$("#soy-tabs .soy-tab:nth-child(" + (tab_n + 1) + ")").addClass("selected");
		try {
			$.ajax({
				url: '/financial-services/securities/document/sweepprogramlist.xml?sopdt='+ new Date().getTime(),
				dataType: 'xml',
				success: function(data) {
					var AsOfDate = $(data).find("AsOfDate").text();
					$(".as-of-date")[0].innerHTML = "as of " + AsOfDate + " (a)";
					$(".as-of-date")[1].innerHTML = "as of " + AsOfDate;
					var tr_string = "";
					$(data).find("item").each(function(n) {
						var FundCategory = $(this).attr("FundCategory");
						var SweepCodeSymbol = $(this).attr("SweepCodeSymbol");
						var FundName = $(this).attr("FundName");
						var CurrentYield_7daySEC = $(this).attr("CurrentYield");
						var CurrentYield_7dayAPY = "";
				
						/*if($.trim(SweepCodeSymbol).length==3){
				  		 SweepCodeSymbol = "JPM MMDA";*/
						if (SweepCodeSymbol.indexOf("A000AB5")!=-1 || SweepCodeSymbol.indexOf("A000AV4") !=-1) {
				   			SweepCodeSymbol = $.trim(SweepCodeSymbol.split("/")[1]);
				   			CurrentYield_7dayAPY = CurrentYield_7daySEC;
				   			CurrentYield_7daySEC = "";
						} else {
							SweepCodeSymbol = $.trim(SweepCodeSymbol.split("/")[1]);
						}
				
						if(fund_category=="as" && FundCategory=="Advisory Services"){
							tr_string = tr_string + "<tr>";
							tr_string = tr_string + "<td class='first-column'>" + SweepCodeSymbol + "</td>";
							tr_string = tr_string + "<td class='second-column'>" + FundName + "</td>";
							tr_string = tr_string + "<td class='third-column'>" + CurrentYield_7daySEC + "</td>";
							tr_string = tr_string + "<td class='fourth-column'>" + CurrentYield_7dayAPY + "</td>";
							tr_string = tr_string + "</tr>";
						} else if (fund_category=="pa" && FundCategory=="Privileged Access"){
							tr_string = tr_string + "<tr>";
							tr_string = tr_string + "<td class='first-column'>" + SweepCodeSymbol + "</td>";
							tr_string = tr_string + "<td class='second-column'>" + FundName + "</td>";
							tr_string = tr_string + "<td class='third-column'>" + CurrentYield_7daySEC + "</td>";
							tr_string = tr_string + "<td class='fourth-column'>" + CurrentYield_7dayAPY + "</td>";
							tr_string = tr_string + "</tr>";
						}
						$("#soy-table-body").html(tr_string);
						$(".soy-table tr:nth-child(even)").addClass("striped");
					});
				}, 
				error: function() {
					var tr_string = "";
					tr_string = tr_string + "<tr>";
					tr_string = tr_string + "<td>Fund data is currently unavailable. Please try again later.</td>";
					tr_string = tr_string + "</tr>";
					$("#soy-table-body").html(tr_string);
				}
			});
		} catch(e) {
		}
	}
}

/*
USAGE:
_URL - the URL of the window that you want to open, for instance: https://www.chase.com
_params - the string with the window parameters, for instance
"left=0,top=0,resizable=yes,scrollbars=no,menubar=yes,location=yes,width=800,height=600" 
DEFAULT, if _params is not passed is
"left=0,top=0,resizable=yes,scrollbars=yes,menubar=no,location=no"
*/
function jsPopup(_URL,_params) {
	try {
		var _param_string = (_params?_params:"left=0,top=0,resizable=yes,scrollbars=yes,menubar=no,location=no");
		var webWin=window.open(_URL,"winview",_param_string);
		webWin.focus();  
		} catch(e) {
	}
}

$(function(){
	// Accordion
	$("#accordion").accordion({
		autoHeight: false,
		header: "h3" 
	});
});

