/* ----------------------------------------------------------------------------
Copyright (c) 2007 Steve Goeckler. All Rights Reserved.

FileName : jslib.js
Author   : Steve Goeckler
Abstract : JavaScript Library
History  : Born									03.01.07		!sg

--------------------------------------------------------------------------- */

function validate (reqField)
{
	var ctrl = document.getElementsByName("txt" + reqField)

	if (ctrl[0].value == "") {
		alert(reqField + " is a required field." )
		ctrl[0].focus()
		return false 
	}
	return true
}

function validateSel (selCtrl)
{
	var ctrl = document.getElementById(selCtrl)
	var idx = ctrl.selectedIndex;
	//alert(idx)
	if (idx==0) {
		alert("\nYou must make a selection from the drop-down menu.");
		ctrl.focus()
		return false 
	}

	return true
}
	//javascript functions to handle adding, editing/viewing and deleting records.
function addRec()
{
	document.location = sEditPage + "?mode=add"
}

function editRec(id)
{
	document.location = sEditPage + "?mode=edit&id=" + id 
}

function delRec(btn)
{
	var bKillIt = window.confirm("Delete " + sDelItemLabel + " [" + btn.name + "] ?");
	if (bKillIt)
		document.location = sPostTarget + "?mode=del&t=" + sTable + "&id=" + btn.id + "&r=" + sRedirectPage
}


function delAssocRec(btn, nIDCurrPageRec, nAssoc, redirect)
{
	var arrRecLabel = new Array ("Person", "Group", "Jurisdiction", "Jurisdiction", "Alias",
								 "Article", "Book", "Link", "Person", "Link", 
								 "Article", "Group", "Bishop", "Person", "Person");
	//alert("PageRec: " + nIDCurrPageRec + " Association: " + nAssoc + " Rec to Delete: " + btn.id)
	//alert (btn.redir)
	var bKillIt = window.confirm("Delete " + arrRecLabel[nAssoc-1] + " [" + btn.name + "] ?");
	if (bKillIt)
		//document.location = "postAssoc.asp?mode=del&assoc=" + nAssoc + "&rid=" + btn.id + "&prid=" + nIDCurrPageRec + "&r=" + btn.redir
		document.location = "postAssoc.asp?mode=del&assoc=" + nAssoc + "&rid=" + btn.id + "&prid=" + nIDCurrPageRec + "&r=" + redirect
}

function navTo(ds,id,sSrch,sType) {
	docLocation = "display.asp?ds=" + ds + "&id=" + id
	if (sSrch) {
		sSrch = "&sSrch=" + sSrch
		docLocation = docLocation + sSrch
	}
	if (sType) {
		sType = "&sType=" + sType
		docLocation = docLocation + sType
	}
	document.location = docLocation
}

function navToresources(ds,id,sSrch,sType) {
	docLocation = "resource.asp?ds=" + ds + "&id=" + id
	if (sSrch) {
		sSrch = "&sSrch=" + sSrch
		docLocation = docLocation + sSrch
	}
	if (sType) {
		sType = "&sType=" + sType
		docLocation = docLocation + sType
	}
	document.location = docLocation
}

function navTocontacts(ds,id) {
	document.location = "contact.asp?ds=" + ds + "&id=" + id
}


/*
	function updateList(item)
	{
		//alert (item.value + " " + item.name)
		objFrom = document.getElementById ("selPersons")
		objTo = document.getElementById ("lstPersons") 
		
		copySelected (objFrom, objTo)
	}
	function copySelected(fromObject,toObject) {
		for (var i=0, l=fromObject.options.length; i< l; i++) {
			if (fromObject.options[i].selected)
				addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
		}
		//for (var i=fromObject.options.length-1;i>-1;i--) {
		//	if (fromObject.options[i].selected)
		//		deleteOption(fromObject,i);
		//}
	}

	function addOption(object,text,value) {
		var defaultSelected = true;
		var selected = true;
		var optionName = new Option(text, value, defaultSelected, selected)
		object.options[object.length] = optionName;
	}

	function deleteOption(object,index) {
		object.options[index] = null;
	}
*/ 

