// looks for the menu and hidden windows, even if this page was opened in a new window
var mparent=window.top;
var menuwindow=mparent.menu;
var mcontent;


try {
while(typeof(menuwindow) == "undefined") {
	mparent=mparent.opener;
	if(mparent == null) {
		break;  // can't find the menu
	}
	mparent=mparent.top;
	menuwindow=mparent.menu;
}
var menubottomwindow=mparent.menubottom;
while(typeof menubottomwindow == "undefined") {
	mparent=mparent.opener;
	if(mparent == null) {
		break;  // can't find the menu
	}

    if(mparent.mparent) {
        // take the mparent of my parent.
        mparent=mparent.mparent;
    }
    else {
        mparent=mparent.top;
    }
    menuwindow=mparent.menu;
}
}
catch(e){}

function dOnFocus() {
  mparent.clearAlertMark();
}
if(mparent && navigator.userAgent.toLowerCase().indexOf("gecko")!=-1) {
 window.onfocus=dOnFocus;
}

// invert the checked status of a group of check boxes
function toggleSelection2(form,prename) {
	var elements=form.elements;
	for(i=0;i<elements.length;i++) {
		var el=elements[i];
		if(typeof el.name!="undefined") {
			if(el.name.indexOf(prename)==0) {
				el.checked=!el.checked;
			}
		}
	}
}

// invert the checked status of a group of check boxes
function toggleSelection(form) {
	toggleSelection2(form,"select_");
}

function isAnySelected(form) {
	var elements=form.elements;
    var prename="select_";
	for(i=0;i<elements.length;i++) {
		var el=elements[i];
		if(typeof el.name!="undefined") {
			if(el.name.indexOf(prename)==0) {
				if(el.checked) return true;
			}
		}
	}
    return false;
}

// cancels an event from bubbling up
function cancelIt(evt) {
  var e = (typeof evt != 'undefined') ? evt : event;
  e.cancelBubble = true;
}

function isSplit() {
if(window.parent) {
  if(window.parent.frames["list"]) return true;
}
return false;
}

// open a link in the parent (if this is a section of a splitframe, like a mailfolder), or in the current win if not split
function openInSplitParent(url) {
var w;
if(isSplit()) {
  w=window.parent;
}
else {
  w=window;
}
w.location.href=url;
}

/** open or download */
function fileOD(urlopen,urldownload) {
// tries to open a file in the proper way.
// urlopen= download url for inline content disposition
// urldownload= download url for attachment content disposition
// if the extension is html, opens inline, in a new browser window
// note that the most strictly appropriate way would be to use also the request's "Accept" header (matching it with the mimetypes database in web.xml) to see other filetypes that the browser can open inline.
// however, most users do not like to edit an Excel spreadsheet in an IE window...
// finally, it is fairly easy to change this code so that other file extensions get opened 'inline'
if(endsWith(urlopen,"html")|| endsWith(urlopen,"htm")) {
  fileO(urlopen);
}
// otherwise shows download/open dialog
else {
  fileD(urldownload);
}
}

function fileO(urlopen) {
  var w=window.open("about:blank","_blank");
  w.location.href=urlopen; // this will open inside the browser's window
}

function fileD(urldownload) {
  // if you have IE on XP before XP ServicePack 2, and notice that the menu buttons don't work after downloading a file or attachment,
  // change this variable to true. Then right-click on the page and select 'Refresh' to reload the script.
  var safe_mode_for_ie_before_sp2=false;


  if(safe_mode_for_ie_before_sp2) {
    if(isIe()) {
      window.open(urldownload,"_blank");
    }
    else {
      window.location.href=urldownload;
    }
  }
  else {
    window.location.href=urldownload;
  }

}

function forceReload() {
  mparent.location="home.do?Action=Reload";
}





