var contObj;var leftObj;var rightObj;var contentObj;var naviObj;var naviTimer;function naviIn()
{naviObj=document.getElementById('myNavigation');if(naviObj&&naviObj.style)
{if(naviTimer)
window.clearTimeout(naviTimer);naviObj.style.display='block';}}
function naviOut()
{naviObj=document.getElementById('myNavigation');if(naviObj&&naviObj.style)
naviTimer=window.setTimeout("naviObj.style.display = 'none';",250);}
var sBoxObj;var sBoxTimer;function sBoxOver(id)
{if(sBoxObj&&(sBoxObj.id!=id))
{sBoxObj.style.display='none';}
sBoxObj=document.getElementById(id);if(sBoxObj&&sBoxObj.style)
{if(sBoxTimer)
window.clearTimeout(sBoxTimer);sBoxObj.style.display='block';}}
function sBoxOut(id)
{sBoxObj=document.getElementById(id);if(sBoxObj&&sBoxObj.style)
sBoxTimer=window.setTimeout("sBoxObj.style.display = 'none';",250);}


function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

function templateTitleBarSymbolSearch_OnClick()
{
	var redirect;
	var rValue;
	var searchText=document.getElementById('topbarSymbolSearchText').value;
	for (i=0; i<3; i++)
	{
		if (document.getElementById('topbarSymbolSearchList'+i))
		{
			if (document.getElementById('topbarSymbolSearchList'+i).checked==true||document.getElementById('topbarSymbolSearchList'+i).checked=="checked")
			{
				rValue=document.getElementById('topbarSymbolSearchList'+i).value;
				break;
			}
		}
	}
	var hostName = location.host;
    if(location.host.indexOf("trading.zecco.com") > -1)
	{
	    hostName = "zecco.com"
	}
	if(location.host.indexOf("qa.trading.zecco.com") > -1)
	{
	    hostName = "qa.zecco.com"
	}
	redirect = "http://" + hostName + "/quotes/Default.aspx?symbol=" + searchText + "&selectedTab=" + rValue;
	top.location.href = redirect;
}

function templateTitleBarBlogsForumsSearch_OnClick()
{
	var redirect;
	var searchText = document.getElementById('topbarBlogsForumsSearchText').value;
	
	var hostName = location.host;
    if(location.host.indexOf("trading.zecco.com") > -1)
	{
	    hostName = "zecco.com"
	}
	if(location.host.indexOf("qa.trading.zecco.com") > -1)
	{
	    hostName = "qa.zecco.com"
	}	
	redirect="http://" + hostName + "/search/SearchResults.aspx?q=" + searchText;
	top.location.href = redirect;
}

function templateTitleBarSearch_OnClick()
{
	var redirect;
	var rValue;
	var searchText=document.getElementById('topbarSearchText').value.trim();
	for (i=0; i<3; i++)
	{
		if (document.getElementById('topbarSearchList'+i))
		{
			if (document.getElementById('topbarSearchList'+i).checked==true||document.getElementById('topbarSearchList'+i).checked=="checked")
			{
				rValue=document.getElementById('topbarSearchList'+i).value;
				break;
			}
		}
	}
	var hostName = location.host;
    if(location.host.indexOf("trading.zecco.com") > -1)
	{
	    hostName = "zecco.com"
	}
	if(location.host.indexOf("qa.trading.zecco.com") > -1)
	{
	    hostName = "qa.zecco.com"
	}
	
	redirect = "http://" + hostName + rValue + searchText;
	top.location.href = redirect;
}

function linkTo_TitleBar(hasSymbol)
{
	if(hasSymbol)
	{
		linkToSymbol_TitleBar();
	}
	else
	{
		linkToQuoteSearch_TitleBar();
	}
}

function linkToSymbol_TitleBar()
{
	var searchText=document.getElementById('topbarSearchText').value;
	var rValue = document.getElementById('topbarSearchList0').value;
	var hostName = location.host;
	
	if(location.host.indexOf("trading.zecco.com") > -1)
	{
		hostName = "zecco.com"
	}
	if(location.host.indexOf("qa.trading.zecco.com") > -1)
	{
		hostName = "qa.zecco.com"
	}
	
	rValue = rValue.replace("symbol", trim(searchText));
	redirect = "http://" + hostName + rValue;
	top.location.href = redirect;
}


var scrollTop = false;
var isPageLoaded = false

function pageLoad()
{
	// a known issue, ajax postback forces a scroll back to the original 
	// position in Sys$WebForms$PageRequestManager$_scriptsLoadComplete; 
	// register scrollTop value as a startup script to force a page to scroll to the top
	if (scrollTop)
	{
		window.scrollTo(0, 0);
	}
	isPageLoaded = true;
}

	function ZeccoShareRedirectFromHome(anchor)
	{
		if (isZeccoShareMember)
		{
			  return true;				  
		}	 
		else
		{     					
			window.top.location = '/zeccoshare';	
			return false;
		}
	}
	
	function RedirectToSigninWithTarget(targetUrl){   
	  var reg = new RegExp("\\w(\/\\w.*)", 'i');
	  var newurl = reg.exec(targetUrl)
	  window.top.location = '/Signin.aspx?ReturnUrl='+ newurl[1];
    }
	
    function CheckTabPermission(sender)
    {
    
		if(sender.id=='MEMBERS' || sender.id=='GROUPS')
		{
			if (isGuest)
			{
				displayTabNotification('TabSignInCreateAccount');
				return false;
			}	 
//			else if(!hasZeccoShareProfile)
//			{        			
//				if(hasPendingZeccoShareApplication)
//				{
//				 displayTabNotification('TabZeccoShareClosedEnrollment');				
//				}
//				else
//				{
//				 displayTabNotification('TabActivateProfile');								
//				}
//			  return false;
//			}
		}        
	 	else if(sender.id=='HOME' || sender.getAttribute('sectionName') == 'HOME')
	 	{
	 		if (isGuest)
			{
				displayTabNotification('SignInDialogNav');
				return false;
			}	
			else if(!hasZeccoShareProfile)
			{
				displayTabNotification('TabActivateProfile');
				return false;
			} 
//			else if (!isSharingPortfolio) // this no longer applies
//			{
//				displayTabNotification('TabChangePortfolioSharingSetting');
//				return false;
//			}
	 	}else
	 	{
	 		return true;
	 	}
	  
    }
    
    function displayTabNotification(id)
    {
       displayTabPopup(id);
    }
    
    function redirectToSignUp(){
	  var url = window.top.location.href;		
	  var reg = new RegExp("\\w(\/\\w.*)", 'i');
	  var newurl = reg.exec(url)
	  window.top.location = '/user/Signup.aspx?ReturnUrl='+ newurl[1];
    }
    function redirectToSignin(){   
	  var url = window.top.location.href;		
	  var reg = new RegExp("\\w(\/\\w.*)", 'i');
	  var newurl = reg.exec(url)
	  window.top.location = '/Signin.aspx?ReturnUrl='+ newurl[1];
    }
    
    function displayTabPopup(popupID)
    {  
        // Check if the page is totally loaded, if not return right away. This prevents IE return OPERATION ABORTED exception
        if (!isPageLoaded) return;
        
        var modalMask   = document.getElementById("modalMask");
        var modalPopup  = document.getElementById(popupID);              
        modalPopup.style.display = "none";
        if (modalPopup && modalMask)
        {
        
            if(modalPopup.parentNode)
            {
                modalPopup = modalPopup.parentNode.removeChild(modalPopup);
                document.body.appendChild(modalPopup);
            }
            
            modalMask.style.display = "block";                     
            modalPopup.style.display = "block";
		
			modalMask.style.height = document.body.clientHeight + 'px';
            modalMask.style.width = document.body.clientWidth + 'px';
            
            modalPopup.style.top = ((document.body.clientHeight - modalPopup.offsetHeight) / 2) + 'px';
            modalPopup.style.left = (document.body.clientWidth - modalPopup.offsetWidth) / 2 + 'px';
            
            //LLD - COMMENT
            //window.scrollTo(0, 0);
            //document.body.style.overflow = "visible";
            //window.setTimeout("document.body.style.overflow = 'hidden';", 1);
            window.scrollTo(0, 0);
            window.setTimeout("document.body.style.overflow = 'hidden';", 1);
        }
        
        inputs = modalPopup.getElementsByTagName('input');
        if (inputs.length > 0)
        {
            for(i = 0; i < inputs.length; i++)
            {
                if (inputs[i].type == 'text') inputs[i].value = '';
            }
        }
        
        textarea = modalPopup.getElementsByTagName('textarea');
        if(textarea.length > 0)
            textarea[0].value = '';
    }    
    
    function closeTabPopup(popupID)
    {
        document.getElementById(popupID).style.display = "none";      
        document.getElementById("modalMask").style.display = "none";  
        document.body.style.overflow = "auto";                                      
    }          
      
    function displayModalPopup(popupID)
    {
        var modalMask   = $get("modalMask");
        var modalPopup  = $get(popupID);
              
        $get(popupID).style.display = "none";
        $get("modalMask").style.display = "none";
        
        if (modalMask && modalPopup)
        {
            modalPopup.style.display = "block";

            var bounds = Sys.UI.DomElement.getBounds(document.documentElement);
            var modalWindowBounds = Sys.UI.DomElement.getBounds(modalPopup);
           
            
            modalPopup.style.top = ((bounds.height - modalWindowBounds.height) / 2)  + 'px';
            modalPopup.style.left = (bounds.width - modalWindowBounds.width) / 2  + 'px';
            
            //modalMask.style.height = bounds.height + 'px';
            //modalMask.style.width = bounds.width + 'px';
            //modalMask.style.display = "block";
            
            window.scrollTo(0, 0);
            
            document.body.style.overflow = "visible";
            
        }
        
        inputs = modalPopup.getElementsByTagName('input');
        if (inputs.length > 0)
        {
            for(i = 0; i < inputs.length; i++)
            {
                if (inputs[i].type == 'text') inputs[i].value = '';
            }
        }
        
        textarea = modalPopup.getElementsByTagName('textarea');
        if(textarea.length > 0)
            textarea[0].value = '';
    }
    
    
    function displayPopup(popupID)
    {
        var modalPopup  = document.getElementById(popupID);              
        document.getElementById(popupID).style.display = "none";
        
        if (modalPopup)
        {
            modalPopup.style.display = "block";            
            modalPopup.style.top = ((document.body.clientHeight - modalPopup.offsetHeight) / 2) + 'px';
            modalPopup.style.left = (document.body.clientWidth - modalPopup.offsetWidth) / 2 + 'px';            
            window.scrollTo(0, 0);            
            document.body.style.overflow = "visible";            
        }
        
        inputs = modalPopup.getElementsByTagName('input');
        if (inputs.length > 0)
        {
            for(i = 0; i < inputs.length; i++)
            {
                if (inputs[i].type == 'text') inputs[i].value = '';
            }
        }
        
        textarea = modalPopup.getElementsByTagName('textarea');
        if(textarea.length > 0)
            textarea[0].value = '';
    }
    
  function closeModalPopup(popupID)
    {
        document.getElementById(popupID).style.display = "none";
        document.getElementById("modalMask").style.display = "none";        
        document.body.style.overflow = "auto";
    }
    
    function closePopup(popupID)
    {
        document.getElementById(popupID).style.display = "none";            
        document.body.style.overflow = "auto";
    }

    function referFriend() 
    {
        window.location = "http://friends.zecco.com";
    }