// Initializations for Millennia Logix savings calculator
// Copyright 1999-2005 Millennia Logix, Inc by Paul Johnson and John B Lisle

// *** NS 4 fixes
 
function NS4_setBodyMargins(marginLeft, marginTop) {
	if (document.tags) {
		document.tags.BODY.margins(marginLeft, marginTop)
	}
}

function NS4_removeBodyMargins() {
	if (document.layers)  {
		var margins = { 'mac':[-8, -8],
					    'win':[-10, -16],
					    'nix':[-20, -22] }
		var platform = navigator.platform.toLowerCase()
		var isMac = platform.indexOf('mac') != -1
		var isWin = platform.indexOf('win') != -1

		if (isMac) {
			NS4_setBodyMargins(margins['mac'][0], margins['mac'][1])
		} else if (isWin) {
			NS4_setBodyMargins(margins['win'][0], margins['mac'][1])
		} else {
			NS4_setBodyMargins(margins['nix'][0], margins['nix'][1])
		}
	}
	return true
}

NS4_removeBodyMargins()

function NS4_initResizeBugfix() {
	if (document.layers) {
	   window.loadWidth = window.innerWidth
	   window.loadHeight = window.innerHeight
	   window.onresize = NS4_restore
	}
}

function NS4_restore() {
   if (window.loadWidth != window.innerWidth || window.loadHeight != window.innerHeight) {
      history.go(0) //reload page
   }
}

/**
 * xbDOM functions
 */

function nav4FindLayer(doc, id)
{
  var i;
  var subdoc;
  var obj;
  
  for (i = 0; i < doc.layers.length; ++i)
  {
    if (doc.layers[i].id && id == doc.layers[i].id)
      return doc.layers[i];
      
    subdoc = doc.layers[i].document;
    obj    = nav4FindLayer(subdoc, id);
    if (obj != null)
      return obj;
  }
  return null;
}

if (document.layers)
{
  xbGetElementById = function (id, windowRef)
  {
    if (!windowRef)
      windowRef = window;

    return nav4FindLayer(windowRef.document, id);
  };

}
else if (document.all)
{
  xbGetElementById = function (id, windowRef) { if (!windowRef) windowRef = window; var elm = windowRef.document.all[id]; if (!elm) elm = null; return elm; };
}
else if (document.getElementById)
{
  xbGetElementById = function (id, windowRef) { if (!windowRef) windowRef = window; return windowRef.document.getElementById(id); };
}
else 
{
  xbGetElementById = function (id, windowRef) { return null; }
}

// tweak PMI disclaimer style for NS4
//if (document.layers && document.ids) {
//	document.ids.PMIdisclaimer.display = 'block'
//	document.ids.PMIdisclaimer.position = 'relative'
//	document.ids.PMIdisclaimer.visibility = 'hidden'
//}

//function ShowPMIdisclaimer() {
//	elt = xbGetElementById('PMIdisclaimer')
//	if (elt) {
//		if (document.layers) {
//			elt.visibility = 'visible'
//		}
//		else {
//			elt.style.display = 'block'
//		}
//	}
//}

//function HidePMIdisclaimer() {
//	elt = xbGetElementById('PMIdisclaimer')
//	if (elt) {
//		if (document.layers) {
//			elt.visibility = 'hidden'
//		}
//		else {
//			elt.style.display = 'none'
//		}
//	}
// reset the calculated indicator
//	bCalc = false
//}


function getRadioButtonValue (radio)
{  var result = ""; 
   for (var i = 0; i < radio.length; i++) {   
	  if (radio[i].checked) {
			result =  radio[i].value;
			break 
	  }
    }
    return result
}


function SetDefaults() {
	if (typeof formDefaults != 'undefined') {
		for (d in formDefaults) {
			if (document.forms[0][d]) {
				document.forms[0][d].value = formDefaults[d]
				document.forms[0][d].defaultValue = formDefaults[d]
			}
		}
	}
}

function InitPage() {
	NS4_initResizeBugfix()
	SetDefaults()
	self.focus()
}

window.onload = InitPage