
/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */

/**
 * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
 * dragged element is inserted before the dragged-over element.
 *
 * @extends YAHOO.util.DDProxy
 * @constructor
 * @param {String} id the id of the linked element
 * @param {String} sGroup the group of related DragDrop objects
 */
function ygDDList(id, sGroup) {

	if (id) {
		this.init(id, sGroup);
		this.initFrame();
		//this.initTarget(id+"_drop", sGroup+"_drop");
		//this.logger = new ygLogger("ygDDList");
	}

	var s = this.getDragEl().style;
	s.border = "0";
	s.opacity = 0.76;
	s.filter = "alpha(opacity=76)";
	
    /**
     * cache of the elements we have changed the style so we can restore it
     * later
     */
    this.els = [];
	
}

ygDDList.prototype = new YAHOO.util.DDProxy();

ygDDList.prototype.startDrag = function(x, y) {
	//this.logger.debug(this.id + " startDrag");

	var dragEl = this.getDragEl();
	var clickEl = this.getEl();

	dragEl.innerHTML = clickEl.innerHTML;
	dragEl.className = clickEl.className;
	//dragEl.style.border = "1px solid blue";
	
	
	this.els['height'] = clickEl.offsetHeight-5;
	this.els['className'] = clickEl.className;
	this.els['innerHTML'] = clickEl.innerHTML;
	clickEl.className = 'expanDivEmpty';
	clickEl.innerHTML = '';
	clickEl.style.height = this.els['height']-2+'px';
	//alert(clickEl.offsetHeight);
};

ygDDList.prototype.endDrag = function(e) {
	// disable moving the linked element
	var clickEl = this.getEl();
	//clickEl.style.height = '';
	clickEl.className = this.els['className'];
	clickEl.innerHTML = this.els['innerHTML'];
	clickEl.style.height = '';
	//clickEl.style.border = "1px solid blue";
};

ygDDList.prototype.onDrag = function(e) {

};

ygDDList.prototype.onDragOver = function(e, id) {
	// this.logger.debug(this.id.toString() + " onDragOver " + id);
	var el;
    
    if ("string" == typeof id) {
        el = YAHOO.util.DDM.getElement(id);
    } else { 
        el = YAHOO.util.DDM.getBestMatch(id).getEl();
    }

	
	var mid = YAHOO.util.DDM.getPosY(el) + ( Math.floor(el.offsetLeft / 2));
    //this.logger.debug("mid: " + mid);

	if (YAHOO.util.Event.getPageY(e) < mid) {
		var el2 = this.getEl();
		var p = el.parentNode;
		//p.insertBefore(el2, el);
	}
};

ygDDList.prototype.onDragEnter = function(e, id) {
	// this.logger.debug(this.id.toString() + " onDragEnter " + id);
	//this.getDragEl().style.border = "1px solid blue";
	
	if ("string" == typeof id) {
        el = YAHOO.util.DDM.getElement(id);
    } else {
        el = YAHOO.util.DDM.getBestMatch(id).getEl();
    }
	//el.style.border = "1px solid green";
	//document.getElementById(el.id+'_drop').style.border = "1px solid #7F99BD";
	document.getElementById(el.id+'_drop').style.background = "#7F99BD";
	
};

ygDDList.prototype.onDragOut = function(e, id) {
    // I need to know when we are over nothing
	//this.getDragEl().style.border = "1px solid red";
    
	if ("string" == typeof id) {
        el = YAHOO.util.DDM.getElement(id);
    } else {
        el = YAHOO.util.DDM.getBestMatch(id).getEl();
    }
	//el.style.border = "1px solid blue";
	//document.getElementById(el.id+'_drop').style.border = "1px solid #F8F9FB";
	document.getElementById(el.id+'_drop').style.background = "#F8F9FB";
}


/////////////////////////////////////////////////////////////////////////////

ygDDList.prototype.onDragDrop = function(e, id) {
	var el;
    if ("string" == typeof id) {
        el = YAHOO.util.DDM.getElement(id);
    } else {
        el = YAHOO.util.DDM.getBestMatch(id).getEl();
    }
	//el.style.border = "1px solid blue";
	//this.getEl().style.border = "1px solid blue";
	//document.getElementById(el.id+'_drop').style.border = "1px solid #F8F9FB";
	document.getElementById(el.id+'_drop').style.background = "#F8F9FB";
	
	var mid = YAHOO.util.DDM.getPosY(el) + ( Math.floor(el.offsetLeft / 2));
    //this.logger.debug("mid: " + mid);

	if (YAHOO.util.Event.getPageY(e) < mid) {
		var el2 = this.getEl();
		var p = el.parentNode;
		p.insertBefore(el2, el);
		el2.innerHTML = this.els['innerHTML'];
		el2.className = this.els['className'];
		el2.style.height = '';
		
		update_box_order(el2.id, el.id, page);
	}
	//YAHOO.util.DDM.swapNode(this.getEl(), el);
};

var handleSuccessOrder = function(o){
	var currency_response_array = new Array();
	if(o.responseText !== undefined){
	}
}

var callbackOrder =
{
	success:handleSuccessOrder,
	argument:[]
};

/*
function loadXMLDoc(sUrlOrder){
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrlOrder, callbackOrder);
}
*/

function update_box_order(id_elem, id_elem_before, page){
	var sUrlOrder = site_url + "login/common/update_user_box_order.inc.php?id_elem=" + id_elem + "&id_elem_before=" + id_elem_before + "&page=" + page;
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrlOrder, callbackOrder);
}