// Foresite Applications Script Library

function isWin(){
	if (navigator.appVersion.indexOf("Win") != -1)	return true;
	else return false;
}

function isIE(){
	if (navigator.appName == "Microsoft Internet Explorer") return true;
	else return false;
}

function isIEPC(){
	if (isWin() && isIE()) return true;
	else return false;
}

function PopWindow(page, winname, width, height, scrolls) {
	winname = window.open(page, winname, 'width='+width+',height='+height+',toolbar=no,location=no,directories=no,menubar=no,scrollbars='+scrolls+',resizable=yes');
	if(isIEPC() != 1) {
		winname.focus();
	}
}

function OnPageLoad(useTimeoutPopup, timeoutMinutes, timeoutMsg) {
	if (document.Skin_SkinForm == undefined)
		document.Skin_SkinForm = document.forms[1];
	
	if(useTimeoutPopup == null)
		useTimeoutPopup = false;
	if(useTimeoutPopup) {
		if(timeoutMinutes == null) { timeoutMinutes = 20; }
		if(timeoutMsg == null) { timeoutMsg = ''; }
		
		timerId = window.setTimeout("LaunchTimeoutPopup('" + timeoutMsg + "')", (timeoutMinutes * 60000));
	}
}

function LaunchTimeoutPopup(timeoutMsg) {
	if(timeoutMsg == '') {
		window.alert('Your session is going to time out soon.  Please save any work.');
	} else {
		window.alert(timeoutMsg);
	}
}

function toggleDiv(divId) {
	var openDisplay = "block";
	var closedDisplay = "none";
	var item;
    
	if (document.all)
		item = document.all[divId];
    
	if (!document.all && document.getElementById)
		item = document.getElementById(divId);
        
	if (item.style.display == closedDisplay) {
		item.style.display = openDisplay;
		return openDisplay;
	} else {
		item.style.display = closedDisplay;
		return closedDisplay;
	}
}

function toggleImageDiv(divId, image, onImage, offImage) {
	newDisplay = toggleDiv(divId);
	
	if(newDisplay == 'none') {
		image.src = offImage;
	} else {
		image.src = onImage;
	}
}

function toggleExpandingDiv(divId, hInputName, image, onImage, offImage) {
	var divStateInput;
    
	if (document.all)
		divStateInput = document.all[hInputName];
    
	if (!document.all && document.getElementById)
		divStateInput = document.getElementById(hInputName);

	if(divStateInput != undefined) {
		if(divStateInput.value.toLowerCase() == 'none') {
			divStateInput.value = 'block';
		} else {
			divStateInput.value = 'none';
		}
	}
	toggleImageDiv(divId, image, onImage, offImage);
}