
var win;

function InstrWindow(URL, height, width) {

	var strOptions;

	strOptions="resizable,scrollbars,height=" + height + ",width=" + width;
	if (win) {
		if (win.closed) {
			win = window.open(URL, "instr", strOptions, true);
			}
		 else {
			win.focus();
			}
		}
	 else {
		win = window.open(URL, "instr", strOptions, true);
		}
	}


function anetClassChg(obj, newClass) {

	obj.classname=newClass;
	}


function NYI() {
	alert("Not Yet Implemented");
	}

//--- formerly of PublUtils   12/26/01 15:45

var Hdl;
var HdlID;
var Story;
var strChgColor = "red";



function LbInit(lb, txtBox) {

	var i;

	Hdl = new Array();
	HdlID = new Array();
	Story = new Array();
	
	document.getElementById("pMsgBox").value = "";
	txtBox.value = "";	
	
	}	


function StoryIndexFind(lb) {

	var	i;
	var bFound;
	var	strVal;	


	bFound = false;
	if (lb.selectedIndex >= 0) {
		strVal = lb.options[lb.selectedIndex].value;		
		
		for (i=0; i<Hdl.length; i++) {
			if (HdlID[i] == strVal) {
				bFound = true;
				break;
				}
			}
		}
				
	if (!bFound) {
	 	i = -1;	
	 	}		
		
	return(i);
	}
	

function HeadlLoad(lb, strHeadlID, strHeadl, strStory) {
	
	var	lgHeadlSeq;
	

	lgHeadlSeq = Hdl.length;
	Hdl[lgHeadlSeq] = strHeadl;
	HdlID[lgHeadlSeq] = strHeadlID;		
	Story[lgHeadlSeq] = strStory;

	AddValue(lb, Hdl[lgHeadlSeq], HdlID[lgHeadlSeq]);

	}


	
function HeadlSeqIndexFind(lb, nSeq) {

	var	i;
	var bFound;
	var	Val;
	

	Val = lb.options[nSeq].value;	
	
	bFound = 0;
	for (i=0; i<Hdl.length; i++) {
		if (HdlID[i] == Val) {
			bFound = 1;
			break;
			}
		}
		
	if (!bFound) {
	 	i = -1;	
	 	}		
		
	return(i);
	}
	

function HeadlValueFind(strVal) {

	var	i;
	var bFound;
	var	Val;
	

	bFound = 0;
	for (i=0; i<Hdl.length; i++) {
		if (HdlID[i] == strVal) {
			bFound = 1;
			break;
			}
		}
		
	if (!bFound) {
	 	i = -1;	
	 	}		
		
	return(i);
	}
	



function StoryLoad(lb, txtBox) {

	var	i;	
	
	
	i = StoryIndexFind(lb);
						
	if (i >= 0) {
		txtBox.value = Story[i];
		}
	 else {
	 	//txtBox.value = "<no story found>";	
		txtBox.value = "";	
	 	}
	}


function StoryUpdate(lb, txtBox, strMsgBoxID) {

	var	i, Msg, tOpt, strIDNew;	
	
	
	lgRem = lb.selectedIndex;	
	tOpt = lb.options[lgRem];
	strIDNew = HeadlIDNew();

	i = StoryIndexFind(lb);
						
	if (i >= 0) {
		Story[i] = txtBox.value;
		lb.options[lb.selectedIndex].style.color = strChgColor;
		HdlID[i] = strIDNew;
		tOpt.value = strIDNew;
		}
	 else {
	 	txtBox.value = "<no story found>";	
	 	}
		
	StatusBox(strMsgBoxID, "changes pending");
	}


function StatusBox(strMsgBoxID, strMsg) {

	var	MsgBox;
	
	
	MsgBox = document.getElementById(strMsgBoxID);	
	MsgBox.innerText = strMsg;	
	MsgBox.style.color = strChgColor;
	}



function HeadlChg(lb, txtBox) {
	
	var	lgRem, lgHeadlSeq;
	var strNew, strIDNew;
	
	
	if (lb.length > 0) {
		if (lb.selectedIndex >= 0) {
			lgRem = lb.selectedIndex;	
			tOpt = lb.options[lgRem];
			strNew = prompt("New Headline?", tOpt.text);
			if (strNew != null) {
				strIDNew = HeadlIDNew();
				tOpt.text = strNew;
				lgHeadlSeq = StoryIndexFind(lb);
				if (lgHeadlSeq >= 0) {
					Hdl[lgHeadlSeq] = strNew;
					HdlID[lgHeadlSeq] = strIDNew;
					tOpt.value = strIDNew;
					}
				else {
					alert("Unable to locate the headline - please reload the page and start over");
					}			
				}
			}
		else {
			alert("You must select a headline to change");
			}
		}
	}


function HeadlAdd(lb, txtBox) {
	
	var	lgHeadlSeq;
	var strNew, strValue, strValueBase;
	//var timNow;
	var	nRetryCt;
	
	var	tOpt;
	

	strNew = prompt("New Headline?", "");
	if (strNew != null) {
		//timNow = new Date();
		//strValue = "new," + timNow;
		strValue = HeadlIDNew();
		strValueBase = strValue;
		nRetryCt = 0;
		while ((HeadlValueFind(strValue) >= 0) && (nRetryCt < 100)) {
			strValue = strValueBase + nRetryCt;
			nRetryCt++;
			}	// and what if we die here?
			
		tOpt = document.createElement("OPTION");
		tOpt.text = strNew;
		tOpt.value = strValue;
		AddValue(lb, strNew, strValue)	
		lgHeadlSeq = Hdl.length;
		Hdl[lgHeadlSeq] = strNew;
		HdlID[lgHeadlSeq] = strValue;		
		Story[lgHeadlSeq] = "{replace this with the story text}";
		lb.selectedIndex = lb.length-1;
		StoryLoad(lb, txtBox);
		txtBox.select();
		txtBox.focus();
		}
	}




function HeadlIDNew() {

	var		timNow;
	var		strID;


	timNow = new Date();
	strID = "new:" + timNow;

	return(strID);
	}


		
function MoveUp(lb) {
	
	var	lgRem;
	
	
	if (lb.length > 0) {
		if (lb.selectedIndex >= 0) {
			lgRem = lb.selectedIndex;	
		
			tOpt = lb.options[lgRem];
			lb.options.remove(lgRem);
			lb.options.add(tOpt, lgRem-1);
			}
		else {
			alert("You must select a headline to move");
			}
		}
	}


function MoveDown(lb) {
	var	lgRem;
	
	if (lb.length > 0) {
		if (lb.selectedIndex >=0) {
			lgRem = lb.selectedIndex;
			tOpt = lb.options[lgRem];
			lb.options.remove(lgRem);
	
			if (lgRem < lb.length) {
				lb.options.add(tOpt, lgRem+1);	
				}
			 else {
				lb.options.add(tOpt, 0);	
				}	
			}
		else {
			alert("You must select a headline to move");
			}
		}
	}
	
		
function HeadlDel(lb, txtBox) {
	var	lgRem;
	
	if (lb.length > 0) {
		if (lb.selectedIndex >= 0) {
			lgRem = lb.selectedIndex;
			tOpt = lb.options[lgRem];
			lb.options.remove(lgRem);
			if (lgRem < lb.length) {
				lb.selectedIndex = lgRem;	
				}
			else {
				lb.selectedIndex = lgRem-1;	
				}
			
			StoryLoad(lb, txtBox);
			}
		else {
			alert("You must select a headline to delete");
			}			
		}
	}


function GetValue(lb) {
	
	alert("Value item '" + lb.options[lb.selectedIndex].value  + "'");
	}


function AddValue(lb, strText, strValue) {
	
	var	lgRem;
	var	tOpt;
	
	
	tOpt = document.createElement("OPTION");
	tOpt.text = strText;
	tOpt.value = strValue;	
	lb.options.add(tOpt);
	}


function LbSelect(lb, txt) {
	
	txt.value = lb.options[lb.selectedIndex].text;	
	}


function PrepReply(lb, txtSetStruct, txtSet1, txtSet2, txtSet3, txtSet4, txtSet5) {

	var	i, nStoryIndex;
	

	txtSetStruct.value = "5|" + lb.length + "|0|0|0|0|";
	txtSet1.value = lb.length + "|";
	
	for (i=0; i<lb.length; i++) {
		nStoryIndex = HeadlSeqIndexFind(lb, i);
		txtSet1.value += HdlID[nStoryIndex] + "|" + Hdl[nStoryIndex] + "|" + Story[nStoryIndex] + "|";
		}
	}
	
	
function TextMenuOver(txt) {
	txt.className="TextMenuOver";
	}	


function TextMenuOut(txt) {
	txt.className="TextMenuOut";
	}	


function TextButtonOver(txt) {
	txt.className="TextButtonOver";
	}	


function TextButtonOut(txt) {
	txt.className="TextButtonOut";
	}	

function TextButtonOver2(txt, strClass) {
	txt.className=strClass;
	}	

function TextButtonOut2(txt, strClass) {
	txt.className=strClass;
	}	



function PrepScreenInfo(txtColorDepth, txtScreenWidth, txtScreenHeight) {

	txtColorDepth.value = screen.colorDepth;
	txtScreenWidth.value = screen.width;
	txtScreenHeight.value = screen.height;
	}

function Rcertify() {
	popupWin = window.open('http://www.bbbonline.org/cks.asp?id=102010810321030', 'Participant','location=yes,scrollbars=yes,width=450,height=300'); 
	window.name = 'opener';
	} 

function PopUpFullWin(URL, winname, height, width) {

	var strOptions, win;

	strOptions="directories,status,menubar,toolbar,titlebar,location,resizable,scrollbars,height=" + height + ",width=" + width;
	if (win) {
		if (win.closed) {
			win = window.open(URL, winname, strOptions, true);
			}
		 else {
			win.focus();
			}
		}
	 else {
		win = window.open(URL, winname, strOptions, true);
		}
	}

