//  Copyright (2010-2013) Cédric Coussinet (cedric.coussinet@nomoseed.net)
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published
//  by the Free Software Foundation, version 2 of the License.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program. If not, see <http://www.gnu.org/licenses/>

function tableView (){
	nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
}

function graphicView (){
	nomoSDK.graphicView (document.getElementsByTagName("textarea")[0].value);
}

function openDatabase (){
	nomoSDK.openDatabase ();
	if (document.getElementsByTagName("svg"))
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
	else
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
}

function addDatabase (){
	nomoSDK.addDatabase ();
	if (document.getElementsByTagName("svg"))
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
	else
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
}

function resetDatabase (){
	nomoSDK.resetDatabase ();
	if (document.getElementsByTagName("svg"))
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
	else
		nomoSDK.tableView (document.getElementsByTagName("textarea")[0].value);
}

function exportView (){
	nomoSDK.exporView ();
}

function action(){}

function init (evt)
{
	document.getElementById("table").onclick = tableView;
	document.getElementById("graphic").onclick = graphicView;
	document.getElementById("export").onclick = exportView;
	document.getElementById("open").onclick = openDatabase;
	document.getElementById("add").onclick = addDatabase;
	document.getElementById("reset").onclick = resetDatabase;
	document.getElementById("table").disabled = "disabled";
	document.getElementById("graphic").disabled = "disabled";
	document.getElementById("export").disabled = "disabled";
	document.getElementById("add").disabled = "disabled";
	document.getElementById("reset").disabled = "disabled";
	var forms = document.getElementsByTagName("form");
	for (i in forms)
	{
		forms[i].action = action;
	}
}

window.onload = init;