//layout.js
// THIS FILE CONTAINS HARDCODED DATA. ONLY EDIT THIS FILE IF YOU ARE 100% SURE YOU KNOW WHAT YOU ARE DOING.


// Modification Record:
// 02Jun2001 atp Original Release of layout
// 03Jun2001 atp Added text-versioning
// 12Jun2001 atp Text versioning now uses cookies. Added HotTopic and TextNavBar related functions, imported email() function and survey handling.
// 04Jan2001 atp Modified wndOpen to pop behind
// ?????2002 sxj Removed pop behind in wndOpen
// ??Apr2002 atp made survey into a function that is called on each page that needs a survey.
// 12Jun2002 atp added function for writing "sidebar" menu in the text version
// 14Feb2003 rs Modified left side bar
//Testing changes
// 01Mar2003 rs Added evaluate us on left side bar
// 10Mar2003 adr Added ReturnCompliace, and a compliance level parameter in the output layout function
// 2Apr2003 Changed a link in the hottopic generating code
// 24May2004 Changed survey call to make main window the focused window (mk)
// 25May2004 Changed survey call to make sure it only pops up once, added surveywindow var declaration

//SURVEY CODE
var surveywindow = '';

// RUN-TIME CODE
var pf;  // Read cookie to determine if we are running pf version
if (GetCookie('version') && GetCookie('version') == 'print') {
	pf = true;
}

// CALLED FUNCTIONS

function survey() { // Pops up a survey every so often if the user hasn't taken one
	if(GetCookie("surveystat")==null && Math.random()<=0.10 && !pf ) {
 		wndOpen('http://' + location.hostname + '/surveys/surveyindex.html', 'surveywindow' ,640,480,1);
	}
}

function chooseCSS() { // Chooses which style sheet to load based on cookie
	if (pf) {
	   	document.write('<link rel="stylesheet" href="http://' + location.hostname + '/tv.css">');
	}
	else if (ns) {
		document.write('<link rel="stylesheet" media="screen" href="http://' + location.hostname + '/gvns.css">');
	}
	else if (mz) {
		document.write('<link rel="stylesheet" media="screen" href="http://' + location.hostname + '/gvns.css">');
		document.write('<link rel="stylesheet" media="print" href="http://' + location.hostname + '/gvmzprint.css">'); 
	}
	else {
		document.write('<link rel="stylesheet" media="screen" href="http://' + location.hostname + '/gv.css">');
		document.write('<link rel="stylesheet" media="print" href="http://' + location.hostname + '/gvprint.css">'); 
	}
}

function ReturnCompliance( clevel )
{
	
	var string = "";
	
	if ( clevel == 1 )
	{
		string += '<img src="http://' + location.hostname + '/images/approved_a.gif" alt="Bobby WorldWide Approved A" width="88" height="31"><p><img height="32" width="88" src="http://' + location.hostname + '/images/wcag1A.gif" alt="Level A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0">';
	}
	else if ( clevel == 2)
	{
		string += '<img src="http://' + location.hostname + '/images/approved_aa.gif" alt="Bobby WorldWide Approved AA" width="88" height="31"><p><img height="32" width="88" src="http://' + location.hostname + '/images/wcag1AA.gif" alt="Level AA conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0">';
	}
	else if ( clevel == 3 )
	{
		string += '<img src="http://' + location.hostname + '/images/approved_aaa.gif" alt="Bobby WorldWide Approved AAA" width="88" height="31"><p><img height="32" width="88" src="http://' + location.hostname + '/images/wcag1AAA.gif" alt="Level AAA conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0">';
	}
	else
	{
		return "";
	}
	
	return string;
}

function writeLayout(moddate, editor, clevel) { // Writes the main divs based on print mode
	layout_temp = "";
	if (pf) {
        clevel = ReturnCompliance( clevel );
		layout_temp += '<div id="OEChead"><p>onlineethics.org</p></div>';
		layout_temp += '<div id="OECtitle"><p>The Online Ethics Center for Engineering and Science at Case Western Reserve University</p></div>';
		layout_temp += '<p id="modifieddate">Last Modified: ' + moddate + ' by ' + editor + '</p><p>' + clevel + '</div>';
	}
	else {
		holdingarray = new Array;
		holdingarray = ReturnHotTopic();
		clevel = ReturnCompliance( clevel );
		hotimage = holdingarray[1];
		hoturl = holdingarray[2];
		hotalt = holdingarray[3];
		// MAIN MENUS
		layout_temp += '<div id="OEChead"><a name="top"></a><img src="http://' + location.hostname + '/images/layout/top.gif" width="667" height="120" border="0" alt="onlineethics.org" usemap="#top_Map"></div>';
		layout_temp += '<div id="OECside"><img src="http://' + location.hostname + '/images/layout/side.gif" width="121" height="299" border="0" alt="sidebar" usemap="#side_Map"><a href = "' + hoturl + '"><p></p><img src="' + hotimage + '" width="121px" height ="184px" border="0" alt="' + hotalt + '"></a><p id="modifieddate">Last Modified:<br>' + moddate + ' by ' + editor + '</p><p>' + clevel + '</div>';
		// MAPS 
		layout_temp += '<MAP NAME="top_Map"><AREA SHAPE="rect" ALT="onlineethics.org home" COORDS="7,5,507,86" HREF="http://' + location.hostname + '/index.html"><AREA SHAPE="rect" ALT="Give us your feedback." COORDS="570,89,630,111" HREF="http://' + location.hostname + '/sfeed.html"><AREA SHAPE="rect" ALT="How to use this site." COORDS="519,89,566,111" HREF="http://' + location.hostname + '/help.html"><AREA SHAPE="rect" ALT="Print friendly version" COORDS="423,89,515,111" HREF="' + location.pathname + '" onclick=\'SetCookie("version", "print", null, "/");\'><AREA SHAPE="rect" ALT="Search the site" COORDS="354,89,419,111" HREF="http://' + location.hostname + '/search.html"></MAP>';
		layout_temp += '<MAP NAME="side_Map"><AREA SHAPE="rect" ALT="Get help with ethical questions." COORDS="12,78,104,91" HREF="http://' + location.hostname + '/helpline/index.html"><AREA SHAPE="rect" ALT="OEC Home page" COORDS="12,174,104,187" HREF="http://' + location.hostname + '/index.html"><AREA SHAPE="rect" ALT="Codes of ethics" COORDS="12,269,104,282" HREF="http://' + location.hostname + '/codes/index.html"><AREA SHAPE="rect" ALT="Browse the OEC by topic." COORDS="12,254,104,267" HREF="http://' + location.hostname + '/topics/index.html"><AREA SHAPE="rect" ALT="Evaluate us" COORDS="12,46,104,59" HREF="http://' + location.hostname + '/surveys/surveyindex.html"><AREA SHAPE="rect" ALT="Conferences, events, and calls for papers" COORDS="12,221,104,234" HREF="http://' + location.hostname + '/events/index.html"><AREA SHAPE="rect" ALT="Organizations and acronyms" COORDS="12,206,104,219" HREF="http://' + location.hostname + '/abbr.html"><AREA SHAPE="rect" ALT="Text version home page" COORDS="12,158,104,171" HREF="/" onclick=\'SetCookie("version", "print", null, "/");\'><AREA SHAPE="rect" ALT="Spanish Index" COORDS="12,142,104,155" HREF="http://' + location.hostname + '/spanish/index.html"><AREA SHAPE="rect" ALT="Glossary" COORDS="12,111,104,124" HREF="http://' + location.hostname + '/glossary.html"><AREA SHAPE="rect" ALT="Works cited" COORDS="12,95,104,108" HREF="http://' + location.hostname + '/bib/index.html"><AREA SHAPE="rect" ALT="How to link to the OEC." COORDS="12,30,104,43" HREF="http://' + location.hostname + '/cite-link.html"><AREA SHAPE="rect" ALT="Learn more about the OEC." COORDS="12,13,104,26" HREF="http://' + location.hostname + '/about.html"></MAP>';
	}
	return layout_temp
}

function tagline () { // writes the copyright tagline
	tagline_temp = "";
	if (pf) {
		tagline_temp += '<p>Switch to <a href="' + location.pathname + '" onclick=\'DeleteCookie("version", "/");\'>Graphics Version</a></p>';
		tagline_temp += OutputNavOptions();
		tagline_temp += OutputSideOptions();
	}
		tagline_temp += '<p class="copyright"><a href="#top">Return to top</a>.</p><p class="copyright">Help us evaluate and improve our site by taking this <a href="http://onlineethics.org/surveys/surveyindex.html" target="_blank"> online survey.</a></p>';
		tagline_temp += '<p class="copyright">Copyright 1995-2005 Online Ethics Center for Engineering and Science, <a href="/tos.html">Terms of Service</a></p>';
	return tagline_temp;
}

function MoveMain() { // repositions main layer for ns browsers
	if (ns) {
		document.layers.OECmain.left += -3;
//		document.layers.OECmain.top += -19;
	}
}

function OutputLayout(moddate, editor, clevel) { // this is what should be called in the html file
	document.write(writeLayout(moddate, editor, clevel));
	if (pf) {
	}
	else { // draws menu
		document.write(TOPICBAR.draw('topicbar'));
		for (j=0; j<TOPICBAR.menu_items.length; j++) {
			HideLayer(TOPICBAR.menu_items[j].sub_menu.id);
		}
	}
}

function OutputNavOptions () { // outputs the navigation option list for the text version
	temp_navoptions = "";
	temp_navoptions += '<form method="POST" action="/cgi-bin/redirect.pl"><p>';
	temp_navoptions += '<SELECT NAME="url">';
	temp_navoptions += '<OPTION VALUE="#">Select a main section to visit and click GO</OPTION>';
	temp_navoptions += '<OPTION VALUE="/">Home</OPTION>';
	temp_navoptions += '<OPTION VALUE="/eng/index.html">Engineering Practice</OPTION>';
	temp_navoptions += '<OPTION VALUE="/reseth/index.html">Responsible Research</OPTION>';
	temp_navoptions += '<OPTION VALUE="/div/index.html">Diverse Workforce</OPTION>';
	temp_navoptions += '<OPTION VALUE="/moral/index.html">Moral Exemplars</OPTION>';
	temp_navoptions += '<OPTION VALUE="/com/index.html">Computers and Software</OPTION>';
	temp_navoptions += '<OPTION VALUE="/other/index.html">Natural Sciences</OPTION>';
	temp_navoptions += '</SELECT><input type="SUBMIT" value="GO"></p></form>';
	return temp_navoptions;
}

function OutputSideOptions () { // outputs the sidebar option list for the text version
	temp_navoptions = "";
	temp_navoptions += '<form method="POST" action="/cgi-bin/redirect.pl"><p>';
	temp_navoptions += '<SELECT NAME="url">';
	temp_navoptions += '<OPTION VALUE="#">Select a auxillary section to visit and click GO</OPTION>';
	temp_navoptions += '<OPTION VALUE="/helpline/index.html">OEC help-Line</OPTION>';
	temp_navoptions += '<OPTION VALUE="/about.html">about us</OPTION>';
	temp_navoptions += '<OPTION VALUE="/howto-link.html">link to us</OPTION>';
	temp_navoptions += '<OPTION VALUE="/bib/index.html">bibliography</OPTION>';
	temp_navoptions += '<OPTION VALUE="/glossary.html">glossary</OPTION>';
	temp_navoptions += '<OPTION VALUE="/spanish/index.html">en espa&ntilde;ol</OPTION>';
	temp_navoptions += '<OPTION VALUE="/abbr.html">organizations and acronyms</OPTION>';
	temp_navoptions += '<OPTION VALUE="/events/index.html">conferences</OPTION>';
	temp_navoptions += '<OPTION VALUE="/othersites.html">links</OPTION>';
	temp_navoptions += '<OPTION VALUE="/keywords/index.html">topics index</OPTION>';
	temp_navoptions += '<OPTION VALUE="/codes/index.html">codes of ethics</OPTION>';
	temp_navoptions += '</SELECT><input type="SUBMIT" value="GO"></p></form>';
	return temp_navoptions;
}
/*
function ReturnHotTopic () { // sidebar randomizer
	var imagenumber = 6 ;
	var randomnumber = Math.random() ;
	var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;

	images = new Array;
		images[1] = 'http://' + location.hostname + '/images/layout/hotboisjoly.gif';
		images[2] = 'http://' + location.hostname + '/images/layout/hotlem.gif';
		images[3] = 'http://' + location.hostname + '/images/layout/hotcuny.gif';
		images[4] = 'http://' + location.hostname + '/images/layout/hotkiller.gif';
		images[5] = 'http://' + location.hostname + '/images/layout/hothelp.gif';
		images[6] = 'http://' + location.hostname + '/images/layout/hotcarson.gif';
	links = new Array;
		links[1] = 'http://' + location.hostname + '/moral/boisjoly/RB-intro.html';
		links[2] = 'http://' + location.hostname + '/moral/lemessurier/index.html';
		links[3] = 'http://' + location.hostname + '/moral/cuny/intro.html';
		links[4] = 'http://' + location.hostname + '/cases/robot/robot.html';
		links[5] = 'http://' + location.hostname + '/helpline/index.html';	
		links[6] = 'http://' + location.hostname + '/moral/carson/index.html';	
	alttext = new Array;
		alttext[1] = "Boisjoly and the shuttle disaster";
		alttext[2] = "LeMessuier and the fifty-nine story crisis"
		alttext[3] = "Fred Cuny: Moral Leader 1944-1995";
		alttext[4] = "The Case of the Killer Robot";
		alttext[5] = "Help Line"
		alttext[6] = "Carson and the Hazards of Pesticides"
	outputarray = new Array;
		outputarray[1] = images[rand1];
		outputarray[2] = links[rand1];
		outputarray[3] = alttext[rand1];
	return outputarray;  // returns [1] image url, [2] link url, [3] alternate text
} */

/* Static Hot Topic for now */
function ReturnHotTopic () {
		outputarray = new Array;
		outputarray[1] = "http://temp.onlineethics.org/images/layout/hotnew.gif"
		outputarray[2] = "http://temp.onlineethics.org/moving.html"
		outputarray[3] =  "Information concerning the summer move of the OEC to the NAE"
	return outputarray;  // returns [1] image url, [2] link url, [3] alternate text
}

function wndOpen( pageToLoad, winName, width, height, center) { // pop-behind survey
	xposition = 0; 
	yposition = 0;

  	if ((parseInt(navigator.appVersion) >= 4 ) && (center)) {
    		xposition = (screen.width - width) / 2;
    		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + ","
	+ "height=" + height + ","
	+ "location=0,"
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=0,"
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + xposition + "," 	//NN Only
	+ "screeny=" + yposition + "," 	//NN Only
	+ "left=" + xposition + "," 	//IE Only
	+ "top=" + yposition; 			//IE Only

	//If statments check to make sure the survey window only opens one at a time
	if(!surveywindow.location && !surveywindow.closed)
	{
		surveywindow = window.open(pageToLoad,winName,args);
		surveywindow.blur(); // Moves survey window to background
		window.focus(); // Makes the Parent window the active window in the foreground
	}
	else if (surveywindow.location && surveywindow.closed)
	{
		surveywindow = window.open(pageToLoad,winName,args);
		surveywindow.blur(); // Moves survey window to background
		window.focus(); // Makes the Parent window the active window in the foreground
	}
}

// These functions not used on all pages, but enough to make them worth putting in the common script

function email(usr, server, display) { // Use instead of a mailto: link to prevent robots from lifting email addresses
	document.write('<a href="mailto:' + usr + '@' + server + '">' + display + '</a>');
}

function helpmail() {  // PLEASE FIND ALL INSTANCES AND CONVERT TO USE email();
	document.write('<a href="mailto:' + 'ethics' + 'help' + '@' + 'onlineethics.org">' + 'email' + '</a>');
}

function feedmail() {  // PLEASE FIND ALL INSTANCES AND CONVERT TO USE email();
	document.write('<a href="mailto:' + 'feed' + '@' + 'onlineethics.org">' + 'email' + '</a>');
}
function feedmail1() {  // PLEASE FIND ALL INSTANCES AND CONVERT TO USE email();
	document.write('<a href="mailto:' + 'feed' + '@' + 'onlineethics.org">' + 'Online Ethics Team' + '</a>');
}
function feedmail2() {  // PLEASE FIND ALL INSTANCES AND CONVERT TO USE email();
	document.write('<a href="mailto:' + 'feed' + '@' + 'onlineethics.org">' + 'Escr&iacute;banos' + '</a>');
}

