var disclaimerObj = new Object();

function addDisclaimer(link, extCompany)
{	
	var onclick = link.onclick;
	var href = link.href;
	var target = link.target ? link.target : "_blank";
	
	link.onclick = function()
	{
		var onAccept = function()
		{				
			//Cookie.set("disclaimer_" + fundFamily,"true");
			
			// original onclick event
			if(onclick)
				if(!onclick())
					return false;
			
			// original href
			window.open(href, target);
			return false;				
		};
	
		popupDisclaimer(extCompany, onAccept, null);	
		return false;
	};
}

function addDisclaimerLink(href, extCompany)
{	
	var target = "_blank";
	var onAccept = function()
	{		
		// original href
		window.open(href,target);
		return false;
	};
	
	popupDisclaimer(extCompany, onAccept, null);
	return false;
}

function addDisclaimerPopup(href, extCompany)
{	
	var onAccept = function()
	{		
		// original href
		window.open(href,'popWin','menubar=0,toolbar=0,scrollbars=1,resizable=0,width=800,height=600');
		return false;
	};
	
	popupDisclaimer(extCompany, onAccept, null);
	return false;
}

function addDisclaimerPopupFull(href, extCompany)
{	
	var onAccept = function()
	{		
		// original href
		window.open(href,'popWin','menubar=1,toolbar=1,scrollbars=1,resizable=1,width=900,height=600');
		return false;
	};
	
	popupDisclaimer(extCompany, onAccept, null);
	return false;
}

function popupDisclaimer(extCompany, onAccept, onCancel)
{
	var mask = createMask();
	var popup = createPopup();
	var content = document.createElement("div");
	var buttonBar = document.createElement("div");
	var acceptButton = document.createElement("div");
	var cancelButton = document.createElement("div");

  var cleanup = function()
  {
    document.body.removeChild(mask);
    document.body.removeChild(popup);
  };    
    
  content.className = "content";
  buttonBar.className = "button_bar";
  if (extCompany == "other")
  {
    content.innerHTML = "<div align=\"left\" style=\"color:#369;font-size:14px;padding:20px\"><strong>You are now opening a website not operated by Western Asset.</strong><p>Western Asset is not responsible for any content on this website.<p><p></div>";
  }
  else if (extCompany == "Legg Mason Inc.")
  {
    content.innerHTML = "<div align=\"left\" style=\"color:#369;font-size:14px;padding:20px\"><strong>By accepting, you will be taken to the Legg Mason Investor Services, LLC's (LMIS) website.</strong><p>LMIS is a FINRA registered broker-dealer and is the underwriter for the Funds. Western Asset and LMIS are Legg Mason affiliated companies. Please confirm that you agree to the terms and conditions of the LMIS website.<p><p></div>";
  }
  else
  {
    var theVar = "the ";
    if (extCompany.substr(0,4) == "The " || extCompany.substr(0,4) == "the ") {
      theVar = "";
    }
    content.innerHTML = "<div align=\"left\" style=\"color:#369;font-size:14px;padding:20px\"><strong>You are now opening a website operated by " + extCompany + ".</strong><p>Western Asset is not responsible for any content on " + theVar + extCompany + " website.<p><p></div>";
  }
  
  acceptButton.className = "accept_button";
  acceptButton.innerHTML = "";
  acceptButton.onclick = function()
  {
    cleanup();
    if(onAccept)
      onAccept();
  };    
  
  cancelButton.className = "cancel_button";
  cancelButton.innerHTML = "";
  cancelButton.onclick = function() 
  {
    cleanup();
    if(onCancel)
      onCancel();
  };
  
  popup.appendChild(content);
  buttonBar.appendChild(cancelButton);  
  buttonBar.appendChild(acceptButton);      
  popup.appendChild(buttonBar);
}


function getViewportHeight()
{
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}

function getViewportWidth() 
{
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}


function createMask()
{
	var mask = $(document.createElement("div"));
	mask.addClass("modal_mask");
	document.body.appendChild(mask);
	mask.setOpacity(0.70);							
	mask.style.width = Math.max(getViewportWidth(), document.body.scrollWidth) + "px";
	mask.style.height = Math.max(getViewportHeight(), document.body.scrollHeight) + "px";
	return mask;
}

function createPopup()
{
	var popup = document.createElement("div");
	popup.className = "modal_popup";
	if (document.documentElement && document.documentElement.scrollTop) {popup.style.top = document.documentElement.scrollTop + "px";}
	else {popup.style.top = document.body.scrollTop + "px";}
	document.body.appendChild(popup);
	
	return popup;		
}