// offline code
var google_db;
var store;
// based on http://code.google.com/apis/gears/samples/hello_world_database.html
function switchOffline() {
  if (!window.google || !google.gears) {
    alert("You must install Google Gears first.");
    return;
  }

	// load offline files
	var localServer = google.gears.factory.create('beta.localserver');
	// store = localServer.createManagedStore('test-store' + Math.floor(Math.random() * 1024));		// force reload
	store = localServer.createManagedStore('ticketsf-store');		// force reload
	store.manifestUrl = '/symfony/ticket-symfony/web/user/manifest/1';

	store.checkForUpdate();

	var timerId = window.setInterval(function() {
	// When the currentVersion property has a value, all of the resources
	// listed in the manifest file for that version are captured. There is
	// an open bug to surface this state change as an event.
		if (store.currentVersion) {
		  window.clearInterval(timerId);
		  textOut("The documents are now available offline.\n" +
				  "With your browser offline, load the document at " +
				  "its normal online URL to see the locally stored " +
						"version. The version stored is: " +
				  store.currentVersion);
		} else if (store.updateStatus == 3) {
		  textOut("Error: " + store.lastErrorMessage);
		}
	}, 500);

}

function textOut(s) {
 var elm = document.getElementById("textOut");


  while (elm.firstChild) {
    elm.removeChild(elm.firstChild);
  }
  elm.appendChild(document.createTextNode(s));
}
