function openNewWin(strURL, sWidth, sHeight)
{
	var newWindow = window.open(strURL, "winURL", "width=" + sWidth + ",height=" + sHeight + ",location=1,menubar=1,titlebar=0,scrollbars=1,toolbar=0,resizable=yes");
	newWindow.focus();
	return false;
}

function toggleItem(sItemID, oTD)
{
	var oItem = document.getElementById(sItemID);
	
	if (oItem.style.display == "none") {
		oItem.style.display = "inline";
		oTD.innerHTML = oTD.innerHTML.replace("see", "hide");
	} else {
		oItem.style.display = "none";
		oTD.innerHTML = oTD.innerHTML.replace("hide", "see");
	}
}

function toggleAllEvents(sClassName)
{
	var sExpectedDisplay;	
	
	if (window.event.srcElement.innerHTML.search("Show") > -1) {
		window.event.srcElement.innerHTML = window.event.srcElement.innerHTML.replace("+ Show", "- Hide");
		sExpectedDisplay = /\+/;
	} else {
		window.event.srcElement.innerHTML =  window.event.srcElement.innerHTML.replace("- Hide", "+ Show");
		sExpectedDisplay = /\-/;
	}

	var elems = document.getElementsByTagName("TD");
	var i = 0;
	for (; i < elems.length; i++) {
		if (elems[i].getAttribute("ItemControl") !== null) {
			elems[i].click();
		}
	}
}

function NewsPubDetail_submit()
{
	var i;
	var aList = document.getElementById("NewsPubAttorneyList");
	
	for (i=0; i < aList.length; i++) {
		aList.options[i].selected = true;
	}
	
	document.getElementById("NewsPubDetail").submit();
}

function removeAtty(oForm)
{
	var newOption;
	var i = 0;
	
	if (oForm.NewsPubAttorneyList.selectedIndex >= 0) {	
		newOption = document.createElement("OPTION");
		newOption.text = oForm.NewsPubAttorneyList.options[oForm.NewsPubAttorneyList.selectedIndex].text;
		newOption.value = oForm.NewsPubAttorneyList.options[oForm.NewsPubAttorneyList.selectedIndex].value;
		
		if (oForm.AttorneyList.options.length === 0) {
			oForm.AttorneyList.options.add(newOption, 0);
		} else {
			for (i=0; i<oForm.AttorneyList.options.length; i++) {
				if (oForm.AttorneyList.options[i].text.toLowerCase() > newOption.text.toLowerCase()) {
					oForm.AttorneyList.options.add(newOption,i);
					break;
				} else if (i + 1 === oForm.AttorneyList.options.length) {
					oForm.AttorneyList.options.add(newOption,i + 1);
					break;		
				}
			}
		}
		
		oForm.NewsPubAttorneyList.options.remove(oForm.NewsPubAttorneyList.selectedIndex);
		oForm.NewsPubAttorneyList.selectedIndex = 0;
	}
	
	//Set buttons
	oForm.buttonRemove.disabled = (oForm.NewsPubAttorneyList.options.length === 0);
}

function addAtty(oForm)
{ 
	var newOption;
	
	if (oForm.AttorneyList.selectedIndex >= 0) {
		newOption = document.createElement("OPTION");
		newOption.text = oForm.AttorneyList.options[oForm.AttorneyList.selectedIndex].text;
		newOption.value = oForm.AttorneyList.options[oForm.AttorneyList.selectedIndex].value;
		oForm.NewsPubAttorneyList.options.add(newOption);
		oForm.AttorneyList.options.remove(oForm.AttorneyList.selectedIndex);
		oForm.AttorneyList.selectedIndex = 0;
	}
	
	//Set Buttons
	oForm.buttonRemove.disabled = (oForm.NewsPubAttorneyList.options.length === 0);  
}

function validateForm() 
{
	var sErrors = "";
	
	if (sErrors !== "") {
		displayMsg("The following errors were found:<P><UL>" + sErrors + "</UL><P>You must correct these errors before you can continue to the next screen.");
		return false;
	} else {
		return true;
	}
}	

function onSubmit(sForm)
{
	if (validateForm()) {
		sForm.submit();
	}
}

function editAward(sPeopleID, sPubYear, sAwardID)
{
	var sArgs = "PeopleID=" + sPeopleID + "&AwardID=" + sAwardID + "&PubYear=" + sPubYear;
	var retVal = window.showModalDialog("popupShell.cfm?" + sArgs, "awardEdit", "dialogHeight:450px; dialogWidth:500px; scroll:yes; resizable:no; status:no; unadorned: yes");
	
//	alert(retVal[0]);
	if (retVal[0] !== 0) {
		location.reload();
	}
}

function editLookup(sTable, sID, oSelect)
{
	var sArgs = "SortOrder=1&TableName=" + sTable + "&ID=" + sID;
	var retVal = [2];
	
	retVal = window.showModalDialog("popupShell.cfm?" + sArgs, "lookupEdit", "dialogHeight:350px; dialogWidth:500px;");
	
	if (retVal[0] < 0) {
		return removeOption(oSelect, (0 - retVal[0]));
	}
	
	if (retVal[0] > 0) {
		removeOption(oSelect, retVal[0]);
		return insertOptionSorted(oSelect, retVal[0], retVal[1]);
	}
	return false;
}

function submitMe(oForm, sMode, sProcessPage)
{
	//	Make sure that your form template 
	//	includes wlrkForm.js and wlrkString.js as well

	var doc = document.all;
	var retVal = [];
	var retString;
	var i = 0;
	var sContent = prepareQueryStringForXmlHttp(oForm) + "&Mode=" + sMode;

	retString = submitToPage(sProcessPage, sContent, false);
	retVal = retString.split("|");
	
	//	alert(retVal);
	/*	if (retVal[0] < 0 ){
			alert("Your data was successfully deleted.");
		}
		if (retVal[0] > 0 ){
			alert("Your data was successfully entered.");
		}
	*/	
	window.returnValue = retVal;
	window.close();
}

function addARow(sTable, sSelect)
{
	var oSelect = document.getElementById(sSelect);
	var i = 0;
	var oTable;
	var oNewRow;
	
	if (oSelect.selectedIndex >= 0) {
		oTable = document.getElementById(sTable);
		oNewRow = oTable.insertRow(-1);
		oNewRow.id = "PeopleID_" + oSelect.value;
		
		for (i=0; i < 3; i++) {
			switch (i) {
				case 0: 
					oNewRow.insertCell(i).innerHTML = oSelect.options[oSelect.selectedIndex].text;
					break;
				case 1:
					oNewRow.insertCell(i).innerHTML = submitToPage("DateBox.cfm","DateName=" + "StartDate_" + oSelect.value,false);
					break;
				default:
					oNewRow.insertCell(i).innerHTML = submitToPage("DateBox.cfm","DateName=" + "EndDate_" + oSelect.value,false);
					break;
			}	
		}
	}
}