﻿window.onload = function()
{
	document.getElementById("searchText").focus();
}

function SelectPublications(allOrNone)
{
	var form = document.forms[0];
	
	for (var i = 0; i < form.elements.length; i++)
	{
		if (!form.elements[i].id.indexOf("publicationCheckList_"))
		{
			if (allOrNone == "all") form.elements[i].checked = "checked";
			else form.elements[i].checked = "";
		}
	}
}

function HideTabs()
{
	Element.hide('search_advanced');
	Element.hide('search_issues');
	Element.hide('search_categories');
	Element.removeClassName('advancedlink', 'selected');
	Element.removeClassName('issueslink', 'selected');
	Element.removeClassName('categorieslink', 'selected');
}

function ToggleAdvanced()
{
	if (!Element.visible('search_advanced')) 
	{
		HideTabs();
		Element.show('search_advanced');
		Element.addClassName('advancedlink', 'selected');
	}
	else
	{
		HideTabs();
	}
}

function ToggleIssues()
{
	if (!Element.visible('search_issues')) 
	{
		HideTabs();
		Element.show('search_issues');
		Element.addClassName('issueslink', 'selected');
	}
	else
	{
		HideTabs();
	}
}

function ToggleCategories()
{
	if (!Element.visible('search_categories')) 
	{
		HideTabs();
		Element.show('search_categories');
		Element.addClassName('categorieslink', 'selected');
	}
	else
	{
		HideTabs();
	}
}

function SelectFields(allOrNone)
{
	var form = document.forms[0];
	
	for (var i = 0; i < form.elements.length; i++)
	{
		if (!form.elements[i].id.indexOf("searchFieldsCheckList_"))
		{
			if (allOrNone == "all") form.elements[i].checked = "checked";
			else form.elements[i].checked = "";
		}
	}
}

function SearchCategory(catid)
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "searchcategory";
	theform.formArgs.value = catid;
	theform.submit();
}

function ShowPageNumber(pageNumber)
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "showpagenumber";
	theform.formArgs.value = pageNumber;
	theform.submit();
}

function Login()
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "login";
	theform.submit();
}

function Logout()
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "logout";
	theform.submit();
}

function GetReminder()
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "getreminder";
	theform.submit();
}

function Search()
{
	if (document.getElementById('searchText').value.length < 2)
	{
		alert("Please enter text to search for");
	}
	else
	{
		var theform;
		theform = document.forms[0];
		theform.formAction.value = "search";
		theform.submit();
	}
}

function isEnterKey(e)
{
	if (e.keyCode == 13) return true;
	else return false;
}

function ShowPublication(publication, edition)
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "showpublication";
	theform.formArgs.value = publication + "," + edition;
	theform.submit();
}

function ShowArticle(articleId)
{
	var theform;
	theform = document.forms[0];
	theform.formAction.value = "showarticle";
	theform.formArgs.value = articleId;
	theform.submit();
}

function LoginMessage()
{
	alert("Sorry, to view this article you need to be a subscriber and to log in.");
}