function aro_displayDocuments()
{
     var url = 'modules.php?mod=adminvideoro';
     displayText('maincontent',url);
}

function aro_displaylist(pageno)
{
     var url = 'modules.php?mod=adminvideoro&pageno='+pageno;
     displayText('maincontent',url);
}


function aro_addDocument()
{
     var url = 'modules.php?mod=adminvideoro&req=add';
     displayText('maincontent',url);
}


function aro_insertDocument()
{
     var form = document.getElementById('documentform');
     var docname = document.getElementById('myfile').value;
     if (docname =='')
          {
         alert('You must upload a file.');
          return false;
          }

     if ( ! aro_validateDocumentForm(form))
          return false;

     var url = 'modules.php?mod=adminvideoro&req=insert'+
               '&docname='+encodeURIComponent(docname)+
               '&title='+encodeURIComponent(form.title.value)+
               '&vtitle='+encodeURIComponent(form.vtitle.value)+
               '&vdescript='+encodeURIComponent(form.vdescript.value)+
               '&vsURL='+encodeURIComponent(form.vsURL.value)+
               '&synopsis='+encodeURIComponent(form.synopsis.value)+
               '&description='+encodeURIComponent(form.description.value)+
               '&month='+encodeURIComponent(form.month.value)+
               '&year='+encodeURIComponent(form.year.value);
     ret = serverFunction(url);
     var url = 'modules.php?mod=adminvideoro';
     displayText('maincontent',url);
     return false;
}

function aro_editDocument(docid)
{
     var url = 'modules.php?mod=adminvideoro&req=edit&id='+docid;
     displayText('maincontent',url);
}

function aro_updateDocument()
{
     var form = document.getElementById('documentform');

     if ( ! aro_validateDocumentForm(form))
          return false;

     var docname = document.getElementById('myfile').value;

     var url = 'modules.php?mod=adminvideoro&req=update'+
               '&docid='+encodeURIComponent(form.docid.value)+               
               '&docname='+encodeURIComponent(docname)+
               '&title='+encodeURIComponent(form.title.value)+
               '&vtitle='+encodeURIComponent(form.vtitle.value)+
               '&vdescript='+encodeURIComponent(form.vdescript.value)+
               '&vsURL='+encodeURIComponent(form.vsURL.value)+
               '&synopsis='+encodeURIComponent(form.synopsis.value)+
               '&description='+encodeURIComponent(form.description.value)+
               '&month='+encodeURIComponent(form.month.value)+
               '&filename='+encodeURIComponent(form.filename.value)+
               '&year='+encodeURIComponent(form.year.value);
     ret = serverFunction(url);
     var url = 'modules.php?mod=adminvideoro';
     displayText('maincontent',url);
}


function aro_deleteDocument(docid)
{
     if (confirm('Are you sure you want to delete this video?'))
          {
          var url = 'modules.php?mod=adminvideoro&req=delete&id='+docid;
          var ret = serverFunction(url);
          var url = 'modules.php?mod=adminvideoro';
          displayText('maincontent',url);
          }
     return false;
}


function aro_archiveDocument(docid)
{
     if (confirm('Are you sure you want to archive this video?'))
          {
          var url = 'modules.php?mod=adminvideoro&req=archive&id='+docid;
          serverFunction(url);
          var url = 'modules.php?mod=adminvideoro';
          displayText('maincontent',url);
          }
     return false;
}


//function stopDocumentUpload(success,path,tmp) is in functions.js

function aro_validateDocumentForm(form)
{
     var error_message = "The following errors occurred:\n";
     var errors=0;
     if (isEmpty(form.title))
          {
          error_message = error_message + "\t\ntitle is missing";
          errors=1;
          }
     if (isEmpty(form.vtitle))
          {
          error_message = error_message + "\t\nViewer title is missing";
          errors=1;
          }
     if (isEmpty(form.vdescript))
          {
          error_message = error_message + "\t\nViewer description is missing";
          errors=1;
          }
     if (isEmpty(form.vsURL))
          {
          error_message = error_message + "\t\nVideo Source URL is missing";
          errors=1;
          }
     if (isEmpty(form.synopsis))
          {
          error_message = error_message + "\t\nsynopsis is missing";
          errors=1;
          }
     if (isEmpty(form.description))
          {
          error_message = error_message + "\t\ndescription is missing";
          errors=1;
          }
     if (isEmpty(form.month))
          {
          error_message = error_message + "\t\nmonth is missing";
          errors=1;
          }
     if (isEmpty(form.year))
          {
          error_message = error_message + "\t\nyear is missing";
          errors=1;
          }

/*
     if (docname != '0' && docname =='')
          {
          error_message = error_message + "\t\nYou must upload a document";
          errors=1;
          }
*/
     if (errors==0)
          return true;
     alert(error_message);
     return false; 



}

