//***** JavaScript document associated with the NCHLA Web site. *****
function openwindowlink(url) {
newwin = window.open(url,"","toolbar=no,width=675,height=650,left=10,top=10,screenX=10,screenY=10,status=no,scrollbars=yes,resizable=1");
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//this is used to show the floating menu on the extranet
function showRemote(url) {
self.name = "main"; // names current window as "main"

//var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
//"menubar=0,scrollbars=0,resizable=0,width=150,height=200";
var loc = (screen.width - 300)
var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
"menubar=0,scrollbars=1,resizable=1,top=40,left=" + loc + ",width=290,height=480";

var OpenWindow = window.open(url, "remote", windowprops); // opens remote control
OpenWindow.opener = self;
OpenWindow.focus();
}

function showSlideShow(url) {
self.name = "main"; // names current window as "main"

//var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
//"menubar=0,scrollbars=0,resizable=0,width=150,height=200";
var loc = 0
//var loc = (screen.width - 300)
var windowprops = "toolbar=0,location=0,directories=0,status=0, " +
"menubar=0,scrollbars=1,resizable=1,top=40,left=" + loc + ",width=650,height=600";

var OpenWindow = window.open(url, "slideshow", windowprops); // opens remote control
OpenWindow.opener = self;
OpenWindow.focus();
}

function closeRemote() {
timer = setTimeout('window.close();', 10);
}

function resetParent(url) {
window.opener.location.href=url;
}

//************************
//THIS FUNCTION IS USED TO SELECT OR DESELECT ALL CHECKBOXES
function check(field) {
if (field.length > 0)
	{
	if (checkflag == "false") {
	for (i = 0; i < field.length; i++) {
	field[i].checked = true;}
	checkflag = "true";
	return "Deselect All"; }
	else {
	for (i = 0; i < field.length; i++) {
	field[i].checked = false; }
	checkflag = "false";
	return "Select All"; }
	}
else
	{
	if (checkflag == "false") {
		field.checked = true;
		checkflag = "true";
		return "Deselect All";}
	else {
		field.checked = false;
		checkflag = "false";
		return "Select All";
		}
	}
}


function createNewWindow(url)
	{
		newWindow = open(url,null,"status=no,toolbar=no,menubar=no,location=no")

	}

var submitcount=0;
	
function checkTwice() {                       
if (submitcount == 0)
      {
      submitcount++;
      return true;
      }
   else 
      {
      alert("The request is being processed.  This may take a few seconds.  Thank you for your patience.");
      return false;
      }
   
}




function newwinFunction(newLoc, newWidth, newHeight){
	newWin=open("",newLoc,"scrollbars=yes,resizable=no,status=no,height=" + newHeight + ",width=" + newWidth);}

function fileFunction(newLoc, newWidth, newHeight){
	newWin=open("",newLoc,"scrollbars=yes,resizable=no,status=no,height=" + newHeight + ",width=" + newWidth);
	document.file.submitTo("http://localhost/nchla/action/upactn-file.asp");}


function selectFunction(numID){
//////////////////////////////////////////////////
//	JavaScript by Rafi and some other guy	//
//////////////////////////////////////////////////
var chosenSelect, chosenIndex, currentSelect, loopIndex, selectStr, linkStr, nameStr
selectStr = document.form1.elements['select' + numID];
linkStr = document.form1.elements['link' + numID];
nameStr = document.form1.elements['name' + numID];
chosenSelect= ('select' + numID);
chosenIndex = document.form1.elements[chosenSelect].selectedIndex;
if(chosenIndex != 0){
	currentSelect = ('select' + 1);
	for (loopIndex = 1;document.form1.elements[currentSelect];){
		if (loopIndex == numID){
			loopIndex++;
			currentSelect = ('select' + loopIndex);
			linkStr.value = selectStr.options[selectStr.selectedIndex].value;}
		else if (document.form1.elements[currentSelect].selectedIndex == chosenIndex){
			window.alert("This link has already been select.  Please select a different link.");
			document.form1.elements[chosenSelect].selectedIndex = 0;
			linkStr.value = "";
			currentSelect = null;}
		else {loopIndex++;
			currentSelect = ('select' + loopIndex);
			linkStr.value = selectStr.options[selectStr.selectedIndex].value;}}
	if (document.form1.id="delete"){
		nameStr.value = (selectStr.options[selectStr.selectedIndex].id);}}}



function submitAction(){
var submitStr, valueStr
submitStr = document.form1
valueStr = document.form1.elements['dowhat'].value;
if (valueStr == "novalue"){
	submitStr = "";}
else if (valueStr == "delete"){
	submitStr.submit();}
else if (valueStr == "update"){
	submitStr.submit();}
else {submitStr.submit();}}



function checkclick(clickedboxid){
//////////////////////////////////
//	JavaScript by Rafi	//
//////////////////////////////////
var clickedbox = "check" + clickedboxid;
var loopindex, currentcheck;
if (!document.form1.elements[clickedbox].checked){
	//if the box was unchecked, add appropriate code here
	//window.alert("You just unchecked " + clickedbox);
	}
else {
	currentcheck = 'check1';
	for(loopindex = 1;document.form1.elements[currentcheck];){
		if(loopindex == clickedboxid){
			loopindex++;
			currentcheck = 'check' + loopindex;
			}
		else if(document.form1.elements[currentcheck].checked){
			window.alert("You may not both post to the Extranet and submit to the archive.");
			document.form1.elements[clickedbox].checked = 0;
			currentcheck = null;
			}
		else {
			loopindex++;
			currentcheck = 'check' + loopindex;
			}
		}
	if (currentcheck){//if it was a successful change, add appropriate code here
		//window.alert("You checked " + clickedbox);
		}
	}
}


function checkclick2(clickedboxid){
//////////////////////////////////
//	JavaScript by Rafi	//
//////////////////////////////////
var clickedbox = "check" + clickedboxid;
var loopindex, currentcheck;
if (!document.form1.elements[clickedbox].checked){
	//if the box was unchecked, add appropriate code here
	//window.alert("You just unchecked " + clickedbox);
	}
else {
	currentcheck = 'check1';
	for(loopindex = 1;document.form1.elements[currentcheck];){
		if(loopindex == clickedboxid){
			loopindex++;
			currentcheck = 'check' + loopindex;
			}
		else if(document.form1.elements[currentcheck].checked){
			window.alert("You may not both post to the Extranet and pull from the Extranet.");
			document.form1.elements[clickedbox].checked = 0;
			currentcheck = null;
			}
		else {
			loopindex++;
			currentcheck = 'check' + loopindex;
			}
		}
	if (currentcheck){//if it was a successful change, add appropriate code here
		//window.alert("You checked " + clickedbox);
		}
	}
}





///////////////////////////////////////////////
////   Help Function Goes After THis   ////////
///////////////////////////////////////////////

// Need help-popups to work in frames?  Read how at:
// http://faq.javascriptsource.com/?help-popups

// Create an entry in this format for each help popup you will have.
// hmsg["popup name"] = new helpmsg(
// "Title of popup", "header style", "Message Style", "Help Message");

// 'popup name' is the what you will call the popup later, used to open help.
// 'title of popup' is shown at the top of the help box that opens.  (Optional)
// 'header style' is a predefined style of how to display the title.  
//    header style valid options include:  'header', 'fancyheader', 'h1', 'h2', or ""
// 'message style' is a predefined style of how to display the help message.
//    message style valid options include:  'plain', 'italics', 'bold', ""
// 'help message' is the the text shown in the popup.  It should explain the topic.

var clicker = -1

function helpfunction(){
clicker = -(clicker)
}

var hmsg = new Array();

hmsg["and"] = new helpmsg(
"Inclusive Search", "h4", "plain", "Clicking 'Inclusive' will return search results that meet <i>all</i> of the criteria selected.");

hmsg["or"] = new helpmsg(
"Exclusive Search", "h4", "plain", "Clicking 'Exclusive' will return search results that meet <i>any</i> of the criteria selected.");

hmsg["exact"] = new helpmsg(
"Exact Search", "h4", "plain", "Clicking 'Exact' will return search results that meet <i>exactly</i> the criteria selected.");

hmsg["narrow"] = new helpmsg(
"Narrow Search", "h4", "plain", "Clicking 'Narrow' will return search results that are <i>close</i> to the criteria selected.");

hmsg["broad"] = new helpmsg(
"Broad Search", "h4", "plain", "Clicking 'Broad' will return search results that are <i>generally similar</i> to the criteria selected.");

hmsg["help"] = new helpmsg(
"", "", "", "Click on 'Help' once to turn on Help Pop-Up windows.  Click on 'Help' again to turn them off.");


var myPopup = new helpbox("myPopup", hmsg, 275, 175, "#eeeeee");

// 275 is the width of the popup box
// 175 is the height of the popup box
// "#ffffee" is the color of the popup box


function helpmsg(header, hstyle, mstyle, message) {
this.DEFAULTHSTYLE = "plain";
this.DEFAULTMSTYLE = "plain";

this.header = header;
if (hstyle) this.hstyle = hstyle;
else this.hstyle = this.DEFAULTHSTYLE;
this.message = message;
if (mstyle) this.mstyle = mstyle;
else this.mstyle = this.DEFAULTMSTYLE;
return this;
}
new helpmsg();
helpmsg.prototype.show = show;

function show() {
var H = "<FONT FACE='arial'>" + this.header + "</FONT>";
if (this.hstyle == "h1") H = "<H1>" + H + "</H1>";
else if (this.hstyle == "h2") H = "<H2>" + H + "</H2>";
else if (this.hstyle == "h3") H = "<H3>" + H + "</H3>";
else if (this.hstyle == "h4") H = "<H4>" + H + "</H4>";
if (this.hstyle == "fancyheader") H = "<table width='75%'>" +
"<tr><td bgcolor='#6060ff' align='center' valign='center'>" +
"<H1><FONT COLOR='white'>" + H +
"</FONT></H1>" + "</td></tr></table>";
else if (this.hstyle == "italics")
H = "<I>" + H + "</I>";

var M = "<FONT FACE='arial'>" + this.message + "</FONT>";
if (this.mstyle == "plain") {}
if (this.mstyle == "italics") M = M.italics();
else if (this.mstyle == "bold") M = M.bold();

var htmlpage = "";
if (this.hstyle.indexOf("header")>=0)
htmlpage = H + M;
else htmlpage = H + "<BR>" + M;
return htmlpage;
}

function helpbox(name, hm, width, height, bgcolor) {
this.name = name;
this.helpmessage = hm;
this.timerHandle = null;
this.windowHandle = null;
this.DEFAULTWIDTH = 250;
this.DEFAULTHEIGHT = 150;
this.DEFAULTBGCOLOR = "#eeeeee";
this.POPUPDELAY = 100;
if (width) this.width = width;
else this.width = this.DEFAULTWIDTH;
if (height) this.height = height;
else this.height = this.DEFAULTHEIGHT;
if (bgcolor) this.bgcolor = bgcolor;
else this.bgcolor = this.DEFAULTBGCOLOR;
return this;
}
function startHelp(msgindex) {
if (clicker == 1){
var cmdstr="top." + this.name + ".showHelp('" + msgindex + "')";
this.timerHandle = setTimeout(cmdstr, this.POPUPDELAY);
}
}
function showHelp(msgindex) {
if (!this.windowHandle || !this.windowHandle.name || this.windowHandle.name=="")
this.windowHandle = window.open(
"", 
"subWindow", 
"toolbar=no," +
"location=no," +
"directories=no," +
"status=no," +
"menubar=no," +
"scrollbars=no," +
"resizable=no," +
"width=" + this.width + "," +
"height=" + this.height
);
else
this.windowHandle.focus();
this.windowHandle.document.open();
var to_page =
"<HTML>\n" +
"<HEAD><TITLE>\n" +
"NCHLA Intranet Help\n" +
"</TITLE></HEAD>\n" +
"<BODY BGCOLOR='" + this.bgcolor + "'><P>" +
this.helpmessage[msgindex].show() +
"</BODY></HTML>\n";
this.windowHandle.document.write(to_page);
this.windowHandle.document.close();
}
function clearHelp() {
clearTimeout(this.timerHandle);
if (this.windowHandle && this.windowHandle.name) {
this.windowHandle.close();
this.windowHandle=null;
   }
}
new helpbox();
helpbox.prototype.startHelp = startHelp;
helpbox.prototype.showHelp = showHelp;
helpbox.prototype.clearHelp = clearHelp;










///////////////////////////////////////////
//  **  NON-USEFUL JAVASCRIPTS HERE  **  //
///////////////////////////////////////////



//function selectFunction(numID){
//var selectStr, linkStr, nameStr, loopIndex, loopStr
//selectStr = document.form1.elements['select' + numID];
//linkStr = document.form1.elements['link' + numID];
//nameStr = document.form1.elements['name' + numID];
//for (loopIndex = 1; loopIndex <= numID; loopIndex++){
//	loopStr = document.form1.elements['link' + loopIndex];
//	if (loopIndex==numID){
//		linkStr.value = selectStr.options[selectStr.selectedIndex].value;}
//	else if (linkStr.value==loopStr.value){
//		window.close();}
//	else {
//		linkStr.value = selectStr.options[selectStr.selectedIndex].value;}}
//if (document.form1.id="delete"){
//nameStr.value = (selectStr.options[selectStr.selectedIndex].id);}
//loopIndex=1;}



//function checkclick2(clickedboxid){
//var clickedbox = "check" + clickedboxid
//var loopIndex, currentcheck;
//if(document.form1.elements[clickedbox] == "check1"){
//	for(loopIndex=2;document.form1.elements[currentcheck];){
//		if(!document.form1.elements[currentcheck].checked){
//			loopIndex++;
//			//nothing
//			}
//		else {
//			window.alert"You may not select both.";
//			document.form1.elements[clickedbox].checked = 0;
//			currentcheck = null;
//			}
//		}
//	}
//else if(document.form1.elements[check1].checked){
//	window.alert"You may not select both.";
//	}
//else {
//	//nothing
//	loopIndex="1";
//}}}