//<!--
//kiosk.js
function showHelp(theURL) {
    theURL = '/Help/'+theURL+'.htm';
    var newWindow = window.open(theURL,'Help','width=300,height=400,scrollbars,resizable');
}

function addToPort(SessionID,Sequence,objID) {
    document.theForm.objID.value = objID;
    suffix = "?sid="+SessionID + "&x=" + Sequence;
    var portWind = window.open("/Kiosk/ChoosePort.htm"+suffix,"ChoosePort","height=150,width=300")
}

function addIDs() {
    document.theForm.action = document.theForm.action+document.theForm.portID.value+"*"+document.theForm.objID.value+suffix;
    document.theForm.submit();
}

function toggle(id) {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
    e.style.display = 'none';
        else
    e.style.display = 'block';
}

function submitPop(page,SessionID) {
    self.document.forms["popup"].action = "/OBJ" + "?sid=" + SessionID + "&rec=" + ( page + 1 );
    self.document.forms["popup"].submit();
}

// kiosk pages\AddOneObj.htm 2011/09/08
function setPort(selOpt) {
if (selOpt == 1) {
		var portName = prompt("Please enter the new portfolio name:");
		if(portName.length>0) {
			opener.document.theForm.name.value = portName;
			submitPort(selOpt);
		}
	}
	else {
		submitPort(selOpt);
	}
}
function submitPort(selOpt) {
	opener.document.theForm.portID.value = document.portForm.portList.options[selOpt].value;
	opener.addIDs();
	window.close();
}

// Kiosk/ChoosePort.htm 2011/09/08 
function setPort(selOpt) {
	if (selOpt == 1) {
		var portName = prompt("Please enter the new portfolio name:","");
		if(portName) {
			opener.document.theForm.name.value = portName;
			submitPort(selOpt);
		}
		else {
			self.document.portForm.portList.selectedIndex = 0;
		}
	}
	else {
		submitPort(selOpt);
	}
}

function submitPort(selOpt) {
	opener.document.theForm.portID.value = document.portForm.portList.options[selOpt].value;
	opener.addIDs();
	window.close();
}

// kiosk pages\AddToPortfolio.htm 2011/09/08
function selPort(SessionID,selOpt) {
	if(selOpt>0){
		if(selOpt==1) {
			document.portSel.name.value=prompt("Please enter the name for the new portfolio:","");
			if(document.portSel.name.value!="null") {
				document.portSel.action = document.portSel.action+document.portSel.portList.options[selOpt].value+"$"+SessionID;
				document.portSel.submit();
			}
			else {
				document.portSel.portList.selectedIndex = 0;
			}
		}
		else {
			document.portSel.action = document.portSel.action+document.portSel.portList.options[selOpt].value+"$"+SessionID;
			document.portSel.submit();
		}
	}
}

// Kiosk Pages/password.htm 2011/09/08
function checkPass() {
	if(document.changePass.Password.value==document.changePass.newPassword2.value)
	document.changePass.submit();
	else {
		alert("Your new password was not entered the same way twice. Please try again.");
		document.changePass.Password.value="";
		document.changePass.newPassword2.value="";
		document.changePass.Password.focus();
	}
}

// Kiosk/Robots.htm 2011/09/08
function submitPop(page,SessionID) {
	self.document.forms["popup"].action = "/OBJ*" + ( page + 1 ) + "$" + SessionID;
	self.document.forms["popup"].submit();
}

// Search/Object/Date.htm 2011/09/08
function lineChange(NameOfForm,srchType,lastLine) {
	document.forms[NameOfForm].action = "/4DACTION/HandleCGI/QS_"+srchType+"*"+lastLine+"?sid={SessionId}";
	document.forms[NameOfForm].submit();
}

// file: Search/Objects/Keywords/SearchScripts.htm
function addKW() { //adds selected KW to KeywordsSelected and FindKW
	var KWFound = self.document.forms["ChooseKW"].elements["KeywordsFound"]
	var KWSelected = self.document.forms["ChooseKW"].elements["KeywordsSelected"]
	var ChooseForm = self.document.forms["ChooseKW"]
	var FindForm = self.document.forms["FindKW"]
	var i = KWFound.selectedIndex //keyword to be added
	var len = KWSelected.length //number of options currently in KeywordsSelected
	if(len == 6) {
	 alert("You may only select 6 keywords to search.")
	}
	else {
	if(KWSelected.options[0].text == "{Blank}") {
		if(len > 1) {
		 alert("Error: contact webmaster or support.")
		}
		KWSelected.options[0]=null //clear the dashes, to be replaced
		KWSelected.length = len
		len = 0
	}
	else {
		KWSelected.length = len + 1
	}
	//the option number is actually one less than the new length of the list (starts with 0)
	KWSelected.options[len].text = KWFound.options[i].text //add to KWSelected
	var KWid = KWFound.options[i].value
	//assign pathNum of selected keyword to search list
	self.document.forms["ChooseKW"].elements["KW"+(len)].value = KWid
	self.document.forms["FindKW"].elements["KW"+(len)].value = KWid
	//assign ID of selected keyword to search list
			self.document.forms["ChooseKW"].elements["KWID"+(len)].value= self.document.forms["KeywordIDs"].elements["ID-"+(i)].value
			self.document.forms["FindKW"].elements["KWID"+(len)].value= self.document.forms["KeywordIDs"].elements["ID-"+(i)].value
  }
}
function removeKW() { //removes selected KW from KeywordsSelected
	var KWSelected = self.document.forms["ChooseKW"].elements["KeywordsSelected"]
	var i = KWSelected.selectedIndex //keyword to be removed
	var ChooseForm = self.document.forms["ChooseKW"]
	var FindForm = self.document.forms["FindKW"]
	//remember that the option number is one less than the place on the list
	KWSelected.options[i] = null
	if(KWSelected.length == 0) {
	 KWSelected.options[0] = new Option("{Blank}")
	}
	if(i<5){
	 for(var j = i; j < 5; j++) { //shift down the values to be passed back to the kiosk on search
		ChooseForm.elements["KW"+j].value =  ChooseForm.elements["KW"+(j+1)].value
		FindForm.elements["KW"+j].value =  FindForm.elements["KW"+(j+1)].value
	 }
	}
	ChooseForm.elements["KW5"].value = ""
	FindForm.elements["KW5"].value = ""
}
function loadPath(word) { //displays path of selected KW
	if(word.selectedIndex>-1) {
	self.document.ChooseKW.DisplayPath.value = self.document.KeywordIDs.elements["Path"+(word.selectedIndex)].value
}
}
function clearKW() {
	self.document.forms["ChooseKW"].elements["KeywordsSelected"].length = (parseInt(self.document.forms["KeywordIDs"].elements["NumSubmitted"].value)+1)
	if(self.document.forms["ChooseKW"].elements["KeywordsSelected"].length == 0) {
	self.document.forms["ChooseKW"].elements["KeywordsSelected"].options[0] = new Option("{Blank}")
	}
for(var i = (parseInt(self.document.forms["KeywordIDs"].elements["NumSubmitted"].value)+1); i < 6; i++) {
	self.document.forms["ChooseKW"].elements["KW"+i].value = ""
	self.document.forms["ChooseKW"].elements["KWID"+i].value = ""
	self.document.forms["FindKW"].elements["KW"+i].value = ""
	self.document.forms["FindKW"].elements["KWID"+i].value = ""
	}
}

// Security/LoginGeneral.htm 2011/09/08
function cont(tag) {
	document.forms["Login"].action="/4DACTION/HANDLECGI/Log"+tag;
	document.forms["Login"].submit();
}

// SharedPortfolioIndex.htm 2011/09/08
function showUser(userList,sessionID) {
	// filter the portfolio list for a single author
	if(userList.selectedIndex>0) {
		if(userList.selectedIndex==1) {
			document.userSelection.action="/SPOR1?sid="+sessionID ;
		}
		else {
			document.userSelection.action= "/PRU"+userList.options[userList.selectedIndex].value+"?sid="+sessionID ;
		}
		document.userSelection.submit();
	}
}

// Users/Login.htm 2011/09/08
function submitLogin() {
	var today = new Date();
	var expdate = new Date();

	if( document.logForm.rememberMe.checked == true ) {
	// Store a cookie that remembers the username.

	// By default, remember the username for a year.
		expdate.setTime( today.getTime() + ( 24 * 60 * 60 * 1000*365 ) );

		document.cookie = "username=" + escape( document.logForm.username.value ) +"; expires=" + expdate.toGMTString();}
	else {
	// If the cookie exists, erase it.
		expdate.setTime( today.getTime() - 3600000*24 );
		document.cookie = "username=;expires=" + expdate.toGMTString;
	}
	return true;
}

function setUsername() {
	var index = document.cookie.indexOf( "username=" );
	if( index == -1 ) {
		document.logForm.username.focus();
		document.logForm.rememberMe.checked = false;
		return null;
	}

	// Set the index to the start of the username.
	index = document.cookie.indexOf( "=", index ) + 1;

	// Find the end of the username.
	var endstr = document.cookie.indexOf(";", index);
	if( endstr == -1 ) endstr = document.cookie.length;

	document.logForm.username.value = unescape(document.cookie.substring(index, endstr));
	document.logForm.rememberMe.checked = true;
	document.logForm.password.focus();
}

// Users/PortfolioIndex.htm
function areUsure(toURL,portName) {
	if(confirm('Are you sure you want to delete portfolio '+portName+'?')) {
		window.location=toURL;
	}
}

// Users/PortfolioSort.htm 2011/09/08
function saveSort() {
	var objForm = self.document.processSort;
	var sortOrder = new Array();

	for(var i = 3; i < objForm.elements.length-3; i++) {
		//loop through all the input boxes in the form
		//skip the first 3 and last 3 - these are buttons
		sortOrder.length += 1; //add one more element to the array
		sortOrder[sortOrder.length-1] = new Array();
		sortOrder[sortOrder.length-1][0] = objForm.elements[i].name;
		sortOrder[sortOrder.length-1][1] = objForm.elements[i].value;
	}
	sortOrder.sort(function(a,b){return a[1] - b[1];});
	var submitForm = self.document.objSort;
	for(var i = 0; i < sortOrder.length; i++) {submitForm.order.value += sortOrder[i][0]+"*";}
	submitForm.submit();
}
	function clearSort() {
		var objForm = self.document.processSort;
		for(var i = 3; i < objForm.elements.length-3; i++) {
			objForm.elements[i].value = 0;
		}
	}

//<!-- SearchScripts.htm
function addKW() { //adds selected KW to KeywordsSelected and FindKW
	var KWFound = self.document.forms["ChooseKW"].elements["KeywordsFound"]
	var KWSelected = self.document.forms["ChooseKW"].elements["KeywordsSelected"]
	var ChooseForm = self.document.forms["ChooseKW"]
	var FindForm = self.document.forms["FindKW"]
	var i = KWFound.selectedIndex //keyword to be added
	var len = KWSelected.length //number of options currently in KeywordsSelected
	if(len == 6) {
		alert("You may only select 6 keywords to search.")
	}
	else {
		if(KWSelected.options[0].text == "{Blank}") {
			if(len > 1) {
			alert("Error: contact webmaster or support.")
			}
			KWSelected.options[0]=null //clear the dashes, to be replaced
			KWSelected.length = len
			len = 0
		}
		else {
			KWSelected.length = len + 1
		}
		//the option number is actually one less than the new length of the list (starts with 0)
		KWSelected.options[len].text = KWFound.options[i].text //add to KWSelected
		var KWid = KWFound.options[i].value
		//assign pathNum of selected keyword to search list
		self.document.forms["ChooseKW"].elements["KW"+(len)].value = KWid
		self.document.forms["FindKW"].elements["KW"+(len)].value = KWid
		//assign ID of selected keyword to search list
			self.document.forms["ChooseKW"].elements["KWID"+(len)].value= self.document.forms["KeywordIDs"].elements["ID-"+(i)].value
			self.document.forms["FindKW"].elements["KWID"+(len)].value= self.document.forms["KeywordIDs"].elements["ID-"+(i)].value
		}
}
function removeKW() { //removes selected KW from KeywordsSelected
	var KWSelected = self.document.forms["ChooseKW"].elements["KeywordsSelected"]
	var i = KWSelected.selectedIndex //keyword to be removed
	var ChooseForm = self.document.forms["ChooseKW"]
	var FindForm = self.document.forms["FindKW"]
	//remember that the option number is one less than the place on the list
	KWSelected.options[i] = null
	if(KWSelected.length == 0) {
		KWSelected.options[0] = new Option("{Blank}")
	}
	if(i<5){
		for(var j = i; j < 5; j++) { //shift down the values to be passed back to the kiosk on search
		ChooseForm.elements["KW"+j].value =  ChooseForm.elements["KW"+(j+1)].value
		FindForm.elements["KW"+j].value =  FindForm.elements["KW"+(j+1)].value
		}
	}
	ChooseForm.elements["KW5"].value = ""
	FindForm.elements["KW5"].value = ""
}
function loadPath(word) { //displays path of selected KW
if(word.selectedIndex>-1) {
	self.document.ChooseKW.DisplayPath.value = self.document.KeywordIDs.elements["Path"+(word.selectedIndex)].value
}
}
function clearKW() {
	self.document.forms["ChooseKW"].elements["KeywordsSelected"].length = (parseInt(self.document.forms["KeywordIDs"].elements["NumSubmitted"].value)+1)
	if(self.document.forms["ChooseKW"].elements["KeywordsSelected"].length == 0) {
	self.document.forms["ChooseKW"].elements["KeywordsSelected"].options[0] = new Option("{Blank}")
	}
for(var i = (parseInt(self.document.forms["KeywordIDs"].elements["NumSubmitted"].value)+1); i < 6; i++) {
		self.document.forms["ChooseKW"].elements["KW"+i].value = ""
		self.document.forms["ChooseKW"].elements["KWID"+i].value = ""
		self.document.forms["FindKW"].elements["KW"+i].value = ""
		self.document.forms["FindKW"].elements["KWID"+i].value = ""
	}
}

// Search/Artist/QuickSearch.htm 2011/09/08, Search/Object/Contains.htm 2011/09/08, Search/Object/QuickSearch.htm 2011/09/08
//{scripts}
// -->

