// Script: DDOBJ (Drag-and-Drop DHTML Objects) v1.21 (FREE TRIAL)
// Company: Interaxis
// Author: dynamicreport.com
// Website: http://dynamicreport.com/ddobj.html
// License: This script is subject to the EULA included in the DDOBJ package



var sRelPath = "images/"; // transparent image relative path excluding 'trans.gif' filename but including last forward slash
// (i.e. relative path from page folder containing inclusion to this javascript file) (eg. images/ or "" if in same folder)

var ddobj = ddobj_ = ddcover = ddimg = ddc = ddw = null; // objects -- when not null, they are tracked by document's move event
var dd_x = dd_y = dd_bForced = 0; // track coordinates for locking on a layer drag operation, force layer drag flag
var dd_ox = dd_oy = 0; // top/left corner of the page
var dd_lock = 0; // toggle the drag-and-drop operation of an object so that obscure interruptions amongst various objects are avoided
var DD_OFFSETX = -15; // X offset from cursor to start of drag-drop layer
var DD_OFFSETY = -15; // Y offset from cursor to start of drag-drop layer
var dd_bInit = 0; // this script has not been initialized yet by a call to dd_initLyr ()
var dd_bDragAll = 1; // internal flag marks whether the entire object is draggable (1) or just a portion (0)
var dd_close = 1; // enable object close section
var dd_dragy = 25; // offset pixels of vertical space will activate the drag-drop operation if dd_bDragAll is not set (0)
var dd_closex = -1; // offset close icon # pixels left from top-right corner of drag-drop layer
var dd_closey = 1; // offset close icon # pixels down from top-right corner of drag-drop layer

var DD_WAITSHOWHIDE = -1; // this flag will be reset and showlyr will exit so that the function call is disabled
// once (necessary to ignore an event handler for an object temporarily - set value to object index)


// INITIALIZE BROWSER DETECTION AND BROWSER-SPECIFIC DOM OBJECT VALUES
var dd_ns = dd_ie = dd_opera = dd_features = 0;
var set_show = set_hide = "";

// SKIN TEMPLATE -- CAPTION & CONTENT IS ENCOMPASSED BY THE HEADER AND FOOTER
var dd_sHeaderT = "";
var dd_sHeaderB = "";
var dd_sFooter = "";

function dd_getUnitValue (sVal)
{
	var sTotal = "";
	iMul = 1;
	for (i = 0; i < sVal.length; i++)
	{
		if (sVal.charAt (0) == '-')
			iMul = -1;
		if (sVal.charAt (i) >= '0' && sVal.charAt (i) <= '9')
			sTotal += sVal.charAt (i);
	}
	return iMul * parseInt (sTotal);
}


function dd_setBrowser ()
{
	var agt = navigator.userAgent.toLowerCase ();
  
	// determine browser types and versions
	if (agt.indexOf("opera") != -1)
	{
		dd_opera = parseInt (navigator.appVersion);
		dd_ie = 5;
	}

	if (navigator.appName == "Microsoft Internet Explorer")
		dd_ie = parseInt (navigator.appVersion);
	else if (navigator.appName == "Netscape")
		dd_ns = parseInt (navigator.appVersion);

	// browser-specific visibility flags
	set_show = (dd_ns) ? 'show' : 'visible';
	set_hide = (dd_ns) ? 'hide' : 'hidden';

	if (dd_ns >= 5)
	{
		set_show = 'visible';
		set_hide = 'hidden';
	}

	// determine applicable features
	if (dd_ie >= 4 || dd_ns >= 5 || dd_opera)
		dd_features = 1;
	else if (dd_ns >= 4)
		dd_features = 2;
	else
		dd_features = 0;
}



function dd_updLyr (iIndex, activeUpdate)
{
	sExt = "dd" + iIndex;

	if (dd_features == 1)
	{
		if (activeUpdate)
		{
			document.getElementById(sExt).style.width = document.getElementById("w_dd"+iIndex).style.width;
			document.getElementById(sExt).style.height = dd_bDragAll ? document.getElementById("flt_"+sExt).offsetHeight : dd_dragy;
			document.getElementById("flt_" + sExt).style.width = document.getElementById("w_dd"+iIndex).style.width;
			document.getElementById("ovr_" + sExt).style.width = document.getElementById("w_dd"+iIndex).style.width;
			document.getElementById("ovr_" + sExt).style.height = dd_bDragAll ? document.getElementById("flt_"+sExt).offsetHeight : dd_dragy;
		}
		else
		{
			document.getElementById("flt_" + sExt).style.visibility = set_hide;
			document.getElementById("ovr_" + sExt).style.visibility = set_hide;
		}
		if (dd_ie)
		{
			if (activeUpdate)
			{
				document.getElementById("cvr_" + sExt).style.width = document.getElementById("w_dd"+iIndex).style.width;
				document.getElementById("cvr_" + sExt).style.height = document.getElementById("w_dd"+iIndex).offsetHeight;
			}
			else
			{
				document.getElementById("cvr_" + sExt).style.visibility = set_hide;
				document.getElementById(sExt).style.visibility = set_hide;
			}
			// iframe hack for drop-down to appear below layer
			if (dd_ie && !dd_opera)
				document.getElementById("cvr_" + sExt).style.display = "inline";
			document.getElementById("cvr_" + sExt).style.left = document.getElementById("flt_" + sExt).style.left;
			document.getElementById("cvr_" + sExt).style.top = document.getElementById("flt_" + sExt).style.top;
		}
	}
	else if (dd_features == 2)
	{
		if (document.layers["flt_" + sExt])
		{
			if (activeUpdate)
			{
				document.layers["c_" + sExt].document.open();
				document.layers["c_" + sExt].document.write("<a href = '#' onclick = 'javascript: dd_showLyr (0, 0, \"\", \"\", 0); return false;'><img src = '"+sRelPath+"close.gif' galleryimg = 'no' alt = 'Close Window' width = '20' height = '20' border = '0'></a>");
				document.layers["c_" + sExt].document.close();

				document.layers["ovr_" + sExt].left = document.layers["flt_" + sExt].left;
				document.layers["ovr_" + sExt].top = document.layers["flt_" + sExt].top;
				document.layers["ovr_" + sExt].document.open();
				document.layers["ovr_" + sExt].document.write("<img src='"+sRelPath+"trans.gif' id = '"+sExt+"' name='"+sExt+"' border = '0' width='" + document.layers["flt_" + sExt].clip.right + "' height='" + (dd_bDragAll ? document.layers["flt_" + sExt].clip.bottom : dd_dragy) + "'>");
				document.layers["ovr_" + sExt].document.close();
			}
			else
			{
				document.layers["flt_" + sExt].visibility = set_hide;
				document.layers["ovr_" + sExt].visibility = set_hide;
			}
		}
	}
}


function dd_initLyr()
{
	if (dd_features == 1)
	{
		// track W3C DOM standard events
		document.onmousedown = dd_down;
		document.onmouseup = dd_up;
		document.onmousemove = dd_move;
		if (document.getElementById("ovr_dd0"))
			dd_updLyr (0, 0);
	}
	else if (dd_features == 2)
	{
		// track DOM events with Netscape 4.x
		window.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE);
		window.onmousedown = dd_down;
		window.onmouseup = dd_up;
		window.onmousemove = dd_move;
		if (document.layers["ovr_dd0"])
			dd_updLyr (0, 0);
	}
	dd_skin_default ();
	dd_bInit = 1; // ok to begin tracking the objects -- avoid premature interruption of initialization
}


function dd_down(e) // called once only when the mouse button is clicked initially
{
	dd_bForced = 0;
	if (dd_features == 1)
	{
		if (dd_ns)
		{
			if (!e)
				return true;
			dd_ox = e.pageX; // obtain cursor location
			dd_oy = e.pageY;
			if ((!e.target || !e.target.name) && dd_bDragAll) // verify that the object is valid and it is a ddobj
				return false;
			if ((!e.target || !e.target.name) && !dd_bDragAll)
				return true; // true enables default mousedown event handling
			if ((e.target.name[0] != 'd' || e.target.name[1] != 'd'))
				return true;

			// object exists, set all object references
			ddimg = document[e.target.name];
			ddobj_ = document.getElementById("flt_" + e.target.name);
			ddobj = document.getElementById("ovr_" + e.target.name);
			ddc = document.getElementById("c_" + e.target.name);

			dd_lock = 1; // once it is identified as a dd object, flag the lock down

			dd_x = e.pageX - dd_getUnitValue (ddobj.style.left); // calculate cursor position relative to layer
			dd_y = e.pageY - dd_getUnitValue (ddobj.style.top);
			if (e.target.name[0] == 'd' && e.target.name[1] == 'd')
				return false;
		}
		else
		{
			if (!window.event) // verify that the object is valid and it is a ddobj
				return false;  // false enables default mousedown event handling
			if (window.event.srcElement.id.charAt (0) != 'd' || window.event.srcElement.id.charAt (1) != 'd')
				return true;

			ddimg = window.event.srcElement.parentElement; // set all object references
			ddobj = document.getElementById("ovr_" + window.event.srcElement.id);
			ddobj_ = document.getElementById("flt_" + window.event.srcElement.id);
			ddc = document.getElementById("c_" + window.event.srcElement.id);
			ddw = document.getElementById("w_" + window.event.srcElement.id);

			dd_lock = 1; // once it is identified as a dd object, flag the lock down

			if (dd_ie)
				ddcover = document.getElementById("cvr_" + window.event.srcElement.id);
			dd_x = window.event.offsetX; // obtain cursor location
			dd_y = window.event.offsetY;

			if (window.event.srcElement != ddobj)
				return false;
		}
	}
	else if (dd_features == 2)
	{
		if (!e)
			return true;
		dd_ox = e.pageX; // obtain cursor location
		dd_oy = e.pageY;
		if (!e.target || !e.target.name) // verify that the object is valid and it is a ddobj
			return true;
		if ((e.target.name[0] != 'd' || e.target.name[1] != 'd'))
			return true;

		if (document.layers["ovr_" + e.target.name]) // object exists, set all object references
		{
			ddimg = document[e.target.name];
			ddobj_ = document.layers["flt_" + e.target.name];
			ddobj = document.layers["ovr_" + e.target.name];
			ddc = document.layers["c_" + e.target.name];

			dd_lock = 1; // once it is identified as a dd object, flag the lock down

			dd_x = e.pageX - ddobj.left; // calculate cursor position relative to layer
			dd_y = e.pageY - ddobj.top;
			return false;
		}
		return true;
	}
	return true;
}


function dd_forceMove(iIndex)
{
	sExt = "dd" + iIndex;
	if (dd_features == 1)
	{
		ddobj = document.getElementById("ovr_" + sExt); // set all object references
		ddobj_ = document.getElementById("flt_" + sExt);
		ddimg = document.getElementById(sExt);
		ddc = document.getElementById("c_" + sExt);
		if (dd_ie) // iframe hack for IE
		{
			ddcover = document.getElementById("cvr_" + sExt);
			ddw = document.getElementById("w_" + sExt);
			// ensure cover (iframe) height is synchronized with table
			if (ddcover.style.height != ddw.offsetHeight)
				ddcover.style.height = ddw.offsetHeight;
		}
		if (dd_ns)
			dd_offset (dd_ox - DD_OFFSETX, dd_oy - DD_OFFSETY); // move action associated with object tracking cursor -- set offset from cursor position (dd_ox/dd_oy already assigned by move or down event handlers)
	}
	else if (dd_features == 2)
	{
		if (document.layers["ovr_" + sExt]) // object exists, set all object references
		{
			ddobj = document.layers["ovr_" + sExt];
			ddobj_ = document.layers["flt_" + sExt];
			ddc = document.layers["c_" + sExt];
			dd_offset (dd_ox - DD_OFFSETX, dd_oy - DD_OFFSETY); // move action associated with object tracking cursor -- set offset from cursor position (dd_ox/dd_oy already assigned by move or down event handlers)
		}
		else
			return true;
	}
}


function dd_offset (offsetX, offsetY)
{
	if (dd_features == 1 && ddobj)
	{
		if (dd_ns)
		{
			ddobj.style.left = ddobj_.style.left = offsetX;
			ddobj.style.top = ddobj_.style.top = offsetY;
			ddc.style.top = offsetY + dd_closey;
			ddc.style.left = dd_getUnitValue (ddobj.style.left) + dd_getUnitValue (ddobj_.style.width) - dd_getUnitValue (ddc.style.width) + dd_closex;
		}
		else
		{
			ddobj.style.posLeft = ddobj_.style.posLeft = offsetX;
			ddobj.style.posTop = ddobj_.style.posTop = offsetY;
			ddc.style.posTop = offsetY + dd_closey;
			ddc.style.posLeft = ddobj.style.posLeft + dd_getUnitValue (ddobj_.style.width) - dd_getUnitValue (ddc.style.width) + dd_closex;
			if (dd_ie)
			{
				ddcover.style.posLeft = offsetX;
				ddcover.style.posTop = offsetY;
				// ensure cover (iframe) height is synchronized with table
				if (ddcover.style.height != ddw.offsetHeight)
					ddcover.style.height = ddw.offsetHeight;
			}
		}
	}
	else if (dd_features == 2 && ddobj)
	{
		ddobj.left = ddobj_.left = offsetX;
		ddobj.top = ddobj_.top = ddc.top = offsetY;
		ddc.top += dd_closey;
		ddc.left = ddobj.left + ddobj_.clip.right - ddc.clip.right + dd_closex;
	}
}


// called continuously for the duration of the object mouse move event
function dd_move(e) // MSIE does not receive an event object parameter (only Mozilla browsers -- NN, Firefox, etc.)
{
	if (dd_bForced) // move action associated with object tracking cursor -- set offset from cursor position
	{
		dd_x = DD_OFFSETX;
		dd_y = DD_OFFSETY;
	}

	if (dd_ns) // obtain cursor location
	{
		dd_ox = e.pageX;
		dd_oy = e.pageY;
	}

	if (dd_features == 1 && ddobj)
	{
		if (dd_ns)
			dd_offset (e.pageX - dd_x, e.pageY - dd_y);
		else
			dd_offset (document.body.scrollLeft + window.event.clientX - dd_x, document.body.scrollTop + window.event.clientY - dd_y);
		ddobj.style.visibility = set_show;
		ddobj_.style.visibility = set_show;
		ddimg.style.visibility = set_show;
		if (dd_close)
			ddc.style.visibility = set_show;
		if (dd_ie)
			ddcover.style.visibility = set_show;
		return false;
	}
	else if (dd_features == 2 && ddobj)
	{
		dd_offset (e.pageX - dd_x, e.pageY - dd_y);
		ddobj.visibility = set_show;
		ddobj_.visibility = set_show;
		if (dd_close)
			ddc.visibility = set_show;
	}
	return true;
}


function dd_up()
{
	// clear current objects since they're not being tracked for motion (drag-drop operation non-existent)
	ddobj = ddobj_ = ddimg = ddcover = ddc = ddw = null;
	dd_lock = 0;
	return true;
}


function dd_release()
{
	// clear current objects since they're not being tracked for motion (drag-drop operation non-existent)
	// user-call version of the dd_up function to release the object drag operation safely without obscure interruption
	// of the drag operation of another object
	if (!dd_lock)
	{

		ddobj = ddobj_ = ddimg = ddcover = ddc = ddw = null;
		dd_bForced = 0;
	}
	return true;
}


function dd_showLyr(bSwitch, bDragAll, sTitle, sContent, w)
{
	if (!dd_bInit) // not yet initialized
		return false;
		
	if (dd_lock) // object already in control, avoid interruptions
		return true;

	if (DD_WAITSHOWHIDE == 0)
	{
		DD_WAITSHOWHIDE = -1;
		return false;
	}

	sExt = "dd0";

	// hide object before making it visible again (avoid glitch appearance when reused object is redrawn during transitional change)
	dd_setvis (sExt, set_hide);

	dd_bForced = 0;
	dd_bDragAll = bDragAll; // global reminder that the current object is to be completely or partially draggable

	if (bSwitch) // visible, initializing the drag-drop layer
	{
		// modify the HTML tags that define the DDOBJ layout template
		if (sContent != "")
		{
			sCaption = "<table id = 'w_dd0' width = '"+w+"' cellpadding = '0' cellspacing = '0' border = '0'";
			if (dd_features == 1)
				sCaption += " style = 'width:"+w+";'";
			sCaption += "><tr><td valign = 'top' align = 'left'>";
			sCaption += dd_sHeaderT;
			sCaption += sTitle;
			sCaption += dd_sHeaderB;
			sCaption += sContent;
			sCaption += dd_sFooter;
			sCaption += "</td></tr></table>";
	
			if (dd_features == 1)
				document.getElementById("flt_" + sExt).innerHTML = sCaption;
			else if (dd_features == 2 && bSwitch) // visible, initializing the drag-drop layer
			{
				document.layers["flt_" + sExt].document.open ();
				document.layers["flt_" + sExt].document.write (sCaption);
				document.layers["flt_" + sExt].document.close ();
			}
		}
		dd_updLyr (0, 1);
		dd_forceMove (0);
		dd_bForced = 1;
		if (dd_ie) // force initial move
			dd_move (0); // (update current location before making visible to avoid glitch)
	}
	if (!bSwitch) // end move event tracking
		dd_up ();
}


function dd_setvis (sIndex, sVis)
{
	sIndex += "";
	var sExt = sIndex;

	if (sIndex.charAt (0) != 'd' || sIndex.charAt (1) != 'd')
		sExt = "dd" + sIndex;

	// toggle visibility of all components belonging to a single object by index
	if (dd_features == 1)
	{
		if (document.getElementById("ovr_" + sExt).style.visibility == sVis)
			return;
		document.getElementById("ovr_" + sExt).style.visibility = sVis;
		document.getElementById("flt_" + sExt).style.visibility = sVis;
		document.getElementById(sExt).style.visibility = sVis;
		if (dd_close)
			document.getElementById("c_" + sExt).style.visibility = sVis;
		if (dd_ie && !dd_opera)
			document.getElementById("cvr_" + sExt).style.visibility = sVis;
	}
	else if (dd_features == 2)
	{
		if (document.layers["ovr_" + sExt].visibility == sVis)
			return;
		document.layers["ovr_" + sExt].visibility = sVis;
		document.layers["flt_" + sExt].visibility = sVis;
		if (dd_close)
			document.layers["c_" + sExt].visibility = sVis;
	}
}


// -------------------- CUSTOM SKINS ARE AVAILABLE IN THE LICENSED VERSION


function dd_skin_default ()
{
	dd_sHeaderT = "<table width = '100%' cellpadding = '0' cellspacing = '0' border = '1'>" +
	"<tr><td bgcolor = '#DFDFEE' height = '20' valign = 'top'>";

	// header text parameter would appear here

	dd_sHeaderB = "</td></tr>" +
	"<tr><td bgcolor = '#EDEDED' valign = 'top'>";

	// main window text parameter would appear here
	
	dd_sFooter = "<p class = 'css_style3' alt = 'Get DDOBJ!' align = 'right'><b>Rentbazaar.com</B></p>" +
	"</td></tr></table>";
}

