dojo.require("dojox.json.ref");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dojo.data.ItemFileWriteStore");

	
function dojo_query_mysql(query_string, db_name, username, password, host) {
  //The parameters to pass to xhrPost, the message, and the url to send it to
  //Also, how to handle the return and callbacks.
  var stored_data = null;
  var total_string = query_string+"\&"+db_name+"\&"+username+"\&"+password + "\&"+host;
  var raw_data = new Object;
  var xhrArgs = {
  url: location.protocol + "//"+location.host+"/js/tools/query.php",
  sync:true,
  postData: total_string,
  handleAs: "text",
  load: function(data) { 
    if(data == "") return;
      raw_data = dojo.fromJson(data);
      stored_data = new dojo.data.ItemFileReadStore({data: raw_data});
      //console.log(stored_data);
   },
  error: function(error) {
      //We'll 404 in the demo, but that's okay.  We don't have a 'postIt' service on the
      //docs server.
      //stored_data = error;
    }
  }
  //Call the asynchronous xhrPost
  var deferred = dojo.xhrPost(xhrArgs);
  //console.log(stored_data);
  return stored_data;
}

function dojo_query_mysql_w(query_string, db_name, username, password, host) {
  //The parameters to pass to xhrPost, the message, and the url to send it to
  //Also, how to handle the return and callbacks.
  var stored_data = null;
  var total_string = query_string+"\&"+db_name+"\&"+username+"\&"+password + "\&"+host;
  var raw_data = new Object;
  var xhrArgs = {
  url: location.protocol + "//"+location.host+"/js/tools/query.php",
  sync:true,
  postData: total_string,
  handleAs: "text",
  load: function(data) {
    if (data == null )
        return;
      raw_data = dojo.fromJson(data);
      stored_data = new dojo.data.ItemFileWriteStore({data: raw_data});
      //console.log(stored_data);
   },
  error: function(error) {
      //We'll 404 in the demo, but that's okay.  We don't have a 'postIt' service on the
      //docs server.
      //stored_data = error;
    }
  }
  //Call the asynchronous xhrPost
  var deferred = dojo.xhrPost(xhrArgs);
  //console.log(stored_data);
  return stored_data;
}

function dojo_query_mysql(query_string) {
  //The parameters to pass to xhrPost, the message, and the url to send it to
  //Also, how to handle the return and callbacks.
  var stored_data = null;
  var total_string = query_string;
  var raw_data = new Object;
  var xhrArgs = {
  url: location.protocol + "//"+location.host+"/js/tools/query.php",
  sync:true,
  postData: total_string,
  handleAs: "text",
  load: function(data) { 
    if(data == "") return;
      raw_data = dojo.fromJson(data);
      stored_data = new dojo.data.ItemFileReadStore({data: raw_data});
      //console.log(stored_data);
   },
  error: function(error) {
      //We'll 404 in the demo, but that's okay.  We don't have a 'postIt' service on the
      //docs server.
      //stored_data = error;
    }
  }
  //Call the asynchronous xhrPost
  var deferred = dojo.xhrPost(xhrArgs);
  //console.log(stored_data);
  return stored_data;
}

function dojo_query_mysql_w(query_string) {
  //The parameters to pass to xhrPost, the message, and the url to send it to
  //Also, how to handle the return and callbacks.
  var stored_data = null;
  var total_string = query_string;
  var raw_data = new Object;
  var xhrArgs = {
  url: location.protocol + "//"+location.host+"/js/tools/query.php",
  sync:true,
  postData: total_string,
  handleAs: "text",
  load: function(data) {
    if (data == null )
        return;
      raw_data = dojo.fromJson(data);
      stored_data = new dojo.data.ItemFileWriteStore({data: raw_data});
      //console.log(stored_data);
   },
  error: function(error) {
      //We'll 404 in the demo, but that's okay.  We don't have a 'postIt' service on the
      //docs server.
      //stored_data = error;
    }
  }
  //Call the asynchronous xhrPost
  var deferred = dojo.xhrPost(xhrArgs);
  //console.log(stored_data);
  return stored_data;
}


