﻿// JQuery Ajax JScript File

function AjaxCall_TB_toDiv(_type, _url, _data, _successTarget, _errorTarget) {
        $.ajax({
                type: _type,
                url: _url,
                data: _data,
                beforeSend:function(){  
                /* 
                 *   If you need to run a function right before the ajax 
                 *   call is made, then it goes here. 
                 */
                 showProgress(true);
                },
                error:function(msg,error){
                 /* 
                  *   This fires at the end of an unsuccessful ajax call 
                  *   Please note that a ASPX error will not cause this 
                  *   callback function to fire. As far as javascript is 
                  *   concerned, any text returned means success. 
                  */  
                    if(msg)
                        { 
                           // alert(msg);
                           $(_errorTarget).html(msg);
                        }  
                    else{ alert(error); }
                    
                },
                success: function(msg,status){
                 /* 
                  *   This callback function fires at the end of 
                  *   a successful ajax call. The following line 
                  *   of code will output whatever content was printed 
                  *   from ASPX to a div with the ID of 'content'. 
                  */  
                  if(msg == "transaction failed!") // FAILED!
                  { 
                      //Show error div
                      $(_errorTarget).show();
                  }
                  else // SUCCESS?
                  {
                    $(_successTarget).html(msg);
                                    
                    // Closes Thickbox window
                    //tb_remove(); 
                  }
                },
                complete:function(msg){ 
                 /* 
                  *   This fires after success and error are done 
                  *   no matter what the outcome of the ajax call.
                  */ 
                }
                
          }); //.ajax utility ends here

} //AjaxCall_toDiv function ends

function AjaxCall_toHiddenElement(_type, _url, _data, _Target, _errorTarget) {
        $.ajax({
                type: _type,
                url: _url,
                data: _data,
                beforeSend:function(){  
                /* 
                 *   If you need to run a function right before the ajax 
                 *   call is made, then it goes here. 
                 */
                 showProgress(true);
                },
                error:function(msg,error){
                 /* 
                  *   This fires at the end of an unsuccessful ajax call 
                  *   Please note that a ASPX error will not cause this 
                  *   callback function to fire. As far as javascript is 
                  *   concerned, any text returned means success. 
                  */  
                    if(msg)
                        { 
                           // alert(msg);
                           $(_errorTarget).html(msg);
                        }  
                    else{ alert(error); }
                    
                },
                success: function(msg,status){
                 /* 
                  *   This callback function fires at the end of 
                  *   a successful ajax call. The following line 
                  *   of code will output whatever content was printed 
                  *   from ASPX to a div with the ID of 'content'. 
                  */  
                  if(msg == "transaction failed!") // FAILED!
                  { 
                      //Show error div
                      $(_errorTarget).show();
                  }
                  else // SUCCESS?
                  {
                      document.getElementById(_Target).value = msg;
                      
                  }
                },
                complete:function(msg){ 
                 /* 
                  *   This fires after success and error are done 
                  *   no matter what the outcome of the ajax call.
                  */ 
                }
                
          }); //.ajax utility ends here

} //AjaxCall_toDiv function ends

function AjaxCall_toDiv(_type, _url, _data, _successTarget, _errorTarget) {
        $.ajax({
                type: _type,
                url: _url,
                data: _data,
                beforeSend:function(){  
                /* 
                 *   If you need to run a function right before the ajax 
                 *   call is made, then it goes here. 
                 */
                 showProgress(true);
                },
                error:function(msg,error){
                 /* 
                  *   This fires at the end of an unsuccessful ajax call 
                  *   Please note that a ASPX error will not cause this 
                  *   callback function to fire. As far as javascript is 
                  *   concerned, any text returned means success. 
                  */  
                    if(msg)
                        { 
                           // alert(msg);
                           $(_errorTarget).html(msg);
                        }  
                    else{ alert(error); }
                    
                },
                success: function(msg,status){
                 /* 
                  *   This callback function fires at the end of 
                  *   a successful ajax call. The following line 
                  *   of code will output whatever content was printed 
                  *   from ASPX to a div with the ID of 'content'. 
                  */  
                  if(msg == "transaction failed!") // FAILED!
                  { 
                      //Show error div
                      $(_errorTarget).show();
                  }
                  else // SUCCESS?
                  {
                    $(_successTarget).html(msg);
                                    
                    // Closes Thickbox window
                    //tb_remove(); 
                  }
                },
                complete:function(msg){ 
                 /* 
                  *   This fires after success and error are done 
                  *   no matter what the outcome of the ajax call.
                  */ 
                }
                
          }); //.ajax utility ends here

} //AjaxCall_toDiv function ends

function AjaxCall_toUrl(_type, _url, _data, _successTarget, _errorTarget) {
        $.ajax({
                type: _type,
                url: _url,
                data: _data,
                beforeSend:function(){  
                /* 
                 *   If you need to run a function right before the ajax 
                 *   call is made, then it goes here. 
                 */
                 showProgress(true);
                },
                error:function(msg,error){
                 /* 
                  *   This fires at the end of an unsuccessful ajax call 
                  *   Please note that a ASPX error will not cause this 
                  *   callback function to fire. As far as javascript is 
                  *   concerned, any text returned means success. 
                  */  
                    if(msg)
                        { 
                           // alert(msg);
                           $(_errorTarget).html(msg);
                        }  
                    else{ alert(error); }
                    
                },
                success: function(msg,status){
                 /* 
                  *   This callback function fires at the end of 
                  *   a successful ajax call. The following line 
                  *   of code will output whatever content was printed 
                  *   from ASPX to a div with the ID of 'content'. 
                  */  
                  if(msg == "transaction failed!") //FAILED!
                  { 
                      var login_response = msg;
                      
                      //Show error div
                      $(_errorTarget).show();
                  }
                  else // SUCCESS
                  {                    
                      window.location.href = _successTarget;           
                  }
                },
                complete:function(msg){ 
                 /* 
                  *   This fires after success and error are done 
                  *   no matter what the outcome of the ajax call.
                  */ 
                }
                
          }); //.ajax utility ends here

} //AjaxCall_toUrl function ends
