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 getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

var homeCookie = GetCookie("MARKETING_COOKIE_1"); // 0:default | 1:amer | 2:apex | 3:uk | 4:amervst | 5: tdw | 6: SY/Suzie Orman
var pageNum = "1"; // 1:default,amervst,uk | 2:sy  | 3:apex | 4:amer,f tdw

switch(homeCookie){
	case "1" : pageNum = "4"; break; // amer
	case "2" : pageNum = "3"; break; // apex
	case "3" : pageNum = "1"; break; // uk
	case "4" : pageNum = "1"; break; // amerivest
	case "5" : pageNum = "4"; break; // tdw
	case "6" : pageNum = "2"; break;	// sy / suzie orman
	default: pageNum = "1";
}

var loc = document.location.href; 
var ht = "teamsite"; var hm = "mantle"; //override properties
var regex = new RegExp('iw-mount');
var testdev = (loc.toLowerCase().indexOf(ht)!=-1 || loc.match(regex));
var mantleindx = loc.toLowerCase().indexOf(hm);
var testmantle = (mantleindx!=-1);

var mantleRotations = mantleArray.length; //number of slots
var randomMantle = (testmantle) ? new Number(loc.substring(mantleindx+7,loc.length))-1 : (Math.floor(Math.random()*mantleRotations));
var thisMantle = mantleArray[randomMantle]; 

if (!testdev){  
	var pageType = ".html";  
	var lngth = loc.indexOf(pageType)-1;
	var thisPage = loc.substring(lngth,lngth+1);
	if (thisPage != pageNum) document.location.href = "\welcome" + pageNum + pageType;
} 

function resizeModBox(frameID) {
  //find the height of the internal page
  var the_height = document.getElementById(frameID).contentWindow.document.body.scrollHeight;
  //change the height of the iframe
  document.getElementById(frameID).height = the_height;
}


