

function IWAPI()
{
}

IWAPI._registeredAPIs = new Array();


IWAPI._initObject = function(apiObj,domObj)
{
    var str = "";
    for (i in apiObj)
    {
        domObj[i] = apiObj[i];
    }
}

IWAPI.getVersion = function() 
{
    //It would be nice if we can get this number from the build...
    return "1.0";
}

IWAPI.getRegisteredAPIs = function()
{
    return IWAPI._registeredAPIs;
}

IWAPI.registerAPI = function(apiID,apiObj)
{
    //We assume here that developers know what they are doing; we don't check
    //for duplicated registration.
    var registeredAPIs = IWAPI.getRegisteredAPIs();
    registeredAPIs[apiID] = apiObj;
}

IWAPI._doInheritance = function(theClass,parentClass)
{
    if (parentClass)
    {
        theClass.prototype = new parentClass();
        theClass.superclass = parentClass;
    }
    theClass.constructor = theClass;
}


IWAPI._bindAPIToObj = function(obj, apiImpl)
{
    //Sanity check
    if (!apiImpl || !obj)
    {
        return;
    }
    //Implement inheritance.
    if (apiImpl.prototype.superclass)
    {
        IWAPI._bindAPIToObj(obj,apiImpl.prototype.superclass);
    }
    for (i in apiImpl.prototype)
    {
        obj[i] = apiImpl.prototype[i];
    }

    //A flag to show that this item has been initialized.
    obj._apiInit = true;
    //Run the initializer 
    if (obj.init)
    {
        obj.init();
    }

}



function IWItem()
{
}

IWItem.prototype.DEFAULT_DISPLAY = "block";

IWItem.prototype.getID = function()
{
    return this.id;
}

IWItem.prototype.setVisible = function(visible)
{
    this.style.display = visible ? this.DEFAULT_DISPLAY : "none";
}

IWItem.prototype.isVisible = function()
{
    return this.style.display != "none";
}

IWItem.prototype.setStyle = function(style)
{
    var pairs = style.split(";");
    for (var i = 0; i < pairs.length; i++)
    {
        var pair = properties[i];
        var propVal = pair.split(":");
        //A quick sanity check
        if (propVal.length == 2)
	{
            this.style[propVal[0]] = propVal[1];
        }
    }
}

IWItem.prototype.setCSSClass = function(cssClassName)
{
    this.className = cssClassName; 
}




IWAPI._doInheritance(IWFormElement,IWItem,null);
function IWFormElement()
{
}

IWFormElement.prototype.getType = function()
{
    //Subclasses need to implement this.
}

IWFormElement.prototype.setFocus = function()
{
    this.focus();
}

IWFormElement.prototype.setReadOnly = function(readOnly)
{
    this.setAttributes("readOnly", readOnly);
    //important:
    //at least 1 browser doesn't ensure the type of assignments
    //for select elements.
}

IWFormElement.prototype.getReadOnly = function()
{
    return this.readOnly;
}

IWFormElement.prototype.setValue = function(value)
{
    this.value = value;
}

IWFormElement.prototype.getValue = function()
{
    return this.value;
}

IWFormElement.prototype.getName = function()
{
    if (this.name){
        return this.name;
    }
    else{
        return this.getAttribute("id");
    }
}

IWFormElement.prototype.isMultiSelect = function()
{
    //By default, it returns false.  However, subclasses may override it.
    return false;
}
