/*
Copyright 2006, Open Source Applications Foundation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
*/

//Author: Adam Christian, Open Source Applications Foundation
//Email: adam@osafoundation.org
//
//Description: The following function allows a selenium test to accurately move an event DIV
//to a destination time/day using the Cosmo UI objects to calculate and compensate for
//The relative DIV offsets
//
//Since the div names are a concatonation of their hash key and a prepending string
//I will just recreate that before I actually look up the dom element, then click
//the appropriate element

windmill.controller.extensions.clickLozenge =function (param_object){
    var hash_key;

    eval ("hash_key=" + param_object.jsid + ";");
    //hash_key = eval('('+ param_object.jsid + ')');
    param_object.id = "eventDivContent__" + hash_key;
    delete param_object.jsid;

    //Since id comes before jsid in the lookup order
    //we don't need to reset it, now go ahead and click it!
    return this.click(param_object);
};


windmill.controller.extensions.cosmoDragDrop = function (p){

    // Nothing to see here, move along
    return true;

    var param = p || {};
    var dragged = param.dragged;
    var dest = param.destination;
    var app = windmill.testingApp;

    dragged.id = dragged.pfx + eval(dragged.jsid);
    // Delete the jsid to force lookup by regular id
    delete dragged.jsid;
    dragged = windmill.controller._lookupDispatch(dragged);
    dest = windmill.controller._lookupDispatch(dest);

    // Bail out if no drag elem or destination
    if (!dragged || !dest) {
        return false;
    }

    var mouseDownX = dragged.parentNode.offsetLeft +
        (app.LEFT_SIDEBAR_WIDTH + app.HOUR_LISTING_WIDTH + 2) + 12;
    var mouseDownY = dragged.parentNode.offsetTop -
        (app.cosmo.view.cal.canvasInstance.getTimedCanvasScrollTop() -
        app.TOP_MENU_HEIGHT) + 12;

    var mouseUpX = dest.parentNode.offsetLeft +
        (app.LEFT_SIDEBAR_WIDTH + app.HOUR_LISTING_WIDTH + 2) + 12;
    var mouseUpY = dest.offsetTop -
        (app.cosmo.view.cal.canvasInstance.getTimedCanvasScrollTop() -
        app.TOP_MENU_HEIGHT) + 12;

    windmill.events.triggerMouseEvent(app.document.body,
        'mousemove', true, mouseDownX, mouseDownY);
    windmill.events.triggerMouseEvent(dragged,
        'mousedown', true);
    windmill.events.triggerMouseEvent(app.document.body,
        'mousemove', true, mouseUpX, mouseUpY);
    windmill.events.triggerMouseEvent(dragged,
        'mouseup', true);
        return true;
};



@@ -1583,65 +1583,8 @@
 )%7B%0A%0A
-    // Nothing to see here, move along%0A    return true;%0A%0A
     
@@ -2059,59 +2059,102 @@
   %7D%0A
-%0A
     
-var mouseDownX = dragged.parentNode.offsetLeft
+// Offsets to convert abs XY pos to local pos on canvas%0A    var vOff = app.TOP_MENU_HEIGHT
  +%0A 
@@ -2164,117 +2164,115 @@
     
-(
 app.
-LEFT_SIDEBAR_WIDTH +
+ALL_DAY_RESIZE_AREA_HEIGHT +%0A       
  app.
-HOUR
+DAY
 _LIST
-ING_WIDTH + 2) + 12;%0A    var mouseDownY = dragged.parentNode.offsetTop
+_DIV_HEIGHT +%0A        app.ALL_DAY_RESIZE_HANDLE_HEIGHT
  -%0A 
@@ -2270,33 +2270,32 @@
 EIGHT -%0A        
-(
 app.cosmo.view.c
@@ -2299,32 +2299,24 @@
 w.cal.canvas
-Instance
 .getTimedCan
@@ -2333,39 +2333,80 @@
 op()
- -%0A        app.TOP_MENU_HEIGHT)
+;%0A    var hOff = app.LEFT_SIDEBAR_WIDTH +%0A        app.HOUR_LISTING_WIDTH
  + 1
@@ -2426,18 +2426,23 @@
 ouse
-Up
+Down
 X = d
-est
+ragged
 .par
@@ -2465,76 +2465,73 @@
 ft +
-%0A        (app.LEFT_SIDEBAR_WIDTH + app.HOUR_LISTING_WIDTH + 2) + 12;
+ hOff;%0A    var mouseDownY = dragged.parentNode.offsetTop + vOff;%0A
 %0A   
@@ -2546,17 +2546,17 @@
 seUp
-Y
+X
  = dest.
 offs
@@ -2555,124 +2555,78 @@
 est.
-offsetTop -%0A        (app.cosmo.view.cal.canvasInstance.getTimedCanvasScrollTop() -%0A        app.TOP_MENU_HEIGHT) + 12
+parentNode.offsetLeft + hOff;%0A    var mouseUpY = dest.offsetTop + vOff
 ;%0A%0A 

Fix for bug 9980 -- Fix offset calculations for lozenge drag/drop tests.