function printResize()
{
   window.resizeTo('800', '600');
}
function getRandom(min, max)
{
   max++;   //add one to the max number specified so that the specified value can actually be returned
   range = max - min;
   now = new Date();
   seed = now.getSeconds();
   randomNumber = Math.random(seed);         //get a random number between 0 & 1
   randomNumber = randomNumber * range;      //convert this to a random number between 0 & range
   roundedNumber = Math.round(randomNumber); //round the number off to an integer (down if less than .5, up if greater than)
   if (roundedNumber == range)
      {roundedNumber = 0;}
   roundedNumber = roundedNumber + min;

   return roundedNumber
}

function showPopupOnce(popupTitle, chance, wUrl, wWindowName, wWidth, wHeight, wTop, wLeft, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable) {

   if (chance<100)
   {
      num = getRandom(0, 100);
      if (num > chance) return false;
   }

	if (GetCookie("seenpopup" + popupTitle) == 'true') return true;

	var expires = new Date();
	expires.setTime(expires.getTime() + 3E11);

   SetCookie("seenpopup" + popupTitle, true, expires, "");
   openAnyWinTwo(wUrl, wWindowName, wWidth, wHeight, wTop, wLeft, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable);

	return true;
}

function showPopup(chance, wUrl, wWindowName, wWidth, wHeight, wTop, wLeft, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable) {

   if (chance<100)
   {
      num = getRandom(0, 100);
      if (num > chance) return false;
   }

   openAnyWinTwo(wUrl, wWindowName, wWidth, wHeight, wTop, wLeft, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable);
	return true;
}

function selectOption(text, value)
{
    this.text=text;
    this.value=value;
}

function img_act(imgName)
{
        if (document.images)
        {
        imgOn = eval(imgName + "on.src");
        document [imgName].src = imgOn;
        }
}

function img_inact(imgName)
{
        if (document.images)
        {
        imgOff = eval(imgName + "off.src");
        document [imgName].src = imgOff;
        }
}

function ReloadPage(pageString)
{
	var amp = "/&";
	var equals = "/=";

	// Add a double ampersand at the end so that all parameters have ampersands
	pageString = pageString + amp;

	// Use the ampersand to work out how many parameters there are
	var numOfPages = 0;

	for (i = 0; i < pageString.length; i++)
	{
		var ch = pageString.substring(i, i+2);
		if (ch == amp)
		{
			numOfPages = numOfPages + 1;
		}
	}

	var ampIndex1 = 0;
	var ampIndex2 = pageString.indexOf(amp, 0);

	// For each parameter, cut it out as a substring, then work out which frame it is asking to be
	// replaced and set the correspoding hidden field to that value
	for (j = 0; j < numOfPages; j++)
	{
		var paramSubstring = pageString.substring(ampIndex1, ampIndex2);
		var equalsIndex = paramSubstring.indexOf(equals, 0);
		var frameNum = paramSubstring.substring(0, equalsIndex);
		var fullFramePath = paramSubstring.substring(equalsIndex + 2, paramSubstring.length);

		if (fullFramePath.indexOf("home") == 1)
		{
			var slashIndex = fullFramePath.indexOf("/", 1)
			var fullFramePath = fullFramePath.substring(slashIndex, fullFramePath.length);
		}

		if ((fullFramePath != null) && (fullFramePath.length > 0))
                {
			field = eval("document.theForm.FC" + frameNum);
			field.value = fullFramePath;
                }

		ampIndex1 = ampIndex2 + 2;
		ampIndex2 = pageString.indexOf(amp, ampIndex1);
	}

	// Remove whitespace from the end of the FC3.
	var url = document.theForm.FC3.value;
	url = url.replace(/\s+$/,'');
   document.theForm.FC3.value = url;

	document.theForm.submit();
}


function SetChildOpenerNull(win)
{
  wind = eval(win);
  wind.opener = null;
}

function setContentHeight() {
  	if (!window.innerHeight) {
  		contentHeight = document.body.clientHeight - bannerHeight - 129;
	} else {
  		contentHeight = window.innerHeight - bannerHeight - 127;
	}
      return contentHeight
}

function setContentWidth() {
  	if (document.all) {
  		contentHeight = document.body.clientWidth - 150 - impulse;
	} else {
		contentHeight = window.innerWidth - 150 - impulse;
	}
		return contentHeight
}

function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function openInParent2(url)
{
   if(window.opener && !window.opener.closed){
      var parentWin = window.opener;
      parentWin.location.href = url;
      parentWin.focus();
      window.close();
   } else {
      now = new Date();
      var winName = 'window' + now.getHours() + now.getMinutes() + now.getSeconds();
      openAnyWinTwo(url,winName,800,600,0,0,0,1,1,1,1,1,1);
      window.close();
   }
}

function openInParent(url, parentUrl, lhnState)
{
   var pattern = /^\/home/;
   parentUrl = replace(parentUrl,'%2F','/');
   parentUrl = replace(parentUrl,'%3D','=');
   parentUrl = replace(parentUrl,'%3F','?');
   if(pattern.test(url)){
      var protocolSplit = parentUrl.split(':');
      var serverSplit = parentUrl.split('/');
      var serverName = protocolSplit[0] + '://' + serverSplit[2];
      if(!lhnState)
      {
         var params = parentUrl.split('&');
         lhnState=params[2].substr(30);
      }
      var result = url.split('/');
      var siteId = result[2];
      url = url.substr(5);

      url = serverName + '/home/Framework?siteId=' + siteId + '&FC1=&FC2=/LeftHandNav?LeftNavState=' + lhnState + '&FC3=' + url + '&FC4=&FC5=';
   }

   if(window.opener && !window.opener.closed){
      var parentWin = window.opener;
      parentWin.location.href = url;
      parentWin.focus();
   }
   else
   {
      now = new Date();
      var winName = 'window' + now.getHours() + now.getMinutes() + now.getSeconds();
      openAnyWinTwo(url,winName,800,600,0,0,0,1,1,1,1,1,1);
   }
}

function openAnyWinTwo (wUrl, wWindowName, wWidth, wHeight, wTop, wLeft, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable)
{
var features= 'width='        + wWidth +
              ',height='      + wHeight +
              ',top='        + wTop +
              ',left='      + wLeft +
              ',directories=' + wDirectories +
              ',location='    + wLocation +
              ',menubar='     + wMenubar +
              ',scrollbars='  + wScrollbars +
              ',status='      + wStatus +
              ',toolbar='     + wToolbar +
              ',resizable='   + wResizable;
window.open (wUrl, wWindowName, features);
}

function openAnyWin (wUrl, wWindowName, wWidth, wHeight, wDirectories, wLocation, wMenubar, wScrollbars, wStatus, wToolbar, wResizable)
{
var features= 'width='        + wWidth +
              ',height='      + wHeight +
              ',directories=' + wDirectories +
              ',location='    + wLocation +
              ',menubar='     + wMenubar +
              ',scrollbars='  + wScrollbars +
              ',status='      + wStatus +
              ',toolbar='     + wToolbar +
              ',resizable='   + wResizable;
window.open (wUrl, wWindowName, features);
}

function SubmitContent(path)
{
  window.document.theForm.FC3.value=path;
  window.document.theForm.action="/home/Framework";
  window.document.theForm.submit();
}

function getsitetype(searchstr, strprefix, offset){
   start = searchstr.lastIndexOf(strprefix);
   if (start != -1){
     return searchstr.substring(start-offset,start);
     }
   else
     {
     return "err";
     }
}

function writebannerimage(sitetype) {
  if (sitetype == "msf" || sitetype == "msd") {
    bannerurl = statichost + "/static/global/fwimgs/" + sitetype + "_banner.jpg";
    document.write("<img src='" + bannerurl + "' border=\"0\" width=\"480\" height=\"101\">");
  } else if(sitetype == "nam") {
    bannerurl = statichost + "/static/global/fwimgs/" + sitetype + "_banner_37by306.gif";
    document.write("<IMG SRC='" + bannerurl + "' border=\"0\" width=\"306\" height=\"37\">");
 }
}

function writeCurve(sitetype) {
   var curveImage = statichost + "/static/global/fwimgs/" + sitetype + "_curve.gif";
   var curveTile = statichost + "/static/global/fwimgs/" + sitetype + "_curve_tile.gif";
   document.write("<td colspan=\"3\" background=\"" + curveTile + "\"><img src=\"" + curveImage + "\" alt=\"\" width=\"409\" height=\"6\"></img></td>");
}

function SubmitImpulse(path) {
  window.document.theForm.FC3.value=path;
  window.document.theForm.action="/home/Framework";
  window.document.theForm.submit();
}

function linkjumpto(){

	if (document.country.countryBox.options[document.country.countryBox.selectedIndex].value != "no_jump") {
		// window.parent.window.parent.location = document.country.countryBox.options[document.country.countryBox.selectedIndex].value
		redirect=document.country.countryBox.options[document.country.countryBox.selectedIndex].value
		top.location = redirect

	}
}

function jumpto2(url) {
	if (url == "" || url == "no_jump") {
	   return;
	}
	top.location = url;
}

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}

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,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function HandleSubscription1 () {
  openAnyWinTwo("", "ShellSubscriptionWindow", 490, 300, 168, 152, 0, 0, 0, 0, 0, 0, 0);
  window.document.SubscriptionForm.referringPage.value = location.href;
  window.document.SubscriptionForm.shellCookie.value = GetCookie("SHELL.COM");
  return true;
}

function HandleSubscription2 () {
  HandleSubscription1();
  window.document.SubscriptionForm.submit();
}