//-------------------------
/* EventClient class
Client side methods used by pages showing information from the Events table
 */

var COL_COUNT = 8;

function EventClient() 
{
  new OnyxObject().bequeath(this); //Inherit OnyxObject methods

  //Privately used properties
  
  //Public properties
  this.formEvents = "formEvents"; //Parent form must be called formEvents, unless it wishes to change this property
  
  //Private methods

  //Public methods
	this.submitEventID = EventClient_submitEventID;
  this.confirmSave = EventClient_confirmSave;
	this.contactOwner = EventClient_contactOwner;
  this.openDownload = EventClient_openDownload;
}

var eventClient = new EventClient();

//-----------------------------
//Note the menu item corresponding to this page.  It is highlight - and the user can't click it.
function EventClient_submitEventID(eventID, action, confirmSave)
{
  if (action == "Delete")
  {
    if (!confirm("Delete this entry?")) return;
  }
  else if (action == "ConfirmHtmlSave")
  {
    if (!this.confirmSave()) return;
    action = "SaveDetail";
  }

  document.getElementById('hiddenEventID').value = eventID;
  document.getElementById('hiddenActionType').value = action;	
  
  document.forms[this.formEvents].submit();
}

//-----------------------------
//
function EventClient_confirmSave()
{
  var s = ""; //Put all form text into here for texting
  
  for (var i=1; i <= COL_COUNT; i++)
  {
    if (document.getElementById("editCol" + i)) s = s + document.getElementById("editCol" + i).value;
  }
  
  if (document.getElementById("editDownload")) s = s + document.getElementById("editDownload").value;
  s = s + document.getElementById("editNotes").value

  if (s.indexOf('<') != -1 || s.indexOf('>') != -1 || s.indexOf('\\') != -1)
  { 
     if (!confirm("One of your field contains HTML characters (<, > or \\).\nIf they are not what you intend, they could mess up the page.\n\nDo you want to save them?")) return false;
  }

  return true;
}

//------------------------------
//Submit a ContactOwner request
function EventClient_contactOwner()
{
  document.getElementById('hiddenActionType').value = "ContactOwner";
  document.forms[this.formEvents].submit();
} 

//------------------------------
//Submit a ContactOwner request
function EventClient_openDownload(url)
{
	var win = window.open(url, "download_window", "toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=yes");
	win.focus();
}

