// JScript source code

var preloadFlag = false;
//added 7/31/06 jvd
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {	
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) 
{	
	window.attachEvent("onload", sfHover);
}
//jvd end changes
function FocusSearch() 
{
	var pageid = location.search.indexOf('id=91');
	var searchterm = location.search.indexOf('term');
	
	if ((pageid > 0) && (searchterm > 0))
	{
	var argname;
	var value;
	var args = new Object();
	var query = location.search.substring(1);
	var pairs = query.split("&");
	
		for (var i = 0; i < pairs.length; i++)
		{
			var pos = pairs[i].indexOf('=');
			if (pos == -1) continue;
			argname = pairs[i].substring(0,pos);
			value = pairs[i].substring(pos + 1);
			if (argname == 'term')
			{
				//decode the URL
				value = unescape(value);
				break;
			}
		}
	
	//replace all '+' with spaces
	var newvalue = value.replace(/\+/g,' ');
	document.SearchAgain.term.value = newvalue;
	
	document.SearchAgain.term.select();
	}
	else
	{
		if (document.loginform != null)
		{document.loginform.username.focus();}
		else if (document.updatepasswordform != null)
		{document.updatepasswordform.newpassword.focus();}
		else
		{
		 if (document.SearchForm != null){document.SearchForm.term.focus();}
		}
	}
}

function PrintPage() {
	if (location.search == '')
	{
		//there's no query string - it may be a promo page, so try to use the backup plan
		//I've included the form that contains the pageid in leftnav.xslt (printhelper.pageid)
		if (document.printhelper != null)
		{
			window.open("/popup.aspx?id=" + document.printhelper.pageid.value + "&print=1","bar","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=yes,width=700,height=500");
		}		
	}
	else
	{
		window.open("/popup.aspx" + location.search + "&print=1","bar","toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=yes,width=700,height=500");	
	}
	return true;
}

function BookmarkPage() {
	if ((navigator.appName == "Microsoft Internet Explorer")&&(parseInt(navigator.appVersion) >= 4))
	{window.external.AddFavorite(location.href,document.title);}
	else alert('Press CTRL+D to add a bookmark to this page.');
	return true;
}

function EmailPage() {
	location.href='mailto:?Subject=' + escape(document.title) + '&Body=Hello,%0D%0A%0D%0AI%20visited%20this%20web%20site%20and%20found%20some%20information%20I%20thought%20you%20may%20be%20interested%20in:%20' + escape(location.href) + '%0D%0A%0D%0ACheck%20it%20out%20and%20let%20me%20know%20what%20you%20think!';
	return true;
}

function SendMail(pjcrecipient) {
	location.href='mailto:' + pjcrecipient + '@pjc.com';
	return true;
}

function AdvancedSendMail(pjcrecipient,subject,body)
{
	location.href='mailto:' + pjcrecipient + '@pjc.com?Subject=' + escape(subject) + '&Body=' + escape(body);
	return true;
}

function KillLinksandShowPrintBox(popoption){
	for(i = 0; i < document.links.length; i++) 
	{
		if (document.links[i].name != 'print' && document.links[i].name != 'close' && document.links[i].target != '_blank' && document.links[i].href.indexOf("pop") == -1 && document.links[i].href.indexOf("goto") == -1 && document.links[i].href.indexOf("pdf") == -1)
		{document.links[i].href = 'javascript:void(0);'}
	}
	if (popoption == 1)
	{
		window.print();
	}
	return true;
}

function PopPage(href) {
	window.open(href,"bar","toolbar=yes,location=yes,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,menubar=yes,width=770,height=500");	
	return true;
}

function AdvancedPopPage(href,name,fullscreen,toolbar,status,menubar,scrollbars,resizable,directories,location,width,height,left,top) {
	window.open(href,name,"fullscreen="+fullscreen+",toolbar="+toolbar+",status="+status+",menubar="+menubar+",scrollbars="+scrollbars+",resizable="+resizable+",directories="+directories+",location="+location+",width="+width+",height="+height+",left="+left+",top="+top);	
	return true;
}

function CheckZipNameForm(frm) {
frm.search.value = frm.search.value.replace(/[^0-9a-z\. ']/ig, "").replace(/(^\s+)|(\s+$)/g, "");
//if the Search string is less than 2 characters, or is the default value, don't bother doing search.
		if(frm.search.value.length < 2 || frm.search.value=='Enter Last Name' || frm.search.value=='Enter ZIP or Last Name') 
		{
			alert("Please enter at least the first two letters of the last name of the Financial Advisor you are looking for.");			
			frm.search.focus();
			frm.search.select();
			return false;
		}
		else
		{
			frm.lname.value = frm.search.value;
			frm.zip.value = "";
			return true;	
			}
/*
	//Trim white space from the ends of Search field and remove characters that are not alphanumeric, period, space, or single quote.
	frm.search.value = frm.search.value.replace(/[^0-9a-z\. ']/ig, "").replace(/(^\s+)|(\s+$)/g, "");	
	//if search field has 5 digits, assign it to the zip field and submit
	if(frm.search.value.match(/^[0-9]{5}$/)){
		frm.zip.value = frm.search.value;
		frm.lname.value = "";
		return true;
	}
	//Check for Canadian Zip Codes
	else if(frm.search.value.replace(/\s/g, "").match(/([a-zA-Z][0-9]){3}$/)){
		alert("Canadian ZIP codes are not allowed in this search. Please modify your search to either a U.S. ZIP code, or a Last Name.");
		frm.search.focus();
		frm.search.select();
		return false;
	}
	else {		
		//if the Search string is less than 2 characters, or is the default value, don't bother doing search.
		if(frm.search.value.length < 2 || frm.search.value.match(/[0-9]/) || frm.search.value=='Enter ZIP or Last Name') {
			alert("Please enter either a U.S. ZIP code, or the last name of the Financial Advisor you are looking for.");			
			frm.search.focus();
			frm.search.select();
			return false;
		}
		else
			frm.lname.value = frm.search.value;
			frm.zip.value = "";
			return true;
	}
	*/
}

function validateform(form)
{
	for (i=0;i<form.elements.length;i++) 
	{
		if (form.elements[i].required != null)
		{
			if (form.elements[i].value == '' && form.elements[i].required == '1')
			{
				alert('Please enter a value for the field "' + form.elements[i].name + '".');
				form.elements[i].focus();
				form.elements[i].select();
				return false;
			}
			else if (form.elements[i].name == 'email')
			{
				var str = form.elements[i].value;
				var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
				if (str == '' | !str.match(re))
				{
					alert('Please enter a valid e-mail address.');
					form.elements[i].focus();
					form.elements[i].select();
					return false;
				}
			}
			else if (form.elements[i].name == 'newpassword' && form.elements[i].value.length < 3)
			{
				alert('Your new password must be at least 3 characters long.');
				form.elements[i].focus();
				form.elements[i].select();
				return false;
			}
		}
	}
	return true;
}

function validateAdvSrch(form)
{
	//You can't do an advanced fa search without at least entering 2 characters of the last name or first name
	if(form.lname.value == '' || form.lname.value.length < 2)
	{
		if(form.fname.value == '' || form.fname.value.length < 2)
		{
			alert('You must enter the first two letters of the last name or first name in addition to any other criteria.');
				return false;
		}
	}
	return true;
}

function validateOfficeSrch(form)
{
	//You can't do an office search with business type as the only criteria.  
	if(form.city.value =='')
	{
		if(form.zip.value =='')
		{
			alert('Please enter a ZIP code or a city and state.');
			form.zip.focus();
			form.zip.select();			
			return false;
		}
	}

	return true;
}

function hidedivs()
{
	//re-instate this functionality if the quotes tab ever returns to markets/quotes
	return true;
//	if (document.all || document.getElementById)
//	{
//		var divs = document.getElementsByTagName("div");
//		for (var i = 0; i < divs.length; i++)
//		{
//			var div = divs.item(i);
//			if (div.style.position == 'absolute')
//			{div.style.visibility = 'hidden';}
//		}
//	}
}

function urlencode(plaintext)
{
	var SAFECHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " "){encoded += "+";}
	    else if (SAFECHARS.indexOf(ch) != -1) {encoded += ch;}
	    else 
	    {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) 
			{
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				encoded += "+";
			} 
			else 
			{
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}

	return encoded;
}

function MM_reloadPage(init) 
{  
	//reloads the window if Nav4 resized
	if (init==true) with (navigator) 
		{
			if ((appName=="Netscape")&&(parseInt(appVersion)==4))
				{
					document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; 
				}
		}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
		{
			MM_reloadPage(true);
		}
}

function engineOut(obj) {window.close();}

function ShowHideTabs(position)
{
	if (document.all || document.getElementById)
	{
		var divs = document.getElementsByTagName("div");
		for (var i = 0; i < divs.length; i++)
		{
			var div = divs.item(i);
			if(div.id.indexOf("tabcontent") > -1)
			{
			    //alert(div.id.substring(div.id.indexOf("_")));
			    if(div.id.substring(div.id.indexOf("_")+1) == position)
			    {
			       div.style.display = "inline";
			    }
			    else
			    {
			        div.style.display = "none";
			    }
			}
		}
	}
}

function ShowDivByName(divName)

{
   if (document.all || document.getElementById)
   {
      var div = document.getElementById(divName);
      if (div != null)
      {
        div.style.visibility = 'visible';
      } 
      else
      {
        alert("div is null");
      }  
    }
}

 

function HideDivByName(divName)

{
   if (document.all || document.getElementById)
   {
      var div = document.getElementById(divName);
      if (div != null)
      {
        div.style.visibility = "hidden";
      } 
      else
      {
        alert("div is null");
      }  
    }
}



/*function ShowHideDivByName(divName)
{

    var div = document.getElementByName(divName);
    alert(divName);

    if (div != null)
    {
        alert(div.style.display);
        if(div.style.visibility == 'hidden')
        {
            div.style.visibility = 'visible';
        }
        else
        {   
            div.style.visibility = "hidden";
        }
    } 
    else
    {
        alert("div is null");
    }  
}*/

function PDFHitBox(user,pdf)
{
    hbx.hc1 = user;
    hbx.hc2 = pdf;
    return true;
}

function showloginmenu()
{
	if (document.all || document.getElementById)
	{
		var nLeftPos = document.images.loginimage.offsetLeft;
		var nTopPos = document.images.loginimage.offsetTop;				      
		var eParElement = document.images.loginimage.offsetParent;
		while (eParElement != null)
		{
			nLeftPos += eParElement.offsetLeft;
			eParElement = eParElement.offsetParent;
		}

		var eParElement2 = document.images.loginimage.offsetParent;
		while (eParElement2 != null)
		{
			nTopPos += eParElement2.offsetTop;
			eParElement2 = eParElement2.offsetParent;
		}

		//alert(nTopPos + ', ' + nLeftPos);
		
		document.getElementById('loginmenu').style.visibility = 'visible'; 
		document.getElementById('loginmenu').style.left = nLeftPos; 
		document.getElementById('loginmenu').style.top = nTopPos + document.images.loginimage.height;
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

if (document.images) {
	portal_individualinvestor_over = newImage("/images/portal_individualinvestor_over.gif");
	portal_instcorp_over = newImage("/images/portal_instcorp_over.gif");
	portal_about_over = newImage("/images/portal_about_over.gif");
	portal_indlogin_over = newImage("/images/portal_indlogin_over.gif");
	portal_instlogin_over = newImage("/images/portal_instlogin_over.gif");
	interior_individual_over = newImage("/images/interior_individual_over.gif");
	interior_instcorp_over = newImage("/images/interior_instcorp_over.gif");
	interior_about_over = newImage("/images/interior_about_over.gif");
	contact_us_over = newImage("/images/contact_us_over.gif");
	locations_over = newImage("/images/locations_over.gif");
	careers_over = newImage("/images/careers_over.gif");
	preloadFlag = true;
}

function switchSites(site)
{
    if (site == 'EU')
       {window.location='http://www.piperjaffray.com/europe';}
    else
       {window.location='http://www.piperjaffray.com';}
      
}