/* ----------------------------------------------------------------------------
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 validateMulti (reqField)
{
	var arrFields=reqField.split(",");
	var numField=0;
	while (numField < arrFields.length) {
		var ctrl = document.getElementsByName("txt" + arrFields[numField])
		if (ctrl[0].value == "") {
			alert(arrFields[numField] + " is a required field." )
			ctrl[0].focus()
			return false 
		}
		numField++
	}
	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, redir)
{
	var arrRecLabel = new Array ("Name", "Group", "Jurisdiction", "Jurisdiction", "Alias",
								 "Article", "Book", "Link", "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=" + redir
}

function navTo(ds,id) {
	document.location = "display.asp?ds=" + ds + "&id=" + id
}



function approveSession(btn,redir)
{
	var bApproveIt = window.confirm("Approve session [" + btn.name + "] ?");
	if (bApproveIt)
		document.location = "postrec.asp?mode=appSess&id=" + btn.id + "&redir=" + redir
}

function delSession(btn,redir)
{
	var bKillIt = window.confirm("Delete session [" + btn.name + "] ?");
	if (bKillIt)
		document.location = "postrec.asp?mode=delSess&id=" + btn.id + "&redir=" + redir
}

function approvePCode(btn,redir)
{
	var bApproveIt = window.confirm("Approve Promo [" + btn.name + "] ?");
	if (bApproveIt) {
		//alert(sPostTarget + "?mode=app&id=" + btn.id + "&r=" + sRedirectPage)
		document.location = "postPromo.asp?mode=app&id=" + btn.id + "&redir=" + redir
	}

}
function rejectPCode(btn,redir)
{
	var bKillIt = window.confirm("Reject Promo [" + btn.name + "] ?");
	if (bKillIt) {
		//alert(sPostTarget + "?mode=rej&id=" + btn.id + "&r=" + sRedirectPage)
		document.location = "postPromo.asp?mode=rej&id=" + btn.id + "&redir=" + redir
	}	
}



/*
	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;
	}
*/ 

