  /*---------------------------------------------------------------------
  Function: search - ediarySubmit
  Description:
    Sets the Events Diary parameter list and Submits the ediary form.

  Parameters:
    [params 0..n]  The parameters for the given action
  ---------------------------------------------------------------------*/
  var strAjaxDoSearchPath = '/eventsdiary/ajax/ajaxDo.php';
  var strSearchQuery = '';

  function renderPastEventYears (selectedYear) {
  	$('#renderPastEventYears').html('<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>');
	var strURL = strAjaxDoSearchPath+'?action=renderPastEventYears';
		$.ajax({
			type: 'GET',
			url: strURL,
			success: function(strReturn) {
				if (strReturn.substr(0, 5) != 'Error') {// display error
					$('#renderPastEventYears').html(strReturn);
					if (selectedYear != '') renderEventItemsByYear(selectedYear);
				} else {
					alert(strReturn);
				}
			}
		});
  } //function renderPastEventYears

  function renderEventItemsByYear(year) {
		if($('#renderEvent'+year).is(':visible')) {
			$('#renderEvent'+year).hide();
			$('#renderEvent'+year).html('');
			$('#ar'+year).attr('src', '/images/expand.gif');
		} else {
			$('#renderEvent'+year).show();
			$('#renderEvent'+year).html('Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/>');
			$('#ar'+year).attr('src', '/images/collapse.gif');

			var strURL = strAjaxDoSearchPath+'?action=renderEventItemsByYear&selectedYear='+year;
		  	$.ajax({
		  		type: 'GET',
		  		url: strURL,
		  		success: function(strReturn) {
		  			if (strReturn.substr(0, 5) != 'Error') {
		  				$('#renderEvent'+year).html(strReturn);
		  			} else {
		  				// display error
		  				alert(strReturn);
		  			}
		  		}
		  	});
		}
	} //function renderEventItemsByYear

  function loadFilter(parentPage, strSearch, timeframe, keydate, viewType, confreport, presentation, submitSearch) {
  		$('#eventSearchFilter').html('<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/>');
		var strURL = strAjaxDoSearchPath+'?action=loadFilter&parentPage='+parentPage+'&search='+strSearch+'&timeframe='+timeframe+'&keydate='+keydate+'&view='+viewType+'&confreport='+confreport+'&presentation='+presentation+'&submitSearch='+submitSearch;
		$.ajax({
			type: 'GET',
			url: strURL,
			success: function(strReturn) {
				if (strReturn.substr(0, 5) != 'Error') {// display error
					$('#eventSearchFilter').html(strReturn);
				} else {
					alert(strReturn);
				}
			}
		});

  } //function loadFilters

  function searchEvents(strSearch, timeframe, keydate, viewType, currentPage, submitSearch, renderStyle, confreport, presentation) {
  	$('#renderSearchResults').html('<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>');
  	var strURL = strAjaxDoSearchPath+'?action=searchEvents&search='+strSearch+'&timeframe='+timeframe+'&keydate='+keydate+'&view='+viewType+'&currentPage='+currentPage+'&submitSearch='+submitSearch+'&renderStyle='+renderStyle+'&confreport='+confreport+'&presentation='+presentation;
		$.ajax({
			type: 'GET',
			url: strURL,
			success: function(strReturn) {
				if (strReturn.substr(0, 5) != 'Error') {// display error
					$('#renderSearchResults').html(strReturn);
					if (strSearch != '' && renderStyle == 'upcomingEvents') searchtermHighlight();	//highlight the search term (searchhi_ediary.js) - using exisitng functions
					var anchor = window.location.hash.replace('#', '');
					if (anchor) $(location).attr('href', window.location.hash);
				} else {
					alert(strReturn);
				}
			}
		});

  } //function searchEvents

  function keyDateOnChange() {
  	var keydate = $('#keydate').val();
  	if (keydate != 'all') {
  		$('#timeframe').attr('disabled', 'disabled');	//disabled timeframe selection box
  		$('#timeframe').val('future');					//set timeframe to future (all specific key dates are for future events)
  	} else {
  		$('#timeframe').removeAttr('disabled');
  	}
  } //function keyDateOnChange

  function loadEvent(parentPage, eventId, strSearch, timeframe, keydate, viewType, confreport, presentation) {
		var strURL = strAjaxDoSearchPath+'?action=loadEvent&id='+eventId+'&parentPage='+parentPage+'&search='+strSearch+'&timeframe='+timeframe+'&keydate='+keydate+'&view='+viewType+'&confreport='+confreport+'&presentation='+presentation;
		$.ajax({
			type: 'GET',
			url: strURL,
			success: function(strReturn) {
				if (strReturn.substr(0, 5) != 'Error') {// display error
					$('#renderEvent').html(strReturn);
				} else {
					alert(strReturn);
				}
			}
		});

  } //function loadFilters

  function submitSearchEvent () {
  	var timeframe = $('#timeframe').val();
  	var formAction = $('#eventSearchForm').attr('action');
  	if (timeframe != 'future' && formAction != '/eventsdiary/search.php') {
  		$('#eventSearchForm').attr('action', '/eventsdiary/search.php');
  		//prompt alert
  		alert('You will now be taken to a new page that will display \''+ timeframe + ' events\' that match your search criteria');
  	} else if (timeframe == 'future' && formAction == '/eventsdiary/search.php') {
  		$('#eventSearchForm').attr('action', '/eventsdiary/index.php');
  		//prompt alert
  		alert('You will now be taken to a new page that will display \'upcoming events\' that match your search criteria');
  	}
  }	//function submitSearchEvent

  function renderFutureEventMonths(strSearch, timeframe, keydate, viewType, submitSearch, renderStyle, confreport, presentation) {
  	$('#renderFutureEventMonths').html('<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>');
  	var strURL = strAjaxDoSearchPath+'?action=renderFutureEventMonths&search='+strSearch+'&timeframe='+timeframe+'&keydate='+keydate+'&view='+viewType+'&submitSearch='+submitSearch+'&renderStyle='+renderStyle+'&confreport='+confreport+'&presentation='+presentation;
		$.ajax({
			type: 'GET',
			url: strURL,
			success: function(strReturn) {
				if (strReturn.substr(0, 5) != 'Error') {// display error
					$('#renderFutureEventMonths').html(strReturn);
				} else {
					alert(strReturn);
				}
			}
		});
  } //function renderFutureEventMonths

  function getURLnRedirect(timeframe) {
  	var anchor = window.location.hash.replace('#', '');
  	var currentURLqs = window.location.search;
  	if (anchor != '') {
  		if (timeframe != '') {	//if timeframe provided, only redirect with the timeframe as part of the query string	(to prevent item with promoid from tracking twice)
  			window.location = '/eventsdiary/search.php?id='+anchor+'&timeframe='+timeframe;
  		} else {
	  		if (currentURLqs != '')
	  			window.location = '/eventsdiary/search.php'+currentURLqs+'&id='+anchor;
	  		else
	  			window.location = '/eventsdiary/search.php?id='+anchor;
  		}
  	}
  } //function getURLnRedirect


  /*function ediarySubmit( ) {
    // Get params
    var paramList = new String();

    // Set Params
    if( document.frmBrowse.params ) {
      for( i=0; i<arguments.length; i++ ) {
	if( i>0 ) {
	  paramList += ',';
	}
	paramList += arguments[i];
      }
      document.frmBrowse.params.value = paramList;
    }

    //Submit Form
    document.frmBrowse.submit();
  }

  //-------------------------------------------------------------------
  function ediaryPopUp( url ) {
    hdl = window.open( url, 'ediaryhelp', "resizable=yes,scrollbars=yes,height=600,width=500" );
    hdl.focus();
  }

  //-------------------------------------------------------------------
  function ediaryClearSearch ( ) {
   if( document.frmBrowse.search ) {
     document.frmBrowse.search.value = "";
  }
    document.frmBrowse.submit();
  }

  //-------------------------------------------------------------------
  function setKeyDate ( control ) {
	  frm = control.form;
	  if( typeof( control.value ) == 'string' ) {
		  switch( control.value ) {
			  case "new":
			  case "updated":
			  case "datereminder":
			  	frm.timeframe.value = "future";
				frm.timeframe.disabled = true;
				break;
			  default:
			    frm.timeframe.value = "future";
				frm.timeframe.disabled = false;
		  }
	  }
  }

  //-------------------------------------------------------------------
  function onChangeTimeFrame( ) {
  	var timeframe = $('#timeframe').val();
  	var strSearch = $('#search').val();

  	if (timeframe == 'all') {
  		//prompt alert
  		alert('You will now be taken to a new page that will display \'all events\' that match your search criteria');
  		//redirect to search.php
  		$(location).attr('href', '/eventsdiary/search.php?search='+strSearch);
  	} else {
  		//submit form
  		$('#frmBrowse').submit();
  	}
  }*/

