/**
 * 通用对象。
 * @create   2004-09-29 source0
 * @author   source0 source0@hotmail.com
 * @copyright 版权所有（C） 2004  source0
 *                这一程序是自由软件，你可以遵照自由软件基金会出版的GNU通用
 *            公共许可证条款来修改和重新发布这一程序。或者用许可证的第二版，
 *            或者（根据你的选择）用任何更新的版本。
 *                发布这一程序的目的是希望它有用，但没有任何担保。甚至没有
 *            适合特定目的的隐含的担保。更详细的情况请参阅GNU通用公共许可证。
 *                你应该已经和程序一起收到一份GNU通用公共许可证的副本。如果
 *            还没有，写信给：
 *                The Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
 *                MA02139, USA
 */

/**
 * 一个取得指定对象实例在窗口内位置的对象
 * @param id 指定对象实例的ID
 */
function PosObject(id){
    var obj = document.getElementById(id);
    this.top     = -1;
    this.left    = -1;
    if ( null == obj ) {
        return;
    }

    this.top   = obj.offsetTop;
    this.left  = obj.offsetLeft;
    while(obj = obj.offsetParent){
        this.top += obj.offsetTop;
        this.left+= obj.offsetLeft;
    }
    this.toString = function(){
        return "PosObject[left=" + this.left +", top=" + this.top + "]";
    }
}

/**
 * 本地化字符串对象。
 * @param value 默认本地语言下的值。
 * @param lang 默认本地语言。如果此参数为 null， 使用 zh_CN 作为默认值。
 */
function CString(value, lang){
    var map = new Array();
    map[( null == lang ) ? DEFAULT_LANGUAGE : lang] = value;

    /**
     * 添加一条信息。
     * @param lang 语言。
     * @param value 值。
     */
    this.add = function(lang, value){
        map[lang] = value;
    }

    /**
     * 得到指定语言的值。
     * @param lang 语言。
     * @return 如果 lang 参数为 null，返回默认语言的值，否则返回该语言的值。如果该语言的值不存在，返回 null 。
     */
    this.get = function(lang){
        return map[(null == lang) ? DEFAULT_LANGUAGE : lang];
    }
    this.toString = function(){
        return this.get(DEFAULT_LANGUAGE);
    }
    this.description = function(){
        return "CString[Local=" + DEFAULT_LANGUAGE + ", Value=" + this.get(DEFAULT_LANGUAGE) + "]";
    }
}

/**
 * 迭代对象。
 * @param map 具有散列表性质的数组对象实例。
 */
function CIterator(map){
    var array = new Array();
    var pos = 0;
    for( var key in map ){
        array[array.length] = map[key];
    }

    /**
     * 是否还有下一个元素。
     * @return 如果有，返回 true，否则返回 false。
     */
    this.hasNext = function(){
        return pos < array.length;
    }
    /**
     * 取下一个元素。
     * @return 如果有，返回下一个元素，否则返回 null 。
     */
    this.next = function(){
        return array[pos++];
    }
    /** 重置。回到刚初始化的状态。*/
    this.reset = function(){
        pos = 0;
    }
}
