/*
 * Copyright 1999-2002 by Vignette, Inc.,
 * All rights reserved.
 * 
 * This software is the confidential and proprietary information
 * of Vignette, Inc. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Vignette.
 * 
 */
 
function UpHandler(e) {

	if (!DraggMod) { return true; }

	if (DropIndicator != null) {
		DropIndicator.hideIt();
	}
	if (PageLayout.dnModCl) {
		DraggMod.view.evnt.className=PageLayout.dnModCl;
	}
	DraggMod.dc.SetZIndex(MOD_BOT_Z);
	DraggMod.view.css.cursor="auto";
	var savedata=0;
	if (!DropCol || DropCol.type==MOD_FIX) {
		if(PageLayout.lockedPanel) {
			if (PageLayout.lockedPanel.isShown) {
				PageLayout.lockedPanel.hideIt();
				if(PageLayout.msg) PageLayout.msg.hideIt();
				PageLayout.lockedPanel.isShown=0;
			}
		}
		DraggMod.dc.Move(DraggMod.x, DraggMod.y);
	} else {
		//alert("this module is moving to column:" + DropCol.id + " position:" + DropIndex);

		var oldCol = DraggMod.parent;
		if (oldCol == DropCol) {
			for (var i=0; i<DropCol.rows.length; i++) {
				if (DropCol.rows[i] == DraggMod) {
					if (i == DropIndex || i + 1 == DropIndex) {
						// position no change
						DraggMod.dc.Move(DraggMod.x,DraggMod.y);
						break;
					} else {
						var mods = DropCol.rows;
						if (i < DropIndex) {
							// move down
							var modsPart1 = mods.slice(0,i);
							modsPart1 = modsPart1.concat(mods.slice(i+1,DropIndex));
							modsPart1[modsPart1.length] = DraggMod;
							modsPart1 = modsPart1.concat(mods.slice(DropIndex,mods.length));
							DropCol.rows = modsPart1;
							savedata=getSubmittingData(DropCol);
							break;
						} else {
							// move up
							var modsPart1 = mods.slice(0,DropIndex);
							modsPart1[modsPart1.length] = DraggMod;
							modsPart1 = modsPart1.concat(mods.slice(DropIndex,i));
							if (i+1 < mods.length) {
								modsPart1 = modsPart1.concat(mods.slice(i+1,mods.length));
							}
							DropCol.rows = modsPart1;
							savedata=getSubmittingData(DropCol);
							break;
						}
					}
				}
			}
		} else {
			oldCol.removeRow(DraggMod);
			DropCol.insertRow(DraggMod, DropIndex);
			savedata=getSubmittingData(oldCol,DropCol);
		}
	}
	// turn off module up location indicator if present
	if (PageLayout.upModFp) {
		PageLayout.upModFp.hideIt();
	}
	DraggMod = null;
	PageLayout.render();

	if(savedata) {
		sendDataToServer(savedata);
	}

	return false;
}

function getSubmittingData(panel1,panel2) {
	var sdata="";
	if(panel1 && panel1.rows) {
		var p1value="";
		var p1id=panel1.id;
		var newid="m"+p1id.substring(1)+"_";
		sdata+="p1="+panel1.id+"&";
		for (var j=0;j<panel1.rows.length;j++) {
			if(panel1.rows[j].type != MOD_NOT){
				p1value+= panel1.rows[j].id;
				panel1.rows[j].id=(newid+j);
			}
		}
		sdata+="p1v="+p1value+"&"
	}
	if(panel2 && panel2.rows) {
		var p2value="";
		var p2id=panel2.id;
		var newid="m"+p2id.substring(1)+"_";
		sdata+="p2="+panel2.id+"&";
		for (var j=0;j<panel2.rows.length;j++) {
			if(panel2.rows[j].type != MOD_NOT){
				p2value+=panel2.rows[j].id;
				panel2.rows[j].id=(newid+j);
			}
		}
		sdata+="p2v="+p2value+"&"
	}
	return sdata;
}

