
function closeWindow(){
	window.close();
}


// -------------------------------------------------------
// write status bar message -------------------------

function statusFieldMessage(msg){
	window.status=msg;
	return true;
}

// --------------------------------------------------------
// generic list scroller ----------------------------------

function scrollList(abc,targetField){
	var s, w, name = abc;
	name = name.toUpperCase();
	var x = name.length;
	if(targetField == undefined){
		targetField =  document.staffoptions.thisrecord;
	}

	for(i = 0; i < targetField.options.length;i++){
		s = targetField.options[i].text;
		s = s.substr(0,x);
		s = s.toUpperCase();
		w = targetField.options[i].value;
		if((s==name)&&(w!="")){
			targetField.options[i].selected = true;
			break;
		}
	}
	window.status = abc;
}


// ------------------------------------------------------------
// generic pop window maker ----------------------------

function makeConsoleWindow(url,winWidth,winHeight,winName){
	i = screen.width;
	k = screen.height;
	i = (i / 2);
	k = ( k / 2 );
	var consoleWin; 
	consoleWin = window.open(url,winName,"status=yes,toolbar=no,resizable,location=no,scrollbars=yes,width=" + winWidth + ",height=" + winHeight);
	consoleWin.focus();
	consoleWin.moveTo((i-(winWidth / 2)),(k-(winHeight / 2)))
}

// ---------------------------------------------------------------
// custom pop window ----------------------------------------
function addWorkItem(list_id){
	makeConsoleWindow("/admin/work/add-work-item/index.asp?gf-id=" + list_id,650,500,"addWorkItemWin");
}

function getAuthorReference(search_string){
	makeConsoleWindow("/admin/agent/summary/index.asp?" + search_string,650,500,"agentBrowseWin");
}
function getWorkAuthor(search_string){
	makeConsoleWindow("/admin/agent/summary/workAgent.asp?" + search_string,650,500,"workAgentBrowseWin");
}
function getWorkReference(){
	makeConsoleWindow("/admin/work/summary/index.asp",650,500,"workBrowseWin");
}

// ---------------------------------------------------------------
// generic select list option selector

function setGroupOption(selected_item,match_field){
						
	var itemTypeFieldPrefix = eval("/" + match_field + "/g");
	var currentFieldName;
	var currentForm;
	
	//find a form in the page with field matching match_field
	// loop forms
	for(j=0; j<document.forms.length; j++){
		currentForm = document.forms[j];
		// loop form elements
		for(i=0; i < currentForm.length; i++){
			// get element name
			currentFieldName = currentForm.elements[i].name;
			// is element Item_Type drop list?
			if(currentFieldName.match(itemTypeFieldPrefix)){
				//if item type not already specified, set to selected_item
				if(currentForm.elements[i].value == ""){
					currentForm.elements[i].options[selected_item].selected = true;
				}
			}
		}		
	}

}


function toggleInfoPanel(){
	var infoPanel = document.getElementById("content_panels");
	if (infoPanel.style.display == "block"){
		infoPanel.style.display = "none";
	}else{
		infoPanel.style.display = "block";
	}
}

function toggleErrorHistoryPanel(){
	var errorHistoryPanel = document.getElementById("error_history_panel");
	if (errorHistoryPanel.style.display == "block"){
		errorHistoryPanel.style.display = "none";
	}else{
		errorHistoryPanel.style.display = "block";
	}
}

function deleteQuickset(forward_url){
	if(confirm("Are you sure you want to Delete this Author Set?")){
		window.location.href = forward_url;
	}
}



function reportWorkError(search_field,search_value){
	makeConsoleWindow("/author/report-error/index.asp?" + search_field + "=" + search_value,650,500,"agentWorkReportErrorWin");
}
