/*--------------------------------------------------------------
** Cookie functions **
** **
** Checks the entire length of a string to ensure that it **
** contains non-whitespace characters... **
**------------------------------------------------------------*/
function getCookieVal(offset) {
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) 
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function getCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
function setCookie(name, value, hours) {
 var expire = "";
 if (hours == null)
 {
 hours = 24;
 }
 expire = new Date((new Date()).getTime() + hours * 3600000);
 expire = "; expires=" + expire.toGMTString();
 document.cookie = name + "=" + escape(value) + expire + "; path=/";;
 return true;
}
function deleteCookie(name, value) {
	var expires = new Date((new Date().getDate() - 1));
 document.cookie = name + "=" + value + "; expires=" + expires.toGMTString();
}
































function checkCookie (name, termPage) {
	var accept;
	if ((accept = getCookie(name))) {
	 if ( accept != "Yes" ) {
		document.location=termPage;
	 }
	} else {
		document.location=termPage;
	}
	return null;
}
// Replace iframe contents with Terms Of Use (TOU) or content depending
// on presence of cookie. Specific to mscibarra.com. Depends on an
// iframe with id="guts", must be called after iframe tag.
// , acceptHeight, noAcceptHeight, acceptWidth)
function acceptTOU(cookieName, acceptTarget, noAcceptTarget)
{
 var accept;
 var target;
 if ((accept = getCookie(cookieName))) 
 {
 if (accept == "Yes")
 {
 if (document.getElementById)
 {
 var fr = document.getElementById("guts");
	 if (null != fr) 
 {
 fr.src = acceptTarget;
 }
 }
 }
 else
 {
 if (document.getElementById)
 {
 var fr = document.getElementById("guts");
 fr.src = noAcceptTarget;
 }
 }
 }
 else
 {
 if (document.getElementById)
 {
 var fr = document.getElementById("guts");
 fr.src = noAcceptTarget;
 }
 }
}
// Legal wants separate click-wrap cookie for each product line.
function pickCookie(loc)
{
var c = "index_data_tou_accept";
if ( (loc.indexOf("/indices/china/") >= 0) || (loc.indexOf("/products/indices/domestic_equity_indices/china/") >= 0) ) {
 c = "china_accept";
} else if (loc.indexOf("/products/indices/domestic_equity_indices/china_zh/") >= 0) {
 c = "china_zh_accept";
} else if (loc.indexOf("/indices/kokunai/") >= 0) {
 c = "kokunai_accept";
} else if ( (loc.indexOf("/indices/us/") >= 0) || (loc.indexOf("/products/indices/domestic_equity_indices/us/") >= 0) ) {
 c = "us_accept";
} else if ( (loc.indexOf("/indices/reit/") >= 0) || (loc.indexOf("/products/indices/domestic_equity_indices/reit/") >= 0) ) {
 c = "reit_accept";
} else if ( (loc.indexOf("/indices/stdindex/") >= 0) || (loc.indexOf("/indices/equity/") >= 0) || (loc.indexOf("/products/indices/international_equity_indices/performance.html") >= 0) || (loc.indexOf("/products/indices/international_equity_indices/gimi/stdindex/performance.html") >= 0) ) {
 c = "equity_accept";
} else if (loc.indexOf("/indices/gcm/") >= 0) {
 c = "gcm_accept";
} else if (loc.indexOf("/indices/fi/") >= 0) {
 c = "fi_accept";
} else if (loc.indexOf("/indices/hfi/") >= 0) {
 c = "hfi_accept";
} else if (loc.indexOf("/products/indices/custom/") >= 0) {
 c = "custom_accept";
} else if (loc.indexOf("/products/indices/tools/gim/") >= 0) {
 c = "gim_accept";
} else if (loc.indexOf("/indices/tools/") >= 0) {
 c = "tools_accept";
}else if (loc.indexOf("/products/gics/") >= 0) {
 c = "gics_accept";
} else if ( (loc.indexOf("/products/indices/hdy/") >= 0) || (loc.indexOf("/products/indices/thematic_and_strategy/hdy/") >= 0) ) {
 c = "hdy_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/ten_forty/performance.html") >= 0) {
 c = "1040_accept";
} else if (loc.indexOf("/products/indices/licd/") >= 0) {
 c = "licd_accept";
} else if ( (loc.indexOf("/products/indices/sector/") >= 0) || (loc.indexOf("/products/indices/international_equity_indices/industry_sector_levels.html") >= 0) ) {
 c = "sector_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/infrastructure/performance.html") >= 0) {
 c = "infrastructure_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/minimum_volatility/performance.html") >= 0) {
 c = "minimum_volatility_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/leveraged/performance.html") >= 0) {
 c = "leveraged_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/equal_weighted/performance.html") >= 0) {
 c = "equal_weighted_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/commodity/performance.html") >= 0) {
 c = "commodity_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/hedging_currency/currency/performance.html") >= 0) {
	c = "currency_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/agriculture/performance.html") >= 0) {
	c = "agriculture_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/hedging_currency/fx_hedge/performance.html") >= 0) {
	c = "fx_hedge_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/fm/performance.html") >= 0) {
	c = "fm_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/fm/gcc/performance.html") >= 0) {
	c = "gcc_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/islamic/performance.html") >= 0) {
	c = "islamic_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/acwi-imi/performance.html") >= 0) {
	c = "acwiimi_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/gimi/vg/performance.html") >= 0) {
	c = "gvg_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/gimi/smallcap/performance.html") >= 0) {
	c = "smallcap_accept";
} else if (loc.indexOf("/products/indices/international_equity_indices/gimi/sector/performance.html") >= 0) {
	c = "sector_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/apex/asia_apex/performance.html") >= 0) {
	c = "asia_apex_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/apex/fem/performance.html") >= 0) {
	c = "apex_fem_accept";
} else if (loc.indexOf("/products/indices/thematic_and_strategy/factor/performance.html") >= 0) {
	c = "factor_accept";
} else if (loc.indexOf("/products/indices/domestic_equity_indices/australia/msci_australia_200_index/performance.html") >= 0) {
	c = "aus_200_accept";
} else if (loc.indexOf("/products/indices/domestic_equity_indices/australia/msci_australia_select_high_dividend_yield_index/performance.html") >= 0) {
	c = "aus_hdy_accept";
}
return c;
}
// set cookie, forward user to url after "?" in query string, if any.
function onIndexDataTermsAccepted()
{
 var newloc = window.location.search;
 if (newloc != null && newloc.length > 0) {
 newloc=newloc.substring(1, newloc.length);
 setCookie(pickCookie(newloc), "Yes");
 document.location=newloc;
 }
}
//TODO: consider going to last item in browser history rather than "/"
function onIndexDataTermsDeclined()
{
 var newloc = window.location.search;
 if (newloc != null && newloc.length > 0) {
 newloc=newloc.substring(1, newloc.length);
var msg = "You have elected not to accept the foregoing Terms of Use.\n";
msg += "You will now be returned to the home page.\n";
deleteCookie(pickCookie(newloc), "No");
alert(msg);
window.open('/','_top');
}else{window.open('/','_top');}
}






























