function Page () {
	this.bodyOnLoadListener = new Array();
}

Page.prototype.onDelete = function (id)
{
	if (!confirm('Are you sure want to delete this?'))
		return false;
		
	document.myform.xid.value = id;
	document.myform.action.value = 'delete';
	document.myform.submit();
	return true;
}

Page.prototype.onEdit   = function (id) 
{
	document.myform.xid.value    = id;
	document.myform.action.value = 'edit';
	document.myform.submit();	
};
	
Page.prototype.onAdd    = function ()
{
	document.myform.action.value = 'add';
	document.myform.submit();
}

Page.prototype.onSave = function ()
{
	document.myform.action.value = 'save';
	document.myform.submit();
}

Page.prototype.isFormValid = function ()
{
	return true;
}

function doEdit (id)
{
	page.onEdit(id);
}

function doAdd ()
{
	page.onAdd();
}

function doDelete (id)
{
	page.onDelete(id);
}

function doSave ()
{
	if (!page.isFormValid())
	{
		return false;
	}
		
	page.onSave();
	return true;
}

Page.prototype.mMethod = 'POST';
Page.prototype.mPage   = 'home';

Page.prototype.doCancel = function () {
	this.mMethod = 'GET';
	this.doLoadContent(this.mPage, 'cancel');
}

Page.prototype.doLoadContent = function (page, action) {
	if (parent && parent.loadContent) {
		parent.loadContent(page, action, '');
		return;
	}
	
	document.myform.method       = this.mMethod;
	document.myform.action.value = action;
	document.myform.page.value   = page;
	document.myform.submit();
	return;
}

Page.prototype.redirect = function (page) {
    if (parent && parent.redirect) {
        parent.redirect(page);
        return;
    }
    
    window.location = page;
}

Page.prototype.showWaitInfo = function (text) {
    if (parent && parent.showWaitInfo) {
        parent.showWaitInfo(text);
        return;
    }
    
    window.status = text;
}

Page.prototype.hideWaitInfo = function () {
    if (parent && parent.hideWaitInfo) {
        parent.hideWaitInfo();
        return;
    }
    
    window.status = 'Done';
}

Page.prototype.onBodyLoaded = function () {

	this.hideWaitInfo();
	
	for (var i = 0; i < this.bodyOnLoadListener.length; i++) {
		this.bodyOnLoadListener[i]();
	}
}

Page.prototype.addBodyOnLoadListener = function (listener) {
    this.bodyOnLoadListener.push(listener);
}

var sPage = new Page;
var page  = sPage;