// debugging alerts through # 4

var Clist, Ctot;
var grade_freqs = new Array();
//var sgrades; // string
//var cp_icsc = new Array();

var consurf_url_base = "http://consurf.tau.ac.il";

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function initConsurf()
{
	if (epitopiaMode)
		Clist = epitopia_processed_chains.toUpperCase() +
			epitopia_ignored_chains.toUpperCase();
	else
		Clist = top.consurf_identical_chains.toUpperCase();

	Ctot = Clist.length;
	if (Ctot == 0)
		Ctot = 1; // when chain name is "none", Clist == "";

//	alert("consurf.js #2: Clist=" + Clist + " Ctot=" + Ctot);

	refreshConsurfFreqs();

	// Jmol starts asynchronously from the HTML loading.
	// Division loading is triggered by messageCallback from Jmol
	// and requires that controlsTarget and helpTarget be defined.
	// controlsTarget is set by onLoad initFG(), but was not always
	// happening early enough.
	// Therefore we'll do it redundantly here.

	initTargetDivs();
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function refreshConsurfFreqs()
{
//	alert("consurf.js #4 epitopiaMode=" + epitopiaMode);
	if (epitopiaMode)
		grade_freqs = epitopia_grade_freqs;
	else
	{
		if (top.consurf_isd_mode == "isd")
		{
			grade_freqs = top.consurf_grade_freqs_isd;
//		sgrades = top.seq3d_grades_isd;
//		cp_icsc = top.insertion_csc_isd;
		}
		else
		{
			grade_freqs = top.consurf_grade_freqs;
//		sgrades = top.seq3d_grades;
//		cp_icsc = top.insertion_csc;
		}
	}
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeLoadingMessage()
{
	var lmsg = "<center><big>FirstGlance in Jmol<br>is loading<br><b>" + pdbFilename +
		"<\/b><br><br>One moment please ...</big></center>";

	return lmsg;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function writeConsurfControls()
{
	controlPanel = "consurf";

	var conMsg = "";

	// BEGIN DEBUG 
	if (checkboxToDebugScripts)
		conMsg += "<form name='controlsForm'> \n" + makeDebugCheckbox();

	// BEGIN CONTROL PANEL
	conMsg += "<center><b>\n"; // BEGIN BOLD

	// NAME OF MOLECULE
	if (!top.pipe_title_enlarged)
		conMsg += "<small>";

	conMsg += "<big>" + pipe_title;

	if (top.pipe_subtitle != "")
		conMsg += "<br>" + top.pipe_subtitle;

	if (!top.pipe_title_enlarged)
		conMsg += "<\/small>";

	conMsg += "<\/big><\/b>"; // END BOLD

//	alert("consurf.js #1: conMsg:\n" + conMsg);

	// CONTROLS
	conMsg += makeConsurfControls2() + "<br>" + makeBottomLinks();

	if (consurfMode || selectonMode || epitopiaMode)
		conMsg +=
"<br><a href='javascript: showFGControls(\"fromConsurf\")'>\
Go to the <i>FirstGlance</i> Control Panel</a>";

	if (consurfMode || selectonMode) // NO HELP for epitopiaMode
		conMsg +=
" &nbsp; \
(<a href='consurf/cs_in_fg.htm' target=_blank>What For?</a>)";

	conMsg += "</center>\n";

	if (checkboxToDebugScripts)
		conMsg += "</form>\n";

	controlsTarget.innerHTML = conMsg;
}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function makeConsurfControls2()
{
	var cc2 = "<table border=0 cellpadding=8><tr><td>\n";

	cc2 += makeBkgSpinZoomButtons(false) // incolumn=false
		+ "</td></tr></table>\n";

	cc2 += makeInfoLinks();

	return cc2;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function showConsurfControls()
{
	clearControls();
	writeConsurfControls();
	showHelp("makeConsurfHelp()");
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// ConSurf reset button uses confirm_reset_consurf() in main_cs.js instead
//function resetConsurf()
//{
	// can't use doViewLink() because resetIndex etc. haven't been defined!

//	contactsShowing = false;
//	markContactsTargets = false;
//	resetPrep();
//	currentView = "consurfSpt";
//	centerMode = false;

//	var spt = consurfSpt + makeEchoSpt("")
//		+ clearBoxes() // axes, unitcell, boundbox
//		+ makeEchoPdbIdSpt(""); // blank parameter means get color from toggle

//	doMolViewSpt(spt); // in resetConsurf()
//}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function consurfView(mode)
{
	consurf_chain_display_mode = mode;

	if (mode == "none" || mode == "cartoon")
		clear_cssf_grades(false);
	else // mode is "all", meaning all spacefilled
		clear_cssf_grades(true);

	if (consurfMode || selectonMode || epitopiaMode)
	{
		currentView = "make_consurf_view_button_spt(\"" + mode + "\")";
//	alert("consurf.js #3: currentView = " + currentView);
		sf(mode);
	}

	if (pepsurfMode)
	{
		reDisplay("", "");
	}

	showHelp("makeConsurfHelp()"); // resets checkboxes!
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function toggleConsurfColors()
{
	useConsurfColors = !useConsurfColors;
	reDisplay("", ""); // no echo, no trailing spt
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function changeISDMode(mode)
{
	// record new display mode
	top.consurf_isd_mode = mode;

	top.consurf_isd_mode_number = 1;
	if (top.consurf_isd_mode == "dotssf")
		top.consurf_isd_mode_number = 2;
	else if (top.consurf_isd_mode == "dots")
		top.consurf_isd_mode_number = 3;
	else if (top.consurf_isd_mode == "sf")
		top.consurf_isd_mode_number = 4;

	// change molecular view to new mode
	if (mode == "isd")
		reset_consurf(false);
	else
		reset_isd_hidden(false);

	refreshConsurfFreqs();
	clear_cssf_grades(true);
	showHelp("makeConsurfHelp()");

	if (mode == "sf")
		alert(
"Warning: this display does not distinguish\n" +
"meaningful colors from those probably meaningless\n" +
"because of insufficient data!");

}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
function consurfNeedsDots()
{
	if (!consurfMode && !selectonMode && !epitopiaMode)
		return false;

	// don't show dots when in consurf-not-applicable FG views
	if (controlPanel == "fg" &&
		!(
			match(currentView, "contacts") ||
			match(currentView, "hide") ||
			match(currentView, "find") ||
			match(currentView, "catpi")
		)
	)
		return false;

	if (consurf_isd_mode.indexOf("dots") != -1) // dotssf, dots
		return true;
	return false;
}
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

