//
// openBookletWindow
//
// Last Revision: 2008/03/10
//
// Defines the function to be used for opening the species booklet window in BISON-M.
//

function openBookletWindow(sSpeciesID) {
	var sLocation;

	// if the booklet window is already open, give it focus
	
	if (wBooklet && !wBooklet.closed) {
		UpdateBooklet(sSpeciesID);
	} else {
		// open the booklet window
		//alert('about to open the window');
		wBooklet = window.open('booklet.aspx?id=' + sSpeciesID,'bookletwin','width=780,height=500,resizable=yes,scrollbars=yes,location=yes');
	}
	
	// give the window focus
	wBooklet.focus();

	return false;
}

function openBookletWindow2(sSpeciesID) {
	var sLocation;

	// use the proper method depending on which window called this function
	
	if (sWindowID == "home") {
		// home window called this function
		
		// if the booklet window is already open, give it focus
		
		if (wBooklet && !wBooklet.closed) {
			UpdateBooklet(sSpeciesID);
		} else {
			// open the booklet window
			//alert('about to open the window');
			wBooklet = window.open('booklet.aspx?id=' + sSpeciesID,'bookletwin','width=780,height=500,resizable=yes,scrollbars=yes,location=yes');
		}
	} else if (sWindowID == 'GIS') {
		// GIS window called this function
		//displayBookletHREF();
		if (wBooklet && !wBooklet.closed) {
			UpdateBooklet(sSpeciesID);
		} else {
			//alert('GIS about to open booklet window');
			wBooklet = window.open('booklet.aspx?id=' + sSpeciesID,'bookletwin','width=780,height=500,resizable=yes,scrollbars=yes,location=yes');
		}
	}
	
	// give the window focus
	wBooklet.focus();

	return false;
}

function UpdateBooklet(sSpeciesID) {
	//alert('booklet is already open');
	// is the proper species loaded, or is it a different species?
	sLocation = wBooklet.location.href;
	var iStart = sLocation.indexOf("id=") + 3;
	var sBookletSpeciesID = sLocation.substr(iStart, iStart + 6);
	if (sBookletSpeciesID != sSpeciesID) {
		// species is different, reload the booklet
		sLocation = sLocation.replace(sBookletSpeciesID, sSpeciesID);
		wBooklet.location.assign(sLocation);
	}
}

function syncBookletWindowHandles() {
	wBooklet.wGIS = wGIS;
}
