

$(document).ready(function()
{
	
	var selFirstChild = $(SedForm.getRootHtmlElem()).children().first();
	// we need this as a hack to push the upcoming buttons below a "click-shadow-zone" that prevents buttons being clicked in Chrome
	// I suspect this is a Chrome bug; altogether the shadow zone remains a mystery
	//selFirstChild.before("<h6/>")
	selFirstChild.before("<button onclick='Test.onClickGetFormData()'>Read Form Data</button>");
	selFirstChild.before("<button onclick='Test.onClickGetFormDataFull()'>Read Full Form Data</button>");
	selFirstChild.before("<button onclick='Test.onClickClearForm()'>Clear Form </button>");
	selFirstChild.before("<button onclick='Test.onClickWriteData()'>Write Form Data</button>");
	selFirstChild.before("<button onclick='Test.onValidate()'>Validate</button>");
	selFirstChild.before("<button onclick='Test.onInjectJson()'>Inject JSON text</button>");
	selFirstChild.before("<button onclick='Test.onPrintItemTree()'>Print Item Tree</button>");

});




function Test()
{
	// we need this solely for eclipse outline to put everything under Test, 
	// otherwise we would have two items in the outline
	this._dummy = null;
}

var FORM_JSON = null;


Test.onClickGetFormData = function()
{
	FORM_JSON = SedForm.readData();
	console.log(FORM_JSON);
}

Test.onClickGetFormDataFull = function()
{
	FORM_JSON = SedForm.readDataFull();
	console.log(FORM_JSON);
}

Test.onClickClearForm = function()
{
	var rootItem = Item.getGlobal();
	rootItem.navigateTree(new VisitorClearData());
}

Test.onClickWriteData = function()
{
	SedForm.writeData(FORM_JSON);
}

Test.onPrintItemTree = function(){
	var sItemTree = SedForm.itemTreeToString();
	console.log(sItemTree);
}

Test.onValidate = function(){
	var sErrorMsg = SedForm.validate();
	if (sErrorMsg == null)
		console.log("Data is OK");
	else
		console.log(sErrorMsg);
}

Test.onInjectJson = function()
{
	var sJson = prompt("Please enter your JSON text");
	if(sJson != null){
		SedForm.writeData(sJson);
	}
	FORM_JSON = sJson;
}