// JavaScript Document
function switchSearchMode()
{
	var advancedSearch = document.getElementById( "id_advancedSearch" );
	var anchor = document.getElementById( "id_switchSearchLink" );
	
	// check if an advanced box exists or not
	if( advancedSearch == null )
	{
		location.href += ( location.href.indexOf( "?" ) == -1 ? "?" : "&" ) + "advancedSearch=true";
		return false;
	}
	
	if( advancedSearch.style.display == "none" )
	{
		advancedSearch.style.display = "";
		document.searchForm.advancedSearch.value = "true";
		anchor.innerHTML = "Basic Search";
	}
	else
	{
		advancedSearch.style.display = "none";
		document.searchForm.advancedSearch.value = "false";
		anchor.innerHTML = "Advanced Search";
	}
/*
	if( advancedSearch.style.visibility == "hidden" )
	{
		advancedSearch.style.visibility = "visible";
		document.searchForm.advancedSearch.value = "true";
		anchor.innerHTML = "Basic Search";
	}
	else
	{
		advancedSearch.style.visibility = "hidden";
		document.searchForm.advancedSearch.value = "false";
		anchor.innerHTML = "Advanced Search";
	}
*/
}


function initSearchCalendars()
{
	try
	{
//		alert("here" );
		if( document.getElementById( "id_advancedSearch" ) != null )
		{
			Calendar.setup(
				{
				inputField : "id_startDate", // ID of the input field
				ifFormat : "%Y-%m-%d", // the date format
				button : "id_startDateButton" // ID of the button
				}
			);
			
			Calendar.setup(
				{
				inputField : "id_startDate", // ID of the input field
				ifFormat : "%Y-%m-%d", // the date format
				button : "id_startDate" // ID of the button
				}
			);
			
			Calendar.setup(
				{
				inputField : "id_endDate", // ID of the input field
				ifFormat : "%Y-%m-%d", // the date format
				button : "id_endDateButton" // ID of the button
				}
			);
			Calendar.setup(
				{
				inputField : "id_endDate", // ID of the input field
				ifFormat : "%Y-%m-%d", // the date format
				button : "id_endDate" // ID of the button
				}
			);
		}
	}
	catch( e ){}
}


function validateEmailAddress( address )
{
	var addresses = new Array();
	// if empty field then return true
	if( address == "" ) 
		return true;
	// split all the addresses into an array.  separate addresses by ';'
	addresses = address.split( ";" );
	
	// check each email address individually
	for( var i = 0; i < addresses.length; i++ )
	{
		if( addresses[i].search(/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i) == -1 )
		{
			return false;
		}
	}
	return true;
}
