/**
 * JavaScript Functions used throughout the site
 *
 * @author      joycelyn.chung@barclaysglobal.com
 * @revision    $Id: default.js,v 1.23 2008-05-29 19:53:41 aktuozg Exp $
*/

var IE = (document.all)?1:0;
var dynamic_uri = "";
var product_info_ajax_uri = "/fund_returns";

/* Function: Fixes HTML-encoded strings 
   XHTML requires special characters like & to be encoded, but the browsers do not decode these characters properly
   when they appear inside Javascript literals. This method does the decoding the browser doesn't.
*/
function decodeHtmlString(s) {
  return s.replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, "\"");
}

/* Function: Sets the mouse point css style */
function setMousePointer(obj) {
  obj.style.cursor='pointer';
}


/* Function: search box text funcitonality */
function searchFocus(obj) {
  if (obj.value == ' Search') {
    obj.value = '';
  }
}

function searchBlur(obj) {
  if (obj.value == '') {
    obj.value = ' Search';
  }
}

/* Function: This is used for the broker/dealer link on the Splash and Welcome Back Pages*/
function goBrokerDealer() {
  ///
  //alert("inside goBrokerDealer() function");
  ///
  if (page_code=="SPLASH") {
    document.welcome.investorTypeCode.options.selectedIndex=0;
    document.welcome.investorTypeCode.options[0].value="BROKER_DEALER";
    document.welcome["continue"].value="true";
  } else if (page_code=="WELCOME_BACK") {
    document.welcome.bd_flag.value="true";
    document.welcome.confirm.value="true";
  }
  document.welcome.submit();
}

/* Function: Used to open popup windows */
var popup_win;
function openPopup(url, name, attributes) {
	if (url) {
		if (name == 'asset_illustrator') { // this logic prevents a second pop-up after the user logs in
			if (popup_win && !popup_win.closed && popup_win.focus) {
				popup_win.focus();
			}
			else {
    			popup_win = window.open(url, "asset_illustrator", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	popup_win.focus(); 
    	}
    }
		else if (name == 'correlation_calculator') { // this logic prevents a second pop-up after the user logs in
			if (popup_win && !popup_win.closed && popup_win.focus) {
				popup_win.focus();
			}
			else {
    			popup_win = window.open(url, "correlation_calculator", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	popup_win.focus(); 
    	}
    }
		else if (name == 'international_exposure') { // this logic prevents a second pop-up after the user logs in
			if (popup_win && !popup_win.closed && popup_win.focus) {
				popup_win.focus();
			}
			else {
    			popup_win = window.open(url, "international_exposure", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	popup_win.focus(); 
    	}
    }
		else if (name == 'index_comparison') { // this logic prevents a second pop-up after the user logs in
			if (popup_win && !popup_win.closed && popup_win.focus) {
				popup_win.focus();
			}
			else {
    			popup_win = window.open(url, "index_comparison", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
		    	popup_win.focus(); 
    	}
    }
    else {
			popup_win = window.open(url, (name)?name:"_blank", (attributes)?attributes:"toolbar=no,scrollbars=yes,resizable=yes,height=510,width=650");
			popup_win.focus(); 
		}
	}
}

/* Function: Javascript link */
function openLocation(url) {
  if (url) {
    window.status = url;
    window.location.href = url;
  }
}

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
    else {
      return null;
    }
  } 
  //alert('Query Variable ' + variable + ' not found');
}

/* Function: Pauses JavaScript processing for specified duration (millis) */
function wait(millis)
{
	date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
}


var sWidth_Streamlogics = (screen.width) ? screen.width : 0;
var sHeight_Streamlogics = (screen.height) ? screen.height : 0;
function openWin_Streamlogics(linkref) { 
	var screensize;
	var pTop;
	var pLeft; 
	var aWidth;
	var aHeight; 
	
	if (sWidth_Streamlogics > 1000) { // if the screen res is higher than 800x600 then open the large auditorium      
		aWidth = 1014;
		aHeight = 678; 
		screensize = "large";   
	}
	else {
		aWidth= 790;     
		aHeight = 510;     
		screensize = "small";   
	}
	   
	pLeft = (sWidth_Streamlogics - aWidth) / 2;   
	pTop = ((sHeight_Streamlogics - aHeight) / 2 ) - 40;   
	if (pTop < 0) pTop = 0;
	if (pLeft < 0) pLeft = 0;
	var aWindow_Streamlogics=window.open(linkref,"thewindow","width="+aWidth+",height="+aHeight+",top="+pTop+",left="+pLeft+",toolbar=0,location=0,statusbar=0,menubar=0,resizable=0;scrollbars=1");   
  if (aWindow_Streamlogics) aWindow_Streamlogics.focus();
}



