var db;

// Open this page's local database.
function init() {
  if (!window.google || !google.gears) {
    return;
  }

  try {
    db = google.gears.factory.create('beta.database', '1.0');
  } catch (ex) {
    alert('Could not connect to GoogleGears database: ' + ex.message);
  }

  return true;
}

function runZSql() {
	sql = $('z-sql').value;	
	b = Gearshift.execSql(sql);
	if(b.success) {
		alert("OK");
	} else {
		alert("Failed: " + b.message);
	}
}


window.addEvent("domready", function() {
	if(!init()) {
		window.location = "no-gears.html";
		return false;
	}
	
	db.open("com.pftqg.testing");
	Gearshift.init(db, true);	
	
	$('kill-db').addEvent('click', function() { Gearshift.migrateTo(0); });
	
	
	
	zt = new PDTable({table: 'ztable', skeleton: 'ztable-s', sticky: ['ztable-h'] });
	zt.clear();
	
	people = Gearshift.execSql("SELECT * FROM demo_table ORDER BY name ASC");
	if(people.success) {
		$A(people.data).each(function(a){
			zt.addRow({ id: 'moo-' + a.id, values: a});
		});
	} else {
		alert("Couldn't get sample data");
	}	
	
});