// this function checks if this page is properly loaded inside our frameset
// if not, it reloads the frameset with this page inside the "text" frame
// IMPORTANT: we assume our address always has "/ism/" its url (e.g. as in
// http://www.math.uqam.ca/ism/cours/algebre_en.shtml) - this will have to
// be changed, if the main url ever changes.

// the function is called with <body onLoad="checkforframe()"> on each page
function checkforframe() {
var myLanguage = self.location.pathname.substring(self.location.pathname.lastIndexOf('_')+1,self.location.pathname.lastIndexOf('.'));
var myFrameSet = (myLanguage=='fr') ? 'index.html?' : 'index_en.html?';
var lowerCaseName = self.location.pathname.toLowerCase();
// take everything after the /ism/ part - including subdirectories
var filenameindex = lowerCaseName.lastIndexOf('/ism/')+5;

    if (document.layers && (self.innerHeight == 0 && self.innerWidth  == 0)) {
       // we seem to be correctly loaded, so we don't have anything to do.
       return;
       }
    if ((top == self) || ((document.images) ?
	 (!parent.ism04tmp05test4frameset) :
	 (parent.frames[1].name !='ism04tmp05test4frameset'))) {
	// we don't have our correct frameset, so must reload it
        var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,filenameindex) + myFrameSet + self.location.pathname.substring(filenameindex,self.location.pathname.length);
        if (document.images) top.location.replace(newURL); else top.location.href = newURL;
    }
}


// this function reloads the same page but in the other language

function switchLanguage() {
var lowerCaseName = self.location.pathname.toLowerCase();
// take everything after the /ism/ part - including subdirectories
var filenameindex = lowerCaseName.lastIndexOf('/ism/')+5;

var myFileName = self.location.pathname.substring(filenameindex,self.location.pathname.length);
var myLanguage =
myFileName.substring(myFileName.lastIndexOf('_')+1,myFileName.lastIndexOf('.'));
// now switch to other language
myLanguage = (myLanguage=='fr') ? 'en' : 'fr';
myFileName = myFileName.substring(0,myFileName.lastIndexOf('_')+1) + myLanguage
+ myFileName.substring(myFileName.lastIndexOf('.'),myFileName.length);

// set frameset-filename
var myFrameSet = (myLanguage=='fr') ? 'index.html?' : 'index_en.html?';

var newURL = self.location.protocol + '//' + self.location.host + self.location.pathname.substring(0,filenameindex) + myFrameSet + myFileName;

// load the new page
if (document.images) top.location.replace(newURL); else top.location.href = newURL;
}

