//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// FILE MAIN-CPS.JS
// Main Chime Presentation Support Javascript
// www.umass.edu/chime/prsswc
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Sections in this file:
// 	PopWindow function that insures things work well
//    functions for movieplaying messages
//    Wayne Added the first two
//    Buttons inlcludes spin and I.d button extras I added
//    Footer and back functions
//    Color keys
//    Font size control
//    Toolbar
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
<!--BEGIN Pop-up Windows Script------------------------------------------>

// Copyright 1999, 2000 by Ray Stott - ver 2.0
// OK to use on noncommercial sites as long as copyright is included
// Commercial Sites, please see http://www.crays.com/jsc/jsCom.htm 
// Script is available at http://www.crays.com/jsc          

var popWin = null    // use this when referring to pop-up window
var winCount = 0
var winName = "popWin"
function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
  var d_winLeft = 20  // default, pixels from screen left to window left
  var d_winTop = 20   // default, pixels from screen top to window top
  winName = "popWin" + winCount++ //unique name for each pop-up window
  closePopWin()           // close any previously opened pop-up window
  if (openPopWin.arguments.length >= 4)  // any additional features? 
    winFeatures = "," + winFeatures
  else 
    winFeatures = "" 
  if (openPopWin.arguments.length == 6)  // location specified
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
  else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
  popWin = window.open(winURL, winName, "width=" + winWidth 
           + ",height=" + winHeight + winFeatures)
  }
function closePopWin(){    // close pop-up window if it is open 
  if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) //do not close if early IE
    if(popWin != null) if(!popWin.closed) popWin.close() 
  }
function getLocation(winWidth, winHeight, winLeft, winTop){
  return ""
  }
//-->

<!--
function getLocation(winWidth, winHeight, winLeft, winTop){
  var winLocation = ""
  if (winLeft < 0)
    winLeft = screen.width - winWidth + winLeft
  if (winTop < 0)
    winTop = screen.height - winHeight + winTop
  if (winTop == "cen")
    winTop = (screen.height - winHeight)/2 - 20
  if (winLeft == "cen")
    winLeft = (screen.width - winWidth)/2
  if (winLeft>0 & winTop>0)
    winLocation =  ",screenX=" + winLeft + ",left=" + winLeft	
                + ",screenY=" + winTop + ",top=" + winTop
  else
    winLocation = ""
  return winLocation
  }
//-->
<!--END Pop-up Windows Script------------------------------------------->
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =


//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// BUTTONS
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

// Frist section deals with putting up movie playing message when button pressed
// Added to Eric Martz's template by Wayne Decatur

function AlertToLoad(pluginName, executedYet)
{		
		if (!executedYet) {
		top.f_left.document.statusimage.src='movieplaying.gif';}
		
	
}


// Here is the function for most buttons

function button(script)
{
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("	script=\"" + script + "\"");
		writeln("	messages3d=true");
		writeln("	ButtonCallback=AlertToLoad");
		writeln(">");
		close();
	}
}



//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// TOOL BAR BUTTONS
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// Next section deals with buttons for polypeptide tunnel section where
// I need to put up movie playing message when button pressed and
// have the spin go off
// Added to Eric Martz's template by Wayne Decatur


function indicatespinoff(){
		top.f_left.document.layer1.visibility='show';
		top.f_left.document.layer2.visibility='hidden';
	}

function tunnelAlert(pluginName, executedYet)
{		
		if (!executedYet) {
		top.f_left.document.statusimage.src='movieplaying.gif';
		indicatespinoff();
}
		
	
}


function tunnelbutton(script)
{
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("	script=\"" + script + "\"");
		writeln("	messages3d=true");
		writeln("	ButtonCallback=tunnelAlert");
		writeln(">");
		close();
	}
}

// Next four buttons deal with putting up indicators of actions
// the four were added to Eric Martz's template by Wayne Decatur

function indicatespinon(){
		top.f_left.document.layer2.visibility='show';
		top.f_left.document.layer1.visibility='hidden';
	}

function spinonbutton(){
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("	script=\"spin on\"");
		writeln(" ButtonCallback=indicatespinon ");
		writeln(">");
		close();
	}
}

//The indicatesinoff function is found up above because
//also used in the tunnelbutton function

function spinoffbutton(){
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("	script=\"spin off\"");
		writeln(" ButtonCallback=indicatespinoff ");
		writeln(">");
		close();
	}
}

function indicateidon(){
		top.f_left.document.layer4.visibility='show';
		if (top.f_left.document.layer2.visibility=='show'){
		top.f_left.document.layer2.visibility='hidden';	
		top.f_left.document.layer1.visibility='show';
		alert ('Rotation has been turned off!\n\nThe identify feature works intolerably slow in\n combination with spin for most structure files in this tour.');}
	}

function idonbutton(){
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("  script=\"spin off; set picking on\"");
		writeln(" ButtonCallback=indicateidon ");
		writeln(">");
		close();
	}
}

function indicateidoff(){
		top.f_left.document.layer4.visibility='hidden';
	}

function idoffbutton(){
	with (document)
	{
		open();
		writeln("<embed");
		writeln("	type='application/x-spt'");
		writeln("	width=15");
		writeln("	height=15");
		writeln("	button=followed");
		writeln("	target='chime_graphic'");
		writeln("	script=\"set picking none\"");
		writeln(" ButtonCallback=indicateidoff ");
		writeln(">");
		close();
	}
}



//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// FOOTER AND BACK FUNCTIONS
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function footer()
{
	with (document)
	{
		open();

// history.back() runs you back thru all the button presses, so is useless.
// (note from Wayne-why does it say useless when used below in next
// function?!?!?
		writeln("<form>");
		writeln("<input type=button value=\"Contents\"");
		writeln("onClick=\"location.href='right-a.htm'\">");
		writeln("</form>");

		writeln("<p><a href=\"rightutl.htm\">Utilities</a>");
		writeln("&nbsp; &nbsp;"); 
		writeln("<a href=\"right-r.htm\">References</a>");
		close();
	}

}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// backhis1() makes a button which moves back one step in the history.

function backhis1()
{
	with (document)
	{
		open();

		writeln("<form>");
		writeln("<div align=center>");
		writeln("<input type=button value=\"Back\"");
		writeln("onClick=\"history.back()\">");
		writeln("</div>");
		writeln("</form>");

		close();
	}

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// Some documents are displayed in a new window; in these cases, the back
// button simply closes the new window.  This saves time reloading a
// Chime frameset, and preserves the state of the parent window.

function backclose()
{
	with (document)
	{
		open();

		writeln("<form>");
		writeln("<div align=center>");
		writeln("<input type=button value=\"Back\"");
		writeln("onClick=\"window.close()\">");
		writeln("</div>");
		writeln("</form>");

		close();
	}

}

//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// COLOR KEYS
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

// wr_doc(to_write) is a utility function used below.
function wr_doc(to_write)
{
	with(document)
	{
		open();
		write(to_write);
		close();
	}
}

//------------------------------------------------------------------
// key_top() begins a color key, key_bottom() completes it.
// These are called in color key functions such as chon() below.

function key_top()
{
	wr_doc(
//		"<table bgcolor='black'>" +
//		"<tr><td>" +
		"<a href='cpk_cs.htm' target='cpk_window'>" +
//		"<tt>" +
		"<font size='+2'><b>"
	);
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function key_bottom()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>"+
		"</b></font>" +
//		"</tt>" +
		"</a>" //+
//		"</td></tr>" +
//		"</table>"
	);
}

//------------------------------------------------------------------
// The following functions each add one element to a color key.
// You can easily add new elements by copying and modifying one of these.
// Correct CPK colors for RasMol and Chime are available at
// http://www.umass.edu/microbio/rasmol/distrib/rasman.htm#cpkcolours
// or in the current folder, open cpk-rgb.htm in your browser.

function C_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#C8C8C8'>C</font>"
	);
}


function Fe_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#FFA500'>Fe</font>"
	);
}

function H_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#FFFFFF'>H</font>"
	);
}


function N_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#8F8FFF'>N</font>"
	);
}



function O_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#F00000'>O</font>"
	);
}



function S_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#FFC832'>S</font>"
	);

}

function P_key()
{
	wr_doc(
		"<font color='black'>&nbsp;</font>" +
		"<font color='#FFA500'>P</font>"
	);

}

//------------------------------------------------------------------
// Here now are complete color key functions.  Each is named according
// to the elements included in the key it produces.

function chon_key()
{
	key_top();
	C_key();
	H_key();
	O_key();
	N_key();
	key_bottom();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function chonp_key()
{
	key_top();
	C_key();
	H_key();
	O_key();
	N_key();
	P_key();
	key_bottom();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function chonfe_key()
{
	key_top();
	C_key();
	H_key();
	O_key();
	N_key();
	Fe_key();
	key_bottom();
}


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function con_key()
{
	key_top();
	C_key();
	O_key();
	N_key();
	key_bottom();
}


//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function cons_key()
{
	key_top();
	C_key();
	O_key();
	N_key();
	S_key();
	key_bottom();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function chons_key()
{
	key_top();
	C_key();
	H_key();
	O_key();
	N_key();
	S_key();
	key_bottom();
}

//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// FONT SIZE CONTROL
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

/*

The fontsize buttons don't work in Nav3.01 (Win95 or Mac).
The second button (down) often doesn't appear; once this happens,
going anywhere else causes Nav to crash.
Therefore they have been disabled in Nav3.01.

*/

// any_navigator() and navv401() were lifted from n4c2.js and can be
// deleted if/when things are reorganized to include that elsewhere.

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function any_navigator()
{
	if (navigator.appName.toLowerCase().indexOf("netscape") != -1)
		return 1;
	return 0;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function navv401()
{
	if (!any_navigator())
		return 0;
	if (4.01 <= parseFloat(navigator.appVersion))
		return 1;
	return 0;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function n4_ok(ask4n4)
{
	if (!navv401())
	{
		if (ask4n4)
		{
			alert("Sorry, font size control does not work in\n" +
			"the browser you are using. Please upgrade to\n" +
			"Netscape Navigator 4.01 or later if you wish to\n" +
			"project with larger fonts. (www.netscape.com)");
		}
		return 0;
	}
	return 1;
}


//- - - - - - - - - - - - - - - - - - - - - - - - - - - 

function up_fontsize()
{
	if (!n4_ok(1))
		return;
	if (parent.FontSize < 6)
	{
		parent.FontSize += 1;
		location.reload();
	}
	else
	{
		alert('Font size is already at maximum (6)');
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function down_fontsize()
{
	if (!n4_ok(1))
		return;
	if (parent.FontSize > 3)
	{
		parent.FontSize -= 1;
		location.reload();
	}
	else
	{
		alert('Font size is already at minimum (3)');
	}
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function set_basefont()
{
	with (document)
	{
		open();
		writeln("<basefont size='" + parent.FontSize + "'>");
		close();
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function fontsize_controls()
{
	fontsize_control_up();
	fontsize_control_down();
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function fontsize_control_up()
{
	with (document)
	{
		open();
		write("<a href='javascript: up_fontsize()'>")
		writeln("<img src='up.gif' border=0></a>")
		close();
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - 
function fontsize_control_down()
{
	if (!n4_ok(0))
		return;
	with (document)
	{
		open();
		write("<a href='javascript: down_fontsize()'>")
		writeln("<img src='down.gif' border=0></a>")
		close();
	}
}


//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// END OF FILE MAIN-CPS.JS
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
