window.onbeforeunload=confirmExit;

var dirty = false;
var userguid;

function confirmExit(){
	var closedTime = new Date();
	var difference = closedTime.getTime() - launchedTime.getTime();
    icoviaTracker("/tracking/closed?sessionLength=" + difference + "&userGuid=" + userguid);
	if (dirty) {
		return "Your plan has changed are you sure you wish to exit without saving your plan?";
	}
}

function setDirty(status){
	dirty = status;
}

function setUserGuid(loggedInUserGuid){
	userguid = loggedInUserGuid;
}

function openCenteredWindow(URLtoOpen,windowName,windowW,windowH){
	var topPos = (screen.height-windowH)/2;
	var lftPos = (screen.width-windowW)/2;
	newWindow=window.open(URLtoOpen,windowName,'height='+windowH+',width='+windowW+',top='+topPos+',left='+lftPos+',toolbar=0,scrollbars=1,resizable=1,menubar=0');
	var popUpMsg = "You appear to have a pop-up blocker that prevents a window from opening. Please enable pop-ups for this site and try again. Thank you.";
	if(!newWindow){
		alert(popUpMsg);
	}
};

function _icoviaVoid() { return; }

function icoviaTracker(page)
{
  var i=new Image(1,1);
  i.src=page;
  i.onload=function() {_icoviaVoid();}
 }

 function setTitle(title)
 {
 	document.title = title;
 }