/**************************************************
Joshua K Roberson - 02-23-2008 - v1
Setup AJAX events to process and/or return a result
to the unique id containers. Also, do pre-processing 
of forms to check required fields.
PARAMETERS:
event - events to trigger rewrite of unique container info
ths - form object passed using 'this'; OPTIONAL
EXAMPLE USAGE:
myAjaxProcess('checkLogin');
<form action="#" method="POST" onsubmit="return myAjaxProcess('login', this);">
**************************************************/
function myAjaxProcess() {
  if(typeof(arguments[1])=='object') {
    ths = arguments[1];
  } else {
    ths = '';
  }

  switch(arguments[0]) {
    case 'loadLogin':
      myAjax('/ajax/checkLogin', 'GET', ths, 'ajax_login');
      break;
    case 'login':
      if(preSubmit(ths)==true) { // pre-processing
        myAjax('/ajax/login', 'POST', ths, 'ajax_login');
      }
      break;
    case 'logout':
      myAjax('/ajax/logout', 'GET', ths, 'ajax_login');
      break;

    case 'loadLoginMini':
      myAjax('/ajax/checkLoginMini', 'GET', ths, 'ajax_loginMini');
      break;
    case 'loginMini':
      if(preSubmit(ths)==true) { // pre-processing
        myAjax('/ajax/loginMini', 'POST', ths, 'ajax_loginMini');
      }
      break;
    case 'logoutMini':
      myAjax('/ajax/logoutMini', 'GET', ths, 'ajax_loginMini');
      break;

    case 'login_form':
      if(preSubmit(ths)==true) { // pre-processing
        myAjax('/ajax/loginform', 'POST', ths, 'login_form');
      }
      break;
    case 'loadFeedback':
      myAjax('/ajax/loadFeedback', 'GET', ths, 'ajax_feedback');
      break;
    case 'feedback':
      if(preSubmit(ths)==true) { // pre-processing
        myAjax('/ajax/feedback', 'POST', ths, 'ajax_feedback');
      }
      break;


    case 'loadMostPopular':
      myAjax('/ajax/loadMostPopular', 'GET', ths, 'most1');
      break;
    case 'loadMostEmailed':
      myAjax('/ajax/loadMostEmailed', 'GET', ths, 'most2');
      break;
    case 'loadTopSearch':
      myAjax('/ajax/loadTopSearch', 'GET', ths, 'most3');
      break;


    case 'forgotUsername':  
      myAjax('/ajax/forgotUsername', 'POST', ths, 'ajax_login');
      break;
    case 'forgotPassword':  
      if(document.getElementById("emailEnterForm").value == ""){
	alert('Please enter your E-Mail address into the E-Mail box');
	return false;
      }
      myAjax('/ajax/forgotPassword', 'POST', ths, 'ajax_login');
      break;
    default:
      alert('Error loading AJAX with non-existent event: ' + event);
      break;
  }
  return false;
}
