function aj(div,url,queryString) {
   $.ajax({
      type: "GET",
      url: url,
      data: queryString,
      success: function(message) {
         $('#'+div).html(message);
      },
      error: function (xhr, ajaxOptions, thrownError){
         alert(xhr.status+': \''+url+'\' '+xhr.statusText);
      }
   });
}

function aj_form_post(f,url){
   var qryString = $('#'+f).serialize();
   $.ajax({
      type: "POST",
      url: url,
      data: qryString,
      success: function(message) {
         var arr = message.split(":");

         if(message=="1"){$('#dialog-form').dialog( "close" );}   // Backwards compatible...

         else if(arr[0]=="CLOSE"){$('#dialog-form').dialog( "close" );}
         else if(arr[0]=="REDIR"){window.location=arr[1];}

         else if(arr[0]=="SUCCESS"){alert(arr[1]);}
         else if(arr[0]=="SUCCESS-RELOAD"){alert(arr[1]);$('#dialog-form').dialog("close");aj(arr[2],arr[3],arr[4]);}
         else if(arr[0]=="SUCCESS-REDIR"){window.location=arr[1];}
         else if(arr[0]=="SUCCESS-CLOSE"){alert(arr[1]);$('#dialog-form').dialog( "close" );}
         else if(arr[0]=="SUCCESS-SUBMIT-REFERENCE"){ $('#REFERENCE').val(arr[1]); $('#'+f).submit(); }
         else if(arr[0]=="SUCCESS-SUBMIT"){$('#'+f).submit();}

         else if(arr[0]=="ERROR"){alert(arr[1]);}
         else if(arr[0]=="ERROR-RELOAD"){alert(arr[1]);aj('dialog-form',url,queryString);}
         else if(arr[0]=="ERROR-CLOSE"){alert(arr[1]);$('#dialog-form').dialog( "close" );}

         else {
            alert(message);
         }
      },
      error: function (xhr, ajaxOptions, thrownError){
         alert(xhr.status+': '+xhr.statusText+'\n'+URL);
      }
   });
}

