// (C) Copyright IBM Corporation, 2001                              
// All rights reserved. Licensed Materials Property of IBM          
// US Government Users Restricted Rights                            
// Use, duplication or disclosure restricted by                     
// GSA ADP Schedule Contract with IBM Corp.                         

// synch.js
// this is the synchronization file for the Information Center
// it is identical to the Information Center Supplemental Manuals' synch.js file except that
// * it looks for a different frameset to verify that the pages aren't being 'framed' by someone else.
// * if the page needs to be 'reframed' within our frameset, it calls index.htm.
// * the navigation frame has a different name.
// * this file DOES call the breadcrumb function.
//
// any changes here, may need to be duplicated in the Supplemental Manuals's synch.js file

//This first line makes sure that we are in the IC frameset
//if not, we replace wherever we are with the IC frameset, passing in the "real location"
//
if (!(top.banner && top.navFrame && top.icmast && top.text)) {		
	//document.images is a funky way to test if the browser supports the replace() function.
	//If a browser supports document.images, it supports the replace() function.
	//We'd rather use the replace() function, because that doesn't mess up the Back button.
	//  "real location" is the index.htm file with the relative path name of this html file
	//  concatinated as a ? parameter.  It used to be easier to calculate, but with the 
	//  subdirectories, I thought I'd better write a function for it instead.
	if (document.images)
		top.location.replace(getRealLocation());
	else
		top.location.href = getRealLocation();
}

//This line calls the Navigation applet's findNode() function.  The findNode() function searches
//the heirarchy for the parameter that we pass in here, and synchs the applet up with the content.
//The if-check is checking to see if the loadContent function in index.htm has been called.
//  If it hasn't, then we know the frameset is loading, so we better not try to communicate with
//  the synching applet.  Index.htm will call findNode() after everything is set up.
//if (parent.loadContentCalled) parent.frames.nav.document.CLNavBar.findNode(getFileToFind());
if (top.loadContentCalled) parent.navFrame.document.CLNavBar.findNode(getFileToFind());

//This line calls the function to update the breadcrumb window
updateBreadcrumbs();

//////////////////////////////////////////////////////////////////////
// supporting functions
//////////////////////////////////////////////////////////////////////
function getRealLocation() {
	//this function needs to return the index.htm file name followed by a '?' which denotes
	//the "search" parameters.  Then it concatinates index.htm? with the relative path to this
	//content file.
	realLocation = location.protocol + "//" + location.host;
	realArray = location.pathname.split("/");

	for (i = 0; i < realArray.length; i++) {
		if (realArray[i] == "info") {
			for (j = 0; j < i; j++) realLocation = realLocation + realArray[j] + "/";
			realLocation = realLocation + "index.htm?";
			for (j = i; j < realArray.length - 1; j++) realLocation = realLocation+realArray[j]+"/";
			realLocation = realLocation + realArray[realArray.length - 1];
			i = realArray.length;
		}
	}
	//if realLocation is the same as we started with-- we are probably using the file 
	//protocol in internet explorer, so split the pathname using the "\" character instead
	if (realLocation == location.protocol + "\\" + location.host) {
		realArray = location.pathname.split("\\");

		for (i = 0; i < realArray.length; i++) {
			if (realArray[i] == "info") {
				for (j = 0; j < i; j++) realLocation = realLocation + realArray[j] + "/";
				realLocation = realLocation + "index.htm?";
				for (j = i; j < realArray.length - 1; j++) realLocation = realLocation+realArray[j]+"/";
				realLocation = realLocation + realArray[realArray.length - 1];
				i = realArray.length;
			}
		}
	}
	return realLocation;
}

function getFileToFind() {
	//This is similar to the function above, but it only returns the relative path to 
	//this content file.  This function is also called by index.htm.
	realFile = "";
	realArray = location.pathname.split("/");
	
	for (i = 0; i < realArray.length; i++) {
		if (realArray[i] == "info") {
			for (j = i+1; j < realArray.length - 1; j++) realFile = realFile+realArray[j]+"/";
			realFile = realFile + realArray[realArray.length - 1];
			i = realArray.length;
		}
	}
	//if realFile is the empty string -- we are probably using the file 
	//protocol in internet explorer, so split the pathname using the "\" character instead
	if (realFile == "") {
	    realArray = location.pathname.split("\\");
	    for (i = 0; i < realArray.length; i++) {
		if (realArray[i] == "info") {
		    for (j = i+1; j < realArray.length - 1; j++) realFile = realFile+realArray[j]+"/";
		    realFile = realFile + realArray[realArray.length - 1];
		    i = realArray.length;
		}
	    }
		
        }
	return realFile;
}


//This function obtains the breadcrumb sting from the applet and
//passes that string to the breadcrumb frame.
function updateBreadcrumbs(){
	if (top.breadcrumbs && top.navFrame.document.CLNavBar) {
		var strPath = top.navFrame.document.CLNavBar.getBreadCrumbs();
		top.breadcrumbs.updateBreadcrumb(strPath);
	}
}
