/******************
 This file is part of m-bread Title Cloaking
 (http://m-bread.com/resources/tc) and is licensed under the Creative
 Commons Attribution-Share Alike 2.0 UK: England & Wales License
 (http://creativecommons.org/licenses/by-sa/2.0/uk/) by Martin Pain
 (http://m-bread.com/). This means you are free to use, distribute and
 modify the calendar, as long as you distribute any work you use it in
 under a similar licence.
******************/

//Flag to set if 'Close Title Cloaking' link is clicked. Surpresses 'are you sure' exit message.
clos = false;

//Function to change which page is displayed in the lower frame
function changePage(page){
  document.getElementById('mainpage').setAttribute('src', page);
};//EoFn changePage

//'Are you sure' message displayed if the page is navigated away from
//The browser adds its own message around this
var promptMSG = "If you did not try to close this window, or close Title Cloaking, then the website you are on has tried to override Title Cloaking.\nPress OK to close Title Cloaking, or Cancel to continue using it.";

// onbeforeunload function.
// Provides the 'Are you sure' message to the browser when called
function notifyExit(event_) {
	if (!event_ && window.event) {
          event_ = window.event;
        }
	event_.returnValue = promptMSG;
	return promptMSG;
}

//Calls the notifyExit function when the page is navigated away from,
//unless the 'Close Title Cloaking' link was used
window.onbeforeunload = function(event) {
  if(!clos) return notifyExit(event);
}