<!--
/*
 * Copyright (c) 2001 Talis Information Ltd.
 * Birmingham Research Park
 * Vincent Drive
 * Birmingham
 * B15 2SQ
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of Talis
 * Information Ltd. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Talis.
 *
 * Functions to support the BrowseAction Functionality as used by ArtifactDisplay
 *
 * @version $Revision: 1.9 $ $Date: 2005/06/07 13:09:44 $
 * @author $Author: al $
 */

 var BrowseFormNum = 99;
 var BrowseFormName = "Undefined"
function setBrowseForm(formName){
	BrowseFormNum = getBrowseFormNum(formName);
	BrowseFormName = formName;
}

function getBrowseFormNum(formName){
	for(i=0;i < document.forms.length;i++){
		if(document.forms[i].name == formName){
			return i;
		}
	}
}

function setFormValue(formName,fieldName,fieldValue){
	formNum = getBrowseFormNum(formName);
	for(i=0;i < document.forms[formNum].elements.length;i++){
		if(document.forms[formNum].elements[i].name == fieldName){
			document.forms[formNum].elements[i].value = fieldValue;
		}
	}
}

function doAction(WorkID,action,actionValue,actionValue2,actionValue3){

  if (timerId!=-1) {
    clearTimeout(timerId);
  }
  timerId = -1;

 document.forms[BrowseFormNum].expandedWorkID.value=WorkID;
 document.forms[BrowseFormNum].browse_action.value=action;
 document.forms[BrowseFormNum].browse_actionValue.value=actionValue;
 document.forms[BrowseFormNum].browse_actionValue2.value=actionValue2;
 document.forms[BrowseFormNum].browse_actionValue3.value=actionValue3;
 document.forms[BrowseFormNum].submit();
}


var refreshCount = 0;
var refreshActionValue = -99;
var refreshAction = -99;
var refreshWorkId = -99;

function doSearchRefresh(){
 document.forms[BrowseFormNum].browse_action.value=refreshAction;
 document.forms[BrowseFormNum].browse_actionValue.value=refreshActionValue;
 document.forms[BrowseFormNum].expandedWorkID.value=refreshWorkId;
 document.forms[BrowseFormNum].refreshCount.value=refreshCount;
 document.forms[BrowseFormNum].submit();
}

function startSearchRefreshTimer(time,count){
	refreshCount = count;
	timerId = setTimeout( "doSearchRefresh()",time * 1000 );
}


function check(field) {
	if (checkflag == "false") {
		if ( field.length){
			for (i = 0; i < field.length; i++) {
					field[i].checked = true;}
		}else{
			field.checked = true
		}
		checkflag = "true";
		return deselectAllText;
	}
	else {
	if ( field.length){
		for (i = 0; i < field.length; i++) {
			 field[i].checked = false;
		}
	}else{
		field.checked = false;
	}
	checkflag = "false";
	return sellectAllText;
	}
}
function hasSelected(field){

	// if user has option to select which records to choose
	if (document.browseForm.selectType!=null) {
		// if ALL is selected then is true
		if (document.browseForm.selectType[1].checked){
			return true;
		}
		if (document.browseForm.selectValues.value.length >0){
			return true;
		}
	}

	if ((document.browseForm.actionPanelSelected!=null) &&
		(document.browseForm.actionPanelSelected=="true") ) {
		return true;
	}

	if ( field.length){
		for (i = 0; i < field.length; i++) {
			if (field[i].checked == true){
				return true;
			}
		}
	}

	// check for singletons as well
	if (field.checked) {
	  return true;
	}

	alert(selectResultsText);

	return false;
}

//-->
