var CL_EVENT_TYPE_ABORT = -1;
var CL_EVENT_TYPE_MOUSE_MOVE = 0;
var CL_EVENT_TYPE_MOUSE_DOWN = 1;
var CL_EVENT_TYPE_MOUSE_UP = 2;
var CL_EVENT_TYPE_MOUSE_CLICK = 3;
var CL_EVENT_TYPE_MOUSE_SCROLL_HORIZONTAL = 4;
var CL_EVENT_TYPE_MOUSE_SCROLL_VERTICAL = 5;
var CL_EVENT_TYPE_PAGE_RESIZE = 6;
var CL_EVENT_TYPE_KEY_DOWN = 7;
var CL_EVENT_TYPE_KEY_UP = 8;
var CL_EVENT_TYPE_KEY_PRESS = 9;
var CL_EVENT_TYPE_FOCUS_GAIN = 10;
var CL_EVENT_TYPE_FOCUS_LOST = 11;

function CL_MouseMoveEvent(type, x, y, time)
{

    this.type = convertType(type);
    this.x = x;
    this.y = y;
    this.time = time;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.x + "|" + this.y;
    };

    function convertType(type)
    {
        if (type == "mousemove") return CL_EVENT_TYPE_MOUSE_MOVE;
        else return "undefined_mme: " + type;
    }
}

function CL_MouseClickEvent(type, x, y, time, ciid)
{

    this.type = convertType(type);
    this.x = x;
    this.y = y;
    this.time = time;
    this.ciid = ciid;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.x + "|" + this.y + "|" + this.ciid;
    };

    function convertType(type)
    {
        if (type == "mousedown") return CL_EVENT_TYPE_MOUSE_DOWN;
        else if (type == "mouseup") return CL_EVENT_TYPE_MOUSE_UP;
        else return "undefined_mce: " + type;
    }
}

function CL_ScrollEvent(type, orientation, offset, time)
{

    this.type = convertType(type);
    this.offset = offset;
    this.time = time;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.offset;
    };

    function convertType(type)
    {
        if (type == "scroll" && orientation == "horizontal") return CL_EVENT_TYPE_MOUSE_SCROLL_HORIZONTAL;
        else if (type == "scroll" && orientation == "vertical") return CL_EVENT_TYPE_MOUSE_SCROLL_VERTICAL;
        else return "undefined_se: " + type + " orientation:" + orientation + " offset:" + offset;
    }
}

function CL_PageEvent(type, width, height, time)
{

    this.type = convertType(type);
    this.width = width;
    this.height = height;
    this.time = time;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.width + "|" + this.height;
    };

    function convertType(type)
    {
        if (type == "resize") return CL_EVENT_TYPE_PAGE_RESIZE;
        else return "undefined_pa: " + type;
    }
}

function CL_KeyEvent(type, keycode, modifier, time)
{

    this.type = convertType(type);
    this.keycode = keycode;
    this.modifier = modifier;
    this.time = time;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.keycode + "|" + this.modifier;
    };

    function convertType(type)
    {
        if (type == "keydown") return CL_EVENT_TYPE_KEY_DOWN;
        else if (type == "keyup") return CL_EVENT_TYPE_KEY_UP;
        else if (type == "keypress") return CL_EVENT_TYPE_KEY_PRESS;
        else return "undefined_ke: " + type;
    }
}

function CL_FocusGainEvent(type, time, ciid)
{
    this.type = convertType(type);
    this.time = time;
    this.ciid = ciid;

    this.toString = function toString()
    {
        return this.type + "|" + this.time + "|" + this.ciid;
    };

    function convertType(type)
    {
        if (type == "focus") return CL_EVENT_TYPE_FOCUS_GAIN;
        else return "undefined_fge: " + type;
    }
}

function CL_FocusLostEvent(type, time, ciid, text)
{
    this.type = convertType(type);
    this.time = time;
    this.ciid = ciid;
    this.chars = text.length;

    if (this.chars == 0) {
        this.words = 0;
    } else {
        this.words = text.split(" ").length;
    }

    this.toString = function toString() {
        return this.type + "|" + this.time + "|" + this.ciid + "|" + this.chars + "|" + this.words;
    };

    function convertType(type) {
        if (type == "blur") return CL_EVENT_TYPE_FOCUS_LOST;
        else return "undefined_fle: " + type;
    }
}

function CL_AbortEvent() {
    this.toString = function toString()
    {
        return CL_EVENT_TYPE_ABORT;
    };
}

