// This is a hacked up version of:
// http://www.codestyle.org/javascript/dom/css/visibility-HorizontalMenus.shtml
// Copyright (c) 2001-2003, Philip Shaw
// This hack is by K. Chayka, at:
// http://accessat.c-net.us/articles/menu/h_drop-down-menu.html
// If you take the code, please give credit where it is due.  thanks!

//  customize these variables as needed
var mCount = 4;           // number of menu groups
var mTix   = "";          // main group link tabindex value (numeric, blank=none)
var sTix   = "";          // sub-menu link item tabindex value (numeric, blank=none)
var lSep   = " &#8226; "  // link separator (space-bullet-space) for legacy browsers
var sInd   = "&nbsp;<span><img src=\"darrow.gif\" height=\"9\" width=\"9\" alt=\"\"><\/span>"
                           // sub-menu indicator (small down arrow image)
                           // might also try &#9660; or &#8595; instead of img
var dbug = false;         // set to true to dump the generated code

//  variables below do not need customizing
var mOpen = null;         // currently open menu
var mClose = null;        // menu to close
var stdDOM = document.getElementById;
var dom = "";
var mStr = "";
var menu = new makeArray(mCount);

function makeArray(n) {
  this.size = n;
  for(i=1; i<=n; i++){
    this[i] = 0;
  }
  return(this);
}

// Top-level menu group/category constructor:
function menuGroup(n,groupName,groupURL,groupTitle,groupAkey) {
// I personally like the idea of the submenu indicator, but the Unicode characters 
// that would give desireable results are not supported in the standard Mac (Classic)
// fonts.  A small image might be substituted, but that is not scalable and doesn't
// look as good, IMO.  Uncomment the 'if' statement if you'd like to experiment with it.
  this.size       = n;             // number of submenu links
  this.groupName  = groupName;     // button 'label'
//  if (stdDOM && (n > 0)) { this.groupName += sInd; }  // submenu indicator
  this.groupURL   = groupURL;      // button URL
  this.groupTitle = groupTitle;    // title attribute
  this.groupAkey  = groupAkey;     // accesskey value
  this.item       = new makeArray(n);
}

// Submenu list item constructor:
function menuItem(itemName,itemURL,itemTitle) {
  this.itemName  = itemName;       // link label
  this.itemURL   = itemURL;        // link url
  this.itemTitle = itemTitle;      // title attribute
}



if (dbug) {debugWindow(mStr);}  // see the generated code in a pop-up window

function debugWindow (val) { 
  var newWin = window.open("","dBug");
  newWin.document.write(val);
  newWin.document.close();
}

// *************** Functions called by mouseover/mouseout start here
// Mouseover a menu
function menuOver(m){
  if (!stdDOM) {return;}
  dom = document.getElementById(m);
  if (dom != null) {
    if (mOpen == dom) {       // already open
      clearTimeout(mClose);   // don't close
    } else {
      if (mOpen != null) {    // another is open
        clearTimeout(mClose);
        hideNow();            // close it now
      }
    }
  mOpen = dom;                // set new open menu
  mOpen.style.visibility = "visible";    // show it
}
}
// Keep menu open
function stayOpen(m){
  // If menuOver has not been called or the menu is hidden, do nothing
  if ((mOpen == null) || ((mOpen.style) && (mOpen.style.visibility) && (mOpen.style.visibility == "hidden"))) return;
  else menuOver(m);
}
// Close menu after timeout
function menuOut(m){
  dom = document.getElementById(m);
  if ((stdDOM) && (dom != null)) {
    mOpen = dom;	// get current open menu
    mClose = window.setTimeout("hideNow();",400);  // auto-close after 400ms
  }
}
// Close previous menu now
function hideNow(){
  if ((mOpen.style) && (mOpen.style.visibility)) {
    mOpen.style.visibility = "hidden";
  }
}
function gotoUrl(url){
top.document.location.hash = 'top';
	if (url.indexOf('subscribeClick') > -1){
		subscribeClick();
	}else if (url.indexOf('questionAcctClick') > -1){
		questionAcctClick();	
	}else if (url.indexOf('subscribenewClick') > -1){
		subscribenewClick();		
	}else{
		//top.document.mainfpn.location.href = url;
		//top.document.frames['mainfpn'].location.href = url;
		var userEmail = "";
		if(document.getElementById("userEmail")) {
			if(url.indexOf("?") > 0)
				userEmail = "&user=" + document.getElementById("userEmail").value;
			else
				userEmail = "?user=" + document.getElementById("userEmail").value;
		}
		if(top.document.getElementById('mainfpn')) {
			top.document.getElementById('mainfpn').contentWindow.focus();
			top.document.getElementById('mainfpn').src = url + userEmail;
		} else if(parent.fpnFrame.document.getElementById('mainfpn')) {
			parent.fpnFrame.document.getElementById('mainfpn').contentWindow.focus();
			parent.fpnFrame.document.getElementById('mainfpn').src = url + userEmail;
		}
		//var content = top.document.getElementById('mainfpn').document.body.createTextRange().htmlText
		//var content = top.document.getElementById('mainfpn').document.body.createTextRange().innerText;
		//alert(content);
		
	}	
}
function calcHeight(id){ 
	top.document.location.hash = 'top';
	var the_height = 0;
	if (document.getElementById('mainfpn').src.indexOf('fpnAccount') > -1){
		the_height = document.getElementById('rightMenu').style.height;
	}else if (document.getElementById('mainfpn').src.indexOf('fpnProduct') > -1){
		the_height = 2400;
	}else{
		try{
			the_height = top.document.getElementById(id).contentWindow.document.body.scrollHeight;//find the height of the internal page
		}catch(e){
			the_height = 2400;
		}
	}
	if(the_height < 1)
		the_height = 2400
	if(top.document.getElementById(id)) {
		top.document.getElementById(id).style.height = the_height;//change the height of the iframe
	} else if(parent.fpnFrame.document.getElementById(id)) {
		parent.fpnFrame.document.getElementById(id).style.height = the_height;
	}
}

//document.domain = "advisen.com";
