// FetchJS: DecodedRequestString=appmod=kernel:formgrid 
// -------------------------------------------------------------------------
// JSFile appmod_kernel_stdlib, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------
String.trim = function String$trim(strValue) {
    /// <summary locid="M:J#String.trim" />
    /// <returns type="String"></returns>
    return strValue.replace(/^\s+|\s+$/g, '');
}
String.prototype.startsWith = function(value, ignoreCase)
{
    /// <summary">Determines whether the beginning of this string matches the specified string.</summary>
    /// <param name"value" type="String"> </param>
    /// <param name"ignoreCase" type="Boolean">Optional. true to ignore case when comparing, false if not.</param>
    /// <returns type="Boolean">true when the specified value matches the beginning, false if not.</returns>

    if (ignoreCase==false) 
        return (value == this.substring(0, value.length)); 
    else 
        return (value.toLowerCase() == this.substring(0, value.length).toLowerCase()); 
}

String.prototype.endsWith = function(value, ignoreCase) 
{ 
    /// <summary">Determines whether the end of this string matches the specified string.</summary>
    /// <param name"value" type="String"> </param>
    /// <param name"ignoreCase" type="Boolean">Optional. true to ignore case when comparing, false if not.</param>
    /// <returns type="Boolean">true when the specified value matches the end, false if not.</returns>
    if (ignoreCase==false) 
        return (value == this.substring(this.length - value.length)); 
    else 
        return (value.toLowerCase() == this.substring(this.length - value.length).toLowerCase()); 
}

function addLoadEvent(func){
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function associateObjWithEvent(obj, methodName){
    /* The returned inner function is intended to act as an event
       handler for a DOM element:-
    */
    return (function(e){
        /* The event object that will have been parsed as the - e -
           parameter on DOM standard browsers is normalised to the IE
           event object if it has not been passed as an argument to the
           event handling inner function:-
        */
        e = e||window.event;
        /* The event handler calls a method of the object - obj - with
           the name held in the string - methodName - passing the now
           normalised event object and a reference to the element to
           which the event handler has been assigned using the - this -
           (which works because the inner function is executed as a
           method of that element because it has been assigned as an
           event handler):-
        */
        return obj[methodName](e, this);
    });
}


function ClassNames(element)
{
    this.element = element;
}
ClassNames.prototype.add = function(className)
{
    this.remove(className);
    if(this.element.className == "")
    {
        this.element.className = className;
    }
    else
    {
        var curClassName = this.element.className;
        curClassName = curClassName + " " + className;
	    this.element.className = curClassName;
	}
}
ClassNames.prototype.remove = function(className)
{
    var cn = " " + this.element.className + " ";
    cn = cn.replace(" "+className+" ", " ");
    cn = cn.replace("  ", " ");
    
    var ts = new TopString(cn);
    ts.allTrim();
	this.element.className = ts.stringValue;
}
ClassNames.prototype.hasClassName = function(className)
{
    var cn = " " + this.element.className + " ";
    className = " "+className+" ";
    if (cn.indexOf(className) > -1)
        return true;
    else
        return false;
}
ClassNames.prototype.clear = function()
{
	this.element.className = "";
}




function TopString(sString)
{
    this.stringValue = sString;
}
TopString.prototype.leftTrim = function() 
{
    var sString = this.stringValue;
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    this.stringValue = sString;
}
TopString.prototype.rightTrim = function()
{
    var sString = this.stringValue;
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    this.stringValue = sString;
}
TopString.prototype.allTrim = function()
{
    var sString = this.stringValue;
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    this.stringValue = sString;
}

function XBrowser() 
{
}
XBrowser.getBrowserWindowSize = function() 
{
    /// <summary>This function returns the Height and the Width of the current browser screen (xBrowser)</summary>
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return { height:myHeight, width:myWidth  };
}





// -------------------------------------------------------------------------
// JSFile appmod_kernel_dom, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------


function DomElement(element) 
{
    this.element = element;
}
DomElement.prototype.removeClassName = function (className)
{
    var cn = " " + this.element.className + " ";
    cn = cn.replace(" "+className+" ", " ");
    cn = cn.replace("  ", " ");

    var ts = new TopString(cn);
    ts.allTrim();
	this.element.className = ts.stringValue;
}
DomElement.prototype.addClassName = function (className)
{
    this.removeClassName(className);
    if(this.element.className == "")
    {
        this.element.className = className;
    }
    else
    {
        var curClassName = this.element.className;
        curClassName = curClassName + " " + className;
	    this.element.className = curClassName;
	}
}
DomElement.prototype.toggleClassName = function(addClassName, removeClassName)
{
    this.removeClassName(removeClassName);
    this.addClassName(addClassName);
}
DomElement.prototype.clearClassNames = function (className)
{
	this.element.className = "";
}
DomElement.prototype.hasClassName = function (className)
{
    var cn = " " + this.element.className + " ";
    className = " "+className+" ";
    if (cn.indexOf(className) > -1)
        return true;
    else
        return false;
}
DomElement.prototype.hasClassNames = function (classNames)
{
    /// <summary>Checks whether the element has the specified classnames.</summary>
    /// <param name="classNames" type="String">classNames contains the names of the classes to check, seperated by a space.</param>
    /// <returns type="Boolean">Returns true or false.</returns>
   var names = classNames.toString().split(" ");
   for(var i=0 ; i<names.length; i++)
   {
        if(!this.hasClassName(names[i]))
            { return false; }
   }
   return true;
}
DomElement.prototype.hide = function() {
    this.addClassName('hide');
}
DomElement.prototype.unHide = function() {
    this.removeClassName('hide');
}

DomElement.prototype.hasTag = function (tagName)
{
    if(this.element.nodeName == tagName) return true;
    return false;
}
DomElement.prototype.hasName = function (nameValue)
{
    if(this.element.name)
    {
        if(this.element.name == nameValue) return true;
        return false;
    }
    if(this.element.attributes)
    {
        var attrNode = this.element.attributes["name"];
        var attrNodeTest = this.element.attributes["namesssss"];
        if(attrNode != undefined)
        {
            var name = attrNode.nodeValue;
            if(name == nameValue) return true;
            
        }
        return false;
    }
    return false;    
}
DomElement.prototype.hasId = function (idValue)
{
debugger;
    if(this.element.id == idValue) return true;
    return false;
}
DomElement.prototype.getId = function() {
    return this.element.id;
}
DomElement.prototype.getName = function() {
    return this.element.name;
}
DomElement.prototype.removeNode = function()
{
    if(this.element != null)
    {
        var parentNode = this.element.parentNode;
        parentNode.removeChild(this.element);
        return true;
    }
    return false;
}
DomElement.prototype.setReadOnly = function(isReadOnly, isDisabled) {
    if ((this.element.nodeName == "INPUT") || (this.element.nodeName == "TEXTAREA")) {
        if (this.element.nodeType == 1) {
            this.element.readOnly = isReadOnly;
            if (isDisabled != undefined) {
                this.element.disabled = isDisabled;
            }
            return true;
        }
    }
    return false;
}
DomElement.prototype.isReadOnly = function() {
    if ((this.element.nodeName == "INPUT") || (this.element.nodeName == "TEXTAREA")) {
        if (this.element.nodeType == 1) {
            return this.element.readOnly;
        }
    }
    return false;
}
DomElement.prototype.isDisabled = function() {
    if ((this.element.nodeName == "INPUT") || (this.element.nodeName == "TEXTAREA")) {
        if (this.element.nodeType == 1) {
            return this.element.disabled;
        }
    }
    return false;
}

DomElement.prototype.setAttribute = function(attrName, attrValue)
{
    this.element.setAttribute(attrName, attrValue);
}
DomElement.prototype.getAttribute = function(attrName)
{
    debugger;
    // use the getAttributeValue instead!!!!
    return this.element.getAttribute(attrName);
}
DomElement.prototype.getAttributeValue = function(attrName, defaultValue)
{
    /// <summary>Returns the value of the names attribute. If the attribute did not exist, the defaultValue is returned.</summary>
    var attrValue = this.element.getAttribute(attrName);
    if(attrValue == null) return defaultValue;
    return attrValue;
}
DomElement.prototype.removeAttribute = function(attrName)
{
    this.element.removeAttribute(attrName);
}


DomElement.prototype.getChildNode = function(childNodeIndex)
{
    /// <summary>Gets an a childnode and returns it as a DomElement type.</summary>
    /// <param name="childNodeIndex" >Index of the childNode, normally an integer value indicating an element in a zero based index.</param>
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return new DomElement(this.element.childNodes[childNodeIndex]);
}
DomElement.prototype.getChildNodeCount = function()
{
    return this.element.childNodes.length;
}
DomElement.prototype.getFirstChildNode= function()
{
    /// <summary>Gets the first childnode and returns it as a DomElement type.</summary>
    /// <returns type="DomElement">Returns a DomElement, or null if no childNode existed.</returns>
    if(this.element.childNodes.length < 1) return null;
    return this.element.childNodes[0];
}
DomElement.prototype.getLastChildNode= function()
{
    /// <summary>Gets the last childnode and returns it as a DomElement type.</summary>
    /// <returns type="DomElement">Returns a DomElement, or null if no childNode existed.</returns>
    debugger;
    var len = this.element.childNodes.length;
    if(len < 1) return null;
    return this.element.childNodes[len-1];
}

DomElement.prototype.getInnerText = function()
{
    /// <summary>Gets the innerText of the element (Use with objects: Div, A, Hn, P ...).</summary>
    /// <returns type="String">Returns a String.</returns>
    if(this.element.innerText != undefined)
    {
        return new String(this.element.innerText);
    }
    if(this.element.innerHTML != undefined)
    {
        return new String(this.element.innerHTML);
    }
    return null;
}
DomElement.prototype.setInnerText = function(text)
{
    /// <summary>Sets the innerText of the element (Use with objects: Div, A, Hn ...).</summary>
    /// <param name="text" >New innertext for the element.</param>
    /// <returns type="void">Returns nothing.</returns>
    if(this.element.innerText != undefined)
    {
        this.element.innerText = text;
        return;
    }
    if(this.element.innerHTML != undefined)
    {
        this.element.innerHTML = text;
        return;
    }
}
DomElement.prototype.getValueAsString = function()
{
    /// <summary>Gets the Value of the element (Use with objects: Hidden, Text, TextArea, Button).</summary>
    /// <returns type="String">Returns a String.</returns>
    return new String(this.element.value);
}
DomElement.prototype.setValue = function(value)
{
    /// <summary>Sets the value of the element (Use with objects: Hidden, Text, TextArea, Button).</summary>
    /// <param name="value" >New value for the element.</param>
    /// <returns type="void">Returns nothing.</returns>
    this.element.value = value;
}

DomElement.prototype.getNativeElement = function()
{
    /// <summary>Gets the native document.getElementById(id) returnvalue.</summary>
    return this.element;
}
DomElement.prototype.getParent = function()
{
    /// <returns type="DomElement">Returns the parent Element as DomElement..</returns>
    if(this.element.parentNode == null) return null;
    return new DomElement(this.element.parentNode);
}
DomElement.prototype.setStyle = function(styleAttributeName, value) {
    /// <summary>Sets a style aatribute.</summary>
    /// <param name="styleAttributeName" >Name of the styleattribute as a string, examples: top, left, right, bottom, width, height ...</param>
    /// <param name="value" >The value to be assigned to the style attribute.</param>
    /// <returns type="void">Returns nothing.</returns>
    switch (styleAttributeName) {
        case "top": this.element.style.top = value + "px"; break;
        case "left": this.element.style.left = value + "px"; break;
        case "width": this.element.style.width = value + "px"; break;
        case "height": this.element.style.height = value + "px"; break;
        case "color": this.element.style.color = value; break;
        case "fontStyle": this.element.style.fontStyle = value; break;
        default:
            break;
    }
}   
DomElement.prototype.getElementSize = function()
{
    /// <summary>This function returns the Height and the Width of the specified element (xBrowser)</summary>
  var myWidth = 0, myHeight = 0;
  if( typeof( this.element.innerWidth ) == 'number' ) 
  {
    //Non-IE
    myWidth = this.element.innerWidth;
    myHeight = this.element.innerHeight;
  }
  else
  {
    if( typeof( this.element.clientWidth ) == 'number' ) 
    {
        //IE7
        myWidth = this.element.clientWidth;
        myHeight = this.element.clientHeight;
    }
  }
  
  return { height:myHeight, width:myWidth  };
}

DomElement.prototype.isChildOf = function(currentElement)
{
    var parent = this;
    var nativeElement = null;
    while(true)
    {   
        parent = parent.getParent();
        if(parent == null) return false;
        nativeElement = parent.getNativeElement();
        
        
        if(nativeElement == currentElement)
        {
            return true;
        }
    }
    return false;
}

DomElement.prototype.getPagePosition = function()
{
    var el = this.element;
    
    var leftX = el.offsetLeft;
	var topY  = el.offsetTop;

	while (el.offsetParent){
		el     = el.offsetParent;
		leftX += el.offsetLeft;
		topY  += el.offsetTop;
	}
    
    return { y:topY, x:leftX};
}
DomElement.prototype.deSelect = function() {
    if (document.selection)
        document.selection.empty();
    else
        if (window.getSelection)
        window.getSelection().removeAllRanges();
}

DomElement.prototype.selectAll = function() {
    this.deSelect();
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(this.element);
        range.select();
    }
    else if (window.getSelection) {
        var range = document.createRange();
        range.selectNode(this.element);
        window.getSelection().addRange(range);
    }
}


function $(el)
{
    /// <summary>Gets an element using the document.getElementById method, and returns it as a DomElement type.</summary>
    /// <param name="el" >Id of an element in the DOM.</param>
    /// <returns type="DomElement">Returns a DomElement.</returns>
    
    if(el == null) return null;
    if ( el instanceof DomElement) return el;

    switch(typeof(el))
    {
    case "string":
        var e = document.getElementById(el);
        if(e == null) return null;
        return new DomElement(e);
    case "DomElement":
        debugger;
        return el;
    case "undefined":
        return null;
    case "object": //  Could very well be a valid element. Check it with a trick.
        if((el.nodeType) && (el.nodeType == 1))
            return new DomElement(el);
        else
            return null;
    default:
        // Need some code to see if it is a valid dom object, and thus we're only performing a valid typecast.
        return new DomElement(el);
    }
}


//function $Form(formId){
//    /// <summary>Gets a form element, using $() and returns an FormElement.</summary>
//    /// <param name="formId">Id of a form, a form element, or a child element of the form.</param>
//    /// <returns type="FormElement">Returns a FormElement.</returns>
//    return $(divId);
//}

function $Div(divId){
    /// <summary>Gets an element using $() and returns an IDivElement.</summary>
    /// <param name="divId">Id of a div element.</param>
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(divId);
}
function $Hidden(hiddenId){
    /// <summary>Gets an element using $() and returns an IHiddenElement.</summary>
    /// <param name="hiddenId">Id of a INPUT-Hidden element.</param>
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(hiddenId);
}
function $Table(tableId){
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(divId);
}
function $Anchor(anchorId){
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(divId);
}
function $Text(textId){
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(textId);
}
function $TextArea(textAreaId){
    /// <returns type="DomElement">Returns a DomElement.</returns>
    return $(textAreaId);
}


// -------------------------------------------------------------------------
// JSFile appmod_kernel_domnavigator, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------
function DomNavigator(filterString)
{
    this.filterItems = this.parseFilterString(filterString);
}

DomNavigator.prototype.parseFilterString = function(filterString)
{

    var filterItems = new Array();
    var nvItems = filterString.split(";");
    var nvItem ;
    for(var i =0; i< nvItems.length; i++)
    {
        nvItem = nvItems[i].split("=");
        filterItems.push({ attribute: nvItem[0], value: nvItem[1] });
    }
    return filterItems;
}
DomNavigator.prototype.isMatch = function(element)
{
    var value;
    for(var i = 0 ; i<this.filterItems.length; i++)
    {
        value = this.filterItems[i].value;
        switch(this.filterItems[i].attribute)
        {
        case "tag": 
            if(element.hasTag(value) != true) return false;
            break;
        case "class": 
            if(element.hasClassName(value) != true) return false;
            break;
        case "name": 
            if(element.hasName(value) != true) return false;
            break;
        case "id": 
            if(element.hasId(value) != true) return false;
            break;
        default:
            return false;
        }
    }
    return true;
}

DomNavigator.prototype.findNodeDownTree = function(startElement, includeStartElement)
{
    /// <param name="startElement" type="DomElement">Element where the downtree search should start.</param>
    /// <param name="includeStartElement" type="Boolean">Should the specified element als be checked for a match, or only the children?</param>
    if(includeStartElement == true)
        if (this.isMatch(startElement)) return startElement;
    
    var len = startElement.getChildNodeCount();
    var resNode;
    for(var i=0 ; i<len;i++)
    {
        resNode = startElement.getChildNode(i);
        if(this.isMatch(resNode)) return resNode;

        resNode = this.findNodeDownTree(resNode, false);
        if(resNode != null) return resNode;
    }
    return null;
}
DomNavigator.prototype.findNodeUpTree = function(startElement, includeStartElement)
{
    /// <param name="startElement" type="DomElement">Element where the downtree search should start.</param>
    /// <param name="includeStartElement" type="Boolean">Should the specified element als be checked for a match, or only the children?</param>
    if(includeStartElement == true)
        if(this.isMatch(startElement)) return startElement;

    var parent = startElement.getParent();
    while (parent != null)
    {
        if(this.isMatch(parent)) return parent;
        parent = parent.getParent();
    }
    return null;
}

function $up(startElement, filterString, includeStartElement)
{
    /// <summary>Gets the element, and then move up in the DOm tree until it meets a parent element which fits the specification.</summary>
    /// <param name="startElement" >Id/element which functions as starting point for finding the desired DomElement.</param>
    /// <param name="filterString" type="String">The filter contains the element specification. Format: attribute=value;attribute=value; ... Attributevalues: tag, class. WARNING: TagName values should be UPPERCASE.</param>
    /// <param name="includeStartElement" type="Boolean" >If true, the search includes the startElement. If false, the startElement is not included in the search.</param>
    /// <returns type="DomElement">Returns a DomElement, or null if not found.</returns>
    var nv = new DomNavigator(filterString);
    return nv.findNodeUpTree($(startElement), includeStartElement);
}

function $down(startElement, filterString, includeStartElement)
{
    /// <summary>Searches an element in the document tree, which fits the specified filter. The search starts at element el, and continues downwards. The first matching element is returned as a DomElement.</summary>
    /// <param name="startElement" >Id/element which functions as starting point for finding the desired DomElement.</param>
    /// <param name="filterString" type="String">The filter contains the element specification. Format: attribute=value;attribute=value; ... Attributevalues: tag, class.</param>
    /// <param name="includeStartElement" type="Boolean" >If true, the search includes the startElement. If false, the startElement is not included in the search.</param>
    /// <returns type="DomElement">Returns a DomElement, or null if not found.</returns>
   if (includeStartElement != true) includeStartElement = false;
   
    var nv = new DomNavigator(filterString);
    return nv.findNodeDownTree($(startElement), includeStartElement);
}    

// DomElement Extensions
DomElement.prototype.getCurrentForm = function()
{
    /// <summary>Searches the first form control which contains the current element.</summary>
    /// <returns type="DomElement">Returns a Form element, or null if not found.</returns>
    // The Current Form can be detected in 2 ways:
    // 1. The event is generated by an elemen which itself is a field of the form, therefore we can check its 'form' property.
    // 2. We look 'up' in the element tree, in order to find the closest form element.
    
    // Try 1.
    if(this.element != null)
    {
        if(this.element.form != null)
        {
            return $(this.element.form);
        }
    }
    
    // Try 2.
    return $up(this, "tag=FORM", true);
}
DomElement.prototype.getNextSibling = function()
{
    /// <summary>Returns the next sibling, Skips all nodetypes except nodeType Element.</summary>
    /// <returns type="DomElement">Returns a DomElement, or null if not found.</returns>
    var x=this.element.nextSibling;
    while ((x != null) && (x.nodeType!=1))
    {
        x=x.nextSibling;
    }
    return $(x);
}
DomElement.prototype.getPrevSibling = function()
{
    /// <summary>Returns the prev sibling. Skips all nodetypes except nodeType Element</summary>
    /// <returns type="DomElement">Returns a DomElement, or null if not found.</returns>
    var x=this.element.previousSibling;
    while ((x != null) && (x.nodeType!=1))
    {
        x=x.prevSibling;
    }
    return $(x);
}

// -------------------------------------------------------------------------
// JSFile appmod_kernel_datadiv, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------
function DataDiv()
{
    this.dataDiv = null;
    this.parameters = new Object();
}
DataDiv.prototype = {}
DataDiv.prototype.setDataDiv = function(dataDivId)
{
    /// <summary>Set the div of the parent of the actual DataDiv element containing the parameters.</summary>
    /// <param name="dataDivId" >a DomElement which is the parent of the actual div element containing the data.</param>
    /// <returns type="Boolean">Returns true/false if succesfull.</returns>
    this.dataDiv = $down(dataDivId, "class=datadiv", true);
    
    if(this.dataDiv == null) 
        return false;
    else
        return true;
    
}
DataDiv.prototype.getParameters = function()
{
    this.parameters = new Object();

    var dataDivelement = this.dataDiv;

    var dataText = dataDivelement.getInnerText();
    
    var nvpairs = dataText.split(";");
    var len = nvpairs.length;
    for(var i=0;i<len;i++)
    {
        var nv = nvpairs[i].split("=");
        this.parameters[nv[0]] = nv[1];
    }
    return this.parameters;
}

function $DataDiv(elementId)
{
    /// <summary>The DataDiv is a DIV Element, which contains data in the form of a name-value-pairs collection. This method returns a DataDiv object to access these parameters.</summary>
    /// <param name="dataDivId" >An id, element or DomElement of the parent of the datadiv element.</param>
    /// <returns type="DataDiv" />
    // Create DataDiv object.
    var dd = new DataDiv();
    var del = $(elementId);
    if (!dd.setDataDiv(del))
    {
        return null;
    }
    return dd;

}

// -------------------------------------------------------------------------
// JSFile appmod_kernel_messagepanel, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------

function MessagePanel(panelId) {
    

    if(panelId == undefined) return;

    

	this.messagePanelId = panelId;
	this.messagePanelElement = null;
	this.messageText = null;
    this.messageNoField = null;
}
MessagePanel.prototype.messagePanelElement = new DomElement();

MessagePanel.prototype.initMessagePanel = function()
{
    if(!this.messagePanelElement)
    {
        this.messagePanelElement = $(this.messagePanelId);
    }
}
// Click CheckBox
MessagePanel.prototype.addMessage = function(message)
{
    this.initMessagePanel();
    this.incrementCurrentMessageNo();
    
	if(!message) this.messageText = "";
	else
	    this.messageText = message;


	if(!this.messagePanelElement){
		alert('Cannot find message panel ('+this.messagePanelId.toString() +') to display message: '+ this.messageText);
		return;
	}
	
	var spanNode = $down(this.messagePanelElement, "tag=SPAN", false);
    spanNode.setInnerText(this.messageText);
    
    if(this.messageText == "")
    {
        this.messagePanelElement.addClassName("hide");
    }
    else
    {
        this.messagePanelElement.removeClassName("hide");
    }
}
MessagePanel.prototype.addTimeOutMessage = function(message, delayInSeconds)
{
    this.addMessage(message);
    var currentMessageNo = this.getCurrentMessageNo();
    setTimeout("resetMessagePanel('"+this.messagePanelId+"', "+currentMessageNo+");", (delayInSeconds*1000));
}
MessagePanel.prototype.getCurrentMessageNo = function() {
    var msgNoField = $Hidden(this.messagePanelId + "_messageno");
    var curMsgNo = msgNoField.getValueAsString();
    curMsgNo = curMsgNo * 1;
    return curMsgNo;
}
MessagePanel.prototype.incrementCurrentMessageNo = function()
{
    var msgNoField = $Hidden(this.messagePanelId+"_messageno");
    var curMsgNo = msgNoField.getValueAsString();
    curMsgNo = curMsgNo * 1;
    curMsgNo = curMsgNo + 1;
    msgNoField.setValue(curMsgNo);
}

MessagePanel.prototype.resetMessage = function(messageNo)
{
    var curMsgNo = this.getCurrentMessageNo();
    if(messageNo == curMsgNo)
    {
        this.addMessage("");
    }
}


// Helper functions.
function resetMessagePanel(messagePanelId, prevMessageNo)
{
    var mp = new MessagePanel(messagePanelId);
    mp.resetMessage(prevMessageNo);
}

// -------------------------------------------------------------------------
// JSFile appmod_kernel_formgrid, added to repository at: 2010/09/05 09:33:29
// -------------------------------------------------------------------------

function FormGrid(formGrid)
{
    if(formGrid == undefined) return;

    this.formGridElement = formGrid.getNativeElement();
    this.formGrid = formGrid;
    this.formGridId = formGrid.getId();
    this.fieldNamePrefix = this.formGridId +"_";
    this.messagePanel = null;
}
FormGrid.prototype.getFormGridAsDomElement = function()
{
    /// <returns type="DomElement">Returns the FormGrid as a DomElement object.</returns>
    return this.formGrid;
}
FormGrid.prototype.addMessage = function(message)
{
    if(this.messagePanel == null)
    {
        var mpId = this.formGridId + "_msgpanel";
        this.messagePanel = new MessagePanel(mpId);
    }
    this.messagePanel.addMessage(message);
}
FormGrid.prototype.addTimeOutMessage = function(message, delayInSeconds)
{
    if(this.messagePanel == null)
    {
        var mpId = this.formGridId + "_msgpanel";
        this.messagePanel = new MessagePanel(mpId);
    }
    this.messagePanel.addTimeOutMessage(message, delayInSeconds);
}

FormGrid.prototype.setFieldValue = function(fieldName, value)
{
    var fieldId = this.fieldNamePrefix + fieldName;
    var field = $(fieldId);
    if(field == null) return false;
    
    field.setValue(value);
    return true;
}
FormGrid.prototype.getFieldValue = function(fieldName, defaultValue)
{
    var fieldId = this.fieldNamePrefix + fieldName;
    var field = $(fieldId);
    if(field == null) return defaultValue;
    
    return field.getValueAsString();;
}
FormGrid.prototype.setActionUrl = function(url) {
    this.formGrid.action = url;
}
FormGrid.prototype.submit = function() {
    if (this.formGridElement.onsubmit != undefined)
        this.formGridElement.onsubmit();

    this.formGridElement.submit();
}

function $FormGrid(el)
{
    /// <summary>Gets a FormGrid object for the element specified. If the specified element already is a FormGrid, it simply is being returned.</summary>
    /// <param name="el" >Id of an element in the DOM, a DomElement or a ClientWindow.</param>
    /// <returns type="FormGrid">Returns a FormGrid object.</returns>

    if(el instanceof FormGrid) return el;
    var del = $(el);
    if(del == null) return null;
    
    return new FormGrid(del);    
}

