if (typeof(jQuery)!='undefined'){
  $(document).ready(function() {
    //alert('jq');
  })
  
  function ajaxFileUpload()
  {
      //starting setting some animation when the ajax starts and completes
      $("#loading")
      .ajaxStart(function(){
          $(this).show();
      })
      .ajaxComplete(function(){
          $(this).hide();
      });
      
      /*
          prepareing ajax file upload
          url: the url of script file handling the uploaded files
                      fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
          dataType: it support json, xml
          secureuri:use secure protocol
          success: call back function when the ajax complete
          error: callback function when the ajax failed
          
              */
      $.ajaxFileUpload
      (
          {
              url:'exec/doAjaxFileUpload.php', 
              secureuri:false,
              fileElementId:'fileToUpload',
              dataType: 'json', // change to xml to print results
              success: function (data, status)
              {
                //alert(data.body.innerHTML);
                  if(typeof(data.error) != 'undefined')
                  {
                      /*
                      if(data.fileExt != '') {
                        alert(data.fileExt);
                      }
                      */
                      if(data.error != '')
                      {
                          alert(data.error);
                      }else
                      {
                          alert(data.msg);
                          //alert(data);
                      }
                  }
              },
              error: function (data, status, e)
              {
                  //alert('error data: '+data.body.innerHTML);
                  alert('error:'+e);
              }
          }
      )
      
      return false;

  } 
}

    
