
// javascript to set print mode, and then submit the form

function setPrintMode(Form, PrintMode, Action)
{
	Form.pt.value = PrintMode
	go(Form, Action)
}



// javascript to mark or unmark all child's checkbox
// the child's name property should be the same with the parent's value property

function UpdateChildCheckBox(Form, ParentCheckBox)
{
	var ParentValue = ParentCheckBox.value
	var ParentStatus = ParentCheckBox.checked
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i++)
	{
		if((Form.elements[i].name == ParentValue) && (Form.elements[i].type == "checkbox"))
		{
			Form.elements[i].checked = ParentStatus
		}
	}
	Form.submit()
}



// javascript to update parent's checkbox
// the parent's value property should be the same with the child's name property

function UpdateParentCheckBox(Form, ChildCheckBox)
{
	var ChildName = ChildCheckBox.name
	var ChildStatus = ChildCheckBox.checked
	var NoOfFormElement = Form.elements.length
	var i

	if(ChildStatus == false)
	{
		for(i = 0; i < NoOfFormElement; i++)
		{
			if((Form.elements[i].value == ChildName) && (Form.elements[i].type == "checkbox"))
			{
				Form.elements[i].checked = ChildStatus
			}
		}
	}
	Form.submit()
}



function checkAll(Form)
{
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i ++)
	{
		if(Form.elements[i].type == "checkbox")
		{
			Form.elements[i].checked = true;
		}
	}
	Form.submit()
}



function uncheckAll(Form)
{
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i ++)
	{
		if(Form.elements[i].type == "checkbox")
		{
			Form.elements[i].checked = false;
		}
	}
	Form.submit()
}



// javascript to set the action of a from, and then submit the form

function go(Form, Action)
{
	Form.act.value = Action
	Form.submit()
}



// javascript to set the search type of the search main from, and then submit the form

function goSearch(Form, Action, SearchType)
{
	Form.type.value = SearchType
	go(Form, Action)
}



// javascript to set the category of the picture search from, and then submit the form

function goCategory(Form, Category)
{
	Form.psc.value = Category
	Form.submit()
}



function goPictureSearch(Form, Action, Argument)
{
	Form.arg1.value = Argument
	go(Form, Action)
}



// javascript to reset the page content, set the action of a from, and then submit the form

function goWithPageReset(Form, Action)
{
	Form.reset()
	go(Form, Action)
}



// javascript to set the hitlist page no and action of a from, and then submit the form

function goHitListPage(Form, Action, Page)
{
	Form.hpg.value = Page
	go(Form, Action)
}



// javascript to set the confirmation result and action of a from, and then submit the form

function exitConfirm(Form, Action, ConfirmationResult)
{
	Form.cfr.value = ConfirmationResult
	go(Form, Action)
}



// javascript to set action with confirmation

function goWithConfirm(Form, Action, YAction, NAction)
{
	Form.yact.value = YAction
	Form.nact.value = NAction

	if(Form.mdf.value == 'y')
	{
		Form.act.value = Action
	}
	else
	{
		Form.act.value = NAction
	}
	Form.submit()
}



// javascript to prompt for the hitlist page no, then set the action and submit the form
// after the user press the ok button

function goHitListPagePrompt(Form, Action, Prompt)
{
	var Page = window.prompt(Prompt, "")
	if(Page)
	{
		Form.hpg.value = Page
		go(Form, Action)
	}
}



function goHitListPagePromptEx(Form, Action, Prompt, ProcessingPromptURL, WinSetting)
{
	var Page = window.prompt(Prompt, "")
	if(Page)
	{
		window.open(ProcessingPromptURL, '', WinSetting)
		Form.hpg.value = Page
		go(Form, Action)
	}
}



// javascript to set the title list page no and action of a from, and then submit the form

function goTitleListPage(Form, Action, Page)
{
	Form.tpg.value = Page
	go(Form, Action)
}



// javascript to prompt for the title list page no, then set the action and submit the form
// after the user press the ok button

function goTitleListPagePrompt(Form, Action, Prompt)
{
	var Page = window.prompt(Prompt, "")
	if(Page)
	{
		Form.tpg.value = Page
		go(Form, Action)
	}
}



function goTitleListPagePromptEx(Form, Action, Prompt, ProcessingPromptURL, WinSetting)
{
	var Page = window.prompt(Prompt, "")
	if(Page)
	{
		window.open(ProcessingPromptURL, '', WinSetting)
		Form.tpg.value = Page
		go(Form, Action)
	}
}



function goResort(Form, Action)
{
	Form.srs.value = "on"
	Form.act.value = Action
	Form.submit()
}



function goWithProcessingPrompt(Form, Action, PromptURL, WinTitle, WinSetting)
{
	var subWin = window.open(PromptURL, WinTitle, WinSetting)
	go(Form, Action)
}



function goRefreshFullRecordPage(Form, Rcn, PageNo, IdxNo, SubIdxNo)
{
	Form.rcn.value = Rcn
	Form.hpg.value = PageNo
	Form.idx.value = IdxNo
	Form.sidx.value = SubIdxNo
	Form.submit()
}



// javascript to set the action and rcn of a form, and then submit the form

function changeLang(Form, LangCode)
{
	Form.lang.value = LangCode
	Form.submit()
}



// javascript to set the action and rcn of a form, then reset and submit the form

function changeLangWithPageReset(Form, LangCode)
{
	Form.reset()
	Form.lang.value = LangCode
	Form.submit()
}



function changeLangWithCachePageReset(Form, LangCode)
{
	Form.chpf.value = "off"
	changeLang(Form, LangCode)
}



// javascript to set action and change language code

function changeLangWithConfirm(Form, LangCode, Action, YAction, NAction)
{
	Form.lang.value = LangCode
	goWithConfirm(Form, Action, YAction, NAction)
}



// javascript to reset password in admin logon page

function changeLangInAdminLogonPage(Form, LangCode)
{
	Form.admp.value = ''
	changeLangWithPageReset(Form, LangCode)
}



// javascript to set record view type, and then submit the form

function toggleRecView(Form, ViewType)
{
	Form.rv.value = ViewType
	Form.submit()
}



// javascript to check the form data, and submit the form if validation success

function chgPwdValidate(Form, Action, ErrMsg)
{
	//if((Form.ii.value == "") || (Form.opp.value == "") || (Form.npp.value == "") || (Form.cpp.value == ""))
	if((Form.opp.value == "") || (Form.npp.value == "") || (Form.cpp.value == ""))
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



// javascript to check the form data, and submit the form if validation success

function logonValidate(Form, Action, ErrMsg)
{
	if((Form.ii.value == "") || (Form.pp.value == ""))
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



// javascript to check the form data (with 1 argument), then submit the form if
// validation success

function searchValidate1(Form, Action, ErrMsg)
{
	if(Form.arg1.value == "")
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



// javascript to check the search form data (with 2 arguments), then submit the form if
// validation success

function searchValidate2(Form, Action, ErrMsg)
{
	if((Form.arg1.value == "") || (Form.arg2.value == ""))
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



// javascript to manage reading level selection

function refeshCheckBox(Form, CtrlName, MaxCheckedLimit, AlertMsg)
{
	var NoOfFormElement = Form.elements.length
	var i
	var NoOfChecked = 0
	var WkName
	var pos = -1

	for(i = 0; i < NoOfFormElement; i++)
	{
		WkName = Form.elements[i].name
		if((WkName.substring(0, 6) == 'cbxirl') &&
			(Form.elements[i].type == "checkbox"))
		{
			if(Form.elements[i].name == CtrlName)
			{
				// save current item position
				pos = i
			}

			if(Form.elements[i].checked == true)
			{
				++NoOfChecked
			}
		}
	}

	if(NoOfChecked > MaxCheckedLimit)
	{
		alert(AlertMsg)
		if(pos >= 0)
		{
			Form.elements[pos].checked = false
		}
	}
}



function getReadLvlListandSubmit(Form, Action)
{
	var NoOfFormElement = Form.elements.length
	var i
	var ReadingLevelList = ''
	var WkName

	for(i = 0; i < NoOfFormElement; i++)
	{
		WkName = Form.elements[i].name
		if((WkName.substring(0, 6) == 'cbxirl') &&
			(Form.elements[i].type == "checkbox"))
		{
			if(Form.elements[i].checked == true)
			{
				if(ReadingLevelList != '')
				{
					ReadingLevelList += ','
				}
				ReadingLevelList += Form.elements[i].value
			}
		}
	}
	Form.irl.value = ReadingLevelList

	if(Form.mdf.value == 'n')
	{
		Form.mdf.value = 'y'
	}

	go(Form, Action)
}



// javascript to set content modify flag

function setModified(Form)
{
	if(Form.mdf.value == 'n')
	{
		Form.mdf.value = 'y'
		//alert(Form.mdf.value)
	}
}



// javascript to set print mode with save confirm, and then submit the form

function setPrintModeWithConfirm(Form, PrintMode, Action, YAction, NAction)
{
	Form.pt.value = PrintMode
	goWithConfirm(Form, Action, YAction, NAction)
}



// javascript to set sort order, and then submit the form

function toggleSortOrder(Form, SortOrder, Action, YAction, NAction)
{
	Form.ilso.value = SortOrder
	goWithConfirm(Form, Action, YAction, NAction)
}



// javascript to set record edit mode, and then submit the form

function toggleEditMode(Form, EditMode, Action, YAction, NAction)
{
	Form.nedm.value = EditMode
	goWithConfirm(Form, Action, YAction, NAction)
}



// javascript to set a control value then submit the form

function SetValueWithSubmit(Ctrl, CtrlValue, FormToSubmit, SubmitAction, HashValue)
{
	Ctrl.value = CtrlValue
	FormToSubmit.act.value = SubmitAction
	FormToSubmit.action += '#' + HashValue
	FormToSubmit.submit()
}



// function to set the copy flag
function setCopyFlag(Form, Action, CopyFlag)
{
	Form.icf.value = CopyFlag
	go(Form, Action)
}



// javascript to call confirmation page before delete

function confirmDelete(Form, Action, YAction, NAction)
{
	Form.yact.value = YAction
	Form.nact.value = NAction
	go(Form, Action)
}



// javascript to check the search form data (with 2 arguments), then submit the form if
// validation success

//function reloadImportRequestForm(Form)
//{
//	Form.ifile.value = ""
//	Form.submit()
//}



function reloadBatchUpdRequestForm(Form)
{
	Form.sfile.value = ""
	Form.submit()
}



// function to redirect a link only if the URL is not empty

function redirect(URL)
{
	if(URL != "")
	{
		window.open(URL)
	}
}



function previewEnrichLink(UrlRoot, UrlContent)
{
	redirect(UrlRoot.options[UrlRoot.selectedIndex].text + UrlContent.value)
}



// function to call help on form

function callFormHelp(URL)
{
	WkURL = URL
	Label = document.forms[0].name
	if(Label != "")
	{
		WkURL += '#' + Label
	}
	window.open(WkURL)
}



// function to call help on field control

function callFieldHelp(URL, Label)
{
	WkURL = URL
	if(Label != "")
	{
		WkURL += '#' + Label
	}
	window.open(WkURL)
}



// function to call help on marc tag

function callMarcHelp(URL, Ctrl)
{
	WkURL = URL
	if(Ctrl.value != "")
	{
		WkURL += '#' + Ctrl.value
	}
	window.open(WkURL)
}



function viewFromRecord(Form, ViewFlag)
{
	Form.vfr.value = ViewFlag
	Form.submit()
}



function viewToRecord(Form, ViewFlag)
{
	Form.vtr.value = ViewFlag
	Form.submit()
}



function startChange(Form, ChangeFlag)
{
	Form.sc.value = ChangeFlag
	Form.submit()
}



function startChangeRcn(Form, Prompt1, Prompt2, ChangeFlag)
{
	if((Form.fmrcn.value != "") && (Form.torcn.value != ""))
	{
		Prompt = Prompt1 + Form.fmrcn.value + Prompt2 + Form.torcn.value + " ?"
		if(window.confirm(Prompt, ""))
		{
			Form.sc.value = ChangeFlag
			Form.submit()
		}
	}
}



function checkAllNoSubmit(Form)
{
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i ++)
	{
		if(Form.elements[i].type == "checkbox")
		{
			Form.elements[i].checked = true;
		}
	}
}



function uncheckAllNoSubmit(Form)
{
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i ++)
	{
		if(Form.elements[i].type == "checkbox")
		{
			Form.elements[i].checked = false;
		}
	}
}



function gotolink(URL)
{
	window.open(URL)
}



// javascript to set library sort order, and then submit the form

function setLibSortOrder(Form, SortType)
{
	Form.lso.value = SortType
	Form.submit()
}



// javascript to check the input fields and submit the form if validation success

function uploadFileValidate(Form, Action, ErrMsg)
{
	if(Form.ufile.value == "")
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



// javascript to check the input fields and submit the form if validation success

function updateFileValidate(Form, Action, ErrMsg)
{
	if((Form.ifile.value == "") || (Form.ilc.value == ""))
	{
		alert(ErrMsg)
		return
	}
	else
	{
		go(Form, Action)
	}
}



function renew(Form, Action, HashValue)
{
	Form.rwif.value = "on"
	Form.action += '#' + HashValue
	go(Form, Action)
}



function renewAll(Form, Action, HashValue)
{
	var NoOfFormElement = Form.elements.length
	var i

	for(i = 0; i < NoOfFormElement; i++)
	{
		if((Form.elements[i].type == "checkbox") && (Form.elements[i].value == "rnw"))
		{
			Form.elements[i].checked = true
		}
	}

	renew(Form, Action, HashValue)
}



function genBorrowingHistory(Form, Action, HashValue)
{
	Form.gbhf.value = "on"
	Form.action += '#' + HashValue
	go(Form, Action)
}



function getCookieData(label)
{
	var labelLen = label.length
	var cLen = document.cookie.length
	var i = 0
	var cEnd
	
	while(i < cLen)
	{
		var j = i + labelLen
		
		if(document.cookie.substring(i, j) == label)
		{
			cEnd = document.cookie.indexOf(";", j)

			if(cEnd == -1)
			{
				cEnd = document.cookie.length
			}
			return unescape(document.cookie.substring(j, cEnd))
		}
		i++
	}
	return ""
}



function goMarkedRecordPrintablePage(Form, URL)
{
	var WkURL = URL
	var Key = "prcn"
	var NoOfFormElement = Form.elements.length
	var Page
	var i

	WkURL += "?act=PO"
	for(i = 0; i < NoOfFormElement; i++)
	{

		if((Form.elements[i].name == Key) && (Form.elements[i].type == "checkbox") && (Form.elements[i].checked))
		{
			WkURL += "&" + Key + "=" + Form.elements[i].value
		}
	}

	window.open(WkURL, "", "scrollbars=yes, resizable=yes")
}



// javascript to set the record key, and then submit the form

function goWithRecordKey(Form, Action, RecordKey)
{
	Form.act.value = Action
	Form.rkey.value = RecordKey
	Form.submit()
}



// javascript to set the patron rcn, and then submit the form

function goWithPatron(Form, Action, PRcn)
{
	Form.act.value = Action
	Form.patron.value = PRcn
	Form.submit()
}



// javascript to limit the length of a text area

function limitLength(TextArea, Length)
{
	if (TextArea.value.length > Length) {
		TextArea.value = TextArea.value.substr(0, Length);
	}
}