//<!--

    /**
    * Init some vars
    */
    _mousePosX = 0;
    _mousePosY = 0;

    notes_layer = '';

    notes_origX = 0;
    notes_origY = 0;

    notes_origLayerX = 0;
    notes_origLayerY = 0;
    
    notes_origWidth  = 0;
    notes_origHeight = 0;
    
    notes_minWidth = 10;
    notes_minHeight = 10;
    
    notes_resize = false;

    /**
    * Layer drag functions
    *
    * NotestartLayerDrag() - Initiates and sets up the drag
    * NoteendLayerDrag()   - Cleans up after a drag
    * NoteonLayerDrag()    - Fired when the mouse moves, updating the position of the layer
    */
    function NotestartLayerDrag(layerID)
    {
        notes_layer = $(layerID);

        notes_origX = _mousePosX;
        notes_origY = _mousePosY;

        notes_origLayerX = Math.abs(notes_layer.style.left.substring(0, notes_layer.style.left.length - 2));
        notes_origLayerY = Math.abs(notes_layer.style.top.substring(0, notes_layer.style.top.length - 2));

        document.onmousemove = (notes_resize == true ? NoteonResize : NoteonLayerDrag);
    }

    function NoteendLayerDrag()
    {
        notes_layer = '';
        notes_origX = 0;
        notes_origY = 0;
        
        document.onmousemove = getMouseXY;
    }
    
    function NoteonLayerDrag(e)
    {
        getMouseXY(e);       
        diffX = _mousePosX - notes_origX;
        diffY = _mousePosY - notes_origY;

        notes_layer.style.left = notes_origLayerX + diffX + 'px';
        notes_layer.style.top  = notes_origLayerY + diffY + 'px';
    }

    /**
    * Layer resize functions
    *
    * NotestartResize() - Initiates and sets up the resize
    * NoteendResize()   - Cleans up after a resize
    * NoteonResize()    - Fired when the mouse moves, updating the size of the layer
    */
    function NotestartResize(layerID)
    {
        notes_layer = $(layerID);

        notes_origX = _mousePosX;
        notes_origY = _mousePosY;

        notes_origWidth  = Math.abs(notes_layer.style.width.substring(0, notes_layer.style.width.length - 2));
        notes_origHeight = Math.abs(notes_layer.style.height.substring(0, notes_layer.style.height.length - 2));

        notes_resize = true;
    }

    function NoteendResize()
    {
        notes_layer = '';
        notes_origX = 0;
        notes_origY = 0;

        notes_resize = false;
        document.onmousemove = getMouseXY;
    }
    
    function NoteonResize(e)
    {
        getMouseXY(e);
        diffX = _mousePosX - notes_origX;
        diffY = _mousePosY - notes_origY;

        if (notes_origWidth + diffX <= notes_minWidth) {
            notes_layer.style.width  = notes_minWidth + 'px';
        } else {
                notes_layer.style.width  = notes_origWidth + diffX + 'px';
        }
        
        if (notes_origHeight + diffY <= notes_minHeight) {
            notes_layer.style.height = notes_minHeight + 'px';
        } else {
                notes_layer.style.height = notes_origHeight + diffY + 'px';
        }
    }
    
    
    function saveNote(userid){      
        notes = encodeURIComponent(document.forms['formNote'].note.value);
        x = $('popupNote');
        notespos = "left:"+getAbsoluteLeft('popupNote')+"px;top:"+getAbsoluteTop('popupNote')+"px;";
        notespos = encodeURIComponent(notespos);
        new Ajax.Request('index.php?fuse=clients&action=UpdateNote',
                         {parameters: 'notes='+notes+'&notespos='+notespos, method: 'post'});
    }
//--> end hide JavaScript
