// JScript File
var mAllObjects = new Array();

var MENU_NAME="stMenu";
var MENU_SHADOW="stShadow";
var MENU_HEIGHT="200px";
var MENU_WIDTH="150px";
var MENU_ACTIVE_COLOR="highlight"; //"lightblue";
var MENU_ACTIVE_TEXT="highlighttext";
var SEPARATOR="<hr style='color:graytext;height:1px' />"
var MENU_TEXT="menutext";
var MENU_BACKGROUND_COLOR="menu";
var MENU_FONT="0.70em Tahoma";
var SEPARATOR_FLAG = "_sep";
var TOOL_TIP_DELAY="1000";
var SESSION_ID_NAME = 'ctl00$sessionID' ;
var mIgnoreMenu = false ;
var mMenuSet = false;
var mMenuValues = new Array();
var mMenuOpen = false;
var mMenu;
var mMenuShadow;
var mCurrentCursor;
var mTooltipTimer ;
var mToolTipWaiting = false;
var mToolTipOpen = false;
var mCurrentMousePosition = new Object();
    mCurrentMousePosition.x = 0;
    mCurrentMousePosition.y = 0;

function showMenu(list, oEvent)
{
    hideToolTip();
    if (mIgnoreMenu) return ;
    initMenu(MENU_NAME);
    
    mIgnoreMenu = true ;
    if (mMenuOpen)
    {
        document.releaseCapture();
        mIgnoreMenu = false;
        mMenu.style.display="none";
        mMenuShadow.style.display="none";
        mMenuOpen = false;
        return;
    }
    mMenu.innerHTML = getMenuValues(list);
    positionMenu(mMenu, oEvent);
    mMenu.style.display="block";
    mMenuShadow.style.display="block";
    mMenu.setCapture();
    mMenuOpen = true;
    mIgnoreMenu = false;  
}
function initMenu(id, color, bgColor, font)
{
    if (!mMenuSet)
    {
        mMenu=docAll(MENU_NAME);
        mMenuShadow=docAll(MENU_SHADOW);
        mMenuSet = true;
        document.createStyleSheet();
        var sheet = document.styleSheets[document.styleSheets.length -1];
        var name="#stMenu";
        if (sheet.addRule)
        {
            sheet.addRule(name, "height:3.0em");
        }
        else if (sheet.insertRule)
        {
            sheet.insertRule("#stMenu {cursor:pointer;height:1.8em}",
                              sheet.cssRules.length);
        }
        mMenu.style.border="1px solid graytext";
        mMenu.style.position="absolute";
        mMenu.style.padding="0.3em";
        mMenu.style.zindex=10000;
        mMenu.style.font=MENU_FONT;
        mMenu.style.display="none";
        mMenu.style.backgroundColor="menu";
        mMenuShadow.style.zindex=9999;
    }
    if (isNotEmpty(color))
        mMenu.style.color=color;
    if (isNotEmpty(bgColor))
        mMenu.style.backgroundColor=bgColor;
    if (isNotEmpty(font))
        mMenu.style.font=font;
}
function getMenuValues(list)
{
    var listHTML = mMenuValues[list];
    if (isNull(listHTML))
    {
        var sep = unescape("%01");
        var count =0;
        var ih = new Array();
        var b = unescape(list).split(sep);
        for (var i = 0; i < b.length; i+=3)
        {
            var val = b[i];
            var blnk = "&nbsp;"
            if (b[i+2] == SEPARATOR_FLAG)
            {
                val=SEPARATOR;
                blnk=SEPARATOR;
            }
            if (isNotNull(b[i]))
            {
                ih[count] = "<tr style='height:1.5em' value='" + b[i + 1] + "' target='" + b[i+2] + "'><td class='stMenu' style='width:18px'>" + blnk + "</td><td class='stMenu' >";
                ih[count+1] = val;
                ih[count+2] = "</td><td class='stMenu' style='width:18px'>" + blnk + "</td></tr>";
                count+=3;
            }
        }
        if (count == 0)
            listHTML = "" ;
        else
            listHTML = "<table cellspacing='0' cellpadding='0'>" + ih.join("") + "</table>";
            
        mMenuValues[list] = listHTML
    }
    return listHTML;
}
function onMenuClick(oEvent)
{
    showMenu(null, oEvent);
    var elem = oEvent.srcElement;
    mCurrentCursor="";
    setNewCursor("default");
    if (!(elem.className == "stMenu" && elem.tagName.toLowerCase()=="td")) return;
    elem = findParent("tr",elem);
    var val = elem.value;
    if (isEmpty(val)) return ;
    {
        var tgt = elem.target;
        if (isNotEmpty(tgt))
        {
            if (tgt.toLowerCase() == "_self")
            {
                this.location.href = val;
            }
            else
                window.open(val, tgt);
        }
        else
            eval(val);
    }

}
function onMenuAlert()
{
    alert("alert");
}
function onMenuHover(state, oEvent)
{
    var menu=docAll(MENU_NAME);
    var elem = oEvent.srcElement;
    if (!(elem.className == "stMenu" && elem.tagName.toLowerCase()=="td"))
    { 
        return;
    }
    elem = findParent("tr",elem) ;
    if (isNotNull(elem))
    {
        for (var i =0; i < elem.children.length; i++)
        {
            var child = elem.children[i];
            if (state && elem.target !=SEPARATOR_FLAG)
            {
                child.style.backgroundColor=MENU_ACTIVE_COLOR; 
                child.style.color=MENU_ACTIVE_TEXT; 
            }
            else
            {
                child.style.backgroundColor=MENU_BACKGROUND_COLOR;
                child.style.color=MENU_TEXT;   
           }
       }
   }
}
function findParent(tagName, elem, noFirstTimeCheck)
{
    var firstTime = true;
    tagName = tagName.toLowerCase();
    while (isNotNull(elem))
    {
        if (!firstTime || (firstTime && !noFirstTimeCheck))
        {
            if (elem.tagName.toLowerCase() == tagName)
                break;
        }
        firstTime = false;
        elem = elem.parentElement;
    }
    
    return elem;
}
function findParentWithAttribute(tagName, elem, attName, attValue, noFirstTimeCheck)
{
    while (isNotNull(elem))
    {
        elem = findParent(tagName, elem, noFirstTimeCheck)
        noFirstTimeCheck = true;
        if (elem != null)
        {
             if (elem.getAttribute(attName) == attValue)
                return elem;
       }
    }
}

function onMouseMove(oEvent)
{
    var menu=docAll(MENU_NAME);
    if (menu.style.display != "block") return ;
    
    var elem = oEvent.srcElement;
	var scrollTop = isNotNull(window.document.documentElement) ? window.document.documentElement.scrollTop : window.document.body.scrollTop;
	var scrollLeft = isNotNull(window.document.documentElement) ? window.document.documentElement.scrollLeft : window.document.body.scrollLeft;
    if (elem.parentElement != menu)
    {
        if (((oEvent.clientX + scrollLeft) <= menu.offsetLeft) || ((oEvent.clientX + scrollLeft) >= (menu.offsetLeft + menu.offsetWidth)) ||
            ((oEvent.clientY + scrollTop) <= menu.offsetTop)  || ((oEvent.clientY + scrollTop) >= (menu.offsetTop  + menu.offsetHeight)))
            { setNewCursor("default") }
                
        else
            { setNewCursor("hand") }
            
        return;
    }
}
function setNewCursor(cursor)
{
    if (mCurrentCursor == cursor) return;
    mCurrentCursor = cursor;
    setTimeout("setCursor()", 10);
}
function setCursor()
{
    document.body.style.cursor=mCurrentCursor;
//    docAll(MENU_NAME).setCapture();
    docAll(MENU_NAME).style.cursor=mCurrentCursor;
}
function showToolTip(html, oEvent)
{
    var tt = docAll("toolTip");
    if (isNull(tt)) return;
    mToolTipWaiting = true;
    tt.innerHTML = html;
    mTooltipTimer = setTimeout("displayToolTip()", TOOL_TIP_DELAY);
    
}
function hideToolTip()
{
    var tt = docAll("toolTip");
    if (isNull(tt))
    {   mToolTipOpen=false;
        return;
    }
    if (isNotNull(mTooltipTimer)) clearTimeout(mTooltipTimer);
    mToolTipWaiting = false;
    
    if (tt.style.display=="block");
        tt.style.display="none";
}
function displayToolTip()
{
    if (!mToolTipWaiting) return ;
    mToolTipOpen=true;
    var tt = docAll("toolTip");
    pos = new Object();
    positionElement(tt, tt, mCurrentMousePosition.x, mCurrentMousePosition.y, pos, 10, 10);
    tt.style.top=pos.y + "px";
    tt.style.left=pos.x + "px";
    tt.style.display="block";    
}
function positionElement(div, elem, clientX, clientY, pos, offsetX, offsetY)
{
	// left and top position of grid
	if (isNull(offsetX)) offsetX = 0;
	if (isNull(offsetY)) offsetY = 0;
	var x = clientX + offsetX;
	var y = clientY + offsetY;
	var scrollTop = isNotNull(window.document.documentElement) ? window.document.documentElement.scrollTop : window.document.body.scrollTop;
	var scrollLeft = isNotNull(window.document.documentElement) ? window.document.documentElement.scrollLeft : window.document.body.scrollLeft;
	// width and height of super parent (document)
	var w = 0, h = 0;
	var orig = elem;
	while(elem != null)
	{
		h = elem.offsetHeight;
		w = elem.offsetWidth;
		elem = elem.offsetParent;
	}
	// check if grid fits below editor
	// if not, then move it above editor
    div.style.left = "-10000px";
    div.style.top = "0px";
	div.style.display="block";
    var width = div.offsetWidth;
    var height = div.offsetHeight;
	div.style.display="none";
    
	if((y + height + scrollTop) > h)
		y -= (height - scrollTop);
	else
	    y += scrollTop;
	// check if grid fits on the right from editor
	// if not, then move it to the left
	// 20 - extra shift for possible vertical scrollbar in browser
	if((x + width + 50) > (w + scrollLeft))
		x -= (width - scrollLeft);
	else
	    x += scrollLeft;
	    
	pos.x = x;
	pos.y = y;
	pos.height = height;
	pos.width = width;

}   
function positionMenu(menu, oEvent)
{
	mMenuShadow.style.display="none";
	var pos = new Object();
	positionElement(menu, oEvent.srcElement, oEvent.clientX, oEvent.clientY, pos);
	menu.style.left = pos.x + "px";
	menu.style.top = pos.y + "px";
	mMenuShadow.style.height=(pos.height-4) + "px";
	mMenuShadow.style.width=(pos.width-7) + "px";
	mMenuShadow.style.left=(pos.x+10) + "px";
	mMenuShadow.style.top=(pos.y+6) + "px";
	
}


function docAll(itemID)
{
    if (isEmpty(itemID)) return null;
    if (isNotNull(mAllObjects[itemID]))
        return mAllObjects[itemID] ;
    
    var obj = document.getElementById(itemID);
    if (isNull(obj))
        return null;
    mAllObjects[itemID] = obj;
    return obj;
}
function isEmpty(item)
{
    if (isNull(item)) return true;
    else if (item.length == 0) return true ;
    return false;
}
function isNotEmpty(item)
{
    return !isEmpty(item);
}
function isNotNull(item)
{
    return !isNull(item);
}
function isNull(item)
{
    if (typeof item == "undefined") return true;
    else if (item == null) return true;
        
    return false; 
}

function trackMouse(oEvent)
{
    mCurrentMousePosition.x = event.clientX;
    mCurrentMousePosition.y = event.clientY;
}
function launchSpear(url, autoOpen)
{
    var pl = new SOAPClientParameters();
    var au = isNull(autoOpen) ? "" : autoOpen;
    pl.add("AutoOpen", au);
    SOAPClient.invoke(url, "GetLaunchToken", pl, true, launchCallBack);

}
function launchCallBack(result)
{
    document.location.href = result;
}

function SOAPClientParameters()
{
	var _pl = new Array();
	this.add = function(name, value) 
	{
		_pl[name] = value; 
		return this; 
	}
	this.toXml = function()
	{
		var xml = "";
		for(var p in _pl)
		{
			if(typeof(_pl[p]) != "function")
				xml += "<" + p + ">" + _pl[p].toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;") + "</" + p + ">";
		}
		return xml;	
	}
}

function SOAPClient() {}

SOAPClient.invoke = function(url, method, parameters, async, callback)
{
	if(async)
		SOAPClient._loadWsdl(url, method, parameters, async, callback);
	else
		return SOAPClient._loadWsdl(url, method, parameters, async, callback);
}

// private: wsdl cache
SOAPClient_cacheWsdl = new Array();

// private: invoke async
SOAPClient._loadWsdl = function(url, method, parameters, async, callback)
{
	// load from cache?
	var wsdl = SOAPClient_cacheWsdl[url];
	if(wsdl + "" != "" && wsdl + "" != "undefined")
		return SOAPClient._sendSoapRequest(url, method, parameters, async, callback, wsdl);
	// get wsdl
	var xmlHttp = SOAPClient._getXmlHttp();
	xmlHttp.open("GET", url + "?wsdl", async);
	if(async) 
	{
		xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4)
				SOAPClient._onLoadWsdl(url, method, parameters, async, callback, xmlHttp);
		}
	}
	xmlHttp.send(null);
	if (!async)
		return SOAPClient._onLoadWsdl(url, method, parameters, async, callback, xmlHttp);
}
SOAPClient._onLoadWsdl = function(url, method, parameters, async, callback, req)
{
	var wsdl = req.responseXML;
	SOAPClient_cacheWsdl[url] = wsdl;	// save a copy in cache
	return SOAPClient._sendSoapRequest(url, method, parameters, async, callback, wsdl);
}
SOAPClient._sendSoapRequest = function(url, method, parameters, async, callback, wsdl)
{
	// get namespace
	var ns = (wsdl.documentElement.attributes["targetNamespace"] + "" == "undefined") ? wsdl.documentElement.attributes.getNamedItem("targetNamespace").nodeValue : wsdl.documentElement.attributes["targetNamespace"].value;
	// build SOAP request
	var sr = 
				"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
				"<soap:Envelope " +
				"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
				"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
				"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
				"<soap:Body>" +
				"<" + method + " xmlns=\"" + ns + "\">" +
				parameters.toXml() +
				"</" + method + "></soap:Body></soap:Envelope>";
	// send request
	var xmlHttp = SOAPClient._getXmlHttp();
	xmlHttp.open("POST", url, async);
	var soapaction = ((ns.lastIndexOf("/") != ns.length - 1) ? ns + "/" : ns) + method;
	xmlHttp.setRequestHeader("SOAPAction", soapaction);
	xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
	if (isNotNull(docAll(SESSION_ID_NAME)))
	{
	    if (isNotEmpty(docAll(SESSION_ID_NAME).value))
	        xmlHttp.setRequestHeader("cookie", "ASP.Net_SessionID=" + docAll(SESSION_ID_NAME).value + ";path=/;");
	}   
	if(async) 
	{
		xmlHttp.onreadystatechange = function() 
		{
			if(xmlHttp.readyState == 4)
				SOAPClient._onSendSoapRequest(method, async, callback, wsdl, xmlHttp);
		}
	}
	xmlHttp.send(sr);
	if (!async)
		return SOAPClient._onSendSoapRequest(method, async, callback, wsdl, xmlHttp);
}

SOAPClient._onSendSoapRequest = function(method, async, callback, wsdl, req)
{
	var o = null;
	var nd = SOAPClient._getElementsByTagName(req.responseXML, method + "Result");
	if(nd.length == 0)
	{
		if(req.responseXML.getElementsByTagName("faultcode").length > 0)
			throw new Error(500, req.responseXML.getElementsByTagName("faultstring")[0].childNodes[0].nodeValue);
	}
	else
		o = SOAPClient._soapresult2object(nd[0], wsdl);
	if(callback)
		callback(o, req.responseXML);
	if(!async)
		return o;		
}

// private: utils
SOAPClient._getElementsByTagName = function(document, tagName)
{
	try
	{
		// trying to get node omitting any namespaces (latest versions of MSXML.XMLDocument)
		return document.selectNodes(".//*[local-name()=\""+ tagName +"\"]");
	}
	catch (ex) {}
	// old XML parser support
	return document.getElementsByTagName(tagName);
}

SOAPClient._soapresult2object = function(node, wsdl)
{
	return SOAPClient._node2object(node, wsdl);
}
SOAPClient._node2object = function(node, wsdl)
{
	// null node
	if(node == null)
		return null;
	// text node
	if(node.nodeType == 3 || node.nodeType == 4)
		return SOAPClient._extractValue(node, wsdl);
	// leaf node
	if (node.childNodes.length == 1 && (node.childNodes[0].nodeType == 3 || node.childNodes[0].nodeType == 4))
		return SOAPClient._node2object(node.childNodes[0], wsdl);
	var isarray = SOAPClient._getTypeFromWsdl(node.nodeName, wsdl).toLowerCase().indexOf("arrayof") != -1;
	// object node
	if(!isarray)
	{
		var obj = null;
		if(node.hasChildNodes())
			obj = new Object();
		for(var i = 0; i < node.childNodes.length; i++)
		{
			var p = SOAPClient._node2object(node.childNodes[i], wsdl);
			obj[node.childNodes[i].nodeName] = p;
		}
		return obj;
	}
	// list node
	else
	{
		// create node ref
		var l = new Array();
		for(var i = 0; i < node.childNodes.length; i++)
			l[l.length] = SOAPClient._node2object(node.childNodes[i], wsdl);
		return l;
	}
	return null;
}
SOAPClient._extractValue = function(node, wsdl)
{
	var value = node.nodeValue;
	switch(SOAPClient._getTypeFromWsdl(node.parentNode.nodeName, wsdl).toLowerCase())
	{
		default:
		case "s:string":			
			return (value != null) ? value + "" : "";
		case "s:boolean":
			return value+"" == "true";
		case "s:int":
		case "s:long":
			return (value != null) ? parseInt(value + "", 10) : 0;
		case "s:double":
			return (value != null) ? parseFloat(value + "") : 0;
		case "s:datetime":
			if(value == null)
				return null;
			else
			{
				value = value + "";
				value = value.substring(0, value.lastIndexOf("."));
				value = value.replace(/T/gi," ");
				value = value.replace(/-/gi,"/");
				var d = new Date();
				d.setTime(Date.parse(value));										
				return d;				
			}
	}
}
SOAPClient._getTypeFromWsdl = function(elementname, wsdl)
{
	var ell = wsdl.getElementsByTagName("s:element");	// IE
	if(ell.length == 0)
		ell = wsdl.getElementsByTagName("element");	// MOZ
	for(var i = 0; i < ell.length; i++)
	{
		if(ell[i].attributes["name"] + "" == "undefined")	// IE
		{
			if(ell[i].attributes.getNamedItem("name") != null && ell[i].attributes.getNamedItem("name").nodeValue == elementname && ell[i].attributes.getNamedItem("type") != null) 
				return ell[i].attributes.getNamedItem("type").nodeValue;
		}	
		else // MOZ
		{
			if(ell[i].attributes["name"] != null && ell[i].attributes["name"].value == elementname && ell[i].attributes["type"] != null)
				return ell[i].attributes["type"].value;
		}
	}
	return "";
}
// private: xmlhttp factory
SOAPClient._getXmlHttp = function() 
{
	try
	{
		if(window.XMLHttpRequest) 
		{
			var req = new XMLHttpRequest();
			// some versions of Moz do not support the readyState property and the onreadystate event so we patch it!
			if(req.readyState == null) 
			{
				req.readyState = 1;
				req.addEventListener("load", 
									function() 
									{
										req.readyState = 4;
										if(typeof req.onreadystatechange == "function")
											req.onreadystatechange();
									},
									false);
			}
			return req;
		}
		if(window.ActiveXObject) 
			return new ActiveXObject(SOAPClient._getXmlHttpProgID());
	}
	catch (ex) {}
	throw new Error("Your browser does not support XmlHttp objects");
}
SOAPClient._getXmlHttpProgID = function()
{
	if(SOAPClient._getXmlHttpProgID.progid)
		return SOAPClient._getXmlHttpProgID.progid;
	var progids = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
	var o;
	for(var i = 0; i < progids.length; i++)
	{
		try
		{
			o = new ActiveXObject(progids[i]);
			return SOAPClient._getXmlHttpProgID.progid = progids[i];
		}
		catch (ex) {};
	}
	throw new Error("Could not find an installed XML parser");
}

function centerElement(elem)
{
    var w = 0, h = 0;
    var child = elem;
	while(child != null)
	{
		h = child.offsetHeight;
		w = child.offsetWidth;
		child = child.offsetParent;
	}
	elem.style.left="-10000px";
	elem.style.display="block";
	var height = elem.offsetHeight;
	var width = elem.offsetWidth;
	elem.style.left=((w - width)/2) + "px";
	elem.style.top=((h-height)/2) + "px" ;
}
function showWait(msg, display)
{
    var elem = docAll("stWait");
    if (isNull(elem)) return;
    if (isEmpty(display)) display = (elem.style.display!="block");
    if (!display)
        elem.style.display="none";
    else
    {
        if (isNotNull(msg))
            elem.children[0].innerText=msg;
        centerElement(elem);
        elem.style.display="block";
    }
}
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

//page functions for popups
var lastSearchControl;
function showSearch(returnControl, lastFrame, lastDiv, lastSearch, seedMode, showMode, delimiter, event)
 {
    debugger
    hideSearch(event); 
    var sc = SearchControl.init(event.srcElement,returnControl,lastFrame, lastDiv, lastSearch, seedMode, showMode, delimiter, event); 
    sc.showSearch(event);
    lastSearchControl = sc;
    event.cancelBubble=true;
}
function hideSearch(event)
{
    debugger
    if(lastSearchControl != null)
    { 
        lastSearchControl.hideSearch(event);
    }
}
function setValue(val, event)
{
    lastSearchControl.setValue(val, event);
    hideSearch(event);
}
// SearchControl class
var SearchControl = {

 ReturnControl: null, 
 Frame: null, 
 Div: null,
 Search:null,
 SeedMode:null,
 ShowMode:null, 
 Delimiter: null,

init: function(ctrl, returnControl, lastFrame, lastDiv, lastSearch, seedMode, showMode,delimiter, event)
{
    debugger
    ReturnControl=returnControl; 
    Frame=lastFrame;
    Div=lastDiv; 
    Search=lastSearch;
    SeedMode=seedMode;
    ShowMode=showMode;
    Delimiter=delimiter;
    return this;
},

showSearch: function(event)
{
     var ifm = document.getElementById(Div);
     if(ShowMode == 'Center')
        centerElement(ifm); 
     else if(ShowMode == 'Cursor')
     {
        var pos = new Object();
        ifm.style.display='block';     
        positionElement(ifm, event.srcElement, event.clientX, event.clientY, pos);
        ifm.style.left = pos.x + 'px';
        ifm.style.top = pos.y + 'px';
        ifm.style.display='block';     
     }
     else// Origin
     {
        ifm.style.display='block';     
     }
    if ((SeedMode == 'Auto') || (SeedMode == 'Store') ||
        (SeedMode == 'QueryString'))
    {
        ifm = document.getElementById(Frame);
    }
    if ((SeedMode == 'Auto')||(SeedMode == 'Store'))
    {
        var scrpt='setSeedValue(' + this.getValues(event)+ ', event)';
        ifm.contentWindow.execScript(scrpt);
    }
    else if (SeedMode == 'QueryString')
    {
        ifm.src=Search + '?seedValues=' + this.getValues(event);
    }
},

 getValues: function(event)
 {
     debugger
     var ctrlArray = ReturnControl.split(Delimiter);
     var vals=''; 
         for(i=0;i<ctrlArray.length;i++)
         { 
            var tb=document.getElementById(ctrlArray[i]);
            if(tb != null)
            {
                vals = vals + tb.value + Delimiter;
            }
         } 
      return "'"+ vals.substring(0,vals.length-1) +"'";
},

 hideSearch: function(event)
 {
     debugger 
     if(Div != null) 
     { 
         var ifm = document.getElementById(Div); 
         ifm.style.display = 'none'; 
     } 
 },
 
 setValue: function(val, event)
 {
     debugger
     var ctrlArray = ReturnControl.split(Delimiter);
     var valArray = val.split(Delimiter);
     for(i = 0;i<valArray.length;i++)
     { 
        var tb = document.getElementById(ctrlArray[i]);
        if(tb != null)
        {
            tb.value = valArray[i];
        }
     }
 }
 };
 
//popup form funcs
var searchPopUp;

function setReturnValue(val, event)
{
    searchPopUp.setValue(val, event);
}

function setSeedValue(val, event)
{
    searchPopUp.setSeedValue(val, event);
}

function hidePopUp(event)
{
    searchPopUp.hideSearch(event); 
}
 //PopUpReturn class
 var SearchPopUp = {
 
    SeedControl:null,
    SeedMode:null,
    Delimiter:null,
    SeedValue:null,
    init: function(seedControl, seedMode, delimiter, event)
    {
        SeedControl = seedControl;
        SeedMode = seedMode;
        Delimiter = delimiter;
        return this;
    },
    
    setValue: function(val, event)
    {
        debugger 
        hideSearch(event);
        var scr = 'setValue("'+ val+ '", event)'; 
        top.execScript(scr);
    },
    
     hideSearch: function(event)
     {
        top.execScript('hideSearch(event)'); 
     },
     
     setSeedValue: function(val, event)
     {
        debugger
        if(SeedMode == 'Auto')
        {
            var ctrlArray = SeedControl.split(Delimiter);
            if((val) && (val != ''))
            {
                var valArray = val.split(Delimiter);
                for(i = 0;i < valArray.length;i++)
                { 
                    var tb = document.getElementById(ctrlArray[i]);
                    tb.value = valArray[i];
                }
            }
        }
        else if(SeedMode == 'Store')
        {
            //use this if you need to write your own seeding code ie: if you are using non-textboxes
            //this will be called by the top page
            SeedValue=val; 
        }
    }
    
 };
 
