// Prompt for Login after 19 mins (Content Management times out after 20)
var intCollabTimeout = 1000*60*19
var strProjectsUrl = "/Projects/default.aspx?Mode=Logoff"
var objTimeout = 0;

//window.onload=function(){
//	if (hasIFrame()){
//		// Ensure Iframe is correct size
//		document.body.onresize=resizeCollab;
//		// Time out in 19 mins
//		resetTimeoutTracker();
//		// Add event to iFrame that resets timer if user clicks within it
//		setTimeout("setIFrameOnClick()",1000);
//	}
//}

function setIFrameOnClick(){
	try{
		// Add timeout cancelling event to iframe
		document.frames[0].document.body.onclick=resetTimeoutTracker;
	}catch(e){
		// Access denied, cross-domain scripting error
		e = null;
	}
}

function resetTimeoutTracker(){
	// Set the session timeout to another 19 minutes
	clearTimeout(objTimeout)
	objTimeout = null;
	objTimeout = setTimeout("window.location.replace('" + strProjectsUrl + "')",intCollabTimeout);
	setTimeout("setIFrameOnClick()",1000);
}

function hasIFrame(){
	// Identify if projects iframe is displayed
	var lobjFrameCell = findIframe();
	if (lobjFrameCell!=null){
		return true;
	}else{
		return false;
	}
}

function Collab_OpenPage(iframeId, url)
{
	// Navigate iframe to specified url
	try{
		document.getElementById(iframeId).src = url;
	}catch(e){
		e = null;
	}
}

function resizeCollab()
{
	// Set the iframe height to maximum height available before page needs to scroll
	var iframeHeight = 0;
	var intMinFrameHeight = 100
	var lobjLoginStatus = document.getElementById("loginStatus");
	var lobjFrameCell = findIframe()
    if (lobjFrameCell!=null){
		iframeHeight = (document.body.clientHeight - findY(lobjFrameCell)) - 75
		iframeHeight = (iframeHeight < intMinFrameHeight) ? intMinFrameHeight : iframeHeight;
//		lobjFrameCell.style.height = iframeHeight;
		lobjFrameCell.style.height = "100%";
	}
	lobjFrameCell = null;
}

function findIframe(){
	// Locates the iframe object without knowing it's ID
	var objIframes = document.getElementsByTagName("IFRAME");
	if (objIframes!=null){
		return objIframes[0];
	}
	else{
		return null;
	}
}

function findY(obj) {
	// Gets the Y co-ordinates of a given object
	if (obj.offsetParent) {
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curtop += obj.offsetTop
		}
	}
	obj = null;
	return curtop;
}



